xen credit
Hi all,
Now I am reading the source code sched-credit. The xen version is 4.2.1. I can not fully understand two places.
One place is:
There is a variable in schedule.c. There is per cpu variable, tasklet_work_to_do. Read this variable, set the tasklet_work,
unsigned long *tasklet_work = &this_cpu(tasklet_work_to_do);
bool_t tasklet_work_scheduled = 0;Then according to the task_work, set the tasklet_work_scheduled:
/* Update tasklet scheduling status. */
switch ( *tasklet_work )
{
case TASKLET_enqueued:
set_bit(_TASKLET_scheduled, tasklet_work);
case TASKLET_enqueued|TASKLET_scheduled:
tasklet_work_scheduled = 1;
break;
case TASKLET_scheduled:
clear_bit(_TASKLET_scheduled, tasklet_work);
case 0:
/*tasklet_work_scheduled = 0;*/
break;
default:
BUG();
}I can not understand the function of tasklet_work_to_do, tasklet_work, tasklet_work_scheduled. I can not understand their meaning. In the sched_credit.c file,
there are two places that use tasklet_work_scheduled. I can not understand the meaning of tasklet_work_scheduled.
One place:
if ( !tasklet_work_scheduled
&& prv->ratelimit_us
&& vcpu_runnable(current)
&& !is_idle_vcpu(current)
&& runtime < MICROSECS(prv->ratelimit_us) )
{
snext = scurr;
snext->start_time += now;
perfc_incr(delay_ms);
tslice = MICROSECS(prv->ratelimit_us);
ret.migrated = 0;
goto out;
}the other place:
if ( tasklet_work_scheduled )
{
snext = CSCHED_VCPU(idle_vcpu[cpu]);
snext->pri = CSCHED_PRI_TS_BOOST;
}This variable tasklet_work_scheduled is obstacle I understand the source code.
Other question is the member s_time_t start_time in structure struct csched_vcpu. The meaning and function for this variable?
I do not know why when a vcpu is descheduled, its start_time - now, why a vcpu is scheduled, its start_time + now?
deschedule:
if ( !is_idle_vcpu(scurr->vcpu) )
{
/* Update credits of a non-idle VCPU. */
burn_credits(scurr, now);
scurr->start_time -= now;
}schedule:
if ( !tasklet_work_scheduled
&& prv->ratelimit_us
&& vcpu_runnable(current)
&& !is_idle_vcpu(current)
&& runtime < MICROSECS(prv->ratelimit_us) )
{
snext = scurr;
snext->start_time += now;
perfc_incr(delay_ms);
tslice = MICROSECS(prv->ratelimit_us);
ret.migrated = 0;
goto out;
}Anybody can give me some advice for these problems? Thank you in advance!
--
View this message in context: http://xen.1045712.n5.nabble.com/xen-credit-tp5715450.html
Sent from the Xen - Dev mailing list archive at Nabble.com.
Quoted 4 lines · zhangwqh
Hi all,
Now I am reading the source code sched-credit. The xen version is 4.2.1. I can not fully understand two places.
It's better if you stick to a single question per e-mail.
Quoted 27 lines
Other question is the member
s_time_tstart_timein structure structcsched_vcpu. The meaning and function for this variable?
I do not know why when a vcpu is descheduled, itsstart_time- now, why a vcpu is scheduled, itsstart_time+ now?
deschedule:
if ( !is_idle_vcpu(scurr->vcpu) ){ /* Update credits of a non-idle VCPU. */ burn_credits(scurr, now); scurr->start_time -= now; }schedule:
if ( !tasklet_work_scheduled&& prv->ratelimit_us && vcpu_runnable(current) && !is_idle_vcpu(current) && runtime < MICROSECS(prv->ratelimit_us) ) { snext = scurr; snext->start_time += now; perfc_incr(delay_ms); tslice = MICROSECS(prv->ratelimit_us); ret.migrated = 0; goto out; }
Quoted 1 line
Anybody can give me some advice for these problems? Thank you in advance!
If you use "git blame" (or "hg annotate"), you'll find that the lines in question were changed in changeset 4f74c85e.
That changeset has a comment briefly explaining the idea:
credit scheduler: fix credits overflow
In changing credits-per-tick from 100 to 1000000, a possible overflow was introduced in the accounting algorithm, when credit totals (which can be in the millions) gets multiplied by a weight (typically 256):
th eresult can easily overflow a signed 32-bit variable.
Fix this by reverting to 100 credits per tick, and maintain long-term fairness/correctness by tracking at the nanosecond level exactly how much execution time has been accounted to each VCPU. We do this by rounding execution time so far to nearest number of credits, but then remember the VCPU's 'partial credit balance'.
The key phrase there is "remembering the VCPU's partial credit balance'.
-George