mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26139e061d | ||
|
|
d1e481f3c8 | ||
|
|
0faad4858e | ||
|
|
e22c2a8f3c | ||
|
|
fe7a99087d | ||
|
|
c04dd86523 | ||
|
|
962701f9f6 | ||
|
|
5a5406925c | ||
|
|
4023afb95f | ||
|
|
37eba4ba0c | ||
|
|
9fa7b4ce7f | ||
|
|
64937862fb | ||
|
|
5bd4e07e04 | ||
|
|
8f2f3d3a16 | ||
|
|
6dd041bf9f | ||
|
|
b45c09efff | ||
|
|
ec5f80adc1 | ||
|
|
ecca042d86 | ||
|
|
e8d2898ae3 | ||
|
|
a67a605fb5 | ||
|
|
9aef2d8493 | ||
|
|
d239906f22 | ||
|
|
586283a1be | ||
|
|
cc356ecb07 | ||
|
|
044608f31f | ||
|
|
27c6507acb | ||
|
|
7420792ef5 | ||
|
|
db32cccd91 | ||
|
|
a8d8ac2e91 |
51
CONTRIBUTING.md
Normal file
51
CONTRIBUTING.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# cpufetch contributing guidelines
|
||||||
|
|
||||||
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||||
|
|
||||||
|
|
||||||
|
- [Creating a pull request](#creating-a-pull-request)
|
||||||
|
- [Case 1: I found a bug in cpufetch](#case-1-i-found-a-bug-in-cpufetch)
|
||||||
|
- [Case 2: I have an idea for a new feature in cpufetch / I want to suggest a change in cpufetch](#case-2-i-have-an-idea-for-a-new-feature-in-cpufetch--i-want-to-suggest-a-change-in-cpufetch)
|
||||||
|
- [Case 3: I want to make changes to the Makefile](#case-3-i-want-to-make-changes-to-the-makefile)
|
||||||
|
- [Creating an issue](#creating-an-issue)
|
||||||
|
- [cpufetch fails / crashes with a segmentation fault / ends without any output](#cpufetch-fails--crashes-with-a-segmentation-fault--ends-without-any-output)
|
||||||
|
- [Option 1 (best)](#option-1-best)
|
||||||
|
- [Option 2 (use this option if you can't work with option 1)](#option-2-use-this-option-if-you-cant-work-with-option-1)
|
||||||
|
|
||||||
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
|
||||||
|
## Creating a pull request
|
||||||
|
|
||||||
|
Thanks for your interest in contributing to cpufetch!
|
||||||
|
|
||||||
|
What kind of contribution are you going to propose?
|
||||||
|
|
||||||
|
### Case 1: I found a bug in cpufetch
|
||||||
|
If you found a bug, please don't open a pull request; open an issue instead, even if you know the solution. I appreciate people finding bugs, but I generally prefer to fix them myself.
|
||||||
|
|
||||||
|
### Case 2: I have an idea for a new feature in cpufetch / I want to suggest a change in cpufetch
|
||||||
|
Great! Make a PR and make sure to explain how did you implement your new feature on the github conversation page.
|
||||||
|
|
||||||
|
### Case 3: I want to make changes to the Makefile
|
||||||
|
Don't open a pull request; open an issue instead and suggest your changes in the Makefile there. Except for extraordinary cases, I will not accept changes in the Makefile.
|
||||||
|
|
||||||
|
## Creating an issue
|
||||||
|
|
||||||
|
If you are going to report a bug or problem, always report the CPU model and OS. If possible, also paste the output of `cpufetch` and `cpufetch --debug`.
|
||||||
|
|
||||||
|
### cpufetch fails / crashes with a segmentation fault / ends without any output
|
||||||
|
You need to provide additional information in the github issue:
|
||||||
|
|
||||||
|
#### Option 1 (best)
|
||||||
|
1. Build cpufetch with debug symbols (`make clean; make debug`).
|
||||||
|
2. Install valgrind (if it is not already installed)
|
||||||
|
3. Run cpufetch with valgrind (`valgrind ./cpufetch`)
|
||||||
|
4. Paste the complete output (preferably on a platform like pastebin)
|
||||||
|
|
||||||
|
#### Option 2 (use this option if you can't work with option 1)
|
||||||
|
1. Build cpufetch with debug symbols (`make clean; make debug`).
|
||||||
|
2. Install gdb (if it is not already installed)
|
||||||
|
3. Debug cpufetch with gdb (`gdb cpufetch`)
|
||||||
|
3. Run cpufetch (just r inside gdb console)
|
||||||
|
4. Paste the complete output (preferably on a platform like pastebin)
|
||||||
23
Makefile
23
Makefile
@@ -1,6 +1,6 @@
|
|||||||
CC=gcc
|
CC ?= gcc
|
||||||
|
|
||||||
CFLAGS=-Wall -Wextra -Werror -pedantic -fstack-protector-all -pedantic -std=c99
|
CFLAGS+=-Wall -Wextra -pedantic -fstack-protector-all -pedantic -std=c99
|
||||||
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith
|
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith
|
||||||
|
|
||||||
PREFIX ?= /usr
|
PREFIX ?= /usr
|
||||||
@@ -35,13 +35,14 @@ else
|
|||||||
OUTPUT=cpufetch.exe
|
OUTPUT=cpufetch.exe
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
all: CFLAGS += -O3
|
||||||
all: $(OUTPUT)
|
all: $(OUTPUT)
|
||||||
|
|
||||||
debug: CFLAGS += -g -O0
|
debug: CFLAGS += -g -O0
|
||||||
debug: $(OUTPUT)
|
debug: $(OUTPUT)
|
||||||
|
|
||||||
release: CFLAGS += -static -O3
|
static: CFLAGS += -static -O3
|
||||||
release: $(OUTPUT)
|
static: $(OUTPUT)
|
||||||
|
|
||||||
$(OUTPUT): Makefile $(SOURCE) $(HEADERS)
|
$(OUTPUT): Makefile $(SOURCE) $(HEADERS)
|
||||||
$(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT)
|
$(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT)
|
||||||
@@ -50,14 +51,14 @@ run: $(OUTPUT)
|
|||||||
./$(OUTPUT)
|
./$(OUTPUT)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm $(OUTPUT)
|
@rm -f $(OUTPUT)
|
||||||
|
|
||||||
install: $(OUTPUT)
|
install: $(OUTPUT)
|
||||||
install -Dm755 "cpufetch" "$(PREFIX)/bin/cpufetch"
|
install -Dm755 "cpufetch" "$(DESTDIR)$(PREFIX)/bin/cpufetch"
|
||||||
install -Dm644 "LICENSE" "$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
|
install -Dm644 "LICENSE" "$(DESTDIR)$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
|
||||||
install -Dm644 "cpufetch.8" "$(PREFIX)/share/man/man8/cpufetch.8.gz"
|
install -Dm644 "cpufetch.1" "$(DESTDIR)$(PREFIX)/share/man/man1/cpufetch.1.gz"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f "$(PREFIX)/bin/cpufetch"
|
rm -f "$(DESTDIR)$(PREFIX)/bin/cpufetch"
|
||||||
rm -f "$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
|
rm -f "$(DESTDIR)$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
|
||||||
rm -f "$(PREFIX)/share/man/man8/cpufetch.8.gz"
|
rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/cpufetch.1.gz"
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -3,10 +3,10 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||

|

|
||||||

|
[](https://github.com/Dr-Noob/cpufetch/stargazers)
|
||||||

|
[](https://github.com/Dr-Noob/cpufetch/issues)
|
||||||

|
[](https://repology.org/project/cpufetch/versions)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://github.com/Dr-Noob/cpufetch/blob/master/LICENSE)
|
||||||
|
|
||||||
<h4 align="center">Simple yet fancy CPU architecture fetching tool</h4>
|
<h4 align="center">Simple yet fancy CPU architecture fetching tool</h4>
|
||||||
|
|
||||||
@@ -23,11 +23,9 @@
|
|||||||
|
|
||||||
- [1. Support](#1-support)
|
- [1. Support](#1-support)
|
||||||
- [2. Installation](#2-installation)
|
- [2. Installation](#2-installation)
|
||||||
- [2.1 Building from source](#21-building-from-source)
|
- [2.1 Available packages](#21-available-packages)
|
||||||
- [2.2 Linux](#22-linux)
|
- [2.2 Building from source (Linux/Windows/macOS)](#22-building-from-source-linuxwindowsmacos)
|
||||||
- [2.2 Windows](#22-windows)
|
- [2.3 Android](#23-android)
|
||||||
- [2.3 macOS](#23-macos)
|
|
||||||
- [2.4 Android](#24-android)
|
|
||||||
- [3. Examples](#3-examples)
|
- [3. Examples](#3-examples)
|
||||||
- [3.1 x86_64 CPUs](#31-x86_64-cpus)
|
- [3.1 x86_64 CPUs](#31-x86_64-cpus)
|
||||||
- [3.2 ARM CPUs](#32-arm-cpus)
|
- [3.2 ARM CPUs](#32-arm-cpus)
|
||||||
@@ -48,7 +46,14 @@ cpufetch supports x86, x86_64 (Intel and AMD) and ARM.
|
|||||||
| macOS | :heavy_check_mark: | :x: | Some information may be missing. <br> Apple M1 support may be added <br> in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))|
|
| macOS | :heavy_check_mark: | :x: | Some information may be missing. <br> Apple M1 support may be added <br> in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))|
|
||||||
|
|
||||||
# 2. Installation
|
# 2. Installation
|
||||||
## 2.1 Building from source
|
## 2.1 Installing from a package
|
||||||
|
Choose the right package for your operating system:
|
||||||
|
|
||||||
|
[](https://repology.org/project/cpufetch/versions)
|
||||||
|
|
||||||
|
If there is no available package for your OS, you can download the cpufetch binary from [the releases page](https://github.com/Dr-Noob/cpufetch/releases), or [build cpufetch from source](#22-building-from-source-linuxwindowsmacos) (see below).
|
||||||
|
|
||||||
|
## 2.2 Building from source (Linux/Windows/macOS)
|
||||||
Just clone the repo and use `make` to compile it
|
Just clone the repo and use `make` to compile it
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -60,16 +65,7 @@ make
|
|||||||
|
|
||||||
The Makefile is designed to work on Linux, Windows and macOS.
|
The Makefile is designed to work on Linux, Windows and macOS.
|
||||||
|
|
||||||
## 2.2 Linux
|
## 2.3 Android
|
||||||
There is a cpufetch package available in Arch Linux ([cpufetch-git](https://aur.archlinux.org/packages/cpufetch-git)). If you are in another distribution, you can build `cpufetch` from source.
|
|
||||||
|
|
||||||
## 2.2 Windows
|
|
||||||
In the [releases](https://github.com/Dr-Noob/cpufetch/releases) section you will find some cpufetch executables compiled for Windows. Just download and run it from Windows CMD. You can also build `cpufetch` from source.
|
|
||||||
|
|
||||||
## 2.3 macOS
|
|
||||||
You need to build `cpufetch` from source.
|
|
||||||
|
|
||||||
## 2.4 Android
|
|
||||||
1. Install `termux` app (terminal emulator)
|
1. Install `termux` app (terminal emulator)
|
||||||
2. Run `pkg install -y git make clang` inside termux.
|
2. Run `pkg install -y git make clang` inside termux.
|
||||||
3. Build from source normally:
|
3. Build from source normally:
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.2.
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.2.
|
||||||
.TH CPUFETCH "1" "March 2021" "cpufetch v0.96 (x86_64 build)" "User Commands"
|
.TH CPUFETCH "1" "June 2021" "cpufetch v0.97 (x86_64 build)" "User Commands"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
cpufetch \- manual page for cpufetch v0.96 (x86_64 build)
|
cpufetch \- Simple yet fancy CPU architecture fetching tool
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B cpufetch
|
.B cpufetch
|
||||||
[\fI\,OPTION\/\fR]...
|
[\fI\,OPTION\/\fR]...
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
Simple yet fancy CPU architecture fetching tool
|
Print detailed information about the CPU architecture. cpufetch displays information like the number of cores, microarchitecture, frequency, cache and peak performance. The program supports x86, x86_64 and ARM architectures and runs on GNU/Linux, Windows, Android and macOS (see https://github.com/Dr-Noob/cpufetch#1-support for more information)
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-c\fR, \fB\-\-color\fR
|
\fB\-c\fR, \fB\-\-color\fR
|
||||||
@@ -21,6 +21,9 @@ Prints CPU model and cpuid levels (debug purposes)
|
|||||||
\fB\-v\fR, \fB\-\-verbose\fR
|
\fB\-v\fR, \fB\-\-verbose\fR
|
||||||
Prints extra information (if available) about how cpufetch tried fetching information
|
Prints extra information (if available) about how cpufetch tried fetching information
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-r\fR, \fB\-\-raw\fR
|
||||||
|
Prints raw cpuid data
|
||||||
|
.TP
|
||||||
\fB\-h\fR, \fB\-\-help\fR
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
Prints this help and exit
|
Prints this help and exit
|
||||||
.TP
|
.TP
|
||||||
@@ -52,13 +55,16 @@ Old cpufetch style
|
|||||||
Fallback style for terminals that do not support colors
|
Fallback style for terminals that do not support colors
|
||||||
.SH "EXAMPLES:"
|
.SH "EXAMPLES:"
|
||||||
Run cpufetch with Intel color scheme:
|
Run cpufetch with Intel color scheme:
|
||||||
|
.PP
|
||||||
\&./cpufetch \fB\-\-color\fR intel
|
\&./cpufetch \fB\-\-color\fR intel
|
||||||
|
.PP
|
||||||
Run cpufetch with a custom color scheme:
|
Run cpufetch with a custom color scheme:
|
||||||
|
.PP
|
||||||
\&./cpufetch \fB\-\-color\fR 239,90,45:210,200,200:100,200,45:0,200,200
|
\&./cpufetch \fB\-\-color\fR 239,90,45:210,200,200:100,200,45:0,200,200
|
||||||
.SH "BUGS:"
|
.SH "BUGS:"
|
||||||
Report bugs to https://github.com/Dr\-Noob/cpufetch/issues
|
Report bugs to https://github.com/Dr\-Noob/cpufetch/issues
|
||||||
.SH "NOTE:"
|
.SH "NOTE:"
|
||||||
Peak performance information is NOT accurate. cpufetch computes peak performance using the max frequency. However, to properly compute peak performance, you need to know the frequency of the CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. For peak performance measurement see: https://github.com/Dr\-Noob/peakperf
|
Peak performance information is NOT accurate. cpufetch computes peak performance using the max frequency. However, to properly compute peak performance, you need to know the frequency of the CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. For peak performance measurement see peakperf (https://github.com/Dr\-Noob/peakperf)
|
||||||
.SH "AUTHOR:"
|
.SH "AUTHOR:"
|
||||||
Dr-Noob (https://github.com/Dr-Noob)
|
Dr-Noob (https://github.com/Dr-Noob)
|
||||||
|
|
||||||
@@ -24,6 +24,10 @@ struct uarch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
ISA_ARMv6,
|
||||||
|
ISA_ARMv6_T2,
|
||||||
|
ISA_ARMv6_KZ,
|
||||||
|
ISA_ARMv6_K,
|
||||||
ISA_ARMv7_A,
|
ISA_ARMv7_A,
|
||||||
ISA_ARMv8_A,
|
ISA_ARMv8_A,
|
||||||
ISA_ARMv8_A_AArch32,
|
ISA_ARMv8_A_AArch32,
|
||||||
@@ -37,7 +41,10 @@ enum {
|
|||||||
// ARM
|
// ARM
|
||||||
UARCH_ARM7,
|
UARCH_ARM7,
|
||||||
UARCH_ARM9,
|
UARCH_ARM9,
|
||||||
UARCH_ARM11, // ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore.
|
UARCH_ARM1136,
|
||||||
|
UARCH_ARM1156,
|
||||||
|
UARCH_ARM1176,
|
||||||
|
UARCH_ARM11MPCORE,
|
||||||
UARCH_CORTEX_A5,
|
UARCH_CORTEX_A5,
|
||||||
UARCH_CORTEX_A7,
|
UARCH_CORTEX_A7,
|
||||||
UARCH_CORTEX_A8,
|
UARCH_CORTEX_A8,
|
||||||
@@ -98,6 +105,10 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const ISA isas_uarch[] = {
|
static const ISA isas_uarch[] = {
|
||||||
|
[UARCH_ARM1136] = ISA_ARMv6,
|
||||||
|
[UARCH_ARM1156] = ISA_ARMv6_T2,
|
||||||
|
[UARCH_ARM1176] = ISA_ARMv6_KZ,
|
||||||
|
[UARCH_ARM11MPCORE] = ISA_ARMv6_K,
|
||||||
[UARCH_CORTEX_A5] = ISA_ARMv7_A,
|
[UARCH_CORTEX_A5] = ISA_ARMv7_A,
|
||||||
[UARCH_CORTEX_A7] = ISA_ARMv7_A,
|
[UARCH_CORTEX_A7] = ISA_ARMv7_A,
|
||||||
[UARCH_CORTEX_A8] = ISA_ARMv7_A,
|
[UARCH_CORTEX_A8] = ISA_ARMv7_A,
|
||||||
@@ -143,6 +154,10 @@ static const ISA isas_uarch[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char* isas_string[] = {
|
static char* isas_string[] = {
|
||||||
|
[ISA_ARMv6] = "ARMv6",
|
||||||
|
[ISA_ARMv6_T2] = "ARMv6T2",
|
||||||
|
[ISA_ARMv6_KZ] = "ARMv6KZ",
|
||||||
|
[ISA_ARMv6_K] = "ARMv6K",
|
||||||
[ISA_ARMv7_A] = "ARMv7",
|
[ISA_ARMv7_A] = "ARMv7",
|
||||||
[ISA_ARMv8_A] = "ARMv8",
|
[ISA_ARMv8_A] = "ARMv8",
|
||||||
[ISA_ARMv8_A_AArch32] = "ARMv8 AArch32",
|
[ISA_ARMv8_A_AArch32] = "ARMv8 AArch32",
|
||||||
@@ -190,6 +205,10 @@ struct uarch* get_uarch_from_midr(uint32_t midr, struct cpuInfo* cpu) {
|
|||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
// IM P V R //
|
// IM P V R //
|
||||||
UARCH_START
|
UARCH_START
|
||||||
|
CHECK_UARCH(arch, cpu, 'A', 0xB36, NA, NA, "ARM1136", UARCH_ARM1136, CPU_VENDOR_ARM)
|
||||||
|
CHECK_UARCH(arch, cpu, 'A', 0xB56, NA, NA, "ARM1156", UARCH_ARM1156, CPU_VENDOR_ARM)
|
||||||
|
CHECK_UARCH(arch, cpu, 'A', 0xB76, NA, NA, "ARM1176", UARCH_ARM1176, CPU_VENDOR_ARM)
|
||||||
|
CHECK_UARCH(arch, cpu, 'A', 0xB02, NA, NA, "ARM11 MPCore", UARCH_ARM11MPCORE, CPU_VENDOR_ARM)
|
||||||
CHECK_UARCH(arch, cpu, 'A', 0xC05, NA, NA, "Cortex-A5", UARCH_CORTEX_A5, CPU_VENDOR_ARM)
|
CHECK_UARCH(arch, cpu, 'A', 0xC05, NA, NA, "Cortex-A5", UARCH_CORTEX_A5, CPU_VENDOR_ARM)
|
||||||
CHECK_UARCH(arch, cpu, 'A', 0xC07, NA, NA, "Cortex-A7", UARCH_CORTEX_A7, CPU_VENDOR_ARM)
|
CHECK_UARCH(arch, cpu, 'A', 0xC07, NA, NA, "Cortex-A7", UARCH_CORTEX_A7, CPU_VENDOR_ARM)
|
||||||
CHECK_UARCH(arch, cpu, 'A', 0xC08, NA, NA, "Cortex-A8", UARCH_CORTEX_A8, CPU_VENDOR_ARM)
|
CHECK_UARCH(arch, cpu, 'A', 0xC08, NA, NA, "Cortex-A8", UARCH_CORTEX_A8, CPU_VENDOR_ARM)
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
int get_ncores_from_cpuinfo() {
|
int get_ncores_from_cpuinfo() {
|
||||||
// Examples:
|
// Examples:
|
||||||
// 0-271
|
// 0-271
|
||||||
// 0-5
|
|
||||||
// 0-7
|
// 0-7
|
||||||
|
// 0
|
||||||
|
|
||||||
int filelen;
|
int filelen;
|
||||||
char* buf;
|
char* buf;
|
||||||
if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) {
|
if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) {
|
||||||
@@ -27,8 +28,16 @@ int get_ncores_from_cpuinfo() {
|
|||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncores = 0;
|
int ncores;
|
||||||
char* tmp1 = strstr(buf, "-") + 1;
|
char* tmp1;
|
||||||
|
if((tmp1 = strstr(buf, "-")) == NULL) {
|
||||||
|
// file contains no - character, we assume that it contains 0,
|
||||||
|
// which means that the CPU contains only one core
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmp1++;
|
||||||
|
}
|
||||||
char* tmp2 = strstr(buf, "\n");
|
char* tmp2 = strstr(buf, "\n");
|
||||||
char ncores_str[filelen];
|
char ncores_str[filelen];
|
||||||
memset(ncores_str, 0, sizeof(char) * filelen);
|
memset(ncores_str, 0, sizeof(char) * filelen);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ static const char *SYTLES_STR_LIST[] = {
|
|||||||
struct args_struct {
|
struct args_struct {
|
||||||
bool debug_flag;
|
bool debug_flag;
|
||||||
bool help_flag;
|
bool help_flag;
|
||||||
|
bool raw_flag;
|
||||||
bool verbose_flag;
|
bool verbose_flag;
|
||||||
bool version_flag;
|
bool version_flag;
|
||||||
STYLE style;
|
STYLE style;
|
||||||
@@ -30,6 +31,7 @@ const char args_chr[] = {
|
|||||||
/* [ARG_CHAR_STYLE] = */ 's',
|
/* [ARG_CHAR_STYLE] = */ 's',
|
||||||
/* [ARG_CHAR_COLOR] = */ 'c',
|
/* [ARG_CHAR_COLOR] = */ 'c',
|
||||||
/* [ARG_CHAR_HELP] = */ 'h',
|
/* [ARG_CHAR_HELP] = */ 'h',
|
||||||
|
/* [ARG_CHAR_RAW] = */ 'r',
|
||||||
/* [ARG_CHAR_DEBUG] = */ 'd',
|
/* [ARG_CHAR_DEBUG] = */ 'd',
|
||||||
/* [ARG_CHAR_VERBOSE] = */ 'v',
|
/* [ARG_CHAR_VERBOSE] = */ 'v',
|
||||||
/* [ARG_CHAR_VERSION] = */ 'V',
|
/* [ARG_CHAR_VERSION] = */ 'V',
|
||||||
@@ -39,6 +41,7 @@ const char *args_str[] = {
|
|||||||
/* [ARG_CHAR_STYLE] = */ "style",
|
/* [ARG_CHAR_STYLE] = */ "style",
|
||||||
/* [ARG_CHAR_COLOR] = */ "color",
|
/* [ARG_CHAR_COLOR] = */ "color",
|
||||||
/* [ARG_CHAR_HELP] = */ "help",
|
/* [ARG_CHAR_HELP] = */ "help",
|
||||||
|
/* [ARG_CHAR_RAW] = */ "raw",
|
||||||
/* [ARG_CHAR_DEBUG] = */ "debug",
|
/* [ARG_CHAR_DEBUG] = */ "debug",
|
||||||
/* [ARG_CHAR_VERBOSE] = */ "verbose",
|
/* [ARG_CHAR_VERBOSE] = */ "verbose",
|
||||||
/* [ARG_CHAR_VERSION] = */ "version",
|
/* [ARG_CHAR_VERSION] = */ "version",
|
||||||
@@ -66,6 +69,10 @@ bool show_debug() {
|
|||||||
return args.debug_flag;
|
return args.debug_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool show_raw() {
|
||||||
|
return args.raw_flag;
|
||||||
|
}
|
||||||
|
|
||||||
bool verbose_enabled() {
|
bool verbose_enabled() {
|
||||||
return args.verbose_flag;
|
return args.verbose_flag;
|
||||||
}
|
}
|
||||||
@@ -182,9 +189,15 @@ char* build_short_options() {
|
|||||||
char* str = (char *) malloc(sizeof(char) * (len*2 + 1));
|
char* str = (char *) malloc(sizeof(char) * (len*2 + 1));
|
||||||
memset(str, 0, sizeof(char) * (len*2 + 1));
|
memset(str, 0, sizeof(char) * (len*2 + 1));
|
||||||
|
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
sprintf(str, "%c:%c:%c%c%c%c%c",
|
||||||
|
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_RAW],
|
||||||
|
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]);
|
||||||
|
#else
|
||||||
sprintf(str, "%c:%c:%c%c%c%c",
|
sprintf(str, "%c:%c:%c%c%c%c",
|
||||||
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
|
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
|
||||||
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]);
|
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]);
|
||||||
|
#endif
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -196,6 +209,7 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
|
|
||||||
bool color_flag = false;
|
bool color_flag = false;
|
||||||
args.debug_flag = false;
|
args.debug_flag = false;
|
||||||
|
args.raw_flag = false;
|
||||||
args.verbose_flag = false;
|
args.verbose_flag = false;
|
||||||
args.help_flag = false;
|
args.help_flag = false;
|
||||||
args.style = STYLE_EMPTY;
|
args.style = STYLE_EMPTY;
|
||||||
@@ -205,6 +219,9 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
{args_str[ARG_STYLE], required_argument, 0, args_chr[ARG_STYLE] },
|
{args_str[ARG_STYLE], required_argument, 0, args_chr[ARG_STYLE] },
|
||||||
{args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
|
{args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
|
||||||
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
{args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] },
|
||||||
|
#endif
|
||||||
{args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] },
|
{args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] },
|
||||||
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
|
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
|
||||||
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
||||||
@@ -241,6 +258,9 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
else if(opt == args_chr[ARG_HELP]) {
|
else if(opt == args_chr[ARG_HELP]) {
|
||||||
args.help_flag = true;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
|
else if(opt == args_chr[ARG_RAW]) {
|
||||||
|
args.raw_flag = true;
|
||||||
|
}
|
||||||
else if(opt == args_chr[ARG_VERBOSE]) {
|
else if(opt == args_chr[ARG_VERBOSE]) {
|
||||||
args.verbose_flag = true;
|
args.verbose_flag = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ enum {
|
|||||||
ARG_STYLE,
|
ARG_STYLE,
|
||||||
ARG_COLOR,
|
ARG_COLOR,
|
||||||
ARG_HELP,
|
ARG_HELP,
|
||||||
|
ARG_RAW,
|
||||||
ARG_DEBUG,
|
ARG_DEBUG,
|
||||||
ARG_VERBOSE,
|
ARG_VERBOSE,
|
||||||
ARG_VERSION
|
ARG_VERSION
|
||||||
@@ -43,6 +44,7 @@ extern const char *args_str[];
|
|||||||
int max_arg_str_length();
|
int max_arg_str_length();
|
||||||
bool parse_args(int argc, char* argv[]);
|
bool parse_args(int argc, char* argv[]);
|
||||||
bool show_help();
|
bool show_help();
|
||||||
|
bool show_raw();
|
||||||
bool show_debug();
|
bool show_debug();
|
||||||
bool show_version();
|
bool show_version();
|
||||||
bool verbose_enabled();
|
bool verbose_enabled();
|
||||||
|
|||||||
0
src/common/cpu.c
Executable file → Normal file
0
src/common/cpu.c
Executable file → Normal file
@@ -119,6 +119,8 @@ struct cpuInfo {
|
|||||||
uint32_t maxLevels;
|
uint32_t maxLevels;
|
||||||
// Max cpuids extended levels
|
// Max cpuids extended levels
|
||||||
uint32_t maxExtendedLevels;
|
uint32_t maxExtendedLevels;
|
||||||
|
// Topology Extensions (AMD only)
|
||||||
|
bool topology_extensions;
|
||||||
#elif ARCH_ARM
|
#elif ARCH_ARM
|
||||||
// Main ID register
|
// Main ID register
|
||||||
uint32_t midr;
|
uint32_t midr;
|
||||||
|
|||||||
@@ -14,7 +14,21 @@
|
|||||||
#include "../arm/midr.h"
|
#include "../arm/midr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char* VERSION = "0.96";
|
#ifdef __linux__
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
static const char* OS_STR = "Android";
|
||||||
|
#else
|
||||||
|
static const char* OS_STR = "Linux";
|
||||||
|
#endif
|
||||||
|
#elif _WIN32
|
||||||
|
static const char* OS_STR = "Windows";
|
||||||
|
#elif defined __APPLE__ || __MACH__
|
||||||
|
static const char* OS_STR = "macOS";
|
||||||
|
#else
|
||||||
|
static const char* OS_STR = "Unknown OS";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const char* VERSION = "0.98";
|
||||||
|
|
||||||
void print_help(char *argv[]) {
|
void print_help(char *argv[]) {
|
||||||
const char **t = args_str;
|
const char **t = args_str;
|
||||||
@@ -33,6 +47,9 @@ void print_help(char *argv[]) {
|
|||||||
printf(" -%c, --%s %*s Prints main ID register values for all cores (debug purposes)\n", c[ARG_DEBUG], t[ARG_DEBUG], (int) (max_len-strlen(t[ARG_DEBUG])), "");
|
printf(" -%c, --%s %*s Prints main ID register values for all cores (debug purposes)\n", c[ARG_DEBUG], t[ARG_DEBUG], (int) (max_len-strlen(t[ARG_DEBUG])), "");
|
||||||
#endif
|
#endif
|
||||||
printf(" -%c, --%s %*s Prints extra information (if available) about how cpufetch tried fetching information\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
|
printf(" -%c, --%s %*s Prints extra information (if available) about how cpufetch tried fetching information\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
printf(" -%c, --%s %*s Prints raw cpuid data\n", c[ARG_RAW], t[ARG_RAW], (int) (max_len-strlen(t[ARG_RAW])), "");
|
||||||
|
#endif
|
||||||
printf(" -%c, --%s %*s Prints this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
|
printf(" -%c, --%s %*s Prints this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
|
||||||
printf(" -%c, --%s %*s Prints cpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
printf(" -%c, --%s %*s Prints cpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
||||||
|
|
||||||
@@ -66,7 +83,7 @@ void print_help(char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_version() {
|
void print_version() {
|
||||||
printf("cpufetch v%s (%s)\n",VERSION, ARCH_STR);
|
printf("cpufetch v%s (%s %s)\n",VERSION, OS_STR, ARCH_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@@ -95,6 +112,17 @@ int main(int argc, char* argv[]) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(show_raw()) {
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
print_version();
|
||||||
|
print_raw(cpu);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
#else
|
||||||
|
printErr("raw option is valid only in x86_64");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if(print_cpufetch(cpu, get_style(), get_colors()))
|
if(print_cpufetch(cpu, get_style(), get_colors()))
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -227,6 +227,11 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
|
|||||||
art->ascii_chars[1] = '#';
|
art->ascii_chars[1] = '#';
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
// Old Windows do not define the flag
|
||||||
|
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||||
|
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
||||||
|
#endif
|
||||||
|
|
||||||
HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
DWORD console_mode;
|
DWORD console_mode;
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ struct apic {
|
|||||||
bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo);
|
bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo);
|
||||||
uint32_t is_smt_enabled_amd(struct topology* topo);
|
uint32_t is_smt_enabled_amd(struct topology* topo);
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
bool bind_to_cpu(int cpu_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
159
src/x86/cpuid.c
Executable file → Normal file
159
src/x86/cpuid.c
Executable file → Normal file
@@ -310,6 +310,13 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
printWarn("Can't read cpu name from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000004, cpu->maxExtendedLevels);
|
printWarn("Can't read cpu name from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000004, cpu->maxExtendedLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpu->topology_extensions = false;
|
||||||
|
if(cpu->cpu_vendor == CPU_VENDOR_AMD && cpu->maxExtendedLevels >= 0x80000001) {
|
||||||
|
eax = 0x80000001;
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
cpu->topology_extensions = (ecx >> 22) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
cpu->arch = get_cpu_uarch(cpu);
|
cpu->arch = get_cpu_uarch(cpu);
|
||||||
cpu->freq = get_frequency_info(cpu);
|
cpu->freq = get_frequency_info(cpu);
|
||||||
cpu->cach = get_cache_info(cpu);
|
cpu->cach = get_cache_info(cpu);
|
||||||
@@ -322,7 +329,7 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool get_cache_topology_amd(struct cpuInfo* cpu, struct topology* topo) {
|
bool get_cache_topology_amd(struct cpuInfo* cpu, struct topology* topo) {
|
||||||
if(cpu->maxExtendedLevels >= 0x8000001D) {
|
if(cpu->maxExtendedLevels >= 0x8000001D && cpu->topology_extensions) {
|
||||||
uint32_t i, eax, ebx, ecx, edx, num_sharing_cache, cache_type, cache_level;
|
uint32_t i, eax, ebx, ecx, edx, num_sharing_cache, cache_type, cache_level;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -379,7 +386,7 @@ bool get_cache_topology_amd(struct cpuInfo* cpu, struct topology* topo) {
|
|||||||
} while (cache_type > 0);
|
} while (cache_type > 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X). Guessing cache sizes", 0x8000001D, cpu->maxExtendedLevels);
|
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X and topology_extensions=%s). Guessing cache topology", 0x8000001D, cpu->maxExtendedLevels, cpu->topology_extensions ? "true" : "false");
|
||||||
topo->cach->L1i->num_caches = topo->physical_cores;
|
topo->cach->L1i->num_caches = topo->physical_cores;
|
||||||
topo->cach->L1d->num_caches = topo->physical_cores;
|
topo->cach->L1d->num_caches = topo->physical_cores;
|
||||||
|
|
||||||
@@ -440,13 +447,13 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach) {
|
|||||||
cpuid(&eax, &ebx, &ecx, &edx);
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
topo->logical_cores = (ecx & 0xFF) + 1;
|
topo->logical_cores = (ecx & 0xFF) + 1;
|
||||||
|
|
||||||
if (cpu->maxExtendedLevels >= 0x8000001E) {
|
if (cpu->maxExtendedLevels >= 0x8000001E && cpu->topology_extensions) {
|
||||||
eax = 0x8000001E;
|
eax = 0x8000001E;
|
||||||
cpuid(&eax, &ebx, &ecx, &edx);
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
topo->smt_supported = ((ebx >> 8) & 0x03) + 1;
|
topo->smt_supported = ((ebx >> 8) & 0x03) + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x8000001E, cpu->maxExtendedLevels);
|
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X and topology_extensions=%s)", 0x8000001E, cpu->maxExtendedLevels, cpu->topology_extensions ? "true" : "false");
|
||||||
topo->smt_supported = 1;
|
topo->smt_supported = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -574,6 +581,7 @@ struct cache* get_cache_info_general(struct cache* cach, uint32_t level) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printWarn("Found unknown unified cache at level %d (size is %d bytes)", cache_level, cache_total_size);
|
printWarn("Found unknown unified cache at level %d (size is %d bytes)", cache_level, cache_total_size);
|
||||||
|
cach->max_cache_level--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -610,8 +618,8 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
level = 0x8000001D;
|
level = 0x8000001D;
|
||||||
if(cpu->maxExtendedLevels < level) {
|
if(cpu->maxExtendedLevels < level || !cpu->topology_extensions) {
|
||||||
printWarn("Can't read cache information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", level, cpu->maxExtendedLevels);
|
printWarn("Can't read cache information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X and topology_extensions=%s)", level, cpu->maxExtendedLevels, cpu->topology_extensions ? "true" : "false");
|
||||||
level = 0x80000006;
|
level = 0x80000006;
|
||||||
if(cpu->maxExtendedLevels < level) {
|
if(cpu->maxExtendedLevels < level) {
|
||||||
printWarn("Can't read cache information from cpuid using old method (needed extended level is 0x%.8X, max is 0x%.8X)", level, cpu->maxExtendedLevels);
|
printWarn("Can't read cache information from cpuid using old method (needed extended level is 0x%.8X, max is 0x%.8X)", level, cpu->maxExtendedLevels);
|
||||||
@@ -625,29 +633,6 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity checks. If we read values greater than this, they can't be valid ones
|
|
||||||
// The values were chosen by me
|
|
||||||
if(cach->L1i->size > 64 * 1024) {
|
|
||||||
printBug("Invalid L1i size: %dKB", cach->L1i->size/1024);
|
|
||||||
}
|
|
||||||
if(cach->L1d->size > 64 * 1024) {
|
|
||||||
printBug("Invalid L1d size: %dKB", cach->L1d->size/1024);
|
|
||||||
}
|
|
||||||
if(cach->L2->exists) {
|
|
||||||
if(cach->L3->exists && cach->L2->size > 2 * 1048576) {
|
|
||||||
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
|
||||||
}
|
|
||||||
else if(cach->L2->size > 100 * 1048576) {
|
|
||||||
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cach->L3->exists && cach->L3->size > 100 * 1048576) {
|
|
||||||
printBug("Invalid L3 size: %dMB", cach->L3->size/(1048576));
|
|
||||||
}
|
|
||||||
if(!cach->L2->exists) {
|
|
||||||
printBug("Could not find L2 cache");
|
|
||||||
}
|
|
||||||
|
|
||||||
return cach;
|
return cach;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,12 +650,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
freq->max = get_max_freq_from_file(0, cpu->hv->present);
|
freq->max = get_max_freq_from_file(0, cpu->hv->present);
|
||||||
|
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
if(cpu->hv->present) {
|
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
||||||
printWarn("Read max CPU frequency and got 0 MHz");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printBug("Read max CPU frequency and got 0 MHz");
|
|
||||||
}
|
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -687,24 +667,19 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
freq->max = ebx;
|
freq->max = ebx;
|
||||||
|
|
||||||
if(freq->base == 0) {
|
if(freq->base == 0) {
|
||||||
if(cpu->hv->present) {
|
printWarn("Read base CPU frequency from CPUID and got 0 MHz");
|
||||||
printWarn("Read base CPU frequency and got 0 MHz");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printBug("Read base CPU frequency and got 0 MHz");
|
|
||||||
}
|
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
if(cpu->hv->present) {
|
printWarn("Read max CPU frequency from CPUID and got 0 MHz. Using udev");
|
||||||
printWarn("Read max CPU frequency and got 0 MHz");
|
freq->max = get_max_freq_from_file(0, cpu->hv->present);
|
||||||
}
|
|
||||||
else {
|
if(freq->max == 0) {
|
||||||
printBug("Read max CPU frequency and got 0 MHz");
|
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
||||||
}
|
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
@@ -890,14 +865,102 @@ void print_debug(struct cpuInfo* cpu) {
|
|||||||
cpuid(&eax, &ebx, &ecx, &edx);
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
printf("%s\n", cpu->cpu_name);
|
printf("%s\n", cpu->cpu_name);
|
||||||
if(cpu->hv->present) printf("- Hypervisor: %s\n", cpu->hv->hv_name);
|
if(cpu->hv->present) {
|
||||||
|
printf("- Hypervisor: %s\n", cpu->hv->hv_name);
|
||||||
|
}
|
||||||
printf("- Max standard level: 0x%.8X\n", cpu->maxLevels);
|
printf("- Max standard level: 0x%.8X\n", cpu->maxLevels);
|
||||||
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
|
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
|
||||||
|
if(cpu->cpu_vendor == CPU_VENDOR_AMD) {
|
||||||
|
printf("- AMD topology extensions: %d\n", cpu->topology_extensions);
|
||||||
|
}
|
||||||
printf("- CPUID dump: 0x%.8X\n", eax);
|
printf("- CPUID dump: 0x%.8X\n", eax);
|
||||||
|
|
||||||
free_cpuinfo_struct(cpu);
|
free_cpuinfo_struct(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Query HV and Xeon Phi levels
|
||||||
|
void print_raw(struct cpuInfo* cpu) {
|
||||||
|
uint32_t eax;
|
||||||
|
uint32_t ebx;
|
||||||
|
uint32_t ecx;
|
||||||
|
uint32_t edx;
|
||||||
|
printf("%s\n\n", cpu->cpu_name);
|
||||||
|
printf(" CPUID leaf sub EAX EBX ECX EDX \n");
|
||||||
|
printf("--------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
for(int c=0; c < cpu->topo->total_cores; c++) {
|
||||||
|
#ifndef __APPLE__
|
||||||
|
if(!bind_to_cpu(c)) {
|
||||||
|
printErr("Failed binding to CPU %d", c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("CPU %d:\n", c);
|
||||||
|
|
||||||
|
for(uint32_t reg=0x00000000; reg <= cpu->maxLevels; reg++) {
|
||||||
|
if(reg == 0x00000004) {
|
||||||
|
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
||||||
|
eax = reg;
|
||||||
|
ebx = 0;
|
||||||
|
ecx = reg2;
|
||||||
|
edx = 0;
|
||||||
|
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
printf(" 0x%.8X 0x%.2X: 0x%.8X 0x%.8X 0x%.8X 0x%.8X\n", reg, reg2, eax, ebx, ecx, edx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(reg == 0x0000000B) {
|
||||||
|
for(uint32_t reg2=0x00000000; reg2 < cpu->topo->smt_supported; reg2++) {
|
||||||
|
eax = reg;
|
||||||
|
ebx = 0;
|
||||||
|
ecx = reg2;
|
||||||
|
edx = 0;
|
||||||
|
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
printf(" 0x%.8X 0x%.2X: 0x%.8X 0x%.8X 0x%.8X 0x%.8X\n", reg, reg2, eax, ebx, ecx, edx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
eax = reg;
|
||||||
|
ebx = 0;
|
||||||
|
ecx = 0;
|
||||||
|
edx = 0;
|
||||||
|
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
printf(" 0x%.8X 0x%.2X: 0x%.8X 0x%.8X 0x%.8X 0x%.8X\n", reg, 0x00, eax, ebx, ecx, edx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(uint32_t reg=0x80000000; reg <= cpu->maxExtendedLevels; reg++) {
|
||||||
|
if(reg == 0x8000001D) {
|
||||||
|
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
||||||
|
eax = reg;
|
||||||
|
ebx = 0;
|
||||||
|
ecx = reg2;
|
||||||
|
edx = 0;
|
||||||
|
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
printf(" 0x%.8X 0x%.2X: 0x%.8X 0x%.8X 0x%.8X 0x%.8X\n", reg, reg2, eax, ebx, ecx, edx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
eax = reg;
|
||||||
|
ebx = 0;
|
||||||
|
ecx = 0;
|
||||||
|
edx = 0;
|
||||||
|
|
||||||
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
printf(" 0x%.8X 0x%.2X: 0x%.8X 0x%.8X 0x%.8X 0x%.8X\n", reg, 0x00, eax, ebx, ecx, edx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void free_topo_struct(struct topology* topo) {
|
void free_topo_struct(struct topology* topo) {
|
||||||
free(topo->apic->cache_select_mask);
|
free(topo->apic->cache_select_mask);
|
||||||
free(topo->apic->cache_id_apic);
|
free(topo->apic->cache_id_apic);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_soc
|
|||||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
|
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
|
||||||
|
|
||||||
void print_debug(struct cpuInfo* cpu);
|
void print_debug(struct cpuInfo* cpu);
|
||||||
|
void print_raw(struct cpuInfo* cpu);
|
||||||
|
|
||||||
void free_topo_struct(struct topology* topo);
|
void free_topo_struct(struct topology* topo);
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
typedef uint32_t MICROARCH;
|
typedef uint32_t MICROARCH;
|
||||||
|
|
||||||
|
#define STRING_UNKNOWN "Unknown"
|
||||||
|
|
||||||
// Data not available
|
// Data not available
|
||||||
#define NA -1
|
#define NA -1
|
||||||
|
|
||||||
@@ -402,13 +404,22 @@ char* get_str_uarch(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* get_str_process(struct cpuInfo* cpu) {
|
char* get_str_process(struct cpuInfo* cpu) {
|
||||||
char* str = malloc(sizeof(char) * (4+2+1));
|
char* str = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||||
uint32_t process = cpu->arch->process;
|
int32_t process = cpu->arch->process;
|
||||||
|
|
||||||
if(process > 100)
|
if(process == UNK) {
|
||||||
|
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||||
|
}
|
||||||
|
else if(process > 100) {
|
||||||
sprintf(str, "%.2fum", (double)process/100);
|
sprintf(str, "%.2fum", (double)process/100);
|
||||||
else
|
}
|
||||||
|
else if(process > 0){
|
||||||
sprintf(str, "%dnm", process);
|
sprintf(str, "%dnm", process);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||||
|
printBug("Found invalid process: '%d'", process);
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user