From: Wei Liu Subject: Re: [PATCH v3 08/19] libxl: functions to build vmemranges for PV guest Date: Wed, 14 Jan 2015 11:05:01 +0000 Message-ID: <20150114110501.GB4226@zion.uk.xensource.com> References: <1421151107-20842-1-git-send-email-wei.liu2@citrix.com> <1421151107-20842-9-git-send-email-wei.liu2@citrix.com> <21685.24789.776819.653166@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <21685.24789.776819.653166@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Wei Liu , Ian Campbell , dario.faggioli@citrix.com, xen-devel@lists.xen.org, jbeulich@suse.com, Elena Ufimtseva List-Id: xen-devel@lists.xenproject.org On Tue, Jan 13, 2015 at 06:15:49PM +0000, Ian Jackson wrote: > Wei Liu writes ("[PATCH v3 08/19] libxl: functions to build vmemranges for PV guest"): > > Introduce a arch-independent routine to generate one vmemrange per > > vnode. Also introduce arch-dependent routines for different > > architectures because part of the process is arch-specific -- ARM has > > yet have NUMA support and E820 is x86 only. > > > > For those x86 guests who care about machine E820 map (i.e. with > > e820_host=1), vnode is further split into several vmemranges to > > accommodate memory holes. A few stubs for libxl_arm.c are created. > ... > > + /* Generate one vmemrange for each virtual node. */ > > + next = 0; > > + for (i = 0; i < b_info->num_vnuma_nodes; i++) { > > + libxl_vnode_info *p = &b_info->vnuma_nodes[i]; > > + > > + v = libxl__realloc(gc, v, sizeof(*v) * (i+1)); > > Please use GCREALLOC_ARRAY. No problem. > > > + v[i].start = next; > > + v[i].end = next + (p->mem << 20); /* mem is in MiB */ > > Why are all these values in different units ? > > Also, it would be best if the units were in the field and variable > names. Then you wouldn't have to write an explanatory comment. > I will rework code / data structures that's unclear about their units. > > diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c > > index e959e37..2018afc 100644 > > --- a/tools/libxl/libxl_x86.c > > +++ b/tools/libxl/libxl_x86.c > > @@ -338,6 +338,80 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc, > ... > > +int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc, > > + uint32_t domid, > > + libxl_domain_build_info *b_info, > > + libxl__domain_build_state *state) > > +{ > ... > > + n = 0; /* E820 counter */ > > How about putting this information in the variable name rather than > dropping it into a comment ? Likewise i. > Sure. Done. > > + while (remaining > 0) { > > + if (n >= nr_e820) { > > + rc = ERROR_FAIL; > > ERROR_NOMEM, surely ? > Done. > > + if (map[n].size >= remaining) { > > + v[x].start = map[n].addr; > > + v[x].end = map[n].addr + remaining; > > + map[n].addr += remaining; > > + map[n].size -= remaining; > > + remaining = 0; > > + } else { > > + v[x].start = map[n].addr; > > + v[x].end = map[n].addr + map[n].size; > > + remaining -= map[n].size; > > + n++; > > + } > > It might be possible to write this more compactly with something like > > use = map[n].size < remaining ? map[n].size : remaining; > I will see what I can do. Wei. > Ian.