Add support for low resolution SMP kernel profiling.

- A nonprofiling version of s_lock (called s_lock_np) is used
    by mcount.

  - When profiling is active, more registers are clobbered in
    seemingly simple assembly routines. This means that some
    callers needed to save/restore extra registers.

  - The stack pointer must have space for a 'fake' return address
    in idle, to avoid stack underflow.
This commit is contained in:
Tor Egge 1997-12-15 02:18:35 +00:00
parent d5bc59bb81
commit 5c623cb649
17 changed files with 115 additions and 28 deletions

View File

@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: swtch.s,v 1.64 1997/10/10 09:44:06 peter Exp $
* $Id: swtch.s,v 1.65 1997/12/14 02:11:13 dyson Exp $
*/
#include "npx.h"
@ -260,7 +260,8 @@ _idle:
#if defined(SWTCH_OPTIM_STATS)
incl _tlb_flush_count
#endif
movl $_idlestack_top,%ecx
/* Keep space for nonexisting return addr, or profiling bombs */
movl $_idlestack_top-4,%ecx
movl %ecx,%esp
/* update common_tss.tss_esp0 pointer */

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: swtch.s,v 1.64 1997/10/10 09:44:06 peter Exp $
* $Id: swtch.s,v 1.65 1997/12/14 02:11:13 dyson Exp $
*/
#include "npx.h"
@ -260,7 +260,8 @@ _idle:
#if defined(SWTCH_OPTIM_STATS)
incl _tlb_flush_count
#endif
movl $_idlestack_top,%ecx
/* Keep space for nonexisting return addr, or profiling bombs */
movl $_idlestack_top-4,%ecx
movl %ecx,%esp
/* update common_tss.tss_esp0 pointer */

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)profile.h 8.1 (Berkeley) 6/11/93
* $Id: profile.h,v 1.11 1997/02/22 09:35:01 peter Exp $
* $Id: profile.h,v 1.12 1997/08/30 08:07:50 fsmp Exp $
*/
#ifndef _MACHINE_PROFILE_H_
@ -62,10 +62,13 @@
#define PC_TO_I(p, pc) ((fptrint_t)(pc) - (fptrint_t)(p)->lowpc)
#else
#define MCOUNT_DECL(s) u_long s;
#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
#ifdef SMP
#define MCOUNT_EXIT(s) { MPINTR_UNLOCK(); write_eflags(s); }
#define MCOUNT_ENTER(s) { s = read_eflags(); \
__asm __volatile("cli" : : : "memory"); \
s_lock_np(&mcount_lock); }
#define MCOUNT_EXIT(s) { s_unlock_np(&mcount_lock); write_eflags(s); }
#else
#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
#define MCOUNT_EXIT(s) (write_eflags(s))
#endif
#endif /* GUPROF */
@ -107,7 +110,7 @@ typedef u_int fptrint_t;
* An unsigned integral type that can hold non-negative difference between
* function pointers.
*/
typedef int fptrdiff_t;
typedef u_int fptrdiff_t;
#ifdef KERNEL

View File

@ -32,7 +32,7 @@
* SUCH DAMAGE.
*
* from: Steve McCanne's microtime code
* $Id: microtime.s,v 1.33 1997/09/07 22:03:51 fsmp Exp $
* $Id: microtime.s,v 1.34 1997/10/28 15:58:09 bde Exp $
*/
#include <machine/asmacros.h>
@ -202,9 +202,11 @@ common_microtime:
#ifdef USE_CLOCKLOCK
pushl %eax /* s_lock destroys %eax, %ecx */
pushl %edx /* during profiling, %edx is also destroyed */
pushl $_clock_lock
call _s_unlock
addl $4, %esp
popl %edx
popl %eax
#endif /* USE_CLOCKLOCK */
popfl /* restore interrupt mask */

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: simplelock.s,v 1.9 1997/08/31 03:05:56 smp Exp smp $
* $Id: simplelock.s,v 1.6 1997/08/31 03:17:48 fsmp Exp $
*/
/*
@ -286,3 +286,33 @@ ENTRY(ss_unlock)
movl _ss_tpr, %eax
movl %eax, lapic_tpr /* restore the old task priority */
ret
/*
* These versions of simple_lock does not contain calls to profiling code.
* Thus they can be called from the profiling code.
*/
/*
* void s_lock_np(struct simplelock *lkp)
*/
NON_GPROF_ENTRY(s_lock_np)
movl 4(%esp), %eax /* get the address of the lock */
movl $1, %ecx
1:
xchgl %ecx, (%eax)
testl %ecx, %ecx
jz 3f
2:
cmpl $0, (%eax) /* wait to empty */
jne 2b /* still set... */
jmp 1b /* empty again, try once more */
3:
NON_GPROF_RET
/*
* void s_unlock_np(struct simplelock *lkp)
*/
NON_GPROF_ENTRY(s_unlock_np)
movl 4(%esp), %eax /* get the address of the lock */
movl $0, (%eax)
NON_GPROF_RET

View File

@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: swtch.s,v 1.64 1997/10/10 09:44:06 peter Exp $
* $Id: swtch.s,v 1.65 1997/12/14 02:11:13 dyson Exp $
*/
#include "npx.h"
@ -260,7 +260,8 @@ _idle:
#if defined(SWTCH_OPTIM_STATS)
incl _tlb_flush_count
#endif
movl $_idlestack_top,%ecx
/* Keep space for nonexisting return addr, or profiling bombs */
movl $_idlestack_top-4,%ecx
movl %ecx,%esp
/* update common_tss.tss_esp0 pointer */

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: lock.h,v 1.7 1997/09/05 20:20:31 smp Exp smp $
* $Id: lock.h,v 1.4 1997/09/07 22:01:39 fsmp Exp $
*/
@ -224,6 +224,8 @@ int s_lock_try __P((struct simplelock *));
void s_unlock __P((struct simplelock *));
void ss_lock __P((struct simplelock *));
void ss_unlock __P((struct simplelock *));
void s_lock_np __P((struct simplelock *));
void s_unlock_np __P((struct simplelock *));
/* global data in mp_machdep.c */
extern struct simplelock imen_lock;
@ -233,6 +235,7 @@ extern struct simplelock intr_lock;
extern struct simplelock clock_lock;
extern struct simplelock com_lock;
extern struct simplelock mpintr_lock;
extern struct simplelock mcount_lock;
#if !defined(SIMPLELOCK_DEBUG) && NCPUS > 1
/*

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)profile.h 8.1 (Berkeley) 6/11/93
* $Id: profile.h,v 1.11 1997/02/22 09:35:01 peter Exp $
* $Id: profile.h,v 1.12 1997/08/30 08:07:50 fsmp Exp $
*/
#ifndef _MACHINE_PROFILE_H_
@ -62,10 +62,13 @@
#define PC_TO_I(p, pc) ((fptrint_t)(pc) - (fptrint_t)(p)->lowpc)
#else
#define MCOUNT_DECL(s) u_long s;
#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
#ifdef SMP
#define MCOUNT_EXIT(s) { MPINTR_UNLOCK(); write_eflags(s); }
#define MCOUNT_ENTER(s) { s = read_eflags(); \
__asm __volatile("cli" : : : "memory"); \
s_lock_np(&mcount_lock); }
#define MCOUNT_EXIT(s) { s_unlock_np(&mcount_lock); write_eflags(s); }
#else
#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
#define MCOUNT_EXIT(s) (write_eflags(s))
#endif
#endif /* GUPROF */
@ -107,7 +110,7 @@ typedef u_int fptrint_t;
* An unsigned integral type that can hold non-negative difference between
* function pointers.
*/
typedef int fptrdiff_t;
typedef u_int fptrdiff_t;
#ifdef KERNEL

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: apic_ipl.s,v 1.35 1997/09/07 19:23:45 smp Exp smp $
* $Id: apic_ipl.s,v 1.16 1997/09/07 22:02:28 fsmp Exp $
*/
@ -137,7 +137,9 @@ splz_unpend:
je splz_next /* "can't happen" */
cmpl $NHWI,%ecx
jae splz_swi
pushl %ecx
AICPL_UNLOCK
popl %ecx
/*
* We would prefer to call the intr handler directly here but that
@ -158,7 +160,9 @@ splz_swi:
pushl %eax
orl imasks(,%ecx,4),%eax
movl %eax,_cpl
pushl %edx
AICPL_UNLOCK
popl %edx
call %edx
AICPL_LOCK
popl %eax

View File

@ -36,7 +36,7 @@
*
* @(#)ipl.s
*
* $Id: ipl.s,v 1.17 1997/09/29 05:32:02 fsmp Exp $
* $Id: ipl.s,v 1.18 1997/10/13 00:01:53 fsmp Exp $
*/
@ -127,9 +127,9 @@ doreti_next:
#ifdef SMP
TEST_CIL
cli /* early to prevent INT deadlock */
movl %eax, %edx /* preserve cpl while getting lock */
pushl %eax /* preserve cpl while getting lock */
ICPL_LOCK
movl %edx, %eax
popl %eax
doreti_next2:
#endif
movl %eax,%ecx
@ -262,6 +262,7 @@ doreti_unpend:
jae doreti_swi
cli
#ifdef SMP
pushl %edx /* preserve %edx */
pushl %eax /* preserve %eax */
ICPL_LOCK
#ifdef CPL_AND_CML
@ -270,6 +271,7 @@ doreti_unpend:
popl _cpl
#endif
FAST_ICPL_UNLOCK
popl %edx
#else
movl %eax,_cpl
#endif
@ -293,6 +295,7 @@ doreti_swi:
*/
#ifdef SMP
orl imasks(,%ecx,4), %eax
pushl %edx /* save handler entry point */
cli /* prevent INT deadlock */
pushl %eax /* save cpl|cml */
ICPL_LOCK
@ -303,6 +306,7 @@ doreti_swi:
#endif
FAST_ICPL_UNLOCK
sti
popl %edx /* restore handler entry point */
#else
orl imasks(,%ecx,4),%eax
movl %eax,_cpl

View File

@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp_machdep.c,v 1.62 1997/12/12 21:45:23 tegge Exp $
* $Id: mp_machdep.c,v 1.63 1997/12/15 01:14:10 tegge Exp $
*/
#include "opt_smp.h"
@ -1512,6 +1512,9 @@ struct simplelock intr_lock;
/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
/* lock region used by kernel profiling */
struct simplelock mcount_lock;
#ifdef USE_COMLOCK
/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
@ -1536,6 +1539,8 @@ init_locks(void)
s_lock_init((struct simplelock*)&mpintr_lock);
s_lock_init((struct simplelock*)&mcount_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
s_lock_init((struct simplelock*)&intr_lock);
s_lock_init((struct simplelock*)&imen_lock);