2012-05-30 20:13:09 +02:00
|
|
|
/*
|
|
|
|
* \brief Implementations of the signaling framework specific for HW-core
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2012-05-05
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2012-05-30 20:13:09 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
2016-01-14 13:22:00 +01:00
|
|
|
#include <util/retry.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/signal.h>
|
2016-01-14 13:22:00 +01:00
|
|
|
#include <base/env.h>
|
|
|
|
#include <base/trace/events.h>
|
2013-11-14 17:29:34 +01:00
|
|
|
|
2016-03-08 16:59:43 +01:00
|
|
|
/* base-internal includes */
|
2017-02-24 14:29:29 +01:00
|
|
|
#include <base/internal/native_thread.h>
|
|
|
|
#include <base/internal/lock_helper.h>
|
2016-03-08 16:59:43 +01:00
|
|
|
#include <base/internal/native_utcb.h>
|
2016-11-06 14:26:34 +01:00
|
|
|
#include <base/internal/native_env.h>
|
2016-06-15 15:04:54 +02:00
|
|
|
#include <base/internal/capability_space.h>
|
2016-11-06 14:26:34 +01:00
|
|
|
#include <base/internal/globals.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2017-05-10 20:11:38 +02:00
|
|
|
static Pd_session *_pd_ptr;
|
|
|
|
static Pd_session &pd()
|
|
|
|
{
|
|
|
|
if (_pd_ptr)
|
|
|
|
return *_pd_ptr;
|
2015-12-23 15:22:33 +01:00
|
|
|
|
2017-05-10 20:11:38 +02:00
|
|
|
class Missing_init_signal_thread { };
|
|
|
|
throw Missing_init_signal_thread();
|
2015-12-23 15:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-10 20:11:38 +02:00
|
|
|
/*
|
|
|
|
* On base-hw, we don't use a signal thread. We mereely save the PD session
|
|
|
|
* pointer of the passed 'env' argument.
|
|
|
|
*/
|
|
|
|
void Genode::init_signal_thread(Env &env) { _pd_ptr = &env.pd(); }
|
|
|
|
void Genode::destroy_signal_thread() { }
|
2015-06-22 14:04:28 +02:00
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2012-11-23 16:47:42 +01:00
|
|
|
Signal_receiver::Signal_receiver()
|
2012-05-30 20:13:09 +02: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
2017-05-08 21:35:43 +02:00
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
Ram_quota ram_upgrade { 0 };
|
|
|
|
Cap_quota cap_upgrade { 0 };
|
|
|
|
|
|
|
|
try {
|
2017-05-10 20:11:38 +02:00
|
|
|
_cap = pd().alloc_signal_source();
|
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
|
|
|
break;
|
2012-11-23 16:47:42 +01: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
2017-05-08 21:35:43 +02:00
|
|
|
catch (Out_of_ram) { ram_upgrade = Ram_quota { 2*1024*sizeof(long) }; }
|
|
|
|
catch (Out_of_caps) { cap_upgrade = Cap_quota { 4 }; }
|
|
|
|
|
|
|
|
internal_env().upgrade(Parent::Env::pd(),
|
|
|
|
String<100>("ram_quota=", ram_upgrade, ", "
|
|
|
|
"cap_quota=", cap_upgrade).string());
|
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-12 00:48:27 +02:00
|
|
|
void Signal_receiver::_platform_destructor()
|
|
|
|
{
|
|
|
|
/* release server resources of receiver */
|
2017-05-10 20:11:38 +02:00
|
|
|
pd().free_signal_source(_cap);
|
2013-09-12 00:48:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-13 15:49:11 +01:00
|
|
|
void Signal_receiver::_platform_begin_dissolve(Signal_context * const c)
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2018-11-29 15:49:24 +01:00
|
|
|
/**
|
|
|
|
* Mark the Signal_context as already pending to prevent the receiver
|
|
|
|
* from taking the lock, and set an invalid context to prevent further
|
|
|
|
* processing
|
|
|
|
*/
|
2019-01-29 15:26:17 +01:00
|
|
|
{
|
|
|
|
Lock::Guard context_guard(c->_lock);
|
|
|
|
c->_pending = true;
|
|
|
|
c->_curr_signal = Signal::Data(nullptr, 0);
|
|
|
|
}
|
2016-06-15 15:04:54 +02:00
|
|
|
Kernel::kill_signal_context(Capability_space::capid(c->_cap));
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
2015-11-13 15:49:11 +01:00
|
|
|
void Signal_receiver::_platform_finish_dissolve(Signal_context *) { }
|
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
Signal_context_capability Signal_receiver::manage(Signal_context * const c)
|
|
|
|
{
|
2013-11-14 13:29:47 +01:00
|
|
|
/* ensure that the context isn't managed already */
|
2012-05-30 20:13:09 +02:00
|
|
|
Lock::Guard contexts_guard(_contexts_lock);
|
|
|
|
Lock::Guard context_guard(c->_lock);
|
2013-09-12 00:48:27 +02:00
|
|
|
if (c->_receiver) { throw Context_already_in_use(); }
|
2012-05-30 20:13:09 +02: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
2017-05-08 21:35:43 +02:00
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
Ram_quota ram_upgrade { 0 };
|
|
|
|
Cap_quota cap_upgrade { 0 };
|
|
|
|
|
|
|
|
try {
|
2016-01-14 13:22:00 +01:00
|
|
|
/* use signal context as imprint */
|
2017-05-10 20:11:38 +02:00
|
|
|
c->_cap = pd().alloc_context(_cap, (unsigned long)c);
|
2013-08-08 20:18:41 +02:00
|
|
|
c->_receiver = this;
|
2017-11-07 14:04:46 +01:00
|
|
|
_contexts.insert_as_tail(c);
|
2013-08-08 20:18:41 +02:00
|
|
|
return c->_cap;
|
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
|
|
|
}
|
|
|
|
catch (Out_of_ram) { ram_upgrade = Ram_quota { 1024*sizeof(long) }; }
|
|
|
|
catch (Out_of_caps) { cap_upgrade = Cap_quota { 4 }; }
|
2016-01-14 13:22:00 +01:00
|
|
|
|
2017-06-13 14:54:08 +02:00
|
|
|
internal_env().upgrade(Parent::Env::pd(),
|
|
|
|
String<100>("ram_quota=", ram_upgrade, ", "
|
|
|
|
"cap_quota=", cap_upgrade).string());
|
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
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-08 17:45:12 +02:00
|
|
|
void Signal_receiver::block_for_signal()
|
|
|
|
{
|
2015-11-13 15:49:11 +01:00
|
|
|
/* wait for a signal */
|
2016-06-15 15:04:54 +02:00
|
|
|
if (Kernel::await_signal(Capability_space::capid(_cap))) {
|
2017-02-14 17:00:53 +01:00
|
|
|
/* canceled */
|
2015-10-08 17:45:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-03-11 11:42:36 +01:00
|
|
|
|
2015-11-13 15:49:11 +01:00
|
|
|
/* read signal data */
|
2019-03-11 11:42:36 +01:00
|
|
|
Signal::Data * const data =
|
|
|
|
(Signal::Data *)Thread::myself()->utcb()->data();
|
2015-11-13 15:49:11 +01:00
|
|
|
Signal_context * const context = data->context;
|
2018-11-29 15:49:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for the signal being pending already to prevent a dead-lock
|
|
|
|
* when the context is in destruction, and its lock is held
|
|
|
|
*/
|
|
|
|
if (!context->_pending) {
|
2015-11-13 15:49:11 +01:00
|
|
|
/* update signal context */
|
|
|
|
Lock::Guard lock_guard(context->_lock);
|
|
|
|
unsigned const num = context->_curr_signal.num + data->num;
|
|
|
|
context->_pending = true;
|
|
|
|
context->_curr_signal = Signal::Data(context, num);
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
2019-03-11 11:42:36 +01:00
|
|
|
|
|
|
|
/* end kernel-aided life-time management */
|
|
|
|
Kernel::ack_signal(Capability_space::capid(data->context->_cap));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Signal Signal_receiver::pending_signal()
|
|
|
|
{
|
|
|
|
Lock::Guard contexts_lock_guard(_contexts_lock);
|
|
|
|
Signal::Data result;
|
|
|
|
_contexts.for_each_locked([&] (Signal_context &context) {
|
|
|
|
|
|
|
|
if (!context._pending) return;
|
|
|
|
|
|
|
|
_contexts.head(context._next);
|
|
|
|
context._pending = false;
|
|
|
|
result = context._curr_signal;
|
|
|
|
context._curr_signal = Signal::Data(0, 0);
|
|
|
|
|
|
|
|
Trace::Signal_received trace_event(context, result.num);
|
|
|
|
throw Context_ring::Break_for_each();
|
|
|
|
});
|
|
|
|
if (result.context) {
|
|
|
|
Lock::Guard lock_guard(result.context->_lock);
|
|
|
|
if (result.num == 0)
|
|
|
|
warning("returning signal with num == 0");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for pending signals */
|
|
|
|
if (Kernel::pending_signal(Capability_space::capid(_cap)) != 0) {
|
|
|
|
throw Signal_not_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read signal data */
|
|
|
|
Signal::Data * const data =
|
|
|
|
(Signal::Data *)Thread::myself()->utcb()->data();
|
|
|
|
Signal_context * const context = data->context;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* update signal context */
|
|
|
|
Lock::Guard lock_guard(context->_lock);
|
|
|
|
context->_pending = false;
|
|
|
|
context->_curr_signal = Signal::Data(context, data->num);
|
|
|
|
result = context->_curr_signal;
|
|
|
|
}
|
|
|
|
|
2015-11-13 15:49:11 +01:00
|
|
|
/* end kernel-aided life-time management */
|
2016-06-15 15:04:54 +02:00
|
|
|
Kernel::ack_signal(Capability_space::capid(data->context->_cap));
|
2019-03-11 11:42:36 +01:00
|
|
|
return result;
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-14 17:00:53 +01:00
|
|
|
void Signal_receiver::unblock_signal_waiter(Rpc_entrypoint &rpc_ep)
|
|
|
|
{
|
2017-02-24 14:29:29 +01:00
|
|
|
Kernel::cancel_next_await_signal(native_thread_id(&rpc_ep));
|
2017-02-14 17:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
void Signal_receiver::local_submit(Signal::Data) { Genode::error("not implemented"); }
|