From cee8ba48f02a7cf0ee45db22915fedbff4349bc9 Mon Sep 17 00:00:00 2001 From: kitsunyan Date: Sat, 6 Jul 2019 20:19:09 +0300 Subject: [PATCH] Remove typedefs --- config.c | 38 +++++++++++++++++++------------------- config.h | 46 +++++++++++++++++++++++----------------------- main.c | 20 +++++++++----------- measure.c | 28 ++++++++++++++-------------- modes.c | 6 +++--- power.c | 46 +++++++++++++++++++++++----------------------- power.h | 16 ++++++++-------- scaling.c | 36 ++++++++++++++++++------------------ scaling.h | 8 ++++---- stat.c | 30 +++++++++++++++--------------- stat.h | 10 +++++----- undervolt.c | 12 ++++++------ undervolt.h | 6 +++--- util.c | 26 +++++++++++++------------- util.h | 14 +++++++------- 15 files changed, 170 insertions(+), 172 deletions(-) diff --git a/config.c b/config.c index 94de091..c88fe11 100644 --- a/config.c +++ b/config.c @@ -9,17 +9,17 @@ #include static void undervolt_free(void * pointer) { - undervolt_t * undervolt = pointer; + struct undervolt_t * undervolt = pointer; free(undervolt->title); } static void hwp_power_term_free(void * pointer) { - hwp_power_term_t * hwp_power_term = pointer; + struct hwp_power_term_t * hwp_power_term = pointer; free(hwp_power_term->domain); } static void hwp_hint_free(void * pointer) { - hwp_hint_t * hwp_hint = pointer; + struct hwp_hint_t * hwp_hint = pointer; if (hwp_hint->hwp_power_terms) { array_free(hwp_hint->hwp_power_terms); } @@ -27,7 +27,7 @@ static void hwp_hint_free(void * pointer) { free(hwp_hint->normal_hint); } -void free_config(config_t * config) { +void free_config(struct config_t * config) { if (config) { unsigned int i; if (config->undervolts) { @@ -52,7 +52,7 @@ void free_config(config_t * config) { } static bool parse_power_limit_value(const char * line, - power_limit_value_t * value) { + struct power_limit_value_t * value) { char * tmp = NULL; char * next = NULL; int power = (int) strtol(line, &tmp, 10); @@ -146,7 +146,7 @@ static bool parse_hwp_load(const char * line, bool * multi, float * threshold, } } -static bool parse_hwp_power(const char * line, array_t ** hwp_power_terms, +static bool parse_hwp_power(const char * line, struct array_t ** hwp_power_terms, bool * nl, bool * nll) { int args = 1; bool error = false; @@ -154,7 +154,7 @@ static bool parse_hwp_power(const char * line, array_t ** hwp_power_terms, char * domain = NULL; bool greater; float power; - array_t * result = NULL; + struct array_t * result = NULL; while (line) { int len; @@ -198,7 +198,7 @@ static bool parse_hwp_power(const char * line, array_t ** hwp_power_terms, break; } } else if (args % 4 == 3) { - hwp_power_term_t * hwp_power_term; + struct hwp_power_term_t * hwp_power_term; power = strtof(line, &tmp); if (tmp) { int tmp_len = (int) (tmp - line); @@ -210,7 +210,7 @@ static bool parse_hwp_power(const char * line, array_t ** hwp_power_terms, } } if (!result) { - result = array_new(sizeof(hwp_power_term_t), + result = array_new(sizeof(struct hwp_power_term_t), hwp_power_term_free); } hwp_power_term = result ? array_add(result) : NULL; @@ -266,13 +266,13 @@ static bool contains_hint_or_append(const char ** hints, int count, return false; } -static bool validate_hwp_hint(array_t * hwp_hints, bool * nl, bool * nll) { +static bool validate_hwp_hint(struct array_t * hwp_hints, bool * nl, bool * nll) { int i; int force_count = 0; const char * hints[2 * hwp_hints->count]; for (i = 0; i < hwp_hints->count; i++) { - hwp_hint_t * hwp_hint = array_get(hwp_hints, i); + struct hwp_hint_t * hwp_hint = array_get(hwp_hints, i); if (contains_hint_or_append(hints, 2 * i, hwp_hint->load_hint) || contains_hint_or_append(hints, 2 * i + 1, hwp_hint->normal_hint)) { NEW_LINE(nl, *nll); @@ -299,10 +299,10 @@ static bool validate_hwp_hint(array_t * hwp_hints, bool * nl, bool * nll) { return true; } -config_t * load_config(config_t * old_config, bool * nl) { +struct config_t * load_config(struct config_t * old_config, bool * nl) { unsigned int i; bool nll = false; - config_t * config; + struct config_t * config; if (old_config) { config = old_config; if (config->undervolts) { @@ -312,7 +312,7 @@ config_t * load_config(config_t * old_config, bool * nl) { array_free(config->hwp_hints); } } else { - config = malloc(sizeof(config_t)); + config = malloc(sizeof(struct config_t)); if (!config) { NEW_LINE(nl, nll); perror("No enough memory"); @@ -390,7 +390,7 @@ config_t * load_config(config_t * old_config, bool * nl) { int len; char * title; float value; - undervolt_t * undervolt; + struct undervolt_t * undervolt; iuv_read_line_error(); tmp = NULL; index = (int) strtol(line, &tmp, 10); @@ -414,7 +414,7 @@ config_t * load_config(config_t * old_config, bool * nl) { iuv_print_break("Invalid value: %s\n", line); } if (!config->undervolts) { - config->undervolts = array_new(sizeof(undervolt_t), + config->undervolts = array_new(sizeof(struct undervolt_t), undervolt_free); if (!config->undervolts) { free(title); @@ -478,10 +478,10 @@ config_t * load_config(config_t * old_config, bool * nl) { bool load_multi; float load_threshold; bool power = false; - array_t * hwp_power_terms = NULL; + struct array_t * hwp_power_terms = NULL; char * load_hint; char * normal_hint; - hwp_hint_t * hwp_hint; + struct hwp_hint_t * hwp_hint; iuv_read_line_error(); if (!strcmp(line, "force")) { force = true; @@ -529,7 +529,7 @@ config_t * load_config(config_t * old_config, bool * nl) { } memcpy(normal_hint, line, len + 1); if (!config->hwp_hints) { - config->hwp_hints = array_new(sizeof(hwp_hint_t), + config->hwp_hints = array_new(sizeof(struct hwp_hint_t), hwp_hint_free); if (!config->hwp_hints) { free(load_hint); diff --git a/config.h b/config.h index 75dc15e..8b7a8bc 100644 --- a/config.h +++ b/config.h @@ -10,65 +10,65 @@ #define MSR_ADDR_UNITS 0x606 #define MSR_ADDR_VOLTAGE 0x150 -typedef struct { +struct undervolt_t { int index; char * title; float value; -} undervolt_t; +}; -typedef struct { +struct power_domain_t { const char * name; size_t mem_addr; int msr_addr; -} power_domain_t; +}; -static power_domain_t power_domains[1] = { +static struct power_domain_t power_domains[1] = { { "package", 0xfed159a0, 0x610 } }; -typedef struct { +struct power_limit_value_t { int power; float time_window; bool enabled; -} power_limit_value_t; +}; -typedef struct { +struct power_limit_t { bool apply; - power_limit_value_t short_term; - power_limit_value_t long_term; + struct power_limit_value_t short_term; + struct power_limit_value_t long_term; void * mem; -} power_limit_t; +}; -typedef struct { +struct hwp_power_term_t { bool and; char * domain; bool greater; double power; -} hwp_power_term_t; +}; -typedef struct { +struct hwp_hint_t { bool force; bool load; bool load_multi; float load_threshold; bool power; - array_t * hwp_power_terms; + struct array_t * hwp_power_terms; char * load_hint; char * normal_hint; -} hwp_hint_t; +}; -typedef struct { +struct config_t { int fd_msr; int fd_mem; - array_t * undervolts; - power_limit_t power[ARRAY_SIZE(power_domains)]; + struct array_t * undervolts; + struct power_limit_t power[ARRAY_SIZE(power_domains)]; bool tjoffset_apply; float tjoffset; - array_t * hwp_hints; + struct array_t * hwp_hints; int interval; -} config_t; +}; -void free_config(config_t * config); -config_t * load_config(config_t * old_config, bool * nl); +void free_config(struct config_t * config); +struct config_t * load_config(struct config_t * old_config, bool * nl); #endif diff --git a/main.c b/main.c index 5e15ba4..daacdd6 100644 --- a/main.c +++ b/main.c @@ -13,24 +13,22 @@ enum arg_mode { ARG_MODE_FLOAT }; -typedef struct arg_t arg_t; - -typedef struct arg_t { +struct arg_t { char short_name; const char * long_name; enum arg_mode mode; - bool (* check)(arg_t *); + bool (* check)(struct arg_t *); bool present; const char * value; float float_value; -} arg_t; +}; #define ARG_END { '\0', NULL, ARG_MODE_END, NULL, false, NULL, 0 } #define ARG_EMPTY(s, l, c) { s, l, ARG_MODE_EMPTY, c, false, NULL, 0 } #define ARG_STRING(s, l, c, v) { s, l, ARG_MODE_STRING, c, false, v, 0 } #define ARG_FLOAT(s, l, c, v) { s, l, ARG_MODE_FLOAT, c, false, #v, v } -static bool handle_arg(arg_t * arg, const char * value, bool * consume_next) { +static bool handle_arg(struct arg_t * arg, const char * value, bool * consume_next) { arg->present = true; if (arg->mode == ARG_MODE_END || arg->mode == ARG_MODE_EMPTY) { *consume_next = false; @@ -63,7 +61,7 @@ static bool handle_arg(arg_t * arg, const char * value, bool * consume_next) { return !arg->check || arg->check(arg); } -static bool parse_args(int argc, char ** argv, arg_t * args) { +static bool parse_args(int argc, char ** argv, struct arg_t * args) { int i, j, k; bool consume_next; for (i = 0; i < argc; i++) { @@ -142,7 +140,7 @@ static bool parse_args(int argc, char ** argv, arg_t * args) { return true; } -static arg_t * arg(arg_t * args, const char * name) { +static struct arg_t * arg(struct arg_t * args, const char * name) { int i; bool s = strlen(name) == 1; for (i = 0; args && args[i].mode != ARG_MODE_END; i++) { @@ -154,7 +152,7 @@ static arg_t * arg(arg_t * args, const char * name) { return NULL; } -static bool arg_check_measure_format(arg_t * arg) { +static bool arg_check_measure_format(struct arg_t * arg) { if (strcmp(arg->value, "terminal") && strcmp(arg->value, "csv")) { fprintf(stderr, "Available formats: terminal, csv.\n"); return false; @@ -162,7 +160,7 @@ static bool arg_check_measure_format(arg_t * arg) { return true; } -static bool arg_check_measure_sleep(arg_t * arg) { +static bool arg_check_measure_sleep(struct arg_t * arg) { if (arg->float_value <= 0) { fprintf(stderr, "Sleep interval should be greater than 0.\n"); return false; @@ -178,7 +176,7 @@ int main(int argc, char ** argv) { return parse_args(argc - 2, &argv[2], NULL) && read_apply_mode(true) ? 0 : 1; } else if (argc >= 2 && !strcmp(argv[1], "measure")) { - arg_t args[3] = { + struct arg_t args[3] = { ARG_STRING('f', "format", arg_check_measure_format, "terminal"), ARG_FLOAT('s', "sleep", arg_check_measure_sleep, 1), ARG_END diff --git a/measure.c b/measure.c index ab8ee55..075db94 100644 --- a/measure.c +++ b/measure.c @@ -19,14 +19,14 @@ #define DIR_HWMON "/sys/class/hwmon" #define BUFSZ 80 -typedef struct { +struct hwmon_t { char * name; char * dir; int index; -} hwmon_t; +}; static void hwmon_free(void * pointer) { - hwmon_t * hwmon = pointer; + struct hwmon_t * hwmon = pointer; free(hwmon->name); free(hwmon->dir); } @@ -40,14 +40,14 @@ static void write_maxname(const char * name, int maxname) { } } -static void print_rapl(rapl_t * rapl, int maxname, bool * nl, bool csv) { +static void print_rapl(struct rapl_t * rapl, int maxname, bool * nl, bool csv) { bool nll = false; int i; rapl_measure(rapl); if (rapl) { for (i = 0; i < rapl->devices->count; i++) { - rapl_device_t * device = array_get(rapl->devices, i); + struct rapl_device_t * device = array_get(rapl->devices, i); if (csv) { CSV_SEPARATOR(nl, nll); printf("%.03f", device->power); @@ -60,13 +60,13 @@ static void print_rapl(rapl_t * rapl, int maxname, bool * nl, bool csv) { } } -static void print_hwmon(array_t * hwmons, int maxname, char * buf, +static void print_hwmon(struct array_t * hwmons, int maxname, char * buf, char * degstr, bool * nl, bool csv) { bool nll = false; int i; for (i = 0; hwmons && i < hwmons->count; i++) { - hwmon_t * hwmon = array_get(hwmons, i); + struct hwmon_t * hwmon = array_get(hwmons, i); int fd; sprintf(buf, DIR_HWMON "/%s/temp%d_input", hwmon->dir, hwmon->index); @@ -155,10 +155,10 @@ END_IGNORE_FORMAT_OVERFLOW return false; } -static array_t * get_coretemp(int * maxname) { +static struct array_t * get_coretemp(int * maxname) { char hdir[BUFSZ]; char buf[BUFSZ]; - array_t * hwmons = NULL; + struct array_t * hwmons = NULL; int i; if (!get_hwmon("coretemp", hdir)) { @@ -170,7 +170,7 @@ static array_t * get_coretemp(int * maxname) { int fd; char * name = NULL; char * dir; - hwmon_t * hwmon; + struct hwmon_t * hwmon; BEGIN_IGNORE_FORMAT_OVERFLOW sprintf(buf, DIR_HWMON "/%s/temp%d_input", hdir, i); @@ -215,7 +215,7 @@ END_IGNORE_FORMAT_OVERFLOW strcpy(dir, hdir); if (!hwmons) { - hwmons = array_new(sizeof(hwmon_t), hwmon_free); + hwmons = array_new(sizeof(struct hwmon_t), hwmon_free); if (!hwmons) { free(name); free(dir); @@ -253,15 +253,15 @@ static void sigint_handler(UNUSED int sig) { bool measure_mode(bool csv, float sleep) { char buf[BUFSZ]; int maxname = 0; - rapl_t * rapl = rapl_init(); - array_t * coretemp = get_coretemp(&maxname); + struct rapl_t * rapl = rapl_init(); + struct array_t * coretemp = get_coretemp(&maxname); char degstr[5] = " C"; bool tty = isatty(1); if (rapl) { int i; for (i = 0; i < rapl->devices->count; i++) { - rapl_device_t * device = array_get(rapl->devices, i); + struct rapl_device_t * device = array_get(rapl->devices, i); int length = strlen(device->name); maxname = length > maxname ? length : maxname; } diff --git a/modes.c b/modes.c index e8f05af..5c07008 100644 --- a/modes.c +++ b/modes.c @@ -11,7 +11,7 @@ bool read_apply_mode(bool write) { bool nl = false; - config_t * config = load_config(NULL, &nl); + struct config_t * config = load_config(NULL, &nl); bool success = true; unsigned int i; @@ -37,10 +37,10 @@ static void sigusr1_handler(UNUSED int sig) { } int daemon_mode() { - config_t * config = load_config(NULL, NULL); + struct config_t * config = load_config(NULL, NULL); struct sigaction act; unsigned int i = 0; - cpu_policy_t * cpu_policy = NULL; + struct cpu_policy_t * cpu_policy = NULL; if (config && config->interval <= 0) { fprintf(stderr, "Interval is not specified\n"); diff --git a/power.c b/power.c index 462d604..9c7eb9f 100644 --- a/power.c +++ b/power.c @@ -12,35 +12,35 @@ #define DIR_POWERCAP "/sys/class/powercap" #define BUFSZ 80 -typedef struct { +struct rapl_device_ext_t { char * dir; int64_t last; struct timespec time; -} rapl_device_ext_t; +}; -typedef struct { - rapl_t parent; - array_t * exts; -} rapl_full_t; +struct rapl_full_t { + struct rapl_t parent; + struct array_t * exts; +}; static void rapl_device_free(void * pointer) { - rapl_device_t * device = pointer; + struct rapl_device_t * device = pointer; free(device->name); } static void rapl_device_ext_free(void * pointer) { - rapl_device_ext_t * ext = pointer; + struct rapl_device_ext_t * ext = pointer; free(ext->dir); } -rapl_t * rapl_init() { +struct rapl_t * rapl_init() { char buf[BUFSZ]; DIR * dir; struct dirent * dirent; - array_t * devices = NULL; - array_t * exts = NULL; + struct array_t * devices = NULL; + struct array_t * exts = NULL; bool nomem = false; - rapl_full_t * full = NULL; + struct rapl_full_t * full = NULL; dir = opendir(DIR_POWERCAP); if (dir == NULL) { @@ -58,8 +58,8 @@ END_IGNORE_FORMAT_OVERFLOW if (fd >= 0) { int size = read(fd, buf, BUFSZ - 1); if (size >= 1) { - rapl_device_t * device; - rapl_device_ext_t * ext; + struct rapl_device_t * device; + struct rapl_device_ext_t * ext; char * name; char * dir; int name_length; @@ -90,9 +90,9 @@ END_IGNORE_FORMAT_OVERFLOW memcpy(dir, dirent->d_name, dir_length + 1); if (!devices && !exts) { - devices = array_new(sizeof(rapl_device_t), + devices = array_new(sizeof(struct rapl_device_t), rapl_device_free); - exts = array_new(sizeof(rapl_device_ext_t), + exts = array_new(sizeof(struct rapl_device_ext_t), rapl_device_ext_free); if (!devices || !exts) { free(name); @@ -133,7 +133,7 @@ END_IGNORE_FORMAT_OVERFLOW closedir(dir); if (!nomem) { - full = malloc(sizeof(rapl_full_t)); + full = malloc(sizeof(struct rapl_full_t)); if (!full) { nomem = true; } @@ -160,16 +160,16 @@ END_IGNORE_FORMAT_OVERFLOW } } -void rapl_measure(rapl_t * rapl) { +void rapl_measure(struct rapl_t * rapl) { if (rapl) { char buf[BUFSZ]; - rapl_full_t * full = (rapl_full_t *) rapl; + struct rapl_full_t * full = (struct rapl_full_t *) rapl; int i; for (i = 0; i < full->parent.devices->count; i++) { int fd; - rapl_device_t * device = array_get(full->parent.devices, i); - rapl_device_ext_t * ext = array_get(full->exts, i); + struct rapl_device_t * device = array_get(full->parent.devices, i); + struct rapl_device_ext_t * ext = array_get(full->exts, i); sprintf(buf, DIR_POWERCAP "/%s/energy_uj", ext->dir); fd = open(buf, O_RDONLY); if (fd >= 0) { @@ -205,9 +205,9 @@ void rapl_measure(rapl_t * rapl) { } } -void rapl_free(rapl_t * rapl) { +void rapl_free(struct rapl_t * rapl) { if (rapl) { - rapl_full_t * full = (rapl_full_t *) rapl; + struct rapl_full_t * full = (struct rapl_full_t *) rapl; if (full->parent.devices) { array_free(full->parent.devices); } diff --git a/power.h b/power.h index 3ddb8a5..23a56ae 100644 --- a/power.h +++ b/power.h @@ -3,17 +3,17 @@ #include "util.h" -typedef struct { +struct rapl_device_t { char * name; float power; -} rapl_device_t; +}; -typedef struct { - array_t * devices; -} rapl_t; +struct rapl_t { + struct array_t * devices; +}; -rapl_t * rapl_init(); -void rapl_measure(rapl_t * rapl); -void rapl_free(rapl_t * rapl); +struct rapl_t * rapl_init(); +void rapl_measure(struct rapl_t * rapl); +void rapl_free(struct rapl_t * rapl); #endif diff --git a/scaling.c b/scaling.c index 91ed86a..a0b1436 100644 --- a/scaling.c +++ b/scaling.c @@ -14,13 +14,13 @@ #define FILE_HINT "energy_performance_preference" #define BUFSZ 80 -typedef struct { +struct cpu_policy_full_t { int cpu_count; - cpu_stat_t * cpu_stat; - rapl_t * rapl; -} cpu_policy_full_t; + struct cpu_stat_t * cpu_stat; + struct rapl_t * rapl; +}; -cpu_policy_t * cpu_policy_init() { +struct cpu_policy_t * cpu_policy_init() { int cpu_count = 0; DIR * dir; @@ -41,7 +41,7 @@ cpu_policy_t * cpu_policy_init() { } if (cpu_count > 0) { - cpu_policy_full_t * full = malloc(sizeof(cpu_policy_full_t)); + struct cpu_policy_full_t * full = malloc(sizeof(struct cpu_policy_full_t)); if (!full) { fprintf(stderr, "No enough memory"); return NULL; @@ -49,21 +49,21 @@ cpu_policy_t * cpu_policy_init() { full->cpu_count = cpu_count; full->cpu_stat = cpu_stat_init(); full->rapl = rapl_init(); - return full; + return (struct cpu_policy_t *) full; } else { return NULL; } } -static bool check_cpu_stat(cpu_stat_t * cpu_stat, bool multi, float threshold) { +static bool check_cpu_stat(struct cpu_stat_t * cpu_stat, bool multi, float threshold) { return cpu_stat && (multi ? cpu_stat->multi_core : cpu_stat->single_core) >= threshold; } -static int rapl_lookup(rapl_t * rapl, const char * domain) { +static int rapl_lookup(struct rapl_t * rapl, const char * domain) { int i; for (i = 0; i < rapl->devices->count; i++) { - rapl_device_t * rapl_device = array_get(rapl->devices, i); + struct rapl_device_t * rapl_device = array_get(rapl->devices, i); const char * tmp = strstr(rapl_device->name, domain); if (tmp == rapl_device->name) { int len = strlen(domain); @@ -76,17 +76,17 @@ static int rapl_lookup(rapl_t * rapl, const char * domain) { return -1; } -static bool check_rapl(rapl_t * rapl, array_t * hwp_power_terms) { +static bool check_rapl(struct rapl_t * rapl, struct array_t * hwp_power_terms) { bool result = false; if (rapl && rapl->devices && hwp_power_terms) { int i; for (i = 0; i < hwp_power_terms->count; i++) { - hwp_power_term_t * hwp_power_term = array_get(hwp_power_terms, i); + struct hwp_power_term_t * hwp_power_term = array_get(hwp_power_terms, i); int device_index = rapl_lookup(rapl, hwp_power_term->domain); float power = 0; bool current; if (device_index >= 0) { - rapl_device_t * rapl_device = array_get(rapl->devices, + struct rapl_device_t * rapl_device = array_get(rapl->devices, device_index); power = rapl_device->power; } @@ -111,9 +111,9 @@ enum { STATUS_LOAD }; -void cpu_policy_update(cpu_policy_t * cpu_policy, array_t * hwp_hints) { +void cpu_policy_update(struct cpu_policy_t * cpu_policy, struct array_t * hwp_hints) { if (cpu_policy) { - cpu_policy_full_t * full = (cpu_policy_full_t *) cpu_policy; + struct cpu_policy_full_t * full = (struct cpu_policy_full_t *) cpu_policy; bool handled[full->cpu_count]; char * current_hints[full->cpu_count]; bool read_hints = false; @@ -125,7 +125,7 @@ void cpu_policy_update(cpu_policy_t * cpu_policy, array_t * hwp_hints) { memset(current_hints, 0, full->cpu_count * sizeof(char *)); for (i = 0; hwp_hints && i < hwp_hints->count; i++) { - hwp_hint_t * hwp_hint = array_get(hwp_hints, i); + struct hwp_hint_t * hwp_hint = array_get(hwp_hints, i); int total_handled = 0; const char * hint; char buf[BUFSZ]; @@ -227,9 +227,9 @@ void cpu_policy_update(cpu_policy_t * cpu_policy, array_t * hwp_hints) { } } -void cpu_policy_free(cpu_policy_t * cpu_policy) { +void cpu_policy_free(struct cpu_policy_t * cpu_policy) { if (cpu_policy) { - cpu_policy_full_t * full = (cpu_policy_full_t *) cpu_policy; + struct cpu_policy_full_t * full = (struct cpu_policy_full_t *) cpu_policy; if (full->cpu_stat) { cpu_stat_free(full->cpu_stat); } diff --git a/scaling.h b/scaling.h index aa4d0e6..8384798 100644 --- a/scaling.h +++ b/scaling.h @@ -3,10 +3,10 @@ #include "util.h" -typedef void cpu_policy_t; +struct cpu_policy_t; -cpu_policy_t * cpu_policy_init(); -void cpu_policy_update(cpu_policy_t * cpu_policy, array_t * hwp_hints); -void cpu_policy_free(cpu_policy_t * cpu_policy); +struct cpu_policy_t * cpu_policy_init(); +void cpu_policy_update(struct cpu_policy_t * cpu_policy, struct array_t * hwp_hints); +void cpu_policy_free(struct cpu_policy_t * cpu_policy); #endif diff --git a/stat.c b/stat.c index 51f25a1..8f628d2 100644 --- a/stat.c +++ b/stat.c @@ -4,23 +4,23 @@ #include #include -typedef struct { +struct cpu_stat_value_t { long int idle; long int total; -} cpu_stat_value_t; +}; -typedef struct { - cpu_stat_t parent; +struct cpu_stat_full_t { + struct cpu_stat_t parent; int cpu_count; - cpu_stat_value_t * values; -} cpu_stat_full_t; + struct cpu_stat_value_t * values; +}; static void read_eol(FILE * file) { int c; while ((c = fgetc(file)) != EOF && c != '\n'); } -cpu_stat_t * cpu_stat_init() { +struct cpu_stat_t * cpu_stat_init() { FILE * file; char buf[80]; int cpu_count = 0; @@ -39,9 +39,9 @@ cpu_stat_t * cpu_stat_init() { } if (cpu_count > 0) { - cpu_stat_full_t * full = malloc(sizeof(cpu_stat_full_t)); - cpu_stat_value_t * values = malloc(cpu_count * - sizeof(cpu_stat_value_t)); + struct cpu_stat_full_t * full = malloc(sizeof(struct cpu_stat_full_t)); + struct cpu_stat_value_t * values = malloc(cpu_count * + sizeof(struct cpu_stat_value_t)); if (!full || !values) { if (full) { free(full); @@ -52,7 +52,7 @@ cpu_stat_t * cpu_stat_init() { fprintf(stderr, "No enough memory\n"); return NULL; } - memset(values, 0, cpu_count * sizeof(cpu_stat_value_t)); + memset(values, 0, cpu_count * sizeof(struct cpu_stat_value_t)); full->parent.single_core = 0; full->parent.multi_core = 0; full->cpu_count = cpu_count; @@ -64,9 +64,9 @@ cpu_stat_t * cpu_stat_init() { } } -void cpu_stat_measure(cpu_stat_t * cpu_stat) { +void cpu_stat_measure(struct cpu_stat_t * cpu_stat) { if (cpu_stat) { - cpu_stat_full_t * full = (cpu_stat_full_t *) cpu_stat; + struct cpu_stat_full_t * full = (struct cpu_stat_full_t *) cpu_stat; int index; int count; long int idle; @@ -123,9 +123,9 @@ void cpu_stat_measure(cpu_stat_t * cpu_stat) { } } -void cpu_stat_free(cpu_stat_t * cpu_stat) { +void cpu_stat_free(struct cpu_stat_t * cpu_stat) { if (cpu_stat) { - cpu_stat_full_t * full = (cpu_stat_full_t *) cpu_stat; + struct cpu_stat_full_t * full = (struct cpu_stat_full_t *) cpu_stat; free(full->values); free(full); } diff --git a/stat.h b/stat.h index 71a2d26..75d6540 100644 --- a/stat.h +++ b/stat.h @@ -1,13 +1,13 @@ #ifndef __STAT_H__ #define __STAT_H__ -typedef struct { +struct cpu_stat_t { float single_core; float multi_core; -} cpu_stat_t; +}; -cpu_stat_t * cpu_stat_init(); -void cpu_stat_measure(cpu_stat_t * cpu_stat); -void cpu_stat_free(cpu_stat_t * cpu_stat); +struct cpu_stat_t * cpu_stat_init(); +void cpu_stat_measure(struct cpu_stat_t * cpu_stat); +void cpu_stat_free(struct cpu_stat_t * cpu_stat); #endif diff --git a/undervolt.c b/undervolt.c index 639362b..1a5d943 100644 --- a/undervolt.c +++ b/undervolt.c @@ -41,13 +41,13 @@ static inline bool cpuctl_wr(int fd, int a, uint64_t * t) { #endif -bool undervolt(config_t * config, bool * nl, bool write) { +bool undervolt(struct config_t * config, bool * nl, bool write) { bool success = true; bool nll = false; int i; for (i = 0; config->undervolts && i < config->undervolts->count; i++) { - undervolt_t * undervolt = array_get(config->undervolts, i); + struct undervolt_t * undervolt = array_get(config->undervolts, i); static const int mask = 0x800; uint64_t uvint = ((uint64_t) (mask - absf(undervolt->value) * 1.024f + @@ -117,10 +117,10 @@ static int power_from_seconds(float seconds, int time_unit) { } } -bool power_limit(config_t * config, int index, bool * nl, bool write) { +bool power_limit(struct config_t * config, int index, bool * nl, bool write) { bool nll = false; - power_limit_t * power = &config->power[index]; - power_domain_t * domain = &power_domains[index]; + struct power_limit_t * power = &config->power[index]; + struct power_domain_t * domain = &power_domains[index]; if (power->apply) { void * mem = NULL; if (power->mem != NULL) { @@ -236,7 +236,7 @@ bool power_limit(config_t * config, int index, bool * nl, bool write) { } } -bool tjoffset(config_t * config, bool * nl, bool write) { +bool tjoffset(struct config_t * config, bool * nl, bool write) { bool nll = false; if (config->tjoffset_apply) { const char * errstr = NULL; diff --git a/undervolt.h b/undervolt.h index 1d2b6e0..c995c2e 100644 --- a/undervolt.h +++ b/undervolt.h @@ -5,8 +5,8 @@ #include -bool undervolt(config_t * config, bool * nl, bool write); -bool power_limit(config_t * config, int index, bool * nl, bool write); -bool tjoffset(config_t * config, bool * nl, bool write); +bool undervolt(struct config_t * config, bool * nl, bool write); +bool power_limit(struct config_t * config, int index, bool * nl, bool write); +bool tjoffset(struct config_t * config, bool * nl, bool write); #endif diff --git a/util.c b/util.c index 03ea62c..87024bd 100644 --- a/util.c +++ b/util.c @@ -34,16 +34,16 @@ bool safe_rw(uint64_t * addr, uint64_t * data, bool write) { return success; } -typedef struct { - array_t parent; +struct array_full_t { + struct array_t parent; int item_size; int capacity; void (* item_free)(void *); void * data; -} array_full_t; +}; -array_t * array_new(int item_size, void (* item_free)(void *)) { - array_full_t * full = malloc(sizeof(array_full_t)); +struct array_t * array_new(int item_size, void (* item_free)(void *)) { + struct array_full_t * full = malloc(sizeof(struct array_full_t)); if (!full) { return NULL; } @@ -55,13 +55,13 @@ array_t * array_new(int item_size, void (* item_free)(void *)) { return &full->parent; } -void * array_get(array_t * array, int index) { - array_full_t * full = (array_full_t *) array; +void * array_get(struct array_t * array, int index) { + struct array_full_t * full = (struct array_full_t *) array; return full->data + index * full->item_size; } -void * array_add(array_t * array) { - array_full_t * full = (array_full_t *) array; +void * array_add(struct array_t * array) { + struct array_full_t * full = (struct array_full_t *) array; if (full->parent.count >= full->capacity) { int capacity = full->capacity > 0 ? 2 * full->capacity : 2; void * data = realloc(full->data, capacity * full->item_size); @@ -74,8 +74,8 @@ void * array_add(array_t * array) { return full->data + (full->parent.count++) * full->item_size; } -bool array_shrink(array_t * array) { - array_full_t * full = (array_full_t *) array; +bool array_shrink(struct array_t * array) { + struct array_full_t * full = (struct array_full_t *) array; if (full->parent.count > full->capacity) { void * data = realloc(full->data, full->parent.count * full->item_size); if (!data) { @@ -87,8 +87,8 @@ bool array_shrink(array_t * array) { return true; } -void array_free(array_t * array) { - array_full_t * full = (array_full_t *) array; +void array_free(struct array_t * array) { + struct array_full_t * full = (struct array_full_t *) array; if (full->data) { if (full->item_free) { int i = 0; diff --git a/util.h b/util.h index b24c541..9b891d6 100644 --- a/util.h +++ b/util.h @@ -48,14 +48,14 @@ bool strn_eq_const(const char * str, const char * cstr, size_t n); bool safe_rw(uint64_t * addr, uint64_t * data, bool write); -typedef struct { +struct array_t { int count; -} array_t; +}; -array_t * array_new(int item_size, void (* item_free)(void *)); -void * array_get(array_t * array, int index); -void * array_add(array_t * array); -bool array_shrink(array_t * array); -void array_free(array_t * array); +struct array_t * array_new(int item_size, void (* item_free)(void *)); +void * array_get(struct array_t * array, int index); +void * array_add(struct array_t * array); +bool array_shrink(struct array_t * array); +void array_free(struct array_t * array); #endif