| 1 | #include <block/block.h> |
|---|---|
| 2 | #include <block/sched.h> |
| 3 | #include <console/printf.h> |
| 4 | #include <mem/alloc.h> |
| 5 | #include <stdint.h> |
| 6 | #include <structures/dll.h> |
| 7 | #include <sync/spinlock.h> |
| 8 | #include <thread/workqueue.h> |
| 9 | #include <time/time.h> |
| 10 | |
| 11 | /* enqueuing skips enqueuing if the req is URGENT */ |
| 12 | |
| 13 | void bio_sched_enqueue_internal(struct bio_scheduler *sched, |
| 14 | struct bio_request *req) { |
| 15 | if (submit_if_urgent(sched, req)) |
| 16 | return; |
| 17 | |
| 18 | MUTEX_ASSERT_HELD(&sched->lock); |
| 19 | update_request_timestamp(req); |
| 20 | enum bio_request_priority prio = req->priority; |
| 21 | struct bio_rqueue *q = &sched->queues[prio]; |
| 22 | |
| 23 | list_add_tail(new: &req->list, head: &q->list); |
| 24 | |
| 25 | q->dirty = true; |
| 26 | q->request_count++; |
| 27 | sched->total_requests++; |
| 28 | } |
| 29 | |
| 30 | void bio_sched_dequeue_internal(struct bio_scheduler *sched, |
| 31 | struct bio_request *req) { |
| 32 | MUTEX_ASSERT_HELD(&sched->lock); |
| 33 | enum bio_request_priority prio = req->priority; |
| 34 | struct bio_rqueue *q = &sched->queues[prio]; |
| 35 | |
| 36 | list_del_init(entry: &req->list); |
| 37 | |
| 38 | q->dirty = true; |
| 39 | q->request_count--; |
| 40 | sched->total_requests--; |
| 41 | } |
| 42 |