summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-12-04 09:51:04 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-12-04 09:51:04 +0000
commit1764f0df2a112e820709360ae1c631b59cc1bc05 (patch)
tree6882f126f28754a7a4010a36ac6b74bde6cbb1bf /sys/kern
parent7c011d9e8d8db99faeb35a7df465a3d0da5621ac (diff)
Change __mp_lock_held() to work with an arbitrary CPU info structure and
extend ddb(4) "ps /o" output to print which CPU is currently holding the KERNEL_LOCK(). Tested by dhill@, ok visa@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_lock.c14
-rw-r--r--sys/kern/kern_proc.c16
2 files changed, 19 insertions, 11 deletions
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index 3b6adb16c93..f067a508bc7 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lock.c,v 1.51 2017/10/17 14:25:35 visa Exp $ */
+/* $OpenBSD: kern_lock.c,v 1.52 2017/12/04 09:51:03 mpi Exp $ */
/*
* Copyright (c) 1995
@@ -96,7 +96,7 @@ _kernel_lock_held(void)
{
if (panicstr)
return 1;
- return (__mp_lock_held(&kernel_lock));
+ return (__mp_lock_held(&kernel_lock, curcpu()));
}
#ifdef __USE_MI_MPLOCK
@@ -168,7 +168,7 @@ ___mp_lock(struct __mp_lock *mpl LOCK_FL_VARS)
unsigned long s;
#ifdef WITNESS
- if (!__mp_lock_held(mpl))
+ if (!__mp_lock_held(mpl, curcpu()))
WITNESS_CHECKORDER(&mpl->mpl_lock_obj,
LOP_EXCLUSIVE | LOP_NEWORDER, file, line, NULL);
#endif
@@ -191,7 +191,7 @@ ___mp_unlock(struct __mp_lock *mpl LOCK_FL_VARS)
unsigned long s;
#ifdef MP_LOCKDEBUG
- if (!__mp_lock_held(mpl)) {
+ if (!__mp_lock_held(mpl, curcpu())) {
db_printf("__mp_unlock(%p): not held lock\n", mpl);
db_enter();
}
@@ -244,7 +244,7 @@ ___mp_release_all_but_one(struct __mp_lock *mpl LOCK_FL_VARS)
#endif
#ifdef MP_LOCKDEBUG
- if (!__mp_lock_held(mpl)) {
+ if (!__mp_lock_held(mpl, curcpu())) {
db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl);
db_enter();
}
@@ -263,9 +263,9 @@ ___mp_acquire_count(struct __mp_lock *mpl, int count LOCK_FL_VARS)
}
int
-__mp_lock_held(struct __mp_lock *mpl)
+__mp_lock_held(struct __mp_lock *mpl, struct cpu_info *ci)
{
- struct __mp_lock_cpu *cpu = &mpl->mpl_cpus[cpu_number()];
+ struct __mp_lock_cpu *cpu = &mpl->mpl_cpus[CPU_INFO_UNIT(ci)];
return (cpu->mplc_ticket == mpl->mpl_ticket && cpu->mplc_depth > 0);
}
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 37ad3232b75..785636968be 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_proc.c,v 1.77 2017/09/29 09:36:04 mpi Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.78 2017/12/04 09:51:03 mpi Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
@@ -466,9 +466,10 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
{
char *mode;
int skipzomb = 0;
+ int has_kernel_lock = 0;
struct proc *p;
struct process *pr, *ppr;
-
+
if (modif[0] == 0)
modif[0] = 'n'; /* default == normal mode */
@@ -483,7 +484,7 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
db_printf("\t/o == show normal info for non-idle SONPROC\n");
return;
}
-
+
pr = LIST_FIRST(&allprocess);
switch (*mode) {
@@ -511,6 +512,12 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
ppr = pr->ps_pptr;
TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
+#ifdef MULTIPROCESSOR
+ if (__mp_lock_held(&kernel_lock, p->p_cpu))
+ has_kernel_lock = 1;
+ else
+ has_kernel_lock = 0;
+#endif
if (p->p_stat) {
if (*mode == 'o') {
if (p->p_stat != SONPROC)
@@ -556,10 +563,11 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
case 'o':
db_printf("%5d %5d %#10x %#10x %3d"
- " %-31s\n",
+ "%c %-31s\n",
pr->ps_pid, pr->ps_ucred->cr_ruid,
pr->ps_flags, p->p_flag,
CPU_INFO_UNIT(p->p_cpu),
+ has_kernel_lock ? 'K' : ' ',
pr->ps_comm);
break;