WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 22 of 25] xenpm: use hypercall buffers

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 22 of 25] xenpm: use hypercall buffers
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 22 Oct 2010 15:16:04 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 22 Oct 2010 07:55:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1287756942@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1287756891 -3600
# Node ID de7310bdfe91d9356d5c6fca92daa93f07ab4fb5
# Parent  5daeac9c13b0d728d93e9e30b53bb70bd5e81ee2
xenpm: use hypercall buffers.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 5daeac9c13b0 -r de7310bdfe91 tools/misc/xenpm.c
--- a/tools/misc/xenpm.c        Fri Oct 22 15:14:51 2010 +0100
+++ b/tools/misc/xenpm.c        Fri Oct 22 15:14:51 2010 +0100
@@ -317,15 +317,25 @@ static void signal_int_handler(int signo
     int i, j, k, ret;
     struct timeval tv;
     int cx_cap = 0, px_cap = 0;
-    uint32_t cpu_to_core[MAX_NR_CPU];
-    uint32_t cpu_to_socket[MAX_NR_CPU];
-    uint32_t cpu_to_node[MAX_NR_CPU];
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_core);
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_socket);
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_node);
     xc_topologyinfo_t info = { 0 };
+
+    cpu_to_core = xc_hypercall_buffer_alloc(xc_handle, cpu_to_core, 
sizeof(*cpu_to_core) * MAX_NR_CPU);
+    cpu_to_socket = xc_hypercall_buffer_alloc(xc_handle, cpu_to_socket, 
sizeof(*cpu_to_socket) * MAX_NR_CPU);
+    cpu_to_node = xc_hypercall_buffer_alloc(xc_handle, cpu_to_node, 
sizeof(*cpu_to_node) * MAX_NR_CPU);
+
+    if ( cpu_to_core == NULL || cpu_to_socket == NULL || cpu_to_node == NULL )
+    {
+       fprintf(stderr, "failed to allocate hypercall buffers\n");
+       goto out;
+    }
 
     if ( gettimeofday(&tv, NULL) == -1 )
     {
         fprintf(stderr, "failed to get timeofday\n");
-        return ;
+        goto out ;
     }
     usec_end = tv.tv_sec * 1000000UL + tv.tv_usec;
 
@@ -385,9 +395,9 @@ static void signal_int_handler(int signo
         }
     }
 
-    set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
-    set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
-    set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
+    xc_set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
+    xc_set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
+    xc_set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
     info.max_cpu_index = MAX_NR_CPU - 1;
 
     ret = xc_topologyinfo(xc_handle, &info);
@@ -485,6 +495,10 @@ static void signal_int_handler(int signo
     free(pxstat);
     free(sum);
     free(avgfreq);
+out:
+    xc_hypercall_buffer_free(xc_handle, cpu_to_core);
+    xc_hypercall_buffer_free(xc_handle, cpu_to_socket);
+    xc_hypercall_buffer_free(xc_handle, cpu_to_node);
     xc_interface_close(xc_handle);
     exit(0);
 }
@@ -934,21 +948,31 @@ out:
 
 void cpu_topology_func(int argc, char *argv[])
 {
-    uint32_t cpu_to_core[MAX_NR_CPU];
-    uint32_t cpu_to_socket[MAX_NR_CPU];
-    uint32_t cpu_to_node[MAX_NR_CPU];
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_core);
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_socket);
+    DECLARE_HYPERCALL_BUFFER(uint32_t, cpu_to_node);
     xc_topologyinfo_t info = { 0 };
     int i;
 
-    set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
-    set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
-    set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
+    cpu_to_core = xc_hypercall_buffer_alloc(xc_handle, cpu_to_core, 
sizeof(*cpu_to_core) * MAX_NR_CPU);
+    cpu_to_socket = xc_hypercall_buffer_alloc(xc_handle, cpu_to_socket, 
sizeof(*cpu_to_socket) * MAX_NR_CPU);
+    cpu_to_node = xc_hypercall_buffer_alloc(xc_handle, cpu_to_node, 
sizeof(*cpu_to_node) * MAX_NR_CPU);
+
+    if ( cpu_to_core == NULL || cpu_to_socket == NULL || cpu_to_node == NULL )
+    {
+       fprintf(stderr, "failed to allocate hypercall buffers\n");
+       goto out;
+    }
+
+    xc_set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
+    xc_set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
+    xc_set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
     info.max_cpu_index = MAX_NR_CPU-1;
 
     if ( xc_topologyinfo(xc_handle, &info) )
     {
         printf("Can not get Xen CPU topology: %d\n", errno);
-        return;
+        goto out;
     }
 
     if ( info.max_cpu_index > (MAX_NR_CPU-1) )
@@ -962,6 +986,10 @@ void cpu_topology_func(int argc, char *a
         printf("CPU%d\t %d\t %d\t %d\n",
                i, cpu_to_core[i], cpu_to_socket[i], cpu_to_node[i]);
     }
+out:
+    xc_hypercall_buffer_free(xc_handle, cpu_to_core);
+    xc_hypercall_buffer_free(xc_handle, cpu_to_socket);
+    xc_hypercall_buffer_free(xc_handle, cpu_to_node);
 }
 
 void set_sched_smt_func(int argc, char *argv[])

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>