[PATCH] Adds additional CPU details fields.
Darryl L. Pierce
dpierce at redhat.com
Wed Sep 3 07:50:00 PDT 2008
The following fields will now reported for each CPU:
1. CPU number explicitly,
2. Core ID,
3. Vendor name,
4. CPU family ID,
5. CPU model ID,
6. CPUID level,
7. Cache size,
8. CPU speed, and
9. CPU flags.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
hald/linux/acpi.c | 110 ++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 87 insertions(+), 23 deletions(-)
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 6f76af6..caae626 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -480,17 +480,19 @@ battery_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_refr
}
/**
- * get_processor_model_name:
+ * get_processor_attribute_by_name:
* @proc_num: Number of processor
+ * @name: Attribute name
*
- * Returns: Name of the processor model
+ * Returns: Value of the attribute.
*
- * Give the model name of the processor.
+ * Returns the value for the named attribute.
*/
static gchar *
-get_processor_model_name (gint proc_num)
+get_processor_attribute_by_name(gint proc_num, gchar * name)
{
- gchar *model_name;
+ gchar *result = NULL;
+ gchar *attr_value;
gchar *contents = NULL;
GError *error = NULL;
@@ -502,46 +504,45 @@ get_processor_model_name (gint proc_num)
gchar *cursor;
gint i;
-
+ gchar *attr_label;
+
if (g_file_get_contents ("/proc/cpuinfo", & contents, NULL, & error)) {
lines = g_strsplit (contents, "\n", 0);
for (i = 0; lines [i]; ++i) {
if (strstr (lines [i], "processor\t:")) {
cursor = strstr (lines [i], ":");
-
+
proc_num_i = atoi (cursor + 1);
-
+
if (proc_num_i == proc_num) {
for (; lines [i]; ++i) {
- if (strstr (lines [i], "model name\t:")) {
+
+ if (g_strv_length(lines[1]) && strstr (lines [i], attr_label)) {
cursor = strstr (lines [i], ":");
-
+
g_strstrip (++ cursor);
- model_name = g_strdup (cursor);
-
- g_strfreev (lines);
- g_free (contents);
+ attr_value = g_strdup (cursor);
- return model_name;
+ result = attr_value;
+ break;
}
}
}
}
}
- if (lines) {
- g_strfreev (lines);
- }
- }
- else {
+ g_strfreev (lines);
+ g_free (contents);
+ g_free (attr_label);
+ } else {
HAL_ERROR (("Couldn't open /proc/cpuinfo: %s", error->message));
g_error_free (error);
}
-
- return NULL;
+
+ return result;
}
static gboolean
@@ -551,6 +552,7 @@ processor_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_re
gchar *model_name;
gint proc_num;
+ gchar *processor_value;
path = hal_device_property_get_string (d, "linux.acpi_path");
if (path == NULL)
@@ -560,7 +562,7 @@ processor_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_re
path, "info", "processor id", 0, 10, FALSE
);
- if ((model_name = get_processor_model_name (proc_num))) {
+ if ((model_name = get_processor_attribute_by_name (proc_num, "model name"))) {
hal_device_property_set_string (d, "info.product", model_name);
g_free (model_name);
@@ -570,6 +572,68 @@ processor_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_re
hal_device_property_set_string (d, "info.category", "processor");
hal_device_add_capability (d, "processor");
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "vendor_id"))) {
+ hal_device_property_set_string (d, "processor.vendor", processor_value);
+
+ g_free (processor_value);
+ }
+
+ hal_device_property_set_int (d, "processor.id", proc_num);
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "core id\t"))) {
+ gint core = atoi (processor_value);
+
+ hal_device_property_set_int (d, "processor.core", core);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "cpu family"))) {
+ gint family = atoi(processor_value);
+
+ hal_device_property_set_int (d, "processor.family", family);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "model\t"))) {
+ gint model = atoi(processor_value);
+
+
+ hal_device_property_set_int (d, "processor.model", model);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "cpuid level"))) {
+ gint level = atoi(processor_value);
+
+ hal_device_property_set_int (d, "processor.cpuid_level", level);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "cpu MHz\t"))) {
+ gdouble speed = g_ascii_strtod(processor_value, NULL);
+
+ hal_device_property_set_double (d, "processor.speed", speed);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "cache size"))) {
+ hal_device_property_set_string (d, "processor.cache", processor_value);
+
+ g_free (processor_value);
+ }
+
+ if((processor_value = get_processor_attribute_by_name(proc_num, "flags\t"))) {
+ hal_device_property_set_string (d, "processor.flags", processor_value);
+
+ g_free (processor_value);
+ }
+
hal_util_set_int_elem_from_file (d, "processor.number", path,
"info", "processor id", 0, 10, FALSE);
hal_util_set_bool_elem_from_file (d, "processor.can_throttle", path,
--
1.5.5.1
More information about the hal
mailing list