[PATCH v2 3/2] trace-cmd: Optimize the logic of reset_cpu_mask()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux