xen: credit2: fix two s_time_t handling issues in load balancing
authorDario Faggioli <dario.faggioli@citrix.com>
Wed, 20 Jul 2016 09:50:12 +0000 (10:50 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 20 Jul 2016 10:08:34 +0000 (11:08 +0100)
both introduced in d205f8a7f48e2ec ("xen: credit2: rework
load tracking logic").

First, in __update_runq_load(), the ASSERT() was actually
useless. Let's instead check that the computed value of
the load has not overflowed (and hence gone negative).

While there, do that in __update_svc_load() as well.

Second, in balance_load(), cpus_max needs being extended
in order to be correctly shifted, and the result compared
with an s_time_t value, without risking loosing info.

Spotted by Coverity.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/common/sched_credit2.c

index 3e1720c6fcb29a6c33a36498a76d7ff02e3be67d..b92226c66e7a24afb21661afe67b2903f1ee1473 100644 (file)
@@ -730,7 +730,8 @@ __update_runq_load(const struct scheduler *ops,
     rqd->load += change;
     rqd->load_last_update = now;
 
-    ASSERT(rqd->avgload <= STIME_MAX && rqd->b_avgload <= STIME_MAX);
+    /* Overflow, capable of making the load look negative, must not occur. */
+    ASSERT(rqd->avgload >= 0 && rqd->b_avgload >= 0);
 
     if ( unlikely(tb_init_done) )
     {
@@ -788,6 +789,9 @@ __update_svc_load(const struct scheduler *ops,
     }
     svc->load_last_update = now;
 
+    /* Overflow, capable of making the load look negative, must not occur. */
+    ASSERT(svc->avgload >= 0);
+
     if ( unlikely(tb_init_done) )
     {
         struct {
@@ -1841,7 +1845,7 @@ retry:
          * If we're under 100% capacaty, only shift if load difference
          * is > 1.  otherwise, shift if under 12.5%
          */
-        if ( load_max < (cpus_max << prv->load_precision_shift) )
+        if ( load_max < ((s_time_t)cpus_max << prv->load_precision_shift) )
         {
             if ( st.load_delta < (1ULL << (prv->load_precision_shift +
                                            opt_underload_balance_tolerance)) )