From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dario Faggioli Subject: [PATCH 1/3] libxl: check whether vcpu affinity and vnuma info match Date: Tue, 24 Mar 2015 14:41:48 +0100 Message-ID: <20150324134146.10874.3628.stgit@Solace.station> References: <20150324132630.10874.78040.stgit@Solace.station> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20150324132630.10874.78040.stgit@Solace.station> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Wei Liu , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org More specifically, vcpus are assigned to a vnode, which in turn is associated with a pnode. If a vcpu also has, in its (hard or soft) affinity, some pcpus that are not part of the said pnode, print a warning to the user. Signed-off-by: Dario Faggioli Cc: Ian Campbell Cc: Ian Jackson Cc: Stefano Stabellini Cc: Wei Liu --- tools/libxl/libxl_vnuma.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/libxl/libxl_vnuma.c b/tools/libxl/libxl_vnuma.c index aad297e..3383724 100644 --- a/tools/libxl/libxl_vnuma.c +++ b/tools/libxl/libxl_vnuma.c @@ -33,6 +33,43 @@ static int compare_vmemrange(const void *a, const void *b) return 0; } +/* Check if a vcpu has an hard (or soft) affinity set in such + * a way that it does not match the pnode to which the vcpu itself + * is assigned to. + */ +static int check_vnuma_affinity(libxl__gc *gc, + unsigned int vcpu, + unsigned int pnode, + unsigned int num_affinity, + const libxl_bitmap *affinity, + const char *kind) +{ + libxl_bitmap nodemap; + int rc = 0; + + libxl_bitmap_init(&nodemap); + + rc = libxl_node_bitmap_alloc(CTX, &nodemap, 0); + if (rc) { + LOG(ERROR, "Can't allocate nodemap"); + goto out; + } + + rc = libxl_cpumap_to_nodemap(CTX, affinity, &nodemap); + if (rc) { + LOG(ERROR, "Can't convert Vcpu %d affinity to nodemap", vcpu); + goto out; + } + + if (libxl_bitmap_count_set(&nodemap) != 1 || + !libxl_bitmap_test(&nodemap, pnode)) + LOG(WARN, "Vcpu %d %s affinity and vnuma info mismatch", vcpu, kind); + +out: + libxl_bitmap_dispose(&nodemap); + return rc; +} + /* Check if vNUMA configuration is valid: * 1. all pnodes inside vnode_to_pnode array are valid * 2. each vcpu belongs to one and only one vnode @@ -101,6 +138,23 @@ int libxl__vnuma_config_check(libxl__gc *gc, } } + /* Check whether vcpu affinity (if any) matches vnuma configuration */ + for (i = 0; i < b_info->num_vnuma_nodes; i++) { + v = &b_info->vnuma_nodes[i]; + libxl_for_each_set_bit(j, v->vcpus) { + if (b_info->num_vcpu_hard_affinity > j) + check_vnuma_affinity(gc, j, v->pnode, + b_info->num_vcpu_hard_affinity, + &b_info->vcpu_hard_affinity[j], + "hard"); + if (b_info->num_vcpu_soft_affinity > j) + check_vnuma_affinity(gc, j, v->pnode, + b_info->num_vcpu_soft_affinity, + &b_info->vcpu_soft_affinity[j], + "soft"); + } + } + /* Check vmemranges */ qsort(state->vmemranges, state->num_vmemranges, sizeof(xen_vmemrange_t), compare_vmemrange);