Skip to contentSkip to conversation

oslib-posix: check for posix_memalign in configure script

PATCH Applied Andreas Gustafsson 4 participants 7 messages Jan 4, 2018 – Feb 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oslib-posix: check for posix_memalign in configure script

Check for the presence of posix_memalign() in the configure script, not using "defined(_POSIX_C_SOURCE) && !defined(__sun__)". This lets qemu use posix_memalign() on NetBSD versions that have it, instead of falling back to valloc() which is wasteful when the required alignment is smaller than a page.

---
 configure          | 19 +++++++++++++++++++
 util/oslib-posix.c |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)
configure +19 -0
index 100309c33f..9f8580332a 100755
@@ -4573,6 +4573,21 @@ if compile_prog "" "" ; then
     posix_madvise=yes
 fi
 
+##########################################
+# check if we have posix_memalign()
+
+posix_memalign=no
+cat > $TMPC << EOF
+#include <stdlib.h>
+int main(void) {
+    void *p;
+    return posix_memalign(&p, 8, 8);
+}
+EOF
+if compile_prog "" "" ; then
+    posix_memalign=yes
+fi
+
 ##########################################
 # check if we have posix_syslog
 
@@ -5542,6 +5557,7 @@ echo "preadv support    $preadv"
 echo "fdatasync         $fdatasync"
 echo "madvise           $madvise"
 echo "posix_madvise     $posix_madvise"
+echo "posix_memalign    $posix_memalign"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
@@ -6015,6 +6031,9 @@ fi
 if test "$posix_madvise" = "yes" ; then
   echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
 fi
+if test "$posix_memalign" = "yes" ; then
+  echo "CONFIG_POSIX_MEMALIGN=y" >> $config_host_mak
+fi
 
 if test "$spice" = "yes" ; then
   echo "CONFIG_SPICE=y" >> $config_host_mak
util/oslib-posix.c +1 -1
index 77369c92ce..4655bc1f89 100644
@@ -105,7 +105,7 @@ void *qemu_try_memalign(size_t alignment, size_t size)
         alignment = sizeof(void*);
     }
 
-#if defined(_POSIX_C_SOURCE) && !defined(__sun__)
+#if defined(CONFIG_POSIX_MEMALIGN)
     int ret;
     ret = posix_memalign(&ptr, alignment, size);
     if (ret != 0) {
Signature · 1 line
2.15.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andreas Gustafsson

Check for the presence of posix_memalign() in the configure script, not using "defined(_POSIX_C_SOURCE) && !defined(__sun__)". This lets qemu use posix_memalign() on NetBSD versions that have it, instead of falling back to valloc() which is wasteful when the required alignment is smaller than a page.

Quoted 63 lines
---
 configure          | 19 +++++++++++++++++++
 util/oslib-posix.c |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)
configure +19 -0
index 100309c33f..9f8580332a 100755
@@ -4573,6 +4573,21 @@ if compile_prog "" "" ; then
     posix_madvise=yes
 fi
 
+##########################################
+# check if we have posix_memalign()
+
+posix_memalign=no
+cat > $TMPC << EOF
+#include <stdlib.h>
+int main(void) {
+    void *p;
+    return posix_memalign(&p, 8, 8);
+}
+EOF
+if compile_prog "" "" ; then
+    posix_memalign=yes
+fi
+
 ##########################################
 # check if we have posix_syslog
 
@@ -5542,6 +5557,7 @@ echo "preadv support    $preadv"
 echo "fdatasync         $fdatasync"
 echo "madvise           $madvise"
 echo "posix_madvise     $posix_madvise"
+echo "posix_memalign    $posix_memalign"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
@@ -6015,6 +6031,9 @@ fi
 if test "$posix_madvise" = "yes" ; then
   echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
 fi
+if test "$posix_memalign" = "yes" ; then
+  echo "CONFIG_POSIX_MEMALIGN=y" >> $config_host_mak
+fi
 
 if test "$spice" = "yes" ; then
   echo "CONFIG_SPICE=y" >> $config_host_mak
util/oslib-posix.c +1 -1
index 77369c92ce..4655bc1f89 100644
@@ -105,7 +105,7 @@ void *qemu_try_memalign(size_t alignment, size_t size)
         alignment = sizeof(void*);
     }
 
-#if defined(_POSIX_C_SOURCE) && !defined(__sun__)
+#if defined(CONFIG_POSIX_MEMALIGN)
     int ret;
     ret = posix_memalign(&ptr, alignment, size);
     if (ret != 0) {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andreas Gustafsson
Quoted 11 lines · Andreas Gustafsson

Check for the presence of posix_memalign() in the configure script, not using "defined(_POSIX_C_SOURCE) && !defined(__sun__)". This lets qemu use posix_memalign() on NetBSD versions that have it, instead of falling back to valloc() which is wasteful when the required alignment is smaller than a page.

---
 configure          | 19 +++++++++++++++++++
 util/oslib-posix.c |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)

Can we put this through the -trivial tree? (cc'd)

thanks
-- PMM

#3 lore raw
Quoted 1 line · Peter Maydell

Can we put this through the -trivial tree? (cc'd)

I'm not sufficiently familiar with the intenal workflows of the qemu project to give a meaningful answer to that question.

Signature · 1 line
Andreas Gustafsson, [email protected]
#4 lore raw
Quoted 5 lines · Andreas Gustafsson
Quoted 1 line · Peter Maydell

Can we put this through the -trivial tree? (cc'd)

I'm not sufficiently familiar with the intenal workflows of the qemu project to give a meaningful answer to that question.

Sorry, I should have been clearer, that question was aimed at the qemu-trivial queue maintainers.

thanks
-- PMM

#5 lore raw
In reply to Andreas Gustafsson
Quoted 6 lines · Andreas Gustafsson
Quoted 1 line · Peter Maydell

Can we put this through the -trivial tree? (cc'd)

I'm not sufficiently familiar with the intenal workflows of the qemu project to give a meaningful answer to that question.

I don't maintain a NetBSD merge queue and NetBSD patches go through other developers (e.g. qemu-trivial).

I would comaintain a BSD merge queue, but so far there are no active volunteers from other BSDs.

#6 lore raw
In reply to Andreas Gustafsson
Quoted 5 lines · Andreas Gustafsson

Check for the presence of posix_memalign() in the configure script, not using "defined(_POSIX_C_SOURCE) && !defined(__sun__)". This lets qemu use posix_memalign() on NetBSD versions that have it, instead of falling back to valloc() which is wasteful when the required alignment is smaller than a page.

Applied to -trivial, thanks!

/mjt