From 4513025a87902aa4469b15e8097beb7590da7b78 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 22 Oct 2010 15:14:51 +0100 Subject: libxc: convert sysctl interfaces over to hypercall buffers Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- tools/misc/xenlockprof.c | 30 +++++++----------------------- tools/misc/xenperf.c | 38 +++++++++----------------------------- 2 files changed, 16 insertions(+), 52 deletions(-) (limited to 'tools/misc') diff --git a/tools/misc/xenlockprof.c b/tools/misc/xenlockprof.c index 0235ab0150..41fcb792cc 100644 --- a/tools/misc/xenlockprof.c +++ b/tools/misc/xenlockprof.c @@ -18,22 +18,6 @@ #include #include -static int lock_pages(void *addr, size_t len) -{ - int e = 0; -#ifndef __sun__ - e = mlock(addr, len); -#endif - return (e); -} - -static void unlock_pages(void *addr, size_t len) -{ -#ifndef __sun__ - munlock(addr, len); -#endif -} - int main(int argc, char *argv[]) { xc_interface *xc_handle; @@ -41,7 +25,7 @@ int main(int argc, char *argv[]) uint64_t time; double l, b, sl, sb; char name[60]; - xc_lockprof_data_t *data; + DECLARE_HYPERCALL_BUFFER(xc_lockprof_data_t, data); if ( (argc > 2) || ((argc == 2) && (strcmp(argv[1], "-r") != 0)) ) { @@ -78,24 +62,22 @@ int main(int argc, char *argv[]) } n += 32; /* just to be sure */ - data = malloc(sizeof(*data) * n); - if ( (data == NULL) || (lock_pages(data, sizeof(*data) * n) != 0) ) + data = xc_hypercall_buffer_alloc(xc_handle, data, sizeof(*data) * n); + if ( data == NULL ) { - fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n", + fprintf(stderr, "Could not allocate buffers: %d (%s)\n", errno, strerror(errno)); return 1; } i = n; - if ( xc_lockprof_query(xc_handle, &i, &time, data) != 0 ) + if ( xc_lockprof_query(xc_handle, &i, &time, HYPERCALL_BUFFER(data)) != 0 ) { fprintf(stderr, "Error getting profile records: %d (%s)\n", errno, strerror(errno)); return 1; } - unlock_pages(data, sizeof(*data) * n); - if ( i > n ) { printf("data incomplete, %d records are missing!\n\n", i - n); @@ -132,5 +114,7 @@ int main(int argc, char *argv[]) printf("total locked time: %20.9fs\n", sl); printf("total blocked time: %20.9fs\n", sb); + xc_hypercall_buffer_free(xc_handle, data); + return 0; } diff --git a/tools/misc/xenperf.c b/tools/misc/xenperf.c index 583abc1f82..07e584a5eb 100644 --- a/tools/misc/xenperf.c +++ b/tools/misc/xenperf.c @@ -68,28 +68,12 @@ const char *hypercall_name_table[64] = }; #undef X -static int lock_pages(void *addr, size_t len) -{ - int e = 0; -#ifndef __sun__ - e = mlock(addr, len); -#endif - return (e); -} - -static void unlock_pages(void *addr, size_t len) -{ -#ifndef __sun__ - munlock(addr, len); -#endif -} - int main(int argc, char *argv[]) { int i, j; xc_interface *xc_handle; - xc_perfc_desc_t *pcd; - xc_perfc_val_t *pcv; + DECLARE_HYPERCALL_BUFFER(xc_perfc_desc_t, pcd); + DECLARE_HYPERCALL_BUFFER(xc_perfc_val_t, pcv); xc_perfc_val_t *val; int num_desc, num_val; unsigned int sum, reset = 0, full = 0, pretty = 0; @@ -154,29 +138,23 @@ int main(int argc, char *argv[]) return 1; } - pcd = malloc(sizeof(*pcd) * num_desc); - pcv = malloc(sizeof(*pcv) * num_val); + pcd = xc_hypercall_buffer_alloc(xc_handle, pcd, sizeof(*pcd) * num_desc); + pcv = xc_hypercall_buffer_alloc(xc_handle, pcv, sizeof(*pcv) * num_val); - if ( pcd == NULL - || lock_pages(pcd, sizeof(*pcd) * num_desc) != 0 - || pcv == NULL - || lock_pages(pcv, sizeof(*pcv) * num_val) != 0) + if ( pcd == NULL || pcv == NULL) { - fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n", + fprintf(stderr, "Could not allocate buffers: %d (%s)\n", errno, strerror(errno)); exit(-1); } - if ( xc_perfc_query(xc_handle, pcd, pcv) != 0 ) + if ( xc_perfc_query(xc_handle, HYPERCALL_BUFFER(pcd), HYPERCALL_BUFFER(pcv)) != 0 ) { fprintf(stderr, "Error getting perf counter: %d (%s)\n", errno, strerror(errno)); return 1; } - unlock_pages(pcd, sizeof(*pcd) * num_desc); - unlock_pages(pcv, sizeof(*pcv) * num_val); - val = pcv; for ( i = 0; i < num_desc; i++ ) { @@ -221,5 +199,7 @@ int main(int argc, char *argv[]) val += pcd[i].nr_vals; } + xc_hypercall_buffer_free(xc_handle, pcd); + xc_hypercall_buffer_free(xc_handle, pcv); return 0; } -- cgit v1.2.3