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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
--- cpufreq/src/cpufreq-monitor-cpuinfo.c.orig Thu Jun 15 01:01:54 2006
+++ cpufreq/src/cpufreq-monitor-cpuinfo.c Sat Jun 17 13:48:19 2006
@@ -22,6 +22,10 @@
#include <glib.h>
#include <glib/gi18n.h>
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif /* __FreeBSD__ */
#include <string.h>
#include <stdio.h>
@@ -59,15 +63,20 @@ cpufreq_monitor_cpuinfo_new (guint cpu)
static gboolean
cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor)
{
+#ifndef __FreeBSD__
gchar *file;
gchar **lines;
gchar *buffer = NULL;
gchar *p;
+#else
+ size_t len;
+#endif /* __FreeBSD__ */
gint cpu, i;
gint cur_freq, max_freq;
gchar *governor;
GError *error = NULL;
+#ifndef __FreeBSD__
file = g_strdup ("/proc/cpuinfo");
if (!g_file_get_contents (file, &buffer, NULL, &error)) {
g_warning (error->message);
@@ -112,6 +121,12 @@ cpufreq_monitor_cpuinfo_run (CPUFreqMoni
g_strfreev (lines);
g_free (buffer);
+#else
+ len = sizeof (cpu);
+
+ if (sysctlbyname ("hw.clockrate", &cpu, &len, NULL, 0) == -1)
+ return FALSE;
+#endif /* __FreeBSD__ */
governor = g_strdup (_("Frequency Scaling Unsupported"));
cur_freq = cpu * 1000;
--- cpufreq/src/cpufreq-applet.c.orig Thu Jun 15 01:01:53 2006
+++ cpufreq/src/cpufreq-applet.c Sat Jun 17 13:42:50 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
@@ -519,6 +524,7 @@ cpufreq_applet_about_cb (BonoboUICompone
{
static const gchar *const authors[] = {
"Carlos Garcia Campos <carlosgc@gnome.org>",
+ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD support)",
NULL
};
static const gchar *const documenters[] = {
--- cpufreq/src/cpufreq-monitor-sysctl.h.orig Sat Jun 17 14:05:37 2006
+++ cpufreq/src/cpufreq-monitor-sysctl.h Sat Jun 17 14:14:13 2006
@@ -0,0 +1,49 @@
+/*
+ * 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_MONITOR_SYSCTL_H__
+#define __CPUFREQ_MONITOR_SYSCTL_H__
+
+#include <glib-object.h>
+
+#include "cpufreq-monitor.h"
+
+#define TYPE_CPUFREQ_MONITOR_SYSCTL (cpufreq_monitor_sysctl_get_type ())
+#define CPUFREQ_MONITOR_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CPUFREQ_MONITOR_SYSCTL, CPUFreqMonitorSysctl))
+#define CPUFREQ_MONITOR_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_CPUFREQ_MONITOR_SYSCTL, CPUFreqMonitorSysctlClass))
+#define IS_CPUFREQ_MONITOR_SYSCTL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CPUFREQ_MONITOR_SYSCTL))
+#define IS_CPUFREQ_MONITOR_SYSCTL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CPUFREQ_MONITOR_SYSCTL))
+#define CPUFREQ_MONITOR_SYSCTL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CPUFREQ_MONITOR_SYSCTL, CPUFreqMonitorSysctlClass))
+
+typedef struct _CPUFreqMonitorSysctl CPUFreqMonitorSysctl;
+typedef struct _CPUFreqMonitorSysctlClass CPUFreqMonitorSysctlClass;
+
+struct _CPUFreqMonitorSysctl {
+ CPUFreqMonitor parent;
+};
+
+struct _CPUFreqMonitorSysctlClass {
+ CPUFreqMonitorClass parent_class;
+};
+
+GType cpufreq_monitor_sysctl_get_type (void) G_GNUC_CONST;
+CPUFreqMonitor *cpufreq_monitor_sysctl_new (guint cpu);
+
+#endif /* __CPUFREQ_MONITOR_SYSCTL_H__ */
--- cpufreq/src/cpufreq-monitor-factory.c.orig Sat Jun 17 06:28:02 2006
+++ cpufreq/src/cpufreq-monitor-factory.c Sat Jun 24 01:45:54 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
@@ -25,11 +26,18 @@
#include <glib.h>
#include <glib/gi18n.h>
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif /* __FreeBSD__ */
#include "cpufreq-applet.h"
#include "cpufreq-utils.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"
#ifdef HAVE_LIBCPUFREQ
#include "cpufreq-monitor-libcpufreq.h"
@@ -40,6 +48,7 @@ CPUFreqMonitor *
cpufreq_monitor_factory_create_monitor (guint cpu)
{
CPUFreqMonitor *monitor = NULL;
+#ifndef __FreeBSD__
#ifdef HAVE_LIBCPUFREQ
monitor = cpufreq_monitor_libcpufreq_new (cpu);
@@ -63,6 +72,19 @@ cpufreq_monitor_factory_create_monitor (
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_utils_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-utils.c.orig Sat Aug 12 21:26:50 2006
+++ cpufreq/src/cpufreq-utils.c Tue Aug 22 11:07:32 2006
@@ -22,6 +22,9 @@
#include <glib.h>
#include <gtk/gtkmessagedialog.h>
#include <sys/types.h>
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#endif
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@@ -30,6 +33,24 @@
#include "cpufreq-utils.h"
+#ifdef __FreeBSD__
+guint
+cpufreq_utils_get_n_cpus (void)
+{
+ size_t len;
+ static guint n_cpus = 0;
+
+ if (n_cpus > 0)
+ return n_cpus;
+
+ len = sizeof (n_cpus);
+ if (sysctlbyname ("hw.ncpu", &n_cpus, &len, NULL, 0) == -1) {
+ return 1;
+ }
+
+ return n_cpus;
+}
+#else
guint
cpufreq_utils_get_n_cpus (void)
{
@@ -72,6 +93,7 @@ cpufreq_utils_get_n_cpus (void)
return 1;
}
+#endif /* __FreeBSD__ */
void
cpufreq_utils_display_error (const gchar *message,
--- cpufreq/src/cpufreq-monitor-sysctl.c.orig Wed Feb 28 14:03:58 2007
+++ cpufreq/src/cpufreq-monitor-sysctl.c Wed Feb 28 14:28:47 2007
@@ -0,0 +1,176 @@
+/*
+ * 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 <glib/gi18n.h>
+
+#include <string.h>
+
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include "cpufreq-monitor-sysctl.h"
+
+#define PARENT_TYPE TYPE_CPUFREQ_MONITOR
+
+#define CPUFREQ_MONITOR_GET_PROTECTED(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PARENT_TYPE, CPUFreqMonitorProtected))
+
+static void cpufreq_monitor_sysctl_class_init (CPUFreqMonitorSysctlClass *klass);
+
+static gboolean cpufreq_monitor_sysctl_run (CPUFreqMonitor *monitor);
+static GList *cpufreq_monitor_sysctl_get_available_frequencies (CPUFreqMonitor *monitor);
+static GList *cpufreq_monitor_sysctl_get_available_governors (CPUFreqMonitor *monitor);
+
+static gboolean cpufreq_monitor_sysctl_get (gpointer gdata);
+
+G_DEFINE_TYPE (CPUFreqMonitorSysctl, cpufreq_monitor_sysctl, CPUFREQ_TYPE_MONITOR)
+
+static void
+cpufreq_monitor_sysctl_init (CPUFreqMonitorSysctl *monitor)
+{
+}
+
+static void
+cpufreq_monitor_sysctl_class_init (CPUFreqMonitorSysctlClass *klass)
+{
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+
+ monitor_class->run = cpufreq_monitor_sysctl_run;
+ monitor_class->get_available_frequencies = cpufreq_monitor_sysctl_get_available_frequencies;
+ monitor_class->get_available_governors = cpufreq_monitor_sysctl_get_available_governors;
+}
+
+CPUFreqMonitor *
+cpufreq_monitor_sysctl_new (guint cpu)
+{
+ CPUFreqMonitorSysctl *monitor;
+
+ monitor = g_object_new (TYPE_CPUFREQ_MONITOR_SYSCTL, "cpu", cpu, NULL);
+
+ return CPUFREQ_MONITOR (monitor);
+}
+
+static gboolean
+cpufreq_monitor_sysctl_run (CPUFreqMonitor *monitor)
+{
+ gint fmax, fmin, ifreq;
+ gchar *governor;
+ size_t len;
+ gchar *freq_oid;
+ guint mon_cpu;
+ GList *list;
+
+ list = cpufreq_monitor_sysctl_get_available_frequencies (CPUFREQ_MONITOR (monitor));
+
+ fmax = atoi ((gchar *) list->data);
+ fmin = atoi ((gchar *) g_list_nth_data (list, (g_list_length (list) - 1)));
+
+ g_object_get (G_OBJECT (monitor), "cpu", &mon_cpu, NULL);
+ len = sizeof (ifreq);
+ freq_oid = g_strdup_printf ("dev.cpu.%d.freq", 0);
+
+ if (sysctlbyname (freq_oid, &ifreq, &len, NULL, 0) == -1) {
+ g_free (freq_oid);
+ return FALSE;
+ }
+
+ ifreq *= 1000;
+
+ if (ifreq == fmax)
+ governor = g_strdup ("performance");
+ else if (ifreq == fmin)
+ governor = g_strdup ("economy");
+ else
+ governor = g_strdup ("userspace");
+
+ g_object_set (G_OBJECT (monitor),
+ "online", TRUE,
+ "governor", governor,
+ "frequency", ifreq,
+ "max-frequency", fmax,
+ NULL);
+
+ return TRUE;
+}
+
+static GList *
+cpufreq_monitor_sysctl_get_available_frequencies (CPUFreqMonitor *monitor)
+{
+ gchar *levels_oid, *levels;
+ gchar **levelsp, **l;
+ GList *list = NULL;
+ gint mib[4];
+ guint mon_cpu;
+ size_t len;
+
+ g_object_get (G_OBJECT (monitor), "cpu", &mon_cpu, NULL);
+
+ levels_oid = g_strdup_printf ("dev.cpu.%d.freq_levels",
+ 0);
+ len = 4;
+ sysctlnametomib (levels_oid, mib, &len);
+ len = sizeof (levels);
+ g_free (levels_oid);
+
+ if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1)
+ return NULL;
+
+ levels = g_malloc (len);
+ if (sysctl (mib, 4, levels, &len, NULL, 0) == -1)
+ return NULL;
+
+ levelsp = g_strsplit (levels, " ", 0);
+ g_free (levels);
+
+ for (l = levelsp; l && *l; l++) {
+ gchar **frpr;
+
+ frpr = g_strsplit (*l, "/", 0);
+ 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]);
+ list =
+ g_list_append (list, g_strdup_printf ("%d", freq * 1000));
+ }
+ g_strfreev (frpr);
+ }
+
+ g_strfreev (levelsp);
+
+ return (list);
+}
+
+static GList *
+cpufreq_monitor_sysctl_get_available_governors (CPUFreqMonitor *monitor)
+{
+ GList *list = NULL;
+
+ list = g_list_prepend (list, g_strdup ("performance"));
+ list = g_list_prepend (list, g_strdup ("userspace"));
+ list = g_list_prepend (list, g_strdup ("economy"));
+
+ return list;
+}
+#endif /* __FreeBSD__ */
--- cpufreq/src/Makefile.in.orig Mon Mar 12 11:58:09 2007
+++ cpufreq/src/Makefile.in Mon Mar 12 12:12:06 2007
@@ -62,7 +62,8 @@ am__cpufreq_applet_SOURCES_DIST = cpufre
cpufreq-monitor-procfs.h cpufreq-monitor-sysfs.c \
cpufreq-monitor-sysfs.h cpufreq-monitor-libcpufreq.c \
cpufreq-monitor-libcpufreq.h cpufreq-monitor-cpuinfo.c \
- cpufreq-monitor-cpuinfo.h
+ cpufreq-monitor-cpuinfo.h cpufreq-monitor-sysctl.c \
+ cpufreq-monitor-sysctl.h
@HAVE_LIBCPUFREQ_TRUE@am__objects_1 = \
@HAVE_LIBCPUFREQ_TRUE@ cpufreq-monitor-libcpufreq.$(OBJEXT)
am_cpufreq_applet_OBJECTS = cpufreq-applet.$(OBJEXT) \
@@ -71,7 +72,8 @@ am_cpufreq_applet_OBJECTS = cpufreq-appl
cpufreq-monitor-factory.$(OBJEXT) \
cpufreq-monitor-procfs.$(OBJEXT) \
cpufreq-monitor-sysfs.$(OBJEXT) $(am__objects_1) \
- cpufreq-monitor-cpuinfo.$(OBJEXT)
+ cpufreq-monitor-cpuinfo.$(OBJEXT) \
+ cpufreq-monitor-sysctl.$(OBJEXT)
cpufreq_applet_OBJECTS = $(am_cpufreq_applet_OBJECTS)
am__DEPENDENCIES_1 =
cpufreq_applet_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@@ -85,6 +87,7 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-monitor-libcpufreq.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-monitor-procfs.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-monitor-sysfs.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-monitor-sysctl.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-monitor.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-popup.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cpufreq-prefs.Po \
@@ -411,6 +414,7 @@ cpufreq_applet_SOURCES = \
cpufreq-monitor.c cpufreq-monitor.h \
cpufreq-monitor-factory.c cpufreq-monitor-factory.h \
cpufreq-monitor-procfs.c cpufreq-monitor-procfs.h \
+ cpufreq-monitor-sysctl.c cpufreq-monitor-sysctl.h \
cpufreq-monitor-sysfs.c cpufreq-monitor-sysfs.h \
$(cpufreq_files) \
cpufreq-monitor-cpuinfo.c cpufreq-monitor-cpuinfo.h
@@ -496,6 +500,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor-factory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor-libcpufreq.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor-procfs.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor-sysctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor-sysfs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-monitor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpufreq-popup.Po@am__quote@
|