From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [question] bug in cpu_schedule_up? Date: Wed, 18 Jan 2012 08:38:55 +0000 Message-ID: <1326875935.29475.23.camel@dagon.hellion.org.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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: Kai Huang Cc: "Xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Wed, 2012-01-18 at 08:13 +0000, Kai Huang wrote: > Hi, > > I see below code in cpu_schedule_up in xen-unstable hg repository > (xen/common/schedule.c). > > if ( idle_vcpu[cpu] == NULL ) > alloc_vcpu(idle_vcpu[0]->domain, cpu, cpu); > if ( idle_vcpu[cpu] == NULL ) > return -ENOMEM; > > Seems it's a bug? Should be like this? > > if ( idle_vcpu[cpu] == NULL ) > idle_vcpu[cpu] = alloc_vcpu(idle_vcpu[0]->domain, cpu, cpu); > if ( idle_vcpu[cpu] == NULL ) > return -ENOMEM; alloc_vcpu will set idle_vcpu[0]->domain->vcpu[cpu] to the newly allocated vcpu. idle_vcpu[0]->domain == idle_domain and idle_vcpu[0]->domain->vcpu == idle_vcpu (both are by construction in scheduler_init). Therefore idle_vcpu[cpu] is already being set inside alloc_vcpu. The return value of alloc_vcpu is to save code which wants a local handle on the newly allocated vcpu to perform further setup from doing the lookup itself. Ian.