History

Make workqueue bit operations work on "atomic_long_t"

On architectures where the atomicity of the bit operations is handled by external means (ie a separate spinlock to protect concurrent accesses), just doing a direct assignment on the workqueue data field (as done by commit 4594bf159f1962cec3b727954b7c598b07e2e737) can cause the assignment to be lost due to lack of serialization with the bitops on the same word. So we need to serialize the assignment with the locks on those architectures (notably older ARM chips, PA-RISC and sparc32). So rather than using an "unsigned long", let's use "atomic_long_t", which already has a safe assignment operation (atomic_long_set()) on such architectures. This requires that the atomic operations use the same atomicity locks as the bit operations do, but that is largely the case anyway. Sparc32 will probably need fixing. Architectures (including modern ARM with LL/SC) that implement sane atomic operations for SMP won't see any of this matter.

Linus Torvalds committed 19 years ago

Commit a08727b1 parent 2f77d102 files · +30 −18Browse files

Showing the changes to kernel/workqueue.c (1 of 2 files). Show all

Unified · Split

kernel/workqueue.c+8−8
@@ -96,13 +96,13 @@ static inline void set_wq_data(struct work_struct *work, void *wq) · 95 unmodified lines
9696 BUG_ON(!work_pending(work));
9797
9898 new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING);
99− new |= work->management & WORK_STRUCT_FLAG_MASK;
100− work->management = new;
99+ new |= WORK_STRUCT_FLAG_MASK & *work_data_bits(work);
100+ atomic_long_set(&work->data, new);
101101 }
102102
103103 static inline void *get_wq_data(struct work_struct *work)
104104 {
105− return (void *) (work->management & WORK_STRUCT_WQ_DATA_MASK);
105+ return (void *) (atomic_long_read(&work->data) & WORK_STRUCT_WQ_DATA_MASK);
106106 }
107107
108108 static int __run_work(struct cpu_workqueue_struct *cwq, struct work_struct *work)
@@ -133,7 +133,7 @@ static int __run_work(struct cpu_workqueue_struct *cwq, struct work_struct *work · 24 unmodified lines
133133 list_del_init(&work->entry);
134134 spin_unlock_irqrestore(&cwq->lock, flags);
135135
136− if (!test_bit(WORK_STRUCT_NOAUTOREL, &work->management))
136+ if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work)))
137137 work_release(work);
138138 f(work);
139139
@@ -206,7 +206,7 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work) · 66 unmodified lines
206206 {
207207 int ret = 0, cpu = get_cpu();
208208
209− if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) {
209+ if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
210210 if (unlikely(is_single_threaded(wq)))
211211 cpu = singlethread_cpu;
212212 BUG_ON(!list_empty(&work->entry));
@@ -248,7 +248,7 @@ int fastcall queue_delayed_work(struct workqueue_struct *wq, · 35 unmodified lines
248248 if (delay == 0)
249249 return queue_work(wq, work);
250250
251− if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) {
251+ if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
252252 BUG_ON(timer_pending(timer));
253253 BUG_ON(!list_empty(&work->entry));
254254
@@ -280,7 +280,7 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, · 25 unmodified lines
280280 struct timer_list *timer = &dwork->timer;
281281 struct work_struct *work = &dwork->work;
282282
283− if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) {
283+ if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
284284 BUG_ON(timer_pending(timer));
285285 BUG_ON(!list_empty(&work->entry));
286286
@@ -321,7 +321,7 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) · 34 unmodified lines
321321 spin_unlock_irqrestore(&cwq->lock, flags);
322322
323323 BUG_ON(get_wq_data(work) != cwq);
324− if (!test_bit(WORK_STRUCT_NOAUTOREL, &work->management))
324+ if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work)))
325325 work_release(work);
326326 f(work);
327327