unsigned long eip;
long weight;
+ long priority;
pid_t pid;
pid_t ppid;
jiffies++;
//printd("^");
- printl(MPL_CLOCK, "clock irq: %d", jiffies);
+ //printl(MPL_CLOCK, "clock irq: %d", jiffies);
}
extern void ret_from_fork_user();
extern void ret_from_fork_krnl();
extern pid_t get_next_pid();
-
+extern list_head_t all_tasks;
int do_fork(pt_regs_t *regs, unsigned long flags)
{
task_union *tsk;
tsk = alloc_task_union();
+
printk("fork task %08x flags %08x\n", tsk, flags);
if (tsk == NULL)
panic("can not malloc PCB");
memcpy(tsk, current, sizeof(task_union));
+ strcpy(tsk->name, "init");
+ tsk->priority = 61;
//{
tsk->cr3 = (unsigned long)alloc_one_page(0);
unsigned long iflags;
irq_save(iflags);
- list_add(&tsk->list, &root_task.list);
+ list_add(&tsk->list, &all_tasks);
irq_restore(iflags);
printk("%s:%d\n", __func__, __LINE__);
while (1)
{
sysc_test();
- //printl(MPL_TASK_1+id-1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, cnt++);
+ printl(MPL_TASK_1 + id - 1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, cnt++);
+ //printl(MPL_TASK_1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, cnt++);
int v = 0; //debug_wait_queue_get();
//printk("task:%d wait queue get %d\n", id, v);
}
void root_task_entry()
{
- kernel_task(init_task_entry);
- kernel_task(user_task_entry);
- kernel_task(init_task_entry);
+ //kernel_task(init_task_entry);
+ //kernel_task(user_task_entry);
+ //kernel_task(init_task_entry);
int cnt = 0;
while (1)
{
sysc_test();
- //printl(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++);
+ printl(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++);
+ //printk("root:0 [%08x] weight %d cnt %d", current, current->weight, cnt++);
asm("sti;hlt;");
sysc_test();
//syscall0(SYSC_TEST);
_irq_handler:
SAVE_REGS
+ // ebp指向栈桢
+ movl $-TASK_SIZE, %ebp
+ andl %esp, %ebp
+
movw %ss, %ax
movw %ax, %ds
movw %ax, %es
movl %esp, %eax
call irq_handler
- movl $-TASK_SIZE, %ebp
- andl %esp, %ebp
-
- movl PT_REGS_CS(%esp), %eax
- testl $0x0003, %eax
- jz resume_kernel
-
-return:
cmpl $0, TI_preempt_cnt(%ebp)
jnz restore_regs
-resched:
-
call schedule
restore_regs:
-
RESTORE_REGS
-
addl $4, %esp
-
iret
-
-resume_kernel:
- # ...
- jmp return
p->chip->ack(irq);
sti();
+
while (action && action->handler)
{
action->handler(irq, regs, action->dev_id);
action = action->next;
}
+
cli();
p->chip->enable(irq);
{
static pid_t g_pid = ROOT_TSK_PID;
- pid_t pid = g_pid++;
+ pid_t pid = ++g_pid;
return pid;
}
}
extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
+
+list_head_t all_tasks;
+
void init_root_tsk()
{
int i;
root_task.ppid = 0;
root_task.state = TASK_RUNNING;
root_task.weight = TASK_INIT_WEIGHT;
- strcpy(root_task.name, "root_task");
- INIT_LIST_HEAD(&root_task.list);
+ root_task.priority = 100;
+ strcpy(root_task.name, "root");
+
+ INIT_LIST_HEAD(&all_tasks);
+ list_add(&root_task.list, &all_tasks);
// TODO
//for(i=0; i<NR_OPENS; i++)
unsigned long iflags;
irq_save(iflags);
- list_for_each_safe(pos, tmp, &root_task.list)
+ list_for_each_safe(pos, tmp, &all_tasks)
{
p = list_entry(pos, task_union, list);
if (p->pid == pid)
unsigned long schedule()
{
static turn = 0;
- task_union *sel = 0;
+ task_union *sel = &root_task;
task_union *p = 0;
list_head_t *pos = 0, *t = 0;
unsigned long iflags;
irq_save(iflags);
printl(MPL_ROOT, "root:%d [%08x] cnt %u", root_task.pid, &root_task, root_task.cnt);
- list_for_each_safe(pos, t, &root_task.list)
+
+ unsigned int min_ratio = ~0U;
+
+ list_for_each_safe(pos, t, &all_tasks)
{
p = list_entry(pos, task_union, list);
printd("%08x %s weight %d\n", p, p->name, p->weight);
- if (sel == 0 && p->weight != turn)
+ unsigned int ratio = p->weight / p->priority;
+ if (ratio < min_ratio)
{
- p->weight = turn;
sel = p;
+ min_ratio = ratio;
+ }
+
+ p->weight++;
+ if (p->weight > p->priority)
+ {
+ p->weight = 0;
}
}
irq_restore(iflags);
- if (sel == 0)
- {
- sel = &root_task;
- turn++;
- }
+ sel = &root_task;
task_union *prev = current;
task_union *next = sel;
extern void cnsl_init();
extern void vga_init();
-#define HZ 10
+#define HZ 100
#define CLOCK_TICK_RATE 1193180
#define LATCH ((CLOCK_TICK_RATE + HZ / 2) / HZ)
setup_tasks();
setup_irqs();
+ return;
+
//switch_printk_screen();
setup_pci();
//switch_printk_screen();
set_sys_int(0x0E, TRAP_GATE, PRIVILEGE_KRNL, PageFault);
set_sys_int(0x10, TRAP_GATE, PRIVILEGE_KRNL, CoprocError);
+ for (i = 0x11; i < 0x20; i++)
+ set_sys_int(i, INTR_GATE, PRIVILEGE_KRNL, no_irq_handler);
+
for (i = 0x20; i < 256; i++)
set_sys_int(i, INTR_GATE, PRIVILEGE_KRNL, no_irq_handler);
unsigned long pfn = 0;
pte_t *pte = 0;
unsigned long pgtb_addr = 0;
+
+ // 在multiboot.S是已经初始化了BOOT_INIT_PAGETBL_CNT个页
+ // 这里接着初始化剩余的页
+ // 最大限制内存1G
for (pfn = pa2pfn(BOOT_INIT_PAGETBL_CNT << 22); pfn < bootmem_data.max_pfn; ++pfn)
{
unsigned long ti = pfn % PAGE_PTE_CNT;