1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
--- cpufreq/src/cpufreq-selector/cpufreq-selector-sysctl.h.orig Sat Jun 24 01:52:35 2006
+++ cpufreq/src/cpufreq-selector/cpufreq-selector-sysctl.h Sat Jun 24 02:13:05 2006
@@ -0,0 +1,53 @@
+/*
+ * 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_SELECTOR_SYSCTL_H__
+#define __CPUFREQ_SELECTOR_SYSCTL_H__
+
+#include <glib-object.h>
+
+#include "cpufreq-selector.h"
+
+G_BEGIN_DECLS
+
+#define CPUFREQ_TYPE_SELECTOR_SYSCTL (cpufreq_selector_sysctl_get_type ())
+#define CPUFREQ_SELECTOR_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_SELECTOR_SYSCTL, CPUFreqSelectorProcfs))
+#define CPUFREQ_SELECTOR_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_SELECTOR_SYSCTL, CPUFreqSelectorProcfsClass))
+#define CPUFREQ_IS_SELECTOR_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_SELECTOR_SYSCTL))
+#define CPUFREQ_IS_SELECTOR_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_SELECTOR_SYSCTL))
+#define CPUFREQ_SELECTOR_SYSCTL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_SELECTOR_SYSCTL, CPUFreqSelectorProcfsClass))
+
+typedef struct _CPUFreqSelectorSysctl CPUFreqSelectorSysctl;
+typedef struct _CPUFreqSelectorSysctlClass CPUFreqSelectorSysctlClass;
+
+struct _CPUFreqSelectorSysctl {
+ CPUFreqSelector parent;
+};
+
+struct _CPUFreqSelectorSysctlClass {
+ CPUFreqSelectorClass parent_class;
+};
+
+GType cpufreq_selector_sysctl_get_type (void) G_GNUC_CONST;
+CPUFreqSelector *cpufreq_selector_sysctl_new (guint cpu);
+
+G_END_DECLS
+
+#endif /* __CPUFREQ_SELECTOR_SYSCTL_H__ */
--- cpufreq/src/cpufreq-selector/main.c.orig Sat Jun 17 22:13:41 2006
+++ cpufreq/src/cpufreq-selector/main.c Sat Jun 24 02:15:02 2006
@@ -17,6 +17,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>
*/
#ifdef HAVE_CONFIG_H
@@ -33,6 +34,9 @@
#ifdef HAVE_LIBCPUFREQ
#include "cpufreq-selector-libcpufreq.h"
#endif
+#ifdef __FreeBSD__
+#include "cpufreq-selector-sysctl.h"
+#endif /* __FreeBSD__ */
static gint cpu = 0;
static gchar *governor = NULL;
@@ -51,6 +55,9 @@ main (gint argc, gchar **argv)
CPUFreqSelector *selector;
GOptionContext *context;
GError *error = NULL;
+#ifdef __FreeBSD__
+ size_t len;
+#endif
if (geteuid () != 0) {
g_printerr ("You must be root\n");
@@ -83,10 +90,15 @@ main (gint argc, gchar **argv)
#ifdef HAVE_LIBCPUFREQ
selector = cpufreq_selector_libcpufreq_new (cpu);
#else
+#ifndef __FreeBSD__
if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
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);
+#else
+ if (sysctlbyname ("dev.cpu.0.freq", NULL, &len, NULL, 0) == 0) {
+ selector = cpufreq_selector_sysctl_new (cpu);
+#endif /* __FreeBSD__ */
} else {
g_printerr ("No cpufreq support\n");
return 1;
--- cpufreq/src/cpufreq-selector/cpufreq-selector-sysctl.c.orig Wed Jul 26 01:34:18 2006
+++ cpufreq/src/cpufreq-selector/cpufreq-selector-sysctl.c Wed Jul 26 01:42:00 2006
@@ -0,0 +1,87 @@
+/*
+ * 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-selector-sysctl.h"
+
+static void cpufreq_selector_sysctl_init (CPUFreqSelectorSysctl *selector);
+static void cpufreq_selector_sysctl_class_init (CPUFreqSelectorSysctlClass *klass);
+
+static gboolean cpufreq_selector_sysctl_set_frequency (CPUFreqSelector *selector, guint frequency, GError **error);
+static gboolean cpufreq_selector_sysctl_set_governor (CPUFreqSelector *selector, const gchar *governor, GError **error);
+
+G_DEFINE_TYPE (CPUFreqSelectorSysctl, cpufreq_selector_sysctl, CPUFREQ_TYPE_SELECTOR)
+
+static void
+cpufreq_selector_sysctl_init (CPUFreqSelectorSysctl *selector)
+{
+}
+
+static void
+cpufreq_selector_sysctl_class_init (CPUFreqSelectorSysctlClass *klass)
+{
+ CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
+
+ selector_class->set_frequency = cpufreq_selector_sysctl_set_frequency;
+ selector_class->set_governor = cpufreq_selector_sysctl_set_governor;
+}
+
+CPUFreqSelector *
+cpufreq_selector_sysctl_new (guint cpu)
+{
+ CPUFreqSelector *selector;
+
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_SYSCTL,
+ "cpu", cpu, NULL));
+
+ return selector;
+}
+
+static gboolean
+cpufreq_selector_sysctl_set_governor (CPUFreqSelector *selector, const gchar *governor, GError **error)
+{
+ return TRUE;
+}
+
+static gboolean
+cpufreq_selector_sysctl_set_frequency (CPUFreqSelector *selector, guint frequency, GError **error)
+{
+ guint cpu, i;
+ size_t len;
+ gchar *freq_oid;
+
+ g_object_get (G_OBJECT (selector), "cpu", &cpu, NULL);
+
+ frequency = (guint) ((gdouble) frequency / 1000); /* Convert back to MHz*/
+ freq_oid = g_strdup_printf ("dev.cpu.%d.freq", (gint) 0);
+
+ sysctlbyname (freq_oid, NULL, &len, &frequency, sizeof (frequency));
+ g_free (freq_oid);
+
+ return TRUE;
+}
--- cpufreq/src/cpufreq-selector/Makefile.in.orig Mon Mar 12 11:58:09 2007
+++ cpufreq/src/cpufreq-selector/Makefile.in Mon Mar 12 12:12:33 2007
@@ -58,13 +58,15 @@ am__cpufreq_selector_SOURCES_DIST = cpuf
cpufreq-selector.h cpufreq-selector-sysfs.c \
cpufreq-selector-sysfs.h cpufreq-selector-procfs.c \
cpufreq-selector-procfs.h cpufreq-selector-libcpufreq.c \
- cpufreq-selector-libcpufreq.h main.c
+ cpufreq-selector-libcpufreq.h main.c \
+ cpufreq-selector-sysctl.c cpufreq-selector-sysctl.h
@HAVE_LIBCPUFREQ_TRUE@am__objects_1 = \
@HAVE_LIBCPUFREQ_TRUE@ cpufreq-selector-libcpufreq.$(OBJEXT)
am_cpufreq_selector_OBJECTS = cpufreq-selector.$(OBJEXT) \
cpufreq-selector-sysfs.$(OBJEXT) \
cpufreq-selector-procfs.$(OBJEXT) $(am__objects_1) \
- main.$(OBJEXT)
+ main.$(OBJEXT) \
+ cpufreq-selector-sysctl.$(OBJEXT)
cpufreq_selector_OBJECTS = $(am_cpufreq_selector_OBJECTS)
am__DEPENDENCIES_1 =
cpufreq_selector_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@@ -75,6 +77,7 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cpufreq-selector-libcpufreq.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-selector-procfs.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-selector-sysfs.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-selector-sysctl.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-selector.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/main.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -385,6 +388,7 @@ 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-selector-sysctl.c cpufreq-selector-sysctl.h \
$(cpufreq_files) \
main.c
@@ -466,6 +470,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-selector-libcpufreq.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-selector-procfs.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-selector-sysctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-selector-sysfs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-selector.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|