diff options
author | Burt P <pburt0@gmail.com> | 2017-08-10 22:54:33 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2017-08-11 02:52:21 -0700 |
commit | ecdc375c54201be5776ce93d665ee77f74b1167a (patch) | |
tree | e7f1354d5587a58306a41ecd2b2f73b40e11f2f0 /modules/devices.c | |
parent | 242cf8f80c05d655c3ae6ce22ec3751668b11895 (diff) |
CPU Frequency Desc and benchmark result re-format
Current CPU configurations aren't properly represented in Hardinfo.
For SMT, each hardware thread is still reported as a CPU. Clusters
with different CPU clock rates are not reported. It is common for
ARM to pair a cluster of fast cores with a cluster of slower, but
more power-efficient cores. These changes attempt to address this.
The getProcessorFrequency method now returns the processor's max
frequency for all its cores. While the new
getProcessorFrequencyDesc lists each unique frequency with a prefix
Nx with the count of cores at that freqency.
Benchmark results have been reformated to use the de-prefixed
getProcessorName and getProcessorFrequencyDesc.
As an example from benchmark.conf:
4x AMD Phenom(tm) II X4 940 Processor | 800 MHz
becomes:
AMD Phenom(tm) II X4 940 Processor | 4x 800 MHz
Which, I think, makes much more sense, as it works well with
this kind of thing:
Qualcomm Snapdragon 691 | 4x 1400 MHz + 4x 800 MHz
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices.c')
-rw-r--r-- | modules/devices.c | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/modules/devices.c b/modules/devices.c index b524f908..7246ef9d 100644 --- a/modules/devices.c +++ b/modules/devices.c @@ -126,10 +126,18 @@ gchar *lginterval = NULL; #include <vendor.h> -static gint proc_cmp(Processor *a, Processor *b) { +static gint proc_cmp_model_name(Processor *a, Processor *b) { return g_strcmp0(a->model_name, b->model_name); } +static gint proc_cmp_max_freq(Processor *a, Processor *b) { + if (a->cpu_mhz == b->cpu_mhz) + return 0; + if (a->cpu_mhz > b->cpu_mhz) + return -1; + return 1; +} + gchar *processor_describe_default(GSList * processors) { int packs, cores, threads; @@ -161,7 +169,7 @@ gchar *processor_name_default(GSList * processors) gint cur_count = 0; tmp = g_slist_copy(processors); - tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp); + tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp_model_name); for (l = tmp; l; l = l->next) { p = (Processor*)l->data; @@ -183,6 +191,7 @@ gchar *processor_name_default(GSList * processors) return ret; } +/* TODO: prefix counts are threads when they should be cores. */ gchar *processor_describe_by_counting_names(GSList * processors) { gchar *ret = g_strdup(""); @@ -192,7 +201,7 @@ gchar *processor_describe_by_counting_names(GSList * processors) gint cur_count = 0; tmp = g_slist_copy(processors); - tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp); + tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp_model_name); for (l = tmp; l; l = l->next) { p = (Processor*)l->data; @@ -266,17 +275,64 @@ gchar *get_processor_count(void) return g_strdup_printf("%d", g_slist_length(processors)); } -gchar *get_processor_frequency(void) +/* TODO: maybe move into processor.c along with processor_name() etc. + * Could mention the big.LITTLE cluster arangement for ARM that kind of thing. + * TODO: prefix counts are threads when they should be cores. */ +gchar *processor_frequency_desc(GSList * processors) { + gchar *ret = g_strdup(""); + GSList *tmp, *l; Processor *p; + float cur_val = -1; + gint cur_count = 0; + + tmp = g_slist_copy(processors); + tmp = g_slist_sort(tmp, (GCompareFunc)proc_cmp_max_freq); + for (l = tmp; l; l = l->next) { + p = (Processor*)l->data; + if (cur_val == -1) { + cur_val = p->cpu_mhz; + cur_count = 1; + } else { + if(cur_val != p->cpu_mhz) { + ret = h_strdup_cprintf("%s%dx %.2f %s", ret, strlen(ret) ? " + " : "", cur_count, cur_val, _("MHz") ); + cur_val = p->cpu_mhz; + cur_count = 1; + } else { + cur_count++; + } + } + } + ret = h_strdup_cprintf("%s%dx %0.2f %s", ret, strlen(ret) ? " + " : "", cur_count, cur_val, _("MHz")); + g_slist_free(tmp); + return ret; +} + +gchar *get_processor_frequency_desc(void) +{ scan_processors(FALSE); + return processor_frequency_desc(processors); +} + +gchar *get_processor_max_frequency(void) +{ + GSList *l; + Processor *p; + float max_freq = 0; + + scan_processors(FALSE); + + for (l = processors; l; l = l->next) { + p = (Processor*)l->data; + if (p->cpu_mhz > max_freq) + max_freq = p->cpu_mhz; + } - p = (Processor *)processors->data; - if (p->cpu_mhz == 0.0f) { + if (max_freq == 0.0f) { return g_strdup(N_("Unknown")); } else { - return g_strdup_printf("%.0f", p->cpu_mhz); + return g_strdup_printf("%.0f %s", max_freq, _("MHz") ); } } @@ -329,11 +385,12 @@ gchar *get_motherboard(void) ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { - {"getProcessorCount", get_processor_count}, + {"getProcessorCount", get_processor_count}, {"getProcessorName", get_processor_name}, {"getProcessorDesc", get_processor_desc}, {"getProcessorNameAndDesc", get_processor_name_and_desc}, - {"getProcessorFrequency", get_processor_frequency}, + {"getProcessorFrequency", get_processor_max_frequency}, + {"getProcessorFrequencyDesc", get_processor_frequency_desc}, {"getMemoryTotal", get_memory_total}, {"getStorageDevices", get_storage_devices}, {"getPrinters", get_printers}, |