linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: "fweisbec@gmail.com" <fweisbec@gmail.com>,
	"jeyu@kernel.org" <jeyu@kernel.org>,
	"mathieu.desnoyers@efficios.com" <mathieu.desnoyers@efficios.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mingo@elte.hu" <mingo@elte.hu>,
	"chris@chris-wilson.co.uk" <chris@chris-wilson.co.uk>,
	"yuanhan.liu@linux.intel.com" <yuanhan.liu@linux.intel.com>,
	"Grumbach, Emmanuel" <emmanuel.grumbach@intel.com>
Subject: Re: [PATCH][RFC] tracing: Enable tracepoints via module parameters
Date: Tue, 20 Apr 2021 23:27:19 -0700	[thread overview]
Message-ID: <CAPcyv4gS7iDrahX9i0PGMhR4k14XVkrCyGk3ZX8JEtO9RAQDhw@mail.gmail.com> (raw)
In-Reply-To: <20210420163243.45293c9a@gandalf.local.home>

On Tue, Apr 20, 2021 at 1:33 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 20 Apr 2021 12:54:39 -0700
> Dan Williams <dan.j.williams@intel.com> wrote:
>
> > On Tue, Apr 20, 2021 at 5:55 AM Steven Rostedt <rostedt@goodmis.org> wrote:
> > > >
> > > > The dev_dbg() filter language is attractive, it's too bad
> > >
> > > Not sure what you mean by that. What filter language. Tracepoints do have a
> > > pretty good filtering too.
> >
> > I'm trying to replicate dev_dbg() usability with tracing. So, when
> > people say "don't use dev_dbg() for that" that tracing can reliably
> > replace everything that dev_dbg() was offering. What I think that
> > looks like is the ability to turn on function tracing by a function
> > name glob in addition to any tracepoints in those same functions all
> > from the kernel boot command line, or a module parameter.
>
> You can enable functions on the kernel command line in globs (and trace
> events as well). And if the kernel command line doesn't work properly (it's
> not as tested as the run time side is), it should be trivial to fix it.
>
>
> >
> > > > trace_printk() has such a high runtime cost as combining dynamic-debug
> > > > and tracing would seem to be a panacea.
> > >
> > > trace_printk() has a high runtime cost? Besides that it's not allowed on
> > > production code (see nasty banner), it is made to be extremely fast.
> > > Although, it does do sprintf() work.
> >
> > I was referring to the banner. dev_dbg() does not have that production
> > code restriction.
>
> You can have a tracepoint like trace_printk that doesn't give a banner.
> Basically, the reason trace_printk() has that restriction is because you
> can't filter it like you can trace events. It's similar to a printk(). If I
> had allowed trace_printk() in the kernel, it would be all over the place,
> and it would just add a bunch of noise to the trace output, because its
> either on or off. And if you have trace_printk() and so would all other
> systems, and then you would deal with trace_printk()s from everyone which
> could drown out the ones you want. Hence, I added that banner to keep that
> from happening. trace_printk() will even drown out events. (I hate it when
> I leave one in my debug kernel, and it adds a bunch of noise against what
> I'm trying to debug with events!).
>
> But you can add your own trace point, and even make it generic. That's what
> bpf did for their bpf_trace_printk. You could convert dev_dbg() into a
> tracepoint!
>
>
> static __printf(2, 3) int __dev_dbg(const struct device *dev, char *fmt, ...)
> {
>         static char buf[DEV_DEBUG_PRINTK_SIZE];
>         unsigned long flags;
>         va_list ap;
>         int ret;
>
>         raw_spin_lock_irqsave(&dev_dbg_printk_lock, flags);
>         va_start(ap, fmt);
>         ret = vsnprintf(buf, sizeof(buf), fmt, ap);
>         va_end(ap);
>         /* vsnprintf() will not append null for zero-length strings */
>         if (ret == 0)
>                 buf[0] = '\0';
>         trace_dev_dbg_printk(dev, buf);
>         raw_spin_unlock_irqrestore(&dev_dbg_printk_lock, flags);
>
>         return ret;
> }
>
> #define dev_dbg(dev, fmt, ...)                                  \
>         do {                                                    \
>                 if (trace_dev_dbg_printk_enabled())             \
>                         __dev_dbg(dev, fmt, ##__VA_ARGS__);     \
>         } while (0)
>
> Note, the "trace_dev_dbg_printk_enabled()" is a static branch, which means
> it is a nop when the dev_dbg_printk tracepoint is not enabled, and is a jmp
> to the __dev_dbg() logic when it is enabled. It's not a conditional branch.
>
> And have:
>
> TRACE_EVENT(dev_dbg_printk,
>
>         TP_PROTO(const struct device *dev, const char *dbg_str),
>
>         TP_ARGS(dev, dbg_str),
>
>         TP_STRUCT__entry(
>                 __field(const struct device *dev)
>                 __string(dev_name, dev_name(dev))
>                 __string(dbg_str, dbg_str)
>         ),
>
>         TP_fast_assign(
>                 __entry->dev = dev;
>                 __assign_str(dev_name, dev_name(dev))
>                 __assign_str(dbg_str, dbg_str);
>         ),
>
>         TP_printk("%p dev=%s %s", __entry->dev, __get_string(dev_name), __get_str(dbg_str))
> );
>
> And then you could even filter on the device name, or even parts of the
> string, as you can filter events, and even have them have glob matches.

Oooh, I might run with this, it's been on my backlog to go investigate
and you just threw out a solution. Imagine being able to to specify
't' instead of 'p' for a given debug print so that dev_dbg() users can
move from console to trace buffer, but also tracing users have access
to more tracepoints that happen to appear at useful dev_dbg()
locations.

Thanks, Steven!

  reply	other threads:[~2021-04-21  6:28 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 22:18 [PATCH][RFC] tracing: Enable tracepoints via module parameters Steven Rostedt
2011-03-08 22:42 ` Steven Rostedt
2011-03-08 23:22 ` Mathieu Desnoyers
2011-03-08 23:32   ` Steven Rostedt
2011-03-09  0:07     ` Mathieu Desnoyers
2011-03-09  0:14       ` Steven Rostedt
2011-03-09  0:29         ` Mathieu Desnoyers
2011-03-09  0:52           ` Steven Rostedt
2011-03-09  1:17             ` Mathieu Desnoyers
2011-03-09  2:01               ` Steven Rostedt
2011-03-09  2:30                 ` Mathieu Desnoyers
2011-03-09  2:01             ` Yuanhan Liu
2011-03-09  2:12               ` Steven Rostedt
2011-03-09  2:19                 ` Yuanhan Liu
2011-03-10 23:33 ` Rusty Russell
2013-08-13 15:14   ` Steven Rostedt
2013-08-13 22:34     ` Mathieu Desnoyers
2013-08-13 23:09       ` Steven Rostedt
2013-08-15  2:02     ` Rusty Russell
2013-08-15  3:32       ` Steven Rostedt
2021-04-19 21:54         ` Williams, Dan J
2021-04-19 22:11           ` Steven Rostedt
2021-04-20  1:25             ` Dan Williams
2021-04-20 12:55               ` Steven Rostedt
2021-04-20 13:29                 ` Mathieu Desnoyers
2021-04-20 14:55                   ` Steven Rostedt
2021-04-20 15:15                     ` Mathieu Desnoyers
2021-04-20 15:34                       ` Steven Rostedt
2021-04-20 19:54                 ` Dan Williams
2021-04-20 20:32                   ` Steven Rostedt
2021-04-21  6:27                     ` Dan Williams [this message]
2021-04-21  7:30                     ` Rasmus Villemoes
2021-04-21 14:20                       ` Steven Rostedt
2021-04-21 14:50                         ` Rasmus Villemoes
2021-04-21 15:00                           ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPcyv4gS7iDrahX9i0PGMhR4k14XVkrCyGk3ZX8JEtO9RAQDhw@mail.gmail.com \
    --to=dan.j.williams@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=emmanuel.grumbach@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=jeyu@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).