Hi Chen,
> I think we currently can only migrate those new created threads.
> However, to migrate the first thread of an application (I think it is
> called thread0 in Genode) I need to get its capability. Do you know
> how I can get thread0's capability with in the main function of my
> app?
I don't think that this approach is the right way to follow. Instead,
the policy should be imposed from outside the server by the server's
parent process similar to how CPU priorities are handled. When the
parent creates the CPU session for the child, it should pass the CPU
policy as session argument to core. This makes it easy to start multiple
instances of the same program with a different policy each.
Attached to this email, you find a patch that you may use as starting
point. Please note that this is just a hacky quick shot. It enables you
to specify the CPU number at the start node of a process in init's
config. In the patch, I have modified the 'start' node of the 'demo.run'
script where you can see how to use new the "cpu" argument. The CPU
number is passed to core and ends up in the Fiasco.OC-specific
constructor of 'Platform_thread'. I've put some 'PDBG' messages at the
interesting points.
Please note that the CPU argument is not passed to the kernel yet - the
patch solely shows how to pass the CPU number as CPU session argument
for immediate children of init into core. As it stands, the CPU policy
is not applied to further CPU sessions created by the respective child's
subsystem. Also, the patch is known to break all base platforms except
for 'base-foc'. Anyway, I hope it can serve you as starting point for
further experimentation.
Cheers
Norman
--
Dr.-Ing. Norman Feske
Genode Labs
http://www.genode-labs.com · http://genode.org
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
Index: base-foc/src/core/include/platform_thread.h
===================================================================
--- base-foc/src/core/include/platform_thread.h (revision 156)
+++ base-foc/src/core/include/platform_thread.h (working copy)
@@ -64,7 +64,7 @@
/**
* Constructor for non-core threads
*/
- Platform_thread(const char *name, unsigned priority);
+ Platform_thread(const char *name, unsigned priority, unsigned cpu);
/**
* Constructor for core main-thread
Index: base-foc/src/core/include/cpu_session_component.h
===================================================================
--- base-foc/src/core/include/cpu_session_component.h (revision 156)
+++ base-foc/src/core/include/cpu_session_component.h (working copy)
@@ -52,8 +52,8 @@
public:
- Cpu_thread_component(const char *name, unsigned priority)
- : _platform_thread(name, priority), _bound(false) { }
+ Cpu_thread_component(const char *name, unsigned priority, unsigned cpu)
+ : _platform_thread(name, priority, cpu), _bound(false) { }
/************************
@@ -86,6 +86,7 @@
unsigned _priority; /* priority of threads
created with this
session */
+ unsigned _default_cpu;
/**
* Lookup thread in CPU session by its capability
Index: base-foc/src/core/platform_thread.cc
===================================================================
--- base-foc/src/core/platform_thread.cc (revision 156)
+++ base-foc/src/core/platform_thread.cc (working copy)
@@ -194,7 +194,8 @@
Platform_thread::Platform_thread(const char *name,
- unsigned prio)
+ unsigned prio,
+ unsigned cpu)
: _core_thread(false),
_thread_cap(Capability_allocator::allocator()->alloc(),
Badge_allocator::allocator()->alloc()),
@@ -203,6 +204,8 @@
_platform_pd(0),
_pager(0)
{
+ PDBG("constructing new thread on CPU %d", cpu);
+
/* register the thread capability */
Capability_tree::tree()->insert(&_node);
Index: os/include/init/child.h
===================================================================
--- os/include/init/child.h (revision 156)
+++ os/include/init/child.h (working copy)
@@ -51,6 +51,15 @@
}
+ inline long read_cpu(Genode::Xml_node start_node)
+ {
+ long cpu = 0;
+ try { start_node.attribute("cpu").value(&cpu); }
+ catch (...) { }
+ return cpu;
+ }
+
+
inline Genode::size_t read_ram_quota(Genode::Xml_node start_node)
{
Genode::Number_of_bytes ram_quota = 0;
@@ -305,6 +314,7 @@
{
long prio_levels_log2;
long priority;
+ long default_cpu;
Genode::size_t ram_quota;
Genode::Ram_connection ram;
Genode::Cpu_connection cpu;
@@ -315,9 +325,12 @@
:
prio_levels_log2(prio_levels_log2),
priority(read_priority(start_node)),
+ default_cpu(read_cpu(start_node)),
ram_quota(read_ram_quota(start_node)),
ram(label),
- cpu(label, priority*(Genode::Cpu_session::PRIORITY_LIMIT >> prio_levels_log2))
+ cpu(label,
+ priority*(Genode::Cpu_session::PRIORITY_LIMIT >> prio_levels_log2),
+ default_cpu)
{
/* deduce session costs from usable ram quota */
enum { RM = 64*1024, CPU = 16*1024, RAM = 32*1024 };
Index: os/run/demo.run
===================================================================
--- os/run/demo.run (revision 156)
+++ os/run/demo.run (working copy)
@@ -74,7 +74,7 @@
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
- <start name="nitpicker">
+ <start name="nitpicker" cpu="13">
<resource name="RAM" quantum="1M"/>
<provides><service name="Nitpicker"/></provides>
</start>
Index: base/include/cpu_session/connection.h
===================================================================
--- base/include/cpu_session/connection.h (revision 156)
+++ base/include/cpu_session/connection.h (working copy)
@@ -30,13 +30,14 @@
* \param label initial session label
* \param priority designated priority of all threads created
* with this CPU session
+ * \param cpu CPU used to execute threads created via the CPU session
*/
- Cpu_connection(const char *label = "", long priority = DEFAULT_PRIORITY)
+ Cpu_connection(const char *label = "", long priority = DEFAULT_PRIORITY, long cpu = 0)
:
Connection<Cpu_session_capability>(
session(service_name(),
- "priority=0x%lx, ram_quota=32K, label=\"%s\"",
- priority, label)),
+ "priority=0x%lx, cpu=%ld, ram_quota=32K, label=\"%s\"",
+ priority, cpu, label)),
Cpu_session_client(cap()) { }
};
}
Index: base/src/core/cpu_session_component.cc
===================================================================
--- base/src/core/cpu_session_component.cc (revision 156)
+++ base/src/core/cpu_session_component.cc (working copy)
@@ -30,7 +30,7 @@
Cpu_thread_component *thread = 0;
try {
- thread = new(&_slab) Cpu_thread_component(name, _priority);
+ thread = new(&_slab) Cpu_thread_component(name, _priority, _default_cpu);
} catch (Allocator::Out_of_memory) {
throw Thread_creation_failed();
}
@@ -164,7 +164,7 @@
const char *args)
: _thread_ep(thread_ep), _pager_ep(pager_ep),
_md_alloc(md_alloc, Arg_string::find_arg(args, "ram_quota").long_value(0)),
- _slab(&_md_alloc), _priority(0)
+ _slab(&_md_alloc), _priority(0), _default_cpu(0)
{
Arg a = Arg_string::find_arg(args, "priority");
if (a.valid()) {
@@ -173,6 +173,12 @@
/* clamp priority value to valid range */
_priority = min((unsigned)PRIORITY_LIMIT - 1, _priority);
}
+
+ a = Arg_string::find_arg(args, "cpu");
+ if (a.valid())
+ _default_cpu = a.ulong_value(0);
+
+ PDBG("new CPU session uses CPU %d as default", _default_cpu);
}
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Genode-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/genode-main