mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-22 08:50:09 +00:00
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
This commit is contained in:
committed by
Christian Helmuth
parent
773e08976d
commit
1f4f119b1e
@ -45,6 +45,7 @@ class Loader::Child : public Child_policy
|
||||
Session_label const _label;
|
||||
Name const _binary_name;
|
||||
|
||||
Cap_quota const _cap_quota;
|
||||
Ram_quota const _ram_quota;
|
||||
|
||||
Parent_services &_parent_services;
|
||||
@ -62,6 +63,7 @@ class Loader::Child : public Child_policy
|
||||
Allocator &alloc,
|
||||
Name const &binary_name,
|
||||
Session_label const &label,
|
||||
Cap_quota cap_quota,
|
||||
Ram_quota ram_quota,
|
||||
Parent_services &parent_services,
|
||||
Service &local_rom_service,
|
||||
@ -74,6 +76,7 @@ class Loader::Child : public Child_policy
|
||||
_alloc(alloc),
|
||||
_label(label),
|
||||
_binary_name(binary_name),
|
||||
_cap_quota(Genode::Child::effective_quota(cap_quota)),
|
||||
_ram_quota(Genode::Child::effective_quota(ram_quota)),
|
||||
_parent_services(parent_services),
|
||||
_local_nitpicker_service(local_nitpicker_service),
|
||||
@ -94,9 +97,18 @@ class Loader::Child : public Child_policy
|
||||
|
||||
Binary_name binary_name() const override { return _binary_name; }
|
||||
|
||||
Pd_session &ref_pd() override { return _env.pd(); }
|
||||
Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
||||
|
||||
Ram_session &ref_ram() override { return _env.ram(); }
|
||||
Ram_session_capability ref_ram_cap() const override { return _env.ram_session_cap(); }
|
||||
|
||||
void init(Pd_session &pd, Pd_session_capability pd_cap) override
|
||||
{
|
||||
pd.ref_account(ref_pd_cap());
|
||||
ref_pd().transfer_quota(pd_cap, _cap_quota);
|
||||
}
|
||||
|
||||
void init(Ram_session &ram, Ram_session_capability ram_cap) override
|
||||
{
|
||||
ram.ref_account(ref_ram_cap());
|
||||
|
@ -14,7 +14,6 @@
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/heap.h>
|
||||
#include <base/rpc_server.h>
|
||||
#include <base/sleep.h>
|
||||
#include <loader_session/loader_session.h>
|
||||
#include <root/component.h>
|
||||
@ -204,9 +203,11 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
Env &_env;
|
||||
Session_label const _label;
|
||||
Xml_node const _config;
|
||||
Cap_quota const _cap_quota;
|
||||
Ram_quota const _ram_quota;
|
||||
Ram_session_client_guard _local_ram { _env.ram_session_cap(), _ram_quota };
|
||||
Heap _md_alloc { _local_ram, _env.rm() };
|
||||
size_t _subsystem_cap_quota_limit = 0;
|
||||
size_t _subsystem_ram_quota_limit = 0;
|
||||
Parent_services _parent_services;
|
||||
Rom_module_registry _rom_modules { _env, _config, _local_ram, _md_alloc };
|
||||
@ -243,10 +244,11 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Session_component(Env &env, Session_label const &label,
|
||||
Xml_node config, Ram_quota quota)
|
||||
Session_component(Env &env, Session_label const &label, Xml_node config,
|
||||
Cap_quota cap_quota, Ram_quota ram_quota)
|
||||
:
|
||||
_env(env), _label(label), _config(config), _ram_quota(quota)
|
||||
_env(env), _label(label), _config(config),
|
||||
_cap_quota(cap_quota), _ram_quota(ram_quota)
|
||||
{
|
||||
/* fetch all parent-provided ROMs according to the config */
|
||||
config.for_each_sub_node("parent-rom", [&] (Xml_node rom)
|
||||
@ -287,6 +289,11 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
throw Rom_module_does_not_exist(); }
|
||||
}
|
||||
|
||||
void cap_quota(Cap_quota caps) override
|
||||
{
|
||||
_subsystem_cap_quota_limit = caps.value;
|
||||
}
|
||||
|
||||
void ram_quota(Ram_quota quantum) override
|
||||
{
|
||||
_subsystem_ram_quota_limit = quantum.value;
|
||||
@ -334,6 +341,10 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
return;
|
||||
}
|
||||
|
||||
size_t const cap_quota = (_subsystem_cap_quota_limit > 0)
|
||||
? min(_subsystem_cap_quota_limit, _cap_quota.value)
|
||||
: _cap_quota.value;
|
||||
|
||||
size_t const ram_quota = (_subsystem_ram_quota_limit > 0)
|
||||
? min(_subsystem_ram_quota_limit, _ram_quota.value)
|
||||
: _ram_quota.value;
|
||||
@ -341,7 +352,7 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
try {
|
||||
_child.construct(_env, _md_alloc, binary_name.string(),
|
||||
prefixed_label(_label, Session_label(label.string())),
|
||||
Ram_quota{ram_quota},
|
||||
Cap_quota{cap_quota}, Ram_quota{ram_quota},
|
||||
_parent_services, _rom_service,
|
||||
_cpu_service, _pd_service, _nitpicker_service,
|
||||
_fault_sigh);
|
||||
@ -381,6 +392,7 @@ class Loader::Root : public Root_component<Session_component>
|
||||
catch (...) { }
|
||||
|
||||
return new (md_alloc()) Session_component(_env, label, session_config,
|
||||
cap_quota_from_args(args),
|
||||
ram_quota_from_args(args));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user