diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2013-02-15 13:32:20 +0000 |
---|---|---|
committer | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2013-02-15 13:32:20 +0000 |
commit | 096578b4e489f87e2a66b213108d511d15b4d9be (patch) | |
tree | 1eb724b854940baab7974283db86a14d3f2c76a5 /xen/common/sysctl.c | |
parent | 89697a13da4262169e6e1c3a9f4e2dee17d143b7 (diff) | |
download | xen-096578b4e489f87e2a66b213108d511d15b4d9be.tar.gz xen-096578b4e489f87e2a66b213108d511d15b4d9be.tar.bz2 xen-096578b4e489f87e2a66b213108d511d15b4d9be.zip |
xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code
Move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and
XEN_SYSCTL_topologyinfo from x86/sysctl.c to common/sysctl.c.
The implementation of XEN_SYSCTL_physinfo is mostly generic but needs to
fill in few arch specific details: introduce arch_do_physinfo to do that.
The implementation of XEN_SYSCTL_physinfo relies on two global
variables: total_pages and cpu_khz. Make them available on ARM.
Implement node_spanned_pages and __node_distance on ARM, assuming 1 numa
node for now.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'xen/common/sysctl.c')
-rw-r--r-- | xen/common/sysctl.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index d663ed7430..20bb864e64 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -249,6 +249,115 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) ret = sched_adjust_global(&op->u.scheduler_op); break; + case XEN_SYSCTL_physinfo: + { + xen_sysctl_physinfo_t *pi = &op->u.physinfo; + + memset(pi, 0, sizeof(*pi)); + pi->threads_per_core = + cpumask_weight(per_cpu(cpu_sibling_mask, 0)); + pi->cores_per_socket = + cpumask_weight(per_cpu(cpu_core_mask, 0)) / pi->threads_per_core; + pi->nr_cpus = num_online_cpus(); + pi->nr_nodes = num_online_nodes(); + pi->max_node_id = MAX_NUMNODES-1; + pi->max_cpu_id = nr_cpu_ids - 1; + pi->total_pages = total_pages; + pi->free_pages = avail_domheap_pages(); + pi->scrub_pages = 0; + pi->cpu_khz = cpu_khz; + arch_do_physinfo(pi); + + if ( copy_to_guest(u_sysctl, op, 1) ) + ret = -EFAULT; + } + break; + + case XEN_SYSCTL_numainfo: + { + uint32_t i, j, max_node_index, last_online_node; + xen_sysctl_numainfo_t *ni = &op->u.numainfo; + + last_online_node = last_node(node_online_map); + max_node_index = min_t(uint32_t, ni->max_node_index, last_online_node); + ni->max_node_index = last_online_node; + + for ( i = 0; i <= max_node_index; i++ ) + { + if ( !guest_handle_is_null(ni->node_to_memsize) ) + { + uint64_t memsize = node_online(i) ? + node_spanned_pages(i) << PAGE_SHIFT : 0ul; + if ( copy_to_guest_offset(ni->node_to_memsize, i, &memsize, 1) ) + break; + } + if ( !guest_handle_is_null(ni->node_to_memfree) ) + { + uint64_t memfree = node_online(i) ? + avail_node_heap_pages(i) << PAGE_SHIFT : 0ul; + if ( copy_to_guest_offset(ni->node_to_memfree, i, &memfree, 1) ) + break; + } + + if ( !guest_handle_is_null(ni->node_to_node_distance) ) + { + for ( j = 0; j <= max_node_index; j++) + { + uint32_t distance = ~0u; + if ( node_online(i) && node_online(j) ) + distance = __node_distance(i, j); + if ( copy_to_guest_offset( + ni->node_to_node_distance, + i*(max_node_index+1) + j, &distance, 1) ) + break; + } + if ( j <= max_node_index ) + break; + } + } + + ret = ((i <= max_node_index) || copy_to_guest(u_sysctl, op, 1)) + ? -EFAULT : 0; + } + break; + + case XEN_SYSCTL_topologyinfo: + { + uint32_t i, max_cpu_index, last_online_cpu; + xen_sysctl_topologyinfo_t *ti = &op->u.topologyinfo; + + last_online_cpu = cpumask_last(&cpu_online_map); + max_cpu_index = min_t(uint32_t, ti->max_cpu_index, last_online_cpu); + ti->max_cpu_index = last_online_cpu; + + for ( i = 0; i <= max_cpu_index; i++ ) + { + if ( !guest_handle_is_null(ti->cpu_to_core) ) + { + uint32_t core = cpu_online(i) ? cpu_to_core(i) : ~0u; + if ( copy_to_guest_offset(ti->cpu_to_core, i, &core, 1) ) + break; + } + if ( !guest_handle_is_null(ti->cpu_to_socket) ) + { + uint32_t socket = cpu_online(i) ? cpu_to_socket(i) : ~0u; + if ( copy_to_guest_offset(ti->cpu_to_socket, i, &socket, 1) ) + break; + } + if ( !guest_handle_is_null(ti->cpu_to_node) ) + { + uint32_t node = cpu_online(i) ? cpu_to_node(i) : ~0u; + if ( copy_to_guest_offset(ti->cpu_to_node, i, &node, 1) ) + break; + } + } + + ret = ((i <= max_cpu_index) || copy_to_guest(u_sysctl, op, 1)) + ? -EFAULT : 0; + } + break; + + default: ret = arch_do_sysctl(op, u_sysctl); copyback = 0; |