diff options
author | raveit65 <[email protected]> | 2020-11-20 16:14:42 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-20 16:14:42 +0100 |
commit | 3dd33d455f60ccb07ca57b2ea083563efa51a252 (patch) | |
tree | 8580a55e0f9c70dbe67efb6a35af58c14b10d5c0 /cpufreq/src/cpufreq-monitor-sysfs.c | |
parent | 882de1f0e1237dac2512e4ecf205b21d073c98c5 (diff) | |
download | mate-applets-3dd33d455f60ccb07ca57b2ea083563efa51a252.tar.bz2 mate-applets-3dd33d455f60ccb07ca57b2ea083563efa51a252.tar.xz |
Cpufreq code style
- tabs to spaces
- 4 spaces at the beginning of a line
Diffstat (limited to 'cpufreq/src/cpufreq-monitor-sysfs.c')
-rw-r--r-- | cpufreq/src/cpufreq-monitor-sysfs.c | 448 |
1 files changed, 224 insertions, 224 deletions
diff --git a/cpufreq/src/cpufreq-monitor-sysfs.c b/cpufreq/src/cpufreq-monitor-sysfs.c index 7893745c..0d7f378a 100644 --- a/cpufreq/src/cpufreq-monitor-sysfs.c +++ b/cpufreq/src/cpufreq-monitor-sysfs.c @@ -29,13 +29,13 @@ #include "cpufreq-utils.h" enum { - SCALING_MAX, - SCALING_MIN, - GOVERNOR, - CPUINFO_MAX, - SCALING_SETSPEED, - SCALING_CUR_FREQ, - N_FILES + SCALING_MAX, + SCALING_MIN, + GOVERNOR, + CPUINFO_MAX, + SCALING_SETSPEED, + SCALING_CUR_FREQ, + N_FILES }; static gboolean cpufreq_monitor_sysfs_run (CPUFreqMonitor *monitor); @@ -43,7 +43,7 @@ static GList *cpufreq_monitor_sysfs_get_available_frequencies (CPUFreqMonitor static GList *cpufreq_monitor_sysfs_get_available_governors (CPUFreqMonitor *monitor); static gchar *cpufreq_sysfs_read (const gchar *path, - GError **error); + GError **error); /* /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_max_freq * /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_min_freq @@ -53,13 +53,13 @@ static gchar *cpufreq_sysfs_read (const gchar * /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_cur_freq (new governors) */ const gchar *monitor_sysfs_files[] = { - "scaling_max_freq", - "scaling_min_freq", - "scaling_governor", - "cpuinfo_max_freq", - "scaling_setspeed", - "scaling_cur_freq", - NULL + "scaling_max_freq", + "scaling_min_freq", + "scaling_governor", + "cpuinfo_max_freq", + "scaling_setspeed", + "scaling_cur_freq", + NULL }; #define CPUFREQ_SYSFS_BASE_PATH "/sys/devices/system/cpu/cpu%u/cpufreq/%s" @@ -73,271 +73,271 @@ cpufreq_monitor_sysfs_init (CPUFreqMonitorSysfs *monitor) static GObject * cpufreq_monitor_sysfs_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params) + guint n_construct_properties, + GObjectConstructParam *construct_params) { - GObject *object; - gchar *path; - gchar *frequency; - gint max_freq; - guint cpu; - GError *error = NULL; - - object = G_OBJECT_CLASS ( - cpufreq_monitor_sysfs_parent_class)->constructor (type, - n_construct_properties, - construct_params); - g_object_get (G_OBJECT (object), - "cpu", &cpu, - NULL); - - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[CPUINFO_MAX]); - - frequency = cpufreq_sysfs_read (path, &error); - if (!frequency) { - g_warning ("%s", error->message); - g_error_free (error); - max_freq = -1; - } else { - max_freq = atoi (frequency); - } - - g_free (path); - g_free (frequency); - - g_object_set (G_OBJECT (object), - "max-frequency", max_freq, - NULL); - - return object; + GObject *object; + gchar *path; + gchar *frequency; + gint max_freq; + guint cpu; + GError *error = NULL; + + object = G_OBJECT_CLASS ( + cpufreq_monitor_sysfs_parent_class)->constructor (type, + n_construct_properties, + construct_params); + g_object_get (G_OBJECT (object), + "cpu", &cpu, + NULL); + + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[CPUINFO_MAX]); + + frequency = cpufreq_sysfs_read (path, &error); + if (!frequency) { + g_warning ("%s", error->message); + g_error_free (error); + max_freq = -1; + } else { + max_freq = atoi (frequency); + } + + g_free (path); + g_free (frequency); + + g_object_set (G_OBJECT (object), + "max-frequency", max_freq, + NULL); + + return object; } static void cpufreq_monitor_sysfs_class_init (CPUFreqMonitorSysfsClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass); - - object_class->constructor = cpufreq_monitor_sysfs_constructor; - - monitor_class->run = cpufreq_monitor_sysfs_run; - monitor_class->get_available_frequencies = cpufreq_monitor_sysfs_get_available_frequencies; - monitor_class->get_available_governors = cpufreq_monitor_sysfs_get_available_governors; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass); + + object_class->constructor = cpufreq_monitor_sysfs_constructor; + + monitor_class->run = cpufreq_monitor_sysfs_run; + monitor_class->get_available_frequencies = cpufreq_monitor_sysfs_get_available_frequencies; + monitor_class->get_available_governors = cpufreq_monitor_sysfs_get_available_governors; } CPUFreqMonitor * cpufreq_monitor_sysfs_new (guint cpu) { - CPUFreqMonitorSysfs *monitor; + CPUFreqMonitorSysfs *monitor; - monitor = g_object_new (CPUFREQ_TYPE_MONITOR_SYSFS, - "cpu", cpu, NULL); + monitor = g_object_new (CPUFREQ_TYPE_MONITOR_SYSFS, + "cpu", cpu, NULL); - return CPUFREQ_MONITOR (monitor); + return CPUFREQ_MONITOR (monitor); } static gchar * cpufreq_sysfs_read (const gchar *path, - GError **error) + GError **error) { - gchar *buffer = NULL; + gchar *buffer = NULL; - if (!cpufreq_file_get_contents (path, &buffer, NULL, error)) { - return NULL; - } - - return g_strchomp (buffer); + if (!cpufreq_file_get_contents (path, &buffer, NULL, error)) { + return NULL; + } + + return g_strchomp (buffer); } static gboolean cpufreq_sysfs_cpu_is_online (guint cpu) { - gchar *path; - gboolean retval; - - path = g_strdup_printf ("/sys/devices/system/cpu/cpu%u/", cpu); - retval = g_file_test (path, G_FILE_TEST_IS_DIR); - g_free (path); - - return retval; + gchar *path; + gboolean retval; + + path = g_strdup_printf ("/sys/devices/system/cpu/cpu%u/", cpu); + retval = g_file_test (path, G_FILE_TEST_IS_DIR); + g_free (path); + + return retval; } static gboolean cpufreq_monitor_sysfs_run (CPUFreqMonitor *monitor) { - guint cpu; - gchar *frequency; - gchar *governor; - gchar *path; - GError *error = NULL; - - g_object_get (G_OBJECT (monitor), - "cpu", &cpu, - NULL); - - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[GOVERNOR]); - governor = cpufreq_sysfs_read (path, &error); - if (!governor) { - gboolean retval = FALSE; - - /* Check whether it failed because - * cpu is not online. - */ - if (!cpufreq_sysfs_cpu_is_online (cpu)) { - g_object_set (G_OBJECT (monitor), "online", FALSE, NULL); - retval = TRUE; - } else { - g_warning ("%s", error->message); - } - - g_error_free (error); - g_free (path); - - return retval; - } - - g_free (path); - - if (g_ascii_strcasecmp (governor, "userspace") == 0) { - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[SCALING_SETSPEED]); - } else if (g_ascii_strcasecmp (governor, "powersave") == 0) { - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[SCALING_MIN]); - } else if (g_ascii_strcasecmp (governor, "performance") == 0) { - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[SCALING_MAX]); - } else { /* Ondemand, Conservative, ... */ - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, - cpu, monitor_sysfs_files[SCALING_CUR_FREQ]); - } - - frequency = cpufreq_sysfs_read (path, &error); - if (!frequency) { - g_warning ("%s", error->message); - g_error_free (error); - g_free (path); - g_free (governor); - - return FALSE; - } - - g_free (path); - - g_object_set (G_OBJECT (monitor), - "online", TRUE, - "governor", governor, - "frequency", atoi (frequency), - NULL); - - g_free (governor); - g_free (frequency); - - return TRUE; + guint cpu; + gchar *frequency; + gchar *governor; + gchar *path; + GError *error = NULL; + + g_object_get (G_OBJECT (monitor), + "cpu", &cpu, + NULL); + + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[GOVERNOR]); + governor = cpufreq_sysfs_read (path, &error); + if (!governor) { + gboolean retval = FALSE; + + /* Check whether it failed because + * cpu is not online. + */ + if (!cpufreq_sysfs_cpu_is_online (cpu)) { + g_object_set (G_OBJECT (monitor), "online", FALSE, NULL); + retval = TRUE; + } else { + g_warning ("%s", error->message); + } + + g_error_free (error); + g_free (path); + + return retval; + } + + g_free (path); + + if (g_ascii_strcasecmp (governor, "userspace") == 0) { + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[SCALING_SETSPEED]); + } else if (g_ascii_strcasecmp (governor, "powersave") == 0) { + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[SCALING_MIN]); + } else if (g_ascii_strcasecmp (governor, "performance") == 0) { + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[SCALING_MAX]); + } else { /* Ondemand, Conservative, ... */ + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, + cpu, monitor_sysfs_files[SCALING_CUR_FREQ]); + } + + frequency = cpufreq_sysfs_read (path, &error); + if (!frequency) { + g_warning ("%s", error->message); + g_error_free (error); + g_free (path); + g_free (governor); + + return FALSE; + } + + g_free (path); + + g_object_set (G_OBJECT (monitor), + "online", TRUE, + "governor", governor, + "frequency", atoi (frequency), + NULL); + + g_free (governor); + g_free (frequency); + + return TRUE; } static gint compare (gconstpointer a, gconstpointer b) { - gint aa, bb; + gint aa, bb; - aa = atoi ((gchar *) a); - bb = atoi ((gchar *) b); + aa = atoi ((gchar *) a); + bb = atoi ((gchar *) b); - if (aa == bb) - return 0; - else if (aa > bb) - return -1; - else - return 1; + if (aa == bb) + return 0; + else if (aa > bb) + return -1; + else + return 1; } static GList * cpufreq_monitor_sysfs_get_available_frequencies (CPUFreqMonitor *monitor) { - gchar *path; - GList *list = NULL; - gchar **frequencies = NULL; - gint i; - guint cpu; - gchar *buffer = NULL; - GError *error = NULL; + gchar *path; + GList *list = NULL; + gchar **frequencies = NULL; + gint i; + guint cpu; + gchar *buffer = NULL; + GError *error = NULL; - g_object_get (G_OBJECT (monitor), - "cpu", &cpu, NULL); + g_object_get (G_OBJECT (monitor), + "cpu", &cpu, NULL); - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu, - "scaling_available_frequencies"); + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu, + "scaling_available_frequencies"); - if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) { - g_warning ("%s", error->message); - g_error_free (error); + if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) { + g_warning ("%s", error->message); + g_error_free (error); - g_free (path); + g_free (path); - return NULL; - } + return NULL; + } - g_free (path); - - buffer = g_strchomp (buffer); - frequencies = g_strsplit (buffer, " ", -1); - - i = 0; - while (frequencies[i]) { - if (!g_list_find_custom (list, frequencies[i], compare)) - list = g_list_prepend (list, g_strdup (frequencies[i])); - i++; - } - - g_strfreev (frequencies); - g_free (buffer); + g_free (path); + + buffer = g_strchomp (buffer); + frequencies = g_strsplit (buffer, " ", -1); - return g_list_sort (list, compare); + i = 0; + while (frequencies[i]) { + if (!g_list_find_custom (list, frequencies[i], compare)) + list = g_list_prepend (list, g_strdup (frequencies[i])); + i++; + } + + g_strfreev (frequencies); + g_free (buffer); + + return g_list_sort (list, compare); } static GList * cpufreq_monitor_sysfs_get_available_governors (CPUFreqMonitor *monitor) { - gchar *path; - GList *list = NULL; - gchar **governors = NULL; - gint i; - guint cpu; - gchar *buffer = NULL; - GError *error = NULL; - - g_object_get (G_OBJECT (monitor), - "cpu", &cpu, NULL); - - path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu, - "scaling_available_governors"); - - if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) { - g_warning ("%s", error->message); - g_error_free (error); - - g_free (path); - - return NULL; - } + gchar *path; + GList *list = NULL; + gchar **governors = NULL; + gint i; + guint cpu; + gchar *buffer = NULL; + GError *error = NULL; + + g_object_get (G_OBJECT (monitor), + "cpu", &cpu, NULL); + + path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu, + "scaling_available_governors"); + + if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) { + g_warning ("%s", error->message); + g_error_free (error); g_free (path); - - buffer = g_strchomp (buffer); - governors = g_strsplit (buffer, " ", -1); + return NULL; + } - i = 0; - while (governors[i] != NULL) { - list = g_list_prepend (list, g_strdup (governors[i])); - i++; - } - - g_strfreev (governors); - g_free (buffer); + g_free (path); + + buffer = g_strchomp (buffer); + + governors = g_strsplit (buffer, " ", -1); + + i = 0; + while (governors[i] != NULL) { + list = g_list_prepend (list, g_strdup (governors[i])); + i++; + } + + g_strfreev (governors); + g_free (buffer); - return list; + return list; } |