aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/skas
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2005-09-03 18:57:36 -0400
committerLinus Torvalds <torvalds@evo.osdl.org>2005-09-05 03:06:22 -0400
commitc56004901fa5dcf55f92318f192ab3c0e87db2d1 (patch)
treeac53ded16ab9886ce05d4b2d424dfed80dce9e57 /arch/um/kernel/skas
parent77fa5adcda6d686d2f45a2b55dcb9a03e7d33fa1 (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/skas')
-rw-r--r--arch/um/kernel/skas/include/skas.h13
-rw-r--r--arch/um/kernel/skas/mem_user.c112
-rw-r--r--arch/um/kernel/skas/tlb.c23
3 files changed, 111 insertions, 37 deletions
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h
index d983ea842547..e91064b7e5a0 100644
--- a/arch/um/kernel/skas/include/skas.h
+++ b/arch/um/kernel/skas/include/skas.h
@@ -24,11 +24,14 @@ extern void new_thread_proc(void *stack, void (*handler)(int sig));
24extern void remove_sigstack(void); 24extern void remove_sigstack(void);
25extern void new_thread_handler(int sig); 25extern void new_thread_handler(int sig);
26extern void handle_syscall(union uml_pt_regs *regs); 26extern void handle_syscall(union uml_pt_regs *regs);
27extern int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, 27extern void *map(struct mm_id * mm_idp, unsigned long virt,
28 int r, int w, int x, int phys_fd, unsigned long long offset); 28 unsigned long len, int r, int w, int x, int phys_fd,
29extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len); 29 unsigned long long offset, int done, void *data);
30extern int protect(struct mm_id * mm_idp, unsigned long addr, 30extern void *unmap(struct mm_id * mm_idp, void *addr,
31 unsigned long len, int r, int w, int x); 31 unsigned long len, int done, void *data);
32extern void *protect(struct mm_id * mm_idp, unsigned long addr,
33 unsigned long len, int r, int w, int x, int done,
34 void *data);
32extern void user_signal(int sig, union uml_pt_regs *regs, int pid); 35extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
33extern int new_mm(int from); 36extern int new_mm(int from);
34extern int start_userspace(unsigned long stub_stack); 37extern int start_userspace(unsigned long stub_stack);
diff --git a/arch/um/kernel/skas/mem_user.c b/arch/um/kernel/skas/mem_user.c
index b0980ff3bd95..c976320ebe84 100644
--- a/arch/um/kernel/skas/mem_user.c
+++ b/arch/um/kernel/skas/mem_user.c
@@ -25,12 +25,14 @@
25#include "sysdep/stub.h" 25#include "sysdep/stub.h"
26#include "skas.h" 26#include "skas.h"
27 27
28extern unsigned long syscall_stub, __syscall_stub_start; 28extern unsigned long syscall_stub, batch_syscall_stub, __syscall_stub_start;
29 29
30extern void wait_stub_done(int pid, int sig, char * fname); 30extern void wait_stub_done(int pid, int sig, char * fname);
31 31
32static long run_syscall_stub(struct mm_id * mm_idp, int syscall, 32int single_count = 0;
33 unsigned long *args) 33
34static long one_syscall_stub(struct mm_id * mm_idp, int syscall,
35 unsigned long *args)
34{ 36{
35 int n, pid = mm_idp->u.pid; 37 int n, pid = mm_idp->u.pid;
36 unsigned long regs[MAX_REG_NR]; 38 unsigned long regs[MAX_REG_NR];
@@ -49,18 +51,80 @@ static long run_syscall_stub(struct mm_id * mm_idp, int syscall,
49 regs[REGS_SYSCALL_ARG6] = args[5]; 51 regs[REGS_SYSCALL_ARG6] = args[5];
50 n = ptrace_setregs(pid, regs); 52 n = ptrace_setregs(pid, regs);
51 if(n < 0){ 53 if(n < 0){
52 printk("run_syscall_stub : PTRACE_SETREGS failed, " 54 printk("one_syscall_stub : PTRACE_SETREGS failed, "
55 "errno = %d\n", n);
56 return(n);
57 }
58
59 wait_stub_done(pid, 0, "one_syscall_stub");
60
61 return(*((unsigned long *) mm_idp->stack));
62}
63
64int multi_count = 0;
65int multi_op_count = 0;
66
67static long many_syscall_stub(struct mm_id * mm_idp, int syscall,
68 unsigned long *args, int done, void **addr_out)
69{
70 unsigned long regs[MAX_REG_NR], *stack;
71 int n, pid = mm_idp->u.pid;
72
73 stack = *addr_out;
74 if(stack == NULL)
75 stack = (unsigned long *) current_stub_stack();
76 *stack++ = syscall;
77 *stack++ = args[0];
78 *stack++ = args[1];
79 *stack++ = args[2];
80 *stack++ = args[3];
81 *stack++ = args[4];
82 *stack++ = args[5];
83 *stack = 0;
84 multi_op_count++;
85
86 if(!done && ((((unsigned long) stack) & ~PAGE_MASK) <
87 PAGE_SIZE - 8 * sizeof(long))){
88 *addr_out = stack;
89 return 0;
90 }
91
92 multi_count++;
93 get_safe_registers(regs);
94 regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE +
95 ((unsigned long) &batch_syscall_stub -
96 (unsigned long) &__syscall_stub_start);
97 regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA;
98
99 n = ptrace_setregs(pid, regs);
100 if(n < 0){
101 printk("many_syscall_stub : PTRACE_SETREGS failed, "
53 "errno = %d\n", n); 102 "errno = %d\n", n);
54 return(n); 103 return(n);
55 } 104 }
56 105
57 wait_stub_done(pid, 0, "run_syscall_stub"); 106 wait_stub_done(pid, 0, "many_syscall_stub");
107 stack = (unsigned long *) mm_idp->stack;
58 108
59 return(*((unsigned long *) mm_idp->stack)); 109 *addr_out = stack;
110 return(*stack);
60} 111}
61 112
62int map(struct mm_id *mm_idp, unsigned long virt, unsigned long len, 113static long run_syscall_stub(struct mm_id * mm_idp, int syscall,
63 int r, int w, int x, int phys_fd, unsigned long long offset) 114 unsigned long *args, void **addr, int done)
115{
116 long res;
117
118 if((*addr == NULL) && done)
119 res = one_syscall_stub(mm_idp, syscall, args);
120 else res = many_syscall_stub(mm_idp, syscall, args, done, addr);
121
122 return res;
123}
124
125void *map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
126 int r, int w, int x, int phys_fd, unsigned long long offset,
127 int done, void *data)
64{ 128{
65 int prot, n; 129 int prot, n;
66 130
@@ -70,6 +134,7 @@ int map(struct mm_id *mm_idp, unsigned long virt, unsigned long len,
70 if(proc_mm){ 134 if(proc_mm){
71 struct proc_mm_op map; 135 struct proc_mm_op map;
72 int fd = mm_idp->u.mm_fd; 136 int fd = mm_idp->u.mm_fd;
137
73 map = ((struct proc_mm_op) { .op = MM_MMAP, 138 map = ((struct proc_mm_op) { .op = MM_MMAP,
74 .u = 139 .u =
75 { .mmap = 140 { .mmap =
@@ -91,21 +156,24 @@ int map(struct mm_id *mm_idp, unsigned long virt, unsigned long len,
91 MAP_SHARED | MAP_FIXED, phys_fd, 156 MAP_SHARED | MAP_FIXED, phys_fd,
92 MMAP_OFFSET(offset) }; 157 MMAP_OFFSET(offset) };
93 158
94 res = run_syscall_stub(mm_idp, STUB_MMAP_NR, args); 159 res = run_syscall_stub(mm_idp, STUB_MMAP_NR, args,
160 &data, done);
95 if((void *) res == MAP_FAILED) 161 if((void *) res == MAP_FAILED)
96 printk("mmap stub failed, errno = %d\n", res); 162 printk("mmap stub failed, errno = %d\n", res);
97 } 163 }
98 164
99 return 0; 165 return data;
100} 166}
101 167
102int unmap(struct mm_id *mm_idp, void *addr, unsigned long len) 168void *unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done,
169 void *data)
103{ 170{
104 int n; 171 int n;
105 172
106 if(proc_mm){ 173 if(proc_mm){
107 struct proc_mm_op unmap; 174 struct proc_mm_op unmap;
108 int fd = mm_idp->u.mm_fd; 175 int fd = mm_idp->u.mm_fd;
176
109 unmap = ((struct proc_mm_op) { .op = MM_MUNMAP, 177 unmap = ((struct proc_mm_op) { .op = MM_MUNMAP,
110 .u = 178 .u =
111 { .munmap = 179 { .munmap =
@@ -113,28 +181,25 @@ int unmap(struct mm_id *mm_idp, void *addr, unsigned long len)
113 (unsigned long) addr, 181 (unsigned long) addr,
114 .len = len } } } ); 182 .len = len } } } );
115 n = os_write_file(fd, &unmap, sizeof(unmap)); 183 n = os_write_file(fd, &unmap, sizeof(unmap));
116 if(n != sizeof(unmap)) { 184 if(n != sizeof(unmap))
117 if(n < 0) 185 printk("unmap - proc_mm write returned %d\n", n);
118 return(n);
119 else if(n > 0)
120 return(-EIO);
121 }
122 } 186 }
123 else { 187 else {
124 int res; 188 int res;
125 unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0, 189 unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0,
126 0 }; 190 0 };
127 191
128 res = run_syscall_stub(mm_idp, __NR_munmap, args); 192 res = run_syscall_stub(mm_idp, __NR_munmap, args,
193 &data, done);
129 if(res < 0) 194 if(res < 0)
130 printk("munmap stub failed, errno = %d\n", res); 195 printk("munmap stub failed, errno = %d\n", res);
131 } 196 }
132 197
133 return(0); 198 return data;
134} 199}
135 200
136int protect(struct mm_id *mm_idp, unsigned long addr, unsigned long len, 201void *protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
137 int r, int w, int x) 202 int r, int w, int x, int done, void *data)
138{ 203{
139 struct proc_mm_op protect; 204 struct proc_mm_op protect;
140 int prot, n; 205 int prot, n;
@@ -160,12 +225,13 @@ int protect(struct mm_id *mm_idp, unsigned long addr, unsigned long len,
160 int res; 225 int res;
161 unsigned long args[] = { addr, len, prot, 0, 0, 0 }; 226 unsigned long args[] = { addr, len, prot, 0, 0, 0 };
162 227
163 res = run_syscall_stub(mm_idp, __NR_mprotect, args); 228 res = run_syscall_stub(mm_idp, __NR_mprotect, args,
229 &data, done);
164 if(res < 0) 230 if(res < 0)
165 panic("mprotect stub failed, errno = %d\n", res); 231 panic("mprotect stub failed, errno = %d\n", res);
166 } 232 }
167 233
168 return(0); 234 return data;
169} 235}
170 236
171void before_mem_skas(unsigned long unused) 237void before_mem_skas(unsigned long unused)
diff --git a/arch/um/kernel/skas/tlb.c b/arch/um/kernel/skas/tlb.c
index 6230999c672c..4b5fd2049547 100644
--- a/arch/um/kernel/skas/tlb.c
+++ b/arch/um/kernel/skas/tlb.c
@@ -18,7 +18,8 @@
18#include "os.h" 18#include "os.h"
19#include "tlb.h" 19#include "tlb.h"
20 20
21static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last) 21static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
22 int finished, void *flush)
22{ 23{
23 struct host_vm_op *op; 24 struct host_vm_op *op;
24 int i; 25 int i;
@@ -27,24 +28,28 @@ static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last)
27 op = &ops[i]; 28 op = &ops[i];
28 switch(op->type){ 29 switch(op->type){
29 case MMAP: 30 case MMAP:
30 map(&mmu->skas.id, op->u.mmap.addr, op->u.mmap.len, 31 flush = map(&mmu->skas.id, op->u.mmap.addr,
31 op->u.mmap.r, op->u.mmap.w, op->u.mmap.x, 32 op->u.mmap.len, op->u.mmap.r, op->u.mmap.w,
32 op->u.mmap.fd, op->u.mmap.offset); 33 op->u.mmap.x, op->u.mmap.fd,
34 op->u.mmap.offset, finished, flush);
33 break; 35 break;
34 case MUNMAP: 36 case MUNMAP:
35 unmap(&mmu->skas.id, (void *) op->u.munmap.addr, 37 flush = unmap(&mmu->skas.id, (void *) op->u.munmap.addr,
36 op->u.munmap.len); 38 op->u.munmap.len, finished, flush);
37 break; 39 break;
38 case MPROTECT: 40 case MPROTECT:
39 protect(&mmu->skas.id, op->u.mprotect.addr, 41 flush = protect(&mmu->skas.id, op->u.mprotect.addr,
40 op->u.mprotect.len, op->u.mprotect.r, 42 op->u.mprotect.len, op->u.mprotect.r,
41 op->u.mprotect.w, op->u.mprotect.x); 43 op->u.mprotect.w, op->u.mprotect.x,
44 finished, flush);
42 break; 45 break;
43 default: 46 default:
44 printk("Unknown op type %d in do_ops\n", op->type); 47 printk("Unknown op type %d in do_ops\n", op->type);
45 break; 48 break;
46 } 49 }
47 } 50 }
51
52 return flush;
48} 53}
49 54
50extern int proc_mm; 55extern int proc_mm;