Skip to content
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

Merged
merged 20 commits into from
Jan 7, 2023
Merged

Conversation

AlbertSanoe
Copy link
Contributor

No description provided.

@@ -1,4 +1,4 @@
pub struct rtc_time_t {
pub struct RtcTimeT {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要T

T_DAY = 0x07,
T_MONTH = 0x08,
T_YEAR = 0x09,
TSecond = 0x00,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要T

@@ -22,45 +22,45 @@ fn read_cmos(addr: u8) -> u8 {
}

enum CMOSTimeSelector {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[repr(u8)]然后下面的as u8的就不用了

@@ -0,0 +1 @@
pub mod softirq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件末尾加空行

}
}

pub struct SoftirqHandlerT {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字改为Softirq

}

pub fn unregister_softirq(&mut self, irq_num: u32) {
self.softirq_vector[irq_num as usize].action = None;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

忘了加锁

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!=None改成调用.is_some()

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不要双重!,否则代码可读性下降很多

cli();
}

pub fn clear_softirq_pending(&mut self, irq_num: u32) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

函数移动到上面去

@@ -171,7 +174,8 @@ void system_initialize()
HPET_enable();

io_mfence();
// 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
// 系统初始化kdebug("io_mfence_finished");到此结束,剩下的初始化功能应当放在初始内核线程中执行
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个注释改回原来那样的

void do_softirq();
// /**
// * @brief 卸载软中断
// *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来的那些代码删掉即可

const MAX_SOFTIRQ_NUM: u64 = 64;
const MAX_UNREGISTER_TRIAL_TIME: u64 = 50;

/// not used until softirq.h is removed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个注释的不对。哪怕softirq.h删掉了,也需要这个结构体的。
直接注释写他的用途即可
结构体改为SoftirqNum

}

pub struct Softirq {
softirq_modify_lock: RawSpinlock,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

softirq_前缀删掉

#[allow(dead_code)]
/// @brief 提供给c的接口函数,用于初始化静态指针
pub extern "C" fn softirq_init() {
unsafe {
Copy link
Member

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 {
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock之后需要再次确认上面的条件是否满足,我们不能信任未lock的部分的数据是完全准确的

/// @brief 判断对应running标志位是否为0
/// @return true: 标志位为1; false: 标志位为0
#[inline]
pub fn read_softirq_running(&mut self, softirq_num: u32) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

函数名改为is_running更合适

/// @brief 判断对应pending标志位是否为0
/// @return true: 标志位为1; false: 标志位为0
#[inline]
pub fn read_softirq_pending(&mut self, softirq_num: u32) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

softirq_table: [SoftirqVector; MAX_SOFTIRQ_NUM as usize],
}

pub static mut SOFTIRQ_HANDLER_PTR: *mut Softirq = null_mut();
Copy link
Member

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加注释

@fslongjin fslongjin merged commit 62e4613 into DragonOS-Community:master Jan 7, 2023
@AlbertSanoe AlbertSanoe deleted the softirq-refractor branch January 8, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants