]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: sched: move the stolen CPU time detection to sched_entering_poll()
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 16:20:30 +0000 (18:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Oct 2021 16:37:51 +0000 (18:37 +0200)
That's where that code initially was but it had been moved to
activity_count_runtime() for pure reasons of dependency loops. These
ones are no longer true so we can move that code back to the scheduler
and keep it where the information are updated and checked.

include/haproxy/activity.h
include/haproxy/task.h

index 66a5f3be7ebdc5061c3815d1b8bfc0c0cdc3b4ad..28f8689a4e6cc82c22e24da90d1ce8c5cd85fe15 100644 (file)
@@ -42,9 +42,6 @@ void report_stolen_time(uint64_t stolen);
  */
 static inline void activity_count_runtime()
 {
-       uint64_t new_mono_time;
-       uint64_t new_cpu_time;
-       int64_t stolen;
        uint32_t run_time;
        uint32_t up, down;
 
@@ -54,22 +51,6 @@ static inline void activity_count_runtime()
        up = 1000;
        down = up * 99 / 100;
 
-       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;
-               stolen = new_mono_time - new_cpu_time;
-               if (unlikely(stolen >= 500000)) {
-                       stolen /= 500000;
-                       /* more than half a millisecond difference might
-                        * indicate an undesired preemption.
-                        */
-                       report_stolen_time(stolen);
-               }
-       }
-
        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);
 
index a38573771d1eb53efa1bf87a8904554b28184f7f..1020eea4d32fc1545a7e06bd76c63f03fa07de51 100644 (file)
@@ -658,10 +658,33 @@ static inline void sched_leaving_poll(int timeout, int interrupted)
 
 /* 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 compares the elasped and cpu times during the activity period to
+ * estimate the amount of stolen time, which is reported if higher than half
+ * a millisecond.
  */
 static inline void sched_entering_poll()
 {
+       uint64_t new_mono_time;
+       uint64_t new_cpu_time;
+       int64_t stolen;
+
        gettimeofday(&before_poll, NULL);
+
+       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;
+               stolen = new_mono_time - new_cpu_time;
+               if (unlikely(stolen >= 500000)) {
+                       stolen /= 500000;
+                       /* more than half a millisecond difference might
+                        * indicate an undesired preemption.
+                        */
+                       report_stolen_time(stolen);
+               }
+       }
 }
 
 /* This function register a new signal. "lua" is the current lua