Skip to content

Commit f65b027

Browse files
fslongjinkkkkkongAlbertSanoe
authored
Patch merge master (#152)
* Patch sched rust (#139) * update * 添加rt调度器的rust初步实现 * 完善rt调度逻辑 * 调试rt调度器 * 修改sched的返回值 * cargo fmt 格式化 * 删除无用代码,修补rt bug * 删除无用的代码,和重复的逻辑 * 软中断bugfix * 删除一些代码 * 添加kthread_run_rt文档 * 解决sphinix警告_static目录不存在的问题 Co-authored-by: longjin <[email protected]> * Raw spin lock 增加lock_irqsave、unlock_irqrestore(#151) Raw spin lock 增加lock_irqsave、unlock_irqrestore Co-authored-by: kong <[email protected]> Co-authored-by: Gou Ngai <[email protected]>
1 parent 33ace4f commit f65b027

File tree

45 files changed

+438
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+438
-176
lines changed

docs/_static/.gitkeep

Whitespace-only changes.

docs/kernel/process_management/kthread.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262

6363
&emsp;&emsp;该宏定义是`kthread_create()`的简单封装,提供创建了内核线程后,立即运行的功能。
6464

65+
### kthread_run_rt()
66+
67+
#### 原型
68+
69+
&emsp;&emsp;`kthread_run_rt(thread_fn, data, name_fmt, ...)`
70+
71+
#### 简介
72+
73+
&emsp;&emsp;创建内核实时线程并加入调度队列。
74+
75+
&emsp;&emsp;类似`kthread_run()`,该宏定义也是`kthread_create()`的简单封装,提供创建了内核实时线程后,在设置实时进程的参数后,立即运行的功能。
76+
6577
## 停止内核线程
6678

6779
### kthread_stop()

kernel/src/arch/x86_64/asm/bitops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::arch::x86_64::_popcnt64;
22

33
/// @brief ffz - 寻找u64中的第一个0所在的位(从第0位开始寻找)
44
/// 请注意,如果x中没有0,那么结果将是未定义的。请确保传入的x至少存在1个0
5-
///
5+
///
66
/// @param x 目标u64
77
/// @return i32 bit-number(0..63) of the first (least significant) zero bit.
88
#[inline]

kernel/src/arch/x86_64/asm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod irqflags;
22
#[macro_use]
33
pub mod current;
4-
pub mod ptrace;
54
pub mod bitops;
6-
pub mod cmpxchg;
5+
pub mod cmpxchg;
6+
pub mod ptrace;

kernel/src/arch/x86_64/asm/ptrace.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::include::bindings::bindings::pt_regs;
33

44
/// @brief 判断给定的栈帧是否来自用户态
55
/// 判断方法为:根据代码段选择子是否具有ring3的访问权限(低2bit均为1)
6-
pub fn user_mode(regs: *const pt_regs)->bool{
7-
if (unsafe{(*regs).cs} & 0x3) != 0{
6+
pub fn user_mode(regs: *const pt_regs) -> bool {
7+
if (unsafe { (*regs).cs } & 0x3) != 0 {
88
return true;
9-
}else {
9+
} else {
1010
return false;
1111
}
12-
}
12+
}

kernel/src/arch/x86_64/interrupt/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use core::arch::asm;
33

44
/// @brief 关闭中断
55
#[inline]
6-
pub fn cli(){
7-
unsafe{
6+
pub fn cli() {
7+
unsafe {
88
asm!("cli");
99
}
1010
}
1111

1212
/// @brief 开启中断
1313
#[inline]
14-
pub fn sti(){
15-
unsafe{
14+
pub fn sti() {
15+
unsafe {
1616
asm!("sti");
1717
}
18-
}
18+
}

kernel/src/arch/x86_64/mm/barrier.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
use core::arch::asm;
33

44
#[inline(always)]
5-
pub fn mfence(){
6-
unsafe{
5+
pub fn mfence() {
6+
unsafe {
77
asm!("mfence");
88
}
99
}
1010

1111
#[inline(always)]
12-
pub fn lfence(){
13-
unsafe{
12+
pub fn lfence() {
13+
unsafe {
1414
asm!("lfence");
1515
}
1616
}
1717

1818
#[inline(always)]
19-
pub fn sfence(){
20-
unsafe{
19+
pub fn sfence() {
20+
unsafe {
2121
asm!("sfence");
2222
}
23-
}
23+
}

kernel/src/arch/x86_64/mm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn switch_mm(
1919
mfence();
2020
// kdebug!("to get pml4t");
2121
let pml4t = unsafe { read_volatile(&next_pcb.mm.as_ref().unwrap().pgd) };
22-
22+
2323
unsafe {
2424
asm!("mov cr3, {}", in(reg) pml4t);
2525
}

kernel/src/arch/x86_64/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[macro_use]
22
pub mod asm;
3+
pub mod context;
34
pub mod cpu;
45
pub mod interrupt;
56
pub mod mm;
6-
pub mod context;
7-
pub mod sched;
7+
pub mod sched;

kernel/src/common/kthread.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data
5454
__kt; \
5555
})
5656

57+
/**
58+
* @brief 创建内核实时线程,并将其唤醒
59+
*
60+
* @param thread_fn 该内核线程要执行的函数
61+
* @param data 传递给 thread_fn 的参数数据
62+
* @param name_fmt printf-style format string for the thread name
63+
* @param arg name_fmt的参数
64+
*/
65+
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
66+
({ \
67+
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
68+
__kt=process_init_rt_pcb(__kt); \
69+
if (!IS_ERR(__kt)){ \
70+
process_wakeup(__kt);} \
71+
__kt; \
72+
})
73+
5774
/**
5875
* @brief 向kthread发送停止信号,请求其结束
5976
*

0 commit comments

Comments
 (0)