From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH v5 08/24] libxl: introduce libxl__vnuma_config_check Date: Tue, 17 Feb 2015 12:56:58 +0000 Message-ID: <20150217125658.GD2159@zion.uk.xensource.com> References: <1423770294-9779-1-git-send-email-wei.liu2@citrix.com> <1423770294-9779-9-git-send-email-wei.liu2@citrix.com> <54DE1AF0.80304@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <54DE1AF0.80304@citrix.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: Andrew Cooper Cc: Wei Liu , ian.campbell@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, JBeulich@suse.com, ufimtseva@gmail.com List-Id: xen-devel@lists.xenproject.org On Fri, Feb 13, 2015 at 03:40:32PM +0000, Andrew Cooper wrote: [...] > > + return 0; > > +} > > + > > +/* Check if vNUMA configuration is valid: > > + * 1. all pnodes inside vnode_to_pnode array are valid > > + * 2. one vcpu belongs to and only belongs to one vnode > > + * 3. each vmemrange is valid and doesn't overlap with each other > > + */ > > +int libxl__vnuma_config_check(libxl__gc *gc, > > + const libxl_domain_build_info *b_info, > > + const libxl__domain_build_state *state) > > +{ > > + int i, j, rc = ERROR_VNUMA_CONFIG_INVALID, nr_nodes; > > i, j and nr_nodes are all semantically unsigned. > Fixed. > > + libxl_numainfo *ninfo = NULL; > > + uint64_t total_memkb = 0; > > + libxl_bitmap cpumap; > > + libxl_vnode_info *p; > > + > > + libxl_bitmap_init(&cpumap); > > + > > + /* Check pnode specified is valid */ > > + ninfo = libxl_get_numainfo(CTX, &nr_nodes); > > + if (!ninfo) { > > + LOG(ERROR, "libxl_get_numainfo failed"); > > + goto out; > > + } > > + > > + for (i = 0; i < b_info->num_vnuma_nodes; i++) { > > + uint32_t pnode; > > + > > + p = &b_info->vnuma_nodes[i]; > > + pnode = p->pnode; > > + > > + /* The pnode specified is not valid? */ > > + if (pnode >= nr_nodes) { > > + LOG(ERROR, "Invalid pnode %d specified", pnode); > > pnode is uint32_t, so should be %u > Fixed. > > + goto out; > > + } > > + > > + total_memkb += p->memkb; > > + } > > + > > + if (total_memkb != b_info->max_memkb) { > > + LOG(ERROR, "Amount of memory mismatch (0x%"PRIx64" != 0x%"PRIx64")", > > + total_memkb, b_info->max_memkb); > > + goto out; > > + } > > + > > + /* Check vcpu mapping */ > > + libxl_cpu_bitmap_alloc(CTX, &cpumap, b_info->max_vcpus); > > + libxl_bitmap_set_none(&cpumap); > > Worth using/making libxl_cpu_bitmap_zalloc(), or perhaps making this a > defined semantic of the alloc() function? This would seem to be a very > common pair of operations to perform. > Actually libxl_bitmap_alloc already uses calloc, so the bitmap is always set to all zeros. > > + for (i = 0; i < b_info->num_vnuma_nodes; i++) { > > + p = &b_info->vnuma_nodes[i]; > > + libxl_for_each_set_bit(j, p->vcpus) { > > + if (!libxl_bitmap_test(&cpumap, j)) > > + libxl_bitmap_set(&cpumap, j); > > + else { > > + LOG(ERROR, "Vcpu %d assigned more than once", j); > > + goto out; > > + } > > + } > > This libxl_for_each_set_bit() loop can be optimised to a > bitmap_intersects() for the error condition, and bitmap_or() for the > success case. > > > + } > > + > > + for (i = 0; i < b_info->max_vcpus; i++) { > > + if (!libxl_bitmap_test(&cpumap, i)) { > > + LOG(ERROR, "Vcpu %d is not assigned to any vnode", i); > > + goto out; > > + } > > This loop can be optimised to !bitmap_all_set(). > I can introduce a new patch set of bitmap operations and switch to that later. Now this series has grown to almost 30 patches and I would like to keep this series focus mostly on vNUMA related stuffs. Wei.