aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2022-04-12 21:51:59 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2022-04-12 21:52:25 +0000
commit4eb43c2c46ed0c9332e29a4b77a8961e6b9e3fa4 (patch)
treee84086e41ff58f7d4c18c87397d37bc327df1e80
parentc434b26cf3ebdb972f8e4121a5490a324a83d69c (diff)
downloadsrc-4eb43c2c46ed0c9332e29a4b77a8961e6b9e3fa4.tar.gz
src-4eb43c2c46ed0c9332e29a4b77a8961e6b9e3fa4.zip
KTR: Add CTR() and TR() macros which accept a variable number of arguments.
These can be used in place of the CTRn() macros which require n to match the number of optional arguments. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D34852
-rw-r--r--share/man/man9/ktr.917
-rw-r--r--sys/sys/ktr.h7
2 files changed, 21 insertions, 3 deletions
diff --git a/share/man/man9/ktr.9 b/share/man/man9/ktr.9
index c7f4138b855c..cfe9cacf8611 100644
--- a/share/man/man9/ktr.9
+++ b/share/man/man9/ktr.9
@@ -23,7 +23,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 26, 2021
+.Dd April 12, 2022
.Dt KTR 9
.Os
.Sh NAME
@@ -39,6 +39,8 @@
.Vt "extern int ktr_verbose" ;
.Vt "extern struct ktr_entry ktr_buf[]" ;
.Ft void
+.Fn CTR "u_int mask" "char *format" "..."
+.Ft void
.Fn CTR0 "u_int mask" "char *format"
.Ft void
.Fn CTR1 "u_int mask" "char *format" "arg1"
@@ -64,6 +66,8 @@ or
.Xr ktrdump 8 .
.Pp
Events are created and logged in the kernel via the
+.Dv CTR
+and
.Dv CTR Ns Ar x
macros.
The first parameter is a mask of event types
@@ -81,7 +85,7 @@ argument is a
style format string used to build the text of the event log message.
Following the
.Fa format
-string are zero to five arguments referenced by
+string are zero to six arguments referenced by
.Fa format .
Each event is logged with a file name and source line number of the
originating CTR call, and a timestamp in addition to the log message.
@@ -91,7 +95,9 @@ and formatting is done at the dump time.
Do not use pointers to the objects with limited lifetime, for instance,
strings, because the pointer may become invalid when buffer is printed.
.Pp
-Note that the different macros differ only in the number of arguments each
+The
+.Dv CTR Ns Ar x
+macros differ only in the number of arguments each
one takes, as indicated by its name.
.Pp
The
@@ -143,6 +149,11 @@ The KTR kernel tracing facility first appeared in
.Bsx 3.0
and was imported into
.Fx 5.0 .
+.Pp
+The
+.Fn CTR
+macro accepting a variable number of arguments first appeared in
+.Fx 14.0 .
.Sh BUGS
Currently there is one global buffer shared among all CPUs.
It might be profitable at some point in time to use per-CPU buffers instead
diff --git a/sys/sys/ktr.h b/sys/sys/ktr.h
index dc06be9fa9cb..396ad21cffc7 100644
--- a/sys/sys/ktr.h
+++ b/sys/sys/ktr.h
@@ -107,6 +107,13 @@ void ktr_tracepoint(uint64_t mask, const char *file, int line,
#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5)
#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6)
+#define _KTR_MACRO(m, format, _1, _2, _3, _4, _5, _6, NAME, ...) \
+ NAME
+#define CTR(...) \
+ _KTR_MACRO(__VA_ARGS__, CTR6, CTR5, CTR4, CTR3, CTR2, CTR1, \
+ CTR0)(__VA_ARGS__)
+#define TR(...) CTR(KTR_GEN, __VA_ARGS__)
+
/*
* The event macros implement KTR graphic plotting facilities provided
* by src/tools/sched/schedgraph.py. Three generic types of events are