*/
#include <printk.h>
+#include <sched.h>
#include <system.h>
static unsigned int jiffies = 0;
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;
+
+ 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);
+
+ p->delay_cnt -= p->delay_cnt == 0 ? 0 : 1;
+
+ if (0 == p->delay_cnt) {
+ p->state = TASK_RUNNING;
+ list_del(&p->pend);
+ }
+ }
+
+ irq_restore(iflags);
+
// printd("^");
// printl(MPL_CLOCK, "clock irq: %d", jiffies);
}
extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
-list_head_t all_tasks;
+// list_head_t all_tasks;
+// list_head_t delay_tasks;
+LIST_HEAD(all_tasks);
+
+LIST_HEAD(pend_tasks);
void init_root_tsk() {
int i;
root_task.priority = 100;
strcpy(root_task.name, "root");
- INIT_LIST_HEAD(&all_tasks);
list_add(&root_task.list, &all_tasks);
+ // INIT_LIST_HEAD(&root_task.next);
// TODO
// for(i=0; i<NR_OPENS; i++)
kmem_cache_t *task_union_cache;
void setup_tasks() {
+ INIT_LIST_HEAD(&all_tasks);
+ INIT_LIST_HEAD(&pend_tasks);
+
init_root_tsk();
task_union_cache = kmem_cache_create("task_union", sizeof(task_union), PAGE_SIZE);
irq_save(iflags);
list_for_each_safe(pos, tmp, &all_tasks) {
p = list_entry(pos, task_union, list);
- if (p->pid == pid) break;
+ if (p->pid == pid) {
+ break;
+ }
}
irq_restore(iflags);
continue;
}
- // printd("%08x %s weight %d\n", p, p->name, p->weight);
-
float ratio = (float)(p->weight * 1.0) / (p->priority * 1.0);
if (ratio < min_ratio) {
sel = p;
irq_restore(iflags);
sel->weight++;
- printd("%08x %s:%d weight %d\n", sel, sel->name, sel->pid, 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");
+ }
+ }
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, "%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);
- }
context_switch(prev, next);
}
}