Skip to contentSkip to conversation

rt-tests: printf format compile warning

PATCH Superseded Frank Rowand 2 participants 8 messages May 2, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 rt-tests: printf format compile warning

Fix printf format string to allow for 32 bit and 64 bit word size.

---
src/cyclictest/cyclictest.c | 3 2 + 1 - 0 !

 1 file changed, 2 insertions(+), 1 deletion(-)
src/cyclictest/cyclictest.c +2 -1
Index: b/src/cyclictest/cyclictest.c
===================================================================
@@ -24,6 +24,7 @@
 #include <time.h>
 #include <errno.h>
 #include <limits.h>
+#include <inttypes.h>
 #include <linux/unistd.h>
 
 #include <sys/prctl.h>
@@ -1575,7 +1576,7 @@ int main(int argc, char **argv)
 		print_tids(parameters, num_threads);
 		if (break_thread_id) {
 			printf("# Break thread: %d\n", break_thread_id);
-			printf("# Break value: %lu\n", break_thread_value);
+			printf("# Break value: %" PRIu64 "\n", break_thread_value);
 		}
 	}
 	
#1 lore raw

PATCH 2/4 rt-tests: cyclictest segfault with '-a'

This fixes a segfault on ARM when the '-a' option is used.

man sched_setaffinity says to use pthread_setaffinity_np() when using the POSIX threads API.

---
src/cyclictest/cyclictest.c | 4 3 + 1 - 0 !

 1 file changed, 3 insertions(+), 1 deletion(-)
src/cyclictest/cyclictest.c +3 -1
Index: b/src/cyclictest/cyclictest.c
===================================================================
@@ -612,6 +612,7 @@ void *timerthread(void *param)
 	struct thread_stat *stat = par->stats;
 	int stopped = 0;
 	cpu_set_t mask;
+	pthread_t thread;
 
 	/* if we're running in numa mode, set our memory node */
 	if (par->node != -1)
@@ -620,7 +621,8 @@ void *timerthread(void *param)
 	if (par->cpu != -1) {
 		CPU_ZERO(&mask);
 		CPU_SET(par->cpu, &mask);
-		if(sched_setaffinity(0, sizeof(mask), &mask) == -1)
+		thread = pthread_self();
+		if(pthread_setaffinity_np(thread, sizeof(mask), &mask) == -1)
 			warn("Could not set CPU affinity to CPU #%d\n", par->cpu);
 	}
 
#3 lore raw

PATCH 3/4 rt-tests: cyclictest avoid unneeded warning

In reply to Frank Rowand

Avoid annoying warning message when tracing is not requested and the debug file system is not available.

The same test already protects against calling event_enable_all().

---
src/cyclictest/cyclictest.c | 5 3 + 2 - 0 !

 1 file changed, 3 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +3 -2
Index: b/src/cyclictest/cyclictest.c
===================================================================
@@ -1605,8 +1605,9 @@ int main(int argc, char **argv)
 	if (trace_fd >= 0)
 		close(trace_fd);
 
-	/* turn off all events */
-	event_disable_all();
+	if (enable_events)
+		/* turn off all events */
+		event_disable_all();
 
 	/* turn off the function tracer */
 	fileprefix = procfileprefix;
#5 lore raw

PATCH 4/4 rt-tests: cyclictest warn of interaction between '-a', '--smp', and '--numa'

In reply to Frank Rowand

The '-a' option is always ignored if --smp or --numa is specified. Fix the warning message to not depend on --smp or --numa occuring first.

---
src/cyclictest/cyclictest.c | 14 11 + 3 - 0 !

 1 file changed, 11 insertions(+), 3 deletions(-)
src/cyclictest/cyclictest.c +11 -3
Index: b/src/cyclictest/cyclictest.c
===================================================================
@@ -949,6 +949,7 @@ static char *policyname(int policy)
 static void process_options (int argc, char *argv[])
 {
 	int error = 0;
+	int option_affinity = 0;
 	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
 	struct rlimit rlim;
 
@@ -1000,10 +1001,9 @@ static void process_options (int argc, c
 			break;
 		switch (c) {
 		case 'a':
-			if (smp) {
-				warn("-a ignored due to --smp\n");
+			option_affinity = 1;
+			if (smp || numa)
 				break;
-			}
 			if (optarg != NULL) {
 				affinity = atoi(optarg);
 				setaffinity = AFFINITY_SPECIFIED;
@@ -1112,6 +1112,14 @@ static void process_options (int argc, c
 		}
 	}
 
+	if (option_affinity) {
+		if (smp) {
+			warn("-a ignored due to --smp\n");
+		} else if (numa) {
+			warn("-a ignored due to --numa\n");
+		}
+	}
+
 	if (setaffinity == AFFINITY_SPECIFIED) {
 		if (affinity < 0)
 			error = 1;
Tested-by on v1 1/4
#7 lore raw
In reply to Frank Rowand
Quoted 4 lines · Frank Rowand

Fix printf format string to allow for 32 bit and 64 bit word size.

Tested cross-compilation for ARM, no warnings for this section.

Quoted 26 lines

---
src/cyclictest/cyclictest.c | 3 2 + 1 - 0 !

 1 file changed, 2 insertions(+), 1 deletion(-)

Index: b/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +2 -1
@@ -24,6 +24,7 @@
 #include <time.h>
 #include <errno.h>
 #include <limits.h>
+#include <inttypes.h>
 #include <linux/unistd.h>
 
 #include <sys/prctl.h>
@@ -1575,7 +1576,7 @@ int main(int argc, char **argv)
 		print_tids(parameters, num_threads);
 		if (break_thread_id) {
 			printf("# Break thread: %d\n", break_thread_id);
-			printf("# Break value: %lu\n", break_thread_value);
+			printf("# Break value: %" PRIu64 "\n", break_thread_value);
 		}
 	}
 
Signature · 3 lines
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
Tested-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] rt-tests: cyclictest segfault with '-a'

In reply to Frank Rowand
Quoted 6 lines · Frank Rowand

This fixes a segfault on ARM when the '-a' option is used.

man sched_setaffinity says to use pthread_setaffinity_np() when using the POSIX threads API.

Compile tested and tried "-a 0", but my ARM kernel/emulation is UP, so not sure this is of much value.

Quoted 27 lines

---
src/cyclictest/cyclictest.c | 4 3 + 1 - 0 !

 1 file changed, 3 insertions(+), 1 deletion(-)

Index: b/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +3 -1
@@ -612,6 +612,7 @@ void *timerthread(void *param)
 	struct thread_stat *stat = par->stats;
 	int stopped = 0;
 	cpu_set_t mask;
+	pthread_t thread;
 
 	/* if we're running in numa mode, set our memory node */
 	if (par->node != -1)
@@ -620,7 +621,8 @@ void *timerthread(void *param)
 	if (par->cpu != -1) {
 		CPU_ZERO(&mask);
 		CPU_SET(par->cpu, &mask);
-		if(sched_setaffinity(0, sizeof(mask), &mask) == -1)
+		thread = pthread_self();
+		if(pthread_setaffinity_np(thread, sizeof(mask), &mask) == -1)
 			warn("Could not set CPU affinity to CPU #%d\n", par->cpu);
 	}
 
Signature · 3 lines
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] rt-tests: cyclictest avoid unneeded warning

In reply to Frank Rowand
Quoted 6 lines · Frank Rowand

Avoid annoying warning message when tracing is not requested and the debug file system is not available.

The same test already protects against calling event_enable_all().

Cross-compile tested for ARM. Visually inspected, looks sane.

Quoted 21 lines

---
src/cyclictest/cyclictest.c | 5 3 + 2 - 0 !

 1 file changed, 3 insertions(+), 2 deletions(-)

Index: b/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +3 -2
@@ -1605,8 +1605,9 @@ int main(int argc, char **argv)
 	if (trace_fd >= 0)
 		close(trace_fd);
 
-	/* turn off all events */
-	event_disable_all();
+	if (enable_events)
+		/* turn off all events */
+		event_disable_all();
 
 	/* turn off the function tracer */
 	fileprefix = procfileprefix;
Signature · 3 lines
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
Tested-by on v1 4/4
#6 lore raw

Re: [PATCH 4/4] rt-tests: cyclictest warn of interaction between '-a', '--smp', and '--numa'

In reply to Frank Rowand
Quoted 4 lines · Frank Rowand

The '-a' option is always ignored if --smp or --numa is specified. Fix the warning message to not depend on --smp or --numa occuring first.

Compiled and tested on qemuarm UP. Behaved as expected with --smp --numa (not built-in) and -a alone.

Quoted 45 lines

---
src/cyclictest/cyclictest.c | 14 11 + 3 - 0 !

 1 file changed, 11 insertions(+), 3 deletions(-)

Index: b/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +11 -3
@@ -949,6 +949,7 @@ static char *policyname(int policy)
 static void process_options (int argc, char *argv[])
 {
 	int error = 0;
+	int option_affinity = 0;
 	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
 	struct rlimit rlim;
 
@@ -1000,10 +1001,9 @@ static void process_options (int argc, c
 			break;
 		switch (c) {
 		case 'a':
-			if (smp) {
-				warn("-a ignored due to --smp\n");
+			option_affinity = 1;
+			if (smp || numa)
 				break;
-			}
 			if (optarg != NULL) {
 				affinity = atoi(optarg);
 				setaffinity = AFFINITY_SPECIFIED;
@@ -1112,6 +1112,14 @@ static void process_options (int argc, c
 		}
 	}
 
+	if (option_affinity) {
+		if (smp) {
+			warn("-a ignored due to --smp\n");
+		} else if (numa) {
+			warn("-a ignored due to --numa\n");
+		}
+	}
+
 	if (setaffinity == AFFINITY_SPECIFIED) {
 		if (affinity < 0)
 			error = 1;
Signature · 3 lines
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel