From d42ee4cb296043ee763ea93afe16ea534b0d70d0 Mon Sep 17 00:00:00 2001 From: Burt P Date: Mon, 10 Jul 2017 00:12:35 -0500 Subject: Move common processor stuff into cpu_util.{h,c} * PROC_CPUINFO define used in testing * STRIFNULL(), UNKIFNULL() EMPIFNULL() macros used in reading cpuinfo * byte order, topology, and cpufreq data structures and functions that are platform independent * processor_has_flag() helper Signed-off-by: Burt P --- includes/cpu_util.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 includes/cpu_util.h (limited to 'includes/cpu_util.h') diff --git a/includes/cpu_util.h b/includes/cpu_util.h new file mode 100644 index 00000000..656a402c --- /dev/null +++ b/includes/cpu_util.h @@ -0,0 +1,48 @@ +#ifndef __CPU_UTIL_H__ +#define __CPU_UTIL_H__ + +#include "hardinfo.h" + +#ifndef PROC_CPUINFO +#define PROC_CPUINFO "/proc/cpuinfo" +#endif + +/* needs a local Processor *processor */ +#define STRIFNULL(f,cs) if (processor->f == NULL) processor->f = g_strdup(cs); +#define UNKIFNULL(f) STRIFNULL(f, _("(Unknown)") ) +#define EMPIFNULL(f) STRIFNULL(f, "") + +gchar *byte_order_str(void); + +/* from /sys/devices/system/cpu/cpu%d/%s */ +gchar* get_cpu_str(const gchar* file, gint cpuid); +gint get_cpu_int(const char* item, int cpuid); + +/* space delimted list of flags, finds flag */ +int processor_has_flag(gchar * strflags, gchar * strflag); + +typedef struct { + gint id; + gint cpukhz_max, cpukhz_min, cpukhz_cur; + gchar *scaling_driver, *scaling_governor; + gint transition_latency; +} cpufreq_data; + +typedef struct { + gint id; /* thread */ + gint socket_id; + gint core_id; +} cpu_topology_data; + +cpufreq_data *cpufreq_new(gint id); +void cpufreq_update(cpufreq_data *cpufd, int cur_only); +void cpufreq_free(cpufreq_data *cpufd); + +gchar *cpufreq_section_str(cpufreq_data *cpufd); + +cpu_topology_data *cputopo_new(gint id); +void cputopo_free(cpu_topology_data *cputd); + +gchar *cputopo_section_str(cpu_topology_data *cputd); + +#endif -- cgit v1.2.3