init: add global 'warned' state
authorJens Axboe <axboe@kernel.dk>
Mon, 12 Feb 2018 17:11:31 +0000 (10:11 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 12 Feb 2018 17:11:31 +0000 (10:11 -0700)
In various places we spew a warning if some static variable
isn't set, but this still means it can happen once per job.
Add some global state to allow to track this globally instead.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
debug.h
init.c

diff --git a/debug.h b/debug.h
index e3aa3f183875ba37a67d80542d7afd110325f6ea..68a5adca268e6b331433ffa58183c44b3b45ed67 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -2,6 +2,7 @@
 #define FIO_DEBUG_H
 
 #include <assert.h>
 #define FIO_DEBUG_H
 
 #include <assert.h>
+#include "lib/types.h"
 #include "log.h"
 
 enum {
 #include "log.h"
 
 enum {
@@ -26,7 +27,17 @@ enum {
        FD_DEBUG_MAX,
 };
 
        FD_DEBUG_MAX,
 };
 
-extern unsigned int fio_debug_jobno, *fio_debug_jobp;
+extern unsigned int fio_debug_jobno, *fio_debug_jobp, *fio_warned;
+
+static inline bool fio_did_warn(unsigned int mask)
+{
+       if (!(*fio_warned & mask)) {
+               *fio_warned |= mask;
+               return true;
+       }
+
+       return false;
+}
 
 #ifdef FIO_INC_DEBUG
 struct debug_level {
 
 #ifdef FIO_INC_DEBUG
 struct debug_level {
diff --git a/init.c b/init.c
index 25661bef6e72fa3dadede80073d2dcef9eabd6ad..28061db8ea8f9a51d8e884c317ee3fc4309e11b1 100644 (file)
--- a/init.c
+++ b/init.c
@@ -79,6 +79,7 @@ static int prev_group_jobs;
 unsigned long fio_debug = 0;
 unsigned int fio_debug_jobno = -1;
 unsigned int *fio_debug_jobp = NULL;
 unsigned long fio_debug = 0;
 unsigned int fio_debug_jobno = -1;
 unsigned int *fio_debug_jobp = NULL;
+unsigned int *fio_warned = NULL;
 
 static char cmd_optstr[256];
 static bool did_arg;
 
 static char cmd_optstr[256];
 static bool did_arg;
@@ -309,6 +310,7 @@ static void free_shm(void)
        if (threads) {
                flow_exit();
                fio_debug_jobp = NULL;
        if (threads) {
                flow_exit();
                fio_debug_jobp = NULL;
+               fio_warned = NULL;
                free_threads_shm();
        }
 
                free_threads_shm();
        }
 
@@ -341,7 +343,7 @@ static int setup_thread_area(void)
        do {
                size_t size = max_jobs * sizeof(struct thread_data);
 
        do {
                size_t size = max_jobs * sizeof(struct thread_data);
 
-               size += sizeof(unsigned int);
+               size += 2 * sizeof(unsigned int);
 
 #ifndef CONFIG_NO_SHM
                shm_id = shmget(0, size, IPC_CREAT | 0600);
 
 #ifndef CONFIG_NO_SHM
                shm_id = shmget(0, size, IPC_CREAT | 0600);
@@ -376,6 +378,8 @@ static int setup_thread_area(void)
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
        fio_debug_jobp = (unsigned int *)(threads + max_jobs);
        *fio_debug_jobp = -1;
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
        fio_debug_jobp = (unsigned int *)(threads + max_jobs);
        *fio_debug_jobp = -1;
+       fio_warned = fio_debug_jobp + 1;
+       *fio_warned = 0;
 
        flow_init();
 
 
        flow_init();