]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: stop abusing the nice field to detect a tasklet
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Mar 2021 14:54:11 +0000 (15:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 07:30:08 +0000 (08:30 +0100)
It's cleaner to use a flag from the task's state to detect a tasklet
and it's even cheaper. One of the best benefits is that this will
allow to get the nice field out of the common part since the tasklet
doesn't need it anymore. This commit uses the last task bit available
but that's temporary as the purpose of the change is to extend this.

include/haproxy/task-t.h
include/haproxy/task.h
src/task.c

index 632f4613a469731f8c028c604554c18790bb15f2..4661715396bd14c5ba300be75c187baa623c01df 100644 (file)
@@ -50,6 +50,8 @@
 #define TASK_WOKEN_RES    0x2000  /* woken up because of available resource */
 #define TASK_WOKEN_OTHER  0x4000  /* woken up for an unspecified reason */
 
+#define TASK_F_TASKLET    0x8000  /* nature of this task: 0=task 1=tasklet */
+
 /* use this to check a task state or to clean it up before queueing */
 #define TASK_WOKEN_ANY    (TASK_WOKEN_OTHER|TASK_WOKEN_INIT|TASK_WOKEN_TIMER| \
                            TASK_WOKEN_IO|TASK_WOKEN_SIGNAL|TASK_WOKEN_MSG| \
@@ -113,7 +115,7 @@ struct task_per_thread {
 #define TASK_COMMON                                                    \
        struct {                                                        \
                unsigned short state; /* task state : bitfield of TASK_ */ \
-               short nice; /* task prio from -1024 to +1024, or -32768 for tasklets */ \
+               short nice; /* task prio from -1024 to +1024 */ \
                unsigned int calls; /* number of times process was called */ \
                struct task *(*process)(struct task *t, void *ctx, unsigned short state); /* the function which processes the task */ \
                void *context; /* the task's context */                 \
index c717420f7700657ac139a0c952ca4f0569792a9a..8f70f5bb24620ed337a10f040a2a10a1b7ee4ca5 100644 (file)
@@ -83,7 +83,7 @@
 #define TIMER_LOOK_BACK       (1U << 31)
 
 /* tasklets are recognized with nice==-32768 */
-#define TASK_IS_TASKLET(t) ((t)->nice == -32768)
+#define TASK_IS_TASKLET(t) ((t)->state & TASK_F_TASKLET)
 
 
 /* a few exported variables */
@@ -435,15 +435,15 @@ static inline struct task *task_init(struct task *t, unsigned long thread_mask)
        return t;
 }
 
-/* Initialize a new tasklet. It's identified as a tasklet by ->nice=-32768. It
- * is expected to run on the calling thread by default, it's up to the caller
- * to change ->tid if it wants to own it.
+/* Initialize a new tasklet. It's identified as a tasklet by its flags
+ * TASK_F_TASKLET. It is expected to run on the calling thread by default,
+ * it's up to the caller to change ->tid if it wants to own it.
  */
 static inline void tasklet_init(struct tasklet *t)
 {
-       t->nice = -32768;
+       t->nice = 0;
        t->calls = 0;
-       t->state = 0;
+       t->state = TASK_F_TASKLET;
        t->process = NULL;
        t->tid = -1;
 #ifdef DEBUG_TASK
index 4c73b8cc551ea12a6f2c172e595a19487f7e88f4..350146d33b95d8cdcd6fea5e6f46cd17df5988ed 100644 (file)
@@ -487,7 +487,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
 
                budgets[queue]--;
                t = (struct task *)LIST_ELEM(tl_queues[queue].n, struct tasklet *, list);
-               state = t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING|TASK_HEAVY|TASK_KILLED);
+               state = t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING|TASK_HEAVY|TASK_F_TASKLET|TASK_KILLED);
 
                ti->flags &= ~TI_FL_STUCK; // this thread is still running
                activity[tid].ctxsw++;
@@ -498,7 +498,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
 
                _HA_ATOMIC_SUB(&sched->rq_total, 1);
 
-               if (TASK_IS_TASKLET(t)) {
+               if (state & TASK_F_TASKLET) {
                        uint64_t before = 0;
 
                        LIST_DEL_INIT(&((struct tasklet *)t)->list);