openbsd-ports/devel/libgtop2/patches/patch-sysdeps_bsd_sysinfo_c
2010-09-18 09:14:17 +00:00

72 lines
1.8 KiB
Plaintext

$OpenBSD: patch-sysdeps_bsd_sysinfo_c,v 1.8 2010/09/18 09:14:18 ajacoutot Exp $
--- sysdeps/bsd/sysinfo.c.orig Sun Apr 19 19:51:00 2009
+++ sysdeps/bsd/sysinfo.c Sat Sep 18 11:06:35 2010
@@ -36,7 +36,12 @@ static void
init_sysinfo (glibtop *server)
{
char *model;
+#if defined(__OpenBSD__)
+ int mib[2];
+ int ncpus = 1;
+#else
guint64 ncpus = 1;
+#endif
int mhz = 0;
size_t len;
@@ -45,6 +50,34 @@ init_sysinfo (glibtop *server)
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+#if defined(__OpenBSD__)
+ mib[0] = CTL_HW;
+
+ /* Get the number of CPU's present */
+ mib[1] = HW_NCPU;
+
+ len = sizeof(ncpus);
+ if (sysctl(mib, 2, &ncpus, &len, NULL, 0) != 0)
+ printf("Couldn't determine hw.ncpu.\n");
+
+ /* Get the CPU model */
+ mib[1] = HW_MODEL;
+ len = 0;
+
+ if (sysctl(mib, 2, NULL, &len, NULL, 0) != -1) {
+ model = g_malloc (len);
+ sysctl(mib, 2, model, &len, NULL, 0);
+ } else {
+ printf("Couldn't determine hw.model.\n");
+ }
+
+ /* Get the clockrate */
+ mib[1] = HW_CPUSPEED;
+ len = sizeof(mhz);
+
+ if (sysctl(mib, 2, &mhz, &len, NULL, 0) != 0)
+ printf("Couldn't determine hw.cpuspeed.\n");
+#else
len = sizeof (ncpus);
sysctlbyname ("hw.ncpu", &ncpus, &len, NULL, 0);
len = 0;
@@ -54,6 +87,8 @@ init_sysinfo (glibtop *server)
len = sizeof (mhz);
sysctlbyname ("hw.clockrate", &mhz, &len, NULL, 0);
+#endif /* __OpenBSD__ */
+
for (sysinfo.ncpu = 0;
sysinfo.ncpu < GLIBTOP_NCPU && sysinfo.ncpu < ncpus;
sysinfo.ncpu++) {
@@ -71,6 +106,10 @@ init_sysinfo (glibtop *server)
g_ptr_array_add (cpuinfo->labels, "vendor_id");
g_hash_table_insert (cpuinfo->values, "vendor_id",
+ g_strdup(model));
+
+ g_ptr_array_add (cpuinfo->labels, "model name");
+ g_hash_table_insert (cpuinfo->values, "model name",
g_strdup(model));
g_ptr_array_add (cpuinfo->labels, "cpu MHz");