summaryrefslogtreecommitdiff
path: root/cpufreq/src/cpufreq-selector
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-11-28 20:26:22 +0100
committerraveit65 <[email protected]>2020-12-09 21:16:36 +0100
commit4cb6f915b1a91497df1b13cdab887df1bdaed101 (patch)
treeef32f9e4d6f6f75de2e15da5bff69562ac7581dc /cpufreq/src/cpufreq-selector
parent66b18c097d5ae6e7bcf712820bc3e6594c8cb79a (diff)
downloadmate-applets-4cb6f915b1a91497df1b13cdab887df1bdaed101.tar.bz2
mate-applets-4cb6f915b1a91497df1b13cdab887df1bdaed101.tar.xz
cpufreq: Remove /proc/cpufreq support (Linux 2.4)
Diffstat (limited to 'cpufreq/src/cpufreq-selector')
-rw-r--r--cpufreq/src/cpufreq-selector/Makefile.am17
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c16
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c242
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h54
4 files changed, 17 insertions, 312 deletions
diff --git a/cpufreq/src/cpufreq-selector/Makefile.am b/cpufreq/src/cpufreq-selector/Makefile.am
index b75a26c4..375d0371 100644
--- a/cpufreq/src/cpufreq-selector/Makefile.am
+++ b/cpufreq/src/cpufreq-selector/Makefile.am
@@ -15,11 +15,6 @@ if CPUFREQ_SELECTOR_SUID
chmod 4755 $(DESTDIR)$(bindir)/mate-cpufreq-selector
endif
-
-if HAVE_LIBCPUFREQ
-cpufreq_files=cpufreq-selector-libcpufreq.c cpufreq-selector-libcpufreq.h
-endif
-
if HAVE_POLKIT
service_files=cpufreq-selector-service.c cpufreq-selector-service.h
endif
@@ -27,13 +22,21 @@ endif
mate_cpufreq_selector_SOURCES = \
cpufreq-selector.c cpufreq-selector.h \
cpufreq-selector-sysfs.c cpufreq-selector-sysfs.h \
- cpufreq-selector-procfs.c cpufreq-selector-procfs.h \
- $(cpufreq_files) \
$(service_files) \
cpufreq-selector-factory.c cpufreq-selector-factory.h \
$(BUILT_SOURCES) \
main.c
+if HAVE_LIBCPUFREQ
+mate_cpufreq_selector_SOURCES += \
+ cpufreq-selector-libcpufreq.c \
+ cpufreq-selector-libcpufreq.h
+else
+mate_cpufreq_selector_SOURCES += \
+ cpufreq-selector-sysfs.h \
+ cpufreq-selector-sysfs.c
+endif
+
mate_cpufreq_selector_LDADD = \
$(CPUFREQ_SELECTOR_LIBS) \
$(LIBCPUFREQ_LIBS)
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
index 9f9bd29d..0328ea40 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
@@ -22,26 +22,24 @@
#endif
#include "cpufreq-selector-factory.h"
-#include "cpufreq-selector-sysfs.h"
-#include "cpufreq-selector-procfs.h"
#ifdef HAVE_LIBCPUFREQ
#include "cpufreq-selector-libcpufreq.h"
+#else
+#include "cpufreq-selector-sysfs.h"
#endif
CPUFreqSelector *
cpufreq_selector_factory_create_selector (guint cpu)
{
- CPUFreqSelector *selector = NULL;
-
#ifdef HAVE_LIBCPUFREQ
- selector = cpufreq_selector_libcpufreq_new (cpu);
+ return cpufreq_selector_libcpufreq_new (cpu);
#else
- if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
+ CPUFreqSelector *selector = NULL;
+
+ if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) {
selector = cpufreq_selector_sysfs_new (cpu);
- } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel */
- selector = cpufreq_selector_procfs_new (cpu);
}
-#endif /* HAVE_LIBCPUFREQ */
return selector;
+#endif /* HAVE_LIBCPUFREQ */
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c
deleted file mode 100644
index 002c387c..00000000
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * MATE CPUFreq Applet
- * Copyright (C) 2004 Carlos Garcia Campos <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Authors : Carlos Garc�a Campos <[email protected]>
- */
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "cpufreq-selector-procfs.h"
-
-static gboolean
-cpufreq_selector_procfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
-static gboolean
-cpufreq_selector_procfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
-
-G_DEFINE_TYPE (CPUFreqSelectorProcfs, cpufreq_selector_procfs, CPUFREQ_TYPE_SELECTOR)
-
-static void
-cpufreq_selector_procfs_init (CPUFreqSelectorProcfs *selector)
-{
-}
-
-static void
-cpufreq_selector_procfs_class_init (CPUFreqSelectorProcfsClass *klass)
-{
- CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
-
- selector_class->set_frequency = cpufreq_selector_procfs_set_frequency;
- selector_class->set_governor = cpufreq_selector_procfs_set_governor;
-}
-
-CPUFreqSelector *
-cpufreq_selector_procfs_new (guint cpu)
-{
- CPUFreqSelector *selector;
-
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_PROCFS,
- "cpu", cpu,
- NULL));
-
- return selector;
-}
-
-static gboolean
-cpufreq_procfs_read (guint selector_cpu,
- guint *fmax,
- guint *pmin,
- guint *pmax,
- guint *fmin,
- gchar *mode,
- GError **error)
-{
- gchar **lines;
- gchar *buffer = NULL;
- gint i;
- guint cpu;
- gboolean found = FALSE;
-
- if (!g_file_get_contents ("/proc/cpufreq", &buffer, NULL, error)) {
- return FALSE;
- }
-
- lines = g_strsplit (buffer, "\n", -1);
- for (i = 0; lines[i]; i++) {
- if (g_ascii_strncasecmp (lines[i], "CPU", 3) == 0) {
- /* CPU 0 650000 kHz ( 81 %) - 800000 kHz (100 %) - powersave */
- sscanf (lines[i], "CPU %u %u kHz (%u %%) - %u kHz (%u %%) - %20s",
- &cpu, fmin, pmin, fmax, pmax, mode);
-
- if (cpu == selector_cpu) {
- found = TRUE;
- break;
- }
- }
- }
-
- g_strfreev (lines);
- g_free (buffer);
-
- if (!found) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_CPU,
- "Invalid CPU number '%d'",
- selector_cpu);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-cpufreq_procfs_write (const gchar *path,
- const gchar *setting,
- GError **error)
-{
- FILE *fd;
-
- fd = g_fopen (path, "w");
-
- if (!fd) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to open '%s' for writing: "
- "g_fopen() failed: %s",
- path,
- g_strerror (errno));
-
- return FALSE;
- }
-
- if (g_fprintf (fd, "%s", setting) < 0) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to write '%s': "
- "g_fprintf() failed: %s",
- path,
- g_strerror (errno));
-
- fclose (fd);
-
- return FALSE;
- }
-
- fclose (fd);
-
- return TRUE;
-}
-
-static gboolean
-cpufreq_selector_procfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
-{
- gchar *str;
- gchar *path;
- guint freq;
- guint cpu;
- guint pmin, pmax;
- guint sc_max, sc_min;
- gchar mode[21];
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
- return FALSE;
- }
-
- if (g_ascii_strcasecmp (mode, "userspace") != 0) {
- if (!cpufreq_selector_procfs_set_governor (selector,
- "userspace",
- error)) {
- return FALSE;
- }
- }
-
- if (frequency != sc_max && frequency != sc_min) {
- if (abs ((int)sc_max - (int)frequency) < abs ((int)frequency - (int)sc_min))
- freq = sc_max;
- else
- freq = sc_min;
- } else {
- freq = frequency;
- }
-
- path = g_strdup_printf ("/proc/sys/cpu/%u/speed", cpu);
- str = g_strdup_printf ("%u", freq);
- if (!cpufreq_procfs_write (path, str, error)) {
- g_free (path);
- g_free (str);
-
- return FALSE;
- }
-
- g_free (path);
- g_free (str);
-
- return TRUE;
-}
-
-static gboolean
-cpufreq_selector_procfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
-{
- gchar *str;
- guint cpu;
- guint pmin, pmax;
- guint sc_max, sc_min;
- gchar mode[21];
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
- return FALSE;
- }
-
- if (g_ascii_strcasecmp (governor, mode) == 0)
- return TRUE;
-
- str = g_strdup_printf ("%u:%u:%u:%s", cpu, sc_min, sc_max, governor);
-
- if (!cpufreq_procfs_write ("/proc/cpufreq", str, error)) {
- g_free (str);
-
- return FALSE;
- }
-
- g_free (str);
-
- return TRUE;
-}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h
deleted file mode 100644
index 7d516b43..00000000
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * MATE CPUFreq Applet
- * Copyright (C) 2004 Carlos Garcia Campos <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Authors : Carlos Garc�a Campos <[email protected]>
- */
-
-#ifndef __CPUFREQ_SELECTOR_PROCFS_H__
-#define __CPUFREQ_SELECTOR_PROCFS_H__
-
-#include <glib-object.h>
-
-#include "cpufreq-selector.h"
-
-G_BEGIN_DECLS
-
-#define CPUFREQ_TYPE_SELECTOR_PROCFS (cpufreq_selector_procfs_get_type ())
-#define CPUFREQ_SELECTOR_PROCFS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_SELECTOR_PROCFS, CPUFreqSelectorProcfs))
-#define CPUFREQ_SELECTOR_PROCFS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_SELECTOR_PROCFS, CPUFreqSelectorProcfsClass))
-#define CPUFREQ_IS_SELECTOR_PROCFS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_SELECTOR_PROCFS))
-#define CPUFREQ_IS_SELECTOR_PROCFS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_SELECTOR_PROCFS))
-#define CPUFREQ_SELECTOR_PROCFS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_SELECTOR_PROCFS, CPUFreqSelectorProcfsClass))
-
-typedef struct _CPUFreqSelectorProcfs CPUFreqSelectorProcfs;
-typedef struct _CPUFreqSelectorProcfsClass CPUFreqSelectorProcfsClass;
-
-struct _CPUFreqSelectorProcfs {
- CPUFreqSelector parent;
-};
-
-struct _CPUFreqSelectorProcfsClass {
- CPUFreqSelectorClass parent_class;
-};
-
-GType cpufreq_selector_procfs_get_type (void) G_GNUC_CONST;
-CPUFreqSelector *cpufreq_selector_procfs_new (guint cpu);
-
-G_END_DECLS
-
-#endif /* __CPUFREQ_SELECTOR_PROCFS_H__ */