1 /*
2 * vnuma.c: obtain vNUMA information from hypervisor
3 *
4 * Copyright (c) 2014 Wei Liu, Citrix Systems (R&D) Ltd.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include "util.h"
29 #include "hypercall.h"
30 #include "vnuma.h"
31
32 unsigned int nr_vnodes, nr_vmemranges;
33 unsigned int *vcpu_to_vnode, *vdistance;
34 xen_vmemrange_t *vmemrange;
35
init_vnuma_info(void)36 void init_vnuma_info(void)
37 {
38 int rc;
39 struct xen_vnuma_topology_info vnuma_topo = { .domid = DOMID_SELF };
40
41 rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
42 if ( rc != -ENOBUFS )
43 return;
44
45 ASSERT(vnuma_topo.nr_vcpus == hvm_info->nr_vcpus);
46
47 vcpu_to_vnode =
48 scratch_alloc(sizeof(*vcpu_to_vnode) * hvm_info->nr_vcpus, 0);
49 vdistance = scratch_alloc(sizeof(uint32_t) * vnuma_topo.nr_vnodes *
50 vnuma_topo.nr_vnodes, 0);
51 vmemrange = scratch_alloc(sizeof(xen_vmemrange_t) *
52 vnuma_topo.nr_vmemranges, 0);
53
54 set_xen_guest_handle(vnuma_topo.vdistance.h, vdistance);
55 set_xen_guest_handle(vnuma_topo.vcpu_to_vnode.h, vcpu_to_vnode);
56 set_xen_guest_handle(vnuma_topo.vmemrange.h, vmemrange);
57
58 rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
59
60 if ( rc < 0 )
61 {
62 printf("Failed to retrieve vNUMA information, rc = %d\n", rc);
63 return;
64 }
65
66 nr_vnodes = vnuma_topo.nr_vnodes;
67 nr_vmemranges = vnuma_topo.nr_vmemranges;
68 }
69
70
71 /*
72 * Local variables:
73 * mode: C
74 * c-file-style: "BSD"
75 * c-basic-offset: 4
76 * tab-width: 4
77 * indent-tabs-mode: nil
78 * End:
79 */
80