]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: time: move the cpu, mono, and idle time to thread_info
authorWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 17:24:50 +0000 (19:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 19:14:14 +0000 (21:14 +0200)
These ones are useful across all threads and would be better placed
in struct thread_info than thread-local. There are very few users.

include/common/hathreads.h
include/common/time.h
include/proto/activity.h
src/compression.c
src/flt_http_comp.c
src/stats.c
src/time.c

index b3c45641ff21a980331032d7c395103df1f5c444..1042c26b6836926f13599c56a9c15764bc3a917e 100644 (file)
@@ -51,6 +51,9 @@ enum { tid = 0 };
 
 extern struct thread_info {
        clockid_t clock_id;
+       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) */
        /* pad to cache line (64B) */
        char __pad[0];            /* unused except to check remaining room */
        char __end[0] __attribute__((aligned(64)));
@@ -382,6 +385,9 @@ void thread_release();
 extern struct thread_info {
        pthread_t pthread;
        clockid_t clock_id;
+       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) */
        /* pad to cache line (64B) */
        char __pad[0];            /* unused except to check remaining room */
        char __end[0] __attribute__((aligned(64)));
index 42bc9579acdf1e056d5ac35420d8d498660ac534..0790873272c965a1b504de63a6b5b5fb3f586340 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <common/config.h>
+#include <common/hathreads.h>
 #include <common/standard.h>
 
 /* eternity when exprimed in timeval */
@@ -57,14 +58,11 @@ extern THREAD_LOCAL unsigned int   curr_sec_ms_scaled;  /* millisecond of curren
 extern THREAD_LOCAL unsigned int   now_ms;           /* internal date in milliseconds (may wrap) */
 extern THREAD_LOCAL unsigned int   samp_time;        /* total elapsed time over current sample */
 extern THREAD_LOCAL unsigned int   idle_time;        /* total idle time over current sample */
-extern THREAD_LOCAL unsigned int   idle_pct;         /* idle to total ratio over last sample (percent) */
 extern THREAD_LOCAL struct timeval now;              /* internal date is a monotonic function of real clock */
 extern THREAD_LOCAL struct timeval date;             /* the real current date */
 extern struct timeval start_date;       /* the process's start date */
 extern THREAD_LOCAL struct timeval before_poll;      /* system date before calling poll() */
 extern THREAD_LOCAL struct timeval after_poll;       /* system date after leaving poll() */
-extern THREAD_LOCAL uint64_t prev_cpu_time;          /* previous per thread CPU time */
-extern THREAD_LOCAL uint64_t prev_mono_time;         /* previous system wide monotonic time */
 
 
 /**** exported functions *************************************************/
@@ -567,7 +565,7 @@ static inline void measure_idle()
        if (samp_time < 500000)
                return;
 
-       idle_pct = (100 * idle_time + samp_time / 2) / samp_time;
+       ti->idle_pct = (100 * idle_time + samp_time / 2) / samp_time;
        idle_time = samp_time = 0;
 }
 
@@ -587,8 +585,8 @@ static inline void tv_entering_poll()
 static inline void tv_leaving_poll(int timeout, int interrupted)
 {
        measure_idle();
-       prev_cpu_time  = now_cpu_time();
-       prev_mono_time = now_mono_time();
+       ti->prev_cpu_time  = now_cpu_time();
+       ti->prev_mono_time = now_mono_time();
 }
 
 #endif /* _COMMON_TIME_H */
index dd783448fbdd27a7d29892fb420ac37065c203c8..673d274578db4d01cd35f3f6dc063f5bc121a890 100644 (file)
@@ -63,9 +63,9 @@ static inline void activity_count_runtime()
        new_cpu_time   = now_cpu_time();
        new_mono_time  = now_mono_time();
 
-       if (prev_cpu_time && prev_mono_time) {
-               new_cpu_time  -= prev_cpu_time;
-               new_mono_time -= prev_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;
                stolen = new_mono_time - new_cpu_time;
                if (unlikely(stolen >= 500000)) {
                        stolen /= 500000;
index 11e09d8085ea94d6cfc015c7b59d35287fa59692..413a9d81b5e469f78171e9a3c2d52b0b84983390 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 */
-          (idle_pct < compress_min_idle)) {                                                                 /* idle */
+          (ti->idle_pct < compress_min_idle)) {                                                                 /* idle */
                if (comp_ctx->cur_lvl > 0)
                        strm->level = --comp_ctx->cur_lvl;
        }
@@ -613,7 +613,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 */
-          (idle_pct < compress_min_idle)) {                                                                     /* idle */
+          (ti->idle_pct < compress_min_idle)) {                                                                     /* idle */
                /* decrease level */
                if (comp_ctx->cur_lvl > 0) {
                        comp_ctx->cur_lvl--;
index 6cad8e1b9008381a7dbd8f9bce834f8ad1d635bb..63873d092a6b7df4140d838bb62c31f12e07a866 100644 (file)
@@ -929,7 +929,7 @@ http_select_comp_reshdr(struct comp_state *st, struct stream *s, struct http_msg
                        goto fail;
 
        /* limit cpu usage */
-       if (idle_pct < compress_min_idle)
+       if (ti->idle_pct < compress_min_idle)
                goto fail;
 
        /* initialize compression */
@@ -1040,7 +1040,7 @@ htx_select_comp_reshdr(struct comp_state *st, struct stream *s, struct http_msg
                        goto fail;
 
        /* limit cpu usage */
-       if (idle_pct < compress_min_idle)
+       if (ti->idle_pct < compress_min_idle)
                goto fail;
 
        /* initialize compression */
index dc57e857e4ad938a511a43c2095b0758a3262311..0fef81650502e6c9b55aa647868be1d01d533257 100644 (file)
@@ -2433,7 +2433,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
                      global.rlimit_nofile,
                      global.maxsock, global.maxconn, global.maxpipes,
                      actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
-                     tasks_run_queue_cur, nb_tasks_cur, idle_pct
+                     tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct
                      );
 
        /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
@@ -3643,7 +3643,7 @@ int stats_fill_info(struct field *info, int len)
 #endif
        info[INF_TASKS]                          = mkf_u32(0, nb_tasks_cur);
        info[INF_RUN_QUEUE]                      = mkf_u32(0, tasks_run_queue_cur);
-       info[INF_IDLE_PCT]                       = mkf_u32(FN_AVG, idle_pct);
+       info[INF_IDLE_PCT]                       = mkf_u32(FN_AVG, ti->idle_pct);
        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 94b498cbca048cd9d430ec423ebb6d933dd1eb6c..187f051424a90a017ce303d1ba927c7b3c0ae5e4 100644 (file)
@@ -23,14 +23,11 @@ THREAD_LOCAL unsigned int   ms_left_scaled;  /* milliseconds left for current se
 THREAD_LOCAL unsigned int   now_ms;          /* internal date in milliseconds (may wrap) */
 THREAD_LOCAL unsigned int   samp_time;       /* total elapsed time over current sample */
 THREAD_LOCAL unsigned int   idle_time;       /* total idle time over current sample */
-THREAD_LOCAL unsigned int   idle_pct;        /* idle to total ratio over last sample (percent) */
 THREAD_LOCAL struct timeval now;             /* internal date is a monotonic function of real clock */
 THREAD_LOCAL struct timeval date;            /* the real current date */
 struct timeval start_date;      /* the process's start date */
 THREAD_LOCAL struct timeval before_poll;     /* system date before calling poll() */
 THREAD_LOCAL struct timeval after_poll;      /* system date after leaving poll() */
-THREAD_LOCAL uint64_t prev_cpu_time = 0;     /* previous per thread CPU time */
-THREAD_LOCAL uint64_t prev_mono_time = 0;    /* previous system wide monotonic time */
 
 static THREAD_LOCAL struct timeval tv_offset;  /* per-thread time ofsset relative to global time */
 volatile unsigned long long global_now;        /* common date between all threads (32:32) */
@@ -188,7 +185,7 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted)
                adjusted = date;
                after_poll = date;
                samp_time = idle_time = 0;
-               idle_pct = 100;
+               ti->idle_pct = 100;
                global_now = (((unsigned long long)adjusted.tv_sec) << 32) +
                             (unsigned int)adjusted.tv_usec;
                goto to_ms;