[v2,3/2] trace-cmd: Optimize the logic of reset_cpu_mask()
diff mbox series

Message ID 20191003104453.51fbdadb@gandalf.local.home
State New
Headers show
Series
  • Reset CPU mask
Related show

Commit Message

Steven Rostedt Oct. 3, 2019, 2:44 p.m. UTC
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(-)

Patch
diff mbox series

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");