Skip to contentSkip to conversation

Fix a few fallouts

PATCH New Daniel Wagner 1 participant 4 messages Jul 4, 2021

lore
Share & tools
lore
#0 lore raw

cover Fix a few fallouts

From: Daniel Wagner <[email protected]>

Another round of small cleanups and fixes.

The first one fixes static builds for armhf host. Patch two is another of the printf format specifier which I got wrong. No idea why we didn't see this earlier. Anyway gcc on armhf was not happy. The same for the third fix. Why the gcc on armhf complains and not on anything else, is dubios to me.

Daniel Wagner (3):
rt-numa: Use sched_getaffinity() instead of pthread_getaffinity_np()
signaltest: Fix printf format specifier
cyclicdeadline: Fix buffer allocation

 src/lib/rt-numa.c                   | 4 +---
 src/sched_deadline/cyclicdeadline.c | 2 +-
 src/signaltest/signaltest.c         | 6 +++---
 3 files changed, 5 insertions(+), 7 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/3 rt-numa: Use sched_getaffinity() instead of pthread_getaffinity_np()

From: Daniel Wagner <[email protected]>

pthread_getaffinity_np() prevents static builds as glibc does not expose it for this configuration. Instead use sched_getaffinity() which is always present and has the exact same semantics.

Fixes f240656b056b ("rt-tests: cyclictest: Fix -t without a user specified [NUM]")
---
 src/lib/rt-numa.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
src/lib/rt-numa.c +1 -3
index babcc634d57e..2d34ae36cc03 100644
@@ -68,13 +68,11 @@ int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
 int cpu_for_thread_ua(int thread_num, int max_cpus)
 {
 	int res, num_cpus, i, m, cpu;
-	pthread_t thread;
 	cpu_set_t cpuset;
 
-	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 
-	res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+	res = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
 	if (res != 0)
 		fatal("pthread_getaffinity_np failed: %s\n", strerror(res));
 
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/3 signaltest: Fix printf format specifier

In reply to Daniel Wagner

From: Daniel Wagner <[email protected]>

The fields are not uint64 just longs, update the printf format specifiers.

---
 src/signaltest/signaltest.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/signaltest/signaltest.c +3 -3
index 6e8f6b51b003..4d89a1aba9d9 100644
@@ -393,9 +393,9 @@ static void write_stats(FILE *f, void *data)
 	for (i = 0; i < num_threads; i++) {
 		fprintf(f, "    \"%u\": {\n", i);
 		s = &par->stats[i];
-		fprintf(f, "      \"cycles\": %" PRIu64 ",\n", s->cycles);
-		fprintf(f, "      \"min\": %" PRIu64 ",\n", s->min);
-		fprintf(f, "      \"max\": %" PRIu64 ",\n", s->max);
+		fprintf(f, "      \"cycles\": %ld,\n", s->cycles);
+		fprintf(f, "      \"min\": %ld,\n", s->min);
+		fprintf(f, "      \"max\": %ld,\n", s->max);
 		fprintf(f, "      \"avg\": %.2f,\n", s->avg/s->cycles);
 		fprintf(f, "      \"cpu\": %d\n", par->cpu);
 		fprintf(f, "    }%s\n", i == num_threads - 1 ? "" : ",");
Signature · 1 line
2.32.0
#3 lore raw

PATCH 3/3 cyclicdeadline: Fix buffer allocation

In reply to Daniel Wagner

From: Daniel Wagner <[email protected]>

gcc complains with "‘sprintf’ output between 2 and 12 bytes" but the buffer is only 10 bytes long. Update the buffer size to hold the complete range of [-2147483648, 2147483646].

---
 src/sched_deadline/cyclicdeadline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/sched_deadline/cyclicdeadline.c +1 -1
index ffefa9e6fecb..8447424273ee 100644
@@ -1092,7 +1092,7 @@ int main(int argc, char **argv)
 
 	/* Default cpu to use is the last one */
 	if (!all_cpus && !setcpu) {
-		setcpu_buf = malloc(10);
+		setcpu_buf = malloc(12);
 		if (!setcpu_buf)
 			fatal("malloc");
 		sprintf(setcpu_buf, "%d", cpu_count - 1);
Signature · 1 line
2.32.0