]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/task: use flag dumping for task state
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:19:33 +0000 (16:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:52:09 +0000 (16:52 +0200)
The new function is task_show_state().

dev/flags/flags.c
include/haproxy/task-t.h

index 46936a385a33cd78e58c601b36e7857caed87e17..c24bde889a15e8c7d06a6f45b247bf1717944058 100644 (file)
@@ -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)
index 06d7f225cf36cca6782bc72d3832cf2074ff5d4a..4dd10f438d6de7f2eb1b3f4a492c16412a27fc23 100644 (file)
 #include <import/ebtree-t.h>
 
 #include <haproxy/api-t.h>
+#include <haproxy/show_flags-t.h>
 #include <haproxy/thread-t.h>
 
-/* 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 */
 #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.
  */