genode/repos/base-linux/src/core/include/core_env.h

199 lines
5.0 KiB
C
Raw Normal View History

/*
* \brief Core-specific environment for Linux
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*/
/*
* Copyright (C) 2006-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _CORE__INCLUDE__CORE_ENV_H_
#define _CORE__INCLUDE__CORE_ENV_H_
2017-05-08 17:09:44 +02:00
/* Genode includes */
#include <base/service.h>
/* core includes */
#include <platform.h>
#include <core_parent.h>
#include <core_pd_session.h>
#include <ram_session_component.h>
#include <core_pd_session.h>
/* base-internal includes */
#include <base/internal/platform_env.h>
namespace Genode { void init_stack_area(); }
namespace Genode {
/**
2017-05-08 17:09:44 +02:00
* Lock-guarded wrapper for a RAM session
*
2017-05-08 17:09:44 +02:00
* In contrast to regular components, core's RAM session is not
* synchronized via the RPC entrypoint.
*/
2017-05-08 17:09:44 +02:00
class Synced_ram_session : public Ram_session
{
private:
Lock mutable _lock;
2017-05-08 17:09:44 +02:00
Ram_session &_ram_session;
public:
2017-05-08 17:09:44 +02:00
Synced_ram_session(Ram_session &ram_session) : _ram_session(ram_session) { }
/***************************
** RAM-session interface **
***************************/
Ram_dataspace_capability alloc(size_t size, Cache_attribute cached) override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
return _ram_session.alloc(size, cached);
}
void free(Ram_dataspace_capability ds) override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
_ram_session.free(ds);
}
size_t dataspace_size(Ram_dataspace_capability ds) const override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
return _ram_session.dataspace_size(ds);
}
void ref_account(Ram_session_capability session) override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
_ram_session.ref_account(session);
}
void transfer_quota(Ram_session_capability session, Ram_quota amount) override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
_ram_session.transfer_quota(session, amount);
}
Ram_quota ram_quota() const override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
return _ram_session.ram_quota();
}
Ram_quota used_ram() const override
{
Lock::Guard lock_guard(_lock);
2017-05-08 17:09:44 +02:00
return _ram_session.used_ram();
}
};
class Core_env : public Platform_env_base
{
private:
2017-05-08 17:09:44 +02:00
enum { STACK_SIZE = 2048 * sizeof(Genode::addr_t) };
/*
* Initialize the stack area before creating the first thread,
* which happens to be the '_entrypoint'.
*/
bool _init_stack_area() { init_stack_area(); return true; }
bool _stack_area_initialized = _init_stack_area();
2017-05-08 17:09:44 +02:00
Rpc_entrypoint _entrypoint { nullptr, STACK_SIZE, "entrypoint" };
Ram_session_component _ram_session;
Synced_ram_session _synced_ram_session { _ram_session };
/*
* The core-local PD session is provided by a real RPC object
* dispatched by the same entrypoint as the signal-source RPC
* objects. This is needed to allow the 'Pd_session::submit'
* method to issue out-of-order replies to
* 'Signal_source::wait_for_signal' calls.
*/
Capability quota accounting and trading This patch mirrors the accounting and trading scheme that Genode employs for physical memory to the accounting of capability allocations. Capability quotas must now be explicitly assigned to subsystems by specifying a 'caps=<amount>' attribute to init's start nodes. Analogously to RAM quotas, cap quotas can be traded between clients and servers as part of the session protocol. The capability budget of each component is maintained by the component's corresponding PD session at core. At the current stage, the accounting is applied to RPC capabilities, signal-context capabilities, and dataspace capabilities. Capabilities that are dynamically allocated via core's CPU and TRACE service are not yet covered. Also, the capabilities allocated by resource multiplexers outside of core (like nitpicker) must be accounted by the respective servers, which is not covered yet. If a component runs out of capabilities, core's PD service prints a warning to the log. To observe the consumption of capabilities per component in detail, the PD service is equipped with a diagnostic mode, which can be enabled via the 'diag' attribute in the target node of init's routing rules. E.g., the following route enables the diagnostic mode for the PD session of the "timer" component: <default-route> <service name="PD" unscoped_label="timer"> <parent diag="yes"/> </service> ... </default-route> For subsystems based on a sub-init instance, init can be configured to report the capability-quota information of its subsystems by adding the attribute 'child_caps="yes"' to init's '<report>' config node. Init's own capability quota can be reported by adding the attribute 'init_caps="yes"'. Fixes #2398
2017-05-08 21:35:43 +02:00
Core_pd_session_component _pd_session_component { _entrypoint };
Pd_session_client _pd_session_client { _pd_session_component.cap() };
Registry<Service> _services;
2017-05-08 17:09:44 +02:00
Heap _heap { _synced_ram_session, *Platform_env_base::rm_session() };
Core_parent _core_parent { _heap, _services };
typedef String<100> Ram_args;
static Session::Resources _ram_resources()
{
return { Ram_quota { platform()->ram_alloc()->avail() },
Cap_quota { 1000 } };
}
public:
/**
* Constructor
*/
Core_env()
:
Platform_env_base(Ram_session_capability(),
Cpu_session_capability(),
Pd_session_capability()),
_ram_session(_entrypoint,
_ram_resources(),
Session::Label("core"),
Session::Diag{false},
*platform()->ram_alloc(),
*Platform_env_base::rm_session(),
Capability quota accounting and trading This patch mirrors the accounting and trading scheme that Genode employs for physical memory to the accounting of capability allocations. Capability quotas must now be explicitly assigned to subsystems by specifying a 'caps=<amount>' attribute to init's start nodes. Analogously to RAM quotas, cap quotas can be traded between clients and servers as part of the session protocol. The capability budget of each component is maintained by the component's corresponding PD session at core. At the current stage, the accounting is applied to RPC capabilities, signal-context capabilities, and dataspace capabilities. Capabilities that are dynamically allocated via core's CPU and TRACE service are not yet covered. Also, the capabilities allocated by resource multiplexers outside of core (like nitpicker) must be accounted by the respective servers, which is not covered yet. If a component runs out of capabilities, core's PD service prints a warning to the log. To observe the consumption of capabilities per component in detail, the PD service is equipped with a diagnostic mode, which can be enabled via the 'diag' attribute in the target node of init's routing rules. E.g., the following route enables the diagnostic mode for the PD session of the "timer" component: <default-route> <service name="PD" unscoped_label="timer"> <parent diag="yes"/> </service> ... </default-route> For subsystems based on a sub-init instance, init can be configured to report the capability-quota information of its subsystems by adding the attribute 'child_caps="yes"' to init's '<report>' config node. Init's own capability quota can be reported by adding the attribute 'init_caps="yes"'. Fixes #2398
2017-05-08 21:35:43 +02:00
Ram_session_component::any_phys_range())
{
_ram_session.init_ram_account();
}
/**
* Destructor
*/
~Core_env() { parent()->exit(0); }
2017-05-08 17:09:44 +02:00
Rpc_entrypoint *entrypoint() { return &_entrypoint; }
/******************************
** Env_deprecated interface **
******************************/
Parent *parent() override { return &_core_parent; }
Ram_session *ram_session() override { return &_ram_session; }
2017-05-08 17:09:44 +02:00
Ram_session_capability ram_session_cap() override { return _ram_session.cap(); }
Pd_session *pd_session() override { return &_pd_session_client; }
2017-05-08 17:09:44 +02:00
Allocator *heap() override { log(__func__, ": not implemented"); return nullptr; }
Cpu_session_capability cpu_session_cap() override
{
warning(__FILE__, ":", __LINE__, " not implemented");
return Cpu_session_capability();
}
Registry<Service> &services() { return _services; }
};
/**
* Request pointer to static environment of Core
*/
extern Core_env *core_env();
}
#endif /* _CORE__INCLUDE__CORE_ENV_H_ */