From owner-freebsd-dtrace@FreeBSD.ORG Tue Sep 2 20:24:50 2014 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AB23E80B; Tue, 2 Sep 2014 20:24:50 +0000 (UTC) Received: from mail-la0-x22c.google.com (mail-la0-x22c.google.com [IPv6:2a00:1450:4010:c03::22c]) (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 D49451E92; Tue, 2 Sep 2014 20:24:49 +0000 (UTC) Received: by mail-la0-f44.google.com with SMTP id hz20so8573030lab.31 for ; Tue, 02 Sep 2014 13:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=9Deun8zuZsqJYjWbjp7FEY6WEOGxPDoKk+niyPXo9p8=; b=Ymwyrj4xdb/uYVq2YYBirEbWwmgJ+Q8YtPFv+nLj8OpY0hLeCY63siY/wjNdO9hqrQ Q8UTbS4o8C3giJNiPeszIUbtQIE1BjMQ8IOxAayvGPlqELkimLGy0ieQYUl8/OeRVzwY Ve/uajW19OGBFdKxIR0BkXcsNCfVlWKPdBmTaKcy07f/mCco9zcsEkZqqWCSVGb3IqyY 71N4oUELH0nJY2ktq6jsXInAYai7dZgtUkCqLSH34TOdY9PUL02CDmdGPrXq/V7ZpT50 RWIN4kmZ1Y6y35IIjZ21CjWTCyYQ+jo5pltv3153NYWMaRx74BCH6kv6uKb7SOweSoAB 4aLA== MIME-Version: 1.0 X-Received: by 10.112.198.34 with SMTP id iz2mr4360069lbc.96.1409689487839; Tue, 02 Sep 2014 13:24:47 -0700 (PDT) Received: by 10.25.205.2 with HTTP; Tue, 2 Sep 2014 13:24:47 -0700 (PDT) Date: Tue, 2 Sep 2014 13:24:47 -0700 Message-ID: Subject: Usage of DTRACE_PROBE macro from sdt.h in kernel modules From: Shrikanth Kamath To: freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org, markj@freebsd.org Content-Type: text/plain; charset=UTF-8 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, 02 Sep 2014 20:24:50 -0000 Adding a DTRACE_PROBE(name) in a kernel module does not create the SDT probe. I added the following to the module file before using DTRACE_PROBE. #include "opt_kdtrace.h" #include function_foo() { ... + DTRACE_PROBE(name); ... } I figured the sdt.h does declare SDT_PROVIDER_DECLARE(set); but that is not helping. Was expecting a sdt probe added under provider 'set'. The SDT probe creation returns from sdt_kld_load from here if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, NULL)) return; I did a nm on the kernel module and did not find anything matching "sdt_providers_set" nm -a module.ko | grep sdt 00000000 r __set_sdt_probes_set_sym_sdt_sdt______func____LINE__.103790 U __start_set_sdt_probes_set U __stop_set_sdt_probes_set U sdt_probe_func U sdt_provider_sdt 000006c0 d sdt_sdt______func____LINE__.103789 Can't seem to figure how to get the SDT probe created by using DTRACE_PROBE macro in a kernel module. From owner-freebsd-dtrace@FreeBSD.ORG Tue Sep 2 20:44:47 2014 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 15415E15; Tue, 2 Sep 2014 20:44:47 +0000 (UTC) Received: from mail-qa0-x233.google.com (mail-qa0-x233.google.com [IPv6:2607:f8b0:400d:c00::233]) (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 B5EAE110D; Tue, 2 Sep 2014 20:44:46 +0000 (UTC) Received: by mail-qa0-f51.google.com with SMTP id j7so6774921qaq.24 for ; Tue, 02 Sep 2014 13:44:45 -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=48LRUFGHwpxhGMJz82XrVxpnjH/xLk2ePxORjYPbE3U=; b=hGcU6LGB5ca1yVNX2cBDVnNdlSuqYw0gnzBVG9055d16fZwPP2DGswztUsAn6T90vG 7D3wR88yuM3LprArkFcx0d3+d3yA9P48aGoBgtAgXtgRVzO8E9m3VzFEtx5LXRGXe93V /l501hg0X0NqwtlOaJM6AnekcR1GpKtdAxKaFQBSaQQzEeVDAl/YjvDfqiE/WOWY6C/g YOm39lcF7h8xqisSMDG/L6Hxro+NZX34pqYuYnIdo56eqCp4i43HVWB8VrQQnJbyZmhs Aw6qQCvZP7R31xir7CBh1WPvpSJo6D22C8Mc736nUa6zy5fIqhVQkBa/H0cf23p3WSLL 0M1Q== X-Received: by 10.224.44.14 with SMTP id y14mr58461359qae.34.1409690685696; Tue, 02 Sep 2014 13:44:45 -0700 (PDT) Received: from charmander.home ([64.229.13.35]) by mx.google.com with ESMTPSA id j3sm12616965qaa.32.2014.09.02.13.44.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 13:44:45 -0700 (PDT) Sender: Mark Johnston Date: Tue, 2 Sep 2014 16:44:13 -0400 From: Mark Johnston To: Shrikanth Kamath Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules Message-ID: <20140902204413.GC59246@charmander.home> References: 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 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, 02 Sep 2014 20:44:47 -0000 On Tue, Sep 02, 2014 at 01:24:47PM -0700, Shrikanth Kamath wrote: > Adding a DTRACE_PROBE(name) in a kernel module does not create the SDT > probe. I added > the following to the module file before using DTRACE_PROBE. Somewhat confusingly, DTRACE_PROBE* shouldn't be used in the kernel. It's there for compatibility with the DTrace probes in ZFS, which use the SDT interfaces in illumos. The SDT_PROBE* macros should be used instead. If you grep the kernel sources, you'll find lots of examples of SDT providers and probes. > #include "opt_kdtrace.h" > #include > > function_foo() { > ... > + DTRACE_PROBE(name); > ... > } > > I figured the sdt.h does declare SDT_PROVIDER_DECLARE(set); but that > is not helping. Was expecting a sdt probe added under provider 'set'. SDT_PROVIDER_DEFINE() is used to define a provider. SDT_PROVIDER_DECLARE() just adds a declaration, so it won't result in anything being added to the SDT provider linker set in the corresponding kld. So SDT_PROVIDER_DEFINE() should be used once to define a new provider, and the provider can be made visible across multiple files using SDT_PROVIDER_DECLARE(). > > The SDT probe creation returns from sdt_kld_load from here > > if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, NULL)) > return; > > I did a nm on the kernel module and did not find anything matching > "sdt_providers_set" > > nm -a module.ko | grep sdt > > 00000000 r __set_sdt_probes_set_sym_sdt_sdt______func____LINE__.103790 > > U __start_set_sdt_probes_set > > U __stop_set_sdt_probes_set > > U sdt_probe_func > > U sdt_provider_sdt > > 000006c0 d sdt_sdt______func____LINE__.103789 > > Can't seem to figure how to get the SDT probe created by using > DTRACE_PROBE macro in a kernel module. In addition to the comments above, I suggest taking a look at the SDT(9) man page, which has a few examples. Thanks, -Mark From owner-freebsd-dtrace@FreeBSD.ORG Wed Sep 3 13:05:46 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 A9A36900; Wed, 3 Sep 2014 13:05:46 +0000 (UTC) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 7EF66144B; Wed, 3 Sep 2014 13:05:42 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id QAA13450; Wed, 03 Sep 2014 16:05:41 +0300 (EEST) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1XPAFo-000GcX-PB; Wed, 03 Sep 2014 16:05:40 +0300 Message-ID: <540711ED.2050909@FreeBSD.org> Date: Wed, 03 Sep 2014 16:04:45 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Mark Johnston , Shrikanth Kamath Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules References: <20140902204413.GC59246@charmander.home> In-Reply-To: <20140902204413.GC59246@charmander.home> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-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: Wed, 03 Sep 2014 13:05:46 -0000 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 From owner-freebsd-dtrace@FreeBSD.ORG Wed Sep 3 21:09:51 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 5991AEC4; Wed, 3 Sep 2014 21:09:51 +0000 (UTC) Received: from mail-lb0-x22b.google.com (mail-lb0-x22b.google.com [IPv6:2a00:1450:4010:c04::22b]) (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 540F015BB; Wed, 3 Sep 2014 21:09:50 +0000 (UTC) Received: by mail-lb0-f171.google.com with SMTP id 10so1820458lbg.30 for ; Wed, 03 Sep 2014 14:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5TUAsTdFDAT1EMz29YOwXKMyE7bwfxVe+kANDoh1YwY=; b=wIfT2MPVe4THb5QTeTSSBjQSgqZD/XLM3e6bUJLX5bbq9ZoVrkvOua2tCRaLRwkhMp RxW+pJ0MXGlb8VYXPgrjaNB1Llih3ELQyKtP2E0G7Cb5YAllRafKJ9pcLXfAzlKPC0uG +4UV47ZRJu2hWDqswdVwfRY34LLp//rugpOWYSvnkb8xqYOn9xK8RC0WfmaLCoQCgzon lTSVxeZIgPpxxLN1gZShen/MOiAZzeZc7XxtSyadg4oN7yXxNu9W6Vor0D6QJMabO3i9 wde/aMxvQdPMCo14GgJH+9Ptz51df2iE/8ALns26GnvG7+yIE+q4iIexBoTS5N1NlFAD lQdw== MIME-Version: 1.0 X-Received: by 10.112.199.42 with SMTP id jh10mr174202lbc.49.1409778588091; Wed, 03 Sep 2014 14:09:48 -0700 (PDT) Received: by 10.25.205.2 with HTTP; Wed, 3 Sep 2014 14:09:48 -0700 (PDT) In-Reply-To: <540711ED.2050909@FreeBSD.org> References: <20140902204413.GC59246@charmander.home> <540711ED.2050909@FreeBSD.org> Date: Wed, 3 Sep 2014 14:09:48 -0700 Message-ID: Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules From: Shrikanth Kamath To: avg@freebsd.org, markj@freebsd.org, freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org Content-Type: text/plain; charset=UTF-8 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: Wed, 03 Sep 2014 21:09:51 -0000 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; 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. 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 From owner-freebsd-dtrace@FreeBSD.ORG Wed Sep 3 23:50:24 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 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-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: 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 From owner-freebsd-dtrace@FreeBSD.ORG Thu Sep 4 09:23:29 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 C80F238A; Thu, 4 Sep 2014 09:23:29 +0000 (UTC) Received: from mail-la0-x22a.google.com (mail-la0-x22a.google.com [IPv6:2a00:1450:4010:c03::22a]) (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 B97AB1B1B; Thu, 4 Sep 2014 09:23:28 +0000 (UTC) Received: by mail-la0-f42.google.com with SMTP id mc6so11587275lab.29 for ; Thu, 04 Sep 2014 02:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=W1QI0/USO/27FH/hPfCrA9bA734UIm30Z8PE4LvoZac=; b=mN7EGmAOLA3OeWqjwOltTY1x/DQYFv1KL0s2GYin40S/jl7jYbbdMIYUxoUg1xV+Ig xu/PgkTXjtYOB+v2K5jGSST5VxZ7bfJDc+uNwukmxTj7s2nD304XEt12jKd2kfgPONA9 BkVA0X1UrF9noE4nMdwL9J56VN9P61zu5cKn+SogeBnQdpDO+mrfIk+ojUiDPDzQOk3k Kt9qs+T9xQaLmj0TY/zZPFyogZxs2oqvBY5aQgEap7aIznBvTJlISB3n3HyRXNTvYM2H dEqP2zCnAWpkSUzgVREAItkzSVjUn9Bca1GX/T7SJK85GNddaufOKZtMZPQBYDy2FDng Tnxg== MIME-Version: 1.0 X-Received: by 10.112.209.36 with SMTP id mj4mr3224027lbc.26.1409822606498; Thu, 04 Sep 2014 02:23:26 -0700 (PDT) Received: by 10.25.205.2 with HTTP; Thu, 4 Sep 2014 02:23:26 -0700 (PDT) In-Reply-To: <20140903234950.GB38016@charmander.home> References: <20140902204413.GC59246@charmander.home> <540711ED.2050909@FreeBSD.org> <20140903234950.GB38016@charmander.home> Date: Thu, 4 Sep 2014 02:23:26 -0700 Message-ID: Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules From: Shrikanth Kamath To: Mark Johnston Content-Type: text/plain; charset=UTF-8 Cc: freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org, avg@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: Thu, 04 Sep 2014 09:23:30 -0000 On Wed, Sep 3, 2014 at 4:49 PM, Mark Johnston wrote: > 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) > Mark, for some reason using a single probe does not seem to fire the probe. -- Shrikanth R K From owner-freebsd-dtrace@FreeBSD.ORG Thu Sep 4 17:48:12 2014 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B8C6CC36; Thu, 4 Sep 2014 17:48:12 +0000 (UTC) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "funkthat.com", Issuer "funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 91B251D18; Thu, 4 Sep 2014 17:48:12 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s84HmBK3000535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 4 Sep 2014 10:48:11 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id s84HmBZV000534; Thu, 4 Sep 2014 10:48:11 -0700 (PDT) (envelope-from jmg) Date: Thu, 4 Sep 2014 10:48:11 -0700 From: John-Mark Gurney To: Shrikanth Kamath Subject: Re: Usage of DTRACE_PROBE macro from sdt.h in kernel modules Message-ID: <20140904174811.GK82175@funkthat.com> Mail-Followup-To: Shrikanth Kamath , Mark Johnston , freebsd-hackers@freebsd.org, freebsd-dtrace@freebsd.org, avg@freebsd.org References: <20140902204413.GC59246@charmander.home> <540711ED.2050909@FreeBSD.org> <20140903234950.GB38016@charmander.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Thu, 04 Sep 2014 10:48:11 -0700 (PDT) Cc: freebsd-hackers@freebsd.org, avg@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: Thu, 04 Sep 2014 17:48:12 -0000 Shrikanth Kamath wrote this message on Thu, Sep 04, 2014 at 02:23 -0700: > On Wed, Sep 3, 2014 at 4:49 PM, Mark Johnston wrote: > > 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) > > > Mark, for some reason using a single probe does not seem to fire the probe. I'm doing something similar in my code: cryptodev.c:SDT_PROBE_DEFINE1(opencrypto, dev, ioctl, error, "int"/*line number*/); cryptodev.c: SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__); and it worked for me... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."