2013-01-24 11:35:27 +01:00
|
|
|
/*
|
2011-12-22 16:19:25 +01:00
|
|
|
* \brief Core implementation of the CPU session/thread interfaces
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2006-07-17
|
|
|
|
*
|
|
|
|
* FIXME arg_string and quota missing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-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
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
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
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <util/arg_string.h>
|
|
|
|
|
2012-09-04 17:32:55 +02:00
|
|
|
/* core includes */
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <cpu_session_component.h>
|
|
|
|
#include <rm_session_component.h>
|
2016-04-20 21:12:57 +02:00
|
|
|
#include <pd_session_component.h>
|
2012-09-04 17:32:55 +02:00
|
|
|
#include <platform_generic.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2013-01-03 20:29:18 +01:00
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
Thread_capability Cpu_session_component::create_thread(Capability<Pd_session> pd_cap,
|
2014-10-16 11:15:46 +02:00
|
|
|
Name const &name,
|
2016-04-20 21:12:57 +02:00
|
|
|
Affinity::Location affinity,
|
2016-05-04 12:27:17 +02:00
|
|
|
Weight weight,
|
2014-10-16 11:15:46 +02:00
|
|
|
addr_t utcb)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-08-10 03:44:55 +02:00
|
|
|
Trace::Thread_name thread_name(name.string());
|
|
|
|
|
2020-05-05 14:27:29 +02:00
|
|
|
withdraw(Ram_quota{_utcb_quota_size()});
|
2020-01-31 15:50:34 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
Cpu_thread_component *thread = 0;
|
2015-03-27 14:05:55 +01:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
if (weight.value == 0) {
|
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
|
|
|
warning("Thread ", name, ": Bad weight 0, using default weight instead.");
|
2016-05-04 12:27:17 +02:00
|
|
|
weight = Weight();
|
2015-03-27 14:05:55 +01:00
|
|
|
}
|
2016-05-04 12:27:17 +02:00
|
|
|
if (weight.value > QUOTA_LIMIT) {
|
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
|
|
|
warning("Thread ", name, ": Oversized weight ", weight.value, ", using limit instead.");
|
2016-05-04 12:27:17 +02:00
|
|
|
weight = Weight(QUOTA_LIMIT);
|
2015-03-27 14:05:55 +01:00
|
|
|
}
|
2016-05-10 18:05:38 +02:00
|
|
|
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard thread_list_lock_guard(_thread_list_lock);
|
2015-03-27 14:05:55 +01:00
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
/*
|
|
|
|
* Create thread associated with its protection domain
|
|
|
|
*/
|
|
|
|
auto create_thread_lambda = [&] (Pd_session_component *pd) {
|
|
|
|
if (!pd) {
|
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
|
|
|
error("create_thread: invalid PD argument");
|
2016-04-20 21:12:57 +02:00
|
|
|
throw Thread_creation_failed();
|
|
|
|
}
|
2016-11-06 14:26:34 +01:00
|
|
|
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard slab_lock_guard(_thread_alloc_lock);
|
2016-04-20 21:12:57 +02:00
|
|
|
thread = new (&_thread_alloc)
|
2014-10-16 11:15:46 +02:00
|
|
|
Cpu_thread_component(
|
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
|
|
|
cap(), _thread_ep, _pager_ep, *pd, _trace_control_area,
|
2016-05-10 18:05:38 +02:00
|
|
|
_trace_sources, weight, _weight_to_quota(weight.value),
|
2016-04-20 21:12:57 +02:00
|
|
|
_thread_affinity(affinity), _label, thread_name,
|
2016-05-10 18:05:38 +02:00
|
|
|
_priority, utcb);
|
2016-04-20 21:12:57 +02:00
|
|
|
};
|
|
|
|
|
2020-02-05 08:44:51 +01:00
|
|
|
try {
|
|
|
|
_incr_weight(weight.value);
|
|
|
|
_thread_ep.apply(pd_cap, create_thread_lambda);
|
|
|
|
} catch (Allocator::Out_of_memory) {
|
|
|
|
_decr_weight(weight.value);
|
|
|
|
throw Out_of_ram();
|
|
|
|
} catch (Native_capability::Reference_count_overflow) {
|
|
|
|
_decr_weight(weight.value);
|
|
|
|
throw Thread_creation_failed();
|
|
|
|
} catch (...) {
|
|
|
|
_decr_weight(weight.value);
|
|
|
|
throw;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
thread->session_exception_sigh(_exception_sigh);
|
2013-01-10 10:04:18 +01:00
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
_thread_list.insert(thread);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
return thread->cap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Affinity::Location Cpu_session_component::_thread_affinity(Affinity::Location location) const
|
|
|
|
{
|
|
|
|
/* convert session-local location to physical location */
|
|
|
|
int const x1 = location.xpos() + _location.xpos(),
|
|
|
|
y1 = location.ypos() + _location.ypos(),
|
|
|
|
x2 = location.xpos() + location.width(),
|
|
|
|
y2 = location.ypos() + location.height();
|
|
|
|
|
|
|
|
int const clipped_x1 = max(_location.xpos(), x1),
|
|
|
|
clipped_y1 = max(_location.ypos(), y1),
|
|
|
|
clipped_x2 = max(_location.xpos() + (int)_location.width() - 1, x2),
|
|
|
|
clipped_y2 = max(_location.ypos() + (int)_location.height() - 1, y2);
|
|
|
|
|
|
|
|
return Affinity::Location(clipped_x1, clipped_y1,
|
|
|
|
clipped_x2 - clipped_x1 + 1,
|
|
|
|
clipped_y2 - clipped_y1 + 1);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-23 08:37:12 +02:00
|
|
|
void Cpu_session_component::_unsynchronized_kill_thread(Thread_capability thread_cap)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-04-20 21:12:57 +02:00
|
|
|
Cpu_thread_component *thread = 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
|
|
|
_thread_ep.apply(thread_cap, [&] (Cpu_thread_component *t) { thread = t; });
|
2015-09-23 08:37:12 +02:00
|
|
|
|
|
|
|
if (!thread) return;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
_thread_list.remove(thread);
|
|
|
|
|
2015-03-27 14:05:55 +01:00
|
|
|
_decr_weight(thread->weight());
|
2014-10-16 11:15:46 +02:00
|
|
|
|
2015-09-23 08:37:12 +02:00
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_alloc_lock);
|
2015-09-23 08:37:12 +02:00
|
|
|
destroy(&_thread_alloc, thread);
|
|
|
|
}
|
2020-01-31 15:50:34 +01:00
|
|
|
|
2020-05-05 14:27:29 +02:00
|
|
|
replenish(Ram_quota{_utcb_quota_size()});
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::kill_thread(Thread_capability thread_cap)
|
|
|
|
{
|
2017-06-08 10:54:49 +02:00
|
|
|
if (!thread_cap.valid())
|
|
|
|
return;
|
|
|
|
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_list_lock);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-06-08 10:54:49 +02:00
|
|
|
/* check that cap belongs to this session */
|
|
|
|
for (Cpu_thread_component *t = _thread_list.first(); t; t = t->next()) {
|
|
|
|
if (t->cap() == thread_cap) {
|
|
|
|
_unsynchronized_kill_thread(thread_cap);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
void Cpu_session_component::exception_sigh(Signal_context_capability sigh)
|
2012-11-12 17:48:18 +01:00
|
|
|
{
|
2016-05-10 18:05:38 +02:00
|
|
|
_exception_sigh = sigh;
|
2013-01-03 20:29:18 +01:00
|
|
|
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_list_lock);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
for (Cpu_thread_component *t = _thread_list.first(); t; t = t->next())
|
|
|
|
t->session_exception_sigh(_exception_sigh);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-07 22:16:58 +02:00
|
|
|
Affinity::Space Cpu_session_component::affinity_space() const
|
2012-09-04 17:32:55 +02:00
|
|
|
{
|
2013-08-08 14:44:00 +02:00
|
|
|
/*
|
|
|
|
* Return affinity subspace as constrained by the CPU session
|
|
|
|
* affinity.
|
|
|
|
*/
|
|
|
|
return Affinity::Space(_location.width(), _location.height());
|
2012-09-04 17:32:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-09 11:11:03 +02:00
|
|
|
Dataspace_capability Cpu_session_component::trace_control()
|
|
|
|
{
|
2013-08-10 03:44:55 +02:00
|
|
|
return _trace_control_area.dataspace();
|
2013-08-09 11:11:03 +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
|
|
|
void Cpu_session_component::_transfer_quota(Cpu_session_component &dst,
|
2015-03-27 14:05:55 +01:00
|
|
|
size_t const quota)
|
2014-10-16 11:15:46 +02:00
|
|
|
{
|
2015-03-27 14:05:55 +01:00
|
|
|
if (!quota) { return; }
|
|
|
|
_decr_quota(quota);
|
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
|
|
|
dst._incr_quota(quota);
|
2015-03-27 14:05:55 +01:00
|
|
|
}
|
2014-10-16 11:15:46 +02:00
|
|
|
|
|
|
|
|
2015-03-27 14:05:55 +01:00
|
|
|
int Cpu_session_component::transfer_quota(Cpu_session_capability dst_cap,
|
|
|
|
size_t amount)
|
|
|
|
{
|
|
|
|
/* lookup targeted CPU session */
|
2015-08-10 13:34:16 +02:00
|
|
|
auto lambda = [&] (Cpu_session_component *dst) {
|
|
|
|
if (!dst) {
|
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
|
|
|
warning("Transfer CPU quota, ", _label, ", targeted session not found");
|
2015-08-10 13:34:16 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* check reference relationship */
|
|
|
|
if (dst->_ref != this && dst != _ref) {
|
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
|
|
|
warning("Transfer CPU quota, ", _label, " -> ", dst->_label, ", "
|
|
|
|
"no reference relation");
|
2015-08-10 13:34:16 +02:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
/* check quota availability */
|
|
|
|
size_t const quota = quota_lim_downscale(_quota, amount);
|
|
|
|
if (quota > _quota) {
|
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
|
|
|
warning("Transfer CPU quota, ", _label, " -> ", dst->_label, ", "
|
|
|
|
"insufficient quota ", _quota, ", need ", quota);
|
2015-08-10 13:34:16 +02:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
/* transfer quota */
|
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
|
|
|
_transfer_quota(*dst, quota);
|
2015-08-10 13:34:16 +02:00
|
|
|
return 0;
|
|
|
|
};
|
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 _session_ep.apply(dst_cap, lambda);
|
2014-10-16 11:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-27 14:05:55 +01:00
|
|
|
int Cpu_session_component::ref_account(Cpu_session_capability ref_cap)
|
2014-10-16 11:15:46 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Ensure that the ref account is set only once
|
|
|
|
*
|
|
|
|
* FIXME Add check for cycles along the tree of reference accounts
|
|
|
|
*/
|
2015-03-27 14:05:55 +01:00
|
|
|
if (_ref) {
|
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
|
|
|
warning("set ref account, ", _label, ", set already");
|
2015-03-27 14:05:55 +01:00
|
|
|
return -2; }
|
|
|
|
|
|
|
|
/* lookup and check targeted CPU-session */
|
2015-08-10 13:34:16 +02:00
|
|
|
auto lambda = [&] (Cpu_session_component *ref) {
|
|
|
|
if (!ref) {
|
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
|
|
|
warning("set ref account, ", _label, ", targeted session not found");
|
2015-08-10 13:34:16 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (ref == this) {
|
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
|
|
|
warning("set ref account, ", _label, ", self reference not allowed");
|
2015-08-10 13:34:16 +02:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
/* establish ref-account relation from targeted CPU-session to us */
|
|
|
|
_ref = ref;
|
|
|
|
_ref->_insert_ref_member(this);
|
|
|
|
return 0;
|
|
|
|
};
|
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 _session_ep.apply(ref_cap, lambda);
|
2014-10-16 11:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-05 14:27:29 +02:00
|
|
|
Cpu_session_component::Cpu_session_component(Rpc_entrypoint &session_ep,
|
|
|
|
Resources const &resources,
|
|
|
|
Label const &label,
|
|
|
|
Diag const &diag,
|
|
|
|
Ram_allocator &ram_alloc,
|
2019-01-30 17:53:16 +01:00
|
|
|
Region_map &local_rm,
|
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
|
|
|
Rpc_entrypoint &thread_ep,
|
|
|
|
Pager_entrypoint &pager_ep,
|
2013-08-10 03:44:55 +02:00
|
|
|
Trace::Source_registry &trace_sources,
|
|
|
|
char const *args,
|
2014-10-16 11:15:46 +02:00
|
|
|
Affinity const &affinity,
|
2015-03-27 14:05:55 +01:00
|
|
|
size_t const quota)
|
2013-08-08 14:44:00 +02:00
|
|
|
:
|
2020-05-05 14:27:29 +02:00
|
|
|
Session_object(session_ep, resources, label, diag),
|
|
|
|
_session_ep(session_ep), _thread_ep(thread_ep), _pager_ep(pager_ep),
|
|
|
|
_ram_alloc(ram_alloc, _ram_quota_guard(), _cap_quota_guard()),
|
|
|
|
_md_alloc(_ram_alloc, local_rm),
|
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
|
|
|
_thread_alloc(_md_alloc), _priority(0),
|
2013-08-08 14:44:00 +02:00
|
|
|
|
|
|
|
/* map affinity to a location within the physical affinity space */
|
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
|
|
|
_location(affinity.scale_to(platform().affinity_space())),
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
_trace_sources(trace_sources),
|
2020-05-05 14:27:29 +02:00
|
|
|
_trace_control_area(_ram_alloc, local_rm),
|
2019-01-30 17:53:16 +01:00
|
|
|
_quota(quota), _ref(0),
|
2016-03-30 15:34:37 +02:00
|
|
|
_native_cpu(*this, args)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
Arg a = Arg_string::find_arg(args, "priority");
|
|
|
|
if (a.valid()) {
|
|
|
|
_priority = a.ulong_value(0);
|
|
|
|
|
|
|
|
/* clamp priority value to valid range */
|
|
|
|
_priority = min((unsigned)PRIORITY_LIMIT - 1, _priority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Cpu_session_component::~Cpu_session_component()
|
2014-10-16 11:15:46 +02:00
|
|
|
{
|
|
|
|
_deinit_threads();
|
|
|
|
_deinit_ref_account();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_deinit_ref_account()
|
|
|
|
{
|
2019-12-06 13:35:00 +01:00
|
|
|
/* rewire child ref accounts to this sessions's ref account */
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_ref_members_lock);
|
2019-12-06 13:35:00 +01:00
|
|
|
for (Cpu_session_component * s; (s = _ref_members.first()); ) {
|
|
|
|
_unsync_remove_ref_member(*s);
|
|
|
|
if (_ref)
|
|
|
|
_ref->_insert_ref_member(s);
|
|
|
|
}
|
|
|
|
}
|
2014-10-16 11:15:46 +02:00
|
|
|
|
2019-12-06 13:35:00 +01:00
|
|
|
if (_ref) {
|
|
|
|
/* give back our remaining quota to our ref account */
|
|
|
|
_transfer_quota(*_ref, _quota);
|
2014-10-16 11:15:46 +02:00
|
|
|
|
2019-12-06 13:35:00 +01:00
|
|
|
/* remove ref-account relation between us and our ref-account */
|
|
|
|
_ref->_remove_ref_member(*this);
|
2014-10-16 11:15:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_deinit_threads()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_list_lock);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to keep the '_thread_list_lock' during the whole destructor to
|
|
|
|
* prevent races with incoming calls of the 'create_thread' function,
|
|
|
|
* adding new threads while we are destroying them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (Cpu_thread_component *thread; (thread = _thread_list.first()); )
|
2015-09-23 08:37:12 +02:00
|
|
|
_unsynchronized_kill_thread(thread->cap());
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
|
2015-03-27 14:05:55 +01:00
|
|
|
void Cpu_session_component::
|
2016-05-10 18:05:38 +02:00
|
|
|
_update_thread_quota(Cpu_thread_component &thread) const
|
2014-10-16 11:15:46 +02:00
|
|
|
{
|
2016-05-10 18:05:38 +02:00
|
|
|
thread.quota(_weight_to_quota(thread.weight()));
|
2014-10-16 11:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-27 14:05:55 +01:00
|
|
|
void Cpu_session_component::_incr_weight(size_t const weight)
|
2014-10-16 11:15:46 +02:00
|
|
|
{
|
2015-03-27 14:05:55 +01:00
|
|
|
_weight += weight;
|
|
|
|
if (_quota) { _update_each_thread_quota(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_decr_weight(size_t const weight)
|
|
|
|
{
|
|
|
|
_weight -= weight;
|
|
|
|
if (_quota) { _update_each_thread_quota(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_decr_quota(size_t const quota)
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_list_lock);
|
2015-03-27 14:05:55 +01:00
|
|
|
_quota -= quota;
|
|
|
|
_update_each_thread_quota();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_incr_quota(size_t const quota)
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard lock_guard(_thread_list_lock);
|
2015-03-27 14:05:55 +01:00
|
|
|
_quota += quota;
|
|
|
|
_update_each_thread_quota();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_session_component::_update_each_thread_quota()
|
|
|
|
{
|
|
|
|
Cpu_thread_component * thread = _thread_list.first();
|
2016-05-10 18:05:38 +02:00
|
|
|
for (; thread; thread = thread->next()) { _update_thread_quota(*thread); }
|
2014-10-16 11:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-05 08:44:51 +01:00
|
|
|
size_t Cpu_session_component::_weight_to_quota(size_t const weight) const
|
|
|
|
{
|
|
|
|
if (_weight == 0) return 0;
|
|
|
|
|
|
|
|
return (weight * _quota) / _weight;
|
|
|
|
}
|
2014-10-16 11:15:46 +02:00
|
|
|
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
/****************************
|
|
|
|
** Trace::Source_registry **
|
|
|
|
****************************/
|
|
|
|
|
|
|
|
unsigned Trace::Source::_alloc_unique_id()
|
|
|
|
{
|
2020-02-18 15:29:47 +01:00
|
|
|
static Mutex lock;
|
2013-08-10 03:44:55 +02:00
|
|
|
static unsigned cnt;
|
2020-02-18 15:29:47 +01:00
|
|
|
Mutex::Guard guard(lock);
|
2013-08-10 03:44:55 +02:00
|
|
|
return cnt++;
|
|
|
|
}
|
|
|
|
|