From: Willy Tarreau Date: Fri, 9 Sep 2022 14:19:33 +0000 (+0200) Subject: MINOR: flags/task: use flag dumping for task state X-Git-Tag: v2.7-dev6~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92a2d3c02bc653704c04bfd32500f1a375766973;p=thirdparty%2Fhaproxy.git MINOR: flags/task: use flag dumping for task state The new function is task_show_state(). --- diff --git a/dev/flags/flags.c b/dev/flags/flags.c index 46936a385a..c24bde889a 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -84,33 +84,8 @@ void show_strm_et(unsigned int f) void show_task_state(unsigned int f) { - printf("task->state = "); - - if (!f) { - printf("TASK_SLEEPING\n"); - return; - } - - SHOW_FLAG(f, TASK_F_USR1); - SHOW_FLAG(f, TASK_F_TASKLET); - SHOW_FLAG(f, TASK_WOKEN_OTHER); - SHOW_FLAG(f, TASK_WOKEN_RES); - SHOW_FLAG(f, TASK_WOKEN_MSG); - SHOW_FLAG(f, TASK_WOKEN_SIGNAL); - SHOW_FLAG(f, TASK_WOKEN_IO); - SHOW_FLAG(f, TASK_WOKEN_TIMER); - SHOW_FLAG(f, TASK_WOKEN_INIT); - SHOW_FLAG(f, TASK_HEAVY); - SHOW_FLAG(f, TASK_IN_LIST); - SHOW_FLAG(f, TASK_KILLED); - SHOW_FLAG(f, TASK_SELF_WAKING); - SHOW_FLAG(f, TASK_QUEUED); - SHOW_FLAG(f, TASK_RUNNING); - - if (f) { - printf("EXTRA(0x%08x)", f); - } - putchar('\n'); + task_show_state(tmpbuf, sizeof(tmpbuf), " | ", f); + printf("task->state = %s\n", tmpbuf); } void show_txn_flags(unsigned int f) diff --git a/include/haproxy/task-t.h b/include/haproxy/task-t.h index 06d7f225cf..4dd10f438d 100644 --- a/include/haproxy/task-t.h +++ b/include/haproxy/task-t.h @@ -27,9 +27,12 @@ #include #include +#include #include -/* values for task->state (32 bits) */ +/* values for task->state (32 bits). + * Please also update the task_show_state() function below in case of changes. + */ #define TASK_SLEEPING 0x00000000 /* task sleeping */ #define TASK_RUNNING 0x00000001 /* the task is currently running */ /* unused 0x00000002 */ @@ -61,6 +64,27 @@ #define TASK_PERSISTENT (TASK_SELF_WAKING | TASK_KILLED | \ TASK_HEAVY | TASK_F_TASKLET | TASK_F_USR1) +/* This function is used to report state in debugging tools. Please reflect + * below any single-bit flag addition above in the same order via the + * __APPEND_FLAG macro. The new end of the buffer is returned. + */ +static forceinline char *task_show_state(char *buf, size_t len, const char *delim, uint flg) +{ +#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__) + /* prologue */ + _(0); + /* flags */ + _(TASK_RUNNING, _(TASK_QUEUED, _(TASK_SELF_WAKING, + _(TASK_KILLED, _(TASK_IN_LIST, _(TASK_HEAVY, _(TASK_WOKEN_INIT, + _(TASK_WOKEN_TIMER, _(TASK_WOKEN_IO, _(TASK_WOKEN_SIGNAL, + _(TASK_WOKEN_MSG, _(TASK_WOKEN_RES, _(TASK_WOKEN_OTHER, + _(TASK_F_TASKLET, _(TASK_F_USR1))))))))))))))); + /* epilogue */ + _(~0U); + return buf; +#undef _ +} + /* these wakeup types are used to indicate how a task/tasklet was woken up, for * debugging purposes. */