diff --git a/kernel/common/dirent.h b/kernel/common/dirent.h index e60bf653..ee02b343 100644 --- a/kernel/common/dirent.h +++ b/kernel/common/dirent.h @@ -1,6 +1,6 @@ #pragma once -#include +#include struct dirent { ino_t d_ino; // 文件序列号 diff --git a/kernel/common/glib.h b/kernel/common/glib.h index d9983cb3..948e3f4e 100644 --- a/kernel/common/glib.h +++ b/kernel/common/glib.h @@ -8,7 +8,7 @@ //引入对bool类型的支持 #include #include -#include +#include #include #define sti() __asm__ __volatile__("sti\n\t" :: \ diff --git a/kernel/common/miniLibc/stddef.h b/kernel/common/stddef.h similarity index 100% rename from kernel/common/miniLibc/stddef.h rename to kernel/common/stddef.h diff --git a/kernel/common/miniLibc/sys/types.h b/kernel/common/sys/types.h similarity index 100% rename from kernel/common/miniLibc/sys/types.h rename to kernel/common/sys/types.h diff --git a/kernel/common/time.h b/kernel/common/time.h new file mode 100644 index 00000000..24572865 --- /dev/null +++ b/kernel/common/time.h @@ -0,0 +1,38 @@ +#pragma once + +#include "stddef.h" + +// 操作系统定义时间以ns为单位 +#define CLOCKS_PER_SEC 1000000 + +struct tm +{ + int tm_sec; /* Seconds. [0-60] (1 leap second) */ + int tm_min; /* Minutes. [0-59] */ + int tm_hour; /* Hours. [0-23] */ + int tm_mday; /* Day. [1-31] */ + int tm_mon; /* Month. [0-11] */ + int tm_year; /* Year - 1900. */ + int tm_wday; /* Day of week. [0-6] */ + int tm_yday; /* Days in year.[0-365] */ + int tm_isdst; /* DST. [-1/0/1]*/ + + long int __tm_gmtoff; /* Seconds east of UTC. */ + const char *__tm_zone; /* Timezone abbreviation. */ +}; + + +struct timespec +{ + long int tv_sec; // 秒 + long int tv_nsec; // 纳秒 +}; + +/** + * @brief 休眠指定时间 + * + * @param rqtp 指定休眠的时间 + * @param rmtp 返回的剩余休眠时间 + * @return int + */ +extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); \ No newline at end of file diff --git a/kernel/driver/timers/HPET/HPET.c b/kernel/driver/timers/HPET/HPET.c index 2a79b1c2..1575fc0b 100644 --- a/kernel/driver/timers/HPET/HPET.c +++ b/kernel/driver/timers/HPET/HPET.c @@ -58,7 +58,7 @@ void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs) switch (param) { case 0: // 定时器0中断 - ++timer_jiffies; + timer_jiffies += HPET0_INTERVAL; /* // 将HEPT中断消息转发到ap:1处理器 @@ -68,7 +68,7 @@ void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs) // 若当前时间比定时任务的时间间隔大,则进入中断下半部 if (container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list)->expire_jiffies <= timer_jiffies) - raise_softirq((1 << TIMER_SIRQ)); + raise_softirq(TIMER_SIRQ); // 当时间到了,或进程发生切换时,刷新帧缓冲区 if (timer_jiffies >= video_refresh_expire_jiffies || (video_last_refresh_pid != current_pcb->pid)) diff --git a/kernel/process/process.c b/kernel/process/process.c index 2942a430..40388b96 100644 --- a/kernel/process/process.c +++ b/kernel/process/process.c @@ -702,13 +702,23 @@ struct process_control_block *process_get_pcb(long pid) * @param pcb 进程的pcb */ void process_wakeup(struct process_control_block *pcb) +{ + pcb->state = PROC_RUNNING; + sched_cfs_enqueue(pcb); +} + +/** + * @brief 将进程加入到调度器的就绪队列中,并标志当前进程需要被调度 + * + * @param pcb 进程的pcb + */ +void process_wakeup_immediately(struct process_control_block *pcb) { pcb->state = PROC_RUNNING; sched_cfs_enqueue(pcb); // 将当前进程标志为需要调度,缩短新进程被wakeup的时间 current_pcb->flags |= PF_NEED_SCHED; } - /** * @brief 拷贝当前进程的标志位 * diff --git a/kernel/process/process.h b/kernel/process/process.h index c55a0f73..4948f735 100644 --- a/kernel/process/process.h +++ b/kernel/process/process.h @@ -286,6 +286,13 @@ struct process_control_block *process_get_pcb(long pid); */ void process_wakeup(struct process_control_block *pcb); +/** + * @brief 将进程加入到调度器的就绪队列中,并标志当前进程需要被调度 + * + * @param pcb 进程的pcb + */ +void process_wakeup_immediately(struct process_control_block *pcb); + /** * @brief 使当前进程去执行新的代码 * diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 00ef1557..da2d71c8 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -10,11 +10,14 @@ #include #include #include +#include