]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity: get the run_time from the clock updates
authorWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 09:34:46 +0000 (11:34 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
Instead of fiddling with before_poll and after_poll in
activity_count_runtime(), the function is now called by
clock_entering_poll() which passes it the number of microseconds
spent working. This allows to remove all calls to
activity_count_runtime() from the pollers.

include/haproxy/activity.h
src/activity.c
src/clock.c
src/ev_epoll.c
src/ev_evports.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c

index 42b0c8793f66d6ddad1754939a7fdd6b67e9a268..f0ca4eea15c42273396cfa4b1bfcd95c840f3ab5 100644 (file)
@@ -31,7 +31,7 @@ extern struct activity activity[MAX_THREADS];
 extern struct sched_activity sched_activity[256];
 
 void report_stolen_time(uint64_t stolen);
-void activity_count_runtime();
+void activity_count_runtime(uint32_t run_time);
 struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func);
 
 #endif /* _HAPROXY_ACTIVITY_H */
index a2d31898c278ab53dbed4c9c373f85b1c24471d1..a4527f2db7a38183e511044532639035507ce7db 100644 (file)
@@ -349,14 +349,13 @@ void report_stolen_time(uint64_t stolen)
        update_freq_ctr_period(&activity[tid].cpust_15s, 15000, stolen);
 }
 
-/* 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.
- * It also makes use of the just updated before_poll timer to count the loop's
- * run time and feed the average loop time metric (in microseconds).
+/* Update avg_loop value for the current thread and possibly decide to enable
+ * task-level profiling on the current thread based on its average run time.
+ * The <run_time> argument is the number of microseconds elapsed since the
+ * last time poll() returned.
  */
-void activity_count_runtime()
+void activity_count_runtime(uint32_t run_time)
 {
-       uint32_t run_time;
        uint32_t up, down;
 
        /* 1 millisecond per loop on average over last 1024 iterations is
@@ -365,7 +364,6 @@ void activity_count_runtime()
        up = 1000;
        down = up * 99 / 100;
 
-       run_time = (before_poll.tv_sec - after_poll.tv_sec) * 1000000U + (before_poll.tv_usec - after_poll.tv_usec);
        run_time = swrate_add(&activity[tid].avg_loop_us, TIME_STATS_SAMPLES, run_time);
 
        /* In automatic mode, reaching the "up" threshold on average switches
index f68830efbeba910503d09744b09f64cefde9dc05..cd5ead7b44ddaab1dbcc99fe32fa64b1aeb6c8a1 100644 (file)
@@ -283,10 +283,13 @@ void clock_entering_poll(void)
 {
        uint64_t new_mono_time;
        uint64_t new_cpu_time;
+       uint32_t run_time;
        int64_t stolen;
 
        gettimeofday(&before_poll, NULL);
 
+       run_time = (before_poll.tv_sec - after_poll.tv_sec) * 1000000U + (before_poll.tv_usec - after_poll.tv_usec);
+
        new_cpu_time   = now_cpu_time();
        new_mono_time  = now_mono_time();
 
@@ -302,6 +305,9 @@ void clock_entering_poll(void)
                        report_stolen_time(stolen);
                }
        }
+
+       /* update the average runtime */
+       activity_count_runtime(run_time);
 }
 
 /* returns the current date as returned by gettimeofday() in ISO+microsecond
index a9b572b2ebadbd6042f160e796679f63b9b4f358..1babe56c2345759a3dd7e7a74abaff4e71638db3 100644 (file)
@@ -190,7 +190,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
        /* now let's wait for polled events */
        wait_time = wake ? 0 : compute_poll_timeout(exp);
        clock_entering_poll();
-       activity_count_runtime();
        do {
                int timeout = (global.tune.options & GTUNE_BUSY_POLLING) ? 0 : wait_time;
 
index dcc30a195959bb7800e9496a45596b99ba0f2f93..710d512367d7bd662d49a4864d7d1bc1ee9b519d 100644 (file)
@@ -160,7 +160,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
         */
        wait_time = wake ? 0 : compute_poll_timeout(exp);
        clock_entering_poll();
-       activity_count_runtime();
 
        do {
                int timeout = (global.tune.options & GTUNE_BUSY_POLLING) ? 0 : wait_time;
index c9f355b93f197266dc4b2601fd976ddd09084bdc..1bd79fd697cdc0d6cf7acd268b21d1a89bc5ffc0 100644 (file)
@@ -147,7 +147,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
        wait_time = wake ? 0 : compute_poll_timeout(exp);
        fd = global.tune.maxpollevents;
        clock_entering_poll();
-       activity_count_runtime();
 
        do {
                int timeout = (global.tune.options & GTUNE_BUSY_POLLING) ? 0 : wait_time;
index dbfa26269d872a53923c4625111c0bce02e26920..5cfdff112bfc422bcc740966684b836dd698d4fd 100644 (file)
@@ -203,7 +203,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
        /* now let's wait for events */
        wait_time = wake ? 0 : compute_poll_timeout(exp);
        clock_entering_poll();
-       activity_count_runtime();
        status = poll(poll_events, nbfd, wait_time);
        clock_update_date(wait_time, status);
        clock_leaving_poll(wait_time, status);
index 87a926d8464295a9668e81218d85116b017ab424..3c8471fcde68d3c7a9c776f9a3a9766915480de4 100644 (file)
@@ -174,7 +174,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
        delta.tv_sec  = (delta_ms / 1000);
        delta.tv_usec = (delta_ms % 1000) * 1000;
        clock_entering_poll();
-       activity_count_runtime();
        status = select(maxfd,
                        readnotnull ? tmp_evts[DIR_RD] : NULL,
                        writenotnull ? tmp_evts[DIR_WR] : NULL,