diff --git a/base/run/affinity.run b/base/run/affinity.run new file mode 100644 index 0000000000..9aef1af8e2 --- /dev/null +++ b/base/run/affinity.run @@ -0,0 +1,25 @@ +build "core init test/affinity" + +create_boot_directory + +install_config { + + + + + + + + + + + + + +} + +build_boot_image "core init test-affinity" + +append qemu_args " -nographic -m 64 -smp 2,cores=2 " + +run_genode_until forever diff --git a/base/src/test/affinity/main.cc b/base/src/test/affinity/main.cc new file mode 100644 index 0000000000..d5bbc59b25 --- /dev/null +++ b/base/src/test/affinity/main.cc @@ -0,0 +1,74 @@ +/* + * \brief Test for setting the CPU affinity of a thread + * \author Norman Feske + * \date 2013-03-21 + */ + +/* + * Copyright (C) 2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include +#include +#include +#include + + +enum { STACK_SIZE = sizeof(long)*1024 }; +struct Spinning_thread : Genode::Thread +{ + int const cpu_number; + + unsigned long volatile cnt; + + Genode::Lock barrier; + + void entry() + { + PINF("thread started on CPU %d, spinning...", cpu_number); + + barrier.unlock(); + + for (;;) { + cnt++; + + /* show a life sign every now and then... */ + if (cnt > 100*1024*1024) { + PINF("thread on CPU %d keeps counting...\n", cpu_number); + cnt = 0; + } + } + } + + Spinning_thread(unsigned cpu_number, char const *name) + : + Genode::Thread(name), cpu_number(cpu_number), cnt(0), + barrier(Genode::Lock::LOCKED) + { + Genode::env()->cpu_session()->affinity(Thread_base::cap(), cpu_number); + start(); + } +}; + + +int main(int argc, char **argv) +{ + using namespace Genode; + + printf("--- test-affinity started ---\n"); + static Spinning_thread thread_0(0, "thread_0"); + static Spinning_thread thread_1(1, "thread_1"); + + /* wait until both threads are up and running */ + thread_0.barrier.lock(); + thread_1.barrier.lock(); + + printf("Threads started on a different CPU each.\n"); + printf("You may inspect them using the kernel debugger\n"); + + sleep_forever(); +} diff --git a/base/src/test/affinity/target.mk b/base/src/test/affinity/target.mk new file mode 100644 index 0000000000..a2aa2db2c9 --- /dev/null +++ b/base/src/test/affinity/target.mk @@ -0,0 +1,3 @@ +TARGET = test-affinity +SRC_CC = main.cc +LIBS = base