From cc78fe7d819881897bbcf6b3a6d30ae71ff8eb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 17 Apr 2020 05:00:04 +0000 Subject: [PATCH] sched_getcpu: input and sample outputs --- README.adoc | 24 ++++++++++++++++++++++++ userland/linux/sched_getcpu.c | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 0e9cae0..20dffdd 100644 --- a/README.adoc +++ b/README.adoc @@ -17305,6 +17305,30 @@ So when running a multicore program, we may see that each thread can be running The cores in which the process runs can be fixed with `sched_setaffinity` as shown at: link:userland/linux/sched_getaffinity.c[]. +So when I run it with `main` thread + 4 threads on a 4 core CPUs: + +.... +./userland/linux/sched_getcpu.out 4 +.... + +I see random outputs like: + +.... +7 +2 +1 +5 +.... + +and: + +.... +5 +0 +2 +1 +.... + === Linux calling conventions A summary of results is shown at: xref:table-linux-calling-conventions[xrefstyle=full]. diff --git a/userland/linux/sched_getcpu.c b/userland/linux/sched_getcpu.c index 294a1b3..0d5cd1b 100644 --- a/userland/linux/sched_getcpu.c +++ b/userland/linux/sched_getcpu.c @@ -12,7 +12,7 @@ void* main_thread(void *arg) { (void)arg; - printf("sched_getcpu = %d\n", sched_getcpu()); + printf("%d\n", sched_getcpu()); return NULL; }