mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-29 13:44:26 +00:00
Simple thread-affinity test
This commit is contained in:
parent
297538678e
commit
e38983a8fa
25
base/run/affinity.run
Normal file
25
base/run/affinity.run
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
build "core init test/affinity"
|
||||||
|
|
||||||
|
create_boot_directory
|
||||||
|
|
||||||
|
install_config {
|
||||||
|
<config>
|
||||||
|
<parent-provides>
|
||||||
|
<service name="LOG"/>
|
||||||
|
<service name="CPU"/>
|
||||||
|
<service name="RM"/>
|
||||||
|
</parent-provides>
|
||||||
|
<default-route>
|
||||||
|
<any-service> <parent/> </any-service>
|
||||||
|
</default-route>
|
||||||
|
<start name="test-affinity">
|
||||||
|
<resource name="RAM" quantum="10M"/>
|
||||||
|
</start>
|
||||||
|
</config>
|
||||||
|
}
|
||||||
|
|
||||||
|
build_boot_image "core init test-affinity"
|
||||||
|
|
||||||
|
append qemu_args " -nographic -m 64 -smp 2,cores=2 "
|
||||||
|
|
||||||
|
run_genode_until forever
|
74
base/src/test/affinity/main.cc
Normal file
74
base/src/test/affinity/main.cc
Normal file
@ -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 <base/printf.h>
|
||||||
|
#include <base/thread.h>
|
||||||
|
#include <base/env.h>
|
||||||
|
#include <base/sleep.h>
|
||||||
|
|
||||||
|
|
||||||
|
enum { STACK_SIZE = sizeof(long)*1024 };
|
||||||
|
struct Spinning_thread : Genode::Thread<STACK_SIZE>
|
||||||
|
{
|
||||||
|
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<STACK_SIZE>(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();
|
||||||
|
}
|
3
base/src/test/affinity/target.mk
Normal file
3
base/src/test/affinity/target.mk
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
TARGET = test-affinity
|
||||||
|
SRC_CC = main.cc
|
||||||
|
LIBS = base
|
Loading…
x
Reference in New Issue
Block a user