Re: [PATCH v3 1/4] lib/dlock-list: Distributed and lock-protected lists

From: Waiman Long
Date: Wed Jul 20 2016 - 18:03:12 EST


On 07/19/2016 03:23 PM, Tejun Heo wrote:
Hello,

On Tue, Jul 19, 2016 at 02:42:31PM -0400, Waiman Long wrote:
+int alloc_dlock_list_head(struct dlock_list_head *dlist)
+{
+ struct dlock_list_head dlist_tmp;
+ int cpu;
+
+ dlist_tmp.head = alloc_percpu(struct dlock_list_head_percpu);
+ if (!dlist_tmp.head)
+ return -ENOMEM;
+
+ for_each_possible_cpu(cpu) {
+ struct dlock_list_head_percpu *head;
+
+ head = per_cpu_ptr(dlist_tmp.head, cpu);
+ INIT_LIST_HEAD(&head->list);
+ head->lock = __SPIN_LOCK_UNLOCKED(&head->lock);
+ lockdep_set_class(&head->lock,&dlock_list_key);
+ }
+
+ dlist->head = dlist_tmp.head;
Just use dlist->head directly or use local __perpcu head pointer?
I just don't want to expose the structure to world until it is fully
initialized. If you think I am over-cautious, I can use dlist->head as
suggested.
I don't think it makes any actual difference. No strong opinion
either way. Just use local __percpu head pointer then?

I have run sparse on dlock_list.c. There is no need to use the __percpu tag here. The head gets assigned the result of per_cpu_ptr() which has no __percpu annotation. I actually got sparse warning if I used the __percpu tag.

Cheers,
Longman