nic_router: relax timer accuracy for timestamps

The NIC router uses the timer for relatively coarse-grained timeouts.
It therefore suffices to update and store the current time when the NIC router
is signalled and use the cached time instead. This prevents frequent
syscalls or RPCs when acquiring the current time for every packet.

genodelabs/genode#4555
This commit is contained in:
Johannes Schlatow 2022-07-07 15:00:56 +02:00 committed by Christian Helmuth
parent 735abca1b6
commit 01c9c32573
21 changed files with 128 additions and 44 deletions

View File

@ -0,0 +1,74 @@
/*
* \brief A wrapper for Timer::Connection that caches time values
* \author Johannes Schlatow
* \date 2022-07-07
*
* This implementation aims for reducing the number of
* Timer::Connection::curr_time() that was found to be relatively
* expensive on base-hw (implies a syscall on each call) by assuming that
* a certain caching is fine with the accuracy requirements of the NIC router.
*/
/*
* Copyright (C) 2022 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 _CACHED_TIMER_H_
#define _CACHED_TIMER_H_
/* Genode includes */
#include <timer_session/connection.h>
namespace Net {
class Cached_timer;
}
class Net::Cached_timer : public ::Timer::Connection
{
private:
using Duration = Genode::Duration;
using Microseconds = Genode::Microseconds;
Duration _cached_time { Microseconds { 0 } };
public:
Cached_timer (Genode::Env &env)
:
Timer::Connection { env }
{ }
/**
* Update cached time with current timer
*/
void update_cached_time()
{
_cached_time = Timer::Connection::curr_time();
}
/**
* Update cached time and return it
*/
Duration curr_time() override
{
update_cached_time();
return cached_time();
}
/***************
** Accessors **
***************/
Duration cached_time() const { return _cached_time; }
void cached_time(Duration time) { _cached_time = time; }
};
#endif /* _CACHED_TIMER_H_ */

View File

@ -105,7 +105,7 @@ Configuration::_init_icmp_type_3_code_on_fragm_ipv4(Xml_node const &node) const
Configuration::Configuration(Env &env,
Xml_node const node,
Allocator &alloc,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &old_config,
Quota const &shared_quota,
Interface_list &interfaces)

View File

@ -71,7 +71,7 @@ class Net::Configuration
Configuration(Genode::Env &env,
Genode::Xml_node const node,
Genode::Allocator &alloc,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &old_config,
Quota const &shared_quota,
Interface_list &interfaces);

View File

@ -54,7 +54,7 @@ Configuration &Dhcp_client::_config() { return _domain().config(); };
Domain &Dhcp_client::_domain() { return _interface.domain(); }
Dhcp_client::Dhcp_client(Timer::Connection &timer,
Dhcp_client::Dhcp_client(Cached_timer &timer,
Interface &interface)
:
_interface(interface),

View File

@ -14,8 +14,10 @@
#ifndef _DHCP_CLIENT_H_
#define _DHCP_CLIENT_H_
/* local includes */
#include <cached_timer.h>
/* Genode includes */
#include <timer_session/connection.h>
#include <net/dhcp.h>
namespace Net {
@ -60,7 +62,7 @@ class Net::Dhcp_client
public:
Dhcp_client(Timer::Connection &timer,
Dhcp_client(Cached_timer &timer,
Interface &interface);
void handle_dhcp_reply(Dhcp_packet &dhcp);

View File

@ -228,7 +228,7 @@ bool Dhcp_server::ready() const
Dhcp_allocation::Dhcp_allocation(Interface &interface,
Ipv4_address const &ip,
Mac_address const &mac,
Timer::Connection &timer,
Cached_timer &timer,
Microseconds lifetime)
:
_interface(interface), _ip(ip), _mac(mac),

View File

@ -20,6 +20,7 @@
#include <pointer.h>
#include <dns.h>
#include <ipv4_config.h>
#include <cached_timer.h>
/* Genode includes */
#include <net/mac_address.h>
@ -171,7 +172,7 @@ class Net::Dhcp_allocation : public Genode::Avl_node<Dhcp_allocation>,
Dhcp_allocation(Interface &interface,
Ipv4_address const &ip,
Mac_address const &mac,
Timer::Connection &timer,
Cached_timer &timer,
Genode::Microseconds lifetime);
~Dhcp_allocation();

View File

@ -1532,6 +1532,8 @@ void Interface::_handle_pkt()
void Interface::_handle_pkt_stream_signal()
{
_timer.update_cached_time();
/*
* Release all sent packets that were already acknowledged by the counter
* side. Doing this first frees packet-stream memory which facilitates
@ -1832,7 +1834,7 @@ void Interface::_send_submit_pkt(Packet_descriptor &pkt,
Interface::Interface(Genode::Entrypoint &ep,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const router_mac,
Genode::Allocator &alloc,
Mac_address const mac,

View File

@ -140,7 +140,7 @@ class Net::Interface : private Interface_list::Element
Mac_address const _mac;
Reference<Configuration> _config;
Interface_policy &_policy;
Timer::Connection &_timer;
Cached_timer &_timer;
Genode::Allocator &_alloc;
Pointer<Domain> _domain { };
Arp_waiter_list _own_arp_waiters { };
@ -375,7 +375,7 @@ class Net::Interface : private Interface_list::Element
};
Interface(Genode::Entrypoint &ep,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const router_mac,
Genode::Allocator &alloc,
Mac_address const mac,

View File

@ -23,8 +23,8 @@
#ifndef _LAZY_ONE_SHOT_TIMEOUT_H_
#define _LAZY_ONE_SHOT_TIMEOUT_H_
/* Genode includes */
#include <timer_session/connection.h>
/* local includes */
#include <cached_timer.h>
namespace Net {
@ -45,7 +45,7 @@ class Net::Lazy_one_shot_timeout
using uint64_t = Genode::uint64_t;
using Handler_method = void (HANDLER::*)(Duration);
Timer::Connection &_timer;
Cached_timer &_timer;
HANDLER &_object;
Handler_method const _method;
uint64_t const _tolerance_us;
@ -53,6 +53,8 @@ class Net::Lazy_one_shot_timeout
void _handle_timeout(Duration curr_time)
{
_timer.cached_time(curr_time);
/*
* If the postponed deadline is set and more than tolerance
* microseconds in the future, skip calling the user handler and
@ -83,10 +85,10 @@ class Net::Lazy_one_shot_timeout
using One_shot_timeout::discard;
using One_shot_timeout::scheduled;
Lazy_one_shot_timeout(Timer::Connection &timer,
HANDLER &object,
Handler_method method,
Microseconds tolerance)
Lazy_one_shot_timeout(Cached_timer &timer,
HANDLER &object,
Handler_method method,
Microseconds tolerance)
:
One_shot_timeout { timer, *this,
&Lazy_one_shot_timeout<HANDLER>::_handle_timeout },
@ -123,7 +125,7 @@ class Net::Lazy_one_shot_timeout
return;
}
uint64_t const curr_time_us {
_timer.curr_time().trunc_to_plain_us().value };
_timer.cached_time().trunc_to_plain_us().value };
uint64_t const new_deadline_us {
duration.value <= ~(uint64_t)0 - curr_time_us ?

View File

@ -90,7 +90,7 @@ Link::Link(Interface &cln_interface,
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Microseconds const dissolve_timeout,
@ -201,7 +201,7 @@ Tcp_link::Tcp_link(Interface &cln_interface,
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats)
@ -282,7 +282,7 @@ Udp_link::Udp_link(Interface &cln_interface,
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats)
@ -313,7 +313,7 @@ Icmp_link::Icmp_link(Interface &cln_interface,
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats)

View File

@ -210,7 +210,7 @@ class Net::Link : public Link_list::Element
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Genode::Microseconds const dissolve_timeout,
@ -274,7 +274,7 @@ class Net::Tcp_link : public Link
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats);
@ -292,7 +292,7 @@ struct Net::Udp_link : Link
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats);
@ -310,7 +310,7 @@ struct Net::Icmp_link : Link
Pointer<Port_allocator_guard> srv_port_alloc,
Domain &srv_domain,
Link_side_id const &srv_id,
Timer::Connection &timer,
Cached_timer &timer,
Configuration &config,
L3_protocol const protocol,
Interface_link_stats &stats);

View File

@ -21,6 +21,7 @@
#include <nic_session_root.h>
#include <uplink_session_root.h>
#include <configuration.h>
#include <cached_timer.h>
using namespace Net;
using namespace Genode;
@ -35,7 +36,7 @@ class Net::Main
Genode::Env &_env;
Quota _shared_quota { };
Interface_list _interfaces { };
Timer::Connection _timer { _env };
Cached_timer _timer { _env };
Genode::Heap _heap { &_env.ram(), &_env.rm() };
Genode::Attached_rom_dataspace _config_rom { _env, "config" };
Reference<Configuration> _config { *new (_heap) Configuration { _config_rom.xml(), _heap } };

View File

@ -50,7 +50,7 @@ Net::Nic_client::Nic_client(Xml_node const &node,
Allocator &alloc,
Nic_client_tree &old_nic_clients,
Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Interface_list &interfaces,
Configuration &config)
:
@ -150,7 +150,7 @@ bool Net::Nic_client_interface_base::interface_link_state() const
**************************/
Net::Nic_client_interface::Nic_client_interface(Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Genode::Allocator &alloc,
Interface_list &interfaces,
Configuration &config,

View File

@ -85,7 +85,7 @@ class Net::Nic_client : public Nic_client_base,
Genode::Allocator &alloc,
Nic_client_tree &old_nic_clients,
Genode::Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Interface_list &interfaces,
Configuration &config);
@ -160,7 +160,7 @@ class Net::Nic_client_interface : public Nic_client_interface_base,
public:
Nic_client_interface(Genode::Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Genode::Allocator &alloc,
Interface_list &interfaces,
Configuration &config,

View File

@ -234,7 +234,7 @@ Nic_session_component::
Nic_session_component(Session_env &session_env,
size_t const tx_buf_size,
size_t const rx_buf_size,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const mac,
Mac_address const &router_mac,
Session_label const &label,
@ -283,7 +283,7 @@ Nic_session_component::link_state_sigh(Signal_context_capability sigh)
**********************/
Net::Nic_session_root::Nic_session_root(Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Allocator &alloc,
Configuration &config,
Quota &shared_quota,

View File

@ -132,7 +132,7 @@ class Net::Nic_session_component : private Nic_session_component_base,
Nic_session_component(Genode::Session_env &session_env,
Genode::size_t const tx_buf_size,
Genode::size_t const rx_buf_size,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const mac,
Mac_address const &router_mac,
Genode::Session_label const &label,
@ -169,7 +169,7 @@ class Net::Nic_session_root
enum { MAC_ALLOC_BASE = 0x02 };
Genode::Env &_env;
Timer::Connection &_timer;
Cached_timer &_timer;
Mac_allocator _mac_alloc;
Mac_address const _router_mac;
Reference<Configuration> _config;
@ -189,7 +189,7 @@ class Net::Nic_session_root
public:
Nic_session_root(Genode::Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Genode::Allocator &alloc,
Configuration &config,
Quota &shared_quota,

View File

@ -22,7 +22,7 @@ using namespace Genode;
Net::Report::Report(bool const &verbose,
Xml_node const node,
Timer::Connection &timer,
Cached_timer &timer,
Domain_tree &domains,
Quota const &shared_quota,
Pd_session &pd,

View File

@ -14,8 +14,10 @@
#ifndef _REPORT_H_
#define _REPORT_H_
/* local includes */
#include <cached_timer.h>
/* Genode */
#include <timer_session/connection.h>
#include <os/reporter.h>
namespace Genode {
@ -68,7 +70,7 @@ class Net::Report
Report(bool const &verbose,
Genode::Xml_node const node,
Timer::Connection &timer,
Cached_timer &timer,
Domain_tree &domains,
Quota const &shared_quota,
Genode::Pd_session &pd,

View File

@ -83,7 +83,7 @@ Net::Uplink_session_component::Interface_policy::determine_domain_name() const
Net::Uplink_session_component::Uplink_session_component(Session_env &session_env,
size_t const tx_buf_size,
size_t const rx_buf_size,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const mac,
Session_label const &label,
Interface_list &interfaces,
@ -118,7 +118,7 @@ Net::Uplink_session_component::Uplink_session_component(Session_env
*************************/
Net::Uplink_session_root::Uplink_session_root(Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Allocator &alloc,
Configuration &config,
Quota &shared_quota,

View File

@ -96,7 +96,7 @@ class Net::Uplink_session_component : private Uplink_session_component_base,
Uplink_session_component(Genode::Session_env &session_env,
Genode::size_t const tx_buf_size,
Genode::size_t const rx_buf_size,
Timer::Connection &timer,
Cached_timer &timer,
Mac_address const mac,
Genode::Session_label const &label,
Interface_list &interfaces,
@ -123,7 +123,7 @@ class Net::Uplink_session_root
enum { MAC_ALLOC_BASE = 0x02 };
Genode::Env &_env;
Timer::Connection &_timer;
Cached_timer &_timer;
Reference<Configuration> _config;
Quota &_shared_quota;
Interface_list &_interfaces;
@ -141,7 +141,7 @@ class Net::Uplink_session_root
public:
Uplink_session_root(Genode::Env &env,
Timer::Connection &timer,
Cached_timer &timer,
Genode::Allocator &alloc,
Configuration &config,
Quota &shared_quota,