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 1 of 3 V6] tools/libxc: introduce page_aligned_alloc

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 1 of 3 V6] tools/libxc: introduce page_aligned_alloc in xc_{minios, linux, solaris, netbsd}.c
From: rshriram@xxxxxxxxx
Date: Tue, 08 Nov 2011 14:39:46 -0800
Cc: brendan@xxxxxxxxx, ian.jackson@xxxxxxxxxxxxx, ian.campbell@xxxxxxxxxx
Delivery-date: Tue, 08 Nov 2011 14:43:21 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1320791985@xxxxxxxxxxxxxxxxxxx>
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>
References: <patchbomb.1320791985@xxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4.3
# HG changeset patch
# User Shriram Rajagopalan <rshriram@xxxxxxxxx>
# Date 1320791162 28800
# Node ID 58a24a7d4b87540692363b081dd72f62a6d380dd
# Parent  54a5e994a241a506900ee0e197bb42e5f1d8e759
tools/libxc: introduce page_aligned_alloc in xc_{minios,linux,solaris,netbsd}.c

Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer
into a global function page_aligned_alloc. This API is also used by Remus
compression code to allocate compression caches that need to be page aligned.

Signed-off-by: Shriram Rajagopalan <rshriram@xxxxxxxxx>

diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_linux.c    Tue Nov 08 14:26:02 2011 -0800
@@ -55,6 +55,18 @@
     errno = saved_errno;
 }
 
+void *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, XC_PAGE_SIZE, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux_osdep.c
--- a/tools/libxc/xc_linux_osdep.c      Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_linux_osdep.c      Tue Nov 08 14:26:02 2011 -0800
@@ -36,9 +36,17 @@
 #include <xen/sys/gntdev.h>
 #include <xen/sys/gntalloc.h>
 
+#include "xc_private.h"
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+/* We need xc_private.h for page_aligned_alloc().
+ * xc_private.h already defines ERROR and PERROR.
+ * So we undef it and redefine it here.
+ */
+#undef ERROR
+#undef PERROR
+
 #define ERROR(_m, _a...)  xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## 
_a )
 #define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \
                   " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
@@ -91,10 +99,9 @@
 {
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
-    int ret;
 
-    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
-    if (ret != 0 || !p)
+    p = page_aligned_alloc(xch, size);
+    if (!p)
         return NULL;
 
     if ( mlock(p, size) < 0 )
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c   Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_minios.c   Tue Nov 08 14:26:02 2011 -0800
@@ -73,7 +73,7 @@
 
 static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
-    return memalign(PAGE_SIZE, npages * PAGE_SIZE);
+    return page_aligned_alloc(xch, npages * PAGE_SIZE);
 }
 
 static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, void *ptr, int npages)
@@ -437,6 +437,11 @@
         fsync(fd);
 }
 
+void *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    return memalign(PAGE_SIZE, size);
+}
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c   Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_netbsd.c   Tue Nov 08 14:26:02 2011 -0800
@@ -71,8 +71,9 @@
 static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
     size_t size = npages * XC_PAGE_SIZE;
-    void *p = valloc(size);
+    void *p;
 
+    p = page_aligned_alloc(xch, size);
     if (!p)
         return NULL;
 
@@ -378,6 +379,11 @@
     errno = saved_errno;
 }
 
+void *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    return valloc(size);
+}
+
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_private.h  Tue Nov 08 14:26:02 2011 -0800
@@ -302,6 +302,9 @@
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush);
 
+/* Encapsulates memalign style calls for different OSes. */
+void *page_aligned_alloc(xc_interface *xch, size_t size);
+
 #define MAX_MMU_UPDATES 1024
 struct xc_mmu {
     mmu_update_t updates[MAX_MMU_UPDATES];
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_solaris.c
--- a/tools/libxc/xc_solaris.c  Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xc_solaris.c  Tue Nov 08 14:26:02 2011 -0800
@@ -70,7 +70,7 @@
 
 static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
-    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return page_aligned_alloc(xch, npages * XC_PAGE_SIZE);
 }
 
 static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, void *ptr, int npages)
@@ -314,6 +314,11 @@
     // TODO: Implement for Solaris!
 }
 
+void *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    return memalign(XC_PAGE_SIZE, size);
+}
+
 static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )

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