Add an interface for a user-defined workqueue lockdep map, which is helpful when multiple workqueues are created for the same purpose. This also helps avoid leaking lockdep maps on each workqueue creation. v2: - Add alloc_workqueue_lockdep_map (Tejun) v3: - Drop __WQ_USER_OWNED_LOCKDEP (Tejun) - static inline alloc_ordered_workqueue_lockdep_map (Tejun)
Unified · Split
| @@ -507,6 +507,58 @@ void workqueue_softirq_dead(unsigned int cpu); · 506 unmodified lines | ||
| 507 | 507 | __printf(1, 4) struct workqueue_struct * |
| 508 | 508 | alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...); |
| 509 | 509 | |
| 510 | +#ifdef CONFIG_LOCKDEP | |
| 511 | +/** | |
| 512 | + * alloc_workqueue_lockdep_map - allocate a workqueue with user-defined lockdep_map | |
| 513 | + * @fmt: printf format for the name of the workqueue | |
| 514 | + * @flags: WQ_* flags | |
| 515 | + * @max_active: max in-flight work items, 0 for default | |
| 516 | + * @lockdep_map: user-defined lockdep_map | |
| 517 | + * @...: args for @fmt | |
| 518 | + * | |
| 519 | + * Same as alloc_workqueue but with the a user-define lockdep_map. Useful for | |
| 520 | + * workqueues created with the same purpose and to avoid leaking a lockdep_map | |
| 521 | + * on each workqueue creation. | |
| 522 | + * | |
| 523 | + * RETURNS: | |
| 524 | + * Pointer to the allocated workqueue on success, %NULL on failure. | |
| 525 | + */ | |
| 526 | +__printf(1, 5) struct workqueue_struct * | |
| 527 | +alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active, | |
| 528 | + struct lockdep_map *lockdep_map, ...); | |
| 529 | + | |
| 530 | +/** | |
| 531 | + * alloc_ordered_workqueue_lockdep_map - allocate an ordered workqueue with | |
| 532 | + * user-defined lockdep_map | |
| 533 | + * | |
| 534 | + * @fmt: printf format for the name of the workqueue | |
| 535 | + * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful) | |
| 536 | + * @lockdep_map: user-defined lockdep_map | |
| 537 | + * @args: args for @fmt | |
| 538 | + * | |
| 539 | + * Same as alloc_ordered_workqueue but with the a user-define lockdep_map. | |
| 540 | + * Useful for workqueues created with the same purpose and to avoid leaking a | |
| 541 | + * lockdep_map on each workqueue creation. | |
| 542 | + * | |
| 543 | + * RETURNS: | |
| 544 | + * Pointer to the allocated workqueue on success, %NULL on failure. | |
| 545 | + */ | |
| 546 | +__printf(1, 4) static inline struct workqueue_struct * | |
| 547 | +alloc_ordered_workqueue_lockdep_map(const char *fmt, unsigned int flags, | |
| 548 | + struct lockdep_map *lockdep_map, ...) | |
| 549 | +{ | |
| 550 | + struct workqueue_struct *wq; | |
| 551 | + va_list args; | |
| 552 | + | |
| 553 | + va_start(args, lockdep_map); | |
| 554 | + wq = alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | flags, | |
| 555 | + 1, lockdep_map, args); | |
| 556 | + va_end(args); | |
| 557 | + | |
| 558 | + return wq; | |
| 559 | +} | |
| 560 | +#endif | |
| 561 | + | |
| 510 | 562 | /** |
| 511 | 563 | * alloc_ordered_workqueue - allocate an ordered workqueue |
| 512 | 564 | * @fmt: printf format for the name of the workqueue |
| @@ -4775,11 +4775,17 @@ static void wq_init_lockdep(struct workqueue_struct *wq) · 4774 unmodified lines | ||
| 4775 | 4775 | |
| 4776 | 4776 | static void wq_unregister_lockdep(struct workqueue_struct *wq) |
| 4777 | 4777 | { |
| 4778 | + if (wq->lockdep_map != &wq->__lockdep_map) | |
| 4779 | + return; | |
| 4780 | + | |
| 4778 | 4781 | lockdep_unregister_key(&wq->key); |
| 4779 | 4782 | } |
| 4780 | 4783 | |
| 4781 | 4784 | static void wq_free_lockdep(struct workqueue_struct *wq) |
| 4782 | 4785 | { |
| 4786 | + if (wq->lockdep_map != &wq->__lockdep_map) | |
| 4787 | + return; | |
| 4788 | + | |
| 4783 | 4789 | if (wq->lock_name != wq->name) |
| 4784 | 4790 | kfree(wq->lock_name); |
| 4785 | 4791 | } |
| @@ -5756,6 +5762,28 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, · 970 unmodified lines | ||
| 5756 | 5762 | } |
| 5757 | 5763 | EXPORT_SYMBOL_GPL(alloc_workqueue); |
| 5758 | 5764 | |
| 5765 | +#ifdef CONFIG_LOCKDEP | |
| 5766 | +__printf(1, 5) | |
| 5767 | +struct workqueue_struct * | |
| 5768 | +alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, | |
| 5769 | + int max_active, struct lockdep_map *lockdep_map, ...) | |
| 5770 | +{ | |
| 5771 | + struct workqueue_struct *wq; | |
| 5772 | + va_list args; | |
| 5773 | + | |
| 5774 | + va_start(args, lockdep_map); | |
| 5775 | + wq = __alloc_workqueue(fmt, flags, max_active, args); | |
| 5776 | + va_end(args); | |
| 5777 | + if (!wq) | |
| 5778 | + return NULL; | |
| 5779 | + | |
| 5780 | + wq->lockdep_map = lockdep_map; | |
| 5781 | + | |
| 5782 | + return wq; | |
| 5783 | +} | |
| 5784 | +EXPORT_SYMBOL_GPL(alloc_workqueue_lockdep_map); | |
| 5785 | +#endif | |
| 5786 | + | |
| 5759 | 5787 | static bool pwq_busy(struct pool_workqueue *pwq) |
| 5760 | 5788 | { |
| 5761 | 5789 | int i; |