From: acevest Date: Fri, 9 Jun 2023 13:32:51 +0000 (+0800) Subject: 任务进入WAIT状态时加入原因 X-Git-Url: http://zhaoyanbai.com/repos/%24relpath%24tabs.css?a=commitdiff_plain;h=504bf9f8692768300fc8ea7371fd19a21cc34b59;p=kernel.git 任务进入WAIT状态时加入原因 --- diff --git a/.gitignore b/.gitignore index 49809ab..cba73dc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,9 @@ *.img *build* *.BIN +*.ELF *.bin +*.elf *.map *.sym *.diff diff --git a/.vscode/launch.json b/.vscode/launch.json index fe909e8..56f7a5d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,5 +1,5 @@ { - // 使用 IntelliSense 了解相关属性。 + // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", @@ -8,7 +8,7 @@ "name": "kernel", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/KERNEL.BIN", + "program": "${workspaceFolder}/KERNEL.ELF", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", @@ -32,4 +32,4 @@ "miDebuggerPath": "i386-elf-gdb" } ] -} \ No newline at end of file +} diff --git a/Makefile b/Makefile index 625e1b1..ba1ce6a 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ CFLAGS += -DNR_TTYS=3 CFLAGS += -DFIX_SYSENTER_ESP_MODE=1 #CFLAGS += -DENABLE_BOOT_WAIT=1 SYSTEMMAP = System.map -KERNELBIN = KERNEL.BIN +KERNELBIN = KERNEL.ELF LINKSCRIPT = scripts/link.ld SRC_DIRS = boot mm lib fs kernel drivers @@ -63,10 +63,10 @@ clean: .PHONY: install install: - cp -p KERNEL.BIN /boot/ + cp -p KERNEL.ELF /boot/ sync - md5sum /boot/KERNEL.BIN - md5sum KERNEL.BIN + md5sum /boot/KERNEL.ELF + md5sum KERNEL.ELF mkdir -p /kernel/bin/ cp bin/hello /kernel/bin/ cp bin/shell /kernel/bin/ diff --git a/include/task.h b/include/task.h index d246066..4c3f74e 100644 --- a/include/task.h +++ b/include/task.h @@ -42,11 +42,11 @@ enum { typedef union task_union { struct { - unsigned long esp0; /* kernel stack */ + uint32_t esp0; /* kernel stack */ /* for context switch */ - unsigned long esp; - unsigned long eip; + uint32_t esp; + uint32_t eip; uint32_t ticks; uint32_t turn; // 时间片用完次数 @@ -57,9 +57,12 @@ typedef union task_union { pid_t pid; pid_t ppid; + volatile unsigned int state; + const char *reason; + long exit_code; - unsigned long cr3; + uint32_t cr3; long tty; diff --git a/kernel/clock.c b/kernel/clock.c index 3cf9330..b104efe 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -65,6 +65,7 @@ void clk_bh_handler(void *arg) { list_del(&p->pend); p->delay_jiffies = 0; p->state = TASK_READY; + p->reason = "clk_bh"; } } diff --git a/kernel/sched.c b/kernel/sched.c index b710ee3..9c8aa3e 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -56,6 +56,7 @@ void init_root_task() { root_task.pid = get_next_pid(); root_task.ppid = 0; root_task.state = TASK_READY; + root_task.reason = "root"; root_task.priority = 7; root_task.ticks = root_task.priority; root_task.turn = 0; @@ -166,12 +167,12 @@ const char *task_state(unsigned int state) { void debug_print_all_tasks() { task_union *p = 0; list_head_t *pos = 0, *t = 0; - printl(MPL_TASK_TITLE, " NAME STATE TK/PI TURN SCHED KEEP"); + printl(MPL_TASK_TITLE, " NAME STATE TK/PI REASON SCHED KEEP"); list_for_each_safe(pos, t, &all_tasks) { p = list_entry(pos, task_union, list); - printl(MPL_TASK_0 + p->pid, "%08x%s%-6s:%u %s %02u/%02u %-10u %-10u %-10u", p, + printl(MPL_TASK_0 + p->pid, "%08x%s%-6s:%u %s %02u/%02u %-10s %-10u %-10u", p, p->state == TASK_RUNNING ? ">" : " ", p->name, p->pid, task_state(p->state), p->ticks, p->priority, - p->turn, p->sched_cnt, p->sched_keep_cnt); + p->reason, p->sched_cnt, p->sched_keep_cnt); } } diff --git a/kernel/semaphore.c b/kernel/semaphore.c index 29b42ad..199b17c 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c @@ -33,7 +33,7 @@ volatile void __down(semaphore_t *s) { while (true) { task->state = TASK_WAIT; - + task->reason = "down"; schedule(); if (waiter.up) { @@ -61,6 +61,7 @@ volatile void __up(semaphore_t *s) { waiter->up = 1; waiter->task->state = TASK_READY; + waiter->task->reason = "up"; } volatile void up(semaphore_t *s) { diff --git a/kernel/syscall.c b/kernel/syscall.c index d4f01d8..a6d4414 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -51,6 +51,7 @@ 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); diff --git a/kernel/task_disk.c b/kernel/task_disk.c index d53cd8d..c02bc1a 100644 --- a/kernel/task_disk.c +++ b/kernel/task_disk.c @@ -63,7 +63,8 @@ void disk_task_entry(void *arg) { ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel; // 为了在DEBUG时看到RUNNING - for (int i = 0; i < 1; i++) { + int cnt = 2; + for (int i = 0; i < cnt; i++) { asm("hlt;"); } diff --git a/kernel/task_root.c b/kernel/task_root.c index 6028d41..394332f 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -126,7 +126,6 @@ void taskB_entry() { while (1) { sysc_wait(7); - uint64_t sect_nr = get_next_deubug_sect_nr(); memset(disk_buf2, 0, 512); disk_request_t r; @@ -148,7 +147,7 @@ void taskC_entry() { current->priority = 17; while (1) { - sysc_wait(1); + sysc_wait(100); for (int i = 0; i < 7; i++) { asm("hlt;"); diff --git a/kernel/wait.c b/kernel/wait.c index bb7360c..86ea8f2 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -53,6 +53,7 @@ volatile void sleep_on(wait_queue_head_t *head) { irq_save(flags); current->state = TASK_WAIT; + current->reason = "sleep_on"; list_add_tail(&wait.task_list, &head->task_list); @@ -72,6 +73,7 @@ volatile void __wake_up(wait_queue_head_t *head, int nr) { list_del(&p->task_list); // printk("wakeup: %s\n", p->task->name); p->task->state = TASK_READY; + current->reason = "wake_up"; --nr; if (nr == 0) { diff --git a/qemu.sh b/qemu.sh index fa9ce47..efff4d2 100755 --- a/qemu.sh +++ b/qemu.sh @@ -17,7 +17,7 @@ qemu-system-i386 \ pid=$! echo "pid is ${pid}" -i386-elf-gdb KERNEL.BIN -x gdbscript; kill -9 $pid +i386-elf-gdb KERNEL.ELF -x gdbscript; kill -9 $pid echo "kill pid ${pid}" diff --git a/scripts/copy.sh b/scripts/copy.sh index c10d0b0..fc1e011 100755 --- a/scripts/copy.sh +++ b/scripts/copy.sh @@ -10,7 +10,7 @@ PART=${lodev}p1 mount $PART /mnt/ -cp ./KERNEL.BIN /mnt/boot/Kernel +cp ./KERNEL.ELF /mnt/boot/Kernel cp scripts/grub.cfg /mnt/boot/grub2/ md5sum /mnt/boot/Kernel diff --git a/scripts/docker_copy.sh b/scripts/docker_copy.sh index 15ea2a9..d9cf241 100755 --- a/scripts/docker_copy.sh +++ b/scripts/docker_copy.sh @@ -13,7 +13,7 @@ kpartx -u HD.IMG mount $PART /mnt/ -cp ./KERNEL.BIN /mnt/boot/Kernel +cp ./KERNEL.ELF /mnt/boot/Kernel cp scripts/grub.cfg /mnt/boot/grub2/ md5sum /mnt/boot/Kernel diff --git a/scripts/init.sh b/scripts/init.sh index e15671b..b8dfdd0 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -53,7 +53,7 @@ cp grub.cfg ${MNT}/boot/grub2/ sleep 1 # 拷贝内核文件 -cp ../KERNEL.BIN ${MNT}/boot/Kernel +cp ../KERNEL.ELF ${MNT}/boot/Kernel sleep 1 umount $MNT diff --git a/scripts/mkiso.sh b/scripts/mkiso.sh index 8fc2b98..fb98eb0 100755 --- a/scripts/mkiso.sh +++ b/scripts/mkiso.sh @@ -3,5 +3,5 @@ # 因为如果在其它机器上运行,其grub就不是x86版本 mkdir -p /tmp/iso/boot/grub/ cp scripts/iso.grub.cfg /tmp/iso/boot/grub/grub.cfg -cp KERNEL.BIN /tmp/iso/boot/Kernel +cp KERNEL.ELF /tmp/iso/boot/Kernel grub2-mkrescue -o kernel.iso /tmp/iso/