Skip to content

Commit 12fcd65

Browse files
committed
MINOR: tasklet: support an optional set of wakeup flags to tasklet_wakeup_on()
tasklet_wakeup_on() and its derivates (tasklet_wakeup_after() and tasklet_wakeup()) do not support passing a wakeup cause like task_wakeup(). This is essentially due to an API limitation cause by the fact that for a very long time the only reason for waking up was to process pending I/O. But with the growing complexity of mux tasks, it is becoming important to be able to skip certain heavy processing when not strictly needed. One possibility is to permit the caller of tasklet_wakeup() to pass flags like task_wakeup(). Instead of going with a complex naming scheme, let's simply make the flags optional and be zero when not specified. This means that tasklet_wakeup_on() now takes either 2 or 3 args, and that the third one is the optional flags to be passed to the callee. Eligible flags are essentially the non-persistent ones (TASK_F_UEVT* and TASK_WOKEN_*) which are cleared when the tasklet is executed. This way the handler will find them in its <state> argument and will be able to distinguish various causes for the call.
1 parent 0334cb2 commit 12fcd65

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

doc/internals/api/scheduler.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ void task_set_thread(t, id)
9898
indicate "any thread". It's ignored and replaced by zero when threads
9999
are disabled.
100100

101-
void tasklet_wakeup(tl)
101+
void tasklet_wakeup(tl, [flags])
102102
Make sure that tasklet <tl> will wake up, that is, will execute at
103103
least once. The tasklet will run on its assigned thread, or on any
104-
thread if its TID is negative.
104+
thread if its TID is negative. An optional <flags> value may be passed
105+
to set a wakeup cause on the tasklet's flags, typically TASK_WOKEN_* or
106+
TASK_F_UEVT*. When not set, 0 is passed (i.e. no flags are changed).
105107

106-
struct list *tasklet_wakeup_after(head, tl)
108+
struct list *tasklet_wakeup_after(head, tl, [flags])
107109
Schedule tasklet <tl> to run immediately the current one if <head> is
108110
NULL, or after the last queued one if <head> is non-null. The new head
109111
is returned, to be passed to the next call. The purpose here is to
@@ -113,15 +115,20 @@ struct list *tasklet_wakeup_after(head, tl)
113115
already queued tasklets. This may induce extra latencies for pending
114116
jobs and must only be used extremely carefully when it's certain that
115117
the processing will benefit from using fresh data from the L1 cache.
118+
An optional <flags> value may be passed to set a wakeup cause on the
119+
tasklet's flags, typically TASK_WOKEN_* or TASK_F_UEVT*. When not set,
120+
0 is passed (i.e. no flags are changed).
116121

117-
void tasklet_wakeup_on(tl, thr)
122+
void tasklet_wakeup_on(tl, thr, [flags])
118123
Make sure that tasklet <tl> will wake up on thread <thr>, that is, will
119124
execute at least once. The designated thread may only differ from the
120125
calling one if the tasklet is already configured to run on another
121126
thread, and it is not permitted to self-assign a tasklet if its tid is
122127
negative, as it may already be scheduled to run somewhere else. Just in
123128
case, only use tasklet_wakeup() which will pick the tasklet's assigned
124-
thread ID.
129+
thread ID. An optional <flags> value may be passed to set a wakeup
130+
cause on the tasklet's flags, typically TASK_WOKEN_* or TASK_F_UEVT*.
131+
When not set, 0 is passed (i.e. no flags are changed).
125132

126133
struct tasklet *tasklet_new()
127134
Allocate a new tasklet and set it to run by default on the calling

include/haproxy/task.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,14 @@ static inline void task_set_thread(struct task *t, int thr)
373373
* at least once scheduled on a specific thread. With DEBUG_TASK, the
374374
* <file>:<line> from the call place are stored into the tasklet for tracing
375375
* purposes.
376+
*
377+
* The macro accepts an optional 3rd argument that is passed as a set of flags
378+
* to be set on the tasklet, among TASK_WOKEN_*, TASK_F_UEVT* etc to indicate a
379+
* wakeup cause to the tasklet. When not set, the arg defaults to zero (i.e. no
380+
* flag is added).
376381
*/
377-
#define tasklet_wakeup_on(tl, thr) \
378-
_tasklet_wakeup_on(tl, thr, 0, MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP, 0, 0))
382+
#define tasklet_wakeup_on(tl, thr, ...) \
383+
_tasklet_wakeup_on(tl, thr, DEFZERO(__VA_ARGS__), MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP, 0, 0))
379384

380385
static inline void _tasklet_wakeup_on(struct tasklet *tl, int thr, uint f, const struct ha_caller *caller)
381386
{
@@ -405,9 +410,14 @@ static inline void _tasklet_wakeup_on(struct tasklet *tl, int thr, uint f, const
405410
* is either its owner thread if >= 0 or the current thread if < 0. When
406411
* DEBUG_TASK is set, the <file>:<line> from the call place are stored into the
407412
* task for tracing purposes.
413+
*
414+
* The macro accepts an optional 3rd argument that is passed as a set of flags
415+
* to be set on the tasklet, among TASK_WOKEN_*, TASK_F_UEVT* etc to indicate a
416+
* wakeup cause to the tasklet. When not set, the arg defaults to zero (i.e. no
417+
* flag is added).
408418
*/
409-
#define tasklet_wakeup(tl) \
410-
_tasklet_wakeup_on(tl, (tl)->tid, 0, MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP, 0, 0))
419+
#define tasklet_wakeup(tl, ...) \
420+
_tasklet_wakeup_on(tl, (tl)->tid, DEFZERO(__VA_ARGS__), MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP, 0, 0))
411421

412422
/* instantly wakes up task <t> on its owner thread even if it's not the current
413423
* one, bypassing the run queue. The purpose is to be able to avoid contention
@@ -466,9 +476,14 @@ static inline void _task_instant_wakeup(struct task *t, unsigned int f, const st
466476
* thread will be used.
467477
* With DEBUG_TASK, the <file>:<line> from the call place are stored into the tasklet
468478
* for tracing purposes.
479+
*
480+
* The macro accepts an optional 3rd argument that is passed as a set of flags
481+
* to be set on the tasklet, among TASK_WOKEN_*, TASK_F_UEVT* etc to indicate a
482+
* wakeup cause to the tasklet. When not set, the arg defaults to zero (i.e. no
483+
* flag is added).
469484
*/
470-
#define tasklet_wakeup_after(head, tl) \
471-
_tasklet_wakeup_after(head, tl, 0, MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP_AFTER, 0, 0))
485+
#define tasklet_wakeup_after(head, tl, ...) \
486+
_tasklet_wakeup_after(head, tl, DEFZERO(__VA_ARGS__), MK_CALLER(WAKEUP_TYPE_TASKLET_WAKEUP_AFTER, 0, 0))
472487

473488
static inline struct list *_tasklet_wakeup_after(struct list *head, struct tasklet *tl,
474489
uint f, const struct ha_caller *caller)

0 commit comments

Comments
 (0)