Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq

Pull workqueue updates from Tejun Heo:
"rcu_work addition and a couple trivial changes"

* 'for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq:
workqueue: remove the comment about the old manager_arb mutex
workqueue: fix the comments of nr_idle
fs/aio: Use rcu_work instead of explicit rcu and work item
cgroup: Use rcu_work instead of explicit rcu and work item
RCU, workqueue: Implement rcu_work

+93 -34
+6 -15
fs/aio.c
··· 115 115 struct page **ring_pages; 116 116 long nr_pages; 117 117 118 - struct rcu_head free_rcu; 119 - struct work_struct free_work; /* see free_ioctx() */ 118 + struct rcu_work free_rwork; /* see free_ioctx() */ 120 119 121 120 /* 122 121 * signals when all in-flight requests are done ··· 591 592 /* 592 593 * free_ioctx() should be RCU delayed to synchronize against the RCU 593 594 * protected lookup_ioctx() and also needs process context to call 594 - * aio_free_ring(), so the double bouncing through kioctx->free_rcu and 595 - * ->free_work. 595 + * aio_free_ring(). Use rcu_work. 596 596 */ 597 597 static void free_ioctx(struct work_struct *work) 598 598 { 599 - struct kioctx *ctx = container_of(work, struct kioctx, free_work); 600 - 599 + struct kioctx *ctx = container_of(to_rcu_work(work), struct kioctx, 600 + free_rwork); 601 601 pr_debug("freeing %p\n", ctx); 602 602 603 603 aio_free_ring(ctx); ··· 604 606 percpu_ref_exit(&ctx->reqs); 605 607 percpu_ref_exit(&ctx->users); 606 608 kmem_cache_free(kioctx_cachep, ctx); 607 - } 608 - 609 - static void free_ioctx_rcufn(struct rcu_head *head) 610 - { 611 - struct kioctx *ctx = container_of(head, struct kioctx, free_rcu); 612 - 613 - INIT_WORK(&ctx->free_work, free_ioctx); 614 - schedule_work(&ctx->free_work); 615 609 } 616 610 617 611 static void free_ioctx_reqs(struct percpu_ref *ref) ··· 615 625 complete(&ctx->rq_wait->comp); 616 626 617 627 /* Synchronize against RCU protected table->table[] dereferences */ 618 - call_rcu(&ctx->free_rcu, free_ioctx_rcufn); 628 + INIT_RCU_WORK(&ctx->free_rwork, free_ioctx); 629 + queue_rcu_work(system_wq, &ctx->free_rwork); 619 630 } 620 631 621 632 /*
+1 -1
include/linux/cgroup-defs.h
··· 151 151 atomic_t online_cnt; 152 152 153 153 /* percpu_ref killing and RCU release */ 154 - struct rcu_head rcu_head; 155 154 struct work_struct destroy_work; 155 + struct rcu_work destroy_rwork; 156 156 157 157 /* 158 158 * PI: the parent css. Placed here for cache proximity to following
+23
include/linux/workqueue.h
··· 13 13 #include <linux/threads.h> 14 14 #include <linux/atomic.h> 15 15 #include <linux/cpumask.h> 16 + #include <linux/rcupdate.h> 16 17 17 18 struct workqueue_struct; 18 19 ··· 121 120 int cpu; 122 121 }; 123 122 123 + struct rcu_work { 124 + struct work_struct work; 125 + struct rcu_head rcu; 126 + 127 + /* target workqueue ->rcu uses to queue ->work */ 128 + struct workqueue_struct *wq; 129 + }; 130 + 124 131 /** 125 132 * struct workqueue_attrs - A struct for workqueue attributes. 126 133 * ··· 158 149 static inline struct delayed_work *to_delayed_work(struct work_struct *work) 159 150 { 160 151 return container_of(work, struct delayed_work, work); 152 + } 153 + 154 + static inline struct rcu_work *to_rcu_work(struct work_struct *work) 155 + { 156 + return container_of(work, struct rcu_work, work); 161 157 } 162 158 163 159 struct execute_work { ··· 279 265 280 266 #define INIT_DEFERRABLE_WORK_ONSTACK(_work, _func) \ 281 267 __INIT_DELAYED_WORK_ONSTACK(_work, _func, TIMER_DEFERRABLE) 268 + 269 + #define INIT_RCU_WORK(_work, _func) \ 270 + INIT_WORK(&(_work)->work, (_func)) 271 + 272 + #define INIT_RCU_WORK_ONSTACK(_work, _func) \ 273 + INIT_WORK_ONSTACK(&(_work)->work, (_func)) 282 274 283 275 /** 284 276 * work_pending - Find out whether a work item is currently pending ··· 467 447 struct delayed_work *work, unsigned long delay); 468 448 extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq, 469 449 struct delayed_work *dwork, unsigned long delay); 450 + extern bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork); 470 451 471 452 extern void flush_workqueue(struct workqueue_struct *wq); 472 453 extern void drain_workqueue(struct workqueue_struct *wq); ··· 482 461 extern bool flush_delayed_work(struct delayed_work *dwork); 483 462 extern bool cancel_delayed_work(struct delayed_work *dwork); 484 463 extern bool cancel_delayed_work_sync(struct delayed_work *dwork); 464 + 465 + extern bool flush_rcu_work(struct rcu_work *rwork); 485 466 486 467 extern void workqueue_set_max_active(struct workqueue_struct *wq, 487 468 int max_active);
+7 -14
kernel/cgroup/cgroup.c
··· 4524 4524 * and thus involve punting to css->destroy_work adding two additional 4525 4525 * steps to the already complex sequence. 4526 4526 */ 4527 - static void css_free_work_fn(struct work_struct *work) 4527 + static void css_free_rwork_fn(struct work_struct *work) 4528 4528 { 4529 - struct cgroup_subsys_state *css = 4530 - container_of(work, struct cgroup_subsys_state, destroy_work); 4529 + struct cgroup_subsys_state *css = container_of(to_rcu_work(work), 4530 + struct cgroup_subsys_state, destroy_rwork); 4531 4531 struct cgroup_subsys *ss = css->ss; 4532 4532 struct cgroup *cgrp = css->cgroup; 4533 4533 ··· 4571 4571 cgroup_destroy_root(cgrp->root); 4572 4572 } 4573 4573 } 4574 - } 4575 - 4576 - static void css_free_rcu_fn(struct rcu_head *rcu_head) 4577 - { 4578 - struct cgroup_subsys_state *css = 4579 - container_of(rcu_head, struct cgroup_subsys_state, rcu_head); 4580 - 4581 - INIT_WORK(&css->destroy_work, css_free_work_fn); 4582 - queue_work(cgroup_destroy_wq, &css->destroy_work); 4583 4574 } 4584 4575 4585 4576 static void css_release_work_fn(struct work_struct *work) ··· 4622 4631 4623 4632 mutex_unlock(&cgroup_mutex); 4624 4633 4625 - call_rcu(&css->rcu_head, css_free_rcu_fn); 4634 + INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn); 4635 + queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork); 4626 4636 } 4627 4637 4628 4638 static void css_release(struct percpu_ref *ref) ··· 4757 4765 err_list_del: 4758 4766 list_del_rcu(&css->sibling); 4759 4767 err_free_css: 4760 - call_rcu(&css->rcu_head, css_free_rcu_fn); 4768 + INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn); 4769 + queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork); 4761 4770 return ERR_PTR(err); 4762 4771 } 4763 4772
+56 -4
kernel/workqueue.c
··· 153 153 unsigned long watchdog_ts; /* L: watchdog timestamp */ 154 154 155 155 struct list_head worklist; /* L: list of pending works */ 156 - int nr_workers; /* L: total number of workers */ 157 156 158 - /* nr_idle includes the ones off idle_list for rebinding */ 159 - int nr_idle; /* L: currently idle ones */ 157 + int nr_workers; /* L: total number of workers */ 158 + int nr_idle; /* L: currently idle workers */ 160 159 161 160 struct list_head idle_list; /* X: list of idle workers */ 162 161 struct timer_list idle_timer; /* L: worker idle timeout */ ··· 165 166 DECLARE_HASHTABLE(busy_hash, BUSY_WORKER_HASH_ORDER); 166 167 /* L: hash of busy workers */ 167 168 168 - /* see manage_workers() for details on the two manager mutexes */ 169 169 struct worker *manager; /* L: purely informational */ 170 170 struct mutex attach_mutex; /* attach/detach exclusion */ 171 171 struct list_head workers; /* A: attached workers */ ··· 1602 1604 } 1603 1605 EXPORT_SYMBOL_GPL(mod_delayed_work_on); 1604 1606 1607 + static void rcu_work_rcufn(struct rcu_head *rcu) 1608 + { 1609 + struct rcu_work *rwork = container_of(rcu, struct rcu_work, rcu); 1610 + 1611 + /* read the comment in __queue_work() */ 1612 + local_irq_disable(); 1613 + __queue_work(WORK_CPU_UNBOUND, rwork->wq, &rwork->work); 1614 + local_irq_enable(); 1615 + } 1616 + 1617 + /** 1618 + * queue_rcu_work - queue work after a RCU grace period 1619 + * @wq: workqueue to use 1620 + * @rwork: work to queue 1621 + * 1622 + * Return: %false if @rwork was already pending, %true otherwise. Note 1623 + * that a full RCU grace period is guaranteed only after a %true return. 1624 + * While @rwork is guarnateed to be executed after a %false return, the 1625 + * execution may happen before a full RCU grace period has passed. 1626 + */ 1627 + bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork) 1628 + { 1629 + struct work_struct *work = &rwork->work; 1630 + 1631 + if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) { 1632 + rwork->wq = wq; 1633 + call_rcu(&rwork->rcu, rcu_work_rcufn); 1634 + return true; 1635 + } 1636 + 1637 + return false; 1638 + } 1639 + EXPORT_SYMBOL(queue_rcu_work); 1640 + 1605 1641 /** 1606 1642 * worker_enter_idle - enter idle state 1607 1643 * @worker: worker which is entering idle state ··· 3032 3000 return flush_work(&dwork->work); 3033 3001 } 3034 3002 EXPORT_SYMBOL(flush_delayed_work); 3003 + 3004 + /** 3005 + * flush_rcu_work - wait for a rwork to finish executing the last queueing 3006 + * @rwork: the rcu work to flush 3007 + * 3008 + * Return: 3009 + * %true if flush_rcu_work() waited for the work to finish execution, 3010 + * %false if it was already idle. 3011 + */ 3012 + bool flush_rcu_work(struct rcu_work *rwork) 3013 + { 3014 + if (test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&rwork->work))) { 3015 + rcu_barrier(); 3016 + flush_work(&rwork->work); 3017 + return true; 3018 + } else { 3019 + return flush_work(&rwork->work); 3020 + } 3021 + } 3022 + EXPORT_SYMBOL(flush_rcu_work); 3035 3023 3036 3024 static bool __cancel_work(struct work_struct *work, bool is_dwork) 3037 3025 {