-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.diff
199 lines (195 loc) · 5.1 KB
/
kernel.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff --git a/block/Kconfig.iosched b/block/Kconfig.iosched
index f95a48b0d7b2..05f07a713dd7 100644
--- a/block/Kconfig.iosched
+++ b/block/Kconfig.iosched
@@ -22,6 +22,14 @@ config IOSCHED_DEADLINE
a new point in the service tree and doing a batch of IO from there
in case of expiry.
+config IOSCHED_CLOOK
+ tristate "CLOOK I/O scheduler"
+ default y
+ ---help---
+ The c-look I/O scheduler is modified from the no-op I/O scheduler.
+ It will sort requests as they are added to the queue, relative to the
+ current head position.
+
config IOSCHED_CFQ
tristate "CFQ I/O scheduler"
default y
@@ -56,6 +64,9 @@ choice
config DEFAULT_NOOP
bool "No-op"
+ config DEFAULT_CLOOK
+ bool "CLOOK" if IOSCHED_CLOOK=y
+
endchoice
config DEFAULT_IOSCHED
@@ -63,6 +74,7 @@ config DEFAULT_IOSCHED
default "deadline" if DEFAULT_DEADLINE
default "cfq" if DEFAULT_CFQ
default "noop" if DEFAULT_NOOP
+ default "clook" if DEFAULT_CLOOK
config MQ_IOSCHED_DEADLINE
tristate "MQ deadline I/O scheduler"
diff --git a/block/Makefile b/block/Makefile
index 27eac600474f..fcce26c44273 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -38,3 +38,4 @@ obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o
obj-$(CONFIG_BLK_DEBUG_FS_ZONED)+= blk-mq-debugfs-zoned.o
obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o
obj-$(CONFIG_BLK_PM) += blk-pm.o
+obj-$(CONFIG_IOSCHED_CLOOK) += clook-iosched.o
diff --git a/block/clook-iosched.c b/block/clook-iosched.c
new file mode 100644
index 000000000000..62e5aa7f8fba
--- /dev/null
+++ b/block/clook-iosched.c
@@ -0,0 +1,147 @@
+/*
+ * elevator clook
+ */
+#include <linux/blkdev.h>
+#include <linux/elevator.h>
+#include <linux/bio.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+
+struct clook_data {
+ struct list_head queue;
+};
+
+static void clook_merged_requests(struct request_queue *q, struct request *rq,
+ struct request *next)
+{
+ list_del_init(&next->queuelist);
+}
+/**
+ * Instrumented to report activity.
+ */
+static int clook_dispatch(struct request_queue *q, int force)
+{
+ struct clook_data *nd = q->elevator->elevator_data;
+ struct request *rq;
+
+ rq = list_first_entry_or_null(&nd->queue, struct request, queuelist);
+ if (rq) {
+ list_del_init(&rq->queuelist);
+ elv_dispatch_sort(q, rq);
+ char direction = ((rq->cmd_flags & 1) ? 'W' : 'R');
+ printk("[CLOOK] dsp %c %lu\n", direction, blk_rq_pos(rq));
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * Modified function
+ * Notes:
+ * - The list we are inserting into is sorted,
+ * because new entries are only added by our function.
+ * - Adjacent requests should be merged.
+ * - Instrumented to report activity.
+ */
+static void clook_add_request(struct request_queue *q, struct request *rq)
+{
+ struct clook_data *nd = q->elevator->elevator_data;
+ //cursor for selecting where to insert
+ struct list_head *cur = NULL;
+
+ //We can assume the array is already sorted, so insert as if inserting into a sorted array
+ list_for_each(cur, &nd->queue) {
+ if(rq_end_sector(list_entry(cur, struct request,queuelist)) > rq_end_sector(rq)) {
+ break;
+ }
+ }
+
+ list_add_tail(&rq->queuelist, &nd->queue);
+ char direction = ((rq->cmd_flags & 1) ? 'W' : 'R');
+ printk("[CLOOK] add %c %lu\n", direction, blk_rq_pos(rq));
+}
+
+static struct request *
+clook_former_request(struct request_queue *q, struct request *rq)
+{
+ struct clook_data *nd = q->elevator->elevator_data;
+
+ if (rq->queuelist.prev == &nd->queue)
+ return NULL;
+ return list_prev_entry(rq, queuelist);
+}
+
+static struct request *
+clook_latter_request(struct request_queue *q, struct request *rq)
+{
+ struct clook_data *nd = q->elevator->elevator_data;
+
+ if (rq->queuelist.next == &nd->queue)
+ return NULL;
+ return list_next_entry(rq, queuelist);
+}
+
+static int clook_init_queue(struct request_queue *q, struct elevator_type *e)
+{
+ struct clook_data *nd;
+ struct elevator_queue *eq;
+
+ eq = elevator_alloc(q, e);
+ if (!eq)
+ return -ENOMEM;
+
+ nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
+ if (!nd) {
+ kobject_put(&eq->kobj);
+ return -ENOMEM;
+ }
+ eq->elevator_data = nd;
+
+ INIT_LIST_HEAD(&nd->queue);
+
+ spin_lock_irq(q->queue_lock);
+ q->elevator = eq;
+ spin_unlock_irq(q->queue_lock);
+ return 0;
+}
+
+static void clook_exit_queue(struct elevator_queue *e)
+{
+ struct clook_data *nd = e->elevator_data;
+
+ BUG_ON(!list_empty(&nd->queue));
+ kfree(nd);
+}
+
+static struct elevator_type elevator_clook = {
+ .ops.sq = {
+ .elevator_merge_req_fn = clook_merged_requests,
+ .elevator_dispatch_fn = clook_dispatch,
+ .elevator_add_req_fn = clook_add_request,
+ .elevator_former_req_fn = clook_former_request,
+ .elevator_latter_req_fn = clook_latter_request,
+ .elevator_init_fn = clook_init_queue,
+ .elevator_exit_fn = clook_exit_queue,
+ },
+ .elevator_name = "clook",
+ .elevator_owner = THIS_MODULE,
+};
+
+static int __init clook_init(void)
+{
+ return elv_register(&elevator_clook);
+}
+
+static void __exit clook_exit(void)
+{
+ elv_unregister(&elevator_clook);
+}
+
+module_init(clook_init);
+module_exit(clook_exit);
+
+
+MODULE_AUTHOR("David Ramirez");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("C-LOOK IO scheduler");