From: "Jan Beulich" Subject: [PATCH] small csched_cpu_pick() adjustments Date: Tue, 27 Oct 2009 13:37:12 +0000 Message-ID: <4AE70598020000780001C373@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartAB800A98.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartAB800A98.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When csched_cpu_pick() decides to move a vCPU to a different pCPU, so far in the vast majority of cases it selected the first core/thread of the most idle socket/core. When there are many short executing entities, this will generally lead to them not getting evenly distributed (since primary cores/threads will be preferred), making the need for subsequent migration more likely. Instead, candidate cores/threads should get treated as symmetrically as possible, and hence this changes the selection logic to cycle through all candidates. Further, since csched_cpu_pick() will never move a vCPU between threads of the same core (and since the weights calculated for individual threads of the same core are always identical), rather than removing just the selected pCPU from the mask that still needs looking at, all siblings of the chosen pCPU can be removed at once without affecting the outcome. Signed-off-by: Jan Beulich --- 2009-10-27.orig/xen/common/sched_credit.c 2009-10-27 12:07:32.0000000= 00 +0100 +++ 2009-10-27/xen/common/sched_credit.c 2009-10-27 14:27:28.0000000= 00 +0100 @@ -110,6 +110,7 @@ struct csched_pcpu { uint32_t runq_sort_last; struct timer ticker; unsigned int tick; + unsigned int idle_bias; }; =20 /* @@ -298,6 +299,7 @@ csched_pcpu_init(int cpu) init_timer(&spc->ticker, csched_tick, (void *)(unsigned long)cpu, = cpu); INIT_LIST_HEAD(&spc->runq); spc->runq_sort_last =3D csched_priv.runq_sort; + spc->idle_bias =3D NR_CPUS - 1; per_cpu(schedule_data, cpu).sched_priv =3D spc; =20 /* Start off idling... */ @@ -379,7 +381,7 @@ __csched_vcpu_is_migrateable(struct vcpu } =20 static int -csched_cpu_pick(struct vcpu *vc) +_csched_cpu_pick(struct vcpu *vc, bool_t commit) { cpumask_t cpus; cpumask_t idlers; @@ -438,8 +440,10 @@ csched_cpu_pick(struct vcpu *vc) if ( ( (weight_cpu < weight_nxt) ^ sched_smt_power_savings ) && (weight_cpu !=3D weight_nxt) ) { - cpu =3D nxt; - cpu_clear(cpu, cpus); + cpu =3D cycle_cpu(CSCHED_PCPU(nxt)->idle_bias, nxt_idlers); + if ( commit ) + CSCHED_PCPU(nxt)->idle_bias =3D cpu; + cpus_andnot(cpus, cpus, per_cpu(cpu_sibling_map, cpu)); } else { @@ -450,6 +454,12 @@ csched_cpu_pick(struct vcpu *vc) return cpu; } =20 +static int +csched_cpu_pick(struct vcpu *vc) +{ + return _csched_cpu_pick(vc, 1); +} + static inline void __csched_vcpu_acct_start(struct csched_vcpu *svc) { @@ -529,7 +539,7 @@ csched_vcpu_acct(unsigned int cpu) { __csched_vcpu_acct_start(svc); } - else if ( csched_cpu_pick(current) !=3D cpu ) + else if ( _csched_cpu_pick(current, 0) !=3D cpu ) { CSCHED_VCPU_STAT_CRANK(svc, migrate_r); CSCHED_STAT_CRANK(migrate_running); --=__PartAB800A98.0__= Content-Type: text/plain; name="xen-csched-adjust.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-csched-adjust.patch" When csched_cpu_pick() decides to move a vCPU to a different pCPU, = so=0Afar in the vast majority of cases it selected the first core/thread = of=0Athe most idle socket/core. When there are many short executing=0Aentit= ies, this will generally lead to them not getting evenly=0Adistributed = (since primary cores/threads will be preferred), making the=0Aneed for = subsequent migration more likely. Instead, candidate=0Acores/threads = should get treated as symmetrically as possible, and=0Ahence this changes = the selection logic to cycle through all candidates.=0A=0AFurther, since = csched_cpu_pick() will never move a vCPU between threads=0Aof the same = core (and since the weights calculated for individual=0Athreads of the = same core are always identical), rather than removing=0Ajust the selected = pCPU from the mask that still needs looking at, all=0Asiblings of the = chosen pCPU can be removed at once without affecting=0Athe outcome.=0A=0ASi= gned-off-by: Jan Beulich =0A=0A--- 2009-10-27.orig/xen= /common/sched_credit.c 2009-10-27 12:07:32.000000000 +0100=0A+++ = 2009-10-27/xen/common/sched_credit.c 2009-10-27 14:27:28.000000000 = +0100=0A@@ -110,6 +110,7 @@ struct csched_pcpu {=0A uint32_t runq_sort_= last;=0A struct timer ticker;=0A unsigned int tick;=0A+ = unsigned int idle_bias;=0A };=0A =0A /*=0A@@ -298,6 +299,7 @@ csched_pcpu_i= nit(int cpu)=0A init_timer(&spc->ticker, csched_tick, (void *)(unsigned= long)cpu, cpu);=0A INIT_LIST_HEAD(&spc->runq);=0A spc->runq_sort_l= ast =3D csched_priv.runq_sort;=0A+ spc->idle_bias =3D NR_CPUS - 1;=0A = per_cpu(schedule_data, cpu).sched_priv =3D spc;=0A =0A /* Start off = idling... */=0A@@ -379,7 +381,7 @@ __csched_vcpu_is_migrateable(struct = vcpu=0A }=0A =0A static int=0A-csched_cpu_pick(struct vcpu *vc)=0A+_csched_= cpu_pick(struct vcpu *vc, bool_t commit)=0A {=0A cpumask_t cpus;=0A = cpumask_t idlers;=0A@@ -438,8 +440,10 @@ csched_cpu_pick(struct vcpu = *vc)=0A if ( ( (weight_cpu < weight_nxt) ^ sched_smt_power_savings = )=0A && (weight_cpu !=3D weight_nxt) )=0A {=0A- = cpu =3D nxt;=0A- cpu_clear(cpu, cpus);=0A+ = cpu =3D cycle_cpu(CSCHED_PCPU(nxt)->idle_bias, nxt_idlers);=0A+ = if ( commit )=0A+ CSCHED_PCPU(nxt)->idle_bias =3D cpu;=0A+ = cpus_andnot(cpus, cpus, per_cpu(cpu_sibling_map, cpu));=0A = }=0A else=0A {=0A@@ -450,6 +454,12 @@ csched_cpu_pick(stru= ct vcpu *vc)=0A return cpu;=0A }=0A =0A+static int=0A+csched_cpu_pick(s= truct vcpu *vc)=0A+{=0A+ return _csched_cpu_pick(vc, 1);=0A+}=0A+=0A = static inline void=0A __csched_vcpu_acct_start(struct csched_vcpu *svc)=0A = {=0A@@ -529,7 +539,7 @@ csched_vcpu_acct(unsigned int cpu)=0A {=0A = __csched_vcpu_acct_start(svc);=0A }=0A- else if ( csched_cpu_pic= k(current) !=3D cpu )=0A+ else if ( _csched_cpu_pick(current, 0) !=3D = cpu )=0A {=0A CSCHED_VCPU_STAT_CRANK(svc, migrate_r);=0A = CSCHED_STAT_CRANK(migrate_running);=0A --=__PartAB800A98.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartAB800A98.0__=--