]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: thread/clock: move the clock parts of thread_info to thread_ctx
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 16:28:49 +0000 (18:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
The "thread_info" name was initially chosen to store all info about
threads but since we now have a separate per-thread context, there is
no point keeping some of its elements in the thread_info struct.

As such, this patch moves prev_cpu_time, prev_mono_time and idle_pct to
thread_ctx, into the thread context, with the scheduler parts. Instead
of accessing them via "ti->" we now access them via "th_ctx->", which
makes more sense as they're totally dynamic, and will be required for
future evolutions. There's no room problem for now, the structure still
has 84 bytes available at the end.

include/haproxy/tinfo-t.h
src/clock.c
src/compression.c
src/debug.c
src/flt_http_comp.c
src/wdt.c

index 3fde2695e2d69f17238a823fe1f37ec317aaaf9c..afbf191d46aa3e35da5ef00857055ff7cdd4c249 100644 (file)
@@ -42,9 +42,6 @@ enum {
  * disabled, it contains the same info for the single running thread.
  */
 struct thread_info {
-       uint64_t prev_cpu_time;    /* previous per thread CPU time */
-       uint64_t prev_mono_time;   /* previous system wide monotonic time  */
-       unsigned int idle_pct;     /* idle to total ratio over last sample (percent) */
        unsigned int flags;        /* thread info flags, TI_FL_* */
 
 #ifdef CONFIG_HAP_POOLS
@@ -82,6 +79,9 @@ struct thread_ctx {
        struct mt_list shared_tasklet_list; /* Tasklet to be run, woken up by other threads */
        unsigned int rq_total;              /* total size of the run queue, prio_tree + tasklets */
        int tasks_in_list;                  /* Number of tasks in the per-thread tasklets list */
+       uint64_t prev_cpu_time;             /* previous per thread CPU time */
+       uint64_t prev_mono_time;            /* previous system wide monotonic time  */
+       uint idle_pct;                      /* idle to total ratio over last sample (percent) */
        ALWAYS_ALIGN(128);
 };
 
index 33d7b4dee588b658330054a0615791d8bc615076..3b9e9ff64a4977cff597d7d8ca7b43fc5ca9042b 100644 (file)
@@ -247,7 +247,7 @@ void clock_init_process_date(void)
        now = after_poll = before_poll = date;
        global_now = ((ullong)date.tv_sec << 32) + (uint)date.tv_usec;
        global_now_ms = now.tv_sec * 1000 + now.tv_usec / 1000;
-       ti->idle_pct = 100;
+       th_ctx->idle_pct = 100;
        clock_update_date(0, 1);
 }
 
@@ -264,7 +264,7 @@ void clock_init_thread_date(void)
        old_now = _HA_ATOMIC_LOAD(&global_now);
        now.tv_sec = old_now >> 32;
        now.tv_usec = (uint)old_now;
-       ti->idle_pct = 100;
+       th_ctx->idle_pct = 100;
        clock_update_date(0, 1);
 }
 
@@ -278,7 +278,7 @@ uint clock_report_idle(void)
        for (thr = 0; thr < MAX_THREADS; thr++) {
                if (!(all_threads_mask & (1UL << thr)))
                        continue;
-               total += HA_ATOMIC_LOAD(&ha_thread_info[thr].idle_pct);
+               total += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].idle_pct);
                rthr++;
        }
        return rthr ? total / rthr : 0;
@@ -310,7 +310,7 @@ static inline void clock_measure_idle(void)
        if (samp_time < 500000)
                return;
 
-       HA_ATOMIC_STORE(&ti->idle_pct, (100ULL * idle_time + samp_time / 2) / samp_time);
+       HA_ATOMIC_STORE(&th_ctx->idle_pct, (100ULL * idle_time + samp_time / 2) / samp_time);
        idle_time = samp_time = 0;
 }
 
@@ -322,8 +322,8 @@ static inline void clock_measure_idle(void)
 void clock_leaving_poll(int timeout, int interrupted)
 {
        clock_measure_idle();
-       ti->prev_cpu_time  = now_cpu_time();
-       ti->prev_mono_time = now_mono_time();
+       th_ctx->prev_cpu_time  = now_cpu_time();
+       th_ctx->prev_mono_time = now_mono_time();
 }
 
 /* Collect date and time information before calling poll(). This will be used
@@ -346,9 +346,9 @@ void clock_entering_poll(void)
        new_cpu_time   = now_cpu_time();
        new_mono_time  = now_mono_time();
 
-       if (ti->prev_cpu_time && ti->prev_mono_time) {
-               new_cpu_time  -= ti->prev_cpu_time;
-               new_mono_time -= ti->prev_mono_time;
+       if (th_ctx->prev_cpu_time && th_ctx->prev_mono_time) {
+               new_cpu_time  -= th_ctx->prev_cpu_time;
+               new_mono_time -= th_ctx->prev_mono_time;
                stolen = new_mono_time - new_cpu_time;
                if (unlikely(stolen >= 500000)) {
                        stolen /= 500000;
index 7a7d90065e1f5cfc24e354d5f312d77c7d9aed19..8095ecb99f7bd0906c334f799617cb74f6875b86 100644 (file)
@@ -360,7 +360,7 @@ static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
 
        /* Verify compression rate limiting and CPU usage */
        if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) ||    /* rate */
-          (ti->idle_pct < compress_min_idle)) {                                                                 /* idle */
+          (th_ctx->idle_pct < compress_min_idle)) {                                                         /* idle */
                if (comp_ctx->cur_lvl > 0)
                        strm->level = --comp_ctx->cur_lvl;
        }
@@ -618,7 +618,7 @@ static int deflate_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
 
        /* compression limit */
        if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) ||    /* rate */
-          (ti->idle_pct < compress_min_idle)) {                                                                     /* idle */
+          (th_ctx->idle_pct < compress_min_idle)) {                                                         /* idle */
                /* decrease level */
                if (comp_ctx->cur_lvl > 0) {
                        comp_ctx->cur_lvl--;
index 51440946fec231d725cf3eda1983e835bf613af1..aafa378394c639056d3fe03bdb46b6ca24ae78ab 100644 (file)
@@ -150,7 +150,7 @@ void ha_backtrace_to_stderr()
 void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
 {
        unsigned long thr_bit = 1UL << thr;
-       unsigned long long p = ha_thread_info[thr].prev_cpu_time;
+       unsigned long long p = ha_thread_ctx[thr].prev_cpu_time;
        unsigned long long n = now_cpu_time_thread(thr);
        int stuck = !!(ha_thread_info[thr].flags & TI_FL_STUCK);
 
index 774b982e4ef7e0a43c4619504dc729e0e6d42797..9d8c3fa6402ea54a60c6ed6f50926af4158f622e 100644 (file)
@@ -564,7 +564,7 @@ select_compression_response_header(struct comp_state *st, struct stream *s, stru
                        goto fail;
 
        /* limit cpu usage */
-       if (ti->idle_pct < compress_min_idle)
+       if (th_ctx->idle_pct < compress_min_idle)
                goto fail;
 
        /* initialize compression */
index 96db84bd9b187b02a1719187ab01f2f0bbe45bfd..b789fbeae9d97e2f26c89c63b572ed18245a86bd 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -71,7 +71,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
                if (thr < 0 || thr >= global.nbthread)
                        break;
 
-               p = ha_thread_info[thr].prev_cpu_time;
+               p = ha_thread_ctx[thr].prev_cpu_time;
                n = now_cpu_time_thread(thr);
 
                /* not yet reached the deadline of 1 sec */