Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern syscall(2): Provide better attribution for biglock ...



details:   https://anonhg.NetBSD.org/src/rev/c604c36a9222
branches:  trunk
changeset: 363510:c604c36a9222
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 14 12:02:19 2022 +0000

description:
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.

diffstat:

 sys/kern/sys_syscall.c |  25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diffs (60 lines):

diff -r 0addb514621d -r c604c36a9222 sys/kern/sys_syscall.c
--- a/sys/kern/sys_syscall.c    Mon Mar 14 11:47:33 2022 +0000
+++ b/sys/kern/sys_syscall.c    Mon Mar 14 12:02:19 2022 +0000
@@ -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 @@
 
 #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 @@
        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 @@
                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



Home | Main Index | Thread Index | Old Index