Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 210f2da)
raw | patch | inline | side by side (parent: 210f2da)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 20 Oct 2023 12:43:31 +0000 (20:43 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Sat, 13 Apr 2024 08:17:03 +0000 (16:17 +0800) |
| fs/buffer.c | patch | blob | history | |
| include/buffer.h | patch | blob | history | |
| include/completion.h | patch | blob | history | |
| include/sched.h | patch | blob | history | |
| include/semaphore.h | patch | blob | history | |
| include/task.h | patch | blob | history | |
| include/wait.h | patch | blob | history | |
| kernel/completion.c | patch | blob | history | |
| kernel/irq.c | patch | blob | history |
diff --git a/fs/buffer.c b/fs/buffer.c
--- a/fs/buffer.c
+++ b/fs/buffer.c
assert(NULL != t);
assert(t->block_size == size);
- if (t->ref_count == 0 && t->locked == 0) {
+ if (t->ref_count == 0) {
b = t;
break;
}
goto again;
}
- // 此时b->locked不一定为0
+ // 把它从free_list上删掉
+ list_del_init(&b->node);
+
+ // 虽然此时该bbuffer_t上的ref_count为0但其可能还有I/O操作没有完成
// 因为可能有的进程调用了write、read后再直接调用brelse
- // 虽然此时ref_count为0,但io操作标记的b->locked并未结束
// 所以需要在此等待其结束
- while (b->locked == 1) {
- // 此时是不用担心wake_up在这个sleep_on之前调用
- }
+ wait_completion(&b->io_done);
// 找到了
b->block = block;
b->dev = 0;
b->page = page;
b->uptodate = 0;
- b->locked = 0;
+ init_completion(&b->io_done);
list_init(&b->node);
assert(NULL != b->data);
diff --git a/include/buffer.h b/include/buffer.h
--- a/include/buffer.h
+++ b/include/buffer.h
#pragma once
#include <atomic.h>
+#include <completion.h>
#include <fs.h>
#include <mm.h>
#include <page.h>
#include <system.h>
-
typedef struct bbuffer {
uint32_t block; // block number
void *data; //
dev_t dev;
page_t *page;
list_head_t node;
+ completion_t io_done;
uint16_t block_size; // block size
uint16_t uptodate : 1;
- uint16_t locked : 1;
- uint16_t dirt : 1; // 还不支持
} bbuffer_t;
diff --git a/include/completion.h b/include/completion.h
--- a/include/completion.h
+++ b/include/completion.h
#pragma once
-#if 0
#include <wait.h>
typedef struct completion {
void init_completion(completion_t *x);
void complete(completion_t *x);
-#endif
diff --git a/include/sched.h b/include/sched.h
--- a/include/sched.h
+++ b/include/sched.h
void schedule();
-void wake_up(wait_queue_head_t *wqh);
-
extern task_union root_task;
extern void load_cr3(task_union *tsk);
diff --git a/include/semaphore.h b/include/semaphore.h
--- a/include/semaphore.h
+++ b/include/semaphore.h
// 如果s->cnt == 0 会重新调度进程
volatile void down(semaphore_t *s);
-// volatile bool try_down(semaphore_t *s);
-
// up
// 只会唤醒进程,但不会立即重新调度进程
volatile void up(semaphore_t *s);
diff --git a/include/task.h b/include/task.h
--- a/include/task.h
+++ b/include/task.h
#include <processor.h>
#include <system.h>
#include <types.h>
-#include <wait.h>
+// #include <wait.h>
enum {
TASK_UNUSED,
diff --git a/include/wait.h b/include/wait.h
--- a/include/wait.h
+++ b/include/wait.h
#include <irq.h>
#include <list.h>
-
+#include <sched.h>
union task_union;
typedef struct wait_queue_head {
diff --git a/kernel/completion.c b/kernel/completion.c
--- a/kernel/completion.c
+++ b/kernel/completion.c
* ------------------------------------------------------------------------
*/
-#if 0
#include <completion.h>
#include <sched.h>
x->done = 0;
init_wait_queue_head(&x->wait);
}
-#endif
diff --git a/kernel/irq.c b/kernel/irq.c
--- a/kernel/irq.c
+++ b/kernel/irq.c
#endif
void irq_bh_handler();
+void schedule();
__attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) {
unsigned int irq = regs->irq;