All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Egger <Christoph.Egger@amd.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [PATCH] libxc: lzma build fix
Date: Wed, 26 Jan 2011 18:27:24 +0100	[thread overview]
Message-ID: <201101261827.25727.Christoph.Egger@amd.com> (raw)
In-Reply-To: <19776.18635.63919.190329@mariner.uk.xensource.com>

[-- Attachment #1: Type: text/plain, Size: 885 bytes --]

On Wednesday 26 January 2011 17:16:11 Ian Jackson wrote:
> Christoph Egger writes ("[Xen-devel] [PATCH] libxc: lzma build fix"):
> > Attached patch lets libxc build with lzma support on NetBSD.
> > NetBSD doesn't have sysconf(_SC_PHYS_PAGES).
>
> Can you please break this out into separate os-dependent code in an
> appropriate different file ?  These kind of #ifdefs break up the code
> and make it hard to see what's going on.

Yes. Attached patch factors physmem() out into os-dependent files
and renamed it to xc_get_physmem() to not pollute the namespace.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>


-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

[-- Attachment #2: xen_libxc_lzma.diff --]
[-- Type: text/x-diff, Size: 3698 bytes --]

diff -r c332e775ba53 tools/libxc/xc_dom_bzimageloader.c
--- a/tools/libxc/xc_dom_bzimageloader.c	Wed Jan 26 17:44:59 2011 +0100
+++ b/tools/libxc/xc_dom_bzimageloader.c	Wed Jan 26 18:23:17 2011 +0100
@@ -140,27 +140,6 @@ static int xc_try_bzip2_decode(
 
 #include <lzma.h>
 
-static uint64_t physmem(void)
-{
-    uint64_t ret = 0;
-    const long pagesize = sysconf(_SC_PAGESIZE);
-    const long pages = sysconf(_SC_PHYS_PAGES);
-
-    if ( (pagesize != -1) || (pages != -1) )
-    {
-        /*
-         * According to docs, pagesize * pages can overflow.
-         * Simple case is 32-bit box with 4 GiB or more RAM,
-         * which may report exactly 4 GiB of RAM, and "long"
-         * being 32-bit will overflow. Casting to uint64_t
-         * hopefully avoids overflows in the near future.
-         */
-        ret = (uint64_t)(pagesize) * (uint64_t)(pages);
-    }
-
-    return ret;
-}
-
 static int xc_try_lzma_decode(
     struct xc_dom_image *dom, void **blob, size_t *size)
 {
@@ -173,7 +152,7 @@ static int xc_try_lzma_decode(
     int outsize;
     const char *msg;
 
-    ret = lzma_alone_decoder(&stream, physmem() / 3);
+    ret = lzma_alone_decoder(&stream, xc_get_physmem() / 3);
     if ( ret != LZMA_OK )
     {
         DOMPRINTF("LZMA: Failed to init stream decoder");
diff -r c332e775ba53 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c	Wed Jan 26 17:44:59 2011 +0100
+++ b/tools/libxc/xc_linux.c	Wed Jan 26 18:23:17 2011 +0100
@@ -55,6 +55,27 @@ void discard_file_cache(xc_interface *xc
     errno = saved_errno;
 }
 
+uint64_t xc_get_physmem(void)
+{
+    uint64_t ret = 0;
+    const long pagesize = sysconf(_SC_PAGESIZE);
+    const long pages = sysconf(_SC_PHYS_PAGES);
+
+    if ( (pagesize != -1) || (pages != -1) )
+    {
+        /*
+         * According to docs, pagesize * pages can overflow.
+         * Simple case is 32-bit box with 4 GiB or more RAM,
+         * which may report exactly 4 GiB of RAM, and "long"
+         * being 32-bit will overflow. Casting to uint64_t
+         * hopefully avoids overflows in the near future.
+         */
+        ret = (uint64_t)(pagesize) * (uint64_t)(pages);
+    }
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r c332e775ba53 tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c	Wed Jan 26 17:44:59 2011 +0100
+++ b/tools/libxc/xc_netbsd.c	Wed Jan 26 18:23:17 2011 +0100
@@ -23,6 +23,9 @@
 #include <xen/sys/evtchn.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/sysctl.h>
 
 static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch)
 {
@@ -351,6 +354,24 @@ void discard_file_cache(xc_interface *xc
     errno = saved_errno;
 }
 
+uint64_t xc_get_physmem(void)
+{
+    int mib[2], rc;
+    size_t len;
+    uint64_t physmem;
+
+    mib[0] = CTL_HW;
+    mib[1] = HW_PHYSMEM64;
+    rc = sysctl(mib, 2, &physmem, &len, NULL, 0);
+
+    if (rc == -1) {
+        /* PERROR("%s: Failed to get hw.physmem64: %s\n", strerror(errno)); */
+        return 0;
+    }
+
+    return physmem;
+}
+
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
diff -r c332e775ba53 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h	Wed Jan 26 17:44:59 2011 +0100
+++ b/tools/libxc/xc_private.h	Wed Jan 26 18:23:17 2011 +0100
@@ -275,6 +275,9 @@ void bitmap_byte_to_64(uint64_t *lp, con
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush);
 
+/* How much physical RAM is available? */
+uint64_t xc_get_physmem(void);
+
 #define MAX_MMU_UPDATES 1024
 struct xc_mmu {
     mmu_update_t updates[MAX_MMU_UPDATES];

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

  reply	other threads:[~2011-01-26 17:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26 15:22 [PATCH] libxc: lzma build fix Christoph Egger
2011-01-26 16:16 ` Ian Jackson
2011-01-26 17:27   ` Christoph Egger [this message]
2011-01-27 19:04     ` Ian Jackson
2011-01-27 19:54     ` Ian Campbell
2011-01-28 11:45       ` Ian Jackson
2011-01-28 18:51         ` Ian Jackson
2011-01-28 19:14           ` Ian Campbell
2011-01-28 19:38             ` Ian Jackson
2011-02-11 13:41           ` Jan Beulich
2011-02-11 13:53             ` Ian Campbell
2011-02-11 17:49               ` 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=201101261827.25727.Christoph.Egger@amd.com \
    --to=christoph.egger@amd.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.