Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
3dc512b5
提交
3dc512b5
authored
4月 06, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.1.29
上级
51a3b88b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
17 行删除
+19
-17
Cargo.toml
Cargo.toml
+1
-1
thread_rt.rs
src/thread_rt.rs
+18
-16
没有找到文件。
Cargo.toml
浏览文件 @
3dc512b5
[package]
name
=
"roboplc"
version
=
"0.1.2
8
"
version
=
"0.1.2
9
"
edition
=
"2021"
authors
=
[
"Serhij S. <div@altertech.com>"
]
license
=
"Apache-2.0"
...
...
src/thread_rt.rs
浏览文件 @
3dc512b5
...
...
@@ -595,56 +595,58 @@ fn get_child_pids_recursive(pid: Pid, sys: &System, to: &mut BTreeSet<Pid>) {
}
}
/// Configure
kernel
parameters (global) while the process is running. Does nothing in simulated
/// Configure
system
parameters (global) while the process is running. Does nothing in simulated
/// mode
///
/// Example:
///
/// ```rust,no_run
/// use roboplc::thread_rt::
Kernel
Config;
/// use roboplc::thread_rt::
System
Config;
///
/// let _
kernel_config = KernelConfig::new().set("
sched_rt_runtime_us", -1)
/// let _
sys = SystemConfig::new().set("kernel/
sched_rt_runtime_us", -1)
/// .apply()
/// .expect("Unable to set
kernel
config");
/// .expect("Unable to set
system
config");
/// // some code
/// //
kernel
config is restored at the end of the scope
/// //
system
config is restored at the end of the scope
/// ```
#[derive(Default)]
pub
struct
Kernel
Config
{
pub
struct
System
Config
{
values
:
BTreeMap
<&
'static
str
,
String
>
,
prev_values
:
BTreeMap
<&
'static
str
,
String
>
,
}
impl
Kernel
Config
{
impl
System
Config
{
pub
fn
new
()
->
Self
{
Self
::
default
()
}
/// Set a parameter to configure
pub
fn
set
<
V
:
fmt
::
Display
>
(
mut
self
,
key
:
&
'static
str
,
value
:
V
)
->
Self
{
self
.values
.insert
(
key
,
value
.to_string
());
self
}
pub
fn
apply
(
mut
self
)
->
Result
<
KernelConfigGuard
>
{
/// Apply values to /proc/sys keys
pub
fn
apply
(
mut
self
)
->
Result
<
SystemConfigGuard
>
{
if
is_simulated
()
{
for
(
key
,
value
)
in
&
self
.values
{
let
prev_value
=
fs
::
read_to_string
(
format!
(
"/proc/sys/
kernel/
{}"
,
key
))
?
;
let
prev_value
=
fs
::
read_to_string
(
format!
(
"/proc/sys/{}"
,
key
))
?
;
self
.prev_values
.insert
(
key
,
prev_value
);
fs
::
write
(
format!
(
"/proc/sys/
kernel/
{}"
,
key
),
value
)
?
;
fs
::
write
(
format!
(
"/proc/sys/{}"
,
key
),
value
)
?
;
}
}
Ok
(
Kernel
ConfigGuard
{
config
:
self
})
Ok
(
System
ConfigGuard
{
config
:
self
})
}
}
pub
struct
Kernel
ConfigGuard
{
config
:
Kernel
Config
,
pub
struct
System
ConfigGuard
{
config
:
System
Config
,
}
impl
Drop
for
Kernel
ConfigGuard
{
impl
Drop
for
System
ConfigGuard
{
fn
drop
(
&
mut
self
)
{
if
is_simulated
()
{
for
(
key
,
value
)
in
&
self
.config.prev_values
{
if
let
Err
(
error
)
=
fs
::
write
(
format!
(
"/proc/sys/
kernel/
{}"
,
key
),
value
)
{
warn!
(
key
,
value
,
%
error
,
"Failed to restore
kernel
config"
);
if
let
Err
(
error
)
=
fs
::
write
(
format!
(
"/proc/sys/{}"
,
key
),
value
)
{
warn!
(
key
,
value
,
%
error
,
"Failed to restore
system
config"
);
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论