Date: Fri, 21 Dec 2007 03:41:02 +0100 From: "Pietro Cerutti" <gahr@gahr.ch> To: "FreeBSD gnats submit" <FreeBSD-gnats-submit@FreeBSD.org> Subject: ports/118916: [patch] sysutils/gkrellms add coretemp(4) support + fix FreeBSD sysctl code Message-ID: <1198204862.73012@gahrtop.localhost> Resent-Message-ID: <200712210250.lBL2o0FB028599@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 118916 >Category: ports >Synopsis: [patch] sysutils/gkrellms add coretemp(4) support + fix FreeBSD sysctl code >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Dec 21 02:50:00 UTC 2007 >Closed-Date: >Last-Modified: >Originator: Pietro Cerutti >Release: FreeBSD 8.0-CURRENT i386 >Organization: >Environment: System: FreeBSD 8.0-CURRENT #18: Tue Dec 18 12:48:22 CET 2007 root@gahrtop.localhost:/usr/obj/usr/src/sys/MSI1034 >Description: The following patch: 1) adds support for the coretemp(4) sensor 2) fixes a bug causing only one instance of a sensor type to be added 1) coretemp(4) is a kernel module allowing to sense the temperature on each core of an Intel Core Duo processor. 2) this means that if you have two sensors of an instance, e.g. two temperature sensors, only the first one is added to GKrellm's sensors list. >How-To-Repeat: >Fix: --- _gkrellm2.diff begins here --- --- Makefile.orig 2007-12-21 03:34:49.000000000 +0100 +++ Makefile 2007-12-21 03:34:58.000000000 +0100 @@ -7,7 +7,7 @@ PORTNAME= gkrellm PORTVERSION= 2.3.0 -#PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= sysutils ipv6 MASTER_SITES= http://members.dslextreme.com/users/billw/gkrellm/ \ ${MASTER_SITE_LOCAL} --- /dev/null 2007-12-21 03:33:00.000000000 +0100 +++ files/patch-src-sysdeps_freebsd.c 2007-12-21 03:34:16.000000000 +0100 @@ -0,0 +1,195 @@ +--- src/sysdeps/freebsd.c.orig 2007-07-07 01:53:07.000000000 +0200 ++++ src/sysdeps/freebsd.c 2007-12-21 03:33:54.000000000 +0100 +@@ -32,7 +32,6 @@ + static void scan_for_sensors(); + #endif + +- + void + gkrellm_sys_main_init(void) + { +@@ -63,18 +62,6 @@ + #include <sys/param.h> + #include <sys/sysctl.h> + +-static int +-gk_sysctlnametomib(const char *name, int *mibp, size_t *lenp) +- { +- static int oid_name2oid[2] = { 0, 3 }; +- +- if (sysctl(oid_name2oid, 2, mibp, lenp, +- (void *)name, strlen(name)) < 0) +- return -1; +- *lenp /= sizeof(int); +- return 0; +- } +- + /* ===================================================================== */ + /* CPU monitor interface */ + +@@ -134,7 +121,7 @@ + + gkrellm_cpu_set_number_of_cpus(1); + +- if (gk_sysctlnametomib(name, oid_cp_time, &oid_cp_time_len) < 0) ++ if (sysctlnametomib(name, oid_cp_time, &oid_cp_time_len) < 0) + return TRUE; + ++have_cp_time; + return TRUE; +@@ -186,11 +173,11 @@ + static char *rname = "vm.stats.vm.v_rforks"; + + /* check if vm.stats.vm.v_forks is available */ +- if (gk_sysctlnametomib(name, oid_v_forks, &oid_v_forks_len) < 0) ++ if (sysctlnametomib(name, oid_v_forks, &oid_v_forks_len) < 0) + return TRUE; +- if (gk_sysctlnametomib(vname, oid_v_vforks, &oid_v_vforks_len) < 0) ++ if (sysctlnametomib(vname, oid_v_vforks, &oid_v_vforks_len) < 0) + return TRUE; +- if (gk_sysctlnametomib(rname, oid_v_rforks, &oid_v_rforks_len) < 0) ++ if (sysctlnametomib(rname, oid_v_rforks, &oid_v_rforks_len) < 0) + return TRUE; + ++have_v_forks; + return TRUE; +@@ -574,7 +561,7 @@ + + if (!initialized) + { +- if (gk_sysctlnametomib(name, oid_pcblist, ++ if (sysctlnametomib(name, oid_pcblist, + &oid_pcblist_len) < 0) + return; + ++initialized; +@@ -879,7 +866,7 @@ + + if (!initialized) + { +- if (gk_sysctlnametomib(name, oid_bufspace, ++ if (sysctlnametomib(name, oid_bufspace, + &oid_bufspace_len) < 0) + return 0; + ++initialized; +@@ -977,7 +964,7 @@ + for (i = 0; mibs[i].name; ++i) + { + mibs[i].oid_len = sizeof(mibs[i].oid); +- if (gk_sysctlnametomib(mibs[i].name, ++ if (sysctlnametomib(mibs[i].name, + mibs[i].oid, + &mibs[i].oid_len) < 0) + return; +@@ -1130,7 +1117,7 @@ + */ + for (i = 0; name[i] != NULL; ++i) + { +- if (gk_sysctlnametomib(name[i], oid[i], ++ if (sysctlnametomib(name[i], oid[i], + &oid_len[i]) < 0) + break; + } +@@ -1286,6 +1273,7 @@ + #define INTERFACE_IO 0 + #define INTERFACE_SMB 1 + #define INTERFACE_ACPI 2 ++#define INTERFACE_CORETEMP 3 /* Already in Celsius */ + + /* Addresses to use for /dev/io */ + #define WBIO1 0x295 +@@ -1363,6 +1351,17 @@ + *temp = (gfloat) TZ_KELVTOC(value); + return TRUE; + } ++ if (interface == INTERFACE_CORETEMP) ++ { ++ int value; ++ size_t size = sizeof(value); ++ ++ if (sysctlbyname(path, &value, &size, NULL, 0) < 0) ++ return FALSE; ++ if (temp) ++ *temp = (gfloat) value; ++ return TRUE; ++ } + if (get_data(iodev, LM78_TEMP, interface, &byte)) + { + if (temp) +@@ -1443,35 +1442,47 @@ + */ + gkrellm_sys_sensors_mbmon_check(TRUE); + +- for (id = 0;;) ++ /* ++ * ACPI Thermal ++ */ ++ for (id = 0;;id++) + { +- snprintf(mib_name, sizeof(mib_name), +- "hw.acpi.thermal.tz%d.temperature", id); +- if (gk_sysctlnametomib(mib_name, oid_acpi_temp, +- &oid_acpi_temp_len) < 0) ++ snprintf(mib_name, sizeof(mib_name), "hw.acpi.thermal.tz%d.temperature", id); ++ if (sysctlnametomib(mib_name, oid_acpi_temp, &oid_acpi_temp_len) < 0) + break; + interface = INTERFACE_ACPI; +- if (!gkrellm_sys_sensors_get_temperature(mib_name, 0, 0, +- interface, NULL)) ++ if (!gkrellm_sys_sensors_get_temperature(mib_name, 0, 0, interface, NULL)) + continue; + snprintf(label, sizeof(label), "tz%d", id); +- gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, +- mib_name, 0, 0, +- interface, 1.0, 0.0, NULL, label); ++ gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, mib_name, 0, 0, interface, 1.0, 0.0, NULL, label); + } + +- if (freebsd_sensor_list) +- { +- for (list = freebsd_sensor_list; list; list = list->next) +- { +- sensor = (struct freebsd_sensor *)list->data; +- gkrellm_sensors_add_sensor(sensor->type, NULL, +- sensor->id_name, sensor->id, +- sensor->iodev, sensor->inter, +- sensor->factor, sensor->offset, +- NULL, sensor->default_label); +- } +- } ++ /* ++ * Coretemp ++ */ ++ for (id = 0;;id++) ++ { ++ snprintf(mib_name, sizeof(mib_name), "dev.cpu.%d.temperature", id); ++ if (sysctlnametomib(mib_name, oid_acpi_temp, &oid_acpi_temp_len) < 0) ++ break; ++ interface = INTERFACE_CORETEMP; ++ if (!gkrellm_sys_sensors_get_temperature(mib_name, 0, 0, interface, NULL)) ++ continue; ++ snprintf(label, sizeof(label), "cpu%d", id); ++ gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, mib_name, 0, 0, interface, 1.0, 0.0, NULL, label); ++ } ++ ++ ++ if (freebsd_sensor_list) { ++ for (list = freebsd_sensor_list; list; list = list->next) { ++ sensor = (struct freebsd_sensor *)list->data; ++ gkrellm_sensors_add_sensor(sensor->type, NULL, ++ sensor->id_name, sensor->id, ++ sensor->iodev, sensor->inter, ++ sensor->factor, sensor->offset, ++ NULL, sensor->default_label); ++ } ++ } + + return (TRUE); + } +@@ -1537,8 +1548,7 @@ + close(iodev); + continue; + } +- sensors_add_sensor(SENSOR_TEMPERATURE, id_name, 0, +- iodev, interface, 1.0, 0.0, NULL); ++ sensors_add_sensor(SENSOR_TEMPERATURE, id_name, 0, iodev, interface, 1.0, 0.0, NULL); + found_sensors = TRUE; + break; + } --- _gkrellm2.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1198204862.73012>