23.12.01 최초 작성
23.12.08 실습 추가
ls /sys/devices/system/cpu/ //사용가능 cpu 확인
$ cpu0 cpu1 cpu2 cpu3 ... online offline
cat /sys/devices/system/cpu/cpu3/online //online여부 확인
$ 1
echo 0 > /sys/devices/system/cpu/cpu3/online //cpu off
echo 0 | sudo tee /sys/devices/system/cpu/cpu3/online
$ 0
grep processor /proc/cpuinfo //확인
CPUfreq
: cpu의 clock을 조절할 수 있는 리눅스 서브시스템Governor
: cpu의 clock 설정Governor
적용 가능Performance
: 가장 높은 freq으로 설정
Powersave
: 가장 낮은 freq으로 설정
Userspace
: 사용자가 freq 설정
Ondemand
: 현재 시스템의 부하에 따라 조절
Conservative
: Ondemand
와 같으나 점진적으로 조절
Schedutil
: 커널 스케줄러에 따라 조절
echo conservative |sudo tee /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
cd /sys/devices/system/cpu/cpu01/cpufre
ls
affected_cpus
: freq 조절에 영향을 받는 online cpu
cpuinfo_cur_freq
: 현재 실제로 CPU가 동작하는 하드웨어 frequency (kHz)
cpuinfo_min_freq
: 최소 frequency, cpuinfo_max_freq: 최대 frequency
cpuinfo_transition_latency
: 두 frequency 사이의 변경 지연시간 (ns)
related_cpus
: freq 조절에 영향을 받는 online + offline cpu
scaling_available_frequencies
: 변경 가능 frequencies
scaling_available_governors
: 사용 가능 governor
scaling_cur_freq
: Governor가 결정한 현재 frequency
scaling_min_freq
, scaling_max_freq
: Governor에서 허용되는 최소/최대 frequency
scaling_setspeed
: userspace governor 에서 설정한 frequency
git clone https://github.com/raspberrypi/buildroot
cd buildroot
make raspberrypi4_64_defconfig
Kconfig
설정// Kconfig, menuconfig 설정
make linux-menuconfig
//minimal rootfs 설정 (qemu를 위한 buildroot 설정)
make menuconfig
cpufreq_mygovernor.c
#include <linux/cpufreq.h>
#include <linux/init.h>
#include <linux/module.h>
static void cpufreq_mygovernor_limits(struct cpufreq_policy *policy)
{
pr_debug("setting to %u kHz\n", policy->max-100000);
__cpufreq_driver_target(policy, policy->max-100000, CPUFREQ_RELATION_H);
}
static struct cpufreq_governor cpufreq_mygovernor = {
.name = "mygovernor",
.owner = THIS_MODULE,
.flags = CPUFREQ_GOV_STRICT_TARGET,
.limits = cpufreq_mygovernor_limits,
};
#ifdef CONFIG_CPU_FREQ_MYGOVERNOR
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_mygovernor;
}
#endif
MODULE_AUTHOR("someone");
MODULE_DESCRIPTION("CPUfreq policy governor 'mygovernor'");
MODULE_LICENSE("GPL");
cpufreq_governor_init(cpufreq_mygovernor);
cpufreq_governor_exit(cpufreq_mygovernor);
// /buildroot/output/build/linux-headers-custom/drivers/cpufreq에
// cpufreq_mygovernor.c 저장 및 Makefile, Kconfig 수정
/buildroot
로 돌아와 make clean
실행make linux-menuconfig
에서make menuconfig
make
make linux-menuconfig
sudo apt install libcpufreq-dev
sudo apt-get install libstdc++6
arm-linux-gnueabihf-gcc -o cpufreq_mygovernor.o cpufreq_mygovernor.c
aarch64-linux-gnu-gcc -o cpufreq_mygovernor.o cpufreq_mygovernor.c
aarch64-linux-gnu-gcc -I ~/ex_linux/065_arm/cpu_freq/buildroot/output/build/linux-headers-custom/include/ -I ~/ex_linux/09_buildroot/buildroot/output/build/linux-custom/arch/arm64/include/generated/ -I ~/ex_linux/065_arm/cpu_freq/buildroot/output/build/linux-headers-custom/include/linux -I ~/ex_linux/065_arm/cpu_freq/buildroot/output/build/linux-custom/arch/arm64/include -o cpufreq_mygovernor.o cpufreq_mygovernor.c
asm/rwonce.h: No such file or directory
/arch/arm/include
/arch/arm64/include/
asm/rwonce.h: No such file or directory
sudo apt-get install git gcc-arm-linux-gnueabihf make ncurses-dev build-essential