diff options
author | Jeff Dike <jdike@addtoit.com> | 2005-09-03 18:57:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@evo.osdl.org> | 2005-09-05 03:06:22 -0400 |
commit | c56004901fa5dcf55f92318f192ab3c0e87db2d1 (patch) | |
tree | ac53ded16ab9886ce05d4b2d424dfed80dce9e57 /arch/um/kernel/tlb.c | |
parent | 77fa5adcda6d686d2f45a2b55dcb9a03e7d33fa1 (diff) |
[PATCH] uml: TLB operation batching
This adds VM op batching to skas0. Rather than having a context switch to and
from the userspace stub for each address space change, we write a number of
operations to the stub data page and invoke a different stub which loops over
them and executes them all in one go.
The operations are stored as [ system call number, arg1, arg2, ... ] tuples.
The set is terminated by a system call number of 0. Single operations, i.e.
page faults, are handled in the old way, since that is slightly more
efficient.
For a kernel build, a minority (~1/4) of the operations are part of a set.
These sets averaged ~100 in length, so for this quarter, the context switching
overhead is greatly reduced.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel/tlb.c')
-rw-r--r-- | arch/um/kernel/tlb.c | 226 |
1 files changed, 116 insertions, 110 deletions
diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c index 83ec8d4747fd..7d914bb6b002 100644 --- a/arch/um/kernel/tlb.c +++ b/arch/um/kernel/tlb.c | |||
@@ -15,12 +15,116 @@ | |||
15 | #include "mem_user.h" | 15 | #include "mem_user.h" |
16 | #include "os.h" | 16 | #include "os.h" |
17 | 17 | ||
18 | static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len, | ||
19 | int r, int w, int x, struct host_vm_op *ops, int index, | ||
20 | int last_filled, union mm_context *mmu, void **flush, | ||
21 | void *(*do_ops)(union mm_context *, struct host_vm_op *, | ||
22 | int, int, void *)) | ||
23 | { | ||
24 | __u64 offset; | ||
25 | struct host_vm_op *last; | ||
26 | int fd; | ||
27 | |||
28 | fd = phys_mapping(phys, &offset); | ||
29 | if(index != -1){ | ||
30 | last = &ops[index]; | ||
31 | if((last->type == MMAP) && | ||
32 | (last->u.mmap.addr + last->u.mmap.len == virt) && | ||
33 | (last->u.mmap.r == r) && (last->u.mmap.w == w) && | ||
34 | (last->u.mmap.x == x) && (last->u.mmap.fd == fd) && | ||
35 | (last->u.mmap.offset + last->u.mmap.len == offset)){ | ||
36 | last->u.mmap.len += len; | ||
37 | return index; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | if(index == last_filled){ | ||
42 | *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); | ||
43 | index = -1; | ||
44 | } | ||
45 | |||
46 | ops[++index] = ((struct host_vm_op) { .type = MMAP, | ||
47 | .u = { .mmap = { | ||
48 | .addr = virt, | ||
49 | .len = len, | ||
50 | .r = r, | ||
51 | .w = w, | ||
52 | .x = x, | ||
53 | .fd = fd, | ||
54 | .offset = offset } | ||
55 | } }); | ||
56 | return index; | ||
57 | } | ||
58 | |||
59 | static int add_munmap(unsigned long addr, unsigned long len, | ||
60 | struct host_vm_op *ops, int index, int last_filled, | ||
61 | union mm_context *mmu, void **flush, | ||
62 | void *(*do_ops)(union mm_context *, struct host_vm_op *, | ||
63 | int, int, void *)) | ||
64 | { | ||
65 | struct host_vm_op *last; | ||
66 | |||
67 | if(index != -1){ | ||
68 | last = &ops[index]; | ||
69 | if((last->type == MUNMAP) && | ||
70 | (last->u.munmap.addr + last->u.mmap.len == addr)){ | ||
71 | last->u.munmap.len += len; | ||
72 | return index; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | if(index == last_filled){ | ||
77 | *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); | ||
78 | index = -1; | ||
79 | } | ||
80 | |||
81 | ops[++index] = ((struct host_vm_op) { .type = MUNMAP, | ||
82 | .u = { .munmap = { | ||
83 | .addr = addr, | ||
84 | .len = len } } }); | ||
85 | return index; | ||
86 | } | ||
87 | |||
88 | static int add_mprotect(unsigned long addr, unsigned long len, int r, int w, | ||
89 | int x, struct host_vm_op *ops, int index, | ||
90 | int last_filled, union mm_context *mmu, void **flush, | ||
91 | void *(*do_ops)(union mm_context *, | ||
92 | struct host_vm_op *, int, int, void *)) | ||
93 | { | ||
94 | struct host_vm_op *last; | ||
95 | |||
96 | if(index != -1){ | ||
97 | last = &ops[index]; | ||
98 | if((last->type == MPROTECT) && | ||
99 | (last->u.mprotect.addr + last->u.mprotect.len == addr) && | ||
100 | (last->u.mprotect.r == r) && (last->u.mprotect.w == w) && | ||
101 | (last->u.mprotect.x == x)){ | ||
102 | last->u.mprotect.len += len; | ||
103 | return index; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | if(index == last_filled){ | ||
108 | *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); | ||
109 | index = -1; | ||
110 | } | ||
111 | |||
112 | ops[++index] = ((struct host_vm_op) { .type = MPROTECT, | ||
113 | .u = { .mprotect = { | ||
114 | .addr = addr, | ||
115 | .len = len, | ||
116 | .r = r, | ||
117 | .w = w, | ||
118 | .x = x } } }); | ||
119 | return index; | ||
120 | } | ||
121 | |||
18 | #define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1)) | 122 | #define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1)) |
19 | 123 | ||
20 | void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | 124 | void fix_range_common(struct mm_struct *mm, unsigned long start_addr, |
21 | unsigned long end_addr, int force, | 125 | unsigned long end_addr, int force, |
22 | void (*do_ops)(union mm_context *, struct host_vm_op *, | 126 | void *(*do_ops)(union mm_context *, struct host_vm_op *, |
23 | int)) | 127 | int, int, void *)) |
24 | { | 128 | { |
25 | pgd_t *npgd; | 129 | pgd_t *npgd; |
26 | pud_t *npud; | 130 | pud_t *npud; |
@@ -29,11 +133,13 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | |||
29 | union mm_context *mmu = &mm->context; | 133 | union mm_context *mmu = &mm->context; |
30 | unsigned long addr, end; | 134 | unsigned long addr, end; |
31 | int r, w, x; | 135 | int r, w, x; |
32 | struct host_vm_op ops[16]; | 136 | struct host_vm_op ops[1]; |
137 | void *flush = NULL; | ||
33 | int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1; | 138 | int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1; |
34 | 139 | ||
35 | if(mm == NULL) return; | 140 | if(mm == NULL) return; |
36 | 141 | ||
142 | ops[0].type = NONE; | ||
37 | for(addr = start_addr; addr < end_addr;){ | 143 | for(addr = start_addr; addr < end_addr;){ |
38 | npgd = pgd_offset(mm, addr); | 144 | npgd = pgd_offset(mm, addr); |
39 | if(!pgd_present(*npgd)){ | 145 | if(!pgd_present(*npgd)){ |
@@ -43,7 +149,7 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | |||
43 | if(force || pgd_newpage(*npgd)){ | 149 | if(force || pgd_newpage(*npgd)){ |
44 | op_index = add_munmap(addr, end - addr, ops, | 150 | op_index = add_munmap(addr, end - addr, ops, |
45 | op_index, last_op, mmu, | 151 | op_index, last_op, mmu, |
46 | do_ops); | 152 | &flush, do_ops); |
47 | pgd_mkuptodate(*npgd); | 153 | pgd_mkuptodate(*npgd); |
48 | } | 154 | } |
49 | addr = end; | 155 | addr = end; |
@@ -58,7 +164,7 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | |||
58 | if(force || pud_newpage(*npud)){ | 164 | if(force || pud_newpage(*npud)){ |
59 | op_index = add_munmap(addr, end - addr, ops, | 165 | op_index = add_munmap(addr, end - addr, ops, |
60 | op_index, last_op, mmu, | 166 | op_index, last_op, mmu, |
61 | do_ops); | 167 | &flush, do_ops); |
62 | pud_mkuptodate(*npud); | 168 | pud_mkuptodate(*npud); |
63 | } | 169 | } |
64 | addr = end; | 170 | addr = end; |
@@ -73,7 +179,7 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | |||
73 | if(force || pmd_newpage(*npmd)){ | 179 | if(force || pmd_newpage(*npmd)){ |
74 | op_index = add_munmap(addr, end - addr, ops, | 180 | op_index = add_munmap(addr, end - addr, ops, |
75 | op_index, last_op, mmu, | 181 | op_index, last_op, mmu, |
76 | do_ops); | 182 | &flush, do_ops); |
77 | pmd_mkuptodate(*npmd); | 183 | pmd_mkuptodate(*npmd); |
78 | } | 184 | } |
79 | addr = end; | 185 | addr = end; |
@@ -96,20 +202,20 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr, | |||
96 | pte_val(*npte) & PAGE_MASK, | 202 | pte_val(*npte) & PAGE_MASK, |
97 | PAGE_SIZE, r, w, x, ops, | 203 | PAGE_SIZE, r, w, x, ops, |
98 | op_index, last_op, mmu, | 204 | op_index, last_op, mmu, |
99 | do_ops); | 205 | &flush, do_ops); |
100 | else op_index = add_munmap(addr, PAGE_SIZE, ops, | 206 | else op_index = add_munmap(addr, PAGE_SIZE, ops, |
101 | op_index, last_op, mmu, | 207 | op_index, last_op, mmu, |
102 | do_ops); | 208 | &flush, do_ops); |
103 | } | 209 | } |
104 | else if(pte_newprot(*npte)) | 210 | else if(pte_newprot(*npte)) |
105 | op_index = add_mprotect(addr, PAGE_SIZE, r, w, x, ops, | 211 | op_index = add_mprotect(addr, PAGE_SIZE, r, w, x, ops, |
106 | op_index, last_op, mmu, | 212 | op_index, last_op, mmu, |
107 | do_ops); | 213 | &flush, do_ops); |
108 | 214 | ||
109 | *npte = pte_mkuptodate(*npte); | 215 | *npte = pte_mkuptodate(*npte); |
110 | addr += PAGE_SIZE; | 216 | addr += PAGE_SIZE; |
111 | } | 217 | } |
112 | (*do_ops)(mmu, ops, op_index); | 218 | flush = (*do_ops)(mmu, ops, op_index, 1, flush); |
113 | } | 219 | } |
114 | 220 | ||
115 | int flush_tlb_kernel_range_common(unsigned long start, unsigned long end) | 221 | int flush_tlb_kernel_range_common(unsigned long start, unsigned long end) |
@@ -226,106 +332,6 @@ pte_t *addr_pte(struct task_struct *task, unsigned long addr) | |||
226 | return(pte_offset_map(pmd, addr)); | 332 | return(pte_offset_map(pmd, addr)); |
227 | } | 333 | } |
228 | 334 | ||
229 | int add_mmap(unsigned long virt, unsigned long phys, unsigned long len, | ||
230 | int r, int w, int x, struct host_vm_op *ops, int index, | ||
231 | int last_filled, union mm_context *mmu, | ||
232 | void (*do_ops)(union mm_context *, struct host_vm_op *, int)) | ||
233 | { | ||
234 | __u64 offset; | ||
235 | struct host_vm_op *last; | ||
236 | int fd; | ||
237 | |||
238 | fd = phys_mapping(phys, &offset); | ||
239 | if(index != -1){ | ||
240 | last = &ops[index]; | ||
241 | if((last->type == MMAP) && | ||
242 | (last->u.mmap.addr + last->u.mmap.len == virt) && | ||
243 | (last->u.mmap.r == r) && (last->u.mmap.w == w) && | ||
244 | (last->u.mmap.x == x) && (last->u.mmap.fd == fd) && | ||
245 | (last->u.mmap.offset + last->u.mmap.len == offset)){ | ||
246 | last->u.mmap.len += len; | ||
247 | return(index); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | if(index == last_filled){ | ||
252 | (*do_ops)(mmu, ops, last_filled); | ||
253 | index = -1; | ||
254 | } | ||
255 | |||
256 | ops[++index] = ((struct host_vm_op) { .type = MMAP, | ||
257 | .u = { .mmap = { | ||
258 | .addr = virt, | ||
259 | .len = len, | ||
260 | .r = r, | ||
261 | .w = w, | ||
262 | .x = x, | ||
263 | .fd = fd, | ||
264 | .offset = offset } | ||
265 | } }); | ||
266 | return(index); | ||
267 | } | ||
268 | |||
269 | int add_munmap(unsigned long addr, unsigned long len, struct host_vm_op *ops, | ||
270 | int index, int last_filled, union mm_context *mmu, | ||
271 | void (*do_ops)(union mm_context *, struct host_vm_op *, int)) | ||
272 | { | ||
273 | struct host_vm_op *last; | ||
274 | |||
275 | if(index != -1){ | ||
276 | last = &ops[index]; | ||
277 | if((last->type == MUNMAP) && | ||
278 | (last->u.munmap.addr + last->u.mmap.len == addr)){ | ||
279 | last->u.munmap.len += len; | ||
280 | return(index); | ||
281 | } | ||
282 | } | ||
283 | |||
284 | if(index == last_filled){ | ||
285 | (*do_ops)(mmu, ops, last_filled); | ||
286 | index = -1; | ||
287 | } | ||
288 | |||
289 | ops[++index] = ((struct host_vm_op) { .type = MUNMAP, | ||
290 | .u = { .munmap = { | ||
291 | .addr = addr, | ||
292 | .len = len } } }); | ||
293 | return(index); | ||
294 | } | ||
295 | |||
296 | int add_mprotect(unsigned long addr, unsigned long len, int r, int w, int x, | ||
297 | struct host_vm_op *ops, int index, int last_filled, | ||
298 | union mm_context *mmu, | ||
299 | void (*do_ops)(union mm_context *, struct host_vm_op *, int)) | ||
300 | { | ||
301 | struct host_vm_op *last; | ||
302 | |||
303 | if(index != -1){ | ||
304 | last = &ops[index]; | ||
305 | if((last->type == MPROTECT) && | ||
306 | (last->u.mprotect.addr + last->u.mprotect.len == addr) && | ||
307 | (last->u.mprotect.r == r) && (last->u.mprotect.w == w) && | ||
308 | (last->u.mprotect.x == x)){ | ||
309 | last->u.mprotect.len += len; | ||
310 | return(index); | ||
311 | } | ||
312 | } | ||
313 | |||
314 | if(index == last_filled){ | ||
315 | (*do_ops)(mmu, ops, last_filled); | ||
316 | index = -1; | ||
317 | } | ||
318 | |||
319 | ops[++index] = ((struct host_vm_op) { .type = MPROTECT, | ||
320 | .u = { .mprotect = { | ||
321 | .addr = addr, | ||
322 | .len = len, | ||
323 | .r = r, | ||
324 | .w = w, | ||
325 | .x = x } } }); | ||
326 | return(index); | ||
327 | } | ||
328 | |||
329 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long address) | 335 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long address) |
330 | { | 336 | { |
331 | address &= PAGE_MASK; | 337 | address &= PAGE_MASK; |