All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: jbeulich@suse.com, keir@xen.org, andrew.cooper3@citrix.com,
	ian.jackson@eu.citrix.com, ian.campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, wei.liu2@citrix.com
Cc: boris.ostrovsky@oracle.com, dario.faggioli@citrix.com,
	port-xen@netbsd.org, ufimtseva@gmail.com,
	xen-devel@lists.xen.org
Subject: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc
Date: Mon,  9 Feb 2015 15:04:33 -0500	[thread overview]
Message-ID: <1423512275-6531-6-git-send-email-boris.ostrovsky@oracle.com> (raw)
In-Reply-To: <1423512275-6531-1-git-send-email-boris.ostrovsky@oracle.com>

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 tools/libxc/include/xenctrl.h     |    4 +-
 tools/libxc/xc_misc.c             |   23 +++++++++++-----
 tools/libxl/libxl.c               |   32 +++++------------------
 tools/misc/xenpm.c                |   51 ++++++++++++++++---------------------
 tools/python/xen/lowlevel/xc/xc.c |   23 ++++++-----------
 5 files changed, 55 insertions(+), 78 deletions(-)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 0cb6743..d94571d 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch,
 int xc_send_debug_keys(xc_interface *xch, char *keys);
 
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_sysctl_cputopoinfo_t xc_cputopoinfo_t;
+typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
@@ -1237,7 +1237,7 @@ typedef uint64_t xc_node_to_memfree_t;
 typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
-int xc_cputopoinfo(xc_interface *xch, xc_cputopoinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);
 int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
 
 int xc_sched_id(xc_interface *xch,
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index be68291..4c654f3 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -177,22 +177,31 @@ int xc_physinfo(xc_interface *xch,
     return 0;
 }
 
-int xc_cputopoinfo(xc_interface *xch,
-                   xc_cputopoinfo_t *put_info)
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus,
+                   xc_cputopo_t *cputopo)
 {
     int ret;
     DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(cputopo, *max_cpus * sizeof(*cputopo),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
 
-    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
+    if ((ret = xc_hypercall_bounce_pre(xch, cputopo)))
+        goto out;
 
-    memcpy(&sysctl.u.cputopoinfo, put_info, sizeof(*put_info));
+    sysctl.u.cputopoinfo.max_cpu_index = *max_cpus;
+    set_xen_guest_handle(sysctl.u.cputopoinfo.cputopo, cputopo);
+
+    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
 
     if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
-        return ret;
+        goto out;
 
-    memcpy(put_info, &sysctl.u.cputopoinfo, sizeof(*put_info));
+    *max_cpus = sysctl.u.cputopoinfo.max_cpu_index + 1;
 
-    return 0;
+out:
+    xc_hypercall_bounce_post(xch, cputopo);
+
+    return ret;
 }
 
 int xc_numainfo(xc_interface *xch,
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index b05c0bb..f8d64c2 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5072,38 +5072,23 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 {
     GC_INIT(ctx);
-    xc_cputopoinfo_t tinfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
+    xc_cputopo_t *cputopo;
     libxl_cputopology *ret = NULL;
-    int i;
-    int max_cpus;
+    int i, max_cpus;
 
     max_cpus = libxl_get_max_cpus(ctx);
-    if (max_cpus < 0)
-    {
+    if (max_cpus < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
-        ret = NULL;
         goto out;
     }
 
-    cputopo = xc_hypercall_buffer_alloc(ctx->xch, cputopo,
-                                        sizeof(*cputopo) * max_cpus);
-    if (cputopo == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");
-        goto fail;
-    }
+    cputopo = libxl__zalloc(gc, sizeof(*cputopo) * max_cpus);
 
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = max_cpus - 1;
-    if (xc_cputopoinfo(ctx->xch, &tinfo) != 0) {
+    if (xc_cputopoinfo(ctx->xch, &max_cpus, cputopo) != 0) {
         LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "CPU topology info hypercall failed");
-        goto fail;
+        goto out;
     }
 
-    if (tinfo.max_cpu_index < max_cpus - 1)
-        max_cpus = tinfo.max_cpu_index + 1;
-
     ret = libxl__zalloc(NOGC, sizeof(libxl_cputopology) * max_cpus);
 
     for (i = 0; i < max_cpus; i++) {
@@ -5115,11 +5100,8 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 #undef V
     }
 
-fail:
-    xc_hypercall_buffer_free(ctx->xch, cputopo);
+    *nb_cpu_out = max_cpus;
 
-    if (ret)
-        *nb_cpu_out = max_cpus;
  out:
     GC_FREE;
     return ret;
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index f7fe620..1d1eb40 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -355,12 +355,11 @@ static void signal_int_handler(int signo)
     int i, j, k;
     struct timeval tv;
     int cx_cap = 0, px_cap = 0;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-    xc_cputopoinfo_t info = { 0 };
-
-    cputopo = xc_hypercall_buffer_alloc(xc_handle, cputopo,
-                                        sizeof(*cputopo) * MAX_NR_CPU);
+    xc_cputopo_t *cputopo;
+    int max_cpus;
 
+    max_cpus = MAX_NR_CPU;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
     {
 	fprintf(stderr, "failed to allocate hypercall buffers\n");
@@ -445,29 +444,26 @@ static void signal_int_handler(int signo)
             printf("  Avg freq\t%d\tKHz\n", avgfreq[i]);
     }
 
-    set_xen_guest_handle(info.cputopo, cputopo);
-    info.max_cpu_index = MAX_NR_CPU - 1;
-
-    if ( cx_cap && !xc_cputopoinfo(xc_handle, &info) )
+    if ( cx_cap && !xc_cputopoinfo(xc_handle, &max_cpus, cputopo) )
     {
         uint32_t socket_ids[MAX_NR_CPU];
         uint32_t core_ids[MAX_NR_CPU];
         uint32_t socket_nr = 0;
         uint32_t core_nr = 0;
 
-        if ( info.max_cpu_index > MAX_NR_CPU - 1 )
-            info.max_cpu_index = MAX_NR_CPU - 1;
+        if ( max_cpus > MAX_NR_CPU )
+            max_cpus = MAX_NR_CPU;
         /* check validity */
-        for ( i = 0; i <= info.max_cpu_index; i++ )
+        for ( i = 0; i < max_cpus; i++ )
         {
             if ( cputopo[i].core == INVALID_CORE_ID ||
                  cputopo[i].socket == INVALID_SOCKET_ID )
                 break;
         }
-        if ( i > info.max_cpu_index )
+        if ( i >= max_cpus )
         {
             /* find socket nr & core nr per socket */
-            for ( i = 0; i <= info.max_cpu_index; i++ )
+            for ( i = 0; i < max_cpus; i++ )
             {
                 for ( j = 0; j < socket_nr; j++ )
                     if ( cputopo[i].socket == socket_ids[j] )
@@ -494,7 +490,7 @@ static void signal_int_handler(int signo)
                 unsigned int n;
                 uint64_t res;
 
-                for ( j = 0; j <= info.max_cpu_index; j++ )
+                for ( j = 0; j < max_cpus; j++ )
                 {
                     if ( cputopo[j].socket == socket_ids[i] )
                         break;
@@ -513,7 +509,7 @@ static void signal_int_handler(int signo)
                 }
                 for ( k = 0; k < core_nr; k++ )
                 {
-                    for ( j = 0; j <= info.max_cpu_index; j++ )
+                    for ( j = 0; j < max_cpus; j++ )
                     {
                         if ( cputopo[j].socket == socket_ids[i] &&
                              cputopo[j].core == core_ids[k] )
@@ -551,7 +547,7 @@ static void signal_int_handler(int signo)
     free(sum);
     free(avgfreq);
 out:
-    xc_hypercall_buffer_free(xc_handle, cputopo);
+    free(cputopo);
     xc_interface_close(xc_handle);
     exit(0);
 }
@@ -958,22 +954,19 @@ void scaling_governor_func(int argc, char *argv[])
 
 void cpu_topology_func(int argc, char *argv[])
 {
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-    xc_cputopoinfo_t info = { 0 };
+    xc_cputopo_t *cputopo;
+    int max_cpus;
     int i, rc = ENOMEM;
 
-    cputopo = xc_hypercall_buffer_alloc(xc_handle, cputopo,
-                                        sizeof(*cputopo) * MAX_NR_CPU);
+    max_cpus = MAX_NR_CPU;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
     {
 	fprintf(stderr, "failed to allocate hypercall buffers\n");
 	goto out;
     }
 
-    set_xen_guest_handle(info.cputopo, cputopo);
-    info.max_cpu_index = MAX_NR_CPU-1;
-
-    if ( xc_cputopoinfo(xc_handle, &info) )
+    if ( xc_cputopoinfo(xc_handle, &max_cpus, cputopo) )
     {
         rc = errno;
         fprintf(stderr, "Cannot get Xen CPU topology (%d - %s)\n",
@@ -981,11 +974,11 @@ void cpu_topology_func(int argc, char *argv[])
         goto out;
     }
 
-    if ( info.max_cpu_index > (MAX_NR_CPU-1) )
-        info.max_cpu_index = MAX_NR_CPU-1;
+    if ( max_cpus > MAX_NR_CPU )
+        max_cpus = MAX_NR_CPU;
 
     printf("CPU\tcore\tsocket\tnode\n");
-    for ( i = 0; i <= info.max_cpu_index; i++ )
+    for ( i = 0; i < max_cpus; i++ )
     {
         if ( cputopo[i].core == INVALID_CORE_ID )
             continue;
@@ -994,7 +987,7 @@ void cpu_topology_func(int argc, char *argv[])
     }
     rc = 0;
 out:
-    xc_hypercall_buffer_free(xc_handle, cputopo);
+    free(cputopo);
     if ( rc )
         exit(rc);
 }
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 4275968..6e49dc5 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -1221,31 +1221,24 @@ static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds)
 static PyObject *pyxc_topologyinfo(XcObject *self)
 {
 #define MAX_CPU_INDEX 255
-    xc_cputopoinfo_t tinfo = { 0 };
-    int i, max_cpu_index;
+    xc_cputopo_t *cputopo;
+    int i, max_cpus;
     PyObject *ret_obj = NULL;
     PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
 
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-
-    cputopo = xc_hypercall_buffer_alloc(self->xc_handle, cputopo, sizeof(*cputopo) * (MAX_CPU_INDEX+1));
+    max_cpus = MAX_CPU_INDEX + 1;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
 	goto out;
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = MAX_CPU_INDEX;
 
-    if ( xc_cputopoinfo(self->xc_handle, &tinfo) != 0 )
+    if ( xc_cputopoinfo(self->xc_handle, &max_cpus, cputopo) != 0 )
         goto out;
 
-    max_cpu_index = tinfo.max_cpu_index;
-    if ( max_cpu_index > MAX_CPU_INDEX )
-        max_cpu_index = MAX_CPU_INDEX;
-
     /* Construct cpu-to-* lists. */
     cpu_to_core_obj = PyList_New(0);
     cpu_to_socket_obj = PyList_New(0);
     cpu_to_node_obj = PyList_New(0);
-    for ( i = 0; i <= max_cpu_index; i++ )
+    for ( i = 0; i < max_cpus; i++ )
     {
         if ( cputopo[i].core == INVALID_CORE_ID )
         {
@@ -1281,7 +1274,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
         }
     }
 
-    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpu_index);
+    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpus - 1);
 
     PyDict_SetItemString(ret_obj, "cpu_to_core", cpu_to_core_obj);
     Py_DECREF(cpu_to_core_obj);
@@ -1293,7 +1286,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
     Py_DECREF(cpu_to_node_obj);
 
 out:
-    xc_hypercall_buffer_free(self->xc_handle, cputopo);
+    free(cputopo);
     return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
 #undef MAX_CPU_INDEX
 }
-- 
1.7.1

  parent reply	other threads:[~2015-02-09 20:04 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 20:04 [PATCH v3 0/7] Display IO topology when PXM data is available (plus some cleanup) Boris Ostrovsky
2015-02-09 20:04 ` [PATCH v3 1/7] x86/numa: Make use of NUMA_NO_NODE consistent Boris Ostrovsky
2015-02-10 10:41   ` Andrew Cooper
2015-02-10 11:39   ` Jan Beulich
     [not found]   ` <54D9FBE7020000780005E91E@mail.emea.novell.com>
2015-02-10 14:55     ` Boris Ostrovsky
     [not found]   ` <54D9E076.1080604@citrix.com>
2015-02-16 13:57     ` Dario Faggioli
2015-02-09 20:04 ` [PATCH v3 2/7] pci: Do not ignore device's PXM information Boris Ostrovsky
2015-02-09 20:04 ` [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient Boris Ostrovsky
2015-02-13 12:26   ` Wei Liu
     [not found]   ` <20150213122609.GU13644@zion.uk.xensource.com>
2015-02-13 14:21     ` Boris Ostrovsky
2015-02-16 14:08   ` Dario Faggioli
2015-02-16 15:55     ` Boris Ostrovsky
2015-02-23 16:40   ` Ian Campbell
     [not found]   ` <1424709653.27930.212.camel@citrix.com>
2015-02-23 16:48     ` Boris Ostrovsky
     [not found]     ` <54EB59F0.2070405@oracle.com>
2015-02-23 16:59       ` Jan Beulich
     [not found]       ` <54EB6A770200007800062BDD@mail.emea.novell.com>
2015-02-23 17:15         ` Ian Campbell
2015-02-09 20:04 ` [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology Boris Ostrovsky
2015-02-10 11:13   ` Andrew Cooper
2015-02-10 14:45     ` Boris Ostrovsky
     [not found]     ` <54DA19A4.8070603@oracle.com>
2015-02-10 14:54       ` Andrew Cooper
     [not found]       ` <54DA1BC1.2030205@citrix.com>
2015-02-10 15:06         ` Boris Ostrovsky
     [not found]         ` <54DA1E6D.2010401@oracle.com>
2015-02-10 16:30           ` Jan Beulich
     [not found]           ` <54DA322B02000078000C8167@mail.emea.novell.com>
2015-02-10 16:33             ` Andrew Cooper
2015-02-09 20:04 ` Boris Ostrovsky [this message]
2015-02-10 11:23   ` [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc Andrew Cooper
2015-02-10 14:48     ` Boris Ostrovsky
2015-02-16 14:22   ` Dario Faggioli
2015-02-23 16:44   ` Ian Campbell
     [not found]   ` <1424709863.27930.214.camel@citrix.com>
2015-02-23 16:52     ` Boris Ostrovsky
     [not found]     ` <54EB5AC9.7070409@oracle.com>
2015-02-23 17:14       ` Ian Campbell
2015-02-23 17:59         ` Boris Ostrovsky
2015-02-09 20:04 ` [PATCH v3 6/7] libxl/libxc: Move libxl_get_numainfo()'s " Boris Ostrovsky
2015-02-09 20:04 ` [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology Boris Ostrovsky
2015-02-13 12:43   ` Wei Liu
     [not found]   ` <20150213124345.GV13644@zion.uk.xensource.com>
2015-02-13 14:22     ` Boris Ostrovsky
2015-02-16 13:45   ` Dario Faggioli
2015-02-16 15:54     ` Boris Ostrovsky
     [not found]     ` <54E212A3.7000802@oracle.com>
2015-02-16 16:06       ` Dario Faggioli
2015-02-16 16:47       ` Wei Liu
2015-02-23 16:52   ` Ian Campbell
2015-02-10  8:52 ` [PATCH v3 0/7] Display IO topology when PXM data is available (plus some cleanup) Jan Beulich
2015-02-10 11:08   ` Andrew Cooper
2015-02-10 10:26 ` [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology Robert Elz
     [not found] ` <1423512275-6531-3-git-send-email-boris.ostrovsky@oracle.com>
2015-02-10 10:45   ` [PATCH v3 2/7] pci: Do not ignore device's PXM information Andrew Cooper
2015-02-10 11:43   ` Jan Beulich
     [not found] ` <2508.1423564006@perseus.noi.kre.to>
2015-02-10 14:37   ` [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology Boris Ostrovsky
     [not found] ` <1423512275-6531-7-git-send-email-boris.ostrovsky@oracle.com>
2015-02-10 11:45   ` [PATCH v3 6/7] libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management to libxc Andrew Cooper
     [not found]   ` <54D9EF57.7050308@citrix.com>
2015-02-10 14:59     ` Boris Ostrovsky
2015-02-23 16:45   ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423512275-6531-6-git-send-email-boris.ostrovsky@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dario.faggioli@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=port-xen@netbsd.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=ufimtseva@gmail.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.