From 25142c5ea1b68cb025cae8ecf7323cd8c530f6bb Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 28 Jun 2001 04:03:29 +0000 Subject: [PATCH] Get kernel profiling on SMP systems closer to working by replacing the mcount spin mutex with a very simple non-recursive spinlock implemented using atomic operations. --- sys/amd64/amd64/mp_machdep.c | 8 +------- sys/amd64/amd64/mptable.c | 8 +------- sys/amd64/include/mptable.h | 8 +------- sys/amd64/include/profile.h | 9 +++++---- sys/i386/i386/mp_machdep.c | 8 +------- sys/i386/i386/mptable.c | 8 +------- sys/i386/include/mptable.h | 8 +------- sys/i386/include/profile.h | 9 +++++---- 8 files changed, 16 insertions(+), 50 deletions(-) diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c index 787a472c5743..0a0de69d44cd 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/amd64/amd64/mptable.c b/sys/amd64/amd64/mptable.c index 787a472c5743..0a0de69d44cd 100644 --- a/sys/amd64/amd64/mptable.c +++ b/sys/amd64/amd64/mptable.c @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/amd64/include/mptable.h b/sys/amd64/include/mptable.h index 787a472c5743..0a0de69d44cd 100644 --- a/sys/amd64/include/mptable.h +++ b/sys/amd64/include/mptable.h @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/amd64/include/profile.h b/sys/amd64/include/profile.h index 5f2a7807c07e..883daf5ee1db 100644 --- a/sys/amd64/include/profile.h +++ b/sys/amd64/include/profile.h @@ -64,10 +64,11 @@ #else #define MCOUNT_DECL(s) u_long s; #ifdef SMP -#define MCOUNT_ENTER(s) { s = read_eflags(); \ - __asm __volatile("cli" : : : "memory"); \ - mtx_lock(&mcount_mtx); } -#define MCOUNT_EXIT(s) { mtx_unlock(&mcount_mtx); write_eflags(s); } +#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); \ + while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1) \ + /* nothing */ ; } +#define MCOUNT_EXIT(s) { atomic_store_rel_int(&mcount_lock, 0); \ + write_eflags(s); } #else #define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } #define MCOUNT_EXIT(s) (write_eflags(s)) diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c index 787a472c5743..0a0de69d44cd 100644 --- a/sys/i386/i386/mp_machdep.c +++ b/sys/i386/i386/mp_machdep.c @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/i386/i386/mptable.c b/sys/i386/i386/mptable.c index 787a472c5743..0a0de69d44cd 100644 --- a/sys/i386/i386/mptable.c +++ b/sys/i386/i386/mptable.c @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/i386/include/mptable.h b/sys/i386/include/mptable.h index 787a472c5743..0a0de69d44cd 100644 --- a/sys/i386/include/mptable.h +++ b/sys/i386/include/mptable.h @@ -325,7 +325,7 @@ static void release_aps(void *dummy); struct mtx imen_mtx; /* lock region used by kernel profiling */ -struct mtx mcount_mtx; +int mcount_lock; #ifdef USE_COMLOCK /* locks com (tty) data/hardware accesses: a FASTINTR() */ @@ -335,12 +335,6 @@ struct mtx com_mtx; static void init_locks(void) { - /* - * XXX The mcount mutex probably needs to be statically initialized, - * since it will be used even in the function calls that get us to this - * point. - */ - mtx_init(&mcount_mtx, "mcount", MTX_DEF); #ifdef USE_COMLOCK mtx_init(&com_mtx, "com", MTX_SPIN); diff --git a/sys/i386/include/profile.h b/sys/i386/include/profile.h index 5f2a7807c07e..883daf5ee1db 100644 --- a/sys/i386/include/profile.h +++ b/sys/i386/include/profile.h @@ -64,10 +64,11 @@ #else #define MCOUNT_DECL(s) u_long s; #ifdef SMP -#define MCOUNT_ENTER(s) { s = read_eflags(); \ - __asm __volatile("cli" : : : "memory"); \ - mtx_lock(&mcount_mtx); } -#define MCOUNT_EXIT(s) { mtx_unlock(&mcount_mtx); write_eflags(s); } +#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); \ + while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1) \ + /* nothing */ ; } +#define MCOUNT_EXIT(s) { atomic_store_rel_int(&mcount_lock, 0); \ + write_eflags(s); } #else #define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } #define MCOUNT_EXIT(s) (write_eflags(s))