Re: [Powertop] [PATCH v3] conditionally disable pci if not supported

Rajagopal Venkat <rajagopal.venkat at linaro.org> Fri, 13 Jul 2012 10:32:21 +0530
Newsgroups dev.linux.lists.powertop
Message-ID <CA+Z25wWbcrkXZYKbeA3Txs7kwh8cX5OfcomHZpWekTQifWV3Kw@mail.gmail.com>
Can someone consider this patch for merge?

On 25 June 2012 22:44, Rajagopal Venkat <rajagopal.venkat(a)linaro.org> wrote:

> disable pci if not supported by host platform. When
> libpci is not found, define a macro which will be
> used for conditional compilation.
>
> Signed-off-by: Rajagopal Venkat <rajagopal.venkat(a)linaro.org>
> ---
>  configure.ac |    5 +++--
>  src/lib.cpp  |   20 ++++++++++++++++++--
>  src/lib.h    |    5 +++++
>  3 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 4da4eea..3cbc7b0 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -48,8 +48,9 @@ AC_CHECK_FUNCS([fdatasync getpagesize gettimeofday
> memmove memset mkdir munmap p
>  AC_SEARCH_LIBS([delwin], [ncursesw ncurses], [], AC_MSG_ERROR([ncurses is
> required but was not found]), [])
>
>  PKG_CHECK_MODULES([PCIUTILS], [libpci],[],[
> -       AC_SEARCH_LIBS([pci_get_dev], [pci], [], AC_MSG_ERROR([libpci is
> required but was not found]), [])
> -])
> +       AC_SEARCH_LIBS([pci_get_dev], [pci], [],
> AC_DEFINE([HAVE_NO_PCI],[1],[Define if pci is not supported]), [])
> +])
> +
>  PKG_CHECK_MODULES([LIBZ], [zlib],[],[
>         AC_SEARCH_LIBS([deflate], [z], [], AC_MSG_ERROR([zlib is required
> but was not found]), [])
>  ])
> diff --git a/src/lib.cpp b/src/lib.cpp
> index 0f87e48..77e49a2 100644
> --- a/src/lib.cpp
> +++ b/src/lib.cpp
> @@ -35,11 +35,13 @@
>  #include <math.h>
>  #include <stdlib.h>
>
> +#include "lib.h"
> +
> +#ifndef HAVE_NO_PCI
>  extern "C" {
>  #include <pci/pci.h>
>  }
> -
> -#include "lib.h"
> +#endif
>
>  #include <stdio.h>
>  #include <stdint.h>
> @@ -266,6 +268,7 @@ void format_watts(double W, char *buffer, unsigned int
> len)
>  }
>
>
> +#ifndef HAVE_NO_PCI
>  static struct pci_access *pci_access;
>
>  char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int
> len)
> @@ -290,6 +293,19 @@ void end_pci_access(void)
>                 pci_free_name_list(pci_access);
>  }
>
> +#else
> +
> +char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int
> len)
> +{
> +       return NULL;
> +}
> +
> +void end_pci_access(void)
> +{
> +}
> +
> +#endif /* HAVE_NO_PCI */
> +
>  int utf_ok = -1;
>
>
> diff --git a/src/lib.h b/src/lib.h
> index 588c023..7093b7f 100644
> --- a/src/lib.h
> +++ b/src/lib.h
> @@ -30,6 +30,11 @@
>  #endif
>  #include <stdint.h>
>
> +/* Include only for Automake builds */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
>  #ifndef DISABLE_I18N
>  #define _(STRING)    gettext(STRING)
>  #else
> --
> 1.7.9.5
>
>
attachment.html (text/html, 3.4 KB)
Can someone consider this patch for merge?<br><br><div class="gmail_quote">On 25 June 2012 22:44, Rajagopal Venkat <span dir="ltr">&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">disable pci if not supported by host platform. When<br>
libpci is not found, define a macro which will be<br>
used for conditional compilation.<br>
<br>
Signed-off-by: Rajagopal Venkat &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;<br>
---<br>
 <a href="http://configure.ac" target="_blank">configure.ac</a> |    5 +++--<br>
 src/lib.cpp  |   20 ++++++++++++++++++--<br>
 src/lib.h    |    5 +++++<br>
 3 files changed, 26 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index 4da4eea..3cbc7b0 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -48,8 +48,9 @@ AC_CHECK_FUNCS([fdatasync getpagesize gettimeofday memmove memset mkdir munmap p<br>
 AC_SEARCH_LIBS([delwin], [ncursesw ncurses], [], AC_MSG_ERROR([ncurses is required but was not found]), [])<br>
<br>
 PKG_CHECK_MODULES([PCIUTILS], [libpci],[],[<br>
-       AC_SEARCH_LIBS([pci_get_dev], [pci], [], AC_MSG_ERROR([libpci is required but was not found]), [])<br>
-])<br>
+       AC_SEARCH_LIBS([pci_get_dev], [pci], [], AC_DEFINE([HAVE_NO_PCI],[1],[Define if pci is not supported]), [])<br>
+])<br>
+<br>
 PKG_CHECK_MODULES([LIBZ], [zlib],[],[<br>
        AC_SEARCH_LIBS([deflate], [z], [], AC_MSG_ERROR([zlib is required but was not found]), [])<br>
 ])<br>
diff --git a/src/lib.cpp b/src/lib.cpp<br>
index 0f87e48..77e49a2 100644<br>
--- a/src/lib.cpp<br>
+++ b/src/lib.cpp<br>
@@ -35,11 +35,13 @@<br>
 #include &lt;math.h&gt;<br>
 #include &lt;stdlib.h&gt;<br>
<br>
+#include &quot;lib.h&quot;<br>
+<br>
+#ifndef HAVE_NO_PCI<br>
 extern &quot;C&quot; {<br>
 #include &lt;pci/pci.h&gt;<br>
 }<br>
-<br>
-#include &quot;lib.h&quot;<br>
+#endif<br>
<br>
 #include &lt;stdio.h&gt;<br>
 #include &lt;stdint.h&gt;<br>
@@ -266,6 +268,7 @@ void format_watts(double W, char *buffer, unsigned int len)<br>
 }<br>
<br>
<br>
+#ifndef HAVE_NO_PCI<br>
 static struct pci_access *pci_access;<br>
<br>
 char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len)<br>
@@ -290,6 +293,19 @@ void end_pci_access(void)<br>
                pci_free_name_list(pci_access);<br>
 }<br>
<br>
+#else<br>
+<br>
+char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len)<br>
+{<br>
+       return NULL;<br>
+}<br>
+<br>
+void end_pci_access(void)<br>
+{<br>
+}<br>
+<br>
+#endif /* HAVE_NO_PCI */<br>
+<br>
 int utf_ok = -1;<br>
<br>
<br>
diff --git a/src/lib.h b/src/lib.h<br>
index 588c023..7093b7f 100644<br>
--- a/src/lib.h<br>
+++ b/src/lib.h<br>
@@ -30,6 +30,11 @@<br>
 #endif<br>
 #include &lt;stdint.h&gt;<br>
<br>
+/* Include only for Automake builds */<br>
+#ifdef HAVE_CONFIG_H<br>
+#include &quot;config.h&quot;<br>
+#endif<br>
+<br>
 #ifndef DISABLE_I18N<br>
 #define _(STRING)    gettext(STRING)<br>
 #else<br>
<span><font color="#888888">--<br>
1.7.9.5<br>
<br>
</font></span></blockquote></div><br>