From owner-freebsd-dtrace@FreeBSD.ORG Tue Sep 16 10:05:27 2014 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8619BB6C; Tue, 16 Sep 2014 10:05:27 +0000 (UTC) Received: from smtp1.multiplay.co.uk (smtp1.multiplay.co.uk [85.236.96.35]) by mx1.freebsd.org (Postfix) with ESMTP id EE35918F; Tue, 16 Sep 2014 10:05:26 +0000 (UTC) Received: by smtp1.multiplay.co.uk (Postfix, from userid 65534) id F093320E7088F; Tue, 16 Sep 2014 10:05:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.multiplay.co.uk X-Spam-Level: * X-Spam-Status: No, score=1.3 required=8.0 tests=AWL,BAYES_00,DOS_OE_TO_MX, FSL_HELO_NON_FQDN_1,RDNS_DYNAMIC,STOX_REPLY_TYPE autolearn=no version=3.3.1 Received: from r2d2 (82-69-141-170.dsl.in-addr.zen.co.uk [82.69.141.170]) by smtp1.multiplay.co.uk (Postfix) with ESMTP id 1A4D720E70886; Tue, 16 Sep 2014 10:05:13 +0000 (UTC) Message-ID: From: "Steven Hartland" To: "Mark Johnston" , "Matthew Ahrens" References: <20140916031318.GB26720@charmander.picturesperfect.net> Subject: Re: ZFS SET_ERROR dtrace probe possible under FreeBSD? Date: Tue, 16 Sep 2014 11:05:09 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Cc: hackers@freebsd.org, freebsd-dtrace@freebsd.org X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Sep 2014 10:05:27 -0000 ----- Original Message ----- From: "Mark Johnston" > On Mon, Sep 15, 2014 at 07:59:50PM -0700, Matthew Ahrens wrote: >> Disclaimer: I'm not an expert in FreeBSD dtrace. >> >> It looks like the FreeBSD kernel uses these declaration for kernel SDT >> probes, in sdt.h: >> >> 333 #*define* >> DTRACE_PROBE1 (name >> , >> type0 , >> arg0 ) \334 >> DTRACE_PROBE_IMPL_START >> (name >> , arg0 >> , 0, >> 0, 0, 0) \335 >> SDT_PROBE_ARGTYPE >> (sdt >> , , >> , name , >> 0, #type0 , >> NULL ); \336 >> DTRACE_PROBE_IMPL_END >> >> >> >> 324 #*define* DTRACE_PROBE_IMPL_START >> (name >> , arg0 >> , arg1 >> , arg2 >> , arg3 >> , arg4 >> ) *do* >> { \325 *static* >> SDT_PROBE_DEFINE >> (sdt >> , , >> , name ); >> \326 SDT_PROBE >> (sdt >> , , >> , name , >> arg0 , >> arg1 , >> arg2 , >> arg3 , >> arg4 );327 >> #*define* >> DTRACE_PROBE_IMPL_END >> } >> *while* (0) >> >> >> 163 #*define* >> SDT_PROBE (prov >> , >> mod , >> func , >> name , >> arg0 , >> arg1 , >> arg2 , >> arg3 , >> arg4 ) *do* >> { \164 *if* >> (sdt_ ##prov >> ##_##mod >> ##_##func >> ##_##name >> ->id >> ) \165 >> (*sdt_probe_func >> )(sdt_ >> ##prov >> ##_##mod >> ##_##func >> ##_##name >> ->id >> , \166 >> >> (uintptr_t ) >> arg0 , >> (uintptr_t ) >> arg1 , >> (uintptr_t ) >> arg2 , \167 >> >> (uintptr_t ) >> arg3 , >> (uintptr_t ) >> arg4 ); \168 >> } >> *while* (0) >> >> >> To do the equivalent "extra static" magic, you will need to expand out the >> DTRACE_PROBE1 macro. I think it should look something like: >> >> SDT_PROBE_DEFINE1(sdt, zfs, , set__error, "int"); >> >> #define SET_ERROR(err) \ >> ((sdt_sdt_zfs__set__error->id && \ >> (*sdt_probe_func)(sdt_sdt_zfs__set__error->id, (uintptr_t)err, 0, 0, 0, >> 0)), \ >> err) > > I think it would need to be > > SDT_PROBE_DECLARE(sdt, , , set__error); > > #define SET_ERROR(err) ... > > in the compat sdt.h, and then kern_dtrace.c or so would contain > > SDT_PROBE_DEFINE1(sdt, , , set__error, "int"); > > Note that the module shouldn't be hard-coded - it'll be filled in when > the probes are created by the SDT code. Thanks guys for the pointers, I tried the following slightly ammended from Matts original due to sdt_probe_func being a void return: Index: sys/cddl/compat/opensolaris/sys/sdt.h =================================================================== --- sys/cddl/compat/opensolaris/sys/sdt.h (revision 271518) +++ sys/cddl/compat/opensolaris/sys/sdt.h (working copy) @@ -34,6 +34,11 @@ #endif #include_next -#define SET_ERROR(err) (err) +SDT_PROBE_DECLARE(sdt, , , set__error); +#define SET_ERROR(err) \ + ((sdt_sdt___set__error->id ? \ + (*sdt_probe_func)(sdt_sdt___set__error->id, \ + (uintptr_t)err, 0, 0, 0, 0) : 0), err) + #endif /* _OPENSOLARIS_SYS_SDT_H_ */ Index: sys/kern/kern_dtrace.c =================================================================== --- sys/kern/kern_dtrace.c (revision 271518) +++ sys/kern/kern_dtrace.c (working copy) @@ -48,6 +48,8 @@ FEATURE(kdtrace_hooks, static MALLOC_DEFINE(M_KDTRACE, "kdtrace", "DTrace hooks"); +SDT_PROBE_DEFINE1(sdt, , , set__error, "int"); + /* Hooks used in the machine-dependent trap handlers. */ dtrace_trap_func_t dtrace_trap_func; dtrace_doubletrap_func_t dtrace_doubletrap_func; But it fails with:- /usr/src/sys/kern/kern_dtrace.c:51:24: error: expected identifier SDT_PROBE_DEFINE1(sdt, , , set__error, "int"); ^ /usr/src/sys/kern/kern_dtrace.c:51:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] SDT_PROBE_DEFINE1(sdt, , , set__error, "int"); All other calls to SDT_PROBE_DEFINE1 seem to define all args e.g. sys/kern/kern_exit.c:SDT_PROBE_DEFINE1(proc, kernel, , exit, "int"); Are you sure they should be ommited? Also is kern_dtrace.c the correct place for the probe define given its zfs specific? Regards Steve