2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Connection to a service
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2008-08-22
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2008-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01: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.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__BASE__CONNECTION_H_
|
|
|
|
#define _INCLUDE__BASE__CONNECTION_H_
|
|
|
|
|
|
|
|
#include <base/env.h>
|
|
|
|
#include <base/capability.h>
|
2016-11-06 14:26:34 +01:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Connection_base;
|
|
|
|
template <typename> class Connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Genode::Connection_base : public Noncopyable
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Env &_env;
|
|
|
|
|
|
|
|
Parent::Client _parent_client;
|
|
|
|
|
|
|
|
Id_space<Parent::Client>::Element const _id_space_element;
|
|
|
|
|
|
|
|
void _block_for_session_response();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Connection_base(Env &env)
|
|
|
|
:
|
|
|
|
_env(env),
|
|
|
|
_id_space_element(_parent_client, _env.id_space())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legacy constructor
|
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
*/
|
|
|
|
Connection_base();
|
|
|
|
|
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
|
|
|
|
|
|
|
void upgrade(Session::Resources resources)
|
2016-11-06 14:26:34 +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
|
|
|
String<80> const args("ram_quota=", resources.ram_quota, ", "
|
|
|
|
"cap_quota=", resources.cap_quota);
|
2016-11-06 14:26:34 +01:00
|
|
|
_env.upgrade(_id_space_element.id(), args.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
|
|
|
|
|
|
|
void upgrade_ram(size_t bytes)
|
|
|
|
{
|
|
|
|
upgrade(Session::Resources { Ram_quota{bytes}, Cap_quota{0} });
|
|
|
|
}
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
|
|
|
|
void upgrade_caps(size_t caps)
|
|
|
|
{
|
|
|
|
upgrade(Session::Resources { Ram_quota{0}, Cap_quota{caps} });
|
|
|
|
}
|
2016-11-06 14:26:34 +01:00
|
|
|
};
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of an open connection to a service
|
|
|
|
*/
|
|
|
|
template <typename SESSION_TYPE>
|
2016-11-06 14:26:34 +01:00
|
|
|
class Genode::Connection : public Connection_base
|
2015-03-04 21:12:14 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
2016-11-08 16:37:27 +01:00
|
|
|
* Buffer for storing the session arguments passed to the
|
|
|
|
* 'session' method that is called before the 'Connection' is
|
|
|
|
* constructed.
|
2015-03-04 21:12:14 +01:00
|
|
|
*/
|
2016-11-06 14:26:34 +01:00
|
|
|
|
2015-03-04 21:12:14 +01:00
|
|
|
enum { FORMAT_STRING_SIZE = Parent::Session_args::MAX_SIZE };
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
char _session_args[FORMAT_STRING_SIZE];
|
|
|
|
char _affinity_arg[sizeof(Affinity)];
|
2015-03-04 21:12:14 +01:00
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
void _session(Parent &parent,
|
|
|
|
Affinity const &affinity,
|
|
|
|
const char *format_args, va_list list)
|
2015-03-04 21:12:14 +01:00
|
|
|
{
|
2016-11-08 16:37:27 +01:00
|
|
|
String_console sc(_session_args, FORMAT_STRING_SIZE);
|
2015-03-04 21:12:14 +01:00
|
|
|
sc.vprintf(format_args, list);
|
|
|
|
va_end(list);
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
memcpy(_affinity_arg, &affinity, sizeof(Affinity));
|
|
|
|
}
|
|
|
|
|
|
|
|
Capability<SESSION_TYPE> _request_cap()
|
|
|
|
{
|
|
|
|
Affinity affinity;
|
|
|
|
memcpy(&affinity, _affinity_arg, sizeof(Affinity));
|
|
|
|
|
|
|
|
try {
|
2016-11-06 14:26:34 +01:00
|
|
|
return _env.session<SESSION_TYPE>(_id_space_element.id(),
|
|
|
|
_session_args, affinity); }
|
2016-11-08 16:37:27 +01:00
|
|
|
catch (...) {
|
|
|
|
error(SESSION_TYPE::service_name(), "-session creation failed "
|
|
|
|
"(", Cstring(_session_args), ")");
|
|
|
|
throw;
|
|
|
|
}
|
2015-03-04 21:12:14 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
Capability<SESSION_TYPE> _cap = _request_cap();
|
|
|
|
|
2015-03-04 21:12:14 +01:00
|
|
|
public:
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
typedef SESSION_TYPE Session_type;
|
|
|
|
|
2015-03-04 21:12:14 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2016-11-06 14:26:34 +01:00
|
|
|
Connection(Env &env, Capability<SESSION_TYPE>)
|
|
|
|
:
|
|
|
|
Connection_base(env), _cap(_request_cap())
|
|
|
|
{ }
|
2016-05-10 17:24:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
* \deprecated Use the constructor with 'Env &' as first
|
|
|
|
* argument instead
|
|
|
|
*/
|
2016-11-06 14:26:34 +01:00
|
|
|
Connection(Capability<SESSION_TYPE>) : _cap(_request_cap()) { }
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2016-11-06 14:26:34 +01:00
|
|
|
~Connection() { _env.close(_id_space_element.id()); }
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return session capability
|
|
|
|
*/
|
|
|
|
Capability<SESSION_TYPE> cap() const { return _cap; }
|
|
|
|
|
2016-05-10 17:24:51 +02:00
|
|
|
/**
|
|
|
|
* Issue session request to the parent
|
|
|
|
*/
|
|
|
|
Capability<SESSION_TYPE> session(Parent &parent, const char *format_args, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, format_args);
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
_session(parent, Affinity(), format_args, list);
|
|
|
|
return Capability<SESSION_TYPE>();
|
2016-05-10 17:24:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Issue session request to the parent
|
|
|
|
*/
|
|
|
|
Capability<SESSION_TYPE> session(Parent &parent,
|
|
|
|
Affinity const &affinity,
|
|
|
|
char const *format_args, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, format_args);
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
_session(parent, affinity, format_args, list);
|
|
|
|
return Capability<SESSION_TYPE>();
|
2016-05-10 17:24:51 +02:00
|
|
|
}
|
|
|
|
|
2015-03-04 21:12:14 +01:00
|
|
|
/**
|
|
|
|
* Shortcut for env()->parent()->session()
|
2016-05-10 17:24:51 +02:00
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
* \deprecated to be removed along with Genode::env()
|
2015-03-04 21:12:14 +01:00
|
|
|
*/
|
|
|
|
Capability<SESSION_TYPE> session(const char *format_args, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, format_args);
|
|
|
|
|
2017-01-09 15:18:49 +01:00
|
|
|
_session(*env_deprecated()->parent(), Affinity(), format_args, list);
|
2016-11-08 16:37:27 +01:00
|
|
|
return Capability<SESSION_TYPE>();
|
2015-03-04 21:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for env()->parent()->session()
|
2016-05-10 17:24:51 +02:00
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
* \deprecated to be removed along with Genode::env()
|
2015-03-04 21:12:14 +01:00
|
|
|
*/
|
|
|
|
Capability<SESSION_TYPE> session(Affinity const &affinity,
|
|
|
|
char const *format_args, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, format_args);
|
|
|
|
|
2016-11-08 16:37:27 +01:00
|
|
|
_session(affinity, format_args, list);
|
|
|
|
return Capability<SESSION_TYPE>();
|
2015-03-04 21:12:14 +01:00
|
|
|
}
|
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
#endif /* _INCLUDE__BASE__CONNECTION_H_ */
|