Skip to content

Commit dbb92f8

Browse files
andrea-parrihtejun
authored andcommitted
workqueue: Document (some) memory-ordering properties of {queue,schedule}_work()
It's desirable to be able to rely on the following property: All stores preceding (in program order) a call to a successful queue_work() will be visible from the CPU which will execute the queued work by the time such work executes, e.g., { x is initially 0 } CPU0 CPU1 WRITE_ONCE(x, 1); [ "work" is being executed ] r0 = queue_work(wq, work); r1 = READ_ONCE(x); Forbids: r0 == true && r1 == 0 The current implementation of queue_work() provides such memory-ordering property: - In __queue_work(), the ->lock spinlock is acquired. - On the other side, in worker_thread(), this same ->lock is held when dequeueing work. So the locking ordering makes things work out. Add this property to the DocBook headers of {queue,schedule}_work(). Suggested-by: Paul E. McKenney <[email protected]> Signed-off-by: Andrea Parri <[email protected]> Acked-by: Paul E. McKenney <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 0bf999f commit dbb92f8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/linux/workqueue.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,19 @@ extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task);
487487
*
488488
* We queue the work to the CPU on which it was submitted, but if the CPU dies
489489
* it can be processed by another CPU.
490+
*
491+
* Memory-ordering properties: If it returns %true, guarantees that all stores
492+
* preceding the call to queue_work() in the program order will be visible from
493+
* the CPU which will execute @work by the time such work executes, e.g.,
494+
*
495+
* { x is initially 0 }
496+
*
497+
* CPU0 CPU1
498+
*
499+
* WRITE_ONCE(x, 1); [ @work is being executed ]
500+
* r0 = queue_work(wq, work); r1 = READ_ONCE(x);
501+
*
502+
* Forbids: r0 == true && r1 == 0
490503
*/
491504
static inline bool queue_work(struct workqueue_struct *wq,
492505
struct work_struct *work)
@@ -546,6 +559,9 @@ static inline bool schedule_work_on(int cpu, struct work_struct *work)
546559
* This puts a job in the kernel-global workqueue if it was not already
547560
* queued and leaves it in the same position on the kernel-global
548561
* workqueue otherwise.
562+
*
563+
* Shares the same memory-ordering properties of queue_work(), cf. the
564+
* DocBook header of queue_work().
549565
*/
550566
static inline bool schedule_work(struct work_struct *work)
551567
{

0 commit comments

Comments
 (0)