diff options
author | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2005-02-14 13:54:59 +0800 |
---|---|---|
committer | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2005-02-14 13:54:59 +0800 |
commit | d662472550375f87b65fad1eff94856cb520c9e2 (patch) | |
tree | 6a6fc2fc5899bb754cd2dc30e3e4a5ddd15c078c | |
parent | 15366306a0eb6be860cd219fb15656c006e28d52 (diff) | |
download | marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar.gz marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar.bz2 marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar.lz marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar.xz marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.tar.zst marcuscom-ports-d662472550375f87b65fad1eff94856cb520c9e2.zip |
Complete cpufreq support by adding the ability to set the frequency from
the applet. Initial tests shows this works, but I would appreciate
real-world feedback.
git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@3650 df743ca5-7f9a-e211-a948-0013205c9059
-rw-r--r-- | x11/gnome-applets/Makefile | 2 | ||||
-rw-r--r-- | x11/gnome-applets/files/patch-cpufreq-freebsd | 237 | ||||
-rw-r--r-- | x11/gnome-applets/files/patch-cpufreq-selector-freebsd | 373 | ||||
-rw-r--r-- | x11/gnomeapplets2/Makefile | 2 | ||||
-rw-r--r-- | x11/gnomeapplets2/files/patch-cpufreq-freebsd | 237 | ||||
-rw-r--r-- | x11/gnomeapplets2/files/patch-cpufreq-selector-freebsd | 373 |
6 files changed, 994 insertions, 230 deletions
diff --git a/x11/gnome-applets/Makefile b/x11/gnome-applets/Makefile index 7b54675b6..b15f14ea6 100644 --- a/x11/gnome-applets/Makefile +++ b/x11/gnome-applets/Makefile @@ -7,7 +7,7 @@ PORTNAME= gnomeapplets2 PORTVERSION= 2.9.6 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= x11 gnome MASTER_SITES= ${MASTER_SITE_GNOME} MASTER_SITE_SUBDIR= sources/gnome-applets/2.9 diff --git a/x11/gnome-applets/files/patch-cpufreq-freebsd b/x11/gnome-applets/files/patch-cpufreq-freebsd index ac8ba31bb..48f2ebb6c 100644 --- a/x11/gnome-applets/files/patch-cpufreq-freebsd +++ b/x11/gnome-applets/files/patch-cpufreq-freebsd @@ -83,9 +83,114 @@ +CPUFreqMonitor *cpufreq_monitor_sysctl_new (guint cpu); + +#endif /* __CPUFREQ_MONITOR_SYSCTL_H__ */ ---- cpufreq/src/cpufreq-monitor-sysctl.c.orig Sun Feb 13 01:46:05 2005 -+++ cpufreq/src/cpufreq-monitor-sysctl.c Sun Feb 13 02:54:18 2005 -@@ -0,0 +1,265 @@ +--- cpufreq/src/cpufreq-monitor-cpuinfo.c.orig Fri Dec 31 14:39:04 2004 ++++ cpufreq/src/cpufreq-monitor-cpuinfo.c Sun Feb 13 23:58:38 2005 +@@ -22,6 +22,10 @@ + #include <glib/gi18n.h> + #include <libgnomevfs/gnome-vfs.h> + ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ + #include <string.h> + + #include "cpufreq-monitor-cpuinfo.h" +@@ -102,6 +106,7 @@ + static gboolean + cpufreq_monitor_cpuinfo_get (gpointer gdata) + { ++#ifndef __FreeBSD__ + GnomeVFSHandle *handle; + GnomeVFSFileSize bytes_read; + GnomeVFSResult result; +@@ -109,6 +114,9 @@ + gchar **lines; + gchar buffer[256]; + gchar *p; ++#else ++ size_t len; ++#endif /* __FreeBSD__ */ + gchar *freq, *perc, *unit, *governor; + gint cpu, i; + CPUFreqMonitorCPUInfo *monitor; +@@ -118,6 +126,7 @@ + + private = CPUFREQ_MONITOR_GET_PROTECTED (CPUFREQ_MONITOR (monitor)); + ++#ifndef __FreeBSD__ + uri = gnome_vfs_get_uri_from_local_path ("/proc/cpuinfo"); + + result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); +@@ -178,6 +187,12 @@ + + g_strfreev (lines); + g_free (file); ++#else ++ len = sizeof (cpu); ++ ++ if (sysctlbyname ("hw.clockrate", &cpu, &len, NULL, 0) == -1) ++ return FALSE; ++#endif /* __FreeBSD__ */ + + governor = g_strdup (_("Frequency Scaling Unsupported")); + freq = parent_class->get_human_readable_freq (cpu * 1000); /* kHz are expected*/ +--- cpufreq/src/cpufreq-monitor-factory.c.orig Mon Dec 27 12:53:46 2004 ++++ cpufreq/src/cpufreq-monitor-factory.c Sun Feb 13 23:58:44 2005 +@@ -16,13 +16,21 @@ + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors : Carlos García Campos <carlosgc@gnome.org> ++ * Joe Marcus Clarke <marcus@FreeBSD.org> + */ + + #include <glib.h> ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ + + #include "cpufreq-applet.h" + #include "cpufreq-monitor-sysfs.h" + #include "cpufreq-monitor-procfs.h" ++#ifdef __FreeBSD__ ++#include "cpufreq-monitor-sysctl.h" ++#endif /* __FreeBSD__ */ + #include "cpufreq-monitor-cpuinfo.h" + #include "cpufreq-monitor-factory.h" + +@@ -30,6 +38,7 @@ + cpufreq_monitor_factory_create_monitor (guint cpu) + { + CPUFreqMonitor *monitor = NULL; ++#ifndef __FreeBSD__ + + if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ + monitor = cpufreq_monitor_sysfs_new (cpu); +@@ -48,6 +57,20 @@ + + monitor = cpufreq_monitor_cpuinfo_new (cpu); + } ++#else ++ size_t len; ++ ++ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { ++ monitor = cpufreq_monitor_sysctl_new (cpu); ++ } else { ++ cpufreq_applet_display_error (_("CPU frequency scaling unsupported"), ++ _("You will not be able to modify the frequency of your machine. " ++ "Your machine may be misconfigured or not have hardware support " ++ "for CPU frequency scaling.")); ++ ++ monitor = cpufreq_monitor_cpuinfo_new (cpu); ++ } ++#endif /* __FreeBSD__ */ + + return monitor; + } +--- cpufreq/src/cpufreq-monitor-sysctl.c.orig Sun Feb 13 03:52:42 2005 ++++ cpufreq/src/cpufreq-monitor-sysctl.c Mon Feb 14 00:42:07 2005 +@@ -0,0 +1,269 @@ +/* + * Copyright (C) 2001, 2002 Free Software Foundation + * @@ -199,7 +304,6 @@ + gchar *freq, *perc, *unit, *governor; + gboolean changed; + size_t len; -+ gint mib[4]; + gchar *freq_oid; + CPUFreqMonitorSysctl *monitor; + CPUFreqMonitorProtected *private; @@ -338,7 +442,12 @@ + gchar **frpr; + + frpr = g_strsplit (*l, "/", 0); -+ if (frpr[0] != NULL) { ++ if (frpr && frpr[0] != NULL) { ++ /* sysctl format is %d/%d where the ++ * first %d is the frequency, and ++ * the second is the power used in ++ * mW. ++ */ + int freq = atoi (frpr[0]); + private->available_freqs = + g_list_append (private->available_freqs, g_strdup_printf ("%d", freq * 1000)); @@ -351,116 +460,17 @@ + return private->available_freqs; +} +#endif /* __FreeBSD__ */ ---- cpufreq/src/cpufreq-monitor-factory.c.orig Mon Dec 27 12:53:46 2004 -+++ cpufreq/src/cpufreq-monitor-factory.c Sun Feb 13 02:56:39 2005 -@@ -16,13 +16,21 @@ +--- cpufreq/src/cpufreq-applet.c.orig Fri Jan 14 23:38:20 2005 ++++ cpufreq/src/cpufreq-applet.c Mon Feb 14 00:47:36 2005 +@@ -16,6 +16,7 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Authors : Carlos García Campos <carlosgc@gnome.org> + * Joe Marcus Clarke <marcus@FreeBSD.org> */ - #include <glib.h> -+#ifdef __FreeBSD__ -+#include <sys/types.h> -+#include <sys/sysctl.h> -+#endif /* __FreeBSD__ */ - - #include "cpufreq-applet.h" - #include "cpufreq-monitor-sysfs.h" - #include "cpufreq-monitor-procfs.h" -+#ifdef __FreeBSD__ -+#include "cpufreq-monitor-sysctl.h" -+#endif /* __FreeBSD__ */ - #include "cpufreq-monitor-cpuinfo.h" - #include "cpufreq-monitor-factory.h" - -@@ -30,6 +38,7 @@ - cpufreq_monitor_factory_create_monitor (guint cpu) - { - CPUFreqMonitor *monitor = NULL; -+#ifndef __FreeBSD__ - - if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ - monitor = cpufreq_monitor_sysfs_new (cpu); -@@ -48,6 +57,21 @@ - - monitor = cpufreq_monitor_cpuinfo_new (cpu); - } -+#else -+ gint mib[4]; -+ size_t len; -+ -+ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { -+ monitor = cpufreq_monitor_sysctl_new (cpu); -+ } else { -+ cpufreq_applet_display_error (_("CPU frequency scaling unsupported"), -+ _("You will not be able to modify the frequency of your machine. " -+ "Your machine may be misconfigured or not have hardware support " -+ "for CPU frequency scaling.")); -+ -+ monitor = cpufreq_monitor_cpuinfo_new (cpu); -+ } -+#endif /* __FreeBSD__ */ - - return monitor; - } ---- cpufreq/src/cpufreq-monitor-cpuinfo.c.orig Fri Dec 31 14:39:04 2004 -+++ cpufreq/src/cpufreq-monitor-cpuinfo.c Sun Feb 13 02:54:51 2005 -@@ -22,6 +22,10 @@ - #include <glib/gi18n.h> - #include <libgnomevfs/gnome-vfs.h> - -+#ifdef __FreeBSD__ -+#include <sys/types.h> -+#include <sys/sysctl.h> -+#endif /* __FreeBSD__ */ - #include <string.h> - - #include "cpufreq-monitor-cpuinfo.h" -@@ -102,6 +106,7 @@ - static gboolean - cpufreq_monitor_cpuinfo_get (gpointer gdata) - { -+#ifndef __FreeBSD__ - GnomeVFSHandle *handle; - GnomeVFSFileSize bytes_read; - GnomeVFSResult result; -@@ -109,6 +114,10 @@ - gchar **lines; - gchar buffer[256]; - gchar *p; -+#else -+ gint mib[2]; -+ size_t len; -+#endif /* __FreeBSD__ */ - gchar *freq, *perc, *unit, *governor; - gint cpu, i; - CPUFreqMonitorCPUInfo *monitor; -@@ -118,6 +127,7 @@ - - private = CPUFREQ_MONITOR_GET_PROTECTED (CPUFREQ_MONITOR (monitor)); - -+#ifndef __FreeBSD__ - uri = gnome_vfs_get_uri_from_local_path ("/proc/cpuinfo"); - - result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); -@@ -178,6 +188,12 @@ - - g_strfreev (lines); - g_free (file); -+#else -+ len = sizeof (cpu); -+ -+ if (sysctlbyname ("hw.clockrate", &cpu, &len, NULL, 0) == -1) -+ return FALSE; -+#endif /* __FreeBSD__ */ - - governor = g_strdup (_("Frequency Scaling Unsupported")); - freq = parent_class->get_human_readable_freq (cpu * 1000); /* kHz are expected*/ ---- cpufreq/src/cpufreq-applet.c.orig Fri Jan 14 23:38:20 2005 -+++ cpufreq/src/cpufreq-applet.c Sun Feb 13 02:58:28 2005 -@@ -25,6 +25,10 @@ + #include <config.h> +@@ -25,6 +26,10 @@ #include <panel-applet-gconf.h> #include <glade/glade.h> #include <glib/gi18n.h> @@ -471,15 +481,15 @@ #include <string.h> #include "cpufreq-applet.h" -@@ -192,6 +196,7 @@ +@@ -192,6 +197,7 @@ { static const gchar *authors[] = { "Carlos Garcia Campos <carlosgc@gnome.org>", -+ "Joe Marcus Clarke <marcus@FreeBSD.org>", ++ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD support)", NULL }; static const gchar *documenters[] = { -@@ -231,6 +236,7 @@ +@@ -231,6 +237,7 @@ cpufreq_applet_get_max_cpu () { gint mcpu = -1; @@ -487,12 +497,11 @@ gchar *file = NULL; do { -@@ -253,6 +259,15 @@ +@@ -253,6 +260,14 @@ } while (g_file_test (file, G_FILE_TEST_EXISTS)); g_free (file); mcpu --; +#else -+ gint mib[2]; + size_t len; + + len = sizeof (mcpu); diff --git a/x11/gnome-applets/files/patch-cpufreq-selector-freebsd b/x11/gnome-applets/files/patch-cpufreq-selector-freebsd new file mode 100644 index 000000000..f577a0fed --- /dev/null +++ b/x11/gnome-applets/files/patch-cpufreq-selector-freebsd @@ -0,0 +1,373 @@ +--- cpufreq/src/cpufreq-selector/Makefile.in.orig Mon Feb 14 00:26:10 2005 ++++ cpufreq/src/cpufreq-selector/Makefile.in Mon Feb 14 00:26:58 2005 +@@ -53,7 +53,7 @@ + PROGRAMS = $(bin_PROGRAMS) + am_cpufreq_selector_OBJECTS = cpufreq.$(OBJEXT) \ + cpufreq-sysfs.$(OBJEXT) cpufreq-procfs.$(OBJEXT) \ +- main.$(OBJEXT) ++ cpufreq-sysctl.$(OBJEXT) main.$(OBJEXT) + cpufreq_selector_OBJECTS = $(am_cpufreq_selector_OBJECTS) + am__DEPENDENCIES_1 = + cpufreq_selector_DEPENDENCIES = $(am__DEPENDENCIES_1) +@@ -61,6 +61,7 @@ + depcomp = $(SHELL) $(top_srcdir)/depcomp + am__depfiles_maybe = depfiles + @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cpufreq-procfs.Po \ ++@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-sysctl.Po \ + @AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-sysfs.Po \ + @AMDEP_TRUE@ ./$(DEPDIR)/cpufreq.Po ./$(DEPDIR)/main.Po + COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ +@@ -310,6 +311,7 @@ + cpufreq.c cpufreq.h \ + cpufreq-sysfs.c cpufreq-sysfs.h \ + cpufreq-procfs.c cpufreq-procfs.h \ ++ cpufreq-sysctl.c cpufreq-sysctl.h \ + main.c + + cpufreq_selector_LDADD = $(CPUFREQ_SELECTOR_LIBS) -lpopt +@@ -385,6 +387,7 @@ + -rm -f *.tab.c + + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-procfs.Po@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-sysctl.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-sysfs.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ +--- cpufreq/src/cpufreq-selector/cpufreq-sysctl.h.orig Mon Feb 14 00:38:57 2005 ++++ cpufreq/src/cpufreq-selector/cpufreq-sysctl.h Mon Feb 14 00:21:39 2005 +@@ -0,0 +1,51 @@ ++/* ++ * Copyright (C) 2001, 2002 Free Software Foundation ++ * ++ * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * Authors : Joe Marcus Clarke <marcus@FreeBSD.org> ++ */ ++ ++#ifndef __CPUFREQ_SYSCTL_H__ ++#define __CPUFREQ_SYSCTL_H__ ++ ++#include <glib-object.h> ++ ++#include "cpufreq.h" ++ ++#define TYPE_CPUFREQ_SYSCTL (cpufreq_sysctl_get_type ()) ++#define CPUFREQ_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctl)) ++#define CPUFREQ_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlClass)) ++#define IS_CPUFREQ_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CPUFREQ_SYSCTL)) ++#define IS_CPUFREQ_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CPUFREQ_SYSCTL)) ++#define CPUFREQ_SYSCTL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlClass)) ++ ++typedef struct _CPUFreqSysctl CPUFreqSysctl; ++typedef struct _CPUFreqSysctlClass CPUFreqSysctlClass; ++typedef struct _CPUFreqSysctlPriv CPUFreqSysctlPriv; ++ ++struct _CPUFreqSysctl { ++ CPUFreq parent; ++}; ++ ++struct _CPUFreqSysctlClass { ++ CPUFreqClass parent_class; ++}; ++ ++ ++GType cpufreq_sysctl_get_type (); ++CPUFreqSysctl *cpufreq_sysctl_new (); ++ ++#endif /* __CPUFREQ_SYSCTL_H__ */ +--- cpufreq/src/cpufreq-selector/main.c.orig Mon Feb 14 00:22:12 2005 ++++ cpufreq/src/cpufreq-selector/main.c Mon Feb 14 00:26:04 2005 +@@ -16,6 +16,7 @@ + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors : Carlos García Campos <carlosgc@gnome.org> ++ * Joe Marcus Clarke <marcus@FreeBSD.org> + */ + + #include <glib-object.h> +@@ -26,6 +27,9 @@ + #include "cpufreq.h" + #include "cpufreq-sysfs.h" + #include "cpufreq-procfs.h" ++#ifdef __FreeBSD__ ++#include "cpufreq-sysctl.h" ++#endif /* __FreeBSD__ */ + + gint + main (gint argc, gchar **argv) +@@ -35,6 +39,9 @@ + gulong frequency = 0; + poptContext ctx; + gint nextopt; ++#ifdef __FreeBSD__ ++ size_t len; ++#endif /* __FreeBSD__ */ + CPUFreq *cfq; + + struct poptOption options[] = { +@@ -76,10 +83,15 @@ + + poptFreeContext(ctx); + ++#ifndef __FreeBSD__ + if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ + cfq = CPUFREQ (cpufreq_sysfs_new ()); + } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel */ + cfq = CPUFREQ (cpufreq_procfs_new ()); ++#else ++ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { ++ cfq = CPUFREQ (cpufreq_sysctl_new ()); ++#endif /* __FreeBSD __ */ + } else { + g_print ("No cpufreq support\n"); + return 1; +--- cpufreq/src/cpufreq-selector/cpufreq-sysctl.c.orig Mon Feb 14 00:38:52 2005 ++++ cpufreq/src/cpufreq-selector/cpufreq-sysctl.c Mon Feb 14 00:44:43 2005 +@@ -0,0 +1,235 @@ ++/* ++ * Copyright (C) 2001, 2002 Free Software Foundation ++ * ++ * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * Authors : Joe Marcus Clarke <marcus@FreeBSD.org> ++ */ ++ ++#include <glib.h> ++#include <stdio.h> ++#include <stdlib.h> ++ ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ ++ ++#include "cpufreq-sysctl.h" ++ ++#define PARENT_TYPE TYPE_CPUFREQ ++ ++#define CPUFREQ_SYSCTL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlPrivate)) ++ ++static void cpufreq_sysctl_init (CPUFreqSysctl *cfq); ++static void cpufreq_sysctl_class_init (CPUFreqSysctlClass *klass); ++static void cpufreq_sysctl_finalize (GObject *object); ++ ++static void cpufreq_sysctl_set_governor (CPUFreq *cfq, const gchar *governor); ++static void cpufreq_sysctl_set_frequency (CPUFreq *cfq, gint frequency); ++ ++static void cpufreq_sysctl_setup (CPUFreqSysctl *cfq); ++ ++static GObjectClass *parent_class = NULL; ++ ++typedef struct _CPUFreqSysctlPrivate CPUFreqSysctlPrivate; ++ ++struct _CPUFreqSysctlPrivate ++{ ++ gint pmax; ++}; ++ ++GType cpufreq_sysctl_get_type () ++{ ++ static GType type = 0; ++ ++ if (!type) { ++ static const GTypeInfo info = { ++ sizeof (CPUFreqSysctlClass), ++ (GBaseInitFunc) NULL, ++ (GBaseFinalizeFunc) NULL, ++ (GClassInitFunc) cpufreq_sysctl_class_init, ++ NULL, ++ NULL, ++ sizeof (CPUFreqSysctl), ++ 0, ++ (GInstanceInitFunc) cpufreq_sysctl_init ++ }; ++ ++ type = g_type_register_static (PARENT_TYPE, "CPUFreqSysctl", ++ &info, 0); ++ } ++ ++ return type; ++} ++ ++static void ++cpufreq_sysctl_init (CPUFreqSysctl *cfq) ++{ ++ CPUFreqSysctlPrivate *private; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ private = CPUFREQ_SYSCTL_GET_PRIVATE (cfq); ++} ++ ++static void ++cpufreq_sysctl_class_init (CPUFreqSysctlClass *klass) ++{ ++ GObjectClass *object_class = G_OBJECT_CLASS (klass); ++ CPUFreqClass *cfq_class = CPUFREQ_CLASS (klass); ++ ++ parent_class = g_type_class_peek_parent (klass); ++ ++ g_type_class_add_private (klass, sizeof (CPUFreqSysctlPrivate)); ++ ++ cfq_class->set_governor = cpufreq_sysctl_set_governor; ++ cfq_class->set_frequency = cpufreq_sysctl_set_frequency; ++ ++ object_class->finalize = cpufreq_sysctl_finalize; ++} ++ ++static void ++cpufreq_sysctl_finalize (GObject *object) ++{ ++ if (G_OBJECT_CLASS (parent_class)->finalize) ++ (* G_OBJECT_CLASS (parent_class)->finalize) (object); ++} ++ ++CPUFreqSysctl * ++cpufreq_sysctl_new () ++{ ++ CPUFreqSysctl *cfq; ++ ++ cfq = g_object_new (TYPE_CPUFREQ_SYSCTL, NULL); ++ ++ cpufreq_sysctl_setup (cfq); ++ ++ return cfq; ++} ++ ++static void ++cpufreq_sysctl_set_governor (CPUFreq *cfq, const gchar *governor) ++{ ++ /* Not implemented. */ ++} ++ ++static void ++cpufreq_sysctl_set_frequency (CPUFreq *cfq, gint frequency) ++{ ++ gint cpu, i; ++ size_t len; ++ gchar *freq_oid; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ g_object_get (G_OBJECT (cfq), "n_cpu", &cpu, NULL); ++ ++ frequency = (gint) ((gdouble) frequency / 1000); /* Convert back to MHz*/ ++ ++ for (i = 0; i < cpu; i++) { ++ freq_oid = g_strdup_printf ("dev.cpu.%d.freq", i); ++ ++ sysctlbyname (freq_oid, NULL, &len, &frequency, sizeof (frequency)); ++ g_free (freq_oid); ++ } ++} ++ ++ ++static void ++cpufreq_sysctl_setup (CPUFreqSysctl *cfq) ++{ ++ guint cpu; ++ gint fmax, fmin; ++ gint pmax; ++ gint ifreq; ++ gint mib[4]; ++ gchar *governor, *levels; ++ gchar **levelsp, **frpr, **l; ++ size_t len; ++ CPUFreqSysctlPrivate *private; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ private = CPUFREQ_SYSCTL_GET_PRIVATE (cfq); ++ ++ pmax = 100; ++ fmax = 0; ++ fmin = 0; ++ ifreq = 0; ++ ++ private->pmax = pmax; ++ ++ len = sizeof (cpu); ++ ++ if (sysctlbyname ("hw.ncpu", &cpu, &len, NULL, 0) == -1) ++ cpu = 1; ++ ++ len = 4; ++ sysctlnametomib ("dev.cpu.0.freq_levels", mib, &len); ++ len = sizeof (levels); ++ ++ if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch dev.cpu.0.freq_levels"); ++ return; ++ } ++ ++ levels = g_malloc (len); ++ if (sysctl (mib, 4, levels, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch data for dev.cpu.0.freq_levels"); ++ return; ++ } ++ ++ levelsp = g_strsplit (levels, " ", 0); ++ g_free (levels); ++ ++ frpr = g_strsplit (levelsp[0], "/", 0); /* MAX */ ++ if (frpr && frpr[0] != NULL) ++ fmax = atoi (frpr[0]); ++ g_strfreev (frpr); ++ ++ for (l = levelsp; l && *l; l++) /* Walk to the last frequency */ ++ ; ++ ++ l --; ++ frpr = g_strsplit (*l, "/", 0); ++ if (frpr && frpr[0] != NULL) ++ fmin = atoi (frpr[0]); ++ ++ g_strfreev (frpr); ++ g_strfreev (levelsp); ++ ++ len = sizeof (ifreq); ++ if (sysctlbyname ("dev.cpu.0.freq", &ifreq, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch data for dev.cpu.0.freq"); ++ return; ++ } ++ ++ if (ifreq == fmax) ++ governor = g_strdup ("performance"); ++ else if (ifreq == fmin) ++ governor = g_strdup ("economy"); ++ else ++ governor = g_strdup ("other"); ++ ++ fmax *= 1000; ++ fmin *= 1000; ++ ++ g_object_set (G_OBJECT (cfq), "n_cpu", cpu, ++ "sc_max", fmax, "sc_min", fmin, ++ "governor", governor, NULL); ++ ++ g_free (governor); ++} diff --git a/x11/gnomeapplets2/Makefile b/x11/gnomeapplets2/Makefile index 7b54675b6..b15f14ea6 100644 --- a/x11/gnomeapplets2/Makefile +++ b/x11/gnomeapplets2/Makefile @@ -7,7 +7,7 @@ PORTNAME= gnomeapplets2 PORTVERSION= 2.9.6 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= x11 gnome MASTER_SITES= ${MASTER_SITE_GNOME} MASTER_SITE_SUBDIR= sources/gnome-applets/2.9 diff --git a/x11/gnomeapplets2/files/patch-cpufreq-freebsd b/x11/gnomeapplets2/files/patch-cpufreq-freebsd index ac8ba31bb..48f2ebb6c 100644 --- a/x11/gnomeapplets2/files/patch-cpufreq-freebsd +++ b/x11/gnomeapplets2/files/patch-cpufreq-freebsd @@ -83,9 +83,114 @@ +CPUFreqMonitor *cpufreq_monitor_sysctl_new (guint cpu); + +#endif /* __CPUFREQ_MONITOR_SYSCTL_H__ */ ---- cpufreq/src/cpufreq-monitor-sysctl.c.orig Sun Feb 13 01:46:05 2005 -+++ cpufreq/src/cpufreq-monitor-sysctl.c Sun Feb 13 02:54:18 2005 -@@ -0,0 +1,265 @@ +--- cpufreq/src/cpufreq-monitor-cpuinfo.c.orig Fri Dec 31 14:39:04 2004 ++++ cpufreq/src/cpufreq-monitor-cpuinfo.c Sun Feb 13 23:58:38 2005 +@@ -22,6 +22,10 @@ + #include <glib/gi18n.h> + #include <libgnomevfs/gnome-vfs.h> + ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ + #include <string.h> + + #include "cpufreq-monitor-cpuinfo.h" +@@ -102,6 +106,7 @@ + static gboolean + cpufreq_monitor_cpuinfo_get (gpointer gdata) + { ++#ifndef __FreeBSD__ + GnomeVFSHandle *handle; + GnomeVFSFileSize bytes_read; + GnomeVFSResult result; +@@ -109,6 +114,9 @@ + gchar **lines; + gchar buffer[256]; + gchar *p; ++#else ++ size_t len; ++#endif /* __FreeBSD__ */ + gchar *freq, *perc, *unit, *governor; + gint cpu, i; + CPUFreqMonitorCPUInfo *monitor; +@@ -118,6 +126,7 @@ + + private = CPUFREQ_MONITOR_GET_PROTECTED (CPUFREQ_MONITOR (monitor)); + ++#ifndef __FreeBSD__ + uri = gnome_vfs_get_uri_from_local_path ("/proc/cpuinfo"); + + result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); +@@ -178,6 +187,12 @@ + + g_strfreev (lines); + g_free (file); ++#else ++ len = sizeof (cpu); ++ ++ if (sysctlbyname ("hw.clockrate", &cpu, &len, NULL, 0) == -1) ++ return FALSE; ++#endif /* __FreeBSD__ */ + + governor = g_strdup (_("Frequency Scaling Unsupported")); + freq = parent_class->get_human_readable_freq (cpu * 1000); /* kHz are expected*/ +--- cpufreq/src/cpufreq-monitor-factory.c.orig Mon Dec 27 12:53:46 2004 ++++ cpufreq/src/cpufreq-monitor-factory.c Sun Feb 13 23:58:44 2005 +@@ -16,13 +16,21 @@ + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors : Carlos García Campos <carlosgc@gnome.org> ++ * Joe Marcus Clarke <marcus@FreeBSD.org> + */ + + #include <glib.h> ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ + + #include "cpufreq-applet.h" + #include "cpufreq-monitor-sysfs.h" + #include "cpufreq-monitor-procfs.h" ++#ifdef __FreeBSD__ ++#include "cpufreq-monitor-sysctl.h" ++#endif /* __FreeBSD__ */ + #include "cpufreq-monitor-cpuinfo.h" + #include "cpufreq-monitor-factory.h" + +@@ -30,6 +38,7 @@ + cpufreq_monitor_factory_create_monitor (guint cpu) + { + CPUFreqMonitor *monitor = NULL; ++#ifndef __FreeBSD__ + + if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ + monitor = cpufreq_monitor_sysfs_new (cpu); +@@ -48,6 +57,20 @@ + + monitor = cpufreq_monitor_cpuinfo_new (cpu); + } ++#else ++ size_t len; ++ ++ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { ++ monitor = cpufreq_monitor_sysctl_new (cpu); ++ } else { ++ cpufreq_applet_display_error (_("CPU frequency scaling unsupported"), ++ _("You will not be able to modify the frequency of your machine. " ++ "Your machine may be misconfigured or not have hardware support " ++ "for CPU frequency scaling.")); ++ ++ monitor = cpufreq_monitor_cpuinfo_new (cpu); ++ } ++#endif /* __FreeBSD__ */ + + return monitor; + } +--- cpufreq/src/cpufreq-monitor-sysctl.c.orig Sun Feb 13 03:52:42 2005 ++++ cpufreq/src/cpufreq-monitor-sysctl.c Mon Feb 14 00:42:07 2005 +@@ -0,0 +1,269 @@ +/* + * Copyright (C) 2001, 2002 Free Software Foundation + * @@ -199,7 +304,6 @@ + gchar *freq, *perc, *unit, *governor; + gboolean changed; + size_t len; -+ gint mib[4]; + gchar *freq_oid; + CPUFreqMonitorSysctl *monitor; + CPUFreqMonitorProtected *private; @@ -338,7 +442,12 @@ + gchar **frpr; + + frpr = g_strsplit (*l, "/", 0); -+ if (frpr[0] != NULL) { ++ if (frpr && frpr[0] != NULL) { ++ /* sysctl format is %d/%d where the ++ * first %d is the frequency, and ++ * the second is the power used in ++ * mW. ++ */ + int freq = atoi (frpr[0]); + private->available_freqs = + g_list_append (private->available_freqs, g_strdup_printf ("%d", freq * 1000)); @@ -351,116 +460,17 @@ + return private->available_freqs; +} +#endif /* __FreeBSD__ */ ---- cpufreq/src/cpufreq-monitor-factory.c.orig Mon Dec 27 12:53:46 2004 -+++ cpufreq/src/cpufreq-monitor-factory.c Sun Feb 13 02:56:39 2005 -@@ -16,13 +16,21 @@ +--- cpufreq/src/cpufreq-applet.c.orig Fri Jan 14 23:38:20 2005 ++++ cpufreq/src/cpufreq-applet.c Mon Feb 14 00:47:36 2005 +@@ -16,6 +16,7 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Authors : Carlos García Campos <carlosgc@gnome.org> + * Joe Marcus Clarke <marcus@FreeBSD.org> */ - #include <glib.h> -+#ifdef __FreeBSD__ -+#include <sys/types.h> -+#include <sys/sysctl.h> -+#endif /* __FreeBSD__ */ - - #include "cpufreq-applet.h" - #include "cpufreq-monitor-sysfs.h" - #include "cpufreq-monitor-procfs.h" -+#ifdef __FreeBSD__ -+#include "cpufreq-monitor-sysctl.h" -+#endif /* __FreeBSD__ */ - #include "cpufreq-monitor-cpuinfo.h" - #include "cpufreq-monitor-factory.h" - -@@ -30,6 +38,7 @@ - cpufreq_monitor_factory_create_monitor (guint cpu) - { - CPUFreqMonitor *monitor = NULL; -+#ifndef __FreeBSD__ - - if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ - monitor = cpufreq_monitor_sysfs_new (cpu); -@@ -48,6 +57,21 @@ - - monitor = cpufreq_monitor_cpuinfo_new (cpu); - } -+#else -+ gint mib[4]; -+ size_t len; -+ -+ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { -+ monitor = cpufreq_monitor_sysctl_new (cpu); -+ } else { -+ cpufreq_applet_display_error (_("CPU frequency scaling unsupported"), -+ _("You will not be able to modify the frequency of your machine. " -+ "Your machine may be misconfigured or not have hardware support " -+ "for CPU frequency scaling.")); -+ -+ monitor = cpufreq_monitor_cpuinfo_new (cpu); -+ } -+#endif /* __FreeBSD__ */ - - return monitor; - } ---- cpufreq/src/cpufreq-monitor-cpuinfo.c.orig Fri Dec 31 14:39:04 2004 -+++ cpufreq/src/cpufreq-monitor-cpuinfo.c Sun Feb 13 02:54:51 2005 -@@ -22,6 +22,10 @@ - #include <glib/gi18n.h> - #include <libgnomevfs/gnome-vfs.h> - -+#ifdef __FreeBSD__ -+#include <sys/types.h> -+#include <sys/sysctl.h> -+#endif /* __FreeBSD__ */ - #include <string.h> - - #include "cpufreq-monitor-cpuinfo.h" -@@ -102,6 +106,7 @@ - static gboolean - cpufreq_monitor_cpuinfo_get (gpointer gdata) - { -+#ifndef __FreeBSD__ - GnomeVFSHandle *handle; - GnomeVFSFileSize bytes_read; - GnomeVFSResult result; -@@ -109,6 +114,10 @@ - gchar **lines; - gchar buffer[256]; - gchar *p; -+#else -+ gint mib[2]; -+ size_t len; -+#endif /* __FreeBSD__ */ - gchar *freq, *perc, *unit, *governor; - gint cpu, i; - CPUFreqMonitorCPUInfo *monitor; -@@ -118,6 +127,7 @@ - - private = CPUFREQ_MONITOR_GET_PROTECTED (CPUFREQ_MONITOR (monitor)); - -+#ifndef __FreeBSD__ - uri = gnome_vfs_get_uri_from_local_path ("/proc/cpuinfo"); - - result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); -@@ -178,6 +188,12 @@ - - g_strfreev (lines); - g_free (file); -+#else -+ len = sizeof (cpu); -+ -+ if (sysctlbyname ("hw.clockrate", &cpu, &len, NULL, 0) == -1) -+ return FALSE; -+#endif /* __FreeBSD__ */ - - governor = g_strdup (_("Frequency Scaling Unsupported")); - freq = parent_class->get_human_readable_freq (cpu * 1000); /* kHz are expected*/ ---- cpufreq/src/cpufreq-applet.c.orig Fri Jan 14 23:38:20 2005 -+++ cpufreq/src/cpufreq-applet.c Sun Feb 13 02:58:28 2005 -@@ -25,6 +25,10 @@ + #include <config.h> +@@ -25,6 +26,10 @@ #include <panel-applet-gconf.h> #include <glade/glade.h> #include <glib/gi18n.h> @@ -471,15 +481,15 @@ #include <string.h> #include "cpufreq-applet.h" -@@ -192,6 +196,7 @@ +@@ -192,6 +197,7 @@ { static const gchar *authors[] = { "Carlos Garcia Campos <carlosgc@gnome.org>", -+ "Joe Marcus Clarke <marcus@FreeBSD.org>", ++ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD support)", NULL }; static const gchar *documenters[] = { -@@ -231,6 +236,7 @@ +@@ -231,6 +237,7 @@ cpufreq_applet_get_max_cpu () { gint mcpu = -1; @@ -487,12 +497,11 @@ gchar *file = NULL; do { -@@ -253,6 +259,15 @@ +@@ -253,6 +260,14 @@ } while (g_file_test (file, G_FILE_TEST_EXISTS)); g_free (file); mcpu --; +#else -+ gint mib[2]; + size_t len; + + len = sizeof (mcpu); diff --git a/x11/gnomeapplets2/files/patch-cpufreq-selector-freebsd b/x11/gnomeapplets2/files/patch-cpufreq-selector-freebsd new file mode 100644 index 000000000..f577a0fed --- /dev/null +++ b/x11/gnomeapplets2/files/patch-cpufreq-selector-freebsd @@ -0,0 +1,373 @@ +--- cpufreq/src/cpufreq-selector/Makefile.in.orig Mon Feb 14 00:26:10 2005 ++++ cpufreq/src/cpufreq-selector/Makefile.in Mon Feb 14 00:26:58 2005 +@@ -53,7 +53,7 @@ + PROGRAMS = $(bin_PROGRAMS) + am_cpufreq_selector_OBJECTS = cpufreq.$(OBJEXT) \ + cpufreq-sysfs.$(OBJEXT) cpufreq-procfs.$(OBJEXT) \ +- main.$(OBJEXT) ++ cpufreq-sysctl.$(OBJEXT) main.$(OBJEXT) + cpufreq_selector_OBJECTS = $(am_cpufreq_selector_OBJECTS) + am__DEPENDENCIES_1 = + cpufreq_selector_DEPENDENCIES = $(am__DEPENDENCIES_1) +@@ -61,6 +61,7 @@ + depcomp = $(SHELL) $(top_srcdir)/depcomp + am__depfiles_maybe = depfiles + @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cpufreq-procfs.Po \ ++@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-sysctl.Po \ + @AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-sysfs.Po \ + @AMDEP_TRUE@ ./$(DEPDIR)/cpufreq.Po ./$(DEPDIR)/main.Po + COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ +@@ -310,6 +311,7 @@ + cpufreq.c cpufreq.h \ + cpufreq-sysfs.c cpufreq-sysfs.h \ + cpufreq-procfs.c cpufreq-procfs.h \ ++ cpufreq-sysctl.c cpufreq-sysctl.h \ + main.c + + cpufreq_selector_LDADD = $(CPUFREQ_SELECTOR_LIBS) -lpopt +@@ -385,6 +387,7 @@ + -rm -f *.tab.c + + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-procfs.Po@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-sysctl.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-sysfs.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ +--- cpufreq/src/cpufreq-selector/cpufreq-sysctl.h.orig Mon Feb 14 00:38:57 2005 ++++ cpufreq/src/cpufreq-selector/cpufreq-sysctl.h Mon Feb 14 00:21:39 2005 +@@ -0,0 +1,51 @@ ++/* ++ * Copyright (C) 2001, 2002 Free Software Foundation ++ * ++ * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * Authors : Joe Marcus Clarke <marcus@FreeBSD.org> ++ */ ++ ++#ifndef __CPUFREQ_SYSCTL_H__ ++#define __CPUFREQ_SYSCTL_H__ ++ ++#include <glib-object.h> ++ ++#include "cpufreq.h" ++ ++#define TYPE_CPUFREQ_SYSCTL (cpufreq_sysctl_get_type ()) ++#define CPUFREQ_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctl)) ++#define CPUFREQ_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlClass)) ++#define IS_CPUFREQ_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CPUFREQ_SYSCTL)) ++#define IS_CPUFREQ_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CPUFREQ_SYSCTL)) ++#define CPUFREQ_SYSCTL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlClass)) ++ ++typedef struct _CPUFreqSysctl CPUFreqSysctl; ++typedef struct _CPUFreqSysctlClass CPUFreqSysctlClass; ++typedef struct _CPUFreqSysctlPriv CPUFreqSysctlPriv; ++ ++struct _CPUFreqSysctl { ++ CPUFreq parent; ++}; ++ ++struct _CPUFreqSysctlClass { ++ CPUFreqClass parent_class; ++}; ++ ++ ++GType cpufreq_sysctl_get_type (); ++CPUFreqSysctl *cpufreq_sysctl_new (); ++ ++#endif /* __CPUFREQ_SYSCTL_H__ */ +--- cpufreq/src/cpufreq-selector/main.c.orig Mon Feb 14 00:22:12 2005 ++++ cpufreq/src/cpufreq-selector/main.c Mon Feb 14 00:26:04 2005 +@@ -16,6 +16,7 @@ + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors : Carlos García Campos <carlosgc@gnome.org> ++ * Joe Marcus Clarke <marcus@FreeBSD.org> + */ + + #include <glib-object.h> +@@ -26,6 +27,9 @@ + #include "cpufreq.h" + #include "cpufreq-sysfs.h" + #include "cpufreq-procfs.h" ++#ifdef __FreeBSD__ ++#include "cpufreq-sysctl.h" ++#endif /* __FreeBSD__ */ + + gint + main (gint argc, gchar **argv) +@@ -35,6 +39,9 @@ + gulong frequency = 0; + poptContext ctx; + gint nextopt; ++#ifdef __FreeBSD__ ++ size_t len; ++#endif /* __FreeBSD__ */ + CPUFreq *cfq; + + struct poptOption options[] = { +@@ -76,10 +83,15 @@ + + poptFreeContext(ctx); + ++#ifndef __FreeBSD__ + if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */ + cfq = CPUFREQ (cpufreq_sysfs_new ()); + } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel */ + cfq = CPUFREQ (cpufreq_procfs_new ()); ++#else ++ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) { ++ cfq = CPUFREQ (cpufreq_sysctl_new ()); ++#endif /* __FreeBSD __ */ + } else { + g_print ("No cpufreq support\n"); + return 1; +--- cpufreq/src/cpufreq-selector/cpufreq-sysctl.c.orig Mon Feb 14 00:38:52 2005 ++++ cpufreq/src/cpufreq-selector/cpufreq-sysctl.c Mon Feb 14 00:44:43 2005 +@@ -0,0 +1,235 @@ ++/* ++ * Copyright (C) 2001, 2002 Free Software Foundation ++ * ++ * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * Authors : Joe Marcus Clarke <marcus@FreeBSD.org> ++ */ ++ ++#include <glib.h> ++#include <stdio.h> ++#include <stdlib.h> ++ ++#ifdef __FreeBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif /* __FreeBSD__ */ ++ ++#include "cpufreq-sysctl.h" ++ ++#define PARENT_TYPE TYPE_CPUFREQ ++ ++#define CPUFREQ_SYSCTL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), TYPE_CPUFREQ_SYSCTL, CPUFreqSysctlPrivate)) ++ ++static void cpufreq_sysctl_init (CPUFreqSysctl *cfq); ++static void cpufreq_sysctl_class_init (CPUFreqSysctlClass *klass); ++static void cpufreq_sysctl_finalize (GObject *object); ++ ++static void cpufreq_sysctl_set_governor (CPUFreq *cfq, const gchar *governor); ++static void cpufreq_sysctl_set_frequency (CPUFreq *cfq, gint frequency); ++ ++static void cpufreq_sysctl_setup (CPUFreqSysctl *cfq); ++ ++static GObjectClass *parent_class = NULL; ++ ++typedef struct _CPUFreqSysctlPrivate CPUFreqSysctlPrivate; ++ ++struct _CPUFreqSysctlPrivate ++{ ++ gint pmax; ++}; ++ ++GType cpufreq_sysctl_get_type () ++{ ++ static GType type = 0; ++ ++ if (!type) { ++ static const GTypeInfo info = { ++ sizeof (CPUFreqSysctlClass), ++ (GBaseInitFunc) NULL, ++ (GBaseFinalizeFunc) NULL, ++ (GClassInitFunc) cpufreq_sysctl_class_init, ++ NULL, ++ NULL, ++ sizeof (CPUFreqSysctl), ++ 0, ++ (GInstanceInitFunc) cpufreq_sysctl_init ++ }; ++ ++ type = g_type_register_static (PARENT_TYPE, "CPUFreqSysctl", ++ &info, 0); ++ } ++ ++ return type; ++} ++ ++static void ++cpufreq_sysctl_init (CPUFreqSysctl *cfq) ++{ ++ CPUFreqSysctlPrivate *private; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ private = CPUFREQ_SYSCTL_GET_PRIVATE (cfq); ++} ++ ++static void ++cpufreq_sysctl_class_init (CPUFreqSysctlClass *klass) ++{ ++ GObjectClass *object_class = G_OBJECT_CLASS (klass); ++ CPUFreqClass *cfq_class = CPUFREQ_CLASS (klass); ++ ++ parent_class = g_type_class_peek_parent (klass); ++ ++ g_type_class_add_private (klass, sizeof (CPUFreqSysctlPrivate)); ++ ++ cfq_class->set_governor = cpufreq_sysctl_set_governor; ++ cfq_class->set_frequency = cpufreq_sysctl_set_frequency; ++ ++ object_class->finalize = cpufreq_sysctl_finalize; ++} ++ ++static void ++cpufreq_sysctl_finalize (GObject *object) ++{ ++ if (G_OBJECT_CLASS (parent_class)->finalize) ++ (* G_OBJECT_CLASS (parent_class)->finalize) (object); ++} ++ ++CPUFreqSysctl * ++cpufreq_sysctl_new () ++{ ++ CPUFreqSysctl *cfq; ++ ++ cfq = g_object_new (TYPE_CPUFREQ_SYSCTL, NULL); ++ ++ cpufreq_sysctl_setup (cfq); ++ ++ return cfq; ++} ++ ++static void ++cpufreq_sysctl_set_governor (CPUFreq *cfq, const gchar *governor) ++{ ++ /* Not implemented. */ ++} ++ ++static void ++cpufreq_sysctl_set_frequency (CPUFreq *cfq, gint frequency) ++{ ++ gint cpu, i; ++ size_t len; ++ gchar *freq_oid; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ g_object_get (G_OBJECT (cfq), "n_cpu", &cpu, NULL); ++ ++ frequency = (gint) ((gdouble) frequency / 1000); /* Convert back to MHz*/ ++ ++ for (i = 0; i < cpu; i++) { ++ freq_oid = g_strdup_printf ("dev.cpu.%d.freq", i); ++ ++ sysctlbyname (freq_oid, NULL, &len, &frequency, sizeof (frequency)); ++ g_free (freq_oid); ++ } ++} ++ ++ ++static void ++cpufreq_sysctl_setup (CPUFreqSysctl *cfq) ++{ ++ guint cpu; ++ gint fmax, fmin; ++ gint pmax; ++ gint ifreq; ++ gint mib[4]; ++ gchar *governor, *levels; ++ gchar **levelsp, **frpr, **l; ++ size_t len; ++ CPUFreqSysctlPrivate *private; ++ ++ g_return_if_fail (IS_CPUFREQ_SYSCTL (cfq)); ++ ++ private = CPUFREQ_SYSCTL_GET_PRIVATE (cfq); ++ ++ pmax = 100; ++ fmax = 0; ++ fmin = 0; ++ ifreq = 0; ++ ++ private->pmax = pmax; ++ ++ len = sizeof (cpu); ++ ++ if (sysctlbyname ("hw.ncpu", &cpu, &len, NULL, 0) == -1) ++ cpu = 1; ++ ++ len = 4; ++ sysctlnametomib ("dev.cpu.0.freq_levels", mib, &len); ++ len = sizeof (levels); ++ ++ if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch dev.cpu.0.freq_levels"); ++ return; ++ } ++ ++ levels = g_malloc (len); ++ if (sysctl (mib, 4, levels, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch data for dev.cpu.0.freq_levels"); ++ return; ++ } ++ ++ levelsp = g_strsplit (levels, " ", 0); ++ g_free (levels); ++ ++ frpr = g_strsplit (levelsp[0], "/", 0); /* MAX */ ++ if (frpr && frpr[0] != NULL) ++ fmax = atoi (frpr[0]); ++ g_strfreev (frpr); ++ ++ for (l = levelsp; l && *l; l++) /* Walk to the last frequency */ ++ ; ++ ++ l --; ++ frpr = g_strsplit (*l, "/", 0); ++ if (frpr && frpr[0] != NULL) ++ fmin = atoi (frpr[0]); ++ ++ g_strfreev (frpr); ++ g_strfreev (levelsp); ++ ++ len = sizeof (ifreq); ++ if (sysctlbyname ("dev.cpu.0.freq", &ifreq, &len, NULL, 0) == -1) { ++ g_warning ("Failed to fetch data for dev.cpu.0.freq"); ++ return; ++ } ++ ++ if (ifreq == fmax) ++ governor = g_strdup ("performance"); ++ else if (ifreq == fmin) ++ governor = g_strdup ("economy"); ++ else ++ governor = g_strdup ("other"); ++ ++ fmax *= 1000; ++ fmin *= 1000; ++ ++ g_object_set (G_OBJECT (cfq), "n_cpu", cpu, ++ "sc_max", fmax, "sc_min", fmin, ++ "governor", governor, NULL); ++ ++ g_free (governor); ++} |