Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f21d90b
支持时间子系统
houmkh Apr 26, 2023
90235c1
解决报错问题
fslongjin Apr 29, 2023
76c4043
timekeeping+clocksource,待测试
houmkh May 10, 2023
dfdaa92
整理time文件夹
houmkh May 11, 2023
69c68e8
整理clocksource jiffies
houmkh May 13, 2023
cdbcdc9
修改time模块
houmkh May 15, 2023
8178217
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh May 15, 2023
f924465
实现timeconv,clocksource+timekeeping板块测试完成
houmkh May 21, 2023
a0a78aa
测试gettimeofday
houmkh May 27, 2023
753b175
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh May 27, 2023
b237645
修改系统调用+修改update wall time
houmkh May 30, 2023
12a2d1e
把一些变量改为Atomic的,并且把裸指针改为Option
fslongjin May 30, 2023
124beae
解决update wall time报错问题。原因:local_irq_save和local_irq_restore汇编代码不规范
fslongjin May 30, 2023
7bb25b7
debug timekeeping
houmkh May 31, 2023
520a93a
清理kdebug
houmkh Jun 1, 2023
e8f0c5e
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jun 1, 2023
2a47e68
test gettimeofday
houmkh Jun 5, 2023
3f5f18f
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jun 7, 2023
0024bd9
暂时注释process_exit_mm()
houmkh Jun 7, 2023
5cec1df
修改dadk
houmkh Jun 7, 2023
2f7e9e9
解决了几个warning
fslongjin Jun 8, 2023
08d0cc0
修复一些小问题
fslongjin Jun 8, 2023
987f295
清理代码
houmkh Jun 15, 2023
03583ae
Merge branch 'posix-timer' of github.com:houmkh/DragonOS into posix-t…
houmkh Jun 15, 2023
8598483
为一些结构体加上了Debug trait
fslongjin Jun 17, 2023
7552345
增加工作队列todo
houmkh Jun 17, 2023
77327bb
Merge branch 'posix-timer' of github.com:houmkh/DragonOS into posix-t…
houmkh Jun 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export ASFLAGS := --64
LD_LIST := head.o


kernel_subdirs := common driver process debug arch exception mm smp sched syscall ktest libs ipc io
kernel_subdirs := common driver process debug arch exception mm smp sched syscall ktest libs ipc io time



Expand Down
16 changes: 8 additions & 8 deletions kernel/src/arch/x86_64/asm/irqflags.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use core::{arch::asm, ptr::read_volatile};
use core::arch::asm;

#[inline]
pub fn local_irq_save(flags: &mut u64) {
pub fn local_irq_save() -> usize {
let x: usize;
unsafe {
asm!("pushfq", "pop rax", "mov rax, {0}", "cli", out(reg)(*flags),);
asm!("pushfq ; pop {} ; cli", out(reg) x, options(nostack));
}
x
}

#[inline]
pub fn local_irq_restore(flags: &u64) {
let x = unsafe { read_volatile(flags) };

// 恢复先前保存的rflags的值x
pub fn local_irq_restore(x: usize) {
unsafe {
asm!("push r15",
"popfq", in("r15")(x));
asm!("push {} ; popfq", in(reg) x, options(nostack));
}
}
10 changes: 4 additions & 6 deletions kernel/src/arch/x86_64/fpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl FpState {
/// @brief 从用户态进入内核时,保存浮点寄存器,并关闭浮点功能
pub fn fp_state_save(pcb: &mut process_control_block) {
// 该过程中不允许中断
let mut rflags: u64 = 0;
local_irq_save(&mut rflags);
let rflags = local_irq_save();

let fp: &mut FpState = if pcb.fp_state == null_mut() {
let f = Box::leak(Box::new(FpState::default()));
Expand Down Expand Up @@ -112,14 +111,13 @@ pub fn fp_state_save(pcb: &mut process_control_block) {
"mov cr4, rax" */
)
}
local_irq_restore(&rflags);
local_irq_restore(rflags);
}

/// @brief 从内核态返回用户态时,恢复浮点寄存器,并开启浮点功能
pub fn fp_state_restore(pcb: &mut process_control_block) {
// 该过程中不允许中断
let mut rflags: u64 = 0;
local_irq_save(&mut rflags);
let rflags = local_irq_save();

if pcb.fp_state == null_mut() {
panic!("fp_state_restore: fp_state is null. pid={}", pcb.pid);
Expand All @@ -143,5 +141,5 @@ pub fn fp_state_restore(pcb: &mut process_control_block) {
fp.restore();
fp.clear();

local_irq_restore(&rflags);
local_irq_restore(rflags);
}
5 changes: 2 additions & 3 deletions kernel/src/arch/x86_64/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ impl InterruptArch for X86_64InterruptArch {

unsafe fn save_and_disable_irq() -> IrqFlagsGuard {
compiler_fence(Ordering::SeqCst);
let mut rflags: u64 = 0;
local_irq_save(&mut rflags);
let rflags = local_irq_save() as u64;
let flags = IrqFlags::new(rflags);
let guard = IrqFlagsGuard::new(flags);
compiler_fence(Ordering::SeqCst);
Expand All @@ -58,7 +57,7 @@ impl InterruptArch for X86_64InterruptArch {

unsafe fn restore_irq(flags: IrqFlags) {
compiler_fence(Ordering::SeqCst);
local_irq_restore(&flags.flags());
local_irq_restore(flags.flags() as usize);
compiler_fence(Ordering::SeqCst);
}
}
9 changes: 8 additions & 1 deletion kernel/src/common/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ extern struct cpu_core_info_t cpu_core_info[MAX_CPU_NUM];
*
* @return uint32_t 当前cpu核心晶振频率
*/
uint32_t cpu_get_core_crysral_freq();
uint32_t cpu_get_core_crysral_freq();

/**
* @brief 获取处理器的tsc频率(单位:hz)
*
* @return uint64_t
*/
uint64_t cpu_get_tsc_freq();
7 changes: 4 additions & 3 deletions kernel/src/driver/timers/HPET/HPET.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ void HPET_enable()
// kdebug("[HPET0] conf register after modify=%#018lx", ((*(uint64_t *)(HPET_REG_BASE + TIM0_CONF))));
// kdebug("[HPET1] conf register =%#018lx", ((*(uint64_t *)(HPET_REG_BASE + TIM1_CONF))));

// 注册中断
irq_register(34, &entry, &HPET_handler, 0, &HPET_intr_controller, "HPET0");
io_mfence();
__write8b(HPET_REG_BASE + GEN_CONF, 3); // 置位旧设备中断路由兼容标志位、定时器组使能标志位
kinfo("HPET0 enabled.");

__write8b(HPET_REG_BASE + GEN_CONF, 3); // 置位旧设备中断路由兼容标志位、定时器组使能标志位
io_mfence();
// 注册中断
irq_register(34, &entry, &HPET_handler, 0, &HPET_intr_controller, "HPET0");
}

int HPET_init()
Expand Down
7 changes: 4 additions & 3 deletions kernel/src/driver/timers/rtc/rtc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
arch::interrupt::{cli, sti},
arch::CurrentIrqArch,
exception::InterruptArch,
include::bindings::bindings::{io_in8, io_out8},
syscall::SystemError,
};
Expand Down Expand Up @@ -33,7 +34,7 @@ impl RtcTime {
///@return int 成功则为0
pub fn get(&mut self) -> Result<i32, SystemError> {
// 为防止中断请求打断该过程,需要先关中断
cli();
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
//0x0B
let status_register_b: u8 = read_cmos(0x0B); // 读取状态寄存器B
let is_24h: bool = if (status_register_b & 0x02) != 0 {
Expand Down Expand Up @@ -81,7 +82,7 @@ impl RtcTime {
self.hour = ((self.hour & 0x7f) + 12) % 24;
} // 将十二小时制转为24小时

sti();
drop(irq_guard);

return Ok(0);
}
Expand Down
5 changes: 2 additions & 3 deletions kernel/src/exception/softirq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,14 @@ impl Softirq {
}

pub fn raise_softirq(&self, softirq_num: SoftirqNumber) {
let mut flags = 0;
local_irq_save(&mut flags);
let flags = local_irq_save();
let processor_id = smp_get_processor_id() as usize;

cpu_pending(processor_id).insert(VecStatus::from(softirq_num));

compiler_fence(Ordering::SeqCst);

local_irq_restore(&flags);
local_irq_restore(flags);
// kdebug!("raise_softirq exited");
}
pub unsafe fn clear_softirq_pending(&self, softirq_num: SoftirqNumber) {
Expand Down
1 change: 1 addition & 0 deletions kernel/src/include/bindings/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
#include <process/process.h>
#include <sched/sched.h>
#include <smp/smp.h>
#include <time/clocksource.h>
#include <time/sleep.h>
9 changes: 9 additions & 0 deletions kernel/src/libs/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,12 @@ uint32_t cpu_get_core_crysral_freq()

return c;
}
/**
* @brief 获取处理器的tsc频率(单位:hz)
*
* @return uint64_t
*/
uint64_t cpu_get_tsc_freq()
{
return Cpu_tsc_freq;
}
12 changes: 6 additions & 6 deletions kernel/src/libs/spinlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::syscall::SystemError;
/// @brief 保存中断状态到flags中,关闭中断,并对自旋锁加锁
#[inline]
pub fn spin_lock_irqsave(lock: *mut spinlock_t, flags: &mut u64) {
local_irq_save(flags);
*flags = local_irq_save() as u64;
unsafe {
spin_lock(lock);
}
Expand All @@ -27,7 +27,7 @@ pub fn spin_unlock_irqrestore(lock: *mut spinlock_t, flags: &u64) {
spin_unlock(lock);
}
// kdebug!("123");
local_irq_restore(flags);
local_irq_restore(*flags as usize);
}

/// 判断一个自旋锁是否已经被加锁
Expand Down Expand Up @@ -130,26 +130,26 @@ impl RawSpinlock {

/// @brief 保存中断状态到flags中,关闭中断,并对自旋锁加锁
pub fn lock_irqsave(&self, flags: &mut u64) {
local_irq_save(flags);
*flags = local_irq_save() as u64;
self.lock();
}

/// @brief 恢复rflags以及中断状态并解锁自旋锁
pub fn unlock_irqrestore(&self, flags: &u64) {
self.unlock();
local_irq_restore(flags);
local_irq_restore(*flags as usize);
}

/// @brief 尝试保存中断状态到flags中,关闭中断,并对自旋锁加锁
/// @return 加锁成功->true
/// 加锁失败->false
#[inline(always)]
pub fn try_lock_irqsave(&self, flags: &mut u64) -> bool {
local_irq_save(flags);
*flags = local_irq_save() as u64;
if self.try_lock() {
return true;
}
local_irq_restore(flags);
local_irq_restore(*flags as usize);
return false;
}
}
Expand Down
24 changes: 16 additions & 8 deletions kernel/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void reload_gdt()
gdtp.size = bsp_gdt_size - 1;
gdtp.gdt_vaddr = (ul)phys_2_virt((ul)&GDT_Table);

asm volatile("lgdt (%0) \n\t" ::"r"(&gdtp) : "memory");
asm volatile("lgdt (%0) \n\t" ::"r"(&gdtp)
: "memory");
}

void reload_idt()
Expand All @@ -62,7 +63,8 @@ void reload_idt()
// kdebug("gdtvaddr=%#018lx", p.gdt_vaddr);
// kdebug("gdt size=%d", p.size);

asm volatile("lidt (%0) \n\t" ::"r"(&idtp) : "memory");
asm volatile("lidt (%0) \n\t" ::"r"(&idtp)
: "memory");
}

// 初始化系统各模块
Expand Down Expand Up @@ -124,23 +126,29 @@ void system_initialize()

current_pcb->cpu_id = 0;
current_pcb->preempt_count = 0;
// 先初始化系统调用模块

syscall_init();

io_mfence();
// 再初始化进程模块。顺序不能调转
// sched_init();

rs_timekeeping_init();
io_mfence();

rs_timer_init();
io_mfence();

rs_jiffies_init();
io_mfence();

rs_clocksource_boot_finish();
// 这里必须加内存屏障,否则会出错
io_mfence();
smp_init();
io_mfence();

vfs_init();
rs_tty_init();

cpu_init();
ps2_keyboard_init();
// tty_init();
Expand All @@ -160,7 +168,7 @@ void system_initialize()
io_mfence();
// current_pcb->preempt_count = 0;
// kdebug("cpu_get_core_crysral_freq()=%ld", cpu_get_core_crysral_freq());

process_init();
// 启用double buffer
// scm_enable_double_buffer(); // 因为时序问题, 该函数调用被移到 initial_kernel_thread
Expand All @@ -173,7 +181,7 @@ void system_initialize()

apic_timer_init();
io_mfence();

// 这里不能删除,否则在O1会报错
// while (1)
// pause();
Expand Down
11 changes: 7 additions & 4 deletions kernel/src/net/net_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ use super::socket::{SOCKET_SET, SOCKET_WAITQUEUE};
/// The network poll function, which will be called by timer.
///
/// The main purpose of this function is to poll all network interfaces.
struct NetWorkPollFunc();
#[derive(Debug)]
struct NetWorkPollFunc;

impl TimerFunction for NetWorkPollFunc {
fn run(&mut self) {
fn run(&mut self) -> Result<(), SystemError> {
poll_ifaces_try_lock(10).ok();
let next_time = next_n_ms_timer_jiffies(10);
let timer = Timer::new(Box::new(NetWorkPollFunc()), next_time);
let timer = Timer::new(Box::new(NetWorkPollFunc), next_time);
timer.activate();
return Ok(());
}
}

pub fn net_init() -> Result<(), SystemError> {
dhcp_query()?;
// Init poll timer function
let next_time = next_n_ms_timer_jiffies(5);
let timer = Timer::new(Box::new(NetWorkPollFunc()), next_time);
let timer = Timer::new(Box::new(NetWorkPollFunc), next_time);
timer.activate();
return Ok(());
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/src/process/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ void process_exit_thread(struct process_control_block *pcb)
int process_release_pcb(struct process_control_block *pcb)
{
// 释放子进程的页表
process_exit_mm(pcb);
// BUG 暂时注释process_exit_mm
// process_exit_mm(pcb);
if ((pcb->flags & PF_KTHREAD)) // 释放内核线程的worker private结构体
free_kthread_struct(pcb);

Expand Down
Loading