2013-08-10 03:44:55 +02:00
|
|
|
/*
|
|
|
|
* \brief Registry containing possible tracing subjects
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-09
|
|
|
|
*
|
|
|
|
* Tracing subjects represent living or previously living tracing sources
|
|
|
|
* that can have trace buffers attached. Each 'Trace::Subject' belongs to
|
|
|
|
* a TRACE session and may point to a 'Trace::Source' (which is owned by
|
|
|
|
* a CPU session).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-10 03:44:55 +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.
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__TRACE__SUBJECT_REGISTRY_H_
|
|
|
|
#define _CORE__INCLUDE__TRACE__SUBJECT_REGISTRY_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/list.h>
|
|
|
|
#include <util/string.h>
|
2020-02-18 15:29:47 +01:00
|
|
|
#include <base/mutex.h>
|
2013-08-10 03:44:55 +02:00
|
|
|
#include <base/trace/types.h>
|
|
|
|
#include <base/env.h>
|
2014-06-05 15:55:34 +02:00
|
|
|
#include <base/weak_ptr.h>
|
2013-08-10 03:44:55 +02:00
|
|
|
#include <dataspace/client.h>
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <trace/source_registry.h>
|
|
|
|
|
|
|
|
/* base-internal include */
|
2016-01-20 18:27:18 +01:00
|
|
|
#include <base/internal/trace_control.h>
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
namespace Genode { namespace Trace {
|
|
|
|
class Subject;
|
|
|
|
class Subject_registry;
|
|
|
|
} }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subject of tracing data
|
|
|
|
*/
|
|
|
|
class Genode::Trace::Subject
|
|
|
|
:
|
|
|
|
public Genode::List<Genode::Trace::Subject>::Element,
|
|
|
|
public Genode::Trace::Source_owner
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
class Ram_dataspace
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
Ram_allocator *_ram_ptr { nullptr };
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
size_t _size { 0 };
|
|
|
|
Ram_dataspace_capability _ds { };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
void _reset()
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_ram_ptr = nullptr;
|
|
|
|
_size = 0;
|
|
|
|
_ds = Ram_dataspace_capability();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Ram_dataspace(Ram_dataspace const &);
|
|
|
|
Ram_dataspace &operator = (Ram_dataspace const &);
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
Ram_dataspace() { _reset(); }
|
|
|
|
|
|
|
|
~Ram_dataspace() { flush(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate new dataspace
|
|
|
|
*/
|
2019-05-06 10:42:05 +02:00
|
|
|
void setup(Ram_allocator &ram, size_t size)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2019-05-06 10:42:05 +02:00
|
|
|
if (_size && _size == size)
|
|
|
|
return;
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
if (_size)
|
2019-05-06 10:42:05 +02:00
|
|
|
_ram_ptr->free(_ds);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_ram_ptr = &ram;
|
|
|
|
_size = size;
|
|
|
|
_ds = ram.alloc(size);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone dataspace into newly allocated dataspace
|
|
|
|
*/
|
2019-01-30 17:53:16 +01:00
|
|
|
bool setup(Ram_allocator &ram, Region_map &local_rm,
|
|
|
|
Dataspace_capability &from_ds, size_t size)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
|
|
|
if (!from_ds.valid())
|
|
|
|
return false;
|
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
if (_size)
|
|
|
|
flush();
|
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_ram_ptr = &ram;
|
|
|
|
_size = size;
|
|
|
|
_ds = ram.alloc(_size);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/* copy content */
|
2019-01-30 17:53:16 +01:00
|
|
|
void *src = local_rm.attach(from_ds),
|
|
|
|
*dst = local_rm.attach(_ds);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
memcpy(dst, src, _size);
|
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
local_rm.detach(src);
|
|
|
|
local_rm.detach(dst);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release dataspace
|
|
|
|
*/
|
|
|
|
size_t flush()
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
if (_ram_ptr)
|
|
|
|
_ram_ptr->free(_ds);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
_reset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dataspace_capability dataspace() const { return _ds; }
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class Subject_registry;
|
|
|
|
|
|
|
|
Subject_id const _id;
|
|
|
|
unsigned const _source_id;
|
|
|
|
Weak_ptr<Source> _source;
|
|
|
|
Session_label const _label;
|
|
|
|
Thread_name const _name;
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Ram_dataspace _buffer { };
|
|
|
|
Ram_dataspace _policy { };
|
|
|
|
Policy_id _policy_id { };
|
2019-05-06 10:42:05 +02:00
|
|
|
size_t _allocated_memory { 0 };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
Subject_info::State _state()
|
|
|
|
{
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
|
|
|
/* source vanished */
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!source.valid())
|
2013-08-10 03:44:55 +02:00
|
|
|
return Subject_info::DEAD;
|
|
|
|
|
|
|
|
if (source->enabled())
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
return source->owned_by(*this) ? Subject_info::TRACED
|
|
|
|
: Subject_info::FOREIGN;
|
2013-08-10 03:44:55 +02:00
|
|
|
if (source->error())
|
|
|
|
return Subject_info::ERROR;
|
|
|
|
|
|
|
|
return Subject_info::UNTRACED;
|
|
|
|
}
|
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
void _traceable_or_throw()
|
|
|
|
{
|
|
|
|
switch(_state()) {
|
|
|
|
case Subject_info::DEAD : throw Source_is_dead();
|
|
|
|
case Subject_info::FOREIGN : throw Traced_by_other_session();
|
|
|
|
case Subject_info::ERROR : throw Source_is_dead();
|
|
|
|
case Subject_info::INVALID : throw Nonexistent_subject();
|
|
|
|
case Subject_info::UNTRACED: return;
|
|
|
|
case Subject_info::TRACED : return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor, called from 'Subject_registry' only
|
|
|
|
*/
|
|
|
|
Subject(Subject_id id, unsigned source_id, Weak_ptr<Source> &source,
|
|
|
|
Session_label const &label, Thread_name const &name)
|
|
|
|
:
|
|
|
|
_id(id), _source_id(source_id), _source(source),
|
|
|
|
_label(label), _name(name)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return registry-local ID
|
|
|
|
*/
|
|
|
|
Subject_id id() const { return _id; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if subject belongs to the specified unique source ID
|
|
|
|
*/
|
|
|
|
bool has_source_id(unsigned id) const { return id == _source_id; }
|
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
size_t allocated_memory() const { return _allocated_memory; }
|
|
|
|
void reset_allocated_memory() { _allocated_memory = 0; }
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
/**
|
|
|
|
* Start tracing
|
|
|
|
*
|
|
|
|
* \param size trace buffer size
|
|
|
|
*
|
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
|
|
|
* \throw Out_of_ram
|
|
|
|
* \throw Out_of_caps
|
|
|
|
* \throw Already_traced
|
|
|
|
* \throw Source_is_dead
|
|
|
|
* \throw Traced_by_other_session
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
|
|
|
void trace(Policy_id policy_id, Dataspace_capability policy_ds,
|
2019-01-30 17:53:16 +01:00
|
|
|
size_t policy_size, Ram_allocator &ram,
|
|
|
|
Region_map &local_rm, size_t size)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2019-05-06 10:42:05 +02:00
|
|
|
/* check state and throw error in case subject is not traceable */
|
|
|
|
_traceable_or_throw();
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
_policy_id = policy_id;
|
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
_buffer.setup(ram, size);
|
|
|
|
if(!_policy.setup(ram, local_rm, policy_ds, policy_size))
|
|
|
|
throw Already_traced();
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/* inform trace source about the new buffer */
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
if (!source->try_acquire(*this))
|
2013-08-10 03:44:55 +02:00
|
|
|
throw Traced_by_other_session();
|
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
_allocated_memory = policy_size + size;
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
source->trace(_policy.dataspace(), _buffer.dataspace());
|
|
|
|
}
|
|
|
|
|
|
|
|
void pause()
|
|
|
|
{
|
|
|
|
/* inform trace source about the new buffer */
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (source.valid())
|
2013-08-10 03:44:55 +02:00
|
|
|
source->disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume tracing of paused source
|
|
|
|
*
|
|
|
|
* \throw Source_is_dead
|
|
|
|
*/
|
|
|
|
void resume()
|
|
|
|
{
|
|
|
|
/* inform trace source about the new buffer */
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!source.valid())
|
2013-08-10 03:44:55 +02:00
|
|
|
throw Source_is_dead();
|
|
|
|
|
|
|
|
source->enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
Subject_info info()
|
|
|
|
{
|
2015-06-11 23:05:02 +02:00
|
|
|
Execution_time execution_time;
|
|
|
|
Affinity::Location affinity;
|
|
|
|
|
|
|
|
{
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (source.valid()) {
|
2015-06-11 23:05:02 +02:00
|
|
|
Trace::Source::Info const info = source->info();
|
|
|
|
execution_time = info.execution_time;
|
|
|
|
affinity = info.affinity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Subject_info(_label, _name, _state(), _policy_id,
|
|
|
|
execution_time, affinity);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Dataspace_capability buffer() const { return _buffer.dataspace(); }
|
|
|
|
|
|
|
|
size_t release()
|
|
|
|
{
|
|
|
|
/* inform trace source about the new buffer */
|
|
|
|
Locked_ptr<Source> source(_source);
|
|
|
|
|
|
|
|
/* source vanished */
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!source.valid())
|
2013-08-10 03:44:55 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return _buffer.flush() + _policy.flush();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registry to tracing subjects
|
|
|
|
*
|
|
|
|
* There exists one instance for each TRACE session.
|
|
|
|
*/
|
|
|
|
class Genode::Trace::Subject_registry
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef List<Subject> Subjects;
|
|
|
|
|
|
|
|
Allocator &_md_alloc;
|
2019-01-30 17:53:16 +01:00
|
|
|
Ram_allocator &_ram;
|
2013-08-10 03:44:55 +02:00
|
|
|
Source_registry &_sources;
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
unsigned _id_cnt { 0 };
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex _mutex { };
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Subjects _entries { };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functor for testing the existance of subjects for a given source
|
|
|
|
*
|
|
|
|
* This functor is invoked by 'Source_registry::export'.
|
|
|
|
*/
|
|
|
|
struct Tester
|
|
|
|
{
|
|
|
|
Subjects &subjects;
|
|
|
|
|
|
|
|
Tester(Subjects &subjects) : subjects(subjects) { }
|
|
|
|
|
|
|
|
bool operator () (unsigned source_id)
|
|
|
|
{
|
|
|
|
for (Subject *s = subjects.first(); s; s = s->next())
|
|
|
|
if (s->has_source_id(source_id))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
} _tester { _entries };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functor for inserting new subjects into the registry
|
|
|
|
*
|
|
|
|
* This functor is invoked by 'Source_registry::export'.
|
|
|
|
*/
|
|
|
|
struct Inserter
|
|
|
|
{
|
|
|
|
Subject_registry ®istry;
|
|
|
|
|
|
|
|
Inserter(Subject_registry ®istry) : registry(registry) { }
|
|
|
|
|
|
|
|
void operator () (unsigned source_id, Weak_ptr<Source> source,
|
|
|
|
Session_label const &label, Thread_name const &name)
|
|
|
|
{
|
|
|
|
Subject *subject = new (®istry._md_alloc)
|
2019-10-04 19:56:20 +02:00
|
|
|
Subject(Subject_id(++registry._id_cnt), source_id, source, label, name);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
registry._entries.insert(subject);
|
|
|
|
}
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
} _inserter { *this };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy subject, and release policy and trace buffers
|
|
|
|
*
|
|
|
|
* \return RAM resources released during destruction
|
|
|
|
*/
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
size_t _unsynchronized_destroy(Subject &s)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_entries.remove(&s);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
size_t const released_ram = s.release();
|
2013-08-10 03:44:55 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
destroy(&_md_alloc, &s);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
return released_ram;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain subject from given session-local ID
|
|
|
|
*
|
|
|
|
* \throw Nonexistent_subject
|
|
|
|
*/
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Subject &_unsynchronized_lookup_by_id(Subject_id id)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
|
|
|
for (Subject *s = _entries.first(); s; s = s->next())
|
|
|
|
if (s->id() == id)
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
return *s;
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
throw Nonexistent_subject();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param md_alloc meta-data allocator used for allocating 'Subject'
|
|
|
|
* objects.
|
2019-01-30 17:53:16 +01:00
|
|
|
* \param ram allocator used for the allocation of trace
|
2013-08-10 03:44:55 +02:00
|
|
|
* buffers and policy dataspaces.
|
|
|
|
*/
|
2019-01-30 17:53:16 +01:00
|
|
|
Subject_registry(Allocator &md_alloc, Ram_allocator &ram,
|
2013-08-10 03:44:55 +02:00
|
|
|
Source_registry &sources)
|
|
|
|
:
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
_md_alloc(md_alloc), _ram(ram), _sources(sources)
|
2013-08-10 03:44:55 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Subject_registry()
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(_mutex);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
while (Subject *s = _entries.first())
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_unsynchronized_destroy(*s);
|
2013-08-10 03:44:55 +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
|
|
|
* \throw Out_of_ram
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
void import_new_sources(Source_registry &)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(_mutex);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
_sources.export_sources(_tester, _inserter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve existing subject IDs
|
|
|
|
*/
|
|
|
|
size_t subjects(Subject_id *dst, size_t dst_len)
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(_mutex);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
unsigned i = 0;
|
|
|
|
for (Subject *s = _entries.first(); s && i < dst_len; s = s->next())
|
|
|
|
dst[i++] = s->id();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove subject and release resources
|
|
|
|
*
|
|
|
|
* \return RAM resources released as a side effect for removing the
|
|
|
|
* subject (i.e., if the subject held a trace buffer or
|
|
|
|
* policy dataspace). The value does not account for
|
|
|
|
* memory allocated from the metadata allocator.
|
|
|
|
*/
|
|
|
|
size_t release(Subject_id subject_id)
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(_mutex);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Subject &subject = _unsynchronized_lookup_by_id(subject_id);
|
|
|
|
return _unsynchronized_destroy(subject);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Subject &lookup_by_id(Subject_id id)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(_mutex);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
return _unsynchronized_lookup_by_id(id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__TRACE__SUBJECT_REGISTRY_H_ */
|