惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
AI
AI
博客园 - 三生石上(FineUI控件)
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网
NISL@THU
NISL@THU
S
Schneier on Security
T
Threatpost
T
Tenable Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
I
Intezer
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
SecWiki News
SecWiki News
AWS News Blog
AWS News Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
V
V2EX
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
Project Zero
Project Zero
PCI Perspectives
PCI Perspectives
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Cloudbric
Cloudbric
Recent Announcements
Recent Announcements
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
C
CERT Recently Published Vulnerability Notes
The Cloudflare Blog
Forbes - Security
Forbes - Security
C
Cisco Blogs
O
OpenAI News
www.infosecurity-magazine.com
www.infosecurity-magazine.com

陈陈菌博客

如何在 podman 容器内使用 systemd 在 podman 运行 GUI 应用的经验总结 管理 podman 容器与镜像的导入或导出 用 xdg-dbus-proxy 解决容器的文件选择器的问题 解决 VSCodium 或 Code-Server 无法安装 GitHub Copilot 问题 不可变发行版 Fedora Silverblue 的体验记录 解决 apt 或 dnf 无法 tab 补全的问题 对 (MPA) 多页面切换实现丝滑动画的探索 让服务在非 Root 权限下使用 80 或 443 端口 AppImage 应用打包快速上手 Flatpak 使用和应用打包快速上手 如何用 webSocket 实现一个实时聊天应用 Linux 内核编译 | 快速上手 | deb 使用 debootstrap 构建 Debian 系根文件系统 高度可定制的 KDE 窗口装饰器 klassy 有关 docker、podman、nspawn、bwrap 的 Linux 容器图形性能测试 创建任意 Linux 容器并支持 GUI 程序 (Docker) 创建任意 Linux 容器并支持 GUI 程序 (nspawn) 文件同步工具 rsync 的使用 玲珑 (Linyaps) 应用打包 RPM 打包指南 | 精简版 PBR 材质的各种贴图类型入门 APU | Stable-Diffusion 使用记录 如何在 Electron 上启用 WebGPU Grub 主题安装与配置 Fcitx5 主题安装与自定义 不使用 Nginx 的网站开发指南 如何自制一个简易的资源监控程序 SQL 常用 CRUD 语法记录 Debian 打包入门,与需要注意的问题 在 fedora 建立一个 Arch 容器 (bwrap) 在 fedora 上建立一个 debian 容器 (bwrap) i3wm | 自制一个极简的屏幕亮度调节器 在 Linux 下启用内存压缩技术 zram 搭建一个本地轻量级聊天 Ai 我又又又重新上线了博客 如何通过命令行管理 wine 容器 (包括 proton) Btrfs 文件系统创建 swap 文件的方法 如何创建适用于 Linux 桌面的程序启动文件 Arch Linux 的基本安装
在 Linux 控制 intel CPU 调度的方法
GlumiStudio@ · 2022-08-22 · via 陈陈菌博客

2022-08-22 08:56:27

分类: Linux 标签: 系统运维,node.js


在硬件驱动成功的情况下,拿到 root 权限,然后编辑以下文件。

参数阈值: 10-100,最大主频

vim /sys/devices/system/cpu/intel_pstate/max_perf_pct

参数阈值:10-100,最小主频

vim /sys/devices/system/cpu/intel_pstate/min_perf_pct

是否关闭CPU睿频,1 为不开启 0 则开启睿频

vim /sys/devices/system/cpu/intel_pstate/no_turbo

如果你动手能力强的话,可以用脚本来实现自动化。比如检查某硬件温度多少时调整多少对应的CPU频率阈值。

对于我之前的老电脑(Surface pro 7 intel i5-1035G4版),WiFi 和 CPU 的温度传感器其中涉及的接口文件参考:

温度阈值 位于 /sys/class/hwmon/hwmon0/temp1_input (文件具体位置每个电脑不同,可以遍历 /sys/class/hwmon/ 的每个文件夹下的 name,如果叫 "coretemp" 即属于CPU的温度传感器然后在计算 temp1_input 的阈值 / 1024 即可换算为摄氏度单位)

频率阈值 位于 /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq (这个文件的阈值 / 1024000 即可换算为常见的 * Ghz 频率单位)

相关案例参考代码

我这里写了一个类似的场景,以下为 JS 的一些实现,当然你也可以选择用 shell 、Python 等语言来编写,本贴仅作为抛砖引玉作用。

#!/usr/bin/env node

const fs = require("fs")
const process = require("process")

function getTemperatureFileURL(){
    return new Promise((res)=>{
        let findUrl = "/sys/class/hwmon/"
        let hwmons = fs.readdirSync(findUrl,{encoding:"utf-8"})
        hwmons.forEach(dir=>{
            let name = fs.readFileSync(`${findUrl}${dir}/name`,{encoding:"utf-8"})
            let re = /coretemp/
            if(re.test(String(name))){
                res(`${findUrl}${dir}/temp1_input`)
            }
        })
    })
}
const cpu = {
    minValueFile: "/sys/devices/system/cpu/intel_pstate/min_perf_pct",
    maxValueFile: "/sys/devices/system/cpu/intel_pstate/max_perf_pct",
    noTurboFile: "/sys/devices/system/cpu/intel_pstate/no_turbo",
    freq: "/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq"
}
async function _test(){
    let temperature = fs.readFileSync(await getTemperatureFileURL(),{encoding:"utf-8"}) 
    let freq = fs.readFileSync(cpu.freq,{encoding:"utf-8"})
    if((temperature/1000)>=70){
        fs.writeFileSync(cpu.maxValueFile,"30")
        console.log("温度>=70,将主频最大值降到 30%")
    }else if((temperature/1000)>=65){
        fs.writeFileSync(cpu.maxValueFile,"40")
        console.log("温度>=65,将主频最大值降到 40%")
    }else if((temperature/1000)>=60){
        fs.writeFileSync(cpu.maxValueFile,"50")
        console.log("温度>=60,将主频最大值降到 50%")
    }else if((temperature/1000)>=55){
        fs.writeFileSync(cpu.maxValueFile,"60")
        console.log("温度>=55,将主频最大值降到 60%")
    }else if((temperature/1000)>=50){
        fs.writeFileSync(cpu.maxValueFile,"70")
        console.log("温度>=50,将主频最大值降到 70%")
    }else if((temperature/1000)>=45){
        fs.writeFileSync(cpu.maxValueFile,"80")
        console.log("温度>=45,将主频最大值降到 80%")
    }else {
        fs.writeFileSync(cpu.maxValueFile,"100",()=>{})
        console.log("当前温度不高,不降频率,全力拉满")
    }
    console.log(`实时CPU温度: ${temperature/1024}℃
实时CPU频率: ${String(freq/1024000).slice(0,3)}Ghz`)
}
setInterval(_test, 300);

对于守护进程,可以通过 PM2 来管理这个不停运作的 JS 进程。