Skip to contentSkip to conversation

UML - TLB operation batching

PATCH In review Jeff Dike 1 participant 1 message Aug 29, 2005 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 7/9 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.

arch/um/include/tlb.h +4 -18
Index: linux-2.6.12/arch/um/include/tlb.h
===================================================================
@@ -9,7 +9,7 @@
 #include "um_mmu.h"
 
 struct host_vm_op {
-	enum { MMAP, MUNMAP, MPROTECT } type;
+	enum { NONE, MMAP, MUNMAP, MPROTECT } type;
 	union {
 		struct {
 			unsigned long addr;
@@ -38,24 +38,10 @@
 extern void force_flush_all(void);
 extern void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
                              unsigned long end_addr, int force,
-                             void (*do_ops)(union mm_context *,
-                                            struct host_vm_op *, int));
+			     void *(*do_ops)(union mm_context *, 
+					     struct host_vm_op *, int, int,
+					     void *));
 extern int flush_tlb_kernel_range_common(unsigned long start,
 					 unsigned long end);
 
-extern int add_mmap(unsigned long virt, unsigned long phys, unsigned long len,
-		    int r, int w, int x, struct host_vm_op *ops, int index,
-                    int last_filled, union mm_context *mmu,
-                    void (*do_ops)(union mm_context *, struct host_vm_op *,
-                                   int));
-extern int add_munmap(unsigned long addr, unsigned long len,
-		      struct host_vm_op *ops, int index, int last_filled,
-                      union mm_context *mmu,
-                      void (*do_ops)(union mm_context *, struct host_vm_op *,
-                                     int));
-extern int add_mprotect(unsigned long addr, unsigned long len, int r, int w,
-			int x, struct host_vm_op *ops, int index,
-                        int last_filled, union mm_context *mmu,
-                        void (*do_ops)(union mm_context *, struct host_vm_op *,
-                                       int));
 #endif
arch/um/kernel/skas/include/skas.h +8 -5
Index: linux-2.6.12/arch/um/kernel/skas/include/skas.h
===================================================================
@@ -24,11 +24,14 @@
 extern void remove_sigstack(void);
 extern void new_thread_handler(int sig);
 extern void handle_syscall(union uml_pt_regs *regs);
-extern int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
-               int r, int w, int x, int phys_fd, unsigned long long offset);
-extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len);
-extern int protect(struct mm_id * mm_idp, unsigned long addr,
-		   unsigned long len, int r, int w, int x);
+extern void *map(struct mm_id * mm_idp, unsigned long virt, 
+		 unsigned long len, int r, int w, int x, int phys_fd, 
+		 unsigned long long offset, int done, void *data);
+extern void *unmap(struct mm_id * mm_idp, void *addr, 
+		   unsigned long len, int done, void *data);
+extern void *protect(struct mm_id * mm_idp, unsigned long addr, 
+		     unsigned long len, int r, int w, int x, int done, 
+		     void *data);
 extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
 extern int new_mm(int from);
 extern int start_userspace(unsigned long stub_stack);
arch/um/kernel/skas/mem_user.c +89 -23

186 lines not on this page · raw message

arch/um/kernel/skas/tlb.c +14 -9
Index: linux-2.6.12/arch/um/kernel/skas/tlb.c
===================================================================
@@ -18,7 +18,8 @@
 #include "os.h"
 #include "tlb.h"
 
-static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last)
+static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
+		    int finished, void *flush)
 {
 	struct host_vm_op *op;
 	int i;
@@ -27,24 +28,28 @@
 		op = &ops[i];
 		switch(op->type){
 		case MMAP:
-                        map(&mmu->skas.id, op->u.mmap.addr, op->u.mmap.len,
-			    op->u.mmap.r, op->u.mmap.w, op->u.mmap.x,
-			    op->u.mmap.fd, op->u.mmap.offset);
+			flush = map(&mmu->skas.id, op->u.mmap.addr, 
+				    op->u.mmap.len, op->u.mmap.r, op->u.mmap.w,
+				    op->u.mmap.x, op->u.mmap.fd,
+				    op->u.mmap.offset, finished, flush);
 			break;
 		case MUNMAP:
-                        unmap(&mmu->skas.id, (void *) op->u.munmap.addr,
-			      op->u.munmap.len);
+			flush = unmap(&mmu->skas.id, (void *) op->u.munmap.addr,
+				      op->u.munmap.len, finished, flush);
 			break;
 		case MPROTECT:
-                        protect(&mmu->skas.id, op->u.mprotect.addr,
-                                op->u.mprotect.len, op->u.mprotect.r,
-                                op->u.mprotect.w, op->u.mprotect.x);
+			flush = protect(&mmu->skas.id, op->u.mprotect.addr,
+					op->u.mprotect.len, op->u.mprotect.r, 
+					op->u.mprotect.w, op->u.mprotect.x, 
+					finished, flush);
 			break;
 		default:
 			printk("Unknown op type %d in do_ops\n", op->type);
 			break;
 		}
 	}
+
+	return flush;
 }
 
 extern int proc_mm;
arch/um/kernel/tlb.c +116 -110

286 lines not on this page · raw message

arch/um/kernel/tt/tlb.c +4 -1
Index: linux-2.6.12/arch/um/kernel/tt/tlb.c
===================================================================
@@ -17,7 +17,8 @@
 #include "os.h"
 #include "tlb.h"
 
-static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last)
+static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
+		    int finished, void *flush)
 {
 	struct host_vm_op *op;
 	int i;
@@ -45,6 +46,8 @@
 			break;
 		}
 	}
+
+	return NULL;
 }
 
 static void fix_range(struct mm_struct *mm, unsigned long start_addr, 
arch/um/sys-i386/stub.S +17 -0
Index: linux-2.6.12/arch/um/sys-i386/stub.S
===================================================================
@@ -6,3 +6,20 @@
 	int 	$0x80
 	mov	%eax, UML_CONFIG_STUB_DATA
 	int3
+
+	.globl batch_syscall_stub
+batch_syscall_stub:
+	mov	$UML_CONFIG_STUB_DATA, %esp
+again:	pop	%eax
+	cmpl	$0, %eax
+	jz	done
+	pop	%ebx
+	pop	%ecx
+	pop	%edx
+	pop	%esi
+ 	pop	%edi
+	pop	%ebp
+	int	$0x80
+	mov	%eax, UML_CONFIG_STUB_DATA
+	jmp	again
+done:	int3
arch/um/sys-x86_64/stub.S +21 -0
Index: linux-2.6.12/arch/um/sys-x86_64/stub.S
===================================================================
@@ -13,3 +13,24 @@
 	or	%rcx, %rbx
 	movq	%rax, (%rbx)
 	int3
+
+	.globl batch_syscall_stub
+batch_syscall_stub:
+	movq	$(UML_CONFIG_STUB_DATA >> 32), %rbx
+	salq	$32, %rbx
+	movq	$(UML_CONFIG_STUB_DATA & 0xffffffff), %rcx
+	or	%rcx, %rbx
+	movq	%rbx, %rsp
+again:	pop	%rax
+	cmpq	$0, %rax
+jz	done
+	pop	%rdi
+	pop	%rsi
+	pop	%rdx
+	pop	%r10
+ 	pop	%r8
+	pop	%r9
+	syscall
+	mov	%rax, (%rbx)
+	jmp	again
+done:	int3

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel