linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 3/2] trace-cmd: Optimize the logic of reset_cpu_mask()
Date: Thu, 3 Oct 2019 10:44:53 -0400	[thread overview]
Message-ID: <20191003104453.51fbdadb@gandalf.local.home> (raw)
In-Reply-To: <20191001145740.8866-1-tz.stoyanov@gmail.com>


From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Change the logic of reset_cpu_mask() to be a little more condensed, and also
move the buffer onto the stack and eliminate the warning message as we no
longer need to use malloc.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 6f3520cc..cfe67f90 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4100,27 +4100,14 @@ static void reset_cpu_mask(void)
 {
 	struct buffer_instance *instance;
 	int cpus = count_cpus();
-	int fullwords;
-	char *buf;
-	int bits;
-	int len;
+	int fullwords = (cpus - 1) / 32;
+	int bits = (cpus - 1) % 32 + 1;
+	int len = (fullwords + 1) * 9;
+	char buf[len + 1];
 
-	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--;
-	}
+
+	sprintf(buf, "%x", (unsigned int)((1ULL << bits) - 1));
 	while (fullwords-- > 0)
 		strcat(buf, ",ffffffff");
 
-- 
2.20.1


      parent reply	other threads:[~2019-10-03 14:44 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
2019-10-03 14:44 ` Steven Rostedt [this message]

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=20191003104453.51fbdadb@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).