diff options
| author | Burt P <pburt0@gmail.com> | 2017-12-10 22:38:17 -0600 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2018-02-27 07:43:20 -0800 | 
| commit | 2f9dad39b0847991dd2b19dc3e999f89397f47f9 (patch) | |
| tree | 59fdcc4a9d62b99a66ba376029ab52dca3b818e5 /modules/devices/x86 | |
| parent | 6a9f6819ae661f64c3c042d48f74d6419f63580e (diff) | |
x86,arm: cpu clocks list in package information
Show actual clocks where cores or threads share a clock.
Ex: x86 SMT each core has one clock shared by both threads.
Ex: BCM2837 has one clock for all four cores.
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices/x86')
| -rw-r--r-- | modules/devices/x86/processor.c | 105 | 
1 files changed, 102 insertions, 3 deletions
| diff --git a/modules/devices/x86/processor.c b/modules/devices/x86/processor.c index f18ef155..46c524b9 100644 --- a/modules/devices/x86/processor.c +++ b/modules/devices/x86/processor.c @@ -234,6 +234,97 @@ fail:      g_free(endpoint);  } +#define khzint_to_mhzdouble(k) (((double)k)/1000) +#define cmp_clocks_test(f) if (a->f < b->f) return -1; if (a->f > b->f) return 1; + +static gint cmp_cpufreq_data(cpufreq_data *a, cpufreq_data *b) { +        gint i = 0; +        i = g_strcmp0(a->shared_list, b->shared_list); if (i!=0) return i; +        cmp_clocks_test(cpukhz_max); +        cmp_clocks_test(cpukhz_min); +        return 0; +} + +static gint cmp_cpufreq_data_ignore_affected(cpufreq_data *a, cpufreq_data *b) { +        gint i = 0; +        cmp_clocks_test(cpukhz_max); +        cmp_clocks_test(cpukhz_min); +        return 0; +} + +gchar *clocks_summary(GSList * processors) +{ +    gchar *ret = g_strdup("[Clocks]\n"); +    GSList *all_clocks = NULL, *uniq_clocks = NULL; +    GSList *tmp, *l; +    Processor *p; +    cpufreq_data *c, *cur = NULL; +    gint cur_count = 0, i = 0; + +    /* create list of all clock references */ +    for (l = processors; l; l = l->next) { +        p = (Processor*)l->data; +        if (p->cpufreq) { +            all_clocks = g_slist_prepend(all_clocks, p->cpufreq); +        } +    } + +    if (g_slist_length(all_clocks) == 0) { +        ret = h_strdup_cprintf("%s=\n", ret, _("(Not Available)") ); +        g_slist_free(all_clocks); +        return ret; +    } + +    /* ignore duplicate references */ +    all_clocks = g_slist_sort(all_clocks, (GCompareFunc)cmp_cpufreq_data); +    for (l = all_clocks; l; l = l->next) { +        c = (cpufreq_data*)l->data; +        if (!cur) { +            cur = c; +        } else { +            if (cmp_cpufreq_data(cur, c) != 0) { +                uniq_clocks = g_slist_prepend(uniq_clocks, cur); +                cur = c; +            } +        } +    } +    uniq_clocks = g_slist_prepend(uniq_clocks, cur); +    uniq_clocks = g_slist_reverse(uniq_clocks); +    cur = 0, cur_count = 0; + +    /* count and list clocks */ +    for (l = uniq_clocks; l; l = l->next) { +        c = (cpufreq_data*)l->data; +        if (!cur) { +            cur = c; +            cur_count = 1; +        } else { +            if (cmp_cpufreq_data_ignore_affected(cur, c) != 0) { +                ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), +                                ret, +                                khzint_to_mhzdouble(cur->cpukhz_min), +                                khzint_to_mhzdouble(cur->cpukhz_max), +                                _("MHz"), +                                cur_count); +                cur = c; +                cur_count = 1; +            } else { +                cur_count++; +            } +        } +    } +    ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), +                    ret, +                    khzint_to_mhzdouble(cur->cpukhz_min), +                    khzint_to_mhzdouble(cur->cpukhz_max), +                    _("MHz"), +                    cur_count); + +    g_slist_free(all_clocks); +    g_slist_free(uniq_clocks); +    return ret; +} +  #define cmp_cache_test(f) if (a->f < b->f) return -1; if (a->f > b->f) return 1;  static gint cmp_cache(ProcessorCache *a, ProcessorCache *b) { @@ -257,7 +348,7 @@ static gint cmp_cache_ignore_id(ProcessorCache *a, ProcessorCache *b) {  gchar *caches_summary(GSList * processors)  { -    gchar *ret = g_strdup("[Caches]\n"); +    gchar *ret = g_strdup_printf("[%s]\n", _("Caches"));      GSList *all_cache = NULL, *uniq_cache = NULL;      GSList *tmp, *l;      Processor *p; @@ -278,7 +369,7 @@ gchar *caches_summary(GSList * processors)      }      if (g_slist_length(all_cache) == 0) { -        ret = h_strdup_cprintf("%s", ret, _("(Not Available)") ); +        ret = h_strdup_cprintf("%s=\n", ret, _("(Not Available)") );          g_slist_free(all_cache);          return ret;      } @@ -574,18 +665,26 @@ gchar *processor_describe(GSList * processors) {  gchar *processor_meta(GSList * processors) {      gchar *meta_cpu_name = processor_name(processors);      gchar *meta_cpu_desc = processor_describe(processors); +    gchar *meta_freq_desc = processor_frequency_desc(processors); +    gchar *meta_clocks = clocks_summary(processors);      gchar *meta_caches = caches_summary(processors);      gchar *ret = NULL;      UNKIFNULL(meta_cpu_desc);      ret = g_strdup_printf("[%s]\n"                          "%s=%s\n"                          "%s=%s\n" +                        "%s=%s\n" +                        "%s"                          "%s",                          _("Package Information"),                          _("Name"), meta_cpu_name, -                        _("Description"), meta_cpu_desc, +                        _("Topology"), meta_cpu_desc, +                        _("Logical CPU Config"), meta_freq_desc, +                        meta_clocks,                          meta_caches);      g_free(meta_cpu_desc); +    g_free(meta_freq_desc); +    g_free(meta_clocks);      g_free(meta_caches);      return ret;  } | 
