Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
7b766986
提交
7b766986
authored
5月 19, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CpuGovernor
上级
4948fe67
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
53 行增加
和
2 行删除
+53
-2
thread_rt.rs
src/thread_rt.rs
+53
-2
没有找到文件。
src/thread_rt.rs
浏览文件 @
7b766986
...
...
@@ -671,9 +671,10 @@ impl SystemConfig {
pub
fn
apply
(
mut
self
)
->
Result
<
SystemConfigGuard
>
{
if
is_realtime
()
{
for
(
key
,
value
)
in
&
self
.values
{
let
prev_value
=
fs
::
read_to_string
(
format!
(
"/proc/sys/{}"
,
key
))
?
;
let
fname
=
format!
(
"/proc/sys/{}"
,
key
);
let
prev_value
=
fs
::
read_to_string
(
&
fname
)
?
;
self
.prev_values
.insert
(
key
,
prev_value
);
fs
::
write
(
f
ormat!
(
"/proc/sys/{}"
,
key
)
,
value
)
?
;
fs
::
write
(
f
name
,
value
)
?
;
}
}
Ok
(
SystemConfigGuard
{
config
:
self
})
...
...
@@ -696,6 +697,56 @@ impl Drop for SystemConfigGuard {
}
}
/// Configure CPU governors for the given CPUs
pub
struct
CpuGovernor
{
prev_governor
:
BTreeMap
<
usize
,
String
>
,
}
impl
CpuGovernor
{
/// Set performance governor for the given CPUs. This sets the maximum frequency for the CPUs,
/// increasing the power consumption but lowering their latency. It is enough to specify a
/// single logical core number per physical core. The governor is restored when the returned
/// guard object is dropped.
pub
fn
performance
<
I
>
(
performance_cpus
:
I
)
->
Result
<
CpuGovernor
>
where
I
:
IntoIterator
<
Item
=
usize
>
,
{
let
mut
prev_governor
=
BTreeMap
::
new
();
for
cpu
in
performance_cpus
{
let
fname
=
format!
(
"/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor"
,
cpu
);
let
prev_value
=
fs
::
read_to_string
(
fname
)
?
;
prev_governor
.insert
(
cpu
,
prev_value
.trim
()
.to_string
());
}
for
cpu
in
prev_governor
.keys
()
{
let
fname
=
format!
(
"/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor"
,
cpu
);
fs
::
write
(
fname
,
"performance"
)
?
;
}
Ok
(
CpuGovernor
{
prev_governor
})
}
}
impl
Drop
for
CpuGovernor
{
fn
drop
(
&
mut
self
)
{
for
(
cpu
,
governor
)
in
&
self
.prev_governor
{
if
let
Err
(
error
)
=
fs
::
write
(
format!
(
"/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor"
,
cpu
),
governor
,
)
{
warn!
(
cpu
,
%
error
,
"Failed to restore governor"
);
}
}
}
}
/// Get absolute number of CPUs, including isolated
pub
fn
num_cpus
()
->
Result
<
usize
>
{
let
f
=
std
::
fs
::
File
::
open
(
"/proc/cpuinfo"
)
?
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论