From: Steven Rostedt <rostedt@goodmis.org>
To: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] trace-cmd: Reset CPU mask to its default value with "trace-cmd reset".
Date: Tue, 1 Oct 2019 11:45:12 -0400 [thread overview]
Message-ID: <20191001114512.37929af3@gandalf.local.home> (raw)
In-Reply-To: <CAPpZLN67T2bbcKiPczA93uW8rNSO5qg3MD+ETUDQLZmCN=iOJA@mail.gmail.com>
On Tue, 1 Oct 2019 18:37:54 +0300
Tzvetomir Stoyanov <tz.stoyanov@gmail.com> wrote:
> On Tue, Oct 1, 2019 at 6:32 PM Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > On Tue, 1 Oct 2019 17:57:40 +0300
> > "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
> >
> > > "trace-cmd reset" command should put all ftrace config to its default
> > > state, but trace cpumask was not reseted. The patch sets cpumask to
> > > its default value - all CPUs are enabled for tracing.
> > >
> > > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> > > ---
> > > tracecmd/trace-record.c | 35 +++++++++++++++++++++++++++++++++++
> > > 1 file changed, 35 insertions(+)
> > >
> > > diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
> > > index 69de82a..6f3520c 100644
> > > --- a/tracecmd/trace-record.c
> > > +++ b/tracecmd/trace-record.c
> > > @@ -4096,6 +4096,40 @@ static void reset_clock(void)
> > > write_instance_file(instance, "trace_clock", "local", "clock");
> > > }
> > >
> > > +static void reset_cpu_mask(void)
> > > +{
> > > + struct buffer_instance *instance;
> > > + int cpus = count_cpus();
> > > + int fullwords;
> > > + char *buf;
> > > + int bits;
> > > + int len;
> > > +
> > > + fullwords = cpus / 32;
> > > + bits = cpus % 32;
> > > + len = (fullwords + 1) * 9;
> > > +
> > > + buf = malloc(len + 1);
> > > + if (!buf) {
> > > + warning("Unable to allocate %d bytes for cpu mask", len + 1);
> > > + return;
> > > + }
> > > + buf[0] = '\0';
> > > + if (bits) {
> > > + sprintf(buf, "%x", (1 << bits) - 1);
> > > + } else if (fullwords) {
> > > + strcat(buf, "ffffffff");
> > > + fullwords--;
> > > + }
> > > + while (fullwords-- > 0)
> > > + strcat(buf, ",ffffffff");
> >
> > I like my way because it's a little more condensed ;-)
> >
> > But this works too and it's far from a fast path. As it's probably
> > more readable, I'll all this one.
> >
> > -- Steve
> >
> Actually the only change here is to handle the case when bits is 0,
> not to put the leading ",".
> The ftrace complains with "Invalid argument" in that case.
>
Mine handled that case too. The difference was the "cpus - 1" part of
my code:
fullwords = (cpus - 1) / 32; <--
bits = (cpus - 1) % 32 + 1; <--
len = (fullwords + 1) * 9;
buf = malloc(len + 1);
buf[0] = '\0';
if (bits)
sprintf(buf, "%x", (unsigned int)((1ULL << bits) - 1));
while (fullwords-- > 0)
strcat(buf, ",ffffffff");
The output of yours and mine were identical. When cpus was a power of
32, it would still have one less of "fullwords", and bits would be 32.
Which is why I needed to add "1ULL" to make:
(1 << 32) - 1 == 0xffffffff
the fullwords was only for non bits.
-- Steve
next prev parent reply other threads:[~2019-10-01 15:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 14:57 [PATCH v2 0/2] Reset CPU mask Tzvetomir Stoyanov (VMware)
2019-10-01 14:57 ` [PATCH v2 1/2] trace-cmd: Reset CPU mask after setting it in trace-cmd record with option -M Tzvetomir Stoyanov (VMware)
2019-10-01 14:57 ` [PATCH v2 2/2] trace-cmd: Reset CPU mask to its default value with "trace-cmd reset" Tzvetomir Stoyanov (VMware)
2019-10-01 15:32 ` Steven Rostedt
2019-10-01 15:37 ` Tzvetomir Stoyanov
2019-10-01 15:45 ` Steven Rostedt [this message]
2019-10-03 14:44 ` [PATCH v2 3/2] trace-cmd: Optimize the logic of reset_cpu_mask() 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=20191001114512.37929af3@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=tz.stoyanov@gmail.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).