diff --git a/README.md b/README.md index 831f3a0..4715579 100644 --- a/README.md +++ b/README.md @@ -37,15 +37,19 @@ # 1. Support -cpufetch supports x86, x86_64 (Intel and AMD) and ARM. -| OS | x86_64 / x86 | ARM | Notes | -|:---------:|:------------------------:|:-------------------:|:-----------------:| -| GNU/Linux | :heavy_check_mark: | :heavy_check_mark: | Best support | -| Windows | :heavy_check_mark: | :x: | Some information may be missing.
Colors will be used if supported | -| Android | :heavy_exclamation_mark: | :heavy_check_mark: | Some information may be missing.
Not tested under x86_64 | -| macOS | :heavy_check_mark: | :x: | Some information may be missing.
Apple M1 support may be added
in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))| -| FreeBSD | :heavy_check_mark: | :x: | Some information may be missing. | +cpufetch supports the following architectures: +- x86 / x86_64 +- ARM +- PowerPC + +| OS | x86_64 / x86 | ARM | PowerPC | Notes | +|:---------:|:------------------------:|:-------------------:|:------------------:|:----------:| +| GNU/Linux | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | Best support | +| Windows | :heavy_check_mark: | :x: | :x: | Some information may be missing.
Colors will be used if supported | +| Android | :heavy_exclamation_mark: | :heavy_check_mark: | :x: | Some information may be missing.
Not tested under x86_64 | +| macOS | :heavy_check_mark: | :x: | :x: | Some information may be missing.
Apple M1 support may be added
in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))| +| FreeBSD | :heavy_check_mark: | :x: | :x: | Some information may be missing. | # 2. Installation ## 2.1 Installing from a package diff --git a/doc/DOCUMENTATION_PPC.md b/doc/DOCUMENTATION_PPC.md new file mode 100644 index 0000000..310451c --- /dev/null +++ b/doc/DOCUMENTATION_PPC.md @@ -0,0 +1,26 @@ +### 2. How to get CPU microarchitecture? +__Involved code: [get_uarch_from_pvr (uarch.c)](https://github.com/Dr-Noob/cpufetch/src/ppc/uarch.c)__ + +Microarchitecture is deduced from the PVR register, which is read using the `mfpvr` instruction. The correspondence between the PVR and the specific microarchitecture has been implemented using the values in `arch/powerpc/kernel/cputable.c` in the Linux kernel. Some of them have been removed. The manufacturing process has been queried by searching on the internet. + +### 3. How to get CPU topology? +__Involved code: [get_topology_info (ppc.c)](https://github.com/Dr-Noob/cpufetch/src/ppc/ppc.c)__ + +The total number of cores is queried using `sysconf(_SC_NPROCESSORS_ONLN)`. Then, with the number of sockets and the number of physical cores, we can calculate the number of threads per core. + +The number of sockets is queried using `/sys/devices/system/cpu/cpu*/topology/physical_package_id`. Once this file has been read for all of the cores, a simple custom algorithm is used to determine the number of sockets. + +The number of physical cores is queried using `/sys/devices/system/cpu/cpu*/topology/core_id`. Again, a custom algorithm is used to determine the number of physical cores. + +### 4. How to get the frequency? +Frequency is read directly from `/sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_max_freq` + +### 5. How to get cache size and topology? +Cache size is retrieved directly from Linux (using `/sys/devices/system/cpu/cpu0/cache/index*/size`). + +To find the cache topology, the files `/sys/devices/system/cpu/cpu0/cache/index*/shared_cpu_map` are used, and a custom algorithm is used to determine how many caches are there at each level. + +_NOTE_: To avoid Linux dependencies at this point, it looks like it is possible to derive the cache size and topology from the microarchitecture. For example, in the POWER9 architecture, wikichip assumes that all the POWER9 CPUs have the same cache size for each core and topology [[1](#references)]. + +#### References +- [1] [POWER9 - wikichip](https://en.wikichip.org/wiki/ibm/microarchitectures/power9) diff --git a/doc/README.md b/doc/README.md index 3ccf911..52240e8 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,13 +1,14 @@ -# cpufetch programming documentation (v0.94) +# cpufetch programming documentation (v0.98) This documentation explains how cpufetch works internally and all the design decisions I made. This document intends to be useful for me in the future, for everyone interested in the project, and for anyone who is trying to obtain any specific information from the CPU. In this way, this can be used as a manual or a page that collects interesting material in this area. ### 1. Basics -cpufetch works for __x86_64__ (Intel and AMD) and __ARM__ CPUs. However, cpufetch is expected to work better on x86_64, because the codebase is older and has been tested much more than the ARM version. Other kinds of x86_64 CPU are not supported (I don't think supporting other CPUs may pay off). Depending on the architecture, cpufetch choose certain files to be compiled. A summarized tree of the source code of cpufetch is shown below. +cpufetch works for __x86_64__ (Intel and AMD), __ARM__ and __PowerPC__ CPUs. However, cpufetch is expected to work better on x86_64, because the codebase is older and has been tested much more than the ARM and PowerPC versions. Depending on the architecture, cpufetch choose certain files to be compiled. A summarized tree of the source code of cpufetch is shown below. ``` cpufetch/ ├── doc │   ├── DOCUMENTATION_ARM.md +| ├── DOCUMENTATION_PPC.md │   ├── DOCUMENTATION_X86.md │   └── README.md ├── Makefile @@ -19,17 +20,22 @@ cpufetch/ │   └── other files ... ├── common/ │   └── common files ... + ├── ppc/ + | ├── ppc.c + | ├── ppc.h + | └── other files ... └── x86/ ├── cpuid.c ├── cpuid.h └── other files ... ``` -Source code is divided into three directories: +Source code is divided into four directories: -- `common/`: Source code shared between x86 and ARM -- `arm/`: ARM dependant source code -- `x86/`: x86_64 dependant source code +- `common/`: Source code shared between all architectures +- `arm/`: ARM source code +- `ppc/`: PowerPC source code +- `x86/`: x86 source code ##### 1.1 Basics (x86_64) @@ -50,10 +56,14 @@ struct cpuInfo { To use any CPUID leaf, cpufetch always needs to check that it is supported in the current CPU. ##### 1.2 Basics (ARM) -In ARM, __cpufetch works using the MIDR register and Linux filesystem__. MIDR (Main ID Register) is read from `/proc/cpuinfo`. It allows the detection of the microarchitecture of the cores. Furthermore, Linux filesystem `/sys/devices/system/cpu/` is used to fetch the number of cores and other information. This is the main reason to explain __why `cpufetch` only works on Linux kernel based systems.__ +In ARM, __cpufetch works using the MIDR register and Linux filesystem__. MIDR (Main ID Register) is read from `/proc/cpuinfo`. It allows the detection of the microarchitecture of the cores. Furthermore, Linux filesystem `/sys/devices/system/cpu/` is used to fetch the number of cores and other information. This is the main reason to explain __why `cpufetch` for ARM only works on Linux systems.__ -##### 1.3 Documentation organization -The rest of the documentation is divided into x86 and ARM architectures since each one needs different implementations: +##### 1.3 Basics (PowerPC) +In PowerPC, __cpufetch works using the PVR register and Linux filesystem__. PVR (Processor Version Register) is read using assembly and it is used to identify the microarchitecture of the CPU. Linux is also used to query the rest of the information, like the CPU topology, frequency, etc. This is the main reason to explain __why `cpufetch` for PowerPC only works on Linux systems.__ + +##### 1.4 Documentation organization +The rest of the documentation is divided in specific files for each architecture, since each one needs different implementations: -- [DOCUMENTATION_X86.md](https://github.com/Dr-Noob/cpufetch/blob/master/doc/DOCUMENTATION_X86.md) - [DOCUMENTATION_ARM.md](https://github.com/Dr-Noob/cpufetch/blob/master/doc/DOCUMENTATION_ARM.md) +- [DOCUMENTATION_PPC.md](https://github.com/Dr-Noob/cpufetch/blob/master/doc/DOCUMENTATION_PPC.md) +- [DOCUMENTATION_X86.md](https://github.com/Dr-Noob/cpufetch/blob/master/doc/DOCUMENTATION_X86.md)