[PATCH 7/9] UML - Speed up tlb flushing

2005-03-09 Thread Jeff Dike
This patch optimizes tlb flushing in a couple of ways to reduce the number
of system calls made to the host in order to update an address space.

Operations are collected, and adjacent ones which can be merged, are.  This
includes consecutive munmaps, mprotects with the same permissions, and mmaps
with the same backing file and permissions and linear in the file.

Second, the munmaps that always preceded mmaps are now done instead of mmap if
necessary.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>

Index: linux-2.6.11/arch/um/include/tlb.h
===
--- linux-2.6.11.orig/arch/um/include/tlb.h 2005-03-08 20:17:35.0 
-0500
+++ linux-2.6.11/arch/um/include/tlb.h  2005-03-08 22:22:23.0 -0500
@@ -6,9 +6,48 @@
 #ifndef __TLB_H__
 #define __TLB_H__
 
+#include "um_mmu.h"
+
+struct host_vm_op {
+   enum { MMAP, MUNMAP, MPROTECT } type;
+   union {
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   unsigned int r:1;
+   unsigned int w:1;
+   unsigned int x:1;
+   int fd;
+   __u64 offset;
+   } mmap;
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   } munmap;
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   unsigned int r:1;
+   unsigned int w:1;
+   unsigned int x:1;
+   } mprotect;
+   } u;
+};
+
 extern void mprotect_kernel_vm(int w);
 extern void force_flush_all(void);
 
+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, int data, 
+   void (*do_ops)(int, 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, 
+ int data, void (*do_ops)(int, 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, int data,
+   void (*do_ops)(int, struct host_vm_op *, int));
 #endif
 
 /*
Index: linux-2.6.11/arch/um/kernel/skas/include/skas.h
===
--- linux-2.6.11.orig/arch/um/kernel/skas/include/skas.h2005-03-08 
20:17:35.0 -0500
+++ linux-2.6.11/arch/um/kernel/skas/include/skas.h 2005-03-08 
22:22:23.0 -0500
@@ -22,11 +22,11 @@
 extern void remove_sigstack(void);
 extern void new_thread_handler(int sig);
 extern void handle_syscall(union uml_pt_regs *regs);
-extern void map(int fd, unsigned long virt, unsigned long phys, 
-   unsigned long len, int r, int w, int x);
-extern int unmap(int fd, void *addr, int len);
+extern void map(int fd, unsigned long virt, unsigned long len, int r, int w, 
+   int x, int phys_fd, unsigned long long offset);
+extern int unmap(int fd, void *addr, unsigned long len);
 extern int protect(int fd, unsigned long addr, unsigned long len, 
-  int r, int w, int x, int must_succeed);
+  int r, int w, int x);
 extern void user_signal(int sig, union uml_pt_regs *regs);
 extern int new_mm(int from);
 extern void start_userspace(int cpu);
Index: linux-2.6.11/arch/um/kernel/skas/mem_user.c
===
--- linux-2.6.11.orig/arch/um/kernel/skas/mem_user.c2005-03-08 
21:56:38.0 -0500
+++ linux-2.6.11/arch/um/kernel/skas/mem_user.c 2005-03-08 22:22:23.0 
-0500
@@ -11,16 +11,14 @@
 #include "os.h"
 #include "proc_mm.h"
 
-void map(int fd, unsigned long virt, unsigned long phys, unsigned long len, 
-int r, int w, int x)
+void map(int fd, unsigned long virt, unsigned long len, int r, int w, 
+int x, int phys_fd, unsigned long long offset)
 {
struct proc_mm_op map;
-   __u64 offset;
-   int prot, n, phys_fd;
+   int prot, n;
 
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 
(x ? PROT_EXEC : 0);
-   phys_fd = phys_mapping(phys, );
 
map = ((struct proc_mm_op) { .op= MM_MMAP,
 .u = 
@@ -38,7 +36,7 @@
printk("map : /proc/mm map failed, err = %d\n", -n);
 }
 
-int unmap(int fd, void *addr, int len)
+int unmap(int fd, void *addr, unsigned long len)
 {
struct proc_mm_op unmap;
int n;
Index: linux-2.6.11/arch/um/kernel/skas/tlb.c
===
--- 

[PATCH 7/9] UML - Speed up tlb flushing

2005-03-09 Thread Jeff Dike
This patch optimizes tlb flushing in a couple of ways to reduce the number
of system calls made to the host in order to update an address space.

Operations are collected, and adjacent ones which can be merged, are.  This
includes consecutive munmaps, mprotects with the same permissions, and mmaps
with the same backing file and permissions and linear in the file.

Second, the munmaps that always preceded mmaps are now done instead of mmap if
necessary.

Signed-off-by: Jeff Dike [EMAIL PROTECTED]

Index: linux-2.6.11/arch/um/include/tlb.h
===
--- linux-2.6.11.orig/arch/um/include/tlb.h 2005-03-08 20:17:35.0 
-0500
+++ linux-2.6.11/arch/um/include/tlb.h  2005-03-08 22:22:23.0 -0500
@@ -6,9 +6,48 @@
 #ifndef __TLB_H__
 #define __TLB_H__
 
+#include um_mmu.h
+
+struct host_vm_op {
+   enum { MMAP, MUNMAP, MPROTECT } type;
+   union {
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   unsigned int r:1;
+   unsigned int w:1;
+   unsigned int x:1;
+   int fd;
+   __u64 offset;
+   } mmap;
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   } munmap;
+   struct {
+   unsigned long addr;
+   unsigned long len;
+   unsigned int r:1;
+   unsigned int w:1;
+   unsigned int x:1;
+   } mprotect;
+   } u;
+};
+
 extern void mprotect_kernel_vm(int w);
 extern void force_flush_all(void);
 
+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, int data, 
+   void (*do_ops)(int, 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, 
+ int data, void (*do_ops)(int, 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, int data,
+   void (*do_ops)(int, struct host_vm_op *, int));
 #endif
 
 /*
Index: linux-2.6.11/arch/um/kernel/skas/include/skas.h
===
--- linux-2.6.11.orig/arch/um/kernel/skas/include/skas.h2005-03-08 
20:17:35.0 -0500
+++ linux-2.6.11/arch/um/kernel/skas/include/skas.h 2005-03-08 
22:22:23.0 -0500
@@ -22,11 +22,11 @@
 extern void remove_sigstack(void);
 extern void new_thread_handler(int sig);
 extern void handle_syscall(union uml_pt_regs *regs);
-extern void map(int fd, unsigned long virt, unsigned long phys, 
-   unsigned long len, int r, int w, int x);
-extern int unmap(int fd, void *addr, int len);
+extern void map(int fd, unsigned long virt, unsigned long len, int r, int w, 
+   int x, int phys_fd, unsigned long long offset);
+extern int unmap(int fd, void *addr, unsigned long len);
 extern int protect(int fd, unsigned long addr, unsigned long len, 
-  int r, int w, int x, int must_succeed);
+  int r, int w, int x);
 extern void user_signal(int sig, union uml_pt_regs *regs);
 extern int new_mm(int from);
 extern void start_userspace(int cpu);
Index: linux-2.6.11/arch/um/kernel/skas/mem_user.c
===
--- linux-2.6.11.orig/arch/um/kernel/skas/mem_user.c2005-03-08 
21:56:38.0 -0500
+++ linux-2.6.11/arch/um/kernel/skas/mem_user.c 2005-03-08 22:22:23.0 
-0500
@@ -11,16 +11,14 @@
 #include os.h
 #include proc_mm.h
 
-void map(int fd, unsigned long virt, unsigned long phys, unsigned long len, 
-int r, int w, int x)
+void map(int fd, unsigned long virt, unsigned long len, int r, int w, 
+int x, int phys_fd, unsigned long long offset)
 {
struct proc_mm_op map;
-   __u64 offset;
-   int prot, n, phys_fd;
+   int prot, n;
 
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 
(x ? PROT_EXEC : 0);
-   phys_fd = phys_mapping(phys, offset);
 
map = ((struct proc_mm_op) { .op= MM_MMAP,
 .u = 
@@ -38,7 +36,7 @@
printk(map : /proc/mm map failed, err = %d\n, -n);
 }
 
-int unmap(int fd, void *addr, int len)
+int unmap(int fd, void *addr, unsigned long len)
 {
struct proc_mm_op unmap;
int n;
Index: linux-2.6.11/arch/um/kernel/skas/tlb.c
===
---