Sun Dec 19 01:04:05 2021 UTC ()
Add work_pending, delayed_work_pending.


(riastradh)
diff -r1.16 -r1.17 src/sys/external/bsd/common/include/linux/workqueue.h
diff -r1.48 -r1.49 src/sys/external/bsd/common/linux/linux_work.c

cvs diff -r1.16 -r1.17 src/sys/external/bsd/common/include/linux/workqueue.h (expand / switch to unified diff)

--- src/sys/external/bsd/common/include/linux/workqueue.h 2021/12/19 01:03:57 1.16
+++ src/sys/external/bsd/common/include/linux/workqueue.h 2021/12/19 01:04:05 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: workqueue.h,v 1.16 2021/12/19 01:03:57 riastradh Exp $ */ 1/* $NetBSD: workqueue.h,v 1.17 2021/12/19 01:04:05 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013, 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013, 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -35,41 +35,43 @@ @@ -35,41 +35,43 @@
35#include <sys/queue.h> 35#include <sys/queue.h>
36#include <sys/stdbool.h> 36#include <sys/stdbool.h>
37 37
38#include <linux/kernel.h> /* container_of */ 38#include <linux/kernel.h> /* container_of */
39 39
40#define INIT_DELAYED_WORK linux_INIT_DELAYED_WORK 40#define INIT_DELAYED_WORK linux_INIT_DELAYED_WORK
41#define INIT_WORK linux_INIT_WORK 41#define INIT_WORK linux_INIT_WORK
42#define alloc_ordered_workqueue linux_alloc_ordered_workqueue 42#define alloc_ordered_workqueue linux_alloc_ordered_workqueue
43#define cancel_delayed_work linux_cancel_delayed_work 43#define cancel_delayed_work linux_cancel_delayed_work
44#define cancel_delayed_work_sync linux_cancel_delayed_work_sync 44#define cancel_delayed_work_sync linux_cancel_delayed_work_sync
45#define cancel_work linux_cancel_work 45#define cancel_work linux_cancel_work
46#define cancel_work_sync linux_cancel_work_sync 46#define cancel_work_sync linux_cancel_work_sync
47#define current_work linux_current_work 47#define current_work linux_current_work
 48#define delayed_work_pending linux_delayed_work_pending
48#define destroy_workqueue linux_destroy_workqueue 49#define destroy_workqueue linux_destroy_workqueue
49#define flush_delayed_work linux_flush_delayed_work 50#define flush_delayed_work linux_flush_delayed_work
50#define flush_scheduled_work linux_flush_scheduled_work 51#define flush_scheduled_work linux_flush_scheduled_work
51#define flush_work linux_flush_work 52#define flush_work linux_flush_work
52#define flush_workqueue linux_flush_workqueue 53#define flush_workqueue linux_flush_workqueue
53#define queue_delayed_work linux_queue_delayed_work 54#define queue_delayed_work linux_queue_delayed_work
54#define mod_delayed_work linux_mod_delayed_work 55#define mod_delayed_work linux_mod_delayed_work
55#define queue_work linux_queue_work 56#define queue_work linux_queue_work
56#define schedule_delayed_work linux_schedule_delayed_work 57#define schedule_delayed_work linux_schedule_delayed_work
57#define schedule_work linux_schedule_work 58#define schedule_work linux_schedule_work
58#define system_long_wq linux_system_long_wq 59#define system_long_wq linux_system_long_wq
59#define system_power_efficient_wq linux_system_power_efficient_wq 60#define system_power_efficient_wq linux_system_power_efficient_wq
60#define system_unbound_wq linux_system_unbound_wq 61#define system_unbound_wq linux_system_unbound_wq
61#define system_wq linux_system_wq 62#define system_wq linux_system_wq
62#define to_delayed_work linux_to_delayed_work 63#define to_delayed_work linux_to_delayed_work
 64#define work_pending linux_work_pending
63 65
64struct workqueue_struct; 66struct workqueue_struct;
65 67
66struct work_struct { 68struct work_struct {
67 volatile uintptr_t work_owner; 69 volatile uintptr_t work_owner;
68 TAILQ_ENTRY(work_struct) work_entry; 70 TAILQ_ENTRY(work_struct) work_entry;
69 void (*func)(struct work_struct *); /* Linux API name */ 71 void (*func)(struct work_struct *); /* Linux API name */
70}; 72};
71 73
72struct delayed_work { 74struct delayed_work {
73 struct work_struct work; /* Linux API name */ 75 struct work_struct work; /* Linux API name */
74 struct callout dw_callout; 76 struct callout dw_callout;
75 TAILQ_ENTRY(delayed_work) dw_entry; 77 TAILQ_ENTRY(delayed_work) dw_entry;
@@ -101,36 +103,38 @@ void linux_workqueue_fini(void); @@ -101,36 +103,38 @@ void linux_workqueue_fini(void);
101 103
102struct workqueue_struct * 104struct workqueue_struct *
103 alloc_ordered_workqueue(const char *, int); 105 alloc_ordered_workqueue(const char *, int);
104void destroy_workqueue(struct workqueue_struct *); 106void destroy_workqueue(struct workqueue_struct *);
105void flush_workqueue(struct workqueue_struct *); 107void flush_workqueue(struct workqueue_struct *);
106void flush_scheduled_work(void); 108void flush_scheduled_work(void);
107 109
108void INIT_WORK(struct work_struct *, void (*)(struct work_struct *)); 110void INIT_WORK(struct work_struct *, void (*)(struct work_struct *));
109bool schedule_work(struct work_struct *); 111bool schedule_work(struct work_struct *);
110bool queue_work(struct workqueue_struct *, struct work_struct *); 112bool queue_work(struct workqueue_struct *, struct work_struct *);
111bool cancel_work(struct work_struct *); 113bool cancel_work(struct work_struct *);
112bool cancel_work_sync(struct work_struct *); 114bool cancel_work_sync(struct work_struct *);
113bool flush_work(struct work_struct *); 115bool flush_work(struct work_struct *);
 116bool work_pending(struct work_struct *);
114 117
115void INIT_DELAYED_WORK(struct delayed_work *, 118void INIT_DELAYED_WORK(struct delayed_work *,
116 void (*)(struct work_struct *)); 119 void (*)(struct work_struct *));
117bool schedule_delayed_work(struct delayed_work *, unsigned long); 120bool schedule_delayed_work(struct delayed_work *, unsigned long);
118bool queue_delayed_work(struct workqueue_struct *, struct delayed_work *, 121bool queue_delayed_work(struct workqueue_struct *, struct delayed_work *,
119 unsigned long ticks); 122 unsigned long ticks);
120bool mod_delayed_work(struct workqueue_struct *, struct delayed_work *, 123bool mod_delayed_work(struct workqueue_struct *, struct delayed_work *,
121 unsigned long ticks); 124 unsigned long ticks);
122bool cancel_delayed_work(struct delayed_work *); 125bool cancel_delayed_work(struct delayed_work *);
123bool cancel_delayed_work_sync(struct delayed_work *); 126bool cancel_delayed_work_sync(struct delayed_work *);
124bool flush_delayed_work(struct delayed_work *); 127bool flush_delayed_work(struct delayed_work *);
 128bool delayed_work_pending(struct delayed_work *);
125 129
126struct work_struct * 130struct work_struct *
127 current_work(void); 131 current_work(void);
128 132
129#define INIT_WORK_ONSTACK INIT_WORK 133#define INIT_WORK_ONSTACK INIT_WORK
130 134
131static inline void 135static inline void
132destroy_work_on_stack(struct work_struct *work) 136destroy_work_on_stack(struct work_struct *work)
133{ 137{
134} 138}
135 139
136#endif /* _LINUX_WORKQUEUE_H_ */ 140#endif /* _LINUX_WORKQUEUE_H_ */

cvs diff -r1.48 -r1.49 src/sys/external/bsd/common/linux/linux_work.c (expand / switch to unified diff)

--- src/sys/external/bsd/common/linux/linux_work.c 2021/12/19 01:03:57 1.48
+++ src/sys/external/bsd/common/linux/linux_work.c 2021/12/19 01:04:05 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux_work.c,v 1.48 2021/12/19 01:03:57 riastradh Exp $ */ 1/* $NetBSD: linux_work.c,v 1.49 2021/12/19 01:04:05 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.48 2021/12/19 01:03:57 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.49 2021/12/19 01:04:05 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/atomic.h> 36#include <sys/atomic.h>
37#include <sys/callout.h> 37#include <sys/callout.h>
38#include <sys/condvar.h> 38#include <sys/condvar.h>
39#include <sys/errno.h> 39#include <sys/errno.h>
40#include <sys/kmem.h> 40#include <sys/kmem.h>
41#include <sys/kthread.h> 41#include <sys/kthread.h>
42#include <sys/lwp.h> 42#include <sys/lwp.h>
43#include <sys/mutex.h> 43#include <sys/mutex.h>
44#ifndef _MODULE 44#ifndef _MODULE
45#include <sys/once.h> 45#include <sys/once.h>
46#endif 46#endif
@@ -528,26 +528,39 @@ INIT_WORK(struct work_struct *work, void @@ -528,26 +528,39 @@ INIT_WORK(struct work_struct *work, void
528 * must be wq, and caller must hold wq's lock. 528 * must be wq, and caller must hold wq's lock.
529 */ 529 */
530static bool 530static bool
531work_claimed(struct work_struct *work, struct workqueue_struct *wq) 531work_claimed(struct work_struct *work, struct workqueue_struct *wq)
532{ 532{
533 533
534 KASSERT(work_queue(work) == wq); 534 KASSERT(work_queue(work) == wq);
535 KASSERT(mutex_owned(&wq->wq_lock)); 535 KASSERT(mutex_owned(&wq->wq_lock));
536 536
537 return work->work_owner & 1; 537 return work->work_owner & 1;
538} 538}
539 539
540/* 540/*
 541 * work_pending(work)
 542 *
 543 * True if work is currently claimed by any workqueue, scheduled
 544 * to run on that workqueue.
 545 */
 546bool
 547work_pending(struct work_struct *work)
 548{
 549
 550 return work->work_owner & 1;
 551}
 552
 553/*
541 * work_queue(work) 554 * work_queue(work)
542 * 555 *
543 * Return the last queue that work was queued on, or NULL if it 556 * Return the last queue that work was queued on, or NULL if it
544 * was never queued. 557 * was never queued.
545 */ 558 */
546static struct workqueue_struct * 559static struct workqueue_struct *
547work_queue(struct work_struct *work) 560work_queue(struct work_struct *work)
548{ 561{
549 562
550 return (struct workqueue_struct *)(work->work_owner & ~(uintptr_t)1); 563 return (struct workqueue_struct *)(work->work_owner & ~(uintptr_t)1);
551} 564}
552 565
553/* 566/*
@@ -1516,13 +1529,25 @@ flush_delayed_work(struct delayed_work * @@ -1516,13 +1529,25 @@ flush_delayed_work(struct delayed_work *
1516 panic("invalid delayed work state: %d", dw->dw_state); 1529 panic("invalid delayed work state: %d", dw->dw_state);
1517 } 1530 }
1518 /* 1531 /*
1519 * Waiting for the whole queue to flush is overkill, 1532 * Waiting for the whole queue to flush is overkill,
1520 * but doesn't hurt. 1533 * but doesn't hurt.
1521 */ 1534 */
1522 flush_workqueue_locked(wq); 1535 flush_workqueue_locked(wq);
1523 waited = true; 1536 waited = true;
1524 } 1537 }
1525 mutex_exit(&wq->wq_lock); 1538 mutex_exit(&wq->wq_lock);
1526 1539
1527 return waited; 1540 return waited;
1528} 1541}
 1542
 1543/*
 1544 * delayed_work_pending(dw)
 1545 *
 1546 * True if dw is currently scheduled to execute, false if not.
 1547 */
 1548bool
 1549delayed_work_pending(struct delayed_work *dw)
 1550{
 1551
 1552 return work_pending(&dw->work);
 1553}