void dump_irq_nr_stack();
void clk_bh_handler(void *arg);
-const char *min_ticks_name = 0;
-int min_ticks_value = 100;
-
void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) {
// if (jiffies % 100 == 0) {
// printl(MPL_CLOCK, "clock irq: %d", jiffies);
// 而如果其下半部分需要处理的事情很多,处理时间过长,两个时钟中断之间的时间还不足以处理完
// 那么下一个时钟中断是完全可以打断还没处理完的下半部逻辑
// 打断后该时钟中断不应该继续减少该进程的时间片,因为这会造成该进程在后续的调底中少了实际的运行时间
-
if (1 == current->need_resched) {
// 这种情况必然已经发生了该时钟中断打断了下半部处理程序
return;
current->ticks--;
-#if 1
- int value = (int)(current->ticks);
-
- if (min_ticks_value > value) {
- min_ticks_value = value;
- min_ticks_name = current->name;
- }
-#endif
-
if (0 == current->ticks) {
current->need_resched = 1;
current->ticks = current->priority;
current->turn++;
}
- assert(current->ticks <= TASK_MAX_PRIORITY); // 防止ticks被减到0后再减溢出
-
- printl(MPL_TEST, "%20s %10d %20s %10d", min_ticks_name, min_ticks_value, current->name, value);
+ assert(current->ticks >= 0); // 防止ticks被减到0后再减溢出
add_irq_bh_handler(clk_bh_handler, NULL);
}
task_t *p = 0;
list_head_t *pos = 0, *t = 0;
- // assert(current->ticks <= TASK_MAX_PRIORITY);
+ assert(current->ticks >= 0);
assert(current->priority <= TASK_MAX_PRIORITY);
unsigned long iflags;
extern uint64_t jiffies;
-// 特别说明:如果想把这个函数的参数ticks改为uint64_t
+// 特别说明:如果想把这个函数的参数ticks改为int64_t
// 那么就需要在编写用户级的系统调用库函数的时候注意
// 不仅需要填写 ebx,还要填写 ecx
// 不然就可能出现诡异的一直WAIT,不会调度到该任务的问题
-int sysc_wait(uint32_t ticks) {
- unsigned long flags;
- irq_save(flags);
- current->state = TASK_WAIT;
- current->reason = "sysc_wait";
- current->delay_jiffies = jiffies + ticks;
- list_add(¤t->pend, &delay_tasks);
- irq_restore(flags);
-
+int sysc_wait(int ticks) {
+ if (ticks < 0) {
+ return -EINVAL;
+ } else {
+ unsigned long flags;
+ irq_save(flags);
+ current->state = TASK_WAIT;
+ current->reason = "sysc_wait";
+ current->delay_jiffies = jiffies + ticks;
+ list_add(¤t->pend, &delay_tasks);
+ irq_restore(flags);
+ }
schedule();
+ return 0;
}
int sysc_test() {}
#include <types.h>
int do_fork(pt_regs_t *regs, unsigned long flags);
-int sysc_wait(uint32_t ticks);
+int sysc_wait(int ticks);
#define get_eflags(x) __asm__ __volatile__("pushfl; popl %0;" : "=g"(x)::"memory")