From owner-freebsd-hackers@FreeBSD.ORG Wed Sep 3 23:50:24 2014 Return-Path: Delivered-To: freebsd-hackers@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 883FFD94; Wed, 3 Sep 2014 23:50:24 +0000 (UTC) Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3FA541ABB; Wed, 3 Sep 2014 23:50:24 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id rl12so10739295iec.39 for ; Wed, 03 Sep 2014 16:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=5/W3aV/+j9dPX++4t9TJqLifhz6pPxZ8Ow9CAQCH+Zc=; b=l/9kQUNIJ7ORssopzFgqv/uTUqTPbLYTxzcqEe3NCHSZm/AZxU5EsPfDTIDc6BAYl6 +V7Qan8ydd2T1FCe0mDjs17ibtN/p9ed5TyvHwsWM/N0BbKq9Wl4lJG9R8Cm/hW3d0zY r/wFdIzglPz+zOGaGaKYIOYewfJDN/JA2YezjLC9JD90TSr9k45IeFG56WlOF8EIShQv 5/CBS72hd4lrW9KneMDYdS6HYkh91xmbrvorEy6AW5+uHUy9Drh/+7Vru0NWaFqQpSQT Fjmw/sgeEBViq8O/PdER1ZastUhSBDYnPspNSDqnDPCz2B4Yc5OaSMYC3YAf3Tvj44UG As+g== X-Received: by 10.42.204.76 with SMTP id fl12mr721777icb.80.1409788223647; Wed, 03 Sep 2014 16:50:23 -0700 (PDT) Received: from charmander.home ([64.229.13.35]) by mx.google.com with ESMTPSA id cj8sm6831568igb.11.2014.09.03.16.50.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Sep 2014 16:50:22 -0700 (PDT) Sender: Mark Johnston Date: Wed, 3 Sep 2014 19:49:50 -0400 From: Mark Johnston To: Shrikanth Kamath Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules Message-ID: <20140903234950.GB38016@charmander.home> References: <20140902204413.GC59246@charmander.home> <540711ED.2050909@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Cc: freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org, avg@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 23:50:24 -0000 On Wed, Sep 03, 2014 at 02:09:48PM -0700, Shrikanth Kamath wrote: > Thanks Mark/Andriy for helping with this query. I checked the define > KDTRACE_HOOKS define that is set. Rather I tried this, I defined a > fake provider just to check if that prompts sdt_kld_load to create the > SDT probes from my kernel module. > > + SDT_PROVIDER_DEFINE(fake); > And it does help load the SDT probes I created, even though I am not > using the fake provider I defined. I feel that sdt_kld_load is flawed > when it is looking for sdt_providers_set in the module. It expects at > least a provider define and cannot use one of the defined ones in > kernel by just declaring it. > > if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, > &end, NULL)) > return; You're completely right; this issue was fixed in http://svnweb.freebsd.org/base?view=revision&revision=267706 > > I intended to use DTRACE_PROBE() instead of the conventional > SDT_PROBE_DEFINE/SDT_PROBE usage because I wanted to create probes > which have probe names based on __LINE__ macro...disclaimer...this was > just for experiment sakes... > > E.g > func_foo() > { > .... > if () > return EINVAL; > ... > if () > return EINVAL; > ... > if () > return EINVAL; > } > > which I replaced with > func_foo() > { > ... > if () > RETSDT(func_foo, EINVAL); > ... > if () > RETSDT(func_foo, EINVAL); > ... > if () > RETSDT(func_foo, EINVAL); > } > where RETSDT macro and other macros are defined as > > #define PROBENAME1(func, __LINE__) func ## __LINE__ > #define PROBENAME(func, line) PROBENAME1(func, line) > > #define RETSDT(func, error_code) \ > do { \ > DTRACE_PROBE(PROBENAME(func, __LINE__));\ > return (error_code); \ > } while (0) > > With the fake provider I defined I get to see and execute my SDT probes > % dtrace -l | grep func_foo > 56455 sdt netstack func_foo1592 > > Here netstack is my module, and I have a probe name based on __LINE__ > which is 1592. Why not just use a single probe and make the line number and function name arguments to the probe? That is, write something like #define RETSDT(error_code) do { \ DTRACE_PROBE2(error__return, __func__, __LINE__) return (error_code); } while (0) > Don't know if that is good way to do it but using SDT_PROBE_DEFINE > looks like a problem because of the presence of __LINE__ in the > probename. > > Thanks for reaching out... > -- > Shrikanth R K > > On Wed, Sep 3, 2014 at 6:04 AM, Andriy Gapon wrote: > > on 02/09/2014 23:44 Mark Johnston said the following: > >> Somewhat confusingly, DTRACE_PROBE* shouldn't be used in the kernel. > > > > But it can be used. > > > > Shrikanth, please double check that KDTRACE_HOOKS is defined when you compile > > your module. > > > > -- > > Andriy Gapon