Home

Awesome

CoreFreq

Purpose

CoreFreq, a CPU monitoring software with BIOS like functionalities, is designed for the 64-bits Processors of architecture Intel Atom, Core2, Nehalem, SandyBridge and superiors; AMD Families from 0Fh ... up to 17h (Zen , Zen+ , Zen 2), 18h (Hygon Dhyana), 19h (Zen 3, Zen 3+, Zen 4, Zen 4c); Arm A64

alt text

CoreFreq provides a framework to retrieve CPU data with a high degree of precision:

To reach this goal, CoreFreq implements a Linux Kernel module which employs the followings:

Build & Run

Prerequisites

a- Intel only: For a better accuracy, disable the Kernel NMI Watchdog

Add the below parameter in the kernel boot loader { Grub, SysLinux } ...

nmi_watchdog=0

... and build with the fixed performance counters

make MSR_CORE_PERF_UC=MSR_CORE_PERF_FIXED_CTR1 MSR_CORE_PERF_URC=MSR_CORE_PERF_FIXED_CTR2

b- AMD and Intel: Some Virtualization

VMs don't provide access to the registers that the CoreFreq driver employs :

However CoreFreq is making use of the virtualized performance counter :

c- Rendering

The UI renders best with an ASCII console or a Xterm with VT100 support, ANSI colors; optionally transparency.
If bold and bright colors are not rendered then use the following terminal options:

Ubuntu Terminal

In the Preferences - Colors tab, select Show bold text in bright colors

alacritty terminal

Uncomment and set draw_bold_text_with_bright_colors: true in <config-file>

Dependencies

Build

  1. Software needed:
  1. Clone the source code into a working directory.
git clone https://github.com/cyring/CoreFreq.git
  1. Build the programs.
cd CoreFreq
make -j
  CC [build/corefreqd.o]
  CC [build/corefreqm.o]
  CC [build/corefreq-cli.o]
  CC [build/corefreq-ui.o]
  CC [build/corefreq-cli-rsc.o]
  CC [build/corefreq-cli-json.o]
  CC [build/corefreq-cli-extra.o]
  LD [build/corefreqd]
  LD [build/corefreq-cli]
  CC [M]  CoreFreq/build/module/corefreqk.o
  LD [M]  CoreFreq/build/corefreqk.o
  MODPOST CoreFreq/build/Module.symvers
  CC [M]  CoreFreq/build/corefreqk.mod.o
  LD [M]  CoreFreq/build/corefreqk.ko
  BTF [M] CoreFreq/build/corefreqk.ko
  1. (Optionally) Sign the driver If module signature verification is enabled into Kernel, you will have to sign the corefreqk.ko driver.

Install

Manual

  1. Copying CoreFreq into the binaries directory
make install

Distribution package

  1. Although CoreFreq is released in the ArchLinux AUR ; other sources of distribution may require to reload the systemd daemons:
systemctl daemon-reload

Start

  1. When built from source code:
insmod build/corefreqk.ko
./build/corefreqd
./build/corefreq-cli
  1. When manually installed or from a distribution package:
modprobe corefreqk
systemctl start corefreqd
corefreq-cli

Stop

  1. Press <kbd>Ctrl+x</kbd> or <kbd>Ctrl+c</kbd> to stop the client.

  2. Press <kbd>Ctrl+c</kbd> to stop the daemon (in foreground) or kill its background job.

  3. Unload the kernel module

rmmod corefreqk.ko

Try

Download the CoreFreq Live CD from the Wiki
alt text

Screenshots

Linux kernel module

Use lsmod, dmesg or journalctl -k to check if the module is started:

CoreFreq(14:30:-1): Processor [ 8F_71] Architecture [Zen2/Matisse] SMT [32/32]

Daemon

CoreFreq Daemon #.##.#  Copyright (C) 2015-2024 CYRIL COURTIAT

  Processor [AMD Ryzen 9 3950X 16-Core Processor]
  Architecture [Zen2/Matisse] 32/32 CPU Online.

Client

Without arguments, the corefreq-cli program displays Top Monitoring
alt text
Remark: Drawing will stall if the terminal width is lower than 80 columns, or its height is less than required.

alt text

alt text

alt text

CPU     IPS            IPC            CPI
#00     0.000579/s     0.059728/c    16.742698/i
#01     0.000334/s     0.150569/c     6.641471/i
#02     0.000598/s     0.161326/c     6.198641/i
#03     0.000294/s     0.233535/c     4.282013/i
#04     0.000240/s     0.042931/c    23.293141/i
#05     0.000284/s     0.158661/c     6.302765/i
#06     0.000128/s     0.128031/c     7.810631/i
#07     0.000088/s     0.150406/c     6.648674/i

alt text

ArchLinux

Gentoo Linux

Debian, Ubuntu, TUXEDO

apt install dkms
apt list git build-essential gawk fakeroot linux-headers*

Red Hat, CentOS

yum install kernel-devel
yum group install "Development Tools"

AlmaLinux

## as root, install kernel development package and dependencies
dnf --assumeyes install kernel-devel gcc make git bc
## as a User, build CoreFreq
cd CoreFreq
make -j
## as root, install the binaries
make install
## and start Driver and Daemon
modprobe corefreqk
corefreqd
## as a User, start the Client
corefreq-cli
## Terminate Client, Daemon and unload Driver as root
modprobe -r corefreqk
## Proceed to uninstallation as root
cd CoreFreq
make uninstall

openSUSE

  1. CoreFreq official release
  2. CoreFreq-kmp-default

ProxMox

Install Tools

apt-get install build-essential dkms git libpthread-stubs0-dev

Install headers related to your kernel

apt install pve-headers-`uname -r`

git clone https://github.com/cyring/CoreFreq.git
cd CoreFreq && make

Install the module in the system, refresh it and start it

make install
depmod
modprobe corefreqk
systemctl start corefreqd

Unraid

  1. corefreq.plg from ich777/unraid-corefreq
  2. Based on latest developments, please contact ich777

Alpine

## Install the kernel development packages
apk add alpine-sdk sed installkernel bc nawk diffutils findutils pahole openssl-dev python3 linux-virt linux-virt-dev

Chimera

## Install the kernel development packages
doas apk add git ckms gmake clang linux-headers linux-lts-devel
## Add the CoreFreq directory containing the ckms.ini file
doas ckms add CoreFreq/
## Build the CoreFreq version M.m.r
doas ckms build corefreqk=M.m.r
## Or manually if using the Clang compiler
gmake CC=clang

Buildroot

Q&A

  1. load the CoreFreq driver with its Register_CPU_Freq parameter:
    insmod corefreqk.ko Register_CPU_Freq=1
  1. Clock Source
  2. Governor driver
  3. CPU-FREQ driver
  4. CPU-IDLE driver
  5. CPU-IDLE route
o---------------------------------------------------------------o
|  make [all] [clean] [info] [help] [install] [module-install]  |
|                                                               |
|  V=<n>                                                        |
|    where <n> is the verbose build level                       |
|                                                               |
|  CC=<COMPILER>                                                |
|    where <COMPILER> is cc, gcc, clang                         |
|                                                               |
|  WARNING=<ARG>                                                |
|    where default argument is -Wall                            |
|                                                               |
|  KERNELDIR=<PATH>                                             |
|    where <PATH> is the Kernel source directory                |
|                                                               |
|  CORE_COUNT=<N>                                               |
|    where <N> is 64, 128, 256, 512 or 1024 builtin CPU         |
|                                                               |
|  LEGACY=<L>                                                   |
|    where level <L>                                            |
|    1: assembly level restriction such as CMPXCHG16            |
|                                                               |
|  UBENCH=<N>                                                   |
|    where <N> is 0 to disable or 1 to enable micro-benchmark   |
|                                                               |
|  TASK_ORDER=<N>                                               |
|    where <N> is the memory page unit of kernel allocation     |
|                                                               |
|  FEAT_DBG=<N>                                                 |
|    where <N> is 0 or N for FEATURE DEBUG level                |
|    3: XMM assembly in RING operations                         |
|                                                               |
|  DELAY_TSC=<N>                                                |
|    where <N> is 1 to build a TSC implementation of udelay()   |
|                                                               |
|  OPTIM_LVL=<N>                                                |
|    where <N> is 0, 1, 2 or 3 of the OPTIMIZATION level        |
|                                                               |
|  MAX_FREQ_HZ=<freq>                                           |
|    where <freq> is at least 4850000000 Hz                     |
|                                                               |
|  HWM_CHIPSET=<chipset>                                        |
|    where <chipset> is W83627; IT8720; AMD_VCO or COMPATIBLE   |
|                                                               |
|  Performance Counters:                                        |
|    -------------------------------------------------------    |
|   |     MSR_CORE_PERF_UCC     |     MSR_CORE_PERF_URC     |   |
|   |----------- REG -----------|----------- REG -----------|   |
|   | MSR_IA32_APERF            |  MSR_IA32_MPERF           |   |
|   | MSR_CORE_PERF_FIXED_CTR1  |  MSR_CORE_PERF_FIXED_CTR2 |   |
|   | MSR_PPERF                 |  MSR_PPERF                |   |
|   | MSR_AMD_F17H_APERF        |  MSR_AMD_F17H_MPERF       |   |
|    -------------------------------------------------------    |
|                                                               |
|  Architectural Counters:                                      |
|    -------------------------------------------------------    |
|   |           Intel           |            AMD            |   |
|   |----------- REG -----------|----------- REG -----------|   |
|   |       ARCH_PMC=PCU        |      ARCH_PMC=L3          |   |
|   |                           |      ARCH_PMC=PERF        |   |
|   |                           |      ARCH_PMC=UMC         |   |
|    -------------------------------------------------------    |
|                                                               |
|  User Interface Layout:                                       |
|    NO_HEADER=<F>  NO_FOOTER=<F>  NO_UPPER=<F>  NO_LOWER=<F>   |
|      when <F> is 1: don't build and display this area part    |
|    UI_TRANSPARENCY=<F>                                        |
|      when <F> is 1: build with background transparency        |
|    UI_RULER_MINIMUM=<N>, UI_RULER_MAXIMUM=<N>                 |
|      set ruler left or right bound to <N> frequency ratio     |
|                                                               |
|  Example:                                                     |
|    make CC=gcc OPTIM_LVL=3 FEAT_DBG=1 ARCH_PMC=PCU            |
|         MSR_CORE_PERF_UCC=MSR_CORE_PERF_FIXED_CTR1            |
|         MSR_CORE_PERF_URC=MSR_CORE_PERF_FIXED_CTR2            |
|         HWM_CHIPSET=W83627 MAX_FREQ_HZ=5350000000             |
|         CORE_COUNT=1024 NO_FOOTER=1 NO_UPPER=1                |
o---------------------------------------------------------------o
$ modinfo corefreqk.ko
parm:           ArchID:Force an architecture (ID) (int)
parm:           AutoClock:Estimate Clock Frequency 0:Spec; 1:Once; 2:Auto (int)
parm:           SleepInterval:Timer interval (ms) (uint)
parm:           TickInterval:System requested interval (ms) (uint)
parm:           Experimental:Enable features under development (int)
parm:           CPU_Count:-1:Kernel(default); 0:Hardware; >0: User value (int)
parm:           Target_Ratio_Unlock:1:Target Ratio Unlock; 0:Lock (short)
parm:           Clock_Ratio_Unlock:1:MinRatio; 2:MaxRatio; 3:Both Unlock (short)
parm:           Turbo_Ratio_Unlock:1:Turbo Ratio Unlock; 0:Lock (short)
parm:           Uncore_Ratio_Unlock:1:Uncore Ratio Unlock; 0:Lock (short)
parm:           ServiceProcessor:Select a CPU to run services with (int)
parm:           RDPMC_Enable:Enable RDPMC bit in CR4 register (ushort)
parm:           NMI_Disable:Disable the NMI Handler (ushort)
parm:           Override_SubCstate:Override Sub C-States (array of ushort)
parm:           PkgCStateLimit:Package C-State Limit (short)
parm:           IOMWAIT_Enable:I/O MWAIT Redirection Enable (short)
parm:           CStateIORedir:Power Mgmt IO Redirection C-State (short)
parm:           Config_TDP_Level:Config TDP Control Level (short)
parm:           Custom_TDP_Offset:TDP Limit Offset (watt) (array of short)
parm:           Activate_TDP_Limit:Activate TDP Limiting (array of short)
parm:           Activate_TDP_Clamp:Activate TDP Clamping (array of short)
parm:           Custom_TDC_Offset:TDC Limit Offset (amp) (short)
parm:           Activate_TDC_Limit:Activate TDC Limiting (short)
parm:           L1_HW_PREFETCH_Disable:Disable L1 HW Prefetcher (short)
parm:           L1_HW_IP_PREFETCH_Disable:Disable L1 HW IP Prefetcher (short)
parm:           L1_NPP_PREFETCH_Disable:Disable L1 NPP Prefetcher (short)
parm:           L1_Scrubbing_Enable:Enable L1 Scrubbing (short)
parm:           L2_HW_PREFETCH_Disable:Disable L2 HW Prefetcher (short)
parm:           L2_HW_CL_PREFETCH_Disable:Disable L2 HW CL Prefetcher (short)
parm:           L2_AMP_PREFETCH_Disable:Adaptive Multipath Probability (short)
parm:           L2_NLP_PREFETCH_Disable:Disable L2 NLP Prefetcher (short)
parm:           L1_STRIDE_PREFETCH_Disable:Disable L1 Stride Prefetcher (short)
parm:           L1_REGION_PREFETCH_Disable:Disable L1 Region Prefetcher (short)
parm:           L1_BURST_PREFETCH_Disable:Disable L1 Burst Prefetcher (short)
parm:           L2_STREAM_PREFETCH_Disable:Disable L2 Stream Prefetcher (short)
parm:           L2_UPDOWN_PREFETCH_Disable:Disable L2 Up/Down Prefetcher (short)
parm:           LLC_Streamer_Disable:Disable LLC Streamer (short)
parm:           SpeedStep_Enable:Enable SpeedStep (short)
parm:           C1E_Enable:Enable SpeedStep C1E (short)
parm:           TurboBoost_Enable:Enable Turbo Boost (array of short)
parm:           C3A_Enable:Enable C3 Auto Demotion (short)
parm:           C1A_Enable:Enable C3 Auto Demotion (short)
parm:           C3U_Enable:Enable C3 UnDemotion (short)
parm:           C1U_Enable:Enable C1 UnDemotion (short)
parm:           C2U_Enable:Enable C2 UnDemotion (short)
parm:           CC6_Enable:Enable Core C6 State (short)
parm:           PC6_Enable:Enable Package C6 State (short)
parm:           ODCM_Enable:Enable On-Demand Clock Modulation (short)
parm:           ODCM_DutyCycle:ODCM DutyCycle [0-7] | [0-14] (short)
parm:           PowerMGMT_Unlock:Unlock Power Management (short)
parm:           PowerPolicy:Power Policy Preference [0-15] (short)
parm:           Turbo_Activation_Ratio:Turbo Activation Ratio (short)
parm:           PState_FID:P-State Frequency Id (int)
parm:           PState_VID:P-State Voltage Id (int)
parm:           Ratio_Boost:Turbo Boost Frequency ratios (array of int)
parm:           Ratio_PPC:Target Performance ratio (int)
parm:           HWP_Enable:Hardware-Controlled Performance States (short)
parm:           HWP_EPP:Energy Performance Preference (short)
parm:           Ratio_HWP:Hardware-Controlled Performance ratios (array of int)
parm:           HDC_Enable:Hardware Duty Cycling (short)
parm:           EEO_Disable:Disable Energy Efficiency Optimization (short)
parm:           R2H_Disable:Disable Race to Halt (short)
parm:           Clear_Events:Clear Thermal and Power Events (ullong)
parm:           ThermalOffset:Thermal Offset (short)
parm:           ThermalScope:[0:None; 1:SMT; 2:Core; 3:Package] (int)
parm:           VoltageScope:[0:None; 1:SMT; 2:Core; 3:Package] (int)
parm:           PowerScope:[0:None; 1:SMT; 2:Core; 3:Package] (int)
parm:           Register_CPU_Idle:Register the Kernel cpuidle driver (short)
parm:           Register_CPU_Freq:Register the Kernel cpufreq driver (short)
parm:           Register_Governor:Register the Kernel governor (short)
parm:           Register_ClockSource:Register Clock Source driver (short)
parm:           Idle_Route:[0:Default; 1:I/O; 2:HALT; 3:MWAIT] (short)
parm:           Mech_IBRS:Mitigation Mechanism IBRS (short)
parm:           Mech_STIBP:Mitigation Mechanism STIBP (short)
parm:           Mech_SSBD:Mitigation Mechanism SSBD (short)
parm:           Mech_IBPB:Mitigation Mechanism IBPB (short)
parm:           Mech_L1D_FLUSH:Mitigation Mechanism Cache L1D Flush (short)
parm:           Mech_PSFD:Mitigation Mechanism PSFD (short)
parm:           Mech_BTC_NOBR:Mitigation Mechanism BTC-NOBR (short)
parm:           Mech_XPROC_LEAK:Mitigation Mech. Cross Processor Leak (short)
parm:           Mech_AGENPICK:Mitigation Mech. LsCfgDisAgenPick (short)
parm:           WDT_Enable:Watchdog Hardware Timer (short)
parm:           HSMP_Attempt:Attempt the HSMP interface (short)

Arm [AArch64]

Screenshots

alt text

Q&A


Algorithm

alt text

About

CyrIng

Copyright (C) 2015-2024 CYRIL COURTIAT