diff options
author | Burt P <pburt0@gmail.com> | 2017-08-10 11:20:16 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2017-08-11 02:52:21 -0700 |
commit | 05c4a4c9451b7b07577255f7927cec6d70f2cf8d (patch) | |
tree | 1de5a3e76a59ecf4784f0fd15152690223c83ac0 /modules/devices.c | |
parent | 0b998d0cf01d497e998c17c251b241510ba38f3e (diff) |
Separate processor name and description + count cores and threads
* add cpu_procs_cores_threads() function to get counts from sysfs/topology
* each platform must now provide processor_name() and processor_describe()
* processor_name_default(): returns a list of unique processor->model_name
* processor_describe_default(): returns "N physical; M cores; L threads"
* processor_describe_by_counting_names(): returns a list of unique
processor->model_name with Nx prefix
(ex: "4x ARM Cortex A53 + 4x ARM Cortex A33")
* x86: _name and _describe use defaults
* arm: _name returns name of SOC, if available, _describe returns
processor_describe_by_counting_names()
* all other platforms: _name and _describe use defaults
* Computer module summary now shows both name and description for CPU
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices.c')
-rw-r--r-- | modules/devices.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/modules/devices.c b/modules/devices.c index 8f1b19e3..affa2a35 100644 --- a/modules/devices.c +++ b/modules/devices.c @@ -130,7 +130,49 @@ static gint proc_cmp(Processor *a, Processor *b) { return g_strcmp0(a->model_name, b->model_name); } -gchar *processor_describe(GSList * processors) +gchar *processor_describe_default(GSList * processors) +{ + int packs, cores, threads; + cpu_procs_cores_threads(&packs, &cores, &threads); + /* if topology info was available, else fallback to old method */ + if (cores > 0) + return g_strdup_printf("%d physical processor(s); %d core(s); %d thread(s)", packs, cores, threads); + else + return processor_describe_by_counting_names(processors); +} + +gchar *processor_name_default(GSList * processors) +{ + gchar *ret = g_strdup(""); + GSList *tmp, *l; + Processor *p; + gchar *cur_str = NULL; + gint cur_count = 0; + + tmp = g_slist_copy(processors); + tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp); + + for (l = tmp; l; l = l->next) { + p = (Processor*)l->data; + if (cur_str == NULL) { + cur_str = p->model_name; + cur_count = 1; + } else { + if(g_strcmp0(cur_str, p->model_name)) { + ret = h_strdup_cprintf("%s%s", ret, strlen(ret) ? "; " : "", cur_str); + cur_str = p->model_name; + cur_count = 1; + } else { + cur_count++; + } + } + } + ret = h_strdup_cprintf("%s%s", ret, strlen(ret) ? "; " : "", cur_str); + g_slist_free(tmp); + return ret; +} + +gchar *processor_describe_by_counting_names(GSList * processors) { gchar *ret = g_strdup(""); GSList *tmp, *l; @@ -164,9 +206,27 @@ gchar *processor_describe(GSList * processors) gchar *get_processor_name(void) { scan_processors(FALSE); + return processor_name(processors); +} + +gchar *get_processor_desc(void) +{ + scan_processors(FALSE); return processor_describe(processors); } +gchar *get_processor_name_and_desc(void) +{ + scan_processors(FALSE); + gchar* name = processor_name(processors); + gchar* desc = processor_describe(processors); + gchar* nd = g_strdup_printf("%s\n%s", name, desc); + g_free(name); + g_free(desc); + return nd; +} + + gchar *get_storage_devices(void) { scan_storage(FALSE); @@ -260,6 +320,8 @@ ShellModuleMethod *hi_exported_methods(void) static ShellModuleMethod m[] = { {"getProcessorCount", get_processor_count}, {"getProcessorName", get_processor_name}, + {"getProcessorDesc", get_processor_desc}, + {"getProcessorNameAndDesc", get_processor_name_and_desc}, {"getProcessorFrequency", get_processor_frequency}, {"getMemoryTotal", get_memory_total}, {"getStorageDevices", get_storage_devices}, |