diff options
author | Burt P <pburt0@gmail.com> | 2017-06-02 10:34:16 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2017-06-02 12:50:14 -0700 |
commit | 9d55d26bb4f3d7a4a07a74ec66ac25240296b7e7 (patch) | |
tree | 5ec911e9afb854f2fe1bd5d6109fa66da110d42f /modules | |
parent | e00d167ea7968928f1130d52f1df62b4434e39cb (diff) |
arm: use processor id from cpuinfo instead of counter
Also fixes a memleak.
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/devices/arm/processor.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/modules/devices/arm/processor.c b/modules/devices/arm/processor.c index a18f6374..5c690e9f 100644 --- a/modules/devices/arm/processor.c +++ b/modules/devices/arm/processor.c @@ -97,7 +97,6 @@ processor_scan(void) { GSList *procs = NULL; Processor *processor = NULL; - gint processor_number = 0; FILE *cpuinfo; gchar buffer[128]; gchar *rep_pname = NULL; @@ -108,24 +107,44 @@ processor_scan(void) if (!cpuinfo) return NULL; +#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) while (fgets(buffer, 128, cpuinfo)) { gchar **tmp = g_strsplit(buffer, ":", 2); if (tmp[0] && tmp[1]) { tmp[0] = g_strstrip(tmp[0]); tmp[1] = g_strstrip(tmp[1]); - } else continue; + } else { + g_strfreev(tmp); + continue; + } get_str("Processor", rep_pname); - if (g_str_has_prefix(tmp[0], "processor")) { + if ( CHECK_FOR("processor") ) { + /* finish previous */ if (processor) { procs = g_slist_append(procs, processor); } + /* start next */ + processor = g_new0(Processor, 1); + processor->id = atol(tmp[1]); + + if (rep_pname) + processor->model_name = g_strdup(rep_pname); + + g_strfreev(tmp); + continue; + } + + if (!processor && + ( CHECK_FOR("model name") + || CHECK_FOR("Features") + || CHECK_FOR("BogoMIPS") ) ) { + + /* single proc/core may not have "processor : n" */ processor = g_new0(Processor, 1); - //get_int("processor", processor->id); //FIXME: - processor->id = processor_number; - processor_number++; + processor->id = 0; if (rep_pname) processor->model_name = g_strdup(rep_pname); |