From: rshriram@cs.ubc.ca
To: xen-devel@lists.xensource.com
Cc: brendan@cs.ubc.ca, ian.jackson@eu.citrix.com, ian.campbell@citrix.com
Subject: [PATCH 1 of 3 V7] tools/libxc: introduce xc_memalign in xc_{minios, linux, solaris, netbsd}.c
Date: Mon, 14 Nov 2011 14:51:42 -0800 [thread overview]
Message-ID: <7e992e479411201fb9a0.1321311102@athos.nss.cs.ubc.ca> (raw)
In-Reply-To: <patchbomb.1321311101@athos.nss.cs.ubc.ca>
# HG changeset patch
# User Shriram Rajagopalan <rshriram@cs.ubc.ca>
# Date 1321309573 28800
# Node ID 7e992e479411201fb9a0356f6f27966de7d48967
# Parent 54a5e994a241a506900ee0e197bb42e5f1d8e759
tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c
Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer
into a global function xc_memalign. 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@cs.ubc.ca>
diff -r 54a5e994a241 -r 7e992e479411 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 Mon Nov 14 14:26:13 2011 -0800
@@ -55,6 +55,18 @@
errno = saved_errno;
}
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+ int ret;
+ void *ptr;
+
+ ret = posix_memalign(&ptr, alignment, size);
+ if (ret != 0 || !ptr)
+ return NULL;
+
+ return ptr;
+}
+
/*
* Local variables:
* mode: C
diff -r 54a5e994a241 -r 7e992e479411 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 Mon Nov 14 14:26:13 2011 -0800
@@ -91,10 +91,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 = xc_memalign(xch, XC_PAGE_SIZE, size);
+ if (!p)
return NULL;
if ( mlock(p, size) < 0 )
diff -r 54a5e994a241 -r 7e992e479411 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 Mon Nov 14 14:26:13 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 xc_memalign(xch, PAGE_SIZE, 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 *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+ return memalign(alignment, size);
+}
+
static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
{
int fd = alloc_fd(FTYPE_GNTMAP);
diff -r 54a5e994a241 -r 7e992e479411 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 Mon Nov 14 14:26:13 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 = xc_memalign(xch, XC_PAGE_SIZE, size);
if (!p)
return NULL;
@@ -378,6 +379,11 @@
errno = saved_errno;
}
+void *xc_memalign(xc_interface *xch, size_t alignment, 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 7e992e479411 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 Mon Nov 14 14:26:13 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 xc_memalign(xch, XC_PAGE_SIZE, 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 *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+ return memalign(alignment, size);
+}
+
static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type)
{
switch ( type )
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Wed Nov 02 17:09:09 2011 +0000
+++ b/tools/libxc/xenctrl.h Mon Nov 14 14:26:13 2011 -0800
@@ -1129,6 +1129,8 @@
uint64_t *time,
xc_hypercall_buffer_t *data);
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
/**
* Memory maps a range within one domain to a local address range. Mappings
* should be unmapped with munmap and should follow the same rules as mmap
next prev parent reply other threads:[~2011-11-14 22:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-14 22:51 [PATCH 0 of 3 V7] libxc: checkpoint compression rshriram
2011-11-14 22:51 ` rshriram [this message]
2011-11-15 8:51 ` [PATCH 1 of 3 V7] tools/libxc: introduce xc_memalign in xc_{minios, linux, solaris, netbsd}.c Ian Campbell
2011-11-14 22:51 ` [PATCH 2 of 3 V7] tools/libxc: Remus Checkpoint Compression rshriram
2011-11-14 22:51 ` [PATCH 3 of 3 V7] remus: command line switch to enable/disable checkpoint compression rshriram
2011-11-18 20:06 ` [PATCH 0 of 3 V7] libxc: " Shriram Rajagopalan
2011-11-29 1:00 ` Shriram Rajagopalan
2011-11-29 16:59 ` Brendan Cully
2011-12-01 15:54 ` Ian Jackson
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=7e992e479411201fb9a0.1321311102@athos.nss.cs.ubc.ca \
--to=rshriram@cs.ubc.ca \
--cc=brendan@cs.ubc.ca \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).