From 4219d2b2ac61b5aad265aa4cdd159f51c6f2d3d9 Mon Sep 17 00:00:00 2001 From: David Greenman Date: Mon, 21 Aug 1995 18:06:48 +0000 Subject: [PATCH] A couple of micro optimizations to improve NULL syscall performance by about 2%. --- sys/amd64/amd64/trap.c | 51 +++++++++++++++++------------------------- sys/i386/i386/trap.c | 51 +++++++++++++++++------------------------- sys/kern/subr_trap.c | 51 +++++++++++++++++------------------------- 3 files changed, 60 insertions(+), 93 deletions(-) diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index d581b623dbd7..37d8e2e26d2c 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.57 1995/07/16 14:10:55 peter Exp $ + * $Id: trap.c,v 1.58 1995/07/30 17:49:24 davidg Exp $ */ /* @@ -798,7 +798,7 @@ syscall(frame) struct sysent *callp; struct proc *p = curproc; u_quad_t sticks; - int error, opc; + int error; int args[8], rval[2]; u_int code; @@ -806,14 +806,9 @@ syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; - - /* - * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always. - */ - opc = frame.tf_eip - 7; + params = (caddr_t)frame.tf_esp + sizeof(int); + code = frame.tf_eax; /* * Need to check if this is a 32 bit or 64 bit syscall. */ @@ -822,25 +817,25 @@ syscall(frame) * Code is first argument, followed by actual args. */ code = fuword(params); - params += sizeof (int); + params += sizeof(int); } else if (code == SYS___syscall) { /* * Like syscall, but code is a quad, so as to maintain * quad alignment for the rest of the arguments. */ - code = fuword(params + _QUAD_LOWWORD * sizeof(int)); + code = fuword(params); params += sizeof(quad_t); } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; - if ((i = callp->sy_narg * sizeof (int)) && + if ((i = callp->sy_narg * sizeof(int)) && (error = copyin(params, (caddr_t)args, (u_int)i))) { #ifdef KTRACE if (KTRPOINT(p, KTR_SYSCALL)) @@ -871,14 +866,17 @@ syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* + * Reconstruct pc, assuming lcall $X,y is 7 bytes. + */ + frame.tf_eip -= 7; break; case EJUSTRETURN: break; default: - bad: +bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */ @@ -906,14 +904,13 @@ void linux_syscall(frame) struct trapframe frame; { - caddr_t params; int i; struct proc *p = curproc; struct sysent *callp; u_quad_t sticks; - int error, opc; + int error; int rval[2]; - int code; + u_int code; struct linux_syscall_args { int arg1; int arg2; @@ -932,20 +929,13 @@ linux_syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("linux syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; + code = frame.tf_eax; - /* Reconstruct pc, subtract size of int 0x80 */ - opc = frame.tf_eip - 2; - if (code == 0) { - code = fuword(params); - params += sizeof (int); - } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; - if (code < 0 || code >= p->p_sysent->sv_size) + if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; @@ -956,7 +946,6 @@ linux_syscall(frame) #endif rval[0] = 0; - rval[1] = frame.tf_edx; error = (*callp->sy_call)(p, &args, rval); @@ -973,14 +962,14 @@ linux_syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* Reconstruct pc, subtract size of int 0x80 */ + frame.tf_eip -= 2; break; case EJUSTRETURN: break; default: - bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */ diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index d581b623dbd7..37d8e2e26d2c 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.57 1995/07/16 14:10:55 peter Exp $ + * $Id: trap.c,v 1.58 1995/07/30 17:49:24 davidg Exp $ */ /* @@ -798,7 +798,7 @@ syscall(frame) struct sysent *callp; struct proc *p = curproc; u_quad_t sticks; - int error, opc; + int error; int args[8], rval[2]; u_int code; @@ -806,14 +806,9 @@ syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; - - /* - * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always. - */ - opc = frame.tf_eip - 7; + params = (caddr_t)frame.tf_esp + sizeof(int); + code = frame.tf_eax; /* * Need to check if this is a 32 bit or 64 bit syscall. */ @@ -822,25 +817,25 @@ syscall(frame) * Code is first argument, followed by actual args. */ code = fuword(params); - params += sizeof (int); + params += sizeof(int); } else if (code == SYS___syscall) { /* * Like syscall, but code is a quad, so as to maintain * quad alignment for the rest of the arguments. */ - code = fuword(params + _QUAD_LOWWORD * sizeof(int)); + code = fuword(params); params += sizeof(quad_t); } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; - if ((i = callp->sy_narg * sizeof (int)) && + if ((i = callp->sy_narg * sizeof(int)) && (error = copyin(params, (caddr_t)args, (u_int)i))) { #ifdef KTRACE if (KTRPOINT(p, KTR_SYSCALL)) @@ -871,14 +866,17 @@ syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* + * Reconstruct pc, assuming lcall $X,y is 7 bytes. + */ + frame.tf_eip -= 7; break; case EJUSTRETURN: break; default: - bad: +bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */ @@ -906,14 +904,13 @@ void linux_syscall(frame) struct trapframe frame; { - caddr_t params; int i; struct proc *p = curproc; struct sysent *callp; u_quad_t sticks; - int error, opc; + int error; int rval[2]; - int code; + u_int code; struct linux_syscall_args { int arg1; int arg2; @@ -932,20 +929,13 @@ linux_syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("linux syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; + code = frame.tf_eax; - /* Reconstruct pc, subtract size of int 0x80 */ - opc = frame.tf_eip - 2; - if (code == 0) { - code = fuword(params); - params += sizeof (int); - } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; - if (code < 0 || code >= p->p_sysent->sv_size) + if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; @@ -956,7 +946,6 @@ linux_syscall(frame) #endif rval[0] = 0; - rval[1] = frame.tf_edx; error = (*callp->sy_call)(p, &args, rval); @@ -973,14 +962,14 @@ linux_syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* Reconstruct pc, subtract size of int 0x80 */ + frame.tf_eip -= 2; break; case EJUSTRETURN: break; default: - bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */ diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c index d581b623dbd7..37d8e2e26d2c 100644 --- a/sys/kern/subr_trap.c +++ b/sys/kern/subr_trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.57 1995/07/16 14:10:55 peter Exp $ + * $Id: trap.c,v 1.58 1995/07/30 17:49:24 davidg Exp $ */ /* @@ -798,7 +798,7 @@ syscall(frame) struct sysent *callp; struct proc *p = curproc; u_quad_t sticks; - int error, opc; + int error; int args[8], rval[2]; u_int code; @@ -806,14 +806,9 @@ syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; - - /* - * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always. - */ - opc = frame.tf_eip - 7; + params = (caddr_t)frame.tf_esp + sizeof(int); + code = frame.tf_eax; /* * Need to check if this is a 32 bit or 64 bit syscall. */ @@ -822,25 +817,25 @@ syscall(frame) * Code is first argument, followed by actual args. */ code = fuword(params); - params += sizeof (int); + params += sizeof(int); } else if (code == SYS___syscall) { /* * Like syscall, but code is a quad, so as to maintain * quad alignment for the rest of the arguments. */ - code = fuword(params + _QUAD_LOWWORD * sizeof(int)); + code = fuword(params); params += sizeof(quad_t); } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; - if ((i = callp->sy_narg * sizeof (int)) && + if ((i = callp->sy_narg * sizeof(int)) && (error = copyin(params, (caddr_t)args, (u_int)i))) { #ifdef KTRACE if (KTRPOINT(p, KTR_SYSCALL)) @@ -871,14 +866,17 @@ syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* + * Reconstruct pc, assuming lcall $X,y is 7 bytes. + */ + frame.tf_eip -= 7; break; case EJUSTRETURN: break; default: - bad: +bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */ @@ -906,14 +904,13 @@ void linux_syscall(frame) struct trapframe frame; { - caddr_t params; int i; struct proc *p = curproc; struct sysent *callp; u_quad_t sticks; - int error, opc; + int error; int rval[2]; - int code; + u_int code; struct linux_syscall_args { int arg1; int arg2; @@ -932,20 +929,13 @@ linux_syscall(frame) if (ISPL(frame.tf_cs) != SEL_UPL) panic("linux syscall"); - code = frame.tf_eax; p->p_md.md_regs = (int *)&frame; - params = (caddr_t)frame.tf_esp + sizeof (int) ; + code = frame.tf_eax; - /* Reconstruct pc, subtract size of int 0x80 */ - opc = frame.tf_eip - 2; - if (code == 0) { - code = fuword(params); - params += sizeof (int); - } if (p->p_sysent->sv_mask) - code = code & p->p_sysent->sv_mask; + code &= p->p_sysent->sv_mask; - if (code < 0 || code >= p->p_sysent->sv_size) + if (code >= p->p_sysent->sv_size) callp = &p->p_sysent->sv_table[0]; else callp = &p->p_sysent->sv_table[code]; @@ -956,7 +946,6 @@ linux_syscall(frame) #endif rval[0] = 0; - rval[1] = frame.tf_edx; error = (*callp->sy_call)(p, &args, rval); @@ -973,14 +962,14 @@ linux_syscall(frame) break; case ERESTART: - frame.tf_eip = opc; + /* Reconstruct pc, subtract size of int 0x80 */ + frame.tf_eip -= 2; break; case EJUSTRETURN: break; default: - bad: if (p->p_sysent->sv_errsize) if (error >= p->p_sysent->sv_errsize) error = -1; /* XXX */