diff --git a/repos/os/include/suoritin/component.h b/repos/os/include/suoritin/component.h
index 91775a2c9c..2712c1bab2 100644
--- a/repos/os/include/suoritin/component.h
+++ b/repos/os/include/suoritin/component.h
@@ -13,7 +13,6 @@
*/
#pragma once
/* Genode includes */
-#include
#include
#include
#include
@@ -25,8 +24,6 @@
#include
#include
-
-
namespace Tukija {
namespace Suoritin {
class Session_component;
@@ -41,25 +38,28 @@ class Tukija::Suoritin::Allocator : public Genode::Allocator
using size_t = Genode::size_t;
private:
- Genode::Region_map::Local_addr _dataspace{};
size_t _interface_size;
- Genode::Region_map::Local_addr _pos {_dataspace};
+ T* _pos;
+ T* _interface;
-public:
- Allocator(Genode::Env &env, Genode::Ram_dataspace_capability *_interface_cap, size_t interface_size) : _interface_size(interface_size)
+ Allocator(const Tukija::Suoritin::Allocator &) {}
+ Allocator &operator=(const Allocator&) {}
+
+ public :
+
+ Allocator(T *interface, size_t interface_size) : _interface_size(interface_size), _pos(interface), _interface(interface)
{
- *_interface_cap = env.ram().alloc(interface_size);
- _dataspace = static_cast(env.rm().attach(*_interface_cap));
- }
+ }
Alloc_result try_alloc(size_t) override
{
- T *pos = _pos;
- if (pos >= static_cast(_dataspace) + _interface_size)
- return Alloc_result(Genode::Ram_allocator::Alloc_error::OUT_OF_RAM);
+ T *pos = _pos;
+ Genode::log("Trying to allocate one interface at ", pos);
+ if (pos >= static_cast(_interface) + _interface_size)
+ return Alloc_result(Genode::Ram_allocator::Alloc_error::OUT_OF_RAM);
- pos++;
- return Alloc_result(static_cast(pos));
+ _pos++;
+ return Alloc_result(static_cast(pos));
}
void free(void *, size_t) override
@@ -69,30 +69,33 @@ public:
bool need_size_for_free() const override { return false; }
- T *interface() { return _dataspace; }
+ T *interface() { return _interface; }
};
-class Tukija::Suoritin::Session_component : public Genode::Rpc_object
+class Tukija::Suoritin::Session_component : public Genode::Session_object
{
private:
Genode::Affinity _affinity;
Genode::Env &_env;
- Genode::Ram_dataspace_capability _workers_interface_cap{};
- Genode::Ram_dataspace_capability _channels_interface_cap{};
- Allocator> _worker_allocator;
- Allocator> _channel_allocator;
+ Genode::Attached_ram_dataspace _workers_if;
+ Genode::Attached_ram_dataspace _channels_if;
+ Genode::Attached_ram_dataspace _event_channel;
+
+ Allocator _worker_allocator;
+ Allocator _channel_allocator;
+
unsigned long no_channels{0};
unsigned long no_workers{0};
- template
- void construct(FUNC const &fn, Allocator> &alloc, Genode::Registry> ®istry) {
+ template
+ void construct(FUNC const &fn, Allocator &alloc, Args ...args) {
T* object = nullptr;
try {
try {
- object = new (alloc) Genode::Registered(registry);
+ object = new (alloc) T(args...);
fn(object);
} catch (Genode::Allocator::Out_of_memory) {
Genode::error("Out of RAM on registering worker.");
@@ -108,30 +111,40 @@ class Tukija::Suoritin::Session_component : public Genode::Rpc_object(),
- _affinity(affinity.space().total() ? affinity : Genode::Affinity(Genode::Affinity::Space(1,1), Genode::Affinity::Location(0,0,1,1))),
- _env(env), _worker_allocator(env, &_workers_interface_cap, _affinity.space().total()*sizeof(Genode::Registered)),
- _channel_allocator(env, &_channels_interface_cap, _affinity.space().total()*sizeof(Genode::Registered))
+ Session_component( Genode::Rpc_entrypoint &session_ep,
+ Resources const &resources,
+ Label const &label,
+ Diag const &diag,
+ Genode::Env &env,
+ Genode::Affinity &affinity)
+ :
+ Genode::Session_object(session_ep, resources, label, diag),
+ _affinity(affinity.space().total() ? affinity : Genode::Affinity(Genode::Affinity::Space(1,1), Genode::Affinity::Location(0,0,1,1))),
+ _env(env),
+ _workers_if(env.ram(), env.rm(), sizeof(Worker)*affinity.space().total()),
+ _channels_if(env.ram(), env.rm(), sizeof(Channel)*affinity.space().total()),
+ _event_channel(env.ram(), env.rm(), sizeof(Event_channel)),
+ _worker_allocator(_workers_if.local_addr(), _affinity.space().total()*sizeof(Worker)),
+ _channel_allocator(_channels_if.local_addr(), _affinity.space().total()*sizeof(Channel))
{
}
- void create_channel() override
+ void create_channel(Worker const &worker) override
{
try {
- construct([&](Channel *) {}, _channel_allocator, _channels);
+ construct([&](Channel *) {}, _channel_allocator, worker);
}
catch (...)
{
Genode::error("Faild to create channel");
}
+ no_channels++;
}
void register_worker(Genode::Thread::Name const &name, Genode::Thread_capability cap) override {
try {
- construct([&](Worker *worker)
- { worker->_cap = cap;
- worker->_name = name; }, _worker_allocator, _workers);
+ construct([&](Worker *w)
+ { w->_id = (w - workers_if()); },
+ _worker_allocator, cap, name);
}
catch (...)
{
@@ -139,9 +152,45 @@ class Tukija::Suoritin::Session_component : public Genode::Rpc_object();
+ }
+ inline Channel *channels_if() {
+ return _channels_if.local_addr();
+ }
+
+ inline Worker &worker(unsigned long id) {
+ return workers_if()[id];
+ }
+
+ void send_request(Genode::Parent::Resource_args &args)
+ {
+ Event_channel *evtchn = _event_channel.local_addr();
+ evtchn->parent_args = args;
+
+ evtchn->parent_flag = true;
+ }
+
+ unsigned long channels() { return no_channels; }
};
class Tukija::Suoritin::Root_component
@@ -152,15 +201,27 @@ class Tukija::Suoritin::Root_component
Genode::Env &_env;
public:
- Session_component *_create_session(const char *) override
+ Session_component *_create_session(const char *args) override
{
Genode::log("Creating new TASKING session");
- return new(md_alloc()) Genode::Registered(sessions, _env, Genode::Affinity(_env.cpu().affinity_space(), Genode::Affinity::Location(0,0,_env.cpu().affinity_space().width(), _env.cpu().affinity_space().height())));
+ return new(md_alloc()) Genode::Registered(sessions,
+ *this->ep(),
+ Genode::session_resources_from_args(args),
+ Genode::session_label_from_args(args),
+ Genode::session_diag_from_args(args),
+ _env,
+ Genode::Affinity(_env.cpu().affinity_space(), Genode::Affinity::Location(0,0,_env.cpu().affinity_space().width(), _env.cpu().affinity_space().height())));
+ }
+
+ /* Interal interface for Hoitaja */
+ template
+ void for_each(FN const &fn) {
+ sessions.for_each(fn);
}
Root_component(Genode::Env &env, Genode::Allocator &alloc)
: Genode::Root_component(env.ep(), alloc), _env(env)
{
- Genode::log("Started TASKING service");
+ Genode::log("Sta:ted TASKING service");
}
};
\ No newline at end of file