Browse Source

将当前的sched_cfs函数做一个包裹,套一层sched(). (#32)

* 将当前的sched_cfs函数做一个包裹,套一层sched().

* 用sched()包裹sched_cfs(),用sched_enqueue()包裹sched_cfs_enqueue()

* 用sched()包裹sched_cfs(),用sched_enqueue()包裹sched_cfs_enqueue(),并替换

* bugfix: 修正拼写错误导致的编译错误

* 修正拼写错误

Co-authored-by: fslongjin <[email protected]>
houmkh 2 years ago
parent
commit
1a2d405384

+ 1 - 1
kernel/common/mutex.c

@@ -17,7 +17,7 @@ void mutex_init(mutex_t *lock)
 static void __mutex_sleep()
 {
     current_pcb->state = PROC_UNINTERRUPTIBLE;
-    sched_cfs();
+    sched();
 }
 
 static void __mutex_acquire(mutex_t *lock)

+ 2 - 2
kernel/common/semaphore.c

@@ -18,7 +18,7 @@ void semaphore_down(semaphore_t *sema)
         list_append(&sema->wait_queue.wait_list, &wait.wait_list);
 
         // 执行调度
-        sched_cfs();
+        sched();
     }
 }
 
@@ -35,7 +35,7 @@ void semaphore_up(semaphore_t *sema)
         list_del(&wq->wait_list);
 
         wq->pcb->state = PROC_RUNNING;
-        sched_cfs_enqueue(wq->pcb);
+        sched_enqueue(wq->pcb);
 
         // 当前进程缺少需要的资源,立即标为需要被调度
         current_pcb->flags |= PF_NEED_SCHED;

+ 3 - 3
kernel/common/wait_queue.c

@@ -28,7 +28,7 @@ void wait_queue_sleep_on(wait_queue_node_t *wait_queue_head)
     current_pcb->state = PROC_UNINTERRUPTIBLE;
     list_append(&wait_queue_head->wait_list, &wait->wait_list);
 
-    sched_cfs();
+    sched();
 }
 
 /**
@@ -44,7 +44,7 @@ void wait_queue_sleep_on_unlock(wait_queue_node_t *wait_queue_head,
     current_pcb->state = PROC_UNINTERRUPTIBLE;
     list_append(&wait_queue_head->wait_list, &wait->wait_list);
     spin_unlock((spinlock_t *)lock);
-    sched_cfs();
+    sched();
 }
 
 /**
@@ -59,7 +59,7 @@ void wait_queue_sleep_on_interriptible(wait_queue_node_t *wait_queue_head)
     current_pcb->state = PROC_INTERRUPTIBLE;
     list_append(&wait_queue_head->wait_list, &wait->wait_list);
 
-    sched_cfs();
+    sched();
 }
 
 /**

+ 2 - 2
kernel/driver/disk/ahci/ahci.c

@@ -284,7 +284,7 @@ static bool ahci_read(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t
     port->ci = 1 << slot; // Issue command
 
     current_pcb->flags |= PF_NEED_SCHED;
-    sched_cfs();
+    sched();
     int retval = AHCI_SUCCESS;
     // Wait for completion
     while (1)
@@ -364,7 +364,7 @@ static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_
     port->ci = 1; // Issue command
     
     current_pcb->flags |= PF_NEED_SCHED;
-    sched_cfs();
+    sched();
     int retval = AHCI_SUCCESS;
 
     while (1)

+ 1 - 1
kernel/driver/interrupt/apic/apic.c

@@ -510,7 +510,7 @@ void do_IRQ(struct pt_regs *rsp, ul number)
     if (current_pcb->flags & PF_NEED_SCHED)
     {
         io_mfence();
-        sched_cfs();
+        sched();
     }
 }
 

+ 15 - 15
kernel/exception/trap.c

@@ -12,7 +12,7 @@ void do_divide_error(struct pt_regs *regs, unsigned long error_code)
     kerror("do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\t pid=%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id, current_pcb->pid);
     traceback(regs);
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 1 #DB 调试异常
@@ -59,7 +59,7 @@ void do_overflow(struct pt_regs *regs, unsigned long error_code)
     printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 5 #BR 越界异常
@@ -79,7 +79,7 @@ void do_undefined_opcode(struct pt_regs *regs, unsigned long error_code)
     kerror("do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d, pid:%ld", error_code, regs->rsp, regs->rip, proc_current_cpu_id, current_pcb->pid);
     traceback(regs);
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 7 #NM 设备异常(FPU不存在)
@@ -89,7 +89,7 @@ void do_dev_not_avaliable(struct pt_regs *regs, unsigned long error_code)
     kerror("do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 8 #DF 双重错误
@@ -101,7 +101,7 @@ void do_double_fault(struct pt_regs *regs, unsigned long error_code)
     printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
     traceback(regs);
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 9 协处理器越界(保留)
@@ -111,7 +111,7 @@ void do_coprocessor_segment_overrun(struct pt_regs *regs, unsigned long error_co
     kerror("do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 10 #TS 无效的TSS段
@@ -142,7 +142,7 @@ void do_invalid_TSS(struct pt_regs *regs, unsigned long error_code)
     printk("\n");
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 11 #NP 段不存在
@@ -152,7 +152,7 @@ void do_segment_not_exists(struct pt_regs *regs, unsigned long error_code)
     kerror("do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 12 #SS SS段错误
@@ -162,7 +162,7 @@ void do_stack_segment_fault(struct pt_regs *regs, unsigned long error_code)
     kerror("do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 13 #GP 通用保护性异常
@@ -187,7 +187,7 @@ void do_general_protection(struct pt_regs *regs, unsigned long error_code)
     printk_color(RED, BLACK, "Segment Selector Index:%#010x\n", error_code & 0xfff8);
     traceback(regs);
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 14 #PF 页故障
@@ -226,7 +226,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long error_code)
     
     traceback(regs);
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 15 Intel保留,请勿使用
@@ -248,7 +248,7 @@ void do_alignment_check(struct pt_regs *regs, unsigned long error_code)
     kerror("do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 18 #MC 机器检测
@@ -258,7 +258,7 @@ void do_machine_check(struct pt_regs *regs, unsigned long error_code)
     kerror("do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 19 #XM SIMD浮点异常
@@ -268,7 +268,7 @@ void do_SIMD_exception(struct pt_regs *regs, unsigned long error_code)
     kerror("do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 20 #VE 虚拟化异常
@@ -278,7 +278,7 @@ void do_virtualization_exception(struct pt_regs *regs, unsigned long error_code)
     kerror("do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
 
     current_pcb->state = PROC_STOPPED;
-    sched_cfs();
+    sched();
 }
 
 // 21-21 Intel保留,请勿使用

+ 3 - 3
kernel/process/process.c

@@ -546,7 +546,7 @@ ul process_do_exit(ul code)
     sti();
 
     process_exit_notify();
-    sched_cfs();
+    sched();
 
     while (1)
         pause();
@@ -801,7 +801,7 @@ struct process_control_block *process_get_pcb(long pid)
 void process_wakeup(struct process_control_block *pcb)
 {
     pcb->state = PROC_RUNNING;
-    sched_cfs_enqueue(pcb);
+    sched_enqueue(pcb);
 }
 
 /**
@@ -812,7 +812,7 @@ void process_wakeup(struct process_control_block *pcb)
 void process_wakeup_immediately(struct process_control_block *pcb)
 {
     pcb->state = PROC_RUNNING;
-    sched_cfs_enqueue(pcb);
+    sched_enqueue(pcb);
     // 将当前进程标志为需要调度,缩短新进程被wakeup的时间
     current_pcb->flags |= PF_NEED_SCHED;
 }

+ 19 - 0
kernel/sched/sched.c

@@ -47,6 +47,16 @@ void sched_cfs_enqueue(struct process_control_block *pcb)
     ++sched_cfs_ready_queue[proc_current_cpu_id].count;
 }
 
+/**
+ * @brief 包裹shced_cfs_enqueue(),将PCB加入就绪队列
+ * 
+ * @param pcb
+ */
+void sched_enqueue(struct process_control_block *pcb)
+{
+    sched_cfs_enqueue(pcb);
+}
+
 /**
  * @brief 调度函数
  *
@@ -118,6 +128,15 @@ void sched_cfs()
     sti();
 }
 
+/**
+ * @brief 包裹sched_cfs(),调度函数
+ * 
+ */
+void sched()
+{
+    sched_cfs();
+}
+
 /**
  * @brief 当时钟中断到达时,更新时间片
  *

+ 12 - 0
kernel/sched/sched.h

@@ -20,6 +20,12 @@ extern struct sched_queue_t sched_cfs_ready_queue[MAX_CPU_NUM]; // 就绪队列
  */
 void sched_cfs();
 
+/**
+ * @brief 包裹sched_cfs(),调度函数
+ * 
+ */
+void sched();
+
 /**
  * @brief 将PCB加入就绪队列
  *
@@ -27,6 +33,12 @@ void sched_cfs();
  */
 void sched_cfs_enqueue(struct process_control_block *pcb);
 
+/**
+ * @brief 包裹sched_enqueue(),将PCB加入就绪队列
+ * 
+ * @param pcb
+ */
+void sched_enqueue(struct process_control_block *pcb);
 
 /**
  * @brief 从就绪队列中取出PCB

+ 1 - 1
kernel/time/sleep.c

@@ -57,7 +57,7 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
 
     current_pcb->state = PROC_INTERRUPTIBLE;
     current_pcb->flags |= PF_NEED_SCHED;
-    sched_cfs();
+    sched();
 
     // todo: 增加信号唤醒的功能后,设置rmtp