extern void load_cr3(task_union *tsk);
extern list_head_t all_tasks;
-extern list_head_t pend_tasks;
\ No newline at end of file
+extern list_head_t delay_tasks;
\ No newline at end of file
void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) {
jiffies++;
- task_union *p = 0, *p1 = 0;
- list_head_t *pos = 0, *t = 0;
+ if (jiffies % 100 == 0) {
+ printl(MPL_CLOCK, "clock irq: %d", jiffies);
+ }
unsigned long iflags;
irq_save(iflags);
- int cnt = 0;
-
- list_for_each_entry_safe(p, p1, &pend_tasks, pend) {
- // printk("cnt %d %d\n", cnt++, p->delay_cnt);
+ task_union *p = 0;
+ task_union *t = 0;
+ list_for_each_entry_safe(p, t, &delay_tasks, pend) {
p->delay_cnt -= p->delay_cnt == 0 ? 0 : 1;
if (0 == p->delay_cnt) {
}
irq_restore(iflags);
-
- // printd("^");
- // printl(MPL_CLOCK, "clock irq: %d", jiffies);
}
// list_head_t delay_tasks;
LIST_HEAD(all_tasks);
-LIST_HEAD(pend_tasks);
+LIST_HEAD(delay_tasks);
void init_root_tsk() {
int i;
void setup_tasks() {
INIT_LIST_HEAD(&all_tasks);
- INIT_LIST_HEAD(&pend_tasks);
+ INIT_LIST_HEAD(&delay_tasks);
init_root_tsk();
}
}
irq_restore(iflags);
-
+ sel->sched_cnt++;
sel->weight++;
- printk("%08x %s weight %d state: %s\n", sel, sel->name, sel->weight, task_state(sel->state));
-
- list_for_each_safe(pos, t, &all_tasks) {
- p = list_entry(pos, task_union, list);
- printl(MPL_TASK_0 + p->pid, " "); //清掉上一次显示的 '>'
- printl(MPL_TASK_0 + p->pid, "%s%4s:%d [%08x] state %s weight %03d sched %u", sel == p ? ">" : " ", p->name,
- p->pid, p, task_state(p->state), p->weight, p->sched_cnt);
- if (sel->state == TASK_WAIT) {
- asm volatile("xchg %bx, %bx");
- }
- }
-
+ // printk("%08x %s weight %d state: %s\n", sel, sel->name, sel->weight, task_state(sel->state));
task_union *prev = current;
task_union *next = sel;
if (prev != next) {
// printk("switch to: %s:%d\n", next->name, next->pid);
- sel->sched_cnt++;
+ list_for_each_safe(pos, t, &all_tasks) {
+ p = list_entry(pos, task_union, list);
+ printl(MPL_TASK_0 + p->pid * 2, " "); //清掉上一次显示的 '>'
+ printl(MPL_TASK_0 + p->pid * 2, "%s%4s:%d [%08x] state %s weight %03d sched %u", next == p ? ">" : " ",
+ p->name, p->pid, p, task_state(p->state), p->weight, p->sched_cnt);
+ }
context_switch(prev, next);
}
}
extern void cnsl_init();
extern void init_ttys();
-#define HZ 10
+#define HZ 100
#define CLOCK_TICK_RATE 1193180
#define LATCH ((CLOCK_TICK_RATE + HZ / 2) / HZ)
setup_irqs();
extern tty_t monitor_tty;
- // tty_switch(&monitor_tty);
+ tty_switch(&monitor_tty);
+ // asm("sti");
+ // while (1) { /* code */
+ // }
+
return;
// switch_printk_screen();
int sysc_test() {
static unsigned int cnt = 0;
- current->delay_cnt = root_task.sched_cnt % 40;
+ { // 这一段仅是测试代码
- unsigned long iflags;
- irq_save(iflags);
+ // 因为现在sysc还没切进程
+ // 所以current把自己加到delay_tasks后不会被立即换出
+ // 下一次系统调用还可能走到这里
+ // 所以这里就直接判断不是RUNNING就返回
+ // 不再操作delay_tasks链表
+ if (current->state != TASK_RUNNING) {
+ return 0;
+ }
- current->state = TASK_WAIT;
- // 现在sysc还没有实现进程切换
- // 这个要到下一次中断之后才生效
- list_add(&(current->pend), &pend_tasks);
+ current->delay_cnt = root_task.sched_cnt % 40;
- irq_restore(iflags);
+ unsigned long iflags;
+ irq_save(iflags);
- schedule();
+ current->state = TASK_WAIT;
+ // 现在sysc还没有实现进程切换
+ // 这个要到下一次中断之后才生效
+ list_add(&(current->pend), &delay_tasks);
+
+ irq_restore(iflags);
+ }
// printl(MPL_TEST, "systest cnt %u current %08x cnt %u ",
// cnt++, current, cnt);