From f341fbf934364d96e2a1f932190f83b3d33b8adf Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 8 Mar 2015 22:45:16 +0000 Subject: [PATCH] dtrace bits from riastradh --- sys/dev/lockstat.c | 26 ++++++++++++++++++++++++-- sys/dev/lockstat.h | 16 +++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/sys/dev/lockstat.c b/sys/dev/lockstat.c index 9884fdd8bed9..fb1a8da7ea09 100644 --- a/sys/dev/lockstat.c +++ b/sys/dev/lockstat.c @@ -1,4 +1,4 @@ -/* $NetBSD: lockstat.c,v 1.19 2014/07/25 08:10:35 dholland Exp $ */ +/* $NetBSD: lockstat.c,v 1.20 2015/03/08 22:45:16 christos Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lockstat.c,v 1.19 2014/07/25 08:10:35 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lockstat.c,v 1.20 2015/03/08 22:45:16 christos Exp $"); #include #include @@ -110,6 +110,20 @@ size_t lockstat_sizeb; int lockstat_busy; struct timespec lockstat_stime; +#ifdef KDTRACE_HOOKS +CTASSERT(LB_NEVENT <= 3); +CTASSERT(LB_NLOCK <= (7 << LB_LOCK_SHIFT)); +void +lockstat_probe_stub(uint32_t id, uintptr_t lock, uintptr_t callsite, + uintptr_t flags, uintptr_t count, uintptr_t cycles) +{ +} + +uint32_t lockstat_probemap[LS_NPROBES]; +void (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t, + uintptr_t, uintptr_t, uintptr_t) = &lockstat_probe_stub; +#endif + const struct cdevsw lockstat_cdevsw = { .d_open = lockstat_open, .d_close = lockstat_close, @@ -344,6 +358,14 @@ lockstat_event(uintptr_t lock, uintptr_t callsite, u_int flags, u_int count, u_int event; int s; +#ifdef KDTRACE_HOOKS + uint32_t id; + CTASSERT((LS_NPROBES & (LS_NPROBES - 1)) == 0); + if ((id = lockstat_probemap[LS_COMPRESS(flags)]) != 0) + (*lockstat_probe_func)(id, lock, callsite, flags, count, + cycles); +#endif + if ((flags & lockstat_enabled) != flags || count == 0) return; if (lock < lockstat_lockstart || lock > lockstat_lockend) diff --git a/sys/dev/lockstat.h b/sys/dev/lockstat.h index d3d0e91b3196..ef95d7c05621 100644 --- a/sys/dev/lockstat.h +++ b/sys/dev/lockstat.h @@ -1,4 +1,4 @@ -/* $NetBSD: lockstat.h,v 1.10 2009/01/20 14:49:00 yamt Exp $ */ +/* $NetBSD: lockstat.h,v 1.11 2015/03/08 22:45:16 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -33,6 +33,7 @@ #define _SYS_LOCKSTAT_H_ #ifdef _KERNEL_OPT +#include "opt_dtrace.h" #include #endif @@ -195,4 +196,17 @@ extern volatile u_int lockstat_enabled; #endif +#ifdef KDTRACE_HOOKS +#define LS_COMPRESS(f) \ + ((((f) & 3) | (((f) & 7) >> 6)) & (LS_NPROBES - 1)) +#define LS_NPROBES 0x20 /* 5 bits */ + +extern uint32_t lockstat_probemap[]; +extern void (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t, + uintptr_t, uintptr_t, uintptr_t); + +void lockstat_probe_stub(uint32_t, uintptr_t, uintptr_t, + uintptr_t, uintptr_t, uintptr_t); +#endif + #endif /* _SYS_LOCKSTAT_H_ */