mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3719dc216 | ||
|
|
7a3fd539c3 | ||
|
|
f6bf00e33d | ||
|
|
985bd6f25f | ||
|
|
f599613f5e | ||
|
|
8a8b1dffa8 | ||
|
|
8e95828fb1 | ||
|
|
93f733cb12 | ||
|
|
0397db2fd8 | ||
|
|
ebe7312c9d | ||
|
|
8c72295f47 | ||
|
|
bec47a44a7 | ||
|
|
de638aba50 | ||
|
|
5be6f8bba0 | ||
|
|
10d4f67cdb | ||
|
|
5dd6ab60cb | ||
|
|
99fd108d0f | ||
|
|
f28f3ef70d | ||
|
|
89aadeead8 | ||
|
|
f58d76ccac | ||
|
|
889fbf2d67 | ||
|
|
91cc04c653 | ||
|
|
2b4e675800 |
10
Makefile
10
Makefile
@@ -1,7 +1,7 @@
|
|||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
|
|
||||||
CFLAGS+=-Wall -Wextra -pedantic
|
CFLAGS+=-Wall -Wextra -pedantic
|
||||||
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith
|
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith -Wstrict-prototypes
|
||||||
|
|
||||||
PREFIX ?= /usr
|
PREFIX ?= /usr
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ ifneq ($(OS),Windows_NT)
|
|||||||
CFLAGS += -DARCH_PPC -std=gnu99 -fstack-protector-all -Wno-language-extension-token
|
CFLAGS += -DARCH_PPC -std=gnu99 -fstack-protector-all -Wno-language-extension-token
|
||||||
else ifeq ($(arch), $(filter $(arch), arm aarch64_be aarch64 arm64 armv8b armv8l armv7l armv6l))
|
else ifeq ($(arch), $(filter $(arch), arm aarch64_be aarch64 arm64 armv8b armv8l armv7l armv6l))
|
||||||
SRC_DIR=src/arm/
|
SRC_DIR=src/arm/
|
||||||
SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c
|
SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_COMMON)soc.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c
|
||||||
HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h
|
HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_COMMON)soc.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h
|
||||||
CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 -fstack-protector-all
|
CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 -fstack-protector-all
|
||||||
|
|
||||||
os := $(shell uname -s)
|
os := $(shell uname -s)
|
||||||
@@ -43,8 +43,8 @@ ifneq ($(OS),Windows_NT)
|
|||||||
endif
|
endif
|
||||||
else ifeq ($(arch), $(filter $(arch), riscv64 riscv32))
|
else ifeq ($(arch), $(filter $(arch), riscv64 riscv32))
|
||||||
SRC_DIR=src/riscv/
|
SRC_DIR=src/riscv/
|
||||||
SOURCE += $(COMMON_SRC) $(SRC_DIR)riscv.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c
|
SOURCE += $(COMMON_SRC) $(SRC_DIR)riscv.c $(SRC_DIR)uarch.c $(SRC_COMMON)soc.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c
|
||||||
HEADERS += $(COMMON_SRC) $(SRC_DIR)riscv.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.h $(SRC_DIR)socs.h
|
HEADERS += $(COMMON_HDR) $(SRC_DIR)riscv.h $(SRC_DIR)uarch.h $(SRC_COMMON)soc.h $(SRC_DIR)soc.h $(SRC_DIR)udev.h $(SRC_DIR)socs.h
|
||||||
CFLAGS += -DARCH_RISCV -Wno-unused-parameter -std=c99 -fstack-protector-all
|
CFLAGS += -DARCH_RISCV -Wno-unused-parameter -std=c99 -fstack-protector-all
|
||||||
else
|
else
|
||||||
# Error lines should not be tabulated because Makefile complains about it
|
# Error lines should not be tabulated because Makefile complains about it
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -57,17 +57,17 @@ cpufetch is a command-line tool written in C that displays the CPU information i
|
|||||||
|
|
||||||
## 1. Support
|
## 1. Support
|
||||||
|
|
||||||
| OS | x86_64 / x86 | ARM | PowerPC |
|
| OS | x86_64 / x86 | ARM | RISC-V | PowerPC |
|
||||||
|:-----------:|:------------------:|:------------------:|:------------------:|
|
|:-----------:|:------------------:|:------------------:|:------------------:|:------------------:|
|
||||||
| GNU / Linux | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
| GNU / Linux | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
| Windows | :heavy_check_mark: | :x: | :x: |
|
| Windows | :heavy_check_mark: | :x: | :x: | :x: |
|
||||||
| Android | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
| Android | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
|
||||||
| macOS | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
| macOS | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||||
| FreeBSD | :heavy_check_mark: | :x: | :x: |
|
| FreeBSD | :heavy_check_mark: | :x: | :x: | :x: |
|
||||||
|
|
||||||
**NOTES:**
|
**NOTES:**
|
||||||
- Colors will be used in Windows only if the terminal supports it.
|
- Colors will be used in Windows only if the terminal supports it.
|
||||||
- Support in macOS ARM is limited to Apple M1 only
|
- Support in macOS ARM is limited to Apple chips only
|
||||||
|
|
||||||
## 2. Installation
|
## 2. Installation
|
||||||
### 2.1 Installing from a package
|
### 2.1 Installing from a package
|
||||||
@@ -153,9 +153,10 @@ See [cpufetch contributing guidelines](https://github.com/Dr-Noob/cpufetch/blob/
|
|||||||
Thanks to the fellow contributors and interested people in the project. Special thanks to:
|
Thanks to the fellow contributors and interested people in the project. Special thanks to:
|
||||||
- [Gonzalocl](https://github.com/Gonzalocl) and [OdnetninI](https://github.com/OdnetninI): Tested cpufetch in the earlier versions of the project in many different CPUs.
|
- [Gonzalocl](https://github.com/Gonzalocl) and [OdnetninI](https://github.com/OdnetninI): Tested cpufetch in the earlier versions of the project in many different CPUs.
|
||||||
- [Kyngo](https://github.com/Kyngo): Tested cpufetch in the Apple M1 CPU.
|
- [Kyngo](https://github.com/Kyngo): Tested cpufetch in the Apple M1 CPU.
|
||||||
- [avollmerhaus](https://github.com/avollmerhaus): Gave me ssh acess to a PowerPC machine, allowing me to develop the PowerPC port.
|
- [avollmerhaus](https://github.com/avollmerhaus): Helped with PowerPC port giving ssh access to a PowerPC machine.
|
||||||
- [bbonev](https://github.com/bbonev) and [stephan-cr](https://github.com/stephan-cr): Reviewed the source code.
|
- [bbonev](https://github.com/bbonev) and [stephan-cr](https://github.com/stephan-cr): Reviewed the source code.
|
||||||
- [mdoksa76](https://github.com/mdoksa76) and [exkc](https://github.com/exkc): Excellent ideas and impeccable feedback for supporting Allwinner SoCs.
|
- [mdoksa76](https://github.com/mdoksa76) and [exkc](https://github.com/exkc): Excellent ideas and feedback for supporting Allwinner SoCs.
|
||||||
|
- [Sakura286](https://github.com/Sakura286), [exkc](https://github.com/exkc) and [Patola](https://github.com/Patola): Helped with RISC-V port with ssh access, ideas, testing, etc.
|
||||||
|
|
||||||
## 8. cpufetch for GPUs (gpufetch)
|
## 8. cpufetch for GPUs (gpufetch)
|
||||||
See [gpufetch](https://github.com/Dr-Noob/gpufetch) project!
|
See [gpufetch](https://github.com/Dr-Noob/gpufetch) project!
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
|
#include "../common/soc.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "midr.h"
|
#include "midr.h"
|
||||||
#include "uarch.h"
|
#include "uarch.h"
|
||||||
#include "soc.h"
|
|
||||||
|
|
||||||
bool cores_are_equal(int c1pos, int c2pos, uint32_t* midr_array, int32_t* freq_array) {
|
bool cores_are_equal(int c1pos, int c2pos, uint32_t* midr_array, int32_t* freq_array) {
|
||||||
return midr_array[c1pos] == midr_array[c2pos] && freq_array[c1pos] == freq_array[c2pos];
|
return midr_array[c1pos] == midr_array[c2pos] && freq_array[c1pos] == freq_array[c2pos];
|
||||||
|
|||||||
@@ -15,17 +15,6 @@
|
|||||||
#define min(a,b) (((a)<(b))?(a):(b))
|
#define min(a,b) (((a)<(b))?(a):(b))
|
||||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
|
|
||||||
static char* soc_trademark_string[] = {
|
|
||||||
[SOC_VENDOR_SNAPDRAGON] = "Snapdragon ",
|
|
||||||
[SOC_VENDOR_MEDIATEK] = "MediaTek ",
|
|
||||||
[SOC_VENDOR_EXYNOS] = "Exynos ",
|
|
||||||
[SOC_VENDOR_KIRIN] = "Kirin ",
|
|
||||||
[SOC_VENDOR_BROADCOM] = "Broadcom BCM",
|
|
||||||
[SOC_VENDOR_APPLE] = "Apple ",
|
|
||||||
[SOC_VENDOR_ALLWINNER] = "Allwinner ",
|
|
||||||
[SOC_VENDOR_ROCKCHIP] = "Rockchip ",
|
|
||||||
};
|
|
||||||
|
|
||||||
static char* soc_rpi_string[] = {
|
static char* soc_rpi_string[] = {
|
||||||
"BCM2835",
|
"BCM2835",
|
||||||
"BCM2836",
|
"BCM2836",
|
||||||
@@ -33,30 +22,6 @@ static char* soc_rpi_string[] = {
|
|||||||
"BCM2711"
|
"BCM2711"
|
||||||
};
|
};
|
||||||
|
|
||||||
void fill_soc(struct system_on_chip* soc, char* soc_name, SOC soc_model, int32_t process) {
|
|
||||||
soc->soc_model = soc_model;
|
|
||||||
soc->soc_vendor = get_soc_vendor_from_soc(soc_model);
|
|
||||||
soc->process = process;
|
|
||||||
int len = strlen(soc_name) + strlen(soc_trademark_string[soc->soc_vendor]) + 1;
|
|
||||||
soc->soc_name = emalloc(sizeof(char) * len);
|
|
||||||
memset(soc->soc_name, 0, sizeof(char) * len);
|
|
||||||
sprintf(soc->soc_name, "%s%s", soc_trademark_string[soc->soc_vendor], soc_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match_soc(struct system_on_chip* soc, char* raw_name, char* expected_name, char* soc_name, SOC soc_model, int32_t process) {
|
|
||||||
int len1 = strlen(raw_name);
|
|
||||||
int len2 = strlen(expected_name);
|
|
||||||
int len = min(len1, len2);
|
|
||||||
|
|
||||||
if(strncmp(raw_name, expected_name, len) != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fill_soc(soc, soc_name, soc_model, process);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char* toupperstr(char* str) {
|
char* toupperstr(char* str) {
|
||||||
int len = strlen(str) + 1;
|
int len = strlen(str) + 1;
|
||||||
char* ret = emalloc(sizeof(char) * len);
|
char* ret = emalloc(sizeof(char) * len);
|
||||||
@@ -123,11 +88,7 @@ bool get_sunxisoc_from_sid(struct system_on_chip* soc, char* raw_name, uint32_t
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SOC_START if (false) {}
|
// Exynos special define (not included in src/common/soc.h)
|
||||||
#define SOC_EQ(raw_name, expected_name, soc_name, soc_model, soc, process) \
|
|
||||||
else if (match_soc(soc, raw_name, expected_name, soc_name, soc_model, process)) return true;
|
|
||||||
#define SOC_END else { return false; }
|
|
||||||
// Exynos special define
|
|
||||||
#define SOC_EXY_EQ(raw_name, tmpsoc, soc_name, soc_model, soc, process) \
|
#define SOC_EXY_EQ(raw_name, tmpsoc, soc_name, soc_model, soc, process) \
|
||||||
sprintf(tmpsoc, "exynos%s", soc_name); \
|
sprintf(tmpsoc, "exynos%s", soc_name); \
|
||||||
if (match_soc(soc, raw_name, tmpsoc, soc_name, soc_model, process)) return true; \
|
if (match_soc(soc, raw_name, tmpsoc, soc_name, soc_model, process)) return true; \
|
||||||
@@ -657,7 +618,7 @@ struct system_on_chip* guess_soc_from_cpuinfo(struct system_on_chip* soc) {
|
|||||||
return soc;
|
return soc;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* get_rk_efuse() {
|
char* get_rk_efuse(void) {
|
||||||
int filelen;
|
int filelen;
|
||||||
char* rk_soc = read_file(_PATH_RK_EFUSE0, &filelen);
|
char* rk_soc = read_file(_PATH_RK_EFUSE0, &filelen);
|
||||||
if(rk_soc == NULL) {
|
if(rk_soc == NULL) {
|
||||||
@@ -838,19 +799,25 @@ struct system_on_chip* get_soc(void) {
|
|||||||
|
|
||||||
soc = guess_soc_from_cpuinfo(soc);
|
soc = guess_soc_from_cpuinfo(soc);
|
||||||
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
|
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
|
||||||
if(soc->raw_name != NULL)
|
if(soc->raw_name != NULL) {
|
||||||
printWarn("SoC detection failed using /proc/cpuinfo: Found '%s' string", soc->raw_name);
|
printWarn("SoC detection failed using /proc/cpuinfo: Found '%s' string", soc->raw_name);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
printWarn("SoC detection failed using /proc/cpuinfo: No string found");
|
printWarn("SoC detection failed using /proc/cpuinfo: No string found");
|
||||||
// If cpufinfo detection fails, try with nvmem
|
}
|
||||||
soc = guess_soc_from_nvmem(soc);
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
soc = guess_soc_from_android(soc);
|
soc = guess_soc_from_android(soc);
|
||||||
if(soc->raw_name == NULL)
|
if(soc->raw_name == NULL) {
|
||||||
printWarn("SoC detection failed using Android: No string found");
|
printWarn("SoC detection failed using Android: No string found");
|
||||||
else if(soc->soc_vendor == SOC_VENDOR_UNKNOWN)
|
}
|
||||||
|
else if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
|
||||||
printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name);
|
printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name);
|
||||||
|
}
|
||||||
#endif // ifdef __ANDROID__
|
#endif // ifdef __ANDROID__
|
||||||
|
// If cpufinfo/Android (if available) detection fails, try with nvmem
|
||||||
|
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
|
||||||
|
soc = guess_soc_from_nvmem(soc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#elif defined __APPLE__ || __MACH__
|
#elif defined __APPLE__ || __MACH__
|
||||||
soc = guess_soc_apple(soc);
|
soc = guess_soc_apple(soc);
|
||||||
@@ -871,28 +838,3 @@ struct system_on_chip* get_soc(void) {
|
|||||||
|
|
||||||
return soc;
|
return soc;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* get_soc_name(struct system_on_chip* soc) {
|
|
||||||
if(soc->soc_model == SOC_MODEL_UNKNOWN)
|
|
||||||
return soc->raw_name;
|
|
||||||
return soc->soc_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
VENDOR get_soc_vendor(struct system_on_chip* soc) {
|
|
||||||
return soc->soc_vendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* get_str_process(struct system_on_chip* soc) {
|
|
||||||
char* str;
|
|
||||||
|
|
||||||
if(soc->process == UNKNOWN) {
|
|
||||||
str = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
|
||||||
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
str = emalloc(sizeof(char) * 5);
|
|
||||||
memset(str, 0, sizeof(char) * 5);
|
|
||||||
snprintf(str, 5, "%dnm", soc->process);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,34 +1,10 @@
|
|||||||
#ifndef __SOC__
|
#ifndef __SOC_ARM__
|
||||||
#define __SOC__
|
#define __SOC_ARM__
|
||||||
|
|
||||||
#include "../common/cpu.h"
|
#include "../common/cpu.h"
|
||||||
|
#include "../common/soc.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef int32_t SOC;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
SOC_VENDOR_UNKNOWN,
|
|
||||||
SOC_VENDOR_SNAPDRAGON,
|
|
||||||
SOC_VENDOR_MEDIATEK,
|
|
||||||
SOC_VENDOR_EXYNOS,
|
|
||||||
SOC_VENDOR_KIRIN,
|
|
||||||
SOC_VENDOR_BROADCOM,
|
|
||||||
SOC_VENDOR_APPLE,
|
|
||||||
SOC_VENDOR_ALLWINNER,
|
|
||||||
SOC_VENDOR_ROCKCHIP
|
|
||||||
};
|
|
||||||
|
|
||||||
struct system_on_chip {
|
|
||||||
SOC soc_model;
|
|
||||||
VENDOR soc_vendor;
|
|
||||||
int32_t process;
|
|
||||||
char* soc_name;
|
|
||||||
char* raw_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct system_on_chip* get_soc(void);
|
struct system_on_chip* get_soc(void);
|
||||||
char* get_soc_name(struct system_on_chip* soc);
|
|
||||||
VENDOR get_soc_vendor(struct system_on_chip* soc);
|
|
||||||
char* get_str_process(struct system_on_chip* soc);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -288,7 +288,17 @@ enum {
|
|||||||
SOC_ALLWINNER_R58,
|
SOC_ALLWINNER_R58,
|
||||||
SOC_ALLWINNER_R328,
|
SOC_ALLWINNER_R328,
|
||||||
// ROCKCHIP
|
// ROCKCHIP
|
||||||
|
SOC_ROCKCHIP_3288,
|
||||||
|
SOC_ROCKCHIP_3229,
|
||||||
|
SOC_ROCKCHIP_3308,
|
||||||
|
SOC_ROCKCHIP_3318,
|
||||||
|
SOC_ROCKCHIP_3326,
|
||||||
|
SOC_ROCKCHIP_3328,
|
||||||
|
SOC_ROCKCHIP_3368,
|
||||||
SOC_ROCKCHIP_3399,
|
SOC_ROCKCHIP_3399,
|
||||||
|
SOC_ROCKCHIP_3566,
|
||||||
|
SOC_ROCKCHIP_3568,
|
||||||
|
SOC_ROCKCHIP_3588,
|
||||||
// UNKNOWN
|
// UNKNOWN
|
||||||
SOC_MODEL_UNKNOWN
|
SOC_MODEL_UNKNOWN
|
||||||
};
|
};
|
||||||
@@ -301,7 +311,7 @@ inline static VENDOR get_soc_vendor_from_soc(SOC soc) {
|
|||||||
else if(soc >= SOC_SNAPD_QSD8650 && soc <= SOC_SNAPD_SM8450) return SOC_VENDOR_SNAPDRAGON;
|
else if(soc >= SOC_SNAPD_QSD8650 && soc <= SOC_SNAPD_SM8450) return SOC_VENDOR_SNAPDRAGON;
|
||||||
else if(soc >= SOC_APPLE_M1 && soc <= SOC_APPLE_M2) return SOC_VENDOR_APPLE;
|
else if(soc >= SOC_APPLE_M1 && soc <= SOC_APPLE_M2) return SOC_VENDOR_APPLE;
|
||||||
else if(soc >= SOC_ALLWINNER_A10 && soc <= SOC_ALLWINNER_R328) return SOC_VENDOR_ALLWINNER;
|
else if(soc >= SOC_ALLWINNER_A10 && soc <= SOC_ALLWINNER_R328) return SOC_VENDOR_ALLWINNER;
|
||||||
else if(soc >= SOC_ROCKCHIP_3399 && soc <= SOC_ROCKCHIP_3399) return SOC_VENDOR_ROCKCHIP;
|
else if(soc >= SOC_ROCKCHIP_3288 && soc <= SOC_ROCKCHIP_3588) return SOC_VENDOR_ROCKCHIP;
|
||||||
return SOC_VENDOR_UNKNOWN;
|
return SOC_VENDOR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#include "midr.h"
|
#include "midr.h"
|
||||||
|
|
||||||
#define _PATH_DEVICETREE_MODEL "/sys/firmware/devicetree/base/model"
|
#define _PATH_DEVICETREE_MODEL "/sys/firmware/devicetree/base/model"
|
||||||
#define _PATH_CPUINFO "/proc/cpuinfo"
|
|
||||||
//#define _PATH_CPUINFO "cpuinfo_debug"
|
|
||||||
|
|
||||||
#define CPUINFO_CPU_IMPLEMENTER_STR "CPU implementer\t: "
|
#define CPUINFO_CPU_IMPLEMENTER_STR "CPU implementer\t: "
|
||||||
#define CPUINFO_CPU_ARCHITECTURE_STR "CPU architecture: "
|
#define CPUINFO_CPU_ARCHITECTURE_STR "CPU architecture: "
|
||||||
@@ -108,27 +106,6 @@ uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success) {
|
|||||||
return midr;
|
return midr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* get_field_from_cpuinfo(char* CPUINFO_FIELD) {
|
|
||||||
int filelen;
|
|
||||||
char* buf;
|
|
||||||
if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) {
|
|
||||||
printWarn("read_file: %s: %s:\n", _PATH_CPUINFO, strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* tmp1 = strstr(buf, CPUINFO_FIELD);
|
|
||||||
if(tmp1 == NULL) return NULL;
|
|
||||||
tmp1 = tmp1 + strlen(CPUINFO_FIELD);
|
|
||||||
char* tmp2 = strstr(tmp1, "\n");
|
|
||||||
|
|
||||||
int strlen = (1 + (tmp2-tmp1));
|
|
||||||
char* hardware = emalloc(sizeof(char) * strlen);
|
|
||||||
memset(hardware, 0, sizeof(char) * strlen);
|
|
||||||
strncpy(hardware, tmp1, tmp2-tmp1);
|
|
||||||
|
|
||||||
return hardware;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* get_hardware_from_cpuinfo(void) {
|
char* get_hardware_from_cpuinfo(void) {
|
||||||
return get_field_from_cpuinfo(CPUINFO_HARDWARE_STR);
|
return get_field_from_cpuinfo(CPUINFO_HARDWARE_STR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,29 +287,6 @@ $C1 ################@@@@@@##@@@@@@################ \
|
|||||||
$C1 ####################@@@@@@#################### \
|
$C1 ####################@@@@@@#################### \
|
||||||
$C1 ############################################## "
|
$C1 ############################################## "
|
||||||
|
|
||||||
#define ASCII_SIFIVE_L \
|
|
||||||
"$C1 ################################################### \
|
|
||||||
$C1 ###########@@@@@@@@@@@@@@@@@@@@@@@@@@@@############ \
|
|
||||||
$C1 ##########@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@########### \
|
|
||||||
$C1 #########@@@@@#######################@@@@########## \
|
|
||||||
$C1 ########@@@@@#########################@@@@######### \
|
|
||||||
$C1 #######@@@@@###########################@@@@######## \
|
|
||||||
$C1 ######@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@@####### \
|
|
||||||
$C1 #####@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@@@@###### \
|
|
||||||
$C1 ####@@@@@################################@@@@@##### \
|
|
||||||
$C1 ###@@@@@##################################@@@@@#### \
|
|
||||||
$C1 ##@@@@@####################################@@@@@### \
|
|
||||||
$C1 ##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#########@@@@### \
|
|
||||||
$C1 ##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@############@@@@### \
|
|
||||||
$C1 ####@@@@@#############@@@@@@@############@@@@@##### \
|
|
||||||
$C1 #######@@@@@@############@############@@@@@@####### \
|
|
||||||
$C1 ##########@@@@@@###################@@@@@@########## \
|
|
||||||
$C1 ##############@@@@@@###########@@@@@@############## \
|
|
||||||
$C1 #################@@@@@@#####@@@@@@################# \
|
|
||||||
$C1 ####################@@@@@@@@@@@#################### \
|
|
||||||
$C1 ########################@@@######################## \
|
|
||||||
$C1 ################################################### "
|
|
||||||
|
|
||||||
#define ASCII_STARFIVE \
|
#define ASCII_STARFIVE \
|
||||||
"$C1 # \
|
"$C1 # \
|
||||||
$C1 ########## \
|
$C1 ########## \
|
||||||
@@ -329,31 +306,6 @@ $C1 ######## ######## \
|
|||||||
$C1 ######### \
|
$C1 ######### \
|
||||||
$C1 # "
|
$C1 # "
|
||||||
|
|
||||||
#define ASCII_STARFIVE_L \
|
|
||||||
"$C1 ####### \
|
|
||||||
$C1 ################. \
|
|
||||||
$C1 ############ ########### \
|
|
||||||
$C1 ############ ##########. \
|
|
||||||
$C1 ############ # ###### \
|
|
||||||
$C1 ########### ##### ## \
|
|
||||||
$C1 #######. ########## \
|
|
||||||
$C1 ###### ### *########### \
|
|
||||||
$C1 ###### #######. ########## \
|
|
||||||
$C1 ######### ############ ###### \
|
|
||||||
$C1 ###########. ###########* # \
|
|
||||||
$C1 ############ ############ \
|
|
||||||
$C1 # ############. .########### \
|
|
||||||
$C1 ###### ########### ######### \
|
|
||||||
$C1 ########## .######, ##### \
|
|
||||||
$C1 ############ ##. #####. \
|
|
||||||
$C1 ######### ######## \
|
|
||||||
$C1 ## ##### ##########. \
|
|
||||||
$C1 ####### # ############ \
|
|
||||||
$C1 ########### ###########. \
|
|
||||||
$C1 ###########. ############ \
|
|
||||||
$C1 ################ \
|
|
||||||
$C1 ####### "
|
|
||||||
|
|
||||||
// --------------------- LONG LOGOS ------------------------- //
|
// --------------------- LONG LOGOS ------------------------- //
|
||||||
#define ASCII_AMD_L \
|
#define ASCII_AMD_L \
|
||||||
"$C1 \
|
"$C1 \
|
||||||
@@ -438,11 +390,59 @@ $C1 ############ ################## ######### #### ######### \
|
|||||||
$C1 \
|
$C1 \
|
||||||
$C1 ############ ################ ######### ## ######### "
|
$C1 ############ ################ ######### ## ######### "
|
||||||
|
|
||||||
|
#define ASCII_SIFIVE_L \
|
||||||
|
"$C1 ################################################### \
|
||||||
|
$C1 ###########@@@@@@@@@@@@@@@@@@@@@@@@@@@@############ \
|
||||||
|
$C1 ##########@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@########### \
|
||||||
|
$C1 #########@@@@@#######################@@@@########## \
|
||||||
|
$C1 ########@@@@@#########################@@@@######### \
|
||||||
|
$C1 #######@@@@@###########################@@@@######## \
|
||||||
|
$C1 ######@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@@####### \
|
||||||
|
$C1 #####@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@@@@###### \
|
||||||
|
$C1 ####@@@@@################################@@@@@##### \
|
||||||
|
$C1 ###@@@@@##################################@@@@@#### \
|
||||||
|
$C1 ##@@@@@####################################@@@@@### \
|
||||||
|
$C1 ##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#########@@@@### \
|
||||||
|
$C1 ##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@############@@@@### \
|
||||||
|
$C1 ####@@@@@#############@@@@@@@############@@@@@##### \
|
||||||
|
$C1 #######@@@@@@############@############@@@@@@####### \
|
||||||
|
$C1 ##########@@@@@@###################@@@@@@########## \
|
||||||
|
$C1 ##############@@@@@@###########@@@@@@############## \
|
||||||
|
$C1 #################@@@@@@#####@@@@@@################# \
|
||||||
|
$C1 ####################@@@@@@@@@@@#################### \
|
||||||
|
$C1 ########################@@@######################## \
|
||||||
|
$C1 ################################################### "
|
||||||
|
|
||||||
|
#define ASCII_STARFIVE_L \
|
||||||
|
"$C1 ####### \
|
||||||
|
$C1 ################. \
|
||||||
|
$C1 ############ ########### \
|
||||||
|
$C1 ############ ##########. \
|
||||||
|
$C1 ############ # ###### \
|
||||||
|
$C1 ########### ##### ## \
|
||||||
|
$C1 #######. ########## \
|
||||||
|
$C1 ###### ### *########### \
|
||||||
|
$C1 ###### #######. ########## \
|
||||||
|
$C1 ######### ############ ###### \
|
||||||
|
$C1 ###########. ###########* # \
|
||||||
|
$C1 ############ ############ \
|
||||||
|
$C1 # ############. .########### \
|
||||||
|
$C1 ###### ########### ######### \
|
||||||
|
$C1 ########## .######, ##### \
|
||||||
|
$C1 ############ ##. #####. \
|
||||||
|
$C1 ######### ######## \
|
||||||
|
$C1 ## ##### ##########. \
|
||||||
|
$C1 ####### # ############ \
|
||||||
|
$C1 ########### ###########. \
|
||||||
|
$C1 ###########. ############ \
|
||||||
|
$C1 ################ \
|
||||||
|
$C1 ####### "
|
||||||
|
|
||||||
typedef struct ascii_logo asciiL;
|
typedef struct ascii_logo asciiL;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------------------------------------+
|
||||||
// | LOGO | W | H | REPLACE | COLORS LOGO (>0 && <10) | COLORS TEXT (=2) |
|
// | LOGO | W | H | REPLACE | COLORS LOGO (>0 && <10) | COLORS TEXT (=2) |
|
||||||
// ------------------------------------------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------------------------------------+
|
||||||
asciiL logo_amd = { ASCII_AMD, 39, 15, false, {C_FG_WHITE, C_FG_GREEN}, {C_FG_WHITE, C_FG_GREEN} };
|
asciiL logo_amd = { ASCII_AMD, 39, 15, false, {C_FG_WHITE, C_FG_GREEN}, {C_FG_WHITE, C_FG_GREEN} };
|
||||||
asciiL logo_intel = { ASCII_INTEL, 48, 14, false, {C_FG_CYAN}, {C_FG_CYAN, C_FG_WHITE} };
|
asciiL logo_intel = { ASCII_INTEL, 48, 14, false, {C_FG_CYAN}, {C_FG_CYAN, C_FG_WHITE} };
|
||||||
asciiL logo_intel_new = { ASCII_INTEL_NEW, 51, 9, false, {C_FG_CYAN}, {C_FG_CYAN, C_FG_WHITE} };
|
asciiL logo_intel_new = { ASCII_INTEL_NEW, 51, 9, false, {C_FG_CYAN}, {C_FG_CYAN, C_FG_WHITE} };
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ enum {
|
|||||||
HV_VENDOR_VMWARE,
|
HV_VENDOR_VMWARE,
|
||||||
HV_VENDOR_XEN,
|
HV_VENDOR_XEN,
|
||||||
HV_VENDOR_PARALLELS,
|
HV_VENDOR_PARALLELS,
|
||||||
|
HV_VENDOR_PHYP,
|
||||||
HV_VENDOR_INVALID
|
HV_VENDOR_INVALID
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GIT_FULL_VERSION
|
#ifndef GIT_FULL_VERSION
|
||||||
static const char* VERSION = "1.03";
|
static const char* VERSION = "1.04";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
@@ -40,11 +40,13 @@ void print_help(char *argv[]) {
|
|||||||
printf(" -%c, --%s %*s Print cpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
printf(" -%c, --%s %*s Print cpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
||||||
|
|
||||||
printf("\nCOLORS: \n");
|
printf("\nCOLORS: \n");
|
||||||
printf(" * \"intel\": Use Intel default color scheme \n");
|
printf(" * \"intel\": Use Intel color scheme \n");
|
||||||
printf(" * \"amd\": Use AMD default color scheme \n");
|
printf(" * \"intel-new\": Use Intel (new logo) color scheme \n");
|
||||||
printf(" * \"ibm\", Use IBM default color scheme \n");
|
printf(" * \"amd\": Use AMD color scheme \n");
|
||||||
printf(" * \"arm\": Use ARM default color scheme \n");
|
printf(" * \"ibm\", Use IBM color scheme \n");
|
||||||
printf(" * \"sifive\": Use SiFive default color scheme \n");
|
printf(" * \"arm\": Use ARM color scheme \n");
|
||||||
|
printf(" * \"rockchip\": Use ARM color scheme \n");
|
||||||
|
printf(" * \"sifive\": Use SiFive color scheme \n");
|
||||||
printf(" * custom: If the argument of --color does not match any of the previous strings, a custom scheme can be specified.\n");
|
printf(" * custom: If the argument of --color does not match any of the previous strings, a custom scheme can be specified.\n");
|
||||||
printf(" 5 colors must be given in RGB with the format: R,G,B:R,G,B:...\n");
|
printf(" 5 colors must be given in RGB with the format: R,G,B:R,G,B:...\n");
|
||||||
printf(" The first 3 colors are the CPU art color and the next 2 colors are the text colors\n");
|
printf(" The first 3 colors are the CPU art color and the next 2 colors are the text colors\n");
|
||||||
@@ -74,8 +76,10 @@ void print_help(char *argv[]) {
|
|||||||
printf("\nNOTE: \n");
|
printf("\nNOTE: \n");
|
||||||
printf(" Peak performance information is NOT accurate. cpufetch computes peak performance using the max\n");
|
printf(" Peak performance information is NOT accurate. cpufetch computes peak performance using the max\n");
|
||||||
printf(" frequency of the CPU. However, to compute the peak performance, you need to know the frequency of the\n");
|
printf(" frequency of the CPU. However, to compute the peak performance, you need to know the frequency of the\n");
|
||||||
printf(" CPU running AVX code. This value is not be fetched by cpufetch since it depends on each specific CPU.\n");
|
printf(" CPU running AVX code. By default, this value is not fetched by cpufetch, but you can use the\n");
|
||||||
printf(" To correctly measure peak performance, see: https://github.com/Dr-Noob/peakperf\n");
|
printf(" --accurate-pp option, which will measure the AVX frequency and show a more precise estimation\n");
|
||||||
|
printf(" (this option is only available in x86 architectures).\n");
|
||||||
|
printf(" To precisely measure peak performance, see: https://github.com/Dr-Noob/peakperf\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@@ -116,8 +120,10 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(print_cpufetch(cpu, get_style(), get_colors(), show_full_cpu_name()))
|
if(print_cpufetch(cpu, get_style(), get_colors(), show_full_cpu_name())) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "../arm/uarch.h"
|
#include "../arm/uarch.h"
|
||||||
#include "../arm/midr.h"
|
#include "../arm/midr.h"
|
||||||
#include "../arm/soc.h"
|
#include "../arm/soc.h"
|
||||||
|
#include "../common/soc.h"
|
||||||
#elif ARCH_RISCV
|
#elif ARCH_RISCV
|
||||||
#include "../riscv/riscv.h"
|
#include "../riscv/riscv.h"
|
||||||
#include "../riscv/uarch.h"
|
#include "../riscv/uarch.h"
|
||||||
@@ -677,11 +678,14 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
|
|
||||||
// Step 2. Set attributes
|
// Step 2. Set attributes
|
||||||
if(cpu_name != NULL) {
|
if(cpu_name != NULL) {
|
||||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
setAttribute(art, ATTRIBUTE_NAME, cpu_name);
|
||||||
}
|
}
|
||||||
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
||||||
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
|
if(cpu->hv->present) {
|
||||||
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
|
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
|
||||||
|
}
|
||||||
|
setAttribute(art, ATTRIBUTE_TECHNOLOGY, manufacturing_process);
|
||||||
|
setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency);
|
||||||
uint32_t socket_num = get_nsockets(cpu->topo);
|
uint32_t socket_num = get_nsockets(cpu->topo);
|
||||||
if (socket_num > 1) {
|
if (socket_num > 1) {
|
||||||
setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
|
setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
|
||||||
@@ -689,16 +693,16 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
setAttribute(art, ATTRIBUTE_NCORES_DUAL, n_cores_dual);
|
setAttribute(art, ATTRIBUTE_NCORES_DUAL, n_cores_dual);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setAttribute(art,ATTRIBUTE_NCORES, n_cores);
|
setAttribute(art, ATTRIBUTE_NCORES, n_cores);
|
||||||
}
|
}
|
||||||
setAttribute(art,ATTRIBUTE_ALTIVEC, altivec);
|
setAttribute(art, ATTRIBUTE_ALTIVEC, altivec);
|
||||||
setAttribute(art,ATTRIBUTE_L1i,l1i);
|
setAttribute(art, ATTRIBUTE_L1i, l1i);
|
||||||
setAttribute(art,ATTRIBUTE_L1d,l1d);
|
setAttribute(art, ATTRIBUTE_L1d, l1d);
|
||||||
setAttribute(art,ATTRIBUTE_L2,l2);
|
setAttribute(art, ATTRIBUTE_L2, l2);
|
||||||
if(l3 != NULL) {
|
if(l3 != NULL) {
|
||||||
setAttribute(art,ATTRIBUTE_L3,l3);
|
setAttribute(art, ATTRIBUTE_L3, l3);
|
||||||
}
|
}
|
||||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
setAttribute(art, ATTRIBUTE_PEAK, pp);
|
||||||
|
|
||||||
// Step 3. Print output
|
// Step 3. Print output
|
||||||
const char** attribute_fields = ATTRIBUTE_FIELDS;
|
const char** attribute_fields = ATTRIBUTE_FIELDS;
|
||||||
@@ -839,26 +843,17 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
char* manufacturing_process = get_str_process(cpu->soc);
|
char* manufacturing_process = get_str_process(cpu->soc);
|
||||||
char* soc_name = get_soc_name(cpu->soc);
|
char* soc_name = get_soc_name(cpu->soc);
|
||||||
char* features = get_str_features(cpu);
|
char* features = get_str_features(cpu);
|
||||||
setAttribute(art,ATTRIBUTE_SOC,soc_name);
|
setAttribute(art, ATTRIBUTE_SOC, soc_name);
|
||||||
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
|
setAttribute(art, ATTRIBUTE_TECHNOLOGY, manufacturing_process);
|
||||||
|
|
||||||
if(cpu->num_cpus == 1) {
|
if(cpu->num_cpus == 1) {
|
||||||
char* uarch = get_str_uarch(cpu);
|
char* uarch = get_str_uarch(cpu);
|
||||||
char* max_frequency = get_str_freq(cpu->freq);
|
char* max_frequency = get_str_freq(cpu->freq);
|
||||||
char* n_cores = get_str_topology(cpu, cpu->topo, false);
|
char* n_cores = get_str_topology(cpu, cpu->topo, false);
|
||||||
/*
|
|
||||||
* char* l1i = get_str_l1i(cpu->cach);
|
|
||||||
* char* l1d = get_str_l1d(cpu->cach);
|
|
||||||
* char* l2 = get_str_l2(cpu->cach);
|
|
||||||
* char* l3 = get_str_l3(cpu->cach);
|
|
||||||
* Do not setAttribute for caches.
|
|
||||||
* Cache functionality may be implemented
|
|
||||||
* in the future
|
|
||||||
*/
|
|
||||||
|
|
||||||
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
||||||
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
|
setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency);
|
||||||
setAttribute(art,ATTRIBUTE_NCORES,n_cores);
|
setAttribute(art, ATTRIBUTE_NCORES, n_cores);
|
||||||
if(features != NULL) {
|
if(features != NULL) {
|
||||||
setAttribute(art, ATTRIBUTE_FEATURES, features);
|
setAttribute(art, ATTRIBUTE_FEATURES, features);
|
||||||
}
|
}
|
||||||
@@ -869,17 +864,8 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
char* uarch = get_str_uarch(ptr);
|
char* uarch = get_str_uarch(ptr);
|
||||||
char* max_frequency = get_str_freq(ptr->freq);
|
char* max_frequency = get_str_freq(ptr->freq);
|
||||||
char* n_cores = get_str_topology(ptr, ptr->topo, false);
|
char* n_cores = get_str_topology(ptr, ptr->topo, false);
|
||||||
/*
|
|
||||||
* char* l1i = get_str_l1i(cpu->cach);
|
|
||||||
* char* l1d = get_str_l1d(cpu->cach);
|
|
||||||
* char* l2 = get_str_l2(cpu->cach);
|
|
||||||
* char* l3 = get_str_l3(cpu->cach);
|
|
||||||
* Do not setAttribute for caches.
|
|
||||||
* Cache functionality may be implemented
|
|
||||||
* in the future
|
|
||||||
*/
|
|
||||||
|
|
||||||
char* cpu_num = emalloc(sizeof(char) * 9);
|
char* cpu_num = emalloc(sizeof(char) * 9);
|
||||||
|
|
||||||
sprintf(cpu_num, "CPU %d:", i+1);
|
sprintf(cpu_num, "CPU %d:", i+1);
|
||||||
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
|
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
|
||||||
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
||||||
@@ -891,7 +877,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* pp = get_str_peak_performance(cpu->peak_performance);
|
char* pp = get_str_peak_performance(cpu->peak_performance);
|
||||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
setAttribute(art, ATTRIBUTE_PEAK, pp);
|
||||||
if(cpu->hv->present) {
|
if(cpu->hv->present) {
|
||||||
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
|
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
|
||||||
}
|
}
|
||||||
@@ -1035,29 +1021,18 @@ bool print_cpufetch_riscv(struct cpuInfo* cpu, STYLE s, struct color** cs, struc
|
|||||||
char* extensions = get_str_extensions(cpu);
|
char* extensions = get_str_extensions(cpu);
|
||||||
char* max_frequency = get_str_freq(cpu->freq);
|
char* max_frequency = get_str_freq(cpu->freq);
|
||||||
char* n_cores = get_str_topology(cpu, cpu->topo);
|
char* n_cores = get_str_topology(cpu, cpu->topo);
|
||||||
|
|
||||||
/*char* l1i = get_str_l1i(cpu->cach);
|
|
||||||
char* l1d = get_str_l1d(cpu->cach);
|
|
||||||
char* l2 = get_str_l2(cpu->cach);
|
|
||||||
char* l3 = get_str_l3(cpu->cach);*/
|
|
||||||
char* pp = get_str_peak_performance(cpu->peak_performance);
|
char* pp = get_str_peak_performance(cpu->peak_performance);
|
||||||
|
|
||||||
// Step 2. Set attributes
|
// Step 2. Set attributes
|
||||||
setAttribute(art,ATTRIBUTE_SOC,soc_name);
|
setAttribute(art, ATTRIBUTE_SOC, soc_name);
|
||||||
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
|
setAttribute(art, ATTRIBUTE_TECHNOLOGY, manufacturing_process);
|
||||||
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
||||||
setAttribute(art,ATTRIBUTE_NCORES, n_cores);
|
setAttribute(art, ATTRIBUTE_NCORES, n_cores);
|
||||||
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
|
setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency);
|
||||||
if(extensions != NULL) {
|
if(extensions != NULL) {
|
||||||
setAttribute(art,ATTRIBUTE_EXTENSIONS,extensions);
|
setAttribute(art, ATTRIBUTE_EXTENSIONS, extensions);
|
||||||
}
|
}
|
||||||
/*setAttribute(art,ATTRIBUTE_L1i,l1i);
|
setAttribute(art, ATTRIBUTE_PEAK, pp);
|
||||||
setAttribute(art,ATTRIBUTE_L1d,l1d);
|
|
||||||
setAttribute(art,ATTRIBUTE_L2,l2);
|
|
||||||
if(l3 != NULL) {
|
|
||||||
setAttribute(art,ATTRIBUTE_L3,l3);
|
|
||||||
}*/
|
|
||||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
|
||||||
|
|
||||||
// Step 3. Print output
|
// Step 3. Print output
|
||||||
const char** attribute_fields = ATTRIBUTE_FIELDS;
|
const char** attribute_fields = ATTRIBUTE_FIELDS;
|
||||||
|
|||||||
88
src/common/soc.c
Normal file
88
src/common/soc.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "soc.h"
|
||||||
|
#ifdef ARCH_ARM
|
||||||
|
#include "../arm/socs.h"
|
||||||
|
#elif ARCH_RISCV
|
||||||
|
#include "../riscv/socs.h"
|
||||||
|
#endif
|
||||||
|
#include "udev.h"
|
||||||
|
#include "../common/global.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static char* soc_trademark_string[] = {
|
||||||
|
// ARM
|
||||||
|
[SOC_VENDOR_SNAPDRAGON] = "Snapdragon ",
|
||||||
|
[SOC_VENDOR_MEDIATEK] = "MediaTek ",
|
||||||
|
[SOC_VENDOR_EXYNOS] = "Exynos ",
|
||||||
|
[SOC_VENDOR_KIRIN] = "Kirin ",
|
||||||
|
[SOC_VENDOR_BROADCOM] = "Broadcom BCM",
|
||||||
|
[SOC_VENDOR_APPLE] = "Apple ",
|
||||||
|
[SOC_VENDOR_ROCKCHIP] = "Rockchip ",
|
||||||
|
// RISC-V
|
||||||
|
[SOC_VENDOR_SIFIVE] = "SiFive ",
|
||||||
|
[SOC_VENDOR_STARFIVE] = "StarFive ",
|
||||||
|
// ARM & RISC-V
|
||||||
|
[SOC_VENDOR_ALLWINNER] = "Allwinner "
|
||||||
|
};
|
||||||
|
|
||||||
|
VENDOR get_soc_vendor(struct system_on_chip* soc) {
|
||||||
|
return soc->soc_vendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* get_str_process(struct system_on_chip* soc) {
|
||||||
|
char* str;
|
||||||
|
|
||||||
|
if(soc->process == UNKNOWN) {
|
||||||
|
str = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||||
|
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str = emalloc(sizeof(char) * 5);
|
||||||
|
memset(str, 0, sizeof(char) * 5);
|
||||||
|
snprintf(str, 5, "%dnm", soc->process);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* get_soc_name(struct system_on_chip* soc) {
|
||||||
|
if(soc->soc_model == SOC_MODEL_UNKNOWN)
|
||||||
|
return soc->raw_name;
|
||||||
|
return soc->soc_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_soc(struct system_on_chip* soc, char* soc_name, SOC soc_model, int32_t process) {
|
||||||
|
soc->soc_model = soc_model;
|
||||||
|
soc->soc_vendor = get_soc_vendor_from_soc(soc_model);
|
||||||
|
soc->process = process;
|
||||||
|
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
|
||||||
|
printBug("fill_soc: soc->soc_vendor == SOC_VENDOR_UNKOWN");
|
||||||
|
// If we fall here there is a bug in socs.h
|
||||||
|
// Reset everything to avoid segfault
|
||||||
|
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
|
||||||
|
soc->soc_model = SOC_MODEL_UNKNOWN;
|
||||||
|
soc->process = UNKNOWN;
|
||||||
|
soc->raw_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||||
|
snprintf(soc->raw_name, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
soc->process = process;
|
||||||
|
int len = strlen(soc_name) + strlen(soc_trademark_string[soc->soc_vendor]) + 1;
|
||||||
|
soc->soc_name = emalloc(sizeof(char) * len);
|
||||||
|
memset(soc->soc_name, 0, sizeof(char) * len);
|
||||||
|
sprintf(soc->soc_name, "%s%s", soc_trademark_string[soc->soc_vendor], soc_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool match_soc(struct system_on_chip* soc, char* raw_name, char* expected_name, char* soc_name, SOC soc_model, int32_t process) {
|
||||||
|
int len1 = strlen(raw_name);
|
||||||
|
int len2 = strlen(expected_name);
|
||||||
|
int len = min(len1, len2);
|
||||||
|
|
||||||
|
if(strncmp(raw_name, expected_name, len) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fill_soc(soc, soc_name, soc_model, process);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/common/soc.h
Normal file
52
src/common/soc.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#ifndef __SOC__
|
||||||
|
#define __SOC__
|
||||||
|
|
||||||
|
// NOTE:
|
||||||
|
// soc.c/soc.h are used by
|
||||||
|
// ARM and RISC-V backends
|
||||||
|
|
||||||
|
#include "../common/cpu.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define UNKNOWN -1
|
||||||
|
|
||||||
|
typedef int32_t SOC;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SOC_VENDOR_UNKNOWN,
|
||||||
|
// ARM
|
||||||
|
SOC_VENDOR_SNAPDRAGON,
|
||||||
|
SOC_VENDOR_MEDIATEK,
|
||||||
|
SOC_VENDOR_EXYNOS,
|
||||||
|
SOC_VENDOR_KIRIN,
|
||||||
|
SOC_VENDOR_BROADCOM,
|
||||||
|
SOC_VENDOR_APPLE,
|
||||||
|
SOC_VENDOR_ROCKCHIP,
|
||||||
|
// RISC-V
|
||||||
|
SOC_VENDOR_SIFIVE,
|
||||||
|
SOC_VENDOR_STARFIVE,
|
||||||
|
// ARM & RISC-V
|
||||||
|
SOC_VENDOR_ALLWINNER
|
||||||
|
};
|
||||||
|
|
||||||
|
struct system_on_chip {
|
||||||
|
SOC soc_model;
|
||||||
|
VENDOR soc_vendor;
|
||||||
|
int32_t process;
|
||||||
|
char* soc_name;
|
||||||
|
char* raw_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct system_on_chip* get_soc(void);
|
||||||
|
char* get_soc_name(struct system_on_chip* soc);
|
||||||
|
VENDOR get_soc_vendor(struct system_on_chip* soc);
|
||||||
|
bool match_soc(struct system_on_chip* soc, char* raw_name, char* expected_name, char* soc_name, SOC soc_model, int32_t process);
|
||||||
|
char* get_str_process(struct system_on_chip* soc);
|
||||||
|
void fill_soc(struct system_on_chip* soc, char* soc_name, SOC soc_model, int32_t process);
|
||||||
|
|
||||||
|
#define SOC_START if (false) {}
|
||||||
|
#define SOC_EQ(raw_name, expected_name, soc_name, soc_model, soc, process) \
|
||||||
|
else if (match_soc(soc, raw_name, expected_name, soc_name, soc_model, process)) return true;
|
||||||
|
#define SOC_END else { return false; }
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -129,6 +129,27 @@ long get_cache_size_from_file(char* path) {
|
|||||||
return ret * 1024;
|
return ret * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* get_field_from_cpuinfo(char* CPUINFO_FIELD) {
|
||||||
|
int filelen;
|
||||||
|
char* buf;
|
||||||
|
if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) {
|
||||||
|
printWarn("read_file: %s: %s:\n", _PATH_CPUINFO, strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* tmp1 = strstr(buf, CPUINFO_FIELD);
|
||||||
|
if(tmp1 == NULL) return NULL;
|
||||||
|
tmp1 = tmp1 + strlen(CPUINFO_FIELD);
|
||||||
|
char* tmp2 = strstr(tmp1, "\n");
|
||||||
|
|
||||||
|
int strlen = (1 + (tmp2-tmp1));
|
||||||
|
char* hardware = emalloc(sizeof(char) * strlen);
|
||||||
|
memset(hardware, 0, sizeof(char) * strlen);
|
||||||
|
strncpy(hardware, tmp1, tmp2-tmp1);
|
||||||
|
|
||||||
|
return hardware;
|
||||||
|
}
|
||||||
|
|
||||||
long get_max_freq_from_file(uint32_t core) {
|
long get_max_freq_from_file(uint32_t core) {
|
||||||
char path[_PATH_FREQUENCY_MAX_LEN];
|
char path[_PATH_FREQUENCY_MAX_LEN];
|
||||||
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MAX);
|
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MAX);
|
||||||
@@ -178,7 +199,13 @@ bool maps_equal(uint32_t* map1, uint32_t* map2, int n) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_num_caches_from_files(char** paths, int num_paths) {
|
// Generic function to count the number of distinct
|
||||||
|
// elements in the list of files passed in char** paths.
|
||||||
|
// An element can be potentially anything.
|
||||||
|
// We use this function to count:
|
||||||
|
// - The number of caches
|
||||||
|
// - The number of sockets
|
||||||
|
int get_num_elements_from_files(char** paths, int num_paths) {
|
||||||
int filelen;
|
int filelen;
|
||||||
char* buf;
|
char* buf;
|
||||||
char* tmpbuf;
|
char* tmpbuf;
|
||||||
@@ -193,10 +220,10 @@ int get_num_caches_from_files(char** paths, int num_paths) {
|
|||||||
num_bitmasks += (buf[i] == ',');
|
num_bitmasks += (buf[i] == ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Read cpu_shared_map from every core
|
// 2. Read map from every core
|
||||||
uint32_t** shared_maps = emalloc(sizeof(uint32_t *) * num_paths);
|
uint32_t** maps = emalloc(sizeof(uint32_t *) * num_paths);
|
||||||
for(int i=0; i < num_paths; i++) {
|
for(int i=0; i < num_paths; i++) {
|
||||||
shared_maps[i] = emalloc(sizeof(uint32_t) * num_bitmasks);
|
maps[i] = emalloc(sizeof(uint32_t) * num_bitmasks);
|
||||||
|
|
||||||
if((buf = read_file(paths[i], &filelen)) == NULL) {
|
if((buf = read_file(paths[i], &filelen)) == NULL) {
|
||||||
printWarn("Could not open '%s'", paths[i]);
|
printWarn("Could not open '%s'", paths[i]);
|
||||||
@@ -221,35 +248,43 @@ int get_num_caches_from_files(char** paths, int num_paths) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_maps[i][j] = (uint32_t) ret;
|
maps[i][j] = (uint32_t) ret;
|
||||||
buf = commaend + 1;
|
buf = commaend + 1;
|
||||||
free(tmpbuf);
|
free(tmpbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Count number of different masks; this is the number of caches
|
// 2. Count number of different masks; this is the number of elements
|
||||||
int num_caches = 0;
|
int num_elements = 0;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
uint32_t** unique_shared_maps = emalloc(sizeof(uint32_t *) * num_paths);
|
uint32_t** unique_maps = emalloc(sizeof(uint32_t *) * num_paths);
|
||||||
for(int i=0; i < num_paths; i++) {
|
for(int i=0; i < num_paths; i++) {
|
||||||
unique_shared_maps[i] = emalloc(sizeof(uint32_t) * num_bitmasks);
|
unique_maps[i] = emalloc(sizeof(uint32_t) * num_bitmasks);
|
||||||
for(int j=0; j < num_bitmasks; j++) {
|
for(int j=0; j < num_bitmasks; j++) {
|
||||||
unique_shared_maps[i][j] = 0;
|
unique_maps[i][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i < num_paths; i++) {
|
for(int i=0; i < num_paths; i++) {
|
||||||
for(int j=0; j < num_paths && !found; j++) {
|
for(int j=0; j < num_paths && !found; j++) {
|
||||||
if(maps_equal(shared_maps[i], unique_shared_maps[j], num_bitmasks)) found = true;
|
if(maps_equal(maps[i], unique_maps[j], num_bitmasks)) found = true;
|
||||||
}
|
}
|
||||||
if(!found) {
|
if(!found) {
|
||||||
add_shared_map(shared_maps, i, unique_shared_maps, num_caches, num_bitmasks);
|
add_shared_map(maps, i, unique_maps, num_elements, num_bitmasks);
|
||||||
num_caches++;
|
num_elements++;
|
||||||
}
|
}
|
||||||
found = false;
|
found = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_caches;
|
return num_elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_num_caches_from_files(char** paths, int num_paths) {
|
||||||
|
return get_num_elements_from_files(paths, num_paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_num_sockets_from_files(char** paths, int num_paths) {
|
||||||
|
return get_num_elements_from_files(paths, num_paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_num_caches_by_level(struct cpuInfo* cpu, uint32_t level) {
|
int get_num_caches_by_level(struct cpuInfo* cpu, uint32_t level) {
|
||||||
@@ -278,3 +313,38 @@ int get_num_caches_by_level(struct cpuInfo* cpu, uint32_t level) {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_num_sockets_package_cpus(struct topology* topo) {
|
||||||
|
// Get number of sockets using
|
||||||
|
// /sys/devices/system/cpu/cpu*/topology/package_cpus
|
||||||
|
|
||||||
|
char** paths = emalloc(sizeof(char *) * topo->total_cores);
|
||||||
|
|
||||||
|
for(int i=0; i < topo->total_cores; i++) {
|
||||||
|
paths[i] = emalloc(sizeof(char) * _PATH_PACKAGE_MAX_LEN);
|
||||||
|
sprintf(paths[i], "%s%s/cpu%d%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, _PATH_TOPO_PACKAGE_CPUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = get_num_sockets_from_files(paths, topo->total_cores);
|
||||||
|
|
||||||
|
for(int i=0; i < topo->total_cores; i++)
|
||||||
|
free(paths[i]);
|
||||||
|
free(paths);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inspired in is_devtree_compatible from lscpu
|
||||||
|
bool is_devtree_compatible(char* str) {
|
||||||
|
int filelen;
|
||||||
|
char* buf;
|
||||||
|
if((buf = read_file("/proc/device-tree/compatible", &filelen)) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* tmp;
|
||||||
|
if((tmp = strstr(buf, str)) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
||||||
|
#define _PATH_CPUINFO "/proc/cpuinfo"
|
||||||
#define _PATH_SYS_SYSTEM "/sys/devices/system"
|
#define _PATH_SYS_SYSTEM "/sys/devices/system"
|
||||||
#define _PATH_SYS_CPU "/cpu"
|
#define _PATH_SYS_CPU "/cpu"
|
||||||
#define _PATH_FREQUENCY "/cpufreq"
|
#define _PATH_FREQUENCY "/cpufreq"
|
||||||
@@ -24,9 +25,11 @@
|
|||||||
#define _PATH_CACHE_SIZE "/size"
|
#define _PATH_CACHE_SIZE "/size"
|
||||||
#define _PATH_CACHE_SHARED_MAP "/shared_cpu_map"
|
#define _PATH_CACHE_SHARED_MAP "/shared_cpu_map"
|
||||||
#define _PATH_CPUS_PRESENT _PATH_SYS_SYSTEM _PATH_SYS_CPU "/present"
|
#define _PATH_CPUS_PRESENT _PATH_SYS_SYSTEM _PATH_SYS_CPU "/present"
|
||||||
|
#define _PATH_TOPO_PACKAGE_CPUS "/topology/package_cpus"
|
||||||
|
|
||||||
#define _PATH_FREQUENCY_MAX_LEN 100
|
#define _PATH_FREQUENCY_MAX_LEN 100
|
||||||
#define _PATH_CACHE_MAX_LEN 200
|
#define _PATH_CACHE_MAX_LEN 200
|
||||||
|
#define _PATH_PACKAGE_MAX_LEN 200
|
||||||
|
|
||||||
char* read_file(char* path, int* len);
|
char* read_file(char* path, int* len);
|
||||||
long get_max_freq_from_file(uint32_t core);
|
long get_max_freq_from_file(uint32_t core);
|
||||||
@@ -36,6 +39,9 @@ long get_l1d_cache_size(uint32_t core);
|
|||||||
long get_l2_cache_size(uint32_t core);
|
long get_l2_cache_size(uint32_t core);
|
||||||
long get_l3_cache_size(uint32_t core);
|
long get_l3_cache_size(uint32_t core);
|
||||||
int get_num_caches_by_level(struct cpuInfo* cpu, uint32_t level);
|
int get_num_caches_by_level(struct cpuInfo* cpu, uint32_t level);
|
||||||
|
int get_num_sockets_package_cpus(struct topology* topo);
|
||||||
int get_ncores_from_cpuinfo(void);
|
int get_ncores_from_cpuinfo(void);
|
||||||
|
char* get_field_from_cpuinfo(char* CPUINFO_FIELD);
|
||||||
|
bool is_devtree_compatible(char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,6 +11,17 @@
|
|||||||
#include "../common/udev.h"
|
#include "../common/udev.h"
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
|
|
||||||
|
static char *hv_vendors_name[] = {
|
||||||
|
[HV_VENDOR_KVM] = "KVM",
|
||||||
|
[HV_VENDOR_QEMU] = "QEMU",
|
||||||
|
[HV_VENDOR_HYPERV] = "Microsoft Hyper-V",
|
||||||
|
[HV_VENDOR_VMWARE] = "VMware",
|
||||||
|
[HV_VENDOR_XEN] = "Xen",
|
||||||
|
[HV_VENDOR_PARALLELS] = "Parallels",
|
||||||
|
[HV_VENDOR_PHYP] = "pHyp",
|
||||||
|
[HV_VENDOR_INVALID] = STRING_UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
||||||
struct cache* cach = emalloc(sizeof(struct cache));
|
struct cache* cach = emalloc(sizeof(struct cache));
|
||||||
init_cache_struct(cach);
|
init_cache_struct(cach);
|
||||||
@@ -63,12 +74,17 @@ struct topology* get_topology_info(struct cache* cach) {
|
|||||||
printWarn("fill_core_ids_from_sys failed, output may be incomplete/invalid");
|
printWarn("fill_core_ids_from_sys failed, output may be incomplete/invalid");
|
||||||
for(int i=0; i < topo->total_cores; i++) core_ids[i] = 0;
|
for(int i=0; i < topo->total_cores; i++) core_ids[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fill_package_ids_from_sys(package_ids, topo->total_cores)) {
|
if(!fill_package_ids_from_sys(package_ids, topo->total_cores)) {
|
||||||
printWarn("fill_package_ids_from_sys failed, output may be incomplete/invalid");
|
printWarn("fill_package_ids_from_sys failed, output may be incomplete/invalid");
|
||||||
for(int i=0; i < topo->total_cores; i++) package_ids[i] = 0;
|
for(int i=0; i < topo->total_cores; i++) package_ids[i] = 0;
|
||||||
|
// fill_package_ids_from_sys failed, use a
|
||||||
|
// more sophisticated wat to find the number of sockets
|
||||||
|
topo->sockets = get_num_sockets_package_cpus(topo);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// 2. Socket detection
|
// fill_package_ids_from_sys succeeded, use the
|
||||||
|
// traditional socket detection algorithm
|
||||||
int *package_ids_count = emalloc(sizeof(int) * topo->total_cores);
|
int *package_ids_count = emalloc(sizeof(int) * topo->total_cores);
|
||||||
for(int i=0; i < topo->total_cores; i++) {
|
for(int i=0; i < topo->total_cores; i++) {
|
||||||
package_ids_count[i] = 0;
|
package_ids_count[i] = 0;
|
||||||
@@ -81,6 +97,8 @@ struct topology* get_topology_info(struct cache* cach) {
|
|||||||
topo->sockets++;
|
topo->sockets++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(package_ids_count);
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Physical cores detection
|
// 3. Physical cores detection
|
||||||
int *core_ids_unified = emalloc(sizeof(int) * topo->total_cores);
|
int *core_ids_unified = emalloc(sizeof(int) * topo->total_cores);
|
||||||
@@ -105,7 +123,6 @@ struct topology* get_topology_info(struct cache* cach) {
|
|||||||
|
|
||||||
free(core_ids);
|
free(core_ids);
|
||||||
free(package_ids);
|
free(package_ids);
|
||||||
free(package_ids_count);
|
|
||||||
free(core_ids_unified);
|
free(core_ids_unified);
|
||||||
|
|
||||||
return topo;
|
return topo;
|
||||||
@@ -129,6 +146,12 @@ struct frequency* get_frequency_info(void) {
|
|||||||
freq->max = get_max_freq_from_file(0);
|
freq->max = get_max_freq_from_file(0);
|
||||||
freq->base = get_min_freq_from_file(0);
|
freq->base = get_min_freq_from_file(0);
|
||||||
|
|
||||||
|
if(freq->max == UNKNOWN_DATA) {
|
||||||
|
// If we are unable to find it in the
|
||||||
|
// standard path, try /proc/cpuinfo
|
||||||
|
freq->max = get_frequency_from_cpuinfo();
|
||||||
|
}
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +181,28 @@ int64_t get_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t
|
|||||||
return flops;
|
return flops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct hypervisor* get_hp_info(void) {
|
||||||
|
struct hypervisor* hv = emalloc(sizeof(struct hypervisor));
|
||||||
|
hv->present = false;
|
||||||
|
|
||||||
|
// Weird heuristic found in lscpu:
|
||||||
|
// https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-virt.c
|
||||||
|
if(access("/proc" _PATH_DT_IBM_PARTIT_NAME, F_OK) == 0 &&
|
||||||
|
access("/proc" _PATH_DT_HMC_MANAGED, F_OK) == 0 &&
|
||||||
|
access("/proc" _PATH_DT_QEMU_WIDTH, F_OK) != 0) {
|
||||||
|
hv->present = true;
|
||||||
|
hv->hv_vendor = HV_VENDOR_PHYP;
|
||||||
|
}
|
||||||
|
else if(is_devtree_compatible("qemu,pseries")) {
|
||||||
|
hv->present = true;
|
||||||
|
hv->hv_vendor = HV_VENDOR_QEMU;
|
||||||
|
}
|
||||||
|
|
||||||
|
hv->hv_name = hv_vendors_name[hv->hv_vendor];
|
||||||
|
|
||||||
|
return hv;
|
||||||
|
}
|
||||||
|
|
||||||
struct cpuInfo* get_cpu_info(void) {
|
struct cpuInfo* get_cpu_info(void) {
|
||||||
struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo));
|
struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo));
|
||||||
struct features* feat = emalloc(sizeof(struct features));
|
struct features* feat = emalloc(sizeof(struct features));
|
||||||
@@ -172,8 +217,11 @@ struct cpuInfo* get_cpu_info(void) {
|
|||||||
char* path = emalloc(sizeof(char) * (strlen(_PATH_DT) + strlen(_PATH_DT_PART) + 1));
|
char* path = emalloc(sizeof(char) * (strlen(_PATH_DT) + strlen(_PATH_DT_PART) + 1));
|
||||||
sprintf(path, "%s%s", _PATH_DT, _PATH_DT_PART);
|
sprintf(path, "%s%s", _PATH_DT, _PATH_DT_PART);
|
||||||
|
|
||||||
cpu->cpu_name = read_file(path, &len);
|
if((cpu->cpu_name = read_file(path, &len)) == NULL) {
|
||||||
|
printWarn("Could not open '%s'", path);
|
||||||
|
}
|
||||||
cpu->pvr = mfpvr();
|
cpu->pvr = mfpvr();
|
||||||
|
cpu->hv = get_hp_info();
|
||||||
cpu->arch = get_cpu_uarch(cpu);
|
cpu->arch = get_cpu_uarch(cpu);
|
||||||
cpu->freq = get_frequency_info();
|
cpu->freq = get_frequency_info();
|
||||||
cpu->topo = get_topology_info(cpu->cach);
|
cpu->topo = get_topology_info(cpu->cach);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ enum {
|
|||||||
UARCH_POWER7,
|
UARCH_POWER7,
|
||||||
UARCH_POWER7PLUS,
|
UARCH_POWER7PLUS,
|
||||||
UARCH_POWER8,
|
UARCH_POWER8,
|
||||||
|
UARCH_POWER8_DD21,
|
||||||
UARCH_POWER9,
|
UARCH_POWER9,
|
||||||
UARCH_POWER9_DD20,
|
UARCH_POWER9_DD20,
|
||||||
UARCH_POWER9_DD21,
|
UARCH_POWER9_DD21,
|
||||||
@@ -84,6 +85,7 @@ void fill_uarch(struct uarch* arch, MICROARCH u) {
|
|||||||
FILL_UARCH(arch->uarch, UARCH_POWER7, "POWER7", 45)
|
FILL_UARCH(arch->uarch, UARCH_POWER7, "POWER7", 45)
|
||||||
FILL_UARCH(arch->uarch, UARCH_POWER7PLUS, "POWER7+", 32)
|
FILL_UARCH(arch->uarch, UARCH_POWER7PLUS, "POWER7+", 32)
|
||||||
FILL_UARCH(arch->uarch, UARCH_POWER8, "POWER8", 22)
|
FILL_UARCH(arch->uarch, UARCH_POWER8, "POWER8", 22)
|
||||||
|
FILL_UARCH(arch->uarch, UARCH_POWER8_DD21, "POWER8 (DD2.1)", 22)
|
||||||
FILL_UARCH(arch->uarch, UARCH_POWER9, "POWER9", 14)
|
FILL_UARCH(arch->uarch, UARCH_POWER9, "POWER9", 14)
|
||||||
FILL_UARCH(arch->uarch, UARCH_POWER9_DD20, "POWER9 (DD2.0)", 14)
|
FILL_UARCH(arch->uarch, UARCH_POWER9_DD20, "POWER9 (DD2.0)", 14)
|
||||||
FILL_UARCH(arch->uarch, UARCH_POWER9_DD21, "POWER9 (DD2.1)", 14)
|
FILL_UARCH(arch->uarch, UARCH_POWER9_DD21, "POWER9 (DD2.1)", 14)
|
||||||
@@ -100,7 +102,19 @@ void fill_uarch(struct uarch* arch, MICROARCH u) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PVR masks/values from arch/powerpc/kernel/cputable.c (Linux kernel)
|
* PVR masks/values from Linux kernel:
|
||||||
|
* - arch/powerpc/kernel/cputable.c (kernel <= 6.0)
|
||||||
|
* - arch/powerpc/kernel/cpu_specs_book3s_64.h (kernel >= 6.1)
|
||||||
|
*
|
||||||
|
* In the kernel, there is a POWER8E identifier. In
|
||||||
|
* https://wiki.raptorcs.com/wiki/POWER8E it says it is
|
||||||
|
* actually DD2.1, while other POWER8 should be DD2.0.
|
||||||
|
* The last assumption does not seem to be correct according
|
||||||
|
* to https://openbenchmarking.org/s/POWER8NVL, which shows a
|
||||||
|
* POWER8NVL where kernel says it is DD1.0. We implement this
|
||||||
|
* to show only the uarch, not the revision, since it seems a bit
|
||||||
|
* redundant?
|
||||||
|
*
|
||||||
* This list may be incorrect, incomplete or overly simplified,
|
* This list may be incorrect, incomplete or overly simplified,
|
||||||
* specially in the case of 32 bit entries
|
* specially in the case of 32 bit entries
|
||||||
*/
|
*/
|
||||||
@@ -125,7 +139,7 @@ struct uarch* get_uarch_from_pvr(uint32_t pvr) {
|
|||||||
CHECK_UARCH(arch, pvr, 0xffffffff, 0x0f000006, UARCH_POWER10)
|
CHECK_UARCH(arch, pvr, 0xffffffff, 0x0f000006, UARCH_POWER10)
|
||||||
CHECK_UARCH(arch, pvr, 0xffff0000, 0x003f0000, UARCH_POWER7)
|
CHECK_UARCH(arch, pvr, 0xffff0000, 0x003f0000, UARCH_POWER7)
|
||||||
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004A0000, UARCH_POWER7PLUS)
|
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004A0000, UARCH_POWER7PLUS)
|
||||||
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004b0000, UARCH_POWER8)
|
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004b0000, UARCH_POWER8_DD21)
|
||||||
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004c0000, UARCH_POWER8)
|
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004c0000, UARCH_POWER8)
|
||||||
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004d0000, UARCH_POWER8)
|
CHECK_UARCH(arch, pvr, 0xffff0000, 0x004d0000, UARCH_POWER8)
|
||||||
CHECK_UARCH(arch, pvr, 0xffffefff, 0x004e0200, UARCH_POWER9_DD20)
|
CHECK_UARCH(arch, pvr, 0xffffefff, 0x004e0200, UARCH_POWER9_DD20)
|
||||||
@@ -234,6 +248,7 @@ bool has_altivec(struct uarch* arch) {
|
|||||||
case UARCH_POWER7:
|
case UARCH_POWER7:
|
||||||
case UARCH_POWER7PLUS:
|
case UARCH_POWER7PLUS:
|
||||||
case UARCH_POWER8:
|
case UARCH_POWER8:
|
||||||
|
case UARCH_POWER8_DD21:
|
||||||
case UARCH_POWER9:
|
case UARCH_POWER9:
|
||||||
case UARCH_POWER9_DD20:
|
case UARCH_POWER9_DD20:
|
||||||
case UARCH_POWER9_DD21:
|
case UARCH_POWER9_DD21:
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "../common/udev.h"
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
|
|
||||||
#define _PATH_TOPO_CORE_ID "topology/core_id"
|
#define _PATH_TOPO_CORE_ID "topology/core_id"
|
||||||
#define _PATH_TOPO_PACKAGE_ID "topology/physical_package_id"
|
#define _PATH_TOPO_PACKAGE_ID "topology/physical_package_id"
|
||||||
|
#define CPUINFO_FREQUENCY_STR "clock\t\t: "
|
||||||
|
|
||||||
bool fill_array_from_sys(int *core_ids, int total_cores, char* SYS_PATH) {
|
bool fill_array_from_sys(int *core_ids, int total_cores, char* SYS_PATH) {
|
||||||
int filelen;
|
int filelen;
|
||||||
char* buf;
|
char* buf;
|
||||||
char* end;
|
char* end;
|
||||||
char path[128];
|
char path[128];
|
||||||
|
memset(path, 0, 128);
|
||||||
|
|
||||||
for(int i=0; i < total_cores; i++) {
|
for(int i=0; i < total_cores; i++) {
|
||||||
sprintf(path, "%s%s/cpu%d/%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, SYS_PATH);
|
sprintf(path, "%s%s/cpu%d/%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, SYS_PATH);
|
||||||
@@ -36,5 +39,52 @@ bool fill_core_ids_from_sys(int *core_ids, int total_cores) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool fill_package_ids_from_sys(int* package_ids, int total_cores) {
|
bool fill_package_ids_from_sys(int* package_ids, int total_cores) {
|
||||||
return fill_array_from_sys(package_ids, total_cores, _PATH_TOPO_PACKAGE_ID);
|
bool status = fill_array_from_sys(package_ids, total_cores, _PATH_TOPO_PACKAGE_ID);
|
||||||
|
if(status) {
|
||||||
|
// fill_array_from_sys completed successfully, but we
|
||||||
|
// must to check the integrity of the package_ids array
|
||||||
|
for(int i=0; i < total_cores; i++) {
|
||||||
|
if(package_ids[i] == -1) {
|
||||||
|
printWarn("fill_package_ids_from_sys: package_ids[%d] = -1", i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(package_ids[i] >= total_cores || package_ids[i] < 0) {
|
||||||
|
printBug("fill_package_ids_from_sys: package_ids[%d] = %d", i, package_ids[i]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long get_frequency_from_cpuinfo(void) {
|
||||||
|
char* freq_str = get_field_from_cpuinfo(CPUINFO_FREQUENCY_STR);
|
||||||
|
if(freq_str == NULL) {
|
||||||
|
return UNKNOWN_DATA;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// freq_str should be in the form XXXX.YYYYYYMHz
|
||||||
|
char* dot = strstr(freq_str, ".");
|
||||||
|
freq_str[dot-freq_str] = '\0';
|
||||||
|
|
||||||
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
long ret = strtol(freq_str, &end, 10);
|
||||||
|
if(errno != 0) {
|
||||||
|
printBug("strtol: %s", strerror(errno));
|
||||||
|
free(freq_str);
|
||||||
|
return UNKNOWN_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We consider it an error if frequency is
|
||||||
|
// greater than 10 GHz or less than 100 MHz
|
||||||
|
if(ret > 10000 || ret < 100) {
|
||||||
|
printBug("Invalid data was read from file '%s': %ld\n", CPUINFO_FREQUENCY_STR, ret);
|
||||||
|
return UNKNOWN_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,13 @@
|
|||||||
#include "../common/udev.h"
|
#include "../common/udev.h"
|
||||||
#define _PATH_DT "/proc/device-tree/vpd/root-node-vpd@a000/enclosure@1e00/backplane@800/processor@1000"
|
#define _PATH_DT "/proc/device-tree/vpd/root-node-vpd@a000/enclosure@1e00/backplane@800/processor@1000"
|
||||||
#define _PATH_DT_PART "/part-number"
|
#define _PATH_DT_PART "/part-number"
|
||||||
|
#define _PATH_DT_IBM_PARTIT_NAME "/device-tree/ibm,partition-name"
|
||||||
|
#define _PATH_DT_HMC_MANAGED "/device-tree/hmc-managed?"
|
||||||
|
#define _PATH_DT_QEMU_WIDTH "/device-tree/chosen/qemu,graphic-width"
|
||||||
|
|
||||||
bool fill_core_ids_from_sys(int *core_ids, int total_cores);
|
bool fill_core_ids_from_sys(int *core_ids, int total_cores);
|
||||||
bool fill_package_ids_from_sys(int* package_ids, int total_cores);
|
bool fill_package_ids_from_sys(int* package_ids, int total_cores);
|
||||||
|
int get_num_sockets_package_cpus(struct topology* topo);
|
||||||
|
long get_frequency_from_cpuinfo(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -101,5 +101,20 @@ char* get_str_extensions(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_debug(struct cpuInfo* cpu) {
|
void print_debug(struct cpuInfo* cpu) {
|
||||||
printf("Unimplemented!\n");
|
printf("- soc: ");
|
||||||
|
if(cpu->soc->raw_name == NULL) {
|
||||||
|
printf("NULL\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("'%s'\n", cpu->soc->raw_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("- uarch: ");
|
||||||
|
char* arch_cpuinfo_str = get_arch_cpuinfo_str(cpu);
|
||||||
|
if(arch_cpuinfo_str == NULL) {
|
||||||
|
printf("NULL\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("'%s'\n", arch_cpuinfo_str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,66 +5,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
VENDOR get_soc_vendor(struct system_on_chip* soc) {
|
|
||||||
return soc->soc_vendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* get_str_process(struct system_on_chip* soc) {
|
|
||||||
char* str;
|
|
||||||
|
|
||||||
if(soc->process == UNKNOWN) {
|
|
||||||
str = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
|
||||||
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
str = emalloc(sizeof(char) * 5);
|
|
||||||
memset(str, 0, sizeof(char) * 5);
|
|
||||||
snprintf(str, 5, "%dnm", soc->process);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* get_soc_name(struct system_on_chip* soc) {
|
|
||||||
if(soc->soc_model == SOC_MODEL_UNKNOWN)
|
|
||||||
return soc->raw_name;
|
|
||||||
return soc->soc_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* soc_trademark_string[] = {
|
|
||||||
[SOC_VENDOR_SIFIVE] = "SiFive ",
|
|
||||||
[SOC_VENDOR_STARFIVE] = "StarFive ",
|
|
||||||
[SOC_VENDOR_ALLWINNER] = "Allwinner "
|
|
||||||
};
|
|
||||||
|
|
||||||
void fill_soc(struct system_on_chip* soc, char* soc_name, SOC soc_model, int32_t process) {
|
|
||||||
soc->soc_model = soc_model;
|
|
||||||
soc->soc_vendor = get_soc_vendor_from_soc(soc_model);
|
|
||||||
soc->process = process;
|
|
||||||
int len = strlen(soc_name) + strlen(soc_trademark_string[soc->soc_vendor]) + 1;
|
|
||||||
soc->soc_name = emalloc(sizeof(char) * len);
|
|
||||||
memset(soc->soc_name, 0, sizeof(char) * len);
|
|
||||||
sprintf(soc->soc_name, "%s%s", soc_trademark_string[soc->soc_vendor], soc_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match_soc(struct system_on_chip* soc, char* raw_name, char* expected_name, char* soc_name, SOC soc_model, int32_t process) {
|
|
||||||
int len1 = strlen(raw_name);
|
|
||||||
int len2 = strlen(expected_name);
|
|
||||||
int len = min(len1, len2);
|
|
||||||
|
|
||||||
if(strncmp(raw_name, expected_name, len) != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fill_soc(soc, soc_name, soc_model, process);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SOC_START if (false) {}
|
|
||||||
#define SOC_EQ(raw_name, expected_name, soc_name, soc_model, soc, process) \
|
|
||||||
else if (match_soc(soc, raw_name, expected_name, soc_name, soc_model, process)) return true;
|
|
||||||
#define SOC_END else { return false; }
|
|
||||||
|
|
||||||
bool match_sifive(char* soc_name, struct system_on_chip* soc) {
|
bool match_sifive(char* soc_name, struct system_on_chip* soc) {
|
||||||
char* tmp = soc_name;
|
char* tmp = soc_name;
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,10 @@
|
|||||||
#ifndef __SOC__
|
#ifndef __SOC_RISCV__
|
||||||
#define __SOC__
|
#define __SOC_RISCV__
|
||||||
|
|
||||||
|
#include "../common/soc.h"
|
||||||
#include "../common/cpu.h"
|
#include "../common/cpu.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef int32_t SOC;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
SOC_VENDOR_UNKNOWN,
|
|
||||||
SOC_VENDOR_SIFIVE,
|
|
||||||
SOC_VENDOR_STARFIVE,
|
|
||||||
SOC_VENDOR_ALLWINNER
|
|
||||||
};
|
|
||||||
|
|
||||||
struct system_on_chip {
|
|
||||||
SOC soc_model;
|
|
||||||
VENDOR soc_vendor;
|
|
||||||
int32_t process;
|
|
||||||
char* soc_name;
|
|
||||||
char* raw_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct system_on_chip* get_soc(void);
|
struct system_on_chip* get_soc(void);
|
||||||
char* get_soc_name(struct system_on_chip* soc);
|
|
||||||
VENDOR get_soc_vendor(struct system_on_chip* soc);
|
|
||||||
char* get_str_process(struct system_on_chip* soc);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ typedef uint32_t MICROARCH;
|
|||||||
struct uarch {
|
struct uarch {
|
||||||
MICROARCH uarch;
|
MICROARCH uarch;
|
||||||
char* uarch_str;
|
char* uarch_str;
|
||||||
|
char* cpuinfo_str;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -40,6 +41,7 @@ void fill_uarch(struct uarch* arch, struct cpuInfo* cpu, char* str, MICROARCH u,
|
|||||||
// T-Head: https://www.t-head.cn/product/c906
|
// T-Head: https://www.t-head.cn/product/c906
|
||||||
struct uarch* get_uarch_from_cpuinfo_str(char* cpuinfo_str, struct cpuInfo* cpu) {
|
struct uarch* get_uarch_from_cpuinfo_str(char* cpuinfo_str, struct cpuInfo* cpu) {
|
||||||
struct uarch* arch = emalloc(sizeof(struct uarch));
|
struct uarch* arch = emalloc(sizeof(struct uarch));
|
||||||
|
arch->cpuinfo_str = cpuinfo_str;
|
||||||
if(cpuinfo_str == NULL) {
|
if(cpuinfo_str == NULL) {
|
||||||
printWarn("get_uarch_from_cpuinfo: Unable to detect microarchitecture, cpuinfo_str is NULL");
|
printWarn("get_uarch_from_cpuinfo: Unable to detect microarchitecture, cpuinfo_str is NULL");
|
||||||
fill_uarch(arch, cpu, "Unknown", UARCH_UNKNOWN, CPU_VENDOR_UNKNOWN);
|
fill_uarch(arch, cpu, "Unknown", UARCH_UNKNOWN, CPU_VENDOR_UNKNOWN);
|
||||||
@@ -72,6 +74,10 @@ char* get_str_uarch(struct cpuInfo* cpu) {
|
|||||||
return cpu->arch->uarch_str;
|
return cpu->arch->uarch_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* get_arch_cpuinfo_str(struct cpuInfo* cpu) {
|
||||||
|
return cpu->arch->cpuinfo_str;
|
||||||
|
}
|
||||||
|
|
||||||
void free_uarch_struct(struct uarch* arch) {
|
void free_uarch_struct(struct uarch* arch) {
|
||||||
free(arch->uarch_str);
|
free(arch->uarch_str);
|
||||||
free(arch);
|
free(arch);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
struct uarch;
|
struct uarch;
|
||||||
|
|
||||||
|
char* get_arch_cpuinfo_str(struct cpuInfo* cpu);
|
||||||
char* get_str_uarch(struct cpuInfo* cpu);
|
char* get_str_uarch(struct cpuInfo* cpu);
|
||||||
void free_uarch_struct(struct uarch* arch);
|
void free_uarch_struct(struct uarch* arch);
|
||||||
struct uarch* get_uarch_from_cpuinfo_str(char* cpuinfo_str, struct cpuInfo* cpu);
|
struct uarch* get_uarch_from_cpuinfo_str(char* cpuinfo_str, struct cpuInfo* cpu);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
|
|
||||||
#define _PATH_CPUINFO "/proc/cpuinfo"
|
|
||||||
#define _PATH_DEVTREE "/proc/device-tree/compatible"
|
#define _PATH_DEVTREE "/proc/device-tree/compatible"
|
||||||
#define CPUINFO_UARCH_STR "uarch\t\t: "
|
#define CPUINFO_UARCH_STR "uarch\t\t: "
|
||||||
#define CPUINFO_EXTENSIONS_STR "isa\t\t: "
|
#define CPUINFO_EXTENSIONS_STR "isa\t\t: "
|
||||||
@@ -86,7 +85,7 @@ char* get_uarch_from_cpuinfo(void) {
|
|||||||
return parse_cpuinfo_field(CPUINFO_UARCH_STR);
|
return parse_cpuinfo_field(CPUINFO_UARCH_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* get_extensions_from_cpuinfo() {
|
char* get_extensions_from_cpuinfo(void) {
|
||||||
return parse_cpuinfo_field(CPUINFO_EXTENSIONS_STR);
|
return parse_cpuinfo_field(CPUINFO_EXTENSIONS_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
104
src/x86/cpuid.c
104
src/x86/cpuid.c
@@ -30,6 +30,7 @@ static const char *hv_vendors_string[] = {
|
|||||||
[HV_VENDOR_VMWARE] = "VMwareVMware",
|
[HV_VENDOR_VMWARE] = "VMwareVMware",
|
||||||
[HV_VENDOR_XEN] = "XenVMMXenVMM",
|
[HV_VENDOR_XEN] = "XenVMMXenVMM",
|
||||||
[HV_VENDOR_PARALLELS] = "lrpepyh vr",
|
[HV_VENDOR_PARALLELS] = "lrpepyh vr",
|
||||||
|
[HV_VENDOR_PHYP] = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *hv_vendors_name[] = {
|
static char *hv_vendors_name[] = {
|
||||||
@@ -39,11 +40,10 @@ static char *hv_vendors_name[] = {
|
|||||||
[HV_VENDOR_VMWARE] = "VMware",
|
[HV_VENDOR_VMWARE] = "VMware",
|
||||||
[HV_VENDOR_XEN] = "Xen",
|
[HV_VENDOR_XEN] = "Xen",
|
||||||
[HV_VENDOR_PARALLELS] = "Parallels",
|
[HV_VENDOR_PARALLELS] = "Parallels",
|
||||||
|
[HV_VENDOR_PHYP] = "pHyp",
|
||||||
[HV_VENDOR_INVALID] = STRING_UNKNOWN
|
[HV_VENDOR_INVALID] = STRING_UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HYPERVISOR_NAME_MAX_LENGTH 17
|
|
||||||
|
|
||||||
#define MASK 0xFF
|
#define MASK 0xFF
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -223,9 +223,10 @@ int64_t get_peak_performance(struct cpuInfo* cpu, bool accurate_pp) {
|
|||||||
if(feat->FMA3 || feat->FMA4)
|
if(feat->FMA3 || feat->FMA4)
|
||||||
flops = flops*2;
|
flops = flops*2;
|
||||||
|
|
||||||
// Ice Lake has AVX512, but it has 1 VPU for AVX512, while
|
// NOTE:
|
||||||
// it has 2 for AVX2. If this is a Ice Lake CPU, we are computing
|
// Some CPUs (Ice Lake, Zen 4) have AVX512, but they have only
|
||||||
// the peak performance supposing AVX2, not AVX512
|
// 1 VPU for AVX512, while they have 2 for AVX2. In such cases,
|
||||||
|
// we are computing the peak performance supposing AVX2, not AVX512
|
||||||
if(feat->AVX512 && vpus_are_AVX512(ptr))
|
if(feat->AVX512 && vpus_are_AVX512(ptr))
|
||||||
flops = flops*16;
|
flops = flops*16;
|
||||||
else if(feat->AVX || feat->AVX2)
|
else if(feat->AVX || feat->AVX2)
|
||||||
@@ -260,6 +261,11 @@ struct hypervisor* get_hp_info(bool hv_present) {
|
|||||||
|
|
||||||
cpuid(&eax, &ebx, &ecx, &edx);
|
cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
|
||||||
|
if(ebx == 0x0 && ecx == 0x0 && edx == 0x0) {
|
||||||
|
hv->hv_vendor = HV_VENDOR_INVALID;
|
||||||
|
printWarn("Hypervisor vendor is empty");
|
||||||
|
}
|
||||||
|
else {
|
||||||
char name[13];
|
char name[13];
|
||||||
memset(name, 0, 13);
|
memset(name, 0, 13);
|
||||||
get_name_cpuid(name, ebx, ecx, edx);
|
get_name_cpuid(name, ebx, ecx, edx);
|
||||||
@@ -268,7 +274,7 @@ struct hypervisor* get_hp_info(bool hv_present) {
|
|||||||
uint8_t len = sizeof(hv_vendors_string) / sizeof(hv_vendors_string[0]);
|
uint8_t len = sizeof(hv_vendors_string) / sizeof(hv_vendors_string[0]);
|
||||||
|
|
||||||
for(uint8_t v=0; v < len && !found; v++) {
|
for(uint8_t v=0; v < len && !found; v++) {
|
||||||
if(strcmp(hv_vendors_string[v], name) == 0) {
|
if(hv_vendors_string[v] != NULL && strcmp(hv_vendors_string[v], name) == 0) {
|
||||||
hv->hv_vendor = v;
|
hv->hv_vendor = v;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@@ -276,7 +282,8 @@ struct hypervisor* get_hp_info(bool hv_present) {
|
|||||||
|
|
||||||
if(!found) {
|
if(!found) {
|
||||||
hv->hv_vendor = HV_VENDOR_INVALID;
|
hv->hv_vendor = HV_VENDOR_INVALID;
|
||||||
printWarn("Unknown hypervisor vendor: %s", name);
|
printBug("Unknown hypervisor vendor: %s", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hv->hv_name = hv_vendors_name[hv->hv_vendor];
|
hv->hv_name = hv_vendors_name[hv->hv_vendor];
|
||||||
@@ -625,6 +632,7 @@ bool get_cache_topology_amd(struct cpuInfo* cpu, struct topology* topo) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
void get_topology_from_udev(struct topology* topo) {
|
void get_topology_from_udev(struct topology* topo) {
|
||||||
// TODO: To be improved in the future
|
// TODO: To be improved in the future
|
||||||
topo->total_cores = get_ncores_from_cpuinfo();
|
topo->total_cores = get_ncores_from_cpuinfo();
|
||||||
@@ -634,6 +642,7 @@ void get_topology_from_udev(struct topology* topo) {
|
|||||||
topo->smt_supported = 1;
|
topo->smt_supported = 1;
|
||||||
topo->sockets = 1;
|
topo->sockets = 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Main reference: https://software.intel.com/content/www/us/en/develop/articles/intel-64-architecture-processor-topology-enumeration.html
|
// Main reference: https://software.intel.com/content/www/us/en/develop/articles/intel-64-architecture-processor-topology-enumeration.html
|
||||||
// Very interesting resource: https://wiki.osdev.org/Detecting_CPU_Topology_(80x86)
|
// Very interesting resource: https://wiki.osdev.org/Detecting_CPU_Topology_(80x86)
|
||||||
@@ -1084,12 +1093,29 @@ void print_debug(struct cpuInfo* cpu) {
|
|||||||
free_cpuinfo_struct(cpu);
|
free_cpuinfo_struct(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Query HV and Xeon Phi levels
|
void print_raw_level(uint32_t reg) {
|
||||||
|
uint32_t eax = reg;
|
||||||
|
uint32_t ebx = 0;
|
||||||
|
uint32_t ecx = 0;
|
||||||
|
uint32_t 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 print_raw_sublevel(uint32_t reg, uint32_t reg2) {
|
||||||
|
uint32_t eax = reg;
|
||||||
|
uint32_t ebx = 0;
|
||||||
|
uint32_t ecx = reg2;
|
||||||
|
uint32_t 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);
|
||||||
|
}
|
||||||
|
|
||||||
void print_raw(struct cpuInfo* cpu) {
|
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("%s\n\n", cpu->cpu_name);
|
||||||
printf(" CPUID leaf sub EAX EBX ECX EDX \n");
|
printf(" CPUID leaf sub EAX EBX ECX EDX \n");
|
||||||
printf("--------------------------------------------------------------\n");
|
printf("--------------------------------------------------------------\n");
|
||||||
@@ -1104,66 +1130,40 @@ void print_raw(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
printf("CPU %d:\n", c);
|
printf("CPU %d:\n", c);
|
||||||
|
|
||||||
|
// Standard levels
|
||||||
for(uint32_t reg=0x00000000; reg <= cpu->maxLevels; reg++) {
|
for(uint32_t reg=0x00000000; reg <= cpu->maxLevels; reg++) {
|
||||||
if(reg == 0x00000004) {
|
if(reg == 0x00000004) {
|
||||||
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
||||||
eax = reg;
|
print_raw_sublevel(reg, reg2);
|
||||||
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) {
|
else if(reg == 0x0000000B) {
|
||||||
for(uint32_t reg2=0x00000000; reg2 < cpu->topo->smt_supported; reg2++) {
|
for(uint32_t reg2=0x00000000; reg2 < cpu->topo->smt_supported; reg2++) {
|
||||||
eax = reg;
|
print_raw_sublevel(reg, reg2);
|
||||||
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 {
|
else {
|
||||||
eax = reg;
|
print_raw_level(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hypervisor levels
|
||||||
|
for(uint32_t reg=0x40000000; reg <= 0x40000006; reg++) {
|
||||||
|
print_raw_level(reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extended levels
|
||||||
for(uint32_t reg=0x80000000; reg <= cpu->maxExtendedLevels; reg++) {
|
for(uint32_t reg=0x80000000; reg <= cpu->maxExtendedLevels; reg++) {
|
||||||
if(reg == 0x8000001D) {
|
if(reg == 0x8000001D) {
|
||||||
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
for(uint32_t reg2=0x00000000; reg2 < cpu->cach->max_cache_level; reg2++) {
|
||||||
eax = reg;
|
print_raw_sublevel(reg, reg2);
|
||||||
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 {
|
else {
|
||||||
eax = reg;
|
print_raw_level(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -364,6 +364,7 @@ struct uarch* get_uarch_from_cpuid_amd(uint32_t ef, uint32_t f, uint32_t em, uin
|
|||||||
CHECK_UARCH(arch, 8, 15, 7, 1, NA, "Zen 2", UARCH_ZEN2, 7) // samples from Steven Noonan and instlatx64
|
CHECK_UARCH(arch, 8, 15, 7, 1, NA, "Zen 2", UARCH_ZEN2, 7) // samples from Steven Noonan and instlatx64
|
||||||
CHECK_UARCH(arch, 8, 15, 9, 0, 2, "Zen 2", UARCH_ZEN2, 7) // Steam Deck (instlatx64)
|
CHECK_UARCH(arch, 8, 15, 9, 0, 2, "Zen 2", UARCH_ZEN2, 7) // Steam Deck (instlatx64)
|
||||||
CHECK_UARCH(arch, 10, 15, 0, 1, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
CHECK_UARCH(arch, 10, 15, 0, 1, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
||||||
|
CHECK_UARCH(arch, 10, 15, 1, 1, NA, "Zen 4", UARCH_ZEN4, 5) // instlatx64
|
||||||
CHECK_UARCH(arch, 10, 15, 2, 1, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
CHECK_UARCH(arch, 10, 15, 2, 1, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
||||||
CHECK_UARCH(arch, 10, 15, 4, 4, NA, "Zen 3+", UARCH_ZEN3_PLUS, 6) // instlatx64 (they say it is Zen3...)
|
CHECK_UARCH(arch, 10, 15, 4, 4, NA, "Zen 3+", UARCH_ZEN3_PLUS, 6) // instlatx64 (they say it is Zen3...)
|
||||||
CHECK_UARCH(arch, 10, 15, 5, 0, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
CHECK_UARCH(arch, 10, 15, 5, 0, NA, "Zen 3", UARCH_ZEN3, 7) // instlatx64
|
||||||
@@ -413,7 +414,9 @@ struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool vpus_are_AVX512(struct cpuInfo* cpu) {
|
bool vpus_are_AVX512(struct cpuInfo* cpu) {
|
||||||
return cpu->arch->uarch != UARCH_ICE_LAKE && cpu->arch->uarch != UARCH_TIGER_LAKE;
|
return cpu->arch->uarch != UARCH_ICE_LAKE &&
|
||||||
|
cpu->arch->uarch != UARCH_TIGER_LAKE &&
|
||||||
|
cpu->arch->uarch != UARCH_ZEN4;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_knights_landing(struct cpuInfo* cpu) {
|
bool is_knights_landing(struct cpuInfo* cpu) {
|
||||||
|
|||||||
Reference in New Issue
Block a user