From 240dc1884ef834773efe0106b93281992a4f9d6c Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Wed, 27 Mar 2019 12:35:51 +0100 Subject: [PATCH] Add affinity --- run/threads.run | 16 +++++++++++---- src/app/threads/main.cc | 43 ++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/run/threads.run b/run/threads.run index c50e5da..a1f369b 100644 --- a/run/threads.run +++ b/run/threads.run @@ -1,4 +1,4 @@ -build { core init app/threads } +build { core init drivers/timer app/threads } create_boot_directory @@ -10,17 +10,25 @@ install_config { + + + + + } -build_boot_image { core ld.lib.so init threads } +build_boot_image { core init timer threads } -append qemu_args " -nographic -smp 4 " +append qemu_args " -nographic -smp 4,cores=4 " -run_genode_until forever \ No newline at end of file +source ${genode_dir}/repos/genode-Profiler/run/profiler.inc +set show_plot true + +run_genode_until "done123" 30 \ No newline at end of file diff --git a/src/app/threads/main.cc b/src/app/threads/main.cc index 0e0940b..43ea9cd 100644 --- a/src/app/threads/main.cc +++ b/src/app/threads/main.cc @@ -1,6 +1,8 @@ #include #include +#include + Genode::size_t Component::stack_size() { return 32 * 1024; } namespace Threads { @@ -9,15 +11,31 @@ namespace Threads { } struct Threads::MyThread : Genode::Thread { + Timer::Connection &_timer; + Genode::String<64> _name; + void entry() { - for(int i = 0; i<10000; i++) { - Genode::log("i=", i); + { + PROFILE_SCOPE(_name.string(), "yellow", _timer) + for(int i = 0; i<500000000; i++) { + __asm__("NOP"); + //Genode::log("i=", i); + } } }; - MyThread(Genode::Env &env, Genode::String<64> name) : Genode::Thread(env, - Name(name), - 4 * 1024) + MyThread(Genode::Env &env, + Genode::String<64> name, + Timer::Connection &timer, + int pos) : Genode::Thread(env, + Genode::Cpu_session::Name(name.string()), + 4 * 1024, + Genode::Affinity::Location(pos, 0), + Genode::Cpu_session::Weight(1), + env.cpu() + ), + _timer(timer), + _name(name) { start(); }; @@ -27,11 +45,22 @@ struct Threads::MyThread : Genode::Thread { struct Threads::Main { Genode::Env &_env; + Timer::Connection timer { _env }; + Main(Genode::Env &env) : _env(env) { Genode::log("Hello World from Threads::Main!"); - static Threads::MyThread t1(_env, Genode::String<64>("thread_1")); - static Threads::MyThread t2(_env, Genode::String<64>("thread_2")); + static Threads::MyThread t1(_env, Genode::String<64>("thread_1"), timer, 0); + static Threads::MyThread t2(_env, Genode::String<64>("thread_2"), timer, 1); + static Threads::MyThread t3(_env, Genode::String<64>("thread_3"), timer, 2); + static Threads::MyThread t4(_env, Genode::String<64>("thread_4"), timer, 3); + + t1.join(); + t2.join(); + t3.join(); + t4.join(); + + Genode::log("done123"); } };