History

workqueue: Add interface for user-defined workqueue lockdep map

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)

Matthew Brost committed 2 years ago

Commit ec0a7d41 parent 4f022f42 files · +80 −0Browse files

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

Unified · Split

kernel/workqueue.c+28−0
@@ -4775,11 +4775,17 @@ static void wq_init_lockdep(struct workqueue_struct *wq) · 4774 unmodified lines
4775 4775
4776static void wq_unregister_lockdep(struct workqueue_struct *wq)4776static void wq_unregister_lockdep(struct workqueue_struct *wq)
4777{4777{
4778 if (wq->lockdep_map != &wq->__lockdep_map)
4779 return;
4780
4778 lockdep_unregister_key(&wq->key);4781 lockdep_unregister_key(&wq->key);
4779}4782}
4780 4783
4781static void wq_free_lockdep(struct workqueue_struct *wq)4784static void wq_free_lockdep(struct workqueue_struct *wq)
4782{4785{
4786 if (wq->lockdep_map != &wq->__lockdep_map)
4787 return;
4788
4783 if (wq->lock_name != wq->name)4789 if (wq->lock_name != wq->name)
4784 kfree(wq->lock_name);4790 kfree(wq->lock_name);
4785}4791}
@@ -5756,6 +5762,28 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, · 970 unmodified lines
5756}5762}
5757EXPORT_SYMBOL_GPL(alloc_workqueue);5763EXPORT_SYMBOL_GPL(alloc_workqueue);
5758 5764
5765#ifdef CONFIG_LOCKDEP
5766__printf(1, 5)
5767struct workqueue_struct *
5768alloc_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}
5784EXPORT_SYMBOL_GPL(alloc_workqueue_lockdep_map);
5785#endif
5786
5759static bool pwq_busy(struct pool_workqueue *pwq)5787static bool pwq_busy(struct pool_workqueue *pwq)
5760{5788{
5761 int i;5789 int i;