-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Softirq refactor #138
Softirq refactor #138
Conversation
kernel/src/driver/timers/rtc/rtc.rs
Outdated
@@ -1,4 +1,4 @@ | |||
pub struct rtc_time_t { | |||
pub struct RtcTimeT { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要T
kernel/src/driver/timers/rtc/rtc.rs
Outdated
T_DAY = 0x07, | ||
T_MONTH = 0x08, | ||
T_YEAR = 0x09, | ||
TSecond = 0x00, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要T
kernel/src/driver/timers/rtc/rtc.rs
Outdated
@@ -22,45 +22,45 @@ fn read_cmos(addr: u8) -> u8 { | |||
} | |||
|
|||
enum CMOSTimeSelector { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加#[repr(u8)]
然后下面的as u8的就不用了
kernel/src/exception/mod.rs
Outdated
@@ -0,0 +1 @@ | |||
pub mod softirq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文件末尾加空行
kernel/src/exception/softirq.rs
Outdated
} | ||
} | ||
|
||
pub struct SoftirqHandlerT { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
名字改为Softirq
kernel/src/exception/softirq.rs
Outdated
} | ||
|
||
pub fn unregister_softirq(&mut self, irq_num: u32) { | ||
self.softirq_vector[irq_num as usize].action = None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
忘了加锁
kernel/src/exception/softirq.rs
Outdated
let mut index: u32 = 0; | ||
while (index as u64) < MAX_SOFTIRQ_NUM && self.softirq_pending != 0 { | ||
if (self.softirq_pending & (1 << index)) != 0 | ||
&& self.softirq_vector[index as usize].action != None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!=None改成调用.is_some()
kernel/src/exception/softirq.rs
Outdated
while (index as u64) < MAX_SOFTIRQ_NUM && self.softirq_pending != 0 { | ||
if (self.softirq_pending & (1 << index)) != 0 | ||
&& self.softirq_vector[index as usize].action != None | ||
&& (!(self.get_softirq_running() & (1 << index))) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不要双重!
,否则代码可读性下降很多
kernel/src/exception/softirq.rs
Outdated
cli(); | ||
} | ||
|
||
pub fn clear_softirq_pending(&mut self, irq_num: u32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数移动到上面去
kernel/src/main.c
Outdated
@@ -171,7 +174,8 @@ void system_initialize() | |||
HPET_enable(); | |||
|
|||
io_mfence(); | |||
// 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行 | |||
// 系统初始化kdebug("io_mfence_finished");到此结束,剩下的初始化功能应当放在初始内核线程中执行 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释改回原来那样的
kernel/src/exception/softirq.h
Outdated
void do_softirq(); | ||
// /** | ||
// * @brief 卸载软中断 | ||
// * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原来的那些代码删掉即可
kernel/src/exception/softirq.rs
Outdated
const MAX_SOFTIRQ_NUM: u64 = 64; | ||
const MAX_UNREGISTER_TRIAL_TIME: u64 = 50; | ||
|
||
/// not used until softirq.h is removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释的不对。哪怕softirq.h删掉了,也需要这个结构体的。
直接注释写他的用途即可
结构体改为SoftirqNum
kernel/src/exception/softirq.rs
Outdated
} | ||
|
||
pub struct Softirq { | ||
softirq_modify_lock: RawSpinlock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
softirq_
前缀删掉
kernel/src/exception/softirq.rs
Outdated
#[allow(dead_code)] | ||
/// @brief 提供给c的接口函数,用于初始化静态指针 | ||
pub extern "C" fn softirq_init() { | ||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的unsafe块太大了,参考cfs.rs
初始化的地方,缩小它
return 0; | ||
} | ||
|
||
pub fn unregister_softirq(&mut self, irq_num: u32) -> i32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数对锁的处理有问题,try_lock成功之后,下面就肯定是is_locked了。
要在try_lock里面检查running位。如果还在running,那就放锁,否则跳出循环,到下面的代码。
还有就是,循环的部分,是左闭右开的,不需要-1
&& !self.read_softirq_running(softirq_index) | ||
{ | ||
if self.softirq_modify_lock.try_lock() { | ||
self.clear_softirq_pending(softirq_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lock之后需要再次确认上面的条件是否满足,我们不能信任未lock的部分的数据是完全准确的
kernel/src/exception/softirq.rs
Outdated
/// @brief 判断对应running标志位是否为0 | ||
/// @return true: 标志位为1; false: 标志位为0 | ||
#[inline] | ||
pub fn read_softirq_running(&mut self, softirq_num: u32) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数名改为is_running
更合适
kernel/src/exception/softirq.rs
Outdated
/// @brief 判断对应pending标志位是否为0 | ||
/// @return true: 标志位为1; false: 标志位为0 | ||
#[inline] | ||
pub fn read_softirq_pending(&mut self, softirq_num: u32) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
kernel/src/exception/softirq.rs
Outdated
softirq_table: [SoftirqVector; MAX_SOFTIRQ_NUM as usize], | ||
} | ||
|
||
pub static mut SOFTIRQ_HANDLER_PTR: *mut Softirq = null_mut(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全局变量放到文件顶部
return (self.softirq_pending & (1 << softirq_num)).ne(&0); | ||
} | ||
|
||
pub fn register_softirq( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加注释
No description provided.