]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: time: uninline report_idle() and move it to task.c
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 06:52:11 +0000 (08:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Oct 2021 16:37:50 +0000 (18:37 +0200)
I don't know why I inlined this one, this makes no sense given that it's
only used for stats, and it starts a circular dependency on tinfo.h which
can be problematic in the future. In addition, all the stuff related to
idle time calculation should be with the rest of the scheduler, which
currently is in task.{c,h}, so let's move it there.

include/haproxy/task.h
include/haproxy/time.h
src/stats.c
src/task.c

index 7b9b4e625bf764c403b3a8178e06512a8f89990d..f7aebedf494d36fa92a6bd799af373ca279504f0 100644 (file)
@@ -110,6 +110,9 @@ void task_kill(struct task *t);
 void tasklet_kill(struct tasklet *t);
 void __task_wakeup(struct task *t);
 void __task_queue(struct task *task, struct eb_root *wq);
+
+uint sched_report_idle();
+
 unsigned int run_tasks_from_lists(unsigned int budgets[]);
 
 /*
index e9baab418b952850706228eb9f6597769e891c79..ad3a1dbfd1f7597bdd50b2ab3e96a8c3f7c1b61f 100644 (file)
@@ -581,22 +581,6 @@ static inline void measure_idle()
        idle_time = samp_time = 0;
 }
 
-/* report the average CPU idle percentage over all running threads, between 0 and 100 */
-static inline uint report_idle()
-{
-       uint total = 0;
-       uint rthr = 0;
-       uint thr;
-
-       for (thr = 0; thr < MAX_THREADS; thr++) {
-               if (!(all_threads_mask & (1UL << thr)))
-                       continue;
-               total += HA_ATOMIC_LOAD(&ha_thread_info[thr].idle_pct);
-               rthr++;
-       }
-       return rthr ? total / rthr : 0;
-}
-
 /* Collect date and time information before calling poll(). This will be used
  * to count the run time of the past loop and the sleep time of the next poll.
  */
index 99efac0b396c13929ae01f7e6e34a1e652697bf6..8cc3bad692a4a0ad8e3102e2deb76d148b4f8f61 100644 (file)
@@ -3446,7 +3446,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
                      actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
                      bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0),
                      bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k',
-                     total_run_queues(), total_allocated_tasks(), report_idle()
+                     total_run_queues(), total_allocated_tasks(), sched_report_idle()
                      );
 
        /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
@@ -4479,7 +4479,7 @@ int stats_fill_info(struct field *info, int len, uint flags)
 #endif
        info[INF_TASKS]                          = mkf_u32(0, total_allocated_tasks());
        info[INF_RUN_QUEUE]                      = mkf_u32(0, total_run_queues());
-       info[INF_IDLE_PCT]                       = mkf_u32(FN_AVG, report_idle());
+       info[INF_IDLE_PCT]                       = mkf_u32(FN_AVG, sched_report_idle());
        info[INF_NODE]                           = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node);
        if (global.desc)
                info[INF_DESCRIPTION]            = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
index 2d063d91b0825429b1d7f6ad90d0d6372f4fdf19..ce544c12dee5bb5b1988063070016050b51e57e8 100644 (file)
@@ -859,6 +859,22 @@ void process_runnable_tasks()
                activity[tid].long_rq++;
 }
 
+/* report the average CPU idle percentage over all running threads, between 0 and 100 */
+uint sched_report_idle()
+{
+       uint total = 0;
+       uint rthr = 0;
+       uint thr;
+
+       for (thr = 0; thr < MAX_THREADS; thr++) {
+               if (!(all_threads_mask & (1UL << thr)))
+                       continue;
+               total += HA_ATOMIC_LOAD(&ha_thread_info[thr].idle_pct);
+               rthr++;
+       }
+       return rthr ? total / rthr : 0;
+}
+
 /*
  * Delete every tasks before running the master polling loop
  */