[gnome-applets] cpufreq: fix build with -lcpupower and kernel 4.7+



commit e48b2d736b8f188daad924dfeb752b3aa41c6691
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Oct 16 13:39:28 2017 +0300

    cpufreq: fix build with -lcpupower and kernel 4.7+
    
    This patch removes --with-cpufreq-lib configure option! Now
    GNOME Applets will try to autodetect cpupower library and will
    fallback to cpufreq if it is not available.
    
    In kernel 4.7+ cpufreq_cpu_exists function was removed, replace
    it with cpupower_is_cpu_online which seems more suitable than
    old function at least according to comment above if statement.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789037

 configure.ac                  |   66 +++++++++++++++++++++++------------------
 cpufreq/src/cpufreq-monitor.c |    8 +++++
 2 files changed, 45 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c87d5cd..b747b2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -432,35 +432,43 @@ AC_ARG_ENABLE(frequency-selector,
                          build frequency selector [@<:@default: yes@:>@]], enable_selector=$enableval,
              enable_selector=yes)
 
-AC_ARG_WITH([cpufreq-lib],
-       AS_HELP_STRING([--with-cpufreq-lib=lib], [library to use for cpufreq applet @<:@default=cpufreq@:>@]),
-       [with_cpufreq_lib=$withval], [with_cpufreq_lib="cpufreq"])
-
-AC_CHECK_HEADER(cpufreq.h, have_libcpufreq=yes, have_libcpufreq=no)
-LIBCPUFREQ_LIBS=
-if test "x$have_libcpufreq" = "xyes"; then
-   LIBCPUFREQ_LIBS="-l$with_cpufreq_lib"
-fi
-AC_SUBST(LIBCPUFREQ_LIBS)
-
-build_cpufreq_applet=no
-
-if test x$disable_cpufreq = xno; then
-   case "${host}" in
-      *linux*)
-         build_cpufreq_applet=yes
-        ;;
-      *)
-         AC_MSG_WARN([${host} is not supported by cpufreq applet, not building])
-        build_cpufreq_applet=no
-        ;;
-   esac
-fi
-
-if test "x$have_libcpufreq" = "xno"; then
-  AC_MSG_WARN([*** cpufreq applet will not be built ***])
-  build_cpufreq_applet=no
-fi
+build_cpufreq_applet=yes
+AS_IF([test "x$disable_cpufreq" = "xno"], [
+  case "${host}" in
+    *linux*)
+      AC_CHECK_HEADER([cpufreq.h], [
+        AC_CHECK_LIB([cpupower], [cpupower_is_cpu_online], [
+          AC_DEFINE([HAVE_IS_CPU_ONLINE], 1,
+                    [Define to 1 if cpupower_is_cpu_online() is available])
+          cpufreq_lib="cpupower"
+        ], [
+          AC_CHECK_LIB([cpupower], [cpufreq_cpu_exists], [
+            cpufreq_lib="cpupower"
+          ], [
+            AC_CHECK_LIB([cpufreq], [cpufreq_cpu_exists], [
+              cpufreq_lib="cpufreq"
+            ], [cpufreq_lib=])
+          ])
+        ])
+
+        AS_IF([test "x$cpufreq_lib" != "x"], [
+          LIBCPUFREQ_LIBS="-l$cpufreq_lib"
+          AC_SUBST([LIBCPUFREQ_LIBS])
+        ], [
+          AC_MSG_WARN([*** cpufreq applet will not be built ***])
+          build_cpufreq_applet=no
+        ])
+      ], [
+        AC_MSG_WARN([*** can't find cpufreq.h, cpufreq applet will not be built ***])
+        build_cpufreq_applet=no
+      ])
+      ;;
+    *)
+      AC_MSG_WARN([${host} is not supported by cpufreq applet, not building])
+      build_cpufreq_applet=no
+      ;;
+  esac
+], [build_cpufreq_applet=no])
 
 AM_CONDITIONAL(BUILD_CPUFREQ_APPLET, test x$build_cpufreq_applet = xyes)
 AM_CONDITIONAL(BUILD_CPUFREQ_SELECTOR, test x$enable_selector = xyes)
diff --git a/cpufreq/src/cpufreq-monitor.c b/cpufreq/src/cpufreq-monitor.c
index 36fbb4e..3704540 100644
--- a/cpufreq/src/cpufreq-monitor.c
+++ b/cpufreq/src/cpufreq-monitor.c
@@ -65,6 +65,10 @@ static guint signals[N_SIGNALS];
 
 G_DEFINE_TYPE (CPUFreqMonitor, cpufreq_monitor, G_TYPE_OBJECT)
 
+#ifdef HAVE_IS_CPU_ONLINE
+extern int cpupower_is_cpu_online (unsigned int cpu);
+#endif
+
 static gboolean
 monitor_run (CPUFreqMonitor *monitor)
 {
@@ -76,7 +80,11 @@ monitor_run (CPUFreqMonitor *monitor)
   if (!policy)
     {
       /* Check whether it failed because cpu is not online. */
+#ifdef HAVE_IS_CPU_ONLINE
+      if (cpupower_is_cpu_online (monitor->cpu) != 1)
+#else
       if (!cpufreq_cpu_exists (monitor->cpu))
+#endif
         {
           monitor->online = FALSE;
           return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]