Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Jan 2018 00:11:56 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r327480 - in stable/11/sys: cddl/dev/sdt kern sys
Message-ID:  <201801020011.w020Buhk026508@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Tue Jan  2 00:11:56 2018
New Revision: 327480
URL: https://svnweb.freebsd.org/changeset/base/327480

Log:
  MFC r324867,r324869:
  
      sdt: whack unused SDT_PROBE_ENABLED
  
  =============
  
      sdt: make all sdt probe sites test one variable
  
      This saves on cache misses at the expense of a slight grow of .text.
  
      Note this is a bandaid for lack of hotpatching.

Modified:
  stable/11/sys/cddl/dev/sdt/sdt.c
  stable/11/sys/kern/kern_sdt.c
  stable/11/sys/sys/sdt.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/cddl/dev/sdt/sdt.c
==============================================================================
--- stable/11/sys/cddl/dev/sdt/sdt.c	Tue Jan  2 00:07:28 2018	(r327479)
+++ stable/11/sys/cddl/dev/sdt/sdt.c	Tue Jan  2 00:11:56 2018	(r327480)
@@ -76,6 +76,8 @@ static void	sdt_kld_unload_try(void *, struct linker_f
 
 static MALLOC_DEFINE(M_SDT, "SDT", "DTrace SDT providers");
 
+static int sdt_probes_enabled_count;
+
 static dtrace_pattr_t sdt_attr = {
 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
@@ -208,6 +210,9 @@ sdt_enable(void *arg __unused, dtrace_id_t id, void *p
 	probe->sdtp_lf->nenabled++;
 	if (strcmp(probe->prov->name, "lockstat") == 0)
 		lockstat_enabled++;
+	sdt_probes_enabled_count++;
+	if (sdt_probes_enabled_count == 1)
+		sdt_probes_enabled = true;
 }
 
 static void
@@ -217,6 +222,9 @@ sdt_disable(void *arg __unused, dtrace_id_t id, void *
 
 	KASSERT(probe->sdtp_lf->nenabled > 0, ("no probes enabled"));
 
+	sdt_probes_enabled_count--;
+	if (sdt_probes_enabled_count == 0)
+		sdt_probes_enabled = false;
 	if (strcmp(probe->prov->name, "lockstat") == 0)
 		lockstat_enabled--;
 	probe->id = 0;

Modified: stable/11/sys/kern/kern_sdt.c
==============================================================================
--- stable/11/sys/kern/kern_sdt.c	Tue Jan  2 00:07:28 2018	(r327479)
+++ stable/11/sys/kern/kern_sdt.c	Tue Jan  2 00:11:56 2018	(r327480)
@@ -37,6 +37,7 @@ SDT_PROVIDER_DEFINE(sdt);
  * dtrace_probe() when it loads.
  */
 sdt_probe_func_t sdt_probe_func = sdt_probe_stub;
+volatile bool __read_frequently sdt_probes_enabled;
 
 /*
  * This is a stub for probe calls in case kernel DTrace support isn't

Modified: stable/11/sys/sys/sdt.h
==============================================================================
--- stable/11/sys/sys/sdt.h	Tue Jan  2 00:07:28 2018	(r327479)
+++ stable/11/sys/sys/sdt.h	Tue Jan  2 00:11:56 2018	(r327480)
@@ -80,13 +80,14 @@
 #include <sys/cdefs.h>
 #include <sys/linker_set.h>
 
+extern volatile bool sdt_probes_enabled;
+
 #ifndef KDTRACE_HOOKS
 
 #define SDT_PROVIDER_DEFINE(prov)
 #define SDT_PROVIDER_DECLARE(prov)
 #define SDT_PROBE_DEFINE(prov, mod, func, name)
 #define SDT_PROBE_DECLARE(prov, mod, func, name)
-#define SDT_PROBE_ENABLED(prov, mod, func, name)	0
 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype)
 
@@ -161,14 +162,13 @@ SET_DECLARE(sdt_argtypes_set, struct sdt_argtype);
 #define SDT_PROBE_DECLARE(prov, mod, func, name)				\
 	extern struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1]
 
-#define SDT_PROBE_ENABLED(prov, mod, func, name)				\
-	__predict_false((sdt_##prov##_##mod##_##func##_##name->id))
-
 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)	do {	\
-	if (__predict_false(sdt_##prov##_##mod##_##func##_##name->id))		\
+	if (__predict_false(sdt_probes_enabled)) {				\
+		if (__predict_false(sdt_##prov##_##mod##_##func##_##name->id))	\
 		(*sdt_probe_func)(sdt_##prov##_##mod##_##func##_##name->id,	\
 		    (uintptr_t) arg0, (uintptr_t) arg1, (uintptr_t) arg2,	\
 		    (uintptr_t) arg3, (uintptr_t) arg4);			\
+	} \
 } while (0)
 
 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype)		\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801020011.w020Buhk026508>