Module Name: src
Committed By: riastradh
Date: Mon Mar 14 12:02:19 UTC 2022
Modified Files:
src/sys/kern: sys_syscall.c
Log Message:
syscall(2): Provide better attribution for biglock slippage.
This adds a small overhead to the syscall path, but only when invoked
via the syscall(2) syscall, for which stack traces generally don't
print the actual syscall number in question so the better attribution
may make a difference.
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/sys_syscall.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/sys_syscall.c
diff -u src/sys/kern/sys_syscall.c:1.13 src/sys/kern/sys_syscall.c:1.14
--- src/sys/kern/sys_syscall.c:1.13 Sat Feb 8 07:07:07 2020
+++ src/sys/kern/sys_syscall.c Mon Mar 14 12:02:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_syscall.c,v 1.13 2020/02/08 07:07:07 maxv Exp $ */
+/* $NetBSD: sys_syscall.c,v 1.14 2022/03/14 12:02:19 riastradh Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_syscall.c,v 1.13 2020/02/08 07:07:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_syscall.c,v 1.14 2022/03/14 12:02:19 riastradh Exp $");
#include <sys/syscall_stats.h>
#include <sys/syscallvar.h>
@@ -44,6 +44,19 @@ __KERNEL_RCSID(0, "$NetBSD: sys_syscall.
#define CONCAT(a,b) __CONCAT(a,b)
+static void
+CONCAT(SYS_SYSCALL, _biglockcheck)(struct proc *p, int code)
+{
+
+#ifdef DIAGNOSTIC
+ kpreempt_disable(); /* make curcpu() stable */
+ KASSERTMSG(curcpu()->ci_biglock_count == 0,
+ "syscall %ld of emul %s leaked %d kernel locks",
+ (long)code, p->p_emul->e_name, curcpu()->ci_biglock_count);
+ kpreempt_enable();
+#endif
+}
+
int
SYS_SYSCALL(struct lwp *l, const struct CONCAT(SYS_SYSCALL, _args) *uap,
register_t *rval)
@@ -73,8 +86,11 @@ SYS_SYSCALL(struct lwp *l, const struct
if (__predict_false(callp->sy_flags & SYCALL_INDIRECT))
return ENOSYS;
- if (__predict_true(!p->p_trace_enabled))
- return sy_call(callp, l, &uap->args, rval);
+ if (__predict_true(!p->p_trace_enabled)) {
+ error = sy_call(callp, l, &uap->args, rval);
+ CONCAT(SYS_SYSCALL, _biglockcheck)(p, code);
+ return error;
+ }
#ifdef NETBSD32_SYSCALL
narg = callp->sy_narg;
@@ -87,6 +103,7 @@ SYS_SYSCALL(struct lwp *l, const struct
return error;
error = sy_call(callp, l, &uap->args, rval);
trace_exit(code, callp, &uap->args, rval, error);
+ CONCAT(SYS_SYSCALL, _biglockcheck)(p, code);
return error;
#undef TRACE_ARGS