From 7d707916fb3832356edc92a5a1fbf2838952872f Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Wed, 18 Nov 2020 23:41:42 +0100 Subject: [PATCH] [v0.86][OPTIONS] Replace levels option with debug option, which does the same on x86, but also exists on ARM, which prints MIDR registers (need work to be properly implemented) --- src/arm/midr.c | 16 ++++++++++++++++ src/arm/midr.h | 1 + src/common/args.c | 26 ++++++++++---------------- src/common/args.h | 2 +- src/common/global.c | 2 +- src/common/main.c | 20 ++++++++------------ src/common/printer.c | 10 ---------- src/x86/cpuid.c | 8 ++++++++ src/x86/cpuid.h | 1 + 9 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index 0eea8db..d71da12 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -195,6 +195,22 @@ char* get_soc_name(struct cpuInfo* cpu) { return cpu->soc_name; } +//TODO: Fix wrong implementation +void print_debug(struct cpuInfo* cpu) { + int ncores = get_ncores_from_cpuinfo(); + + if(ncores >= 10) { + for(int i=0; i < ncores; i++) { + printf("[Core %02d] 0x%.8X\n", i, cpu->midr); + } + } + else { + for(int i=0; i < ncores; i++) { + printf("[Core %d] 0x%.8X\n", i, cpu->midr); + } + } +} + void free_topo_struct(struct topology* topo) { free(topo); } diff --git a/src/arm/midr.h b/src/arm/midr.h index 61cbbd9..68517df 100644 --- a/src/arm/midr.h +++ b/src/arm/midr.h @@ -13,6 +13,7 @@ char* get_soc_name(struct cpuInfo* cpu); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq); +void print_debug(struct cpuInfo* cpu); void free_topo_struct(struct topology* topo); // Code taken from cpuinfo (https://github.com/pytorch/cpuinfo/blob/master/src/arm/midr.h) diff --git a/src/common/args.c b/src/common/args.c index 82dc2c3..577d931 100644 --- a/src/common/args.c +++ b/src/common/args.c @@ -21,15 +21,13 @@ enum { ARG_CHAR_STYLE, ARG_CHAR_COLOR, ARG_CHAR_HELP, -#ifdef ARCH_X86 - ARG_CHAR_LEVELS, -#endif + ARG_CHAR_DEBUG, ARG_CHAR_VERBOSE, ARG_CHAR_VERSION }; struct args_struct { - bool levels_flag; + bool debug_flag; bool help_flag; bool verbose_flag; bool version_flag; @@ -55,8 +53,8 @@ bool show_version() { return args.version_flag; } -bool show_levels() { - return args.levels_flag; +bool show_debug() { + return args.debug_flag; } bool verbose_enabled() { @@ -166,7 +164,7 @@ bool parse_args(int argc, char* argv[]) { opterr = 0; bool color_flag = false; - args.levels_flag = false; + args.debug_flag = false; args.verbose_flag = false; args.help_flag = false; args.style = STYLE_EMPTY; @@ -176,9 +174,7 @@ bool parse_args(int argc, char* argv[]) { {"style", required_argument, 0, ARG_CHAR_STYLE }, {"color", required_argument, 0, ARG_CHAR_COLOR }, {"help", no_argument, 0, ARG_CHAR_HELP }, -#ifdef ARCH_X86 - {"levels", no_argument, 0, ARG_CHAR_LEVELS }, -#endif + {"debug", no_argument, 0, ARG_CHAR_DEBUG }, {"verbose", no_argument, 0, ARG_CHAR_VERBOSE }, {"version", no_argument, 0, ARG_CHAR_VERSION }, {0, 0, 0, 0} @@ -223,15 +219,13 @@ bool parse_args(int argc, char* argv[]) { } args.verbose_flag = true; } -#ifdef ARCH_X86 - else if(c == ARG_CHAR_LEVELS) { - if(args.levels_flag) { - printErr("Levels option specified more than once"); + else if(c == ARG_CHAR_DEBUG) { + if(args.debug_flag) { + printErr("Debug option specified more than once"); return false; } - args.levels_flag = true; + args.debug_flag = true; } -#endif else if (c == ARG_CHAR_VERSION) { if(args.version_flag) { printErr("Version option specified more than once"); diff --git a/src/common/args.h b/src/common/args.h index 91c7e99..7c25925 100644 --- a/src/common/args.h +++ b/src/common/args.h @@ -30,7 +30,7 @@ enum { bool parse_args(int argc, char* argv[]); bool show_help(); -bool show_levels(); +bool show_debug(); bool show_version(); bool verbose_enabled(); void free_colors_struct(struct colors* cs); diff --git a/src/common/global.c b/src/common/global.c index f356122..bfaa787 100644 --- a/src/common/global.c +++ b/src/common/global.c @@ -53,7 +53,7 @@ void printBug(const char *fmt, ...) { vsnprintf(buffer,buffer_size, fmt, args); va_end(args); fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer); - fprintf(stderr,"Please, create a new issue with this error message and your CPU model in https://github.com/Dr-Noob/cpufetch/issues\n"); + fprintf(stderr,"Please, create a new issue with this error message the output of 'cpufetch --debug' in https://github.com/Dr-Noob/cpufetch/issues\n"); } void set_log_level(bool verbose) { diff --git a/src/common/main.c b/src/common/main.c index b8c49e4..b87d287 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -8,19 +8,15 @@ #ifdef ARCH_X86 static const char* ARCH_STR = "x86_64 build"; #include "../x86/cpuid.h" -#else +#elif ARCH_ARM static const char* ARCH_STR = "ARM build"; #include "../arm/midr.h" #endif -static const char* VERSION = "0.85"; +static const char* VERSION = "0.86"; void print_help(char *argv[]) { -#ifdef ARCH_X86 - printf("Usage: %s [--version] [--help] [--levels] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]); -#else - printf("Usage: %s [--version] [--help] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]); -#endif + printf("Usage: %s [--version] [--help] [--debug] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]); printf("Options: \n\ --color Set the color scheme. By default, cpufetch uses the system color scheme. This option \n\ @@ -38,7 +34,9 @@ void print_help(char *argv[]) { * \"legacy\": Fallback style for terminals that does not support colors \n\n"); #ifdef ARCH_X86 - printf(" --levels Prints CPU model and cpuid levels (debug purposes)\n\n"); + printf(" --debug Prints CPU model and cpuid levels (debug purposes)\n\n"); +#elif ARCH_ARM + printf(" --debug Prints main ID register values for all cores (debug purposes)\n\n"); #endif printf(" --verbose Prints extra information (if available) about how cpufetch tried fetching information\n\n\ @@ -77,13 +75,11 @@ int main(int argc, char* argv[]) { if(cpu == NULL) return EXIT_FAILURE; -#ifdef ARCH_X86 - if(show_levels()) { + if(show_debug()) { print_version(); - print_levels(cpu); + print_debug(cpu); return EXIT_SUCCESS; } -#endif struct frequency* freq = get_frequency_info(cpu); if(freq == NULL) diff --git a/src/common/printer.c b/src/common/printer.c index 2e610a6..1b0eee3 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -526,13 +526,3 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f return true; } - -#ifdef ARCH_X86 -void print_levels(struct cpuInfo* cpu) { - printf("%s\n", cpu->cpu_name); - printf("- Max standart level: 0x%.8X\n", cpu->maxLevels); - printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels); - - free_cpuinfo_struct(cpu); -} -#endif diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index af2ded3..9549472 100755 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -828,6 +828,14 @@ char* get_str_fma(struct cpuInfo* cpu) { /*** DEBUG ***/ +void print_debug(struct cpuInfo* cpu) { + printf("%s\n", cpu->cpu_name); + printf("- Max standart level: 0x%.8X\n", cpu->maxLevels); + printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels); + + free_cpuinfo_struct(cpu); +} + void debug_cpu_info(struct cpuInfo* cpu) { printf("AVX=%s\n", cpu->AVX ? "true" : "false"); printf("AVX2=%s\n", cpu->AVX2 ? "true" : "false"); diff --git a/src/x86/cpuid.h b/src/x86/cpuid.h index ec357ee..d2be947 100644 --- a/src/x86/cpuid.h +++ b/src/x86/cpuid.h @@ -14,6 +14,7 @@ char* get_str_fma(struct cpuInfo* cpu); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq); +void print_debug(struct cpuInfo* cpu); void debug_cpu_info(struct cpuInfo* cpu); void debug_cache(struct cache* cach); void debug_frequency(struct frequency* freq);