Support for dynamic ROM sessions, fix #170
This patch introduces support for ROM sessions that update their
provided data during the lifetime of the session. The 'Rom_session'
interface had been extended with the new 'release()' and 'sigh()'
functions, which are needed to support the new protocol. All ROM
services have been updated to the new interface.
Furthermore, the patch changes the child policy of init
with regard to the handling of configuration files. The 'Init::Child'
used to always provide the ROM dataspace with the child's config file
via a locally implemented ROM service. However, for dynamic ROM
sessions, we need to establish a session to the real supplier of the ROM
data. This is achieved by using a new 'Child_policy_redirect_rom_file'
policy to handle the 'configfile' rather than handling the 'configfile'
case entirely within 'Child_config'.
To see the new facility in action, the new 'os/run/dynamic_config.run'
script provides a simple scenario. The config file of the test program
is provided by a service, which generates and updates the config data
at regular intervals.
In addition, new support has been added to let slaves use dynamic
reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the
configuration of a slave can be changed dynamically at runtime via the
new 'configure()' function.
The config is provided as plain null-terminated string (instead of a
dataspace capability) because we need to buffer the config data anyway.
So there is no benefit of using a dataspace. For buffering configuration
data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified
at construction time of a 'Slave_policy', no config is supplied to the
slave (which is still a common case).
An example for dynamically reconfiguring a slave is provided by
'os/run/dynamic_config_slave.run'.
2012-04-04 17:07:19 +02:00
|
|
|
/*
|
|
|
|
* \brief Test for changing configuration at runtime (server-side)
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2012-04-04
|
|
|
|
*
|
|
|
|
* This program provides a generated config file as ROM service. After
|
|
|
|
* opening a ROM session, the data gets repeatedly updated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
Support for dynamic ROM sessions, fix #170
This patch introduces support for ROM sessions that update their
provided data during the lifetime of the session. The 'Rom_session'
interface had been extended with the new 'release()' and 'sigh()'
functions, which are needed to support the new protocol. All ROM
services have been updated to the new interface.
Furthermore, the patch changes the child policy of init
with regard to the handling of configuration files. The 'Init::Child'
used to always provide the ROM dataspace with the child's config file
via a locally implemented ROM service. However, for dynamic ROM
sessions, we need to establish a session to the real supplier of the ROM
data. This is achieved by using a new 'Child_policy_redirect_rom_file'
policy to handle the 'configfile' rather than handling the 'configfile'
case entirely within 'Child_config'.
To see the new facility in action, the new 'os/run/dynamic_config.run'
script provides a simple scenario. The config file of the test program
is provided by a service, which generates and updates the config data
at regular intervals.
In addition, new support has been added to let slaves use dynamic
reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the
configuration of a slave can be changed dynamically at runtime via the
new 'configure()' function.
The config is provided as plain null-terminated string (instead of a
dataspace capability) because we need to buffer the config data anyway.
So there is no benefit of using a dataspace. For buffering configuration
data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified
at construction time of a 'Slave_policy', no config is supplied to the
slave (which is still a common case).
An example for dynamically reconfiguring a slave is provided by
'os/run/dynamic_config_slave.run'.
2012-04-04 17:07:19 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/signal.h>
|
|
|
|
#include <os/attached_ram_dataspace.h>
|
2012-10-05 17:12:20 +02:00
|
|
|
#include <os/static_root.h>
|
Support for dynamic ROM sessions, fix #170
This patch introduces support for ROM sessions that update their
provided data during the lifetime of the session. The 'Rom_session'
interface had been extended with the new 'release()' and 'sigh()'
functions, which are needed to support the new protocol. All ROM
services have been updated to the new interface.
Furthermore, the patch changes the child policy of init
with regard to the handling of configuration files. The 'Init::Child'
used to always provide the ROM dataspace with the child's config file
via a locally implemented ROM service. However, for dynamic ROM
sessions, we need to establish a session to the real supplier of the ROM
data. This is achieved by using a new 'Child_policy_redirect_rom_file'
policy to handle the 'configfile' rather than handling the 'configfile'
case entirely within 'Child_config'.
To see the new facility in action, the new 'os/run/dynamic_config.run'
script provides a simple scenario. The config file of the test program
is provided by a service, which generates and updates the config data
at regular intervals.
In addition, new support has been added to let slaves use dynamic
reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the
configuration of a slave can be changed dynamically at runtime via the
new 'configure()' function.
The config is provided as plain null-terminated string (instead of a
dataspace capability) because we need to buffer the config data anyway.
So there is no benefit of using a dataspace. For buffering configuration
data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified
at construction time of a 'Slave_policy', no config is supplied to the
slave (which is still a common case).
An example for dynamically reconfiguring a slave is provided by
'os/run/dynamic_config_slave.run'.
2012-04-04 17:07:19 +02:00
|
|
|
#include <timer_session/connection.h>
|
|
|
|
#include <rom_session/rom_session.h>
|
|
|
|
#include <cap_session/connection.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The implementation of this class follows the lines of
|
|
|
|
* 'os/include/os/child_policy_dynamic_rom.h'.
|
|
|
|
*/
|
|
|
|
class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Genode::Attached_ram_dataspace _fg;
|
|
|
|
Genode::Attached_ram_dataspace _bg;
|
|
|
|
|
|
|
|
bool _bg_has_pending_data;
|
|
|
|
|
|
|
|
Genode::Lock _lock;
|
|
|
|
|
|
|
|
Genode::Signal_context_capability _sigh;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Rom_session_component()
|
|
|
|
: _fg(0, 0), _bg(0, 0), _bg_has_pending_data(false) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the config file
|
|
|
|
*/
|
|
|
|
void configure(char const *data)
|
|
|
|
{
|
|
|
|
Genode::Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
Genode::size_t const data_len = Genode::strlen(data) + 1;
|
|
|
|
|
|
|
|
/* let background buffer grow if needed */
|
|
|
|
if (_bg.size() < data_len)
|
|
|
|
_bg.realloc(Genode::env()->ram_session(), data_len);
|
|
|
|
|
|
|
|
Genode::strncpy(_bg.local_addr<char>(), data, data_len);
|
|
|
|
_bg_has_pending_data = true;
|
|
|
|
|
|
|
|
/* inform client about the changed data */
|
|
|
|
if (_sigh.valid())
|
|
|
|
Genode::Signal_transmitter(_sigh).submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** ROM session interface **
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
Genode::Rom_dataspace_capability dataspace()
|
|
|
|
{
|
|
|
|
Genode::Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
if (!_fg.size() && !_bg_has_pending_data) {
|
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
|
|
|
Genode::error("no data loaded");
|
Support for dynamic ROM sessions, fix #170
This patch introduces support for ROM sessions that update their
provided data during the lifetime of the session. The 'Rom_session'
interface had been extended with the new 'release()' and 'sigh()'
functions, which are needed to support the new protocol. All ROM
services have been updated to the new interface.
Furthermore, the patch changes the child policy of init
with regard to the handling of configuration files. The 'Init::Child'
used to always provide the ROM dataspace with the child's config file
via a locally implemented ROM service. However, for dynamic ROM
sessions, we need to establish a session to the real supplier of the ROM
data. This is achieved by using a new 'Child_policy_redirect_rom_file'
policy to handle the 'configfile' rather than handling the 'configfile'
case entirely within 'Child_config'.
To see the new facility in action, the new 'os/run/dynamic_config.run'
script provides a simple scenario. The config file of the test program
is provided by a service, which generates and updates the config data
at regular intervals.
In addition, new support has been added to let slaves use dynamic
reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the
configuration of a slave can be changed dynamically at runtime via the
new 'configure()' function.
The config is provided as plain null-terminated string (instead of a
dataspace capability) because we need to buffer the config data anyway.
So there is no benefit of using a dataspace. For buffering configuration
data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified
at construction time of a 'Slave_policy', no config is supplied to the
slave (which is still a common case).
An example for dynamically reconfiguring a slave is provided by
'os/run/dynamic_config_slave.run'.
2012-04-04 17:07:19 +02:00
|
|
|
return Genode::Rom_dataspace_capability();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep foreground if no background exists. Otherwise, use old
|
|
|
|
* background as new foreground.
|
|
|
|
*/
|
|
|
|
if (_bg_has_pending_data) {
|
|
|
|
_fg.swap(_bg);
|
|
|
|
_bg_has_pending_data = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::Dataspace_capability ds_cap = _fg.cap();
|
|
|
|
return Genode::static_cap_cast<Genode::Rom_dataspace>(ds_cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sigh(Genode::Signal_context_capability sigh_cap)
|
|
|
|
{
|
|
|
|
Genode::Lock::Guard guard(_lock);
|
|
|
|
_sigh = sigh_cap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
/* connection to capability service needed to create capabilities */
|
|
|
|
static Cap_connection cap;
|
|
|
|
|
|
|
|
enum { STACK_SIZE = 8*1024 };
|
|
|
|
static Rpc_entrypoint ep(&cap, STACK_SIZE, "rom_ep");
|
|
|
|
|
|
|
|
static Rom_session_component rom_session;
|
|
|
|
static Static_root<Rom_session> rom_root(ep.manage(&rom_session));
|
|
|
|
|
|
|
|
rom_session.configure("<config><counter>-1</counter></config>");
|
|
|
|
|
|
|
|
/* announce server */
|
|
|
|
env()->parent()->announce(ep.manage(&rom_root));
|
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
static Timer::Connection timer;
|
|
|
|
timer.msleep(250);
|
|
|
|
|
|
|
|
/* re-generate configuration */
|
|
|
|
char buf[100];
|
|
|
|
Genode::snprintf(buf, sizeof(buf),
|
|
|
|
"<config><counter>%d</counter></config>",
|
|
|
|
counter++);
|
|
|
|
|
|
|
|
rom_session.configure(buf);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|