svn commit: r262025 - in stable/9: share/man/man9 sys/cddl/dev/sdt sys/sys
Andriy Gapon
avg at FreeBSD.org
Mon Feb 17 11:36:31 UTC 2014
Author: avg
Date: Mon Feb 17 11:36:30 2014
New Revision: 262025
URL: http://svnweb.freebsd.org/changeset/base/262025
Log:
MFC r254468,r254469: Add a "translated type" argument to SDT_PROBE_ARGTYPE()
Note: this breaks ABI compatibility with older modules with SDT probes.
My opinion is that benefits outweigh downsides, because I am not aware
of any thirdparty binary-only modules with SDT probes.
Modified:
stable/9/share/man/man9/SDT.9
stable/9/sys/cddl/dev/sdt/sdt.c
stable/9/sys/sys/sdt.h
Directory Properties:
stable/9/share/man/man9/ (props changed)
stable/9/sys/ (props changed)
stable/9/sys/sys/ (props changed)
Modified: stable/9/share/man/man9/SDT.9
==============================================================================
--- stable/9/share/man/man9/SDT.9 Mon Feb 17 11:28:27 2014 (r262024)
+++ stable/9/share/man/man9/SDT.9 Mon Feb 17 11:36:30 2014 (r262025)
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 3, 2013
+.Dd August 17, 2013
.Dt SDT 9
.Os
.Sh NAME
@@ -45,6 +45,19 @@
.Fn SDT_PROBE_DEFINE6 prov mod func name sname arg0 arg1 arg2 arg3 arg4 arg5
.Fn SDT_PROBE_DEFINE7 prov mod func name sname arg0 arg1 arg2 arg3 arg4 arg5 \
arg6
+.Fn SDT_PROBE_DEFINE0_XLATE prov mod func name sname
+.Fn SDT_PROBE_DEFINE1_XLATE prov mod func name sname arg0 xarg0
+.Fn SDT_PROBE_DEFINE2_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1
+.Fn SDT_PROBE_DEFINE3_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1 \
+ arg2 xarg2
+.Fn SDT_PROBE_DEFINE4_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1 \
+ arg2 xarg2 arg3 xarg3
+.Fn SDT_PROBE_DEFINE5_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1 \
+ arg2 xarg2 arg3 xarg3 arg4 xarg4
+.Fn SDT_PROBE_DEFINE6_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1 \
+ arg2 xarg2 arg3 xarg3 arg4 xarg4 arg5 xarg5
+.Fn SDT_PROBE_DEFINE7_XLATE prov mod func name sname arg0 xarg0 arg1 xarg1 \
+ arg2 xarg2 arg3 xarg3 arg4 xarg4 arg5 xarg5 arg6 xarg6
.Fn SDT_PROBE0 prov mod func name
.Fn SDT_PROBE1 prov mod func name arg0
.Fn SDT_PROBE2 prov mod func name arg0 arg1
@@ -151,6 +164,30 @@ It is strongly recommended that probe de
argument types.
.Pp
The
+.Fn SDT_PROBE_DEFINE*_XLATE
+macros are used for probes whose argument types are to be dynamically translated
+to the types specified by the corresponding
+.Ar xarg
+arguments.
+This is mainly useful when porting probe definitions from other operating
+systems.
+As seen by
+.Xr dtrace 1 ,
+the arguments of a probe defined using these macros will have types which match
+the
+.Ar xarg
+types in the probe definition.
+However, the arguments passed in at the trace point will have types matching the
+native argument types in the probe definition, and thus the native type is
+dynamically translated to the translated type.
+So long as an appropriate translator is defined in
+.Pa /usr/lib/dtrace ,
+scripts making use of the probe need not concern themselves with the underlying
+type of a given
+.Nm
+probe argument.
+.Pp
+The
.Fn SDT_PROBE*
macros are used to create
.Nm
@@ -166,21 +203,20 @@ of type Destination Unreachable:
.Bd -literal -offset indent
SDT_PROVIDER_DECLARE(icmp);
-SDT_PROBE_DEFINE2(icmp, , unreach, pkt_receive, pkt-receive,
- "struct mbuf *", "struct icmp *");
+SDT_PROBE_DEFINE1(icmp, , unreach, pkt_receive, pkt-receive,
+ "struct icmp *");
.Ed
-This particular probe would take two arguments: a pointer to the
-.Xr mbuf 9
-containing the incoming packet, and a pointer to the ICMP header for the packet.
+This particular probe would take a single argument: a pointer to the struct
+containing the ICMP header for the packet.
Note that the module name of this probe is not specified.
.Pp
Consider a DTrace probe which fires when the network stack receives an IP
packet.
Such a probe would be defined by multiple tracepoints:
.Bd -literal -offset indent
-SDT_PROBE_DEFINE2(ip, , , receive, receive, "struct mbuf *",
- "struct ifnet *", "struct ip *", "struct ip6_hdr *");
+SDT_PROBE_DEFINE3(ip, , , receive, receive, "struct ifnet *",
+ "struct ip *", "struct ip6_hdr *");
int
ip_input(struct mbuf *m)
@@ -188,7 +224,7 @@ ip_input(struct mbuf *m)
struct ip *ip;
...
ip = mtod(m, struct ip *);
- SDT_PROBE4(ip, , , receive, m, m->m_pkthdr.rcvif, ip, NULL);
+ SDT_PROBE3(ip, , , receive, m->m_pkthdr.rcvif, ip, NULL);
...
}
@@ -198,13 +234,46 @@ ip6_input(struct mbuf *m)
struct ip6_hdr *ip6;
...
ip6 = mtod(m, struct ip6_hdr *);
- SDT_PROBE4(ip, , , receive, m, m->m_pkthdr.rcvif, NULL, ip6);
+ SDT_PROBE3(ip, , , receive, m->m_pkthdr.rcvif, NULL, ip6);
...
}
.Ed
In particular, the probe should fire when the kernel receives either an IPv4
packet or an IPv6 packet.
+.Pp
+Consider the ICMP probe discussed above.
+We note that its second argument is of type
+.Ar struct icmp ,
+which is a type defined in the FreeBSD kernel to represent the ICMP header of
+an ICMP packet, defined in RFC 792.
+Linux has a corresponding type,
+.Ar struct icmphdr ,
+for the same purpose, but its field names differ from FreeBSD's
+.Ar struct icmp .
+Similarly, illumos defines the
+.Ar icmph_t
+type, again with different field names.
+Even with the
+.Ql icmp:::pkt-receive
+probes defined in all three operating systems,
+one would still have to write OS-specific scripts to extract a given field out
+of the ICMP header argument.
+Dynamically-translated types solve this problem: one can define an
+OS-independent
+.Xr c 7
+struct to represent an ICMP header, say
+.Ar struct icmp_hdr_dt ,
+and define translators from each of the three OS-specific types to
+.Ar struct icmp_hdr_dt ,
+all in the
+.Xr dtrace 1
+library path.
+Then the FreeBSD probe above can be defined with:
+.Bd -literal -offset indent
+SDT_PROBE_DEFINE1_XLATE(ip, , , receive, receive, "struct icmp *",
+ "struct icmp_hdr_dt *");
+.Ed
.Sh SEE ALSO
.Xr dtrace 1
.Sh AUTHORS
Modified: stable/9/sys/cddl/dev/sdt/sdt.c
==============================================================================
--- stable/9/sys/cddl/dev/sdt/sdt.c Mon Feb 17 11:28:27 2014 (r262024)
+++ stable/9/sys/cddl/dev/sdt/sdt.c Mon Feb 17 11:36:30 2014 (r262025)
@@ -201,11 +201,15 @@ sdt_getargdesc(void *arg, dtrace_id_t id
if (desc->dtargd_ndx < probe->n_args) {
TAILQ_FOREACH(argtype, &probe->argtype_list, argtype_entry) {
if (desc->dtargd_ndx == argtype->ndx) {
- /* XXX */
desc->dtargd_mapping = desc->dtargd_ndx;
strlcpy(desc->dtargd_native, argtype->type,
sizeof(desc->dtargd_native));
- desc->dtargd_xlate[0] = '\0'; /* XXX */
+ if (argtype->xtype != NULL)
+ strlcpy(desc->dtargd_xlate,
+ argtype->xtype,
+ sizeof(desc->dtargd_xlate));
+ else
+ desc->dtargd_xlate[0] = '\0';
}
}
} else
Modified: stable/9/sys/sys/sdt.h
==============================================================================
--- stable/9/sys/sys/sdt.h Mon Feb 17 11:28:27 2014 (r262024)
+++ stable/9/sys/sys/sdt.h Mon Feb 17 11:36:30 2014 (r262025)
@@ -87,7 +87,7 @@
#define SDT_PROBE_DEFINE(prov, mod, func, name, sname)
#define SDT_PROBE_DECLARE(prov, mod, func, name)
#define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
-#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type)
+#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype)
#define SDT_PROBE_DEFINE0(prov, mod, func, name, sname)
#define SDT_PROBE_DEFINE1(prov, mod, func, name, sname, arg0)
@@ -110,6 +110,22 @@
#define SDT_PROBE7(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5, \
arg6)
+#define SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name, sname)
+#define SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, sname, arg0, xarg0)
+#define SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1)
+#define SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2)
+#define SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3)
+#define SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4)
+#define SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5)
+#define SDT_PROBE_DEFINE7_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5, arg6, \
+ xarg6)
+
#else
SET_DECLARE(sdt_providers_set, struct sdt_provider);
@@ -143,9 +159,9 @@ SET_DECLARE(sdt_argtypes_set, struct sdt
(uintptr_t) arg3, (uintptr_t) arg4); \
} while (0)
-#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type) \
+#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype) \
static struct sdt_argtype sdt_##prov##_##mod##_##func##_##name##num[1] \
- = { { num, type, { NULL, NULL }, \
+ = { { num, type, xtype, { NULL, NULL }, \
sdt_##prov##_##mod##_##func##_##name } \
}; \
DATA_SET(sdt_argtypes_set, sdt_##prov##_##mod##_##func##_##name##num);
@@ -155,54 +171,113 @@ SET_DECLARE(sdt_argtypes_set, struct sdt
#define SDT_PROBE_DEFINE1(prov, mod, func, name, sname, arg0) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0)
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL)
#define SDT_PROBE_DEFINE2(prov, mod, func, name, sname, arg0, arg1) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1)
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL)
#define SDT_PROBE_DEFINE3(prov, mod, func, name, sname, arg0, arg1, arg2)\
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2)
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL)
#define SDT_PROBE_DEFINE4(prov, mod, func, name, sname, arg0, arg1, arg2, arg3) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3)
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL)
#define SDT_PROBE_DEFINE5(prov, mod, func, name, sname, arg0, arg1, arg2, arg3, arg4) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4)
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL)
#define SDT_PROBE_DEFINE6(prov, mod, func, name, sname, arg0, arg1, arg2, arg3,\
arg4, arg5) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5);
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, NULL)
#define SDT_PROBE_DEFINE7(prov, mod, func, name, sname, arg0, arg1, arg2, arg3,\
arg4, arg5, arg6) \
SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5); \
- SDT_PROBE_ARGTYPE(prov, mod, func, name, 6, arg6);
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, NULL); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 6, arg6, NULL)
+
+#define SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name, sname) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname)
+
+#define SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, sname, arg0, xarg0) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0)
+
+#define SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1)
+
+#define SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2)
+
+#define SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3)
+
+#define SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4)
+
+#define SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, xarg5)
+
+#define SDT_PROBE_DEFINE7_XLATE(prov, mod, func, name, sname, arg0, xarg0, \
+ arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5, arg6, \
+ xarg6) \
+ SDT_PROBE_DEFINE(prov, mod, func, name, sname); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, xarg5); \
+ SDT_PROBE_ARGTYPE(prov, mod, func, name, 6, arg6, xarg6)
#define SDT_PROBE0(prov, mod, func, name) \
SDT_PROBE(prov, mod, func, name, 0, 0, 0, 0, 0)
@@ -257,12 +332,12 @@ struct sdt_provider;
struct linker_file;
struct sdt_argtype {
- int ndx; /* Argument index. */
- const char *type; /* Argument type string. */
+ int ndx; /* Argument index. */
+ const char *type; /* Argument type string. */
+ const char *xtype; /* Translated argument type. */
TAILQ_ENTRY(sdt_argtype)
argtype_entry; /* Argument type list entry. */
- struct sdt_probe
- *probe; /* Ptr to the probe structure. */
+ struct sdt_probe *probe; /* Ptr to the probe structure. */
};
struct sdt_probe {
More information about the svn-src-stable-9
mailing list