All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] [PATCH] host context switch reduction
@ 2004-02-29  4:35 Jeff Dike
  2004-02-29 16:48 ` BlaisorBlade
                   ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Jeff Dike @ 2004-02-29  4:35 UTC (permalink / raw)
  To: user-mode-linux-devel

[-- Attachment #1: Type: text/plain, Size: 436 bytes --]

The patches below are from Laurent Vivier who didn't make them public.  They
add a new feature to ptrace on the host which cuts down on the number of
context switches needed for a UML system call, plus makes UML use it.

There's some interest in this, so I'm putting it out as-is.  I haven't played
with it.

Laurent did some performance testing and found ~40% speedup on a getpid
loop, and a 3.5% speedup on a kernel build.

				Jeff


[-- Attachment #2: x --]
[-- Type: text/plain, Size: 4539 bytes --]

diff -Nrc skas3-linux-2.4.22/Makefile skas4-linux-2.4.22/Makefile
*** skas3-linux-2.4.22/Makefile	Tue Dec  2 21:24:14 2003
--- skas4-linux-2.4.22/Makefile	Tue Dec  2 20:32:41 2003
***************
*** 1,7 ****
  VERSION = 2
  PATCHLEVEL = 4
  SUBLEVEL = 22
! EXTRAVERSION = -skas3
  
  KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  
--- 1,7 ----
  VERSION = 2
  PATCHLEVEL = 4
  SUBLEVEL = 22
! EXTRAVERSION = -sysemu
  
  KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  
diff -Nrc skas3-linux-2.4.22/arch/i386/kernel/entry.S skas4-linux-2.4.22/arch/i386/kernel/entry.S
*** skas3-linux-2.4.22/arch/i386/kernel/entry.S	Fri Jun 13 16:51:29 2003
--- skas4-linux-2.4.22/arch/i386/kernel/entry.S	Tue Dec  2 20:27:41 2003
***************
*** 203,208 ****
--- 203,210 ----
  	pushl %eax			# save orig_eax
  	SAVE_ALL
  	GET_CURRENT(%ebx)
+ 	testb $0x20,tsk_ptrace(%ebx)	# PT_SCEMU
+ 	jne emulatesys
  	testb $0x02,tsk_ptrace(%ebx)	# PT_TRACESYS
  	jne tracesys
  	cmpl $(NR_syscalls),%eax
***************
*** 237,242 ****
--- 239,248 ----
  	jmp restore_all
  
  	ALIGN
+ emulatesys:
+ 	call SYMBOL_NAME(syscall_emulate)
+ 	jmp ret_from_sys_call
+ 	ALIGN
  tracesys:
  	movl $-ENOSYS,EAX(%esp)
  	call SYMBOL_NAME(syscall_trace)
diff -Nrc skas3-linux-2.4.22/arch/i386/kernel/ptrace.c skas4-linux-2.4.22/arch/i386/kernel/ptrace.c
*** skas3-linux-2.4.22/arch/i386/kernel/ptrace.c	Tue Dec  2 21:24:01 2003
--- skas4-linux-2.4.22/arch/i386/kernel/ptrace.c	Tue Dec  2 18:52:10 2003
***************
*** 275,280 ****
--- 275,281 ----
  		  }
  		  break;
  
+ 	case PTRACE_SCEMU: /* continue and replace next syscall */
  	case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
  	case PTRACE_CONT: { /* restart after signal. */
  		long tmp;
***************
*** 282,287 ****
--- 283,292 ----
  		ret = -EIO;
  		if ((unsigned long) data > _NSIG)
  			break;
+ 		if (request == PTRACE_SCEMU)
+ 			child->ptrace |= PT_SCEMU;
+ 		else
+ 			child->ptrace &= ~PT_SCEMU;
  		if (request == PTRACE_SYSCALL)
  			child->ptrace |= PT_TRACESYS;
  		else
***************
*** 320,326 ****
  		ret = -EIO;
  		if ((unsigned long) data > _NSIG)
  			break;
! 		child->ptrace &= ~PT_TRACESYS;
  		if ((child->ptrace & PT_DTRACE) == 0) {
  			/* Spurious delayed TF traps may occur */
  			child->ptrace |= PT_DTRACE;
--- 325,331 ----
  		ret = -EIO;
  		if ((unsigned long) data > _NSIG)
  			break;
! 		child->ptrace &= ~(PT_TRACESYS|PT_SCEMU);
  		if ((child->ptrace & PT_DTRACE) == 0) {
  			/* Spurious delayed TF traps may occur */
  			child->ptrace |= PT_DTRACE;
***************
*** 482,487 ****
--- 487,515 ----
  	return ret;
  }
  
+ asmlinkage void syscall_emulate(void)
+ {
+ 	if ((current->ptrace & (PT_PTRACED|PT_SCEMU)) !=
+ 			(PT_PTRACED|PT_SCEMU))
+ 		return;
+ 	/* the 0x80 provides a way for the tracing parent to distinguish
+ 	   between a syscall stop and SIGTRAP delivery */
+ 	current->exit_code = SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
+ 					? 0x80 : 0);
+ 	current->state = TASK_STOPPED;
+ 	notify_parent(current, SIGCHLD);
+ 	schedule();
+ 	/*
+ 	 * this isn't the same as continuing with a signal, but it will do
+ 	 * for normal use.  strace only continues with a signal if the
+ 	 * stopping signal is not SIGTRAP.  -brl
+ 	 */
+ 	if (current->exit_code) {
+ 		send_sig(current->exit_code, current, 1);
+ 		current->exit_code = 0;
+ 	}
+ }
+ 
  asmlinkage void syscall_trace(void)
  {
  	if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) !=
diff -Nrc skas3-linux-2.4.22/include/linux/ptrace.h skas4-linux-2.4.22/include/linux/ptrace.h
*** skas3-linux-2.4.22/include/linux/ptrace.h	Sat Sep 15 00:55:17 2001
--- skas4-linux-2.4.22/include/linux/ptrace.h	Tue Dec  2 18:42:55 2003
***************
*** 20,25 ****
--- 20,26 ----
  #define PTRACE_DETACH		0x11
  
  #define PTRACE_SYSCALL		  24
+ #define PTRACE_SCEMU		  25
  
  #include <asm/ptrace.h>
  
diff -Nrc skas3-linux-2.4.22/include/linux/sched.h skas4-linux-2.4.22/include/linux/sched.h
*** skas3-linux-2.4.22/include/linux/sched.h	Fri Jun 13 16:51:39 2003
--- skas4-linux-2.4.22/include/linux/sched.h	Tue Dec  2 20:28:19 2003
***************
*** 444,449 ****
--- 444,450 ----
  #define PT_DTRACE	0x00000004	/* delayed trace (used on m68k, i386) */
  #define PT_TRACESYSGOOD	0x00000008
  #define PT_PTRACE_CAP	0x00000010	/* ptracer can follow suid-exec */
+ #define PT_SCEMU	0x00000020	/* syscall emulation for UML */
  
  #define is_dumpable(tsk)    ((tsk)->task_dumpable && (tsk)->mm && (tsk)->mm->dumpable)
  


[-- Attachment #3: y --]
[-- Type: text/plain, Size: 4124 bytes --]

diff -Nrc uml-linux-2.4.22/arch/um/kernel/process.c sysemu-uml-linux-2.4.22/arch/um/kernel/process.c
*** uml-linux-2.4.22/arch/um/kernel/process.c	Tue Oct 14 15:28:28 2003
--- sysemu-uml-linux-2.4.22/arch/um/kernel/process.c	Thu Dec  4 20:14:33 2003
***************
*** 222,227 ****
--- 222,243 ----
  	}
  	stop_ptraced_child(pid, stack, 0);
  	printk("OK\n");
+ 
+ #ifdef PTRACE_SYSEMU
+ 	printk("Checking syscall emulation patch for ptrace...");
+ 
+ 	use_sysemu = 0;
+ 	pid = start_ptraced_child(&stack);
+ 	if(ptrace(PTRACE_SYSEMU, pid, 0, 0) >= 0)
+ 	{
+ 		printk("OK\n");
+         	use_sysemu = 1;
+ 	}
+ 	else
+ 		printk("missing\n");
+ 
+ 	stop_ptraced_child(pid, stack, 0);
+ #endif
  }
  
  int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr)
diff -Nrc uml-linux-2.4.22/arch/um/kernel/skas/include/ptrace-skas.h sysemu-uml-linux-2.4.22/arch/um/kernel/skas/include/ptrace-skas.h
*** uml-linux-2.4.22/arch/um/kernel/skas/include/ptrace-skas.h	Tue Oct 14 15:28:28 2003
--- sysemu-uml-linux-2.4.22/arch/um/kernel/skas/include/ptrace-skas.h	Thu Dec  4 20:15:34 2003
***************
*** 10,15 ****
--- 10,22 ----
  
  #ifdef UML_CONFIG_MODE_SKAS
  
+ /* syscall emulation path in ptrace */
+ 
+ #ifndef PTRACE_SYSEMU
+ #define PTRACE_SYSEMU 25
+ #endif
+ extern int use_sysemu;
+ 
  #include "skas_ptregs.h"
  
  #define HOST_FRAME_SIZE 17
diff -Nrc uml-linux-2.4.22/arch/um/kernel/skas/process.c sysemu-uml-linux-2.4.22/arch/um/kernel/skas/process.c
*** uml-linux-2.4.22/arch/um/kernel/skas/process.c	Wed Dec  3 18:53:54 2003
--- sysemu-uml-linux-2.4.22/arch/um/kernel/skas/process.c	Fri Dec  5 17:57:03 2003
***************
*** 27,32 ****
--- 27,36 ----
  #include "skas_ptrace.h"
  #include "chan_user.h"
  
+ #ifdef PTRACE_SYSEMU
+ int use_sysemu = 0;
+ #endif
+ 
  int is_skas_winch(int pid, int fd, void *data)
  {
  	if(pid != getpid())
***************
*** 65,85 ****
  		return;
  	}
  
! 	err = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, __NR_getpid);
! 	if(err < 0)
! 	        panic("handle_trap - nullifying syscall failed errno = %d\n", 
! 		      errno);
  
! 	err = ptrace(PTRACE_SYSCALL, pid, 0, 0);
! 	if(err < 0)
! 	        panic("handle_trap - continuing to end of syscall failed, "
! 		      "errno = %d\n", errno);
! 
! 	err = waitpid(pid, &status, WUNTRACED);
! 	if((err < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
! 		panic("handle_trap - failed to wait at end of syscall, "
! 		      "errno = %d, status = %d\n", errno, status);
  
  	handle_syscall(regs);
  }
  
--- 69,91 ----
  		return;
  	}
  
! 	if (!use_sysemu)
! 	{
! 		err = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, __NR_getpid);
! 		if(err < 0)
! 	        	panic("handle_trap - nullifying syscall failed errno = %d\n", 
! 		      	errno);
  
! 		err = ptrace(PTRACE_SYSCALL, pid, 0, 0);
! 		if(err < 0)
! 	        	panic("handle_trap - continuing to end of syscall failed, "
! 		      	"errno = %d\n", errno);
  
+ 		err = waitpid(pid, &status, WUNTRACED);
+ 		if((err < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
+ 			panic("handle_trap - failed to wait at end of syscall, "
+ 		      	"errno = %d, status = %d\n", errno, status);
+ 	}
  	handle_syscall(regs);
  }
  
***************
*** 134,140 ****
--- 140,154 ----
  
  	restore_registers(regs);
  		
+ #ifdef PTRACE_SYSEMU
+ 	if (use_sysemu)
+ 		err = ptrace(PTRACE_SYSEMU, userspace_pid, 0, 0);
+ 	else
+ 		err = ptrace(PTRACE_SYSCALL, userspace_pid, 0, 0);
+ #else
  	err = ptrace(PTRACE_SYSCALL, userspace_pid, 0, 0);
+ #endif
+ 
  	if(err)
  		panic("userspace - PTRACE_SYSCALL failed, errno = %d\n", 
  		       errno);
***************
*** 172,179 ****
--- 186,202 ----
  
  		restore_registers(regs);
  
+ #ifdef PTRACE_SYSEMU
+ 		if (use_sysemu)
+ 			op = singlestepping_skas() ? PTRACE_SINGLESTEP : 
+ 				PTRACE_SYSEMU;
+ 		else
+ 			op = singlestepping_skas() ? PTRACE_SINGLESTEP : 
+ 				PTRACE_SYSCALL;
+ #else
  		op = singlestepping_skas() ? PTRACE_SINGLESTEP : 
  			PTRACE_SYSCALL;
+ #endif
  		err = ptrace(op, userspace_pid, 0, 0);
  		if(err)
  			panic("userspace - PTRACE_SYSCALL failed, "

^ permalink raw reply	[flat|nested] 31+ messages in thread
* Re: [uml-devel] [PATCH] host context switch reduction
@ 2004-05-20  2:34 roland
  0 siblings, 0 replies; 31+ messages in thread
From: roland @ 2004-05-20  2:34 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Jeff Dike, user-mode-linux-devel, blaisorblade_spam

ohh..
that mail was still open in the background....waiting to be send :)

i recognized that blaisorblades skas-patch doesn`t seem to activate
skas in .config by default, so my uml`s accidently ran in TT Mode.
Recompiled the HOST and the effect i mentioned doesn`t happen with skas.
btw: the getpid-loop is more than THREE TIMES faster with skas.
i hope skas will do it`s way into the mainstream-kernel, so TT is obsolete soon.
skas should be a MUST for uml :)

jeff - can we expect this happening soon, or doesn`t that happen before skas4 ?

suse-distro has skas in their kernels - in 9.0 and also in 9.1 - so i would think, skas
is ready for the kernel.....but....linus decides :)

so - that`s enough mails.
sorry for that "spamming" today. i promise to reduce my output :)

regards
roland


----- Original Message ----- 
From: "roland" <for_spam@gmx.de>
To: "Laurent Vivier" <LaurentVivier@wanadoo.fr>
Cc: "Jeff Dike" <jdike@addtoit.com>; <user-mode-linux-devel@lists.sourceforge.net>
Sent: Thursday, May 20, 2004 3:01 AM
Subject: Re: [uml-devel] [PATCH] host context switch reduction


> while testing laurents patch,
> i have made the following interesting observation:
>
> if i run a getpid-loop inside one uml, the other uml`s behaviour becomes
> quite sluggish - this doesn`t seem to have a relation to laurents patch - i
> just recognized this for the first time, because i never did getpid-loops
> inside a uml. :)
>
> ok - i would say:
> yes - the system is heavily stressed - a busy uml makes the other one behave
> sluggish, too .....but.....
>
> why don`t i see any sluggish behaviour on the HOST itself ?
>
> want to reproduce?
>
> compile this little program and transfer it to your uml-root_fs`s
> --------------------------
> int main(void)
> {
>  int i;
>  for(i=0;i<1000000;i++)
>   getpid();
> }
> --------------------------
>
> - let it run in one uml and the other uml(s) get sluggish - typing into the window and
>   issuing commands gives very slow response
> - on the HOST there is no noticeable performance loss - typing,echoing, ls -la, df -kl,
>   ... all seems normal and "feels" quite good.
> - stop the getpid program and start another cpu/io hog (e.g. "while true;do find /;done)
>   inside one uml and compare that behaviour. other uml`s behave quite ok - the host, too.
>   no sluggish behaviour.
>
> maybe this behaviour is quite normal (ok - a getpid-loop is a worst case scenario) - but
> my system knowledge isn`t good enough, to explain , what`s going on here in detail.
>
> is it, because the processing overhead of an uml is so high - so typing a char or issuing a
> command "costs" so much more in an uml, so that we just can "see" the performance drop here,
> and not on the host ?
>
> regards
> roland
>
>
>
> ----- Original Message ----- 
> From: "Laurent Vivier" <LaurentVivier@wanadoo.fr>
> To: "roland" <for_spam@gmx.de>
> Cc: "Jeff Dike" <jdike@addtoit.com>; <user-mode-linux-devel@lists.sourceforge.net>
> Sent: Wednesday, May 19, 2004 8:17 PM
> Subject: Re: [uml-devel] [PATCH] host context switch reduction
>
>
> Le mer 19/05/2004 à 20:01, roland a écrit :
> > Hi Laurent !
> > Great!
> > Thanks a lot for your work :)
> >
> > but i have a question:
> >
> > old mail from jeff:
> > >The patches below are from Laurent Vivier who didn't make them public.  They
> > >add a new feature to ptrace on the host which cuts down on the number of
> > >context switches needed for a UML system call, plus makes UML use it
> >
> > so - if your patch adds a new feature for ptrace on the HOST - shouldn`t we need TWO patches for 2.6 ?
> > One patch for uml and one patch for the host ?
> >
> > this one seems for uml only.
> > some of us already run uml 2.6(.x) on a 2.6.(.x) host and put their focus on the "new kernel" (me too).
>
> OK, as I didn't find skas patch for 2.6 I thought it didn't exist...
> anyway I tried to port the 2.4 host sysemu patch to 2.6, find it
> attached. I never tested it, or compiled it ! I have no system with 2.6
> kernel, and the only I386 system I have is very, very, very noisy...
> it's a good system only when it is switched off ;-) !
>
> > regards
> > roland
> >
> > ps:
> > since this would be the 2nd patch for the HOST (besides skas), would it make sense, to merge "skas" and "sysemu" into one common
> > HOST-patch (if it has been tested and approved stable) ?
> >
>
> YES, I think... but Jeff is the boss ;-)
>
> >
> >
> > ----- Original Message ----- 
> > From: "Laurent Vivier" <LaurentVivier@wanadoo.fr>
> > To: "Jeff Dike" <jdike@addtoit.com>
> > Cc: "roland" <for_spam@gmx.de>; <user-mode-linux-devel@lists.sourceforge.net>
> > Sent: Wednesday, May 19, 2004 7:27 PM
> > Subject: Re: [uml-devel] [PATCH] host context switch reduction
> >
> >
> > Hi,
> >
> > as it is a plebiscite ;-), find attached the patch for UML 2.6.6 and
> > measurements I made on my poor netserver.
> >
> > Laurent
> >
> > Le mar 18/05/2004 à 19:59, Jeff Dike a écrit :
> > > On Tue, May 18, 2004 at 12:22:45AM +0200, roland wrote:
> > > > the question is:
> > > > is the "real world" performance benefit, uml get`s from this patch worth taking your time and is it implemented in a way, so
> > that
> > > > uml maintainers are happy with that ?
> > >
> > > The patch seems reasonable to me.  I'd be happiest with Laurent pushing this
> > > into mainline himself.
> > >
> > > > i cannot really estimate, what performance benefits your patch brings to uml in detail, but what i have seen so far, this
> seems
> > > > quite worth doing the work.  reducing context switches by 1/3 is a LOT, imho - and reducing the execution time of the
> > getpid-loop to
> > > > nearly the half is quite impressive.
> > >
> > > Yeah, but no real workloads do while(1) getpid();
> > >
> > > The kernel build improvement is obviously smaller, but still worth having.
> > >
> > > > are there any "con`s" that argue for that work _NOT_ being done ?
> > >
> > > No.  But testing, and happy reports to the appropriate mailing lists would
> > > help.
> > >
> > > Jeff
> >
> >
> >
> > --------------------------------------------------------------------------------
> >
> >
> > > HP Netserver LH Pro bi-pro 200 MHz / 256 MB RAM
> > >
> > > NATIF:
> > >
> > > netserver:/usr/src# uname -a
> > > Linux netserver 2.4.24-sysemu #4 SMP Tue Feb 17 16:43:11 CET 2004 i686 GNU/Linux
> > >
> > > netserver:/usr/src# time ./getpid 1000000
> > >
> > > real    0m1.763s
> > > user    0m0.910s
> > > sys     0m0.860s
> > >
> > > real    0m1.759s
> > > user    0m0.900s
> > > sys     0m0.870s
> > >
> > > real    0m1.759s
> > > user    0m0.950s
> > > sys     0m0.800s
> > >
> > > UML with sysemu:
> > >
> > > (none):~# uname -a
> > > Linux (none) 2.6.6-1um #10 Wed May 19 12:54:37 CEST 2004 i686 unknown
> > >
> > > (none):/mnt/usr/src# time ./getpid 1000000
> > >
> > > real    1m1.508s
> > > user    0m7.960s
> > > sys     0m53.450s
> > >
> > > real    1m1.881s
> > > user    0m6.630s
> > > sys     0m55.240s
> > >
> > > real    1m1.920s
> > > user    0m6.580s
> > > sys     0m55.340s
> > >
> > > UML w/o sysemu
> > >
> > > real    1m32.833s
> > > user    0m7.610s
> > > sys     1m25.130s
> > >
> > > real    1m32.921s
> > > user    0m7.890s
> > > sys     1m24.980s
> > >
> > > real    1m33.493s
> > > user    0m8.010s
> > > sys     1m24.960s
> > >
> >
>



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2004-05-28  4:52 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-29  4:35 [uml-devel] [PATCH] host context switch reduction Jeff Dike
2004-02-29 16:48 ` BlaisorBlade
2004-03-15 11:42 ` Sven 'Darkman' Michels
2004-03-15 19:13   ` Jeff Dike
2004-05-17 20:08 ` roland
2004-05-17 22:00   ` Laurent Vivier
2004-05-17 22:22     ` roland
2004-05-18 17:59       ` Jeff Dike
2004-05-19 17:27         ` Laurent Vivier
2004-05-19 18:01           ` roland
2004-05-19 18:17             ` Laurent Vivier
2004-05-19 19:39               ` roland
2004-05-19 19:49                 ` Laurent Vivier
2004-05-20  2:30                   ` roland
2004-05-20 12:49                     ` Laurent Vivier
2004-05-23  0:42                       ` [uml-devel] [PATCH] commandline switch for sysemu patch roland
2004-05-23 13:31                       ` [uml-devel] [PATCH] host context switch reduction roland
2004-05-19 23:54               ` Jeff Dike
2004-05-20  1:01               ` roland
2004-05-20 14:12                 ` Henrik Nordstrom
2004-05-20 15:27                   ` roland
2004-05-20 15:35                     ` Henrik Nordstrom
2004-05-19 22:40           ` Nuno Silva
2004-05-20 18:28           ` roland
2004-05-20 18:47             ` Henrik Nordstrom
2004-05-27  6:16           ` Christopher S. Aker
2004-05-27  8:22             ` Laurent Vivier
2004-05-27  9:25               ` Christopher S. Aker
2004-05-27 11:50                 ` Laurent Vivier
2004-05-28  4:53                   ` [uml-devel] [PATCH] host context switch reduction Benchmarks Christopher S. Aker
  -- strict thread matches above, loose matches on Subject: below --
2004-05-20  2:34 [uml-devel] [PATCH] host context switch reduction roland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.