Skip to contentSkip to conversation

schedule: move last_run_time to the credit scheduler privates

PATCH Superseded Andrii Anisov 3 participants 3 messages Sep 12, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 schedule: move last_run_time to the credit scheduler privates

From: Andrii Anisov <[email protected]>

The structure member last_run_time is used by credit scheduler only. So move it from a generic vcpu sctructure to the credit scheduler private vcpu definition.

---
Changes in v2:
- last_run_time type changed to s_time_t
- scurr changed to svc
- dropped stray blanks
- pointers to const are used appropriately

---
 xen/common/sched_credit.c | 12 +++++++++---
 xen/common/schedule.c     |  1 -
 xen/include/xen/sched.h   |  3 ---
 3 files changed, 9 insertions(+), 7 deletions(-)
xen/common/sched_credit.c +9 -3
index 84e744b..88de35c 100644
@@ -175,6 +175,9 @@ struct csched_vcpu {
     atomic_t credit;
     unsigned int residual;
 
+    /* last time when vCPU is scheduled out */
+    s_time_t last_run_time;
+
 #ifdef CSCHED_STATS
     struct {
         int credit_last;
@@ -701,10 +704,11 @@ static unsigned int vcpu_migration_delay_us;
 integer_param("vcpu_migration_delay", vcpu_migration_delay_us);
 
 static inline bool
-__csched_vcpu_is_cache_hot(const struct csched_private *prv, struct vcpu *v)
+__csched_vcpu_is_cache_hot(const struct csched_private *prv,
+                           const struct csched_vcpu *svc)
 {
     bool hot = prv->vcpu_migr_delay &&
-               (NOW() - v->last_run_time) < prv->vcpu_migr_delay;
+               (NOW() - svc->last_run_time) < prv->vcpu_migr_delay;
 
     if ( hot )
         SCHED_STAT_CRANK(vcpu_hot);
@@ -716,6 +720,7 @@ static inline int
 __csched_vcpu_is_migrateable(const struct csched_private *prv, struct vcpu *vc,
                              int dest_cpu, cpumask_t *mask)
 {
+    const struct csched_vcpu *svc = CSCHED_VCPU(vc);
     /*
      * Don't pick up work that's hot on peer PCPU, or that can't (or
      * would prefer not to) run on cpu.
@@ -725,7 +730,7 @@ __csched_vcpu_is_migrateable(const struct csched_private *prv, struct vcpu *vc,
      */
     ASSERT(!vc->is_running);
 
-    return !__csched_vcpu_is_cache_hot(prv, vc) &&
+    return !__csched_vcpu_is_cache_hot(prv, svc) &&
            cpumask_test_cpu(dest_cpu, mask);
 }
 
@@ -1869,6 +1874,7 @@ csched_schedule(
         /* Update credits of a non-idle VCPU. */
         burn_credits(scurr, now);
         scurr->start_time -= now;
+        scurr->last_run_time = now;
     }
     else
     {
xen/common/schedule.c +0 -1
index 05281d6..3c299ca 100644
@@ -1556,7 +1556,6 @@ static void schedule(void)
         ((prev->pause_flags & VPF_blocked) ? RUNSTATE_blocked :
          (vcpu_runnable(prev) ? RUNSTATE_runnable : RUNSTATE_offline)),
         now);
-    prev->last_run_time = now;
 
     ASSERT(next->runstate.state != RUNSTATE_running);
     vcpu_runstate_change(next, RUNSTATE_running, now);
xen/include/xen/sched.h +0 -3
index 0ba80cb..b6b2c43 100644
@@ -173,9 +173,6 @@ struct vcpu
     } runstate_guest; /* guest address */
 #endif
 
-    /* last time when vCPU is scheduled out */
-    uint64_t last_run_time;
-
     /* Has the FPU been initialised? */
     bool             fpu_initialised;
     /* Has the FPU been used since it was last saved? */
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 7 lines · Andrii Anisov

From: Andrii Anisov <[email protected]>

The structure member last_run_time is used by credit scheduler only. So move it from a generic vcpu sctructure to the credit scheduler private
vcpu definition.

Quoted 8 lines

---
Changes in v2:
- last_run_time type changed to s_time_t
- scurr changed to svc
- dropped stray blanks
- pointers to const are used appropriately

Well, the fact that the type is changing, and that you're also fixing/improving const-ness, should IMO at least be quickly mentioned in the changelog.

Something like:
"While there, also turn it into s_time_t, which is more appropriate. Also, properly const-ify one of the argument of __csched_vcpu_is_cache_hot()"

And I was right about to write that I would also like the changelog itself to contain the usual sentence:
"No functional change intended"

but then I saw this (sorry for not noticing it in v1):

Quoted 18 lines
xen/common/sched_credit.c +1 -0
@@ -1869,6 +1874,7 @@ csched_schedule(
         /* Update credits of a non-idle VCPU. */
         burn_credits(scurr, now);
         scurr->start_time -= now;
+        scurr->last_run_time = now;
     }
     else
     {
xen/common/schedule.c +0 -1
index 05281d6..3c299ca 100644
@@ -1556,7 +1556,6 @@ static void schedule(void)
         ((prev->pause_flags & VPF_blocked) ? RUNSTATE_blocked :
          (vcpu_runnable(prev) ? RUNSTATE_runnable :
 RUNSTATE_offline)),
         now);
-    prev->last_run_time = now;
 
     ASSERT(next->runstate.state != RUNSTATE_running);
Quoted 2 lines
     vcpu_runstate_change(next, RUNSTATE_running, now);

Basically, right now last_run_time is updated only when, in csched_schedule() we chose a different vcpu than the one which was running, and it also was updated for the idle vcpu.

With the patch, it looks to me that it is updated even when we continue to run the same vcpu, and is never updated for the idle vcpu.

Now, considering how the info it contains is used currently, I'd say that not updating the field for the idle vcpu is not a problem.

The fact that we _always_ update it for non-idle vcpus means we're changing what the field contains for running vcpus. Which again does not look to matter much right now.

Do you agree with this analysis?

If yes, well, I think this is bearable. Or, at least, that the benefit of having the logic self-contained in Credit code, overweight this slight loss of coherency between the name of the field and its content (things remains well within Credit's standards wrt to time accounting! :-/).

But I'd add a few words about all this either in the changelog, and probably also in a comment (even a very short one, like "last_run_time is only meaningful for non running tasks" close to where you update it, or something like that).

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 16 lines · Dario Faggioli
Quoted 7 lines · Andrii Anisov

From: Andrii Anisov <[email protected]>

The structure member last_run_time is used by credit scheduler only. So move it from a generic vcpu sctructure to the credit scheduler private
vcpu definition.

Quoted 8 lines

---
Changes in v2:
- last_run_time type changed to s_time_t
- scurr changed to svc
- dropped stray blanks
- pointers to const are used appropriately

Quoted 8 lines

Well, the fact that the type is changing, and that you're also fixing/improving const-ness, should IMO at least be quickly mentioned in the changelog.

Something like:
"While there, also turn it into s_time_t, which is more appropriate. Also, properly const-ify one of the argument of __csched_vcpu_is_cache_hot()"

OK.

Quoted 10 lines

And I was right about to write that I would also like the changelog itself to contain the usual sentence:
"No functional change intended"

but then I saw this (sorry for not noticing it in v1):

xen/common/sched_credit.c csched_schedule( · line 1876

Quoted 4 lines
xen/common/sched_credit.c +0 -0
@@ -1869,6 +1874,7 @@ csched_schedule(
          /* Update credits of a non-idle VCPU. */
          burn_credits(scurr, now);
          scurr->start_time -= now;

In the first (internal) version of the patch this line was commented as "No matter what happens next with the current VCPU, we are safe to set its last run time here"

Quoted 13 lines
Quoted 13 lines
xen/common/sched_credit.c +1 -0
+        scurr->last_run_time = now;
      }
      else
      {
xen/common/schedule.c +0 -1
index 05281d6..3c299ca 100644
@@ -1556,7 +1556,6 @@ static void schedule(void)
          ((prev->pause_flags & VPF_blocked) ? RUNSTATE_blocked :
           (vcpu_runnable(prev) ? RUNSTATE_runnable :
 RUNSTATE_offline)),
          now);
-    prev->last_run_time = now;
 
Quoted 8 lines
Quoted 3 lines
xen/common/schedule.c +0 -0
      ASSERT(next->runstate.state != RUNSTATE_running);
      vcpu_runstate_change(next, RUNSTATE_running, now);

Basically, right now last_run_time is updated only when, in csched_schedule() we chose a different vcpu than the one which was running, and it also was updated for the idle vcpu.
With the patch, it looks to me that it is updated even when we continue to run the same vcpu,

Right you are. But while it is used for vcpu cache "temperature" measurement only, it is still OK. Scheduling parameters and statistics are tracked by other entities.

Quoted 1 line

and is never updated for the idle vcpu.

Yep, but it has no meaning for the idle vcpu. It never migrates.

Quoted 8 lines

Now, considering how the info it contains is used currently, I'd say that not updating the field for the idle vcpu is not a problem.

The fact that we _always_ update it for non-idle vcpus means we're changing what the field contains for running vcpus. Which again does not look to matter much right now.

Do you agree with this analysis?

Sure :)

Quoted 10 lines

If yes, well, I think this is bearable. Or, at least, that the benefit of having the logic self-contained in Credit code, overweight this slight loss of coherency between the name of the field and its content (things remains well within Credit's standards wrt to time accounting! :-/).

But I'd add a few words about all this either in the changelog, and probably also in a comment (even a very short one, like "last_run_time is only meaningful for non running tasks" close to where you update it, or something like that).

OK.

Signature · 8 lines
*Andrii Anisov*



_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel