Skip to content

Commit ad6c3c8

Browse files
committed
Small corrections in code and Makefile
1 parent e114bde commit ad6c3c8

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CXX=gcc
22

3-
CXXFLAGS=-Wall -Wextra -Werror -fstack-protector-all -pedantic -Wno-unused -std=c99
3+
CXXFLAGS=-Wall -Wextra -Werror -pedantic -fstack-protector-all -pedantic -std=c99
44
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith -Wstrict-overflow=5 -Wformat=2
55

66
SRC_DIR=src/
@@ -10,12 +10,12 @@ HEADERS=$(SRC_DIR)cpuid.h $(SRC_DIR)apic.h $(SRC_DIR)cpuid_asm.h $(SRC_DIR)print
1010
ifneq ($(OS),Windows_NT)
1111
SOURCE += $(SRC_DIR)udev.c
1212
HEADERS += $(SRC_DIR)udev.h
13+
OUTPUT=cpufetch
1314
else
1415
SANITY_FLAGS += -Wno-pedantic-ms-format
16+
OUTPUT=cpufetch.exe
1517
endif
1618

17-
OUTPUT=cpufetch
18-
1919
all: $(OUTPUT)
2020

2121
debug: CXXFLAGS += -g -O0

src/apic.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ unsigned char bit_scan_reverse(uint32_t* index, uint64_t mask) {
2929
}
3030

3131
uint32_t create_mask(uint32_t num_entries, uint32_t *mask_width) {
32-
uint32_t i;
33-
uint64_t k;
32+
uint32_t i = 0;
33+
uint64_t k = 0;
3434

3535
// NearestPo2(numEntries) is the nearest power of 2 integer that is not less than numEntries
3636
// The most significant bit of (numEntries * 2 -1) matches the above definition
@@ -91,7 +91,6 @@ bool fill_topo_masks_apic(struct topology** topo) {
9191
uint32_t core_plus_smt_id_max_cnt;
9292
uint32_t core_id_max_cnt;
9393
uint32_t smt_id_per_core_max_cnt;
94-
uint32_t SMTIDPerCoreMaxCnt;
9594

9695
cpuid(&eax, &ebx, &ecx, &edx);
9796

@@ -117,7 +116,7 @@ bool fill_topo_masks_x2apic(struct topology** topo) {
117116
int32_t level_type;
118117
int32_t level_shift;
119118

120-
int32_t coreplus_smt_mask;
119+
int32_t coreplus_smt_mask = 0;
121120
bool level2 = false;
122121
bool level1 = false;
123122

@@ -173,7 +172,7 @@ bool fill_topo_masks_x2apic(struct topology** topo) {
173172
return true;
174173
}
175174

176-
bool build_topo_from_apic(uint32_t* apic_pkg, uint32_t* apic_core, uint32_t* apic_smt, struct topology** topo) {
175+
bool build_topo_from_apic(uint32_t* apic_pkg, uint32_t* apic_smt, struct topology** topo) {
177176
uint32_t sockets[64];
178177
uint32_t smt[64];
179178

@@ -236,7 +235,7 @@ bool get_topology_from_apic(uint32_t cpuid_max_levels, struct topology** topo) {
236235
printf("[%2d] 0x%.8X\n", i, apic_smt[i]);*/
237236

238237

239-
bool ret = build_topo_from_apic(apic_pkg, apic_core, apic_smt, topo);
238+
bool ret = build_topo_from_apic(apic_pkg, apic_smt, topo);
240239

241240
// Assumption: If we cant get smt_available, we assume it is equal to smt_supported...
242241
if(!x2apic_id) (*topo)->smt_supported = (*topo)->smt_available;

src/args.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ bool parse_color(char* optarg, struct colors** cs) {
131131

132132
bool parse_args(int argc, char* argv[]) {
133133
int c;
134-
int digit_optind = 0;
135134
int option_index = 0;
136135
opterr = 0;
137136

src/cpuid.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
272272
uint32_t ebx = 0;
273273
uint32_t ecx = 0;
274274
uint32_t edx = 0;
275-
int32_t type;
276275

277276
// Ask the OS the total number of cores it sees
278277
// If we have one socket, it will be same as the cpuid,
@@ -386,8 +385,6 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
386385
// If its 0, we tried fetching a non existing cache
387386
if (cache_type > 0) {
388387
int32_t cache_level = (eax >>= 5) & 0x7;
389-
int32_t cache_is_self_initializing = (eax >>= 3) & 0x1; // does not need SW initialization
390-
int32_t cache_is_fully_associative = (eax >>= 1) & 0x1;
391388
uint32_t cache_sets = ecx + 1;
392389
uint32_t cache_coherency_line_size = (ebx & 0xFFF) + 1;
393390
uint32_t cache_physical_line_partitions = ((ebx >>= 12) & 0x3FF) + 1;
@@ -444,9 +441,15 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
444441
printBug("Invalid L1d size: %dKB", cach->L1d/1024);
445442
return NULL;
446443
}
447-
if(cach->L2 != UNKNOWN && cach->L2 > 2 * 1048576) {
448-
printBug("Invalid L2 size: %dMB", cach->L2/(1048576));
449-
return NULL;
444+
if(cach->L2 != UNKNOWN) {
445+
if(cach->L3 != UNKNOWN && cach->L2 > 2 * 1048576) {
446+
printBug("Invalid L2 size: %dMB", cach->L2/(1048576));
447+
return NULL;
448+
}
449+
else if(cach->L2 > 100 * 1048576) {
450+
printBug("Invalid L2 size: %dMB", cach->L2/(1048576));
451+
return NULL;
452+
}
450453
}
451454
if(cach->L3 != UNKNOWN && cach->L3 > 100 * 1048576) {
452455
printBug("Invalid L3 size: %dMB", cach->L3/(1048576));

src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#include "cpuid.h"
77
#include "global.h"
88

9-
static const char* VERSION = "0.510";
9+
static const char* VERSION = "0.6";
1010

1111
void print_help(char *argv[]) {
1212
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\
1313
Options: \n\
14-
--color Set text color. 4 colors (in RGB format) must be specified in the form: R,G,B:R,G,B:...\n\
14+
--color Set a custom color scheme. 4 colors must be specified in RGB with the format: R,G,B:R,G,B:...\n\
1515
These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\
1616
Suggested color (Intel): --color 15,125,194:230,230,230:40,150,220:230,230,230\n\
17+
Suggested color (AMD): --color 250,250,250:0,154,102:250,250,250:0,154,102\n\
1718
--style Set the style of the ASCII art:\n\
1819
* fancy \n\
1920
* retro \n\

src/printer.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#define COL_INTEL_RETRO_1 "\x1b[36;1m"
1616
#define COL_INTEL_RETRO_2 "\x1b[37;1m"
1717
#define COL_AMD_FANCY_1 "\x1b[47;1m"
18-
#define COL_AMD_FANCY_2 "\x1b[41;1m"
18+
#define COL_AMD_FANCY_2 "\x1b[42;1m"
1919
#define COL_AMD_FANCY_3 "\x1b[37;1m"
20-
#define COL_AMD_FANCY_4 "\x1b[31;1m"
20+
#define COL_AMD_FANCY_4 "\x1b[32;1m"
2121
#define COL_AMD_RETRO_1 "\x1b[37;1m"
22-
#define COL_AMD_RETRO_2 "\x1b[31;1m"
22+
#define COL_AMD_RETRO_2 "\x1b[32;1m"
2323
#define RESET "\x1b[m"
2424

2525
#define TITLE_NAME "Name:"
@@ -223,7 +223,7 @@ uint32_t get_next_attribute(struct ascii* art, uint32_t last_attr) {
223223
return last_attr;
224224
}
225225

226-
void print_ascii_intel(struct ascii* art, STYLE s, uint32_t la) {
226+
void print_ascii_intel(struct ascii* art, uint32_t la) {
227227
bool flag = false;
228228
int attr_to_print = -1;
229229
uint32_t space_right;
@@ -260,7 +260,7 @@ void print_ascii_intel(struct ascii* art, STYLE s, uint32_t la) {
260260
}
261261
}
262262

263-
void print_ascii_amd(struct ascii* art, STYLE s, uint32_t la) {
263+
void print_ascii_amd(struct ascii* art, uint32_t la) {
264264
int attr_to_print = -1;
265265
uint32_t space_right;
266266
uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2;
@@ -300,12 +300,12 @@ uint32_t longest_attribute_length(struct ascii* art) {
300300
return max;
301301
}
302302

303-
void print_ascii(struct ascii* art, STYLE s) {
303+
void print_ascii(struct ascii* art) {
304304
uint32_t longest_attribute = longest_attribute_length(art);
305305
if(art->vendor == VENDOR_INTEL)
306-
print_ascii_intel(art, s, longest_attribute);
306+
print_ascii_intel(art, longest_attribute);
307307
else
308-
print_ascii_amd(art, s, longest_attribute);
308+
print_ascii_amd(art, longest_attribute);
309309
}
310310

311311
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs) {
@@ -355,7 +355,7 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f
355355
return false;
356356
}
357357

358-
print_ascii(art, s);
358+
print_ascii(art);
359359

360360
free(cpu_name);
361361
free(max_frequency);

0 commit comments

Comments
 (0)