From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keir Fraser Subject: Re: [PATCH] xen,credit1: Add variable timeslice Date: Tue, 13 Sep 2011 10:44:06 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: George Dunlap , xen-devel@lists.xensource.com Cc: Tim Deegan List-Id: xen-devel@lists.xenproject.org On 13/09/2011 10:25, "George Dunlap" wrote: > Ping? Now done. -- Keir > On Thu, Sep 1, 2011 at 4:30 PM, George Dunlap > wrote: >> Add a xen command-line parameter, sched_credit_tslice_ms, >> to set the timeslice of the credit1 scheduler. >>=20 >> Signed-off-by: George Dunlap >>=20 >> diff -r 4a4882df5649 -r 782284c5b1bc xen/common/sched_credit.c >> --- a/xen/common/sched_credit.c Wed Aug 31 15:23:49 2011 +0100 >> +++ b/xen/common/sched_credit.c Thu Sep 01 16:29:50 2011 +0100 >> @@ -41,15 +41,9 @@ >> =A0*/ >> =A0#define CSCHED_DEFAULT_WEIGHT =A0 =A0 =A0 256 >> =A0#define CSCHED_TICKS_PER_TSLICE =A0 =A0 3 >> -#define CSCHED_TICKS_PER_ACCT =A0 =A0 =A0 3 >> -#define CSCHED_MSECS_PER_TICK =A0 =A0 =A0 10 >> -#define CSCHED_MSECS_PER_TSLICE =A0 =A0 \ >> - =A0 =A0(CSCHED_MSECS_PER_TICK * CSCHED_TICKS_PER_TSLICE) >> +/* Default timeslice: 30ms */ >> +#define CSCHED_DEFAULT_TSLICE_MS =A0 =A030 >> =A0#define CSCHED_CREDITS_PER_MSEC =A0 =A0 10 >> -#define CSCHED_CREDITS_PER_TSLICE =A0 \ >> - =A0 =A0(CSCHED_CREDITS_PER_MSEC * CSCHED_MSECS_PER_TSLICE) >> -#define CSCHED_CREDITS_PER_ACCT =A0 =A0 \ >> - =A0 =A0(CSCHED_CREDITS_PER_MSEC * CSCHED_MSECS_PER_TICK * >> CSCHED_TICKS_PER_ACCT) >>=20 >>=20 >> =A0/* >> @@ -113,6 +107,8 @@ >> =A0*/ >> =A0static bool_t __read_mostly sched_credit_default_yield; >> =A0boolean_param("sched_credit_default_yield", sched_credit_default_yield)= ; >> +static int __read_mostly sched_credit_tslice_ms =3D CSCHED_DEFAULT_TSLICE= _MS; >> +integer_param("sched_credit_tslice_ms", sched_credit_tslice_ms); >>=20 >> =A0/* >> =A0* Physical CPU >> @@ -176,6 +172,9 @@ struct csched_private { >> =A0 =A0 uint32_t credit; >> =A0 =A0 int credit_balance; >> =A0 =A0 uint32_t runq_sort; >> + =A0 =A0/* Period of master and tick in milliseconds */ >> + =A0 =A0unsigned tslice_ms, tick_period_us, ticks_per_tslice; >> + =A0 =A0unsigned credits_per_tslice; >> =A0}; >>=20 >> =A0static void csched_tick(void *_cpu); >> @@ -326,7 +325,7 @@ csched_free_pdata(const struct scheduler >>=20 >> =A0 =A0 spin_lock_irqsave(&prv->lock, flags); >>=20 >> - =A0 =A0prv->credit -=3D CSCHED_CREDITS_PER_ACCT; >> + =A0 =A0prv->credit -=3D prv->credits_per_tslice; >> =A0 =A0 prv->ncpus--; >> =A0 =A0 cpu_clear(cpu, prv->idlers); >> =A0 =A0 cpu_clear(cpu, prv->cpus); >> @@ -360,19 +359,19 @@ csched_alloc_pdata(const struct schedule >> =A0 =A0 spin_lock_irqsave(&prv->lock, flags); >>=20 >> =A0 =A0 /* Initialize/update system-wide config */ >> - =A0 =A0prv->credit +=3D CSCHED_CREDITS_PER_ACCT; >> + =A0 =A0prv->credit +=3D prv->credits_per_tslice; >> =A0 =A0 prv->ncpus++; >> =A0 =A0 cpu_set(cpu, prv->cpus); >> =A0 =A0 if ( prv->ncpus =3D=3D 1 ) >> =A0 =A0 { >> =A0 =A0 =A0 =A0 prv->master =3D cpu; >> =A0 =A0 =A0 =A0 init_timer(&prv->master_ticker, csched_acct, prv, cpu); >> - =A0 =A0 =A0 =A0set_timer(&prv->master_ticker, NOW() + >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0MILLISECS(CSCHED_MSECS_PER_TICK) * CSCHED_TICKS_PER_A= CCT); >> + =A0 =A0 =A0 =A0set_timer(&prv->master_ticker, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0NOW() + MILLISECS(prv->tslice_ms)); >> =A0 =A0 } >>=20 >> =A0 =A0 init_timer(&spc->ticker, csched_tick, (void *)(unsigned long)cpu, cp= u); >> - =A0 =A0set_timer(&spc->ticker, NOW() + MILLISECS(CSCHED_MSECS_PER_TICK)); >> + =A0 =A0set_timer(&spc->ticker, NOW() + MICROSECS(prv->tick_period_us) ); >>=20 >> =A0 =A0 INIT_LIST_HEAD(&spc->runq); >> =A0 =A0 spc->runq_sort_last =3D prv->runq_sort; >> @@ -1002,7 +1001,7 @@ csched_acct(void* dummy) >> =A0 =A0 =A0 =A0 =A0* for one full accounting period. We allow a domain to earn mor= e >> =A0 =A0 =A0 =A0 =A0* only when the system-wide credit balance is negative. >> =A0 =A0 =A0 =A0 =A0*/ >> - =A0 =A0 =A0 =A0credit_peak =3D sdom->active_vcpu_count * CSCHED_CREDITS_PER_ACCT= ; >> + =A0 =A0 =A0 =A0credit_peak =3D sdom->active_vcpu_count * prv->credits_per_tslice= ; >> =A0 =A0 =A0 =A0 if ( prv->credit_balance < 0 ) >> =A0 =A0 =A0 =A0 { >> =A0 =A0 =A0 =A0 =A0 =A0 credit_peak +=3D ( ( -prv->credit_balance >> @@ -1014,7 +1013,7 @@ csched_acct(void* dummy) >>=20 >> =A0 =A0 =A0 =A0 if ( sdom->cap !=3D 0U ) >> =A0 =A0 =A0 =A0 { >> - =A0 =A0 =A0 =A0 =A0 =A0credit_cap =3D ((sdom->cap * CSCHED_CREDITS_PER_ACCT) + 99) /= 100; >> + =A0 =A0 =A0 =A0 =A0 =A0credit_cap =3D ((sdom->cap * prv->credits_per_tslice) + 99) /= 100; >> =A0 =A0 =A0 =A0 =A0 =A0 if ( credit_cap < credit_peak ) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 credit_peak =3D credit_cap; >>=20 >> @@ -1092,10 +1091,10 @@ csched_acct(void* dummy) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >>=20 >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Lower bound on credits */ >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( credit < -CSCHED_CREDITS_PER_TSLICE ) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( credit < -prv->credits_per_tslice ) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 CSCHED_STAT_CRANK(acct_min_credit); >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credit =3D -CSCHED_CREDITS_PER_TSLICE; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credit =3D -prv->credits_per_tslice; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 atomic_set(&svc->credit, credit); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> =A0 =A0 =A0 =A0 =A0 =A0 } >> @@ -1117,7 +1116,7 @@ csched_acct(void* dummy) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >>=20 >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Upper bound on credits means VCPU stops earning */ >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( credit > CSCHED_CREDITS_PER_TSLICE ) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( credit > prv->credits_per_tslice ) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __csched_vcpu_acct_stop_locked(prv, svc); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Divide credits in half, so that when it starts >> @@ -1141,8 +1140,8 @@ csched_acct(void* dummy) >> =A0 =A0 prv->runq_sort++; >>=20 >> =A0out: >> - =A0 =A0set_timer( &prv->master_ticker, NOW() + >> - =A0 =A0 =A0 =A0 =A0 =A0MILLISECS(CSCHED_MSECS_PER_TICK) * CSCHED_TICKS_PER_ACCT ); >> + =A0 =A0set_timer( &prv->master_ticker, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 NOW() + MILLISECS(prv->tslice_ms)); >> =A0} >>=20 >> =A0static void >> @@ -1169,7 +1168,7 @@ csched_tick(void *_cpu) >> =A0 =A0 =A0*/ >> =A0 =A0 csched_runq_sort(prv, cpu); >>=20 >> - =A0 =A0set_timer(&spc->ticker, NOW() + MILLISECS(CSCHED_MSECS_PER_TICK)); >> + =A0 =A0set_timer(&spc->ticker, NOW() + MICROSECS(prv->tick_period_us) ); >> =A0} >>=20 >> =A0static struct csched_vcpu * >> @@ -1375,7 +1374,7 @@ csched_schedule( >> =A0 =A0 =A0* Return task to run next... >> =A0 =A0 =A0*/ >> =A0 =A0 ret.time =3D (is_idle_vcpu(snext->vcpu) ? >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-1 : MILLISECS(CSCHED_MSECS_PER_TSLICE)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-1 : MILLISECS(prv->tslice_ms)); >> =A0 =A0 ret.task =3D snext->vcpu; >>=20 >> =A0 =A0 CSCHED_VCPU_CHECK(ret.task); >> @@ -1469,10 +1468,9 @@ csched_dump(const struct scheduler *ops) >> =A0 =A0 =A0 =A0 =A0 =A0"\tweight =A0 =A0 =A0 =A0 =A0 =A0 =3D %u\n" >> =A0 =A0 =A0 =A0 =A0 =A0"\trunq_sort =A0 =A0 =A0 =A0 =A0=3D %u\n" >> =A0 =A0 =A0 =A0 =A0 =A0"\tdefault-weight =A0 =A0 =3D %d\n" >> - =A0 =A0 =A0 =A0 =A0 "\tmsecs per tick =A0 =A0 =3D %dms\n" >> + =A0 =A0 =A0 =A0 =A0 "\ttslice =A0 =A0 =A0 =A0 =A0 =A0 =3D %dms\n" >> =A0 =A0 =A0 =A0 =A0 =A0"\tcredits per msec =A0 =3D %d\n" >> =A0 =A0 =A0 =A0 =A0 =A0"\tticks per tslice =A0 =3D %d\n" >> - =A0 =A0 =A0 =A0 =A0 "\tticks per acct =A0 =A0 =3D %d\n" >> =A0 =A0 =A0 =A0 =A0 =A0"\tmigration delay =A0 =A0=3D %uus\n", >> =A0 =A0 =A0 =A0 =A0 =A0prv->ncpus, >> =A0 =A0 =A0 =A0 =A0 =A0prv->master, >> @@ -1481,10 +1479,9 @@ csched_dump(const struct scheduler *ops) >> =A0 =A0 =A0 =A0 =A0 =A0prv->weight, >> =A0 =A0 =A0 =A0 =A0 =A0prv->runq_sort, >> =A0 =A0 =A0 =A0 =A0 =A0CSCHED_DEFAULT_WEIGHT, >> - =A0 =A0 =A0 =A0 =A0 CSCHED_MSECS_PER_TICK, >> + =A0 =A0 =A0 =A0 =A0 prv->tslice_ms, >> =A0 =A0 =A0 =A0 =A0 =A0CSCHED_CREDITS_PER_MSEC, >> - =A0 =A0 =A0 =A0 =A0 CSCHED_TICKS_PER_TSLICE, >> - =A0 =A0 =A0 =A0 =A0 CSCHED_TICKS_PER_ACCT, >> + =A0 =A0 =A0 =A0 =A0 prv->ticks_per_tslice, >> =A0 =A0 =A0 =A0 =A0 =A0vcpu_migration_delay); >>=20 >> =A0 =A0 cpumask_scnprintf(idlers_buf, sizeof(idlers_buf), prv->idlers); >> @@ -1526,6 +1523,13 @@ csched_init(struct scheduler *ops) >> =A0 =A0 INIT_LIST_HEAD(&prv->active_sdom); >> =A0 =A0 prv->master =3D UINT_MAX; >>=20 >> + =A0 =A0prv->tslice_ms =3D sched_credit_tslice_ms; >> + =A0 =A0prv->ticks_per_tslice =3D CSCHED_TICKS_PER_TSLICE; >> + =A0 =A0if ( prv->tslice_ms < prv->ticks_per_tslice ) >> + =A0 =A0 =A0 =A0prv->ticks_per_tslice =3D 1; >> + =A0 =A0prv->tick_period_us =3D prv->tslice_ms * 1000 / prv->ticks_per_tslice= ; >> + =A0 =A0prv->credits_per_tslice =3D CSCHED_CREDITS_PER_MSEC * prv->tslice_ms; >> + >> =A0 =A0 return 0; >> =A0} >>=20 >> @@ -1550,13 +1554,16 @@ static void csched_tick_suspend(const st >>=20 >> =A0static void csched_tick_resume(const struct scheduler *ops, unsigned in= t >> cpu) >> =A0{ >> + =A0 =A0struct csched_private *prv; >> =A0 =A0 struct csched_pcpu *spc; >> =A0 =A0 uint64_t now =3D NOW(); >>=20 >> =A0 =A0 spc =3D CSCHED_PCPU(cpu); >>=20 >> - =A0 =A0set_timer(&spc->ticker, now + MILLISECS(CSCHED_MSECS_PER_TICK) >> - =A0 =A0 =A0 =A0 =A0 =A0- now % MILLISECS(CSCHED_MSECS_PER_TICK) ); >> + =A0 =A0prv =3D CSCHED_PRIV(ops); >> + >> + =A0 =A0set_timer(&spc->ticker, now + MICROSECS(prv->tick_period_us) >> + =A0 =A0 =A0 =A0 =A0 =A0- now % MICROSECS(prv->tick_period_us) ); >> =A0} >>=20 >> =A0static struct csched_private _csched_priv; >>=20 >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@lists.xensource.com >> http://lists.xensource.com/xen-devel >>=20