2014-10-10 16:13:52 +02:00
|
|
|
/*
|
|
|
|
* \brief Class for kernel data that is needed to manage a specific CPU
|
|
|
|
* \author Martin Stein
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2014-01-14
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-10-10 16:13:52 +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.
|
2014-10-10 16:13:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <kernel/cpu.h>
|
|
|
|
#include <kernel/kernel.h>
|
|
|
|
#include <kernel/thread.h>
|
|
|
|
#include <kernel/irq.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <kernel/pd.h>
|
2014-10-10 16:13:52 +02:00
|
|
|
#include <pic.h>
|
2017-02-21 13:46:59 +01:00
|
|
|
#include <hw/assert.h>
|
2018-11-26 11:18:57 +01:00
|
|
|
#include <hw/boot_info.h>
|
2014-10-10 16:13:52 +02:00
|
|
|
|
2016-01-20 18:27:18 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/unmanaged_singleton.h>
|
2014-10-10 16:13:52 +02:00
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
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
|
|
|
Kernel::Cpu_pool &Kernel::cpu_pool() { return *unmanaged_singleton<Cpu_pool>(); }
|
2014-10-10 16:13:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*************
|
|
|
|
** Cpu_job **
|
|
|
|
*************/
|
|
|
|
|
2016-05-18 12:20:04 +02:00
|
|
|
time_t Cpu_job::timeout_age_us(Timeout const * const timeout) const
|
|
|
|
{
|
|
|
|
return _cpu->timeout_age_us(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
os/timer: interpolate time via timestamps
Previously, the Genode::Timer::curr_time always used the
Timer_session::elapsed_ms RPC as back end. Now, Genode::Timer reads
this remote time only in a periodic fashion independently from the calls
to Genode::Timer::curr_time. If now one calls Genode::Timer::curr_time,
the function takes the last read remote time value and adapts it using
the timestamp difference since the remote-time read. The conversion
factor from timestamps to time is estimated on every remote-time read
using the last read remote-time value and the timestamp difference since
the last remote time read.
This commit also re-works the timeout test. The test now has two stages.
In the first stage, it tests fast polling of the
Genode::Timer::curr_time. This stage checks the error between locally
interpolated and timer-driver time as well as wether the locally
interpolated time is monotone and sufficiently homogeneous. In the
second stage several periodic and one-shot timeouts are scheduled at
once. This stage checks if the timeouts trigger sufficiently precise.
This commit adds the new Kernel::time syscall to base-hw. The syscall is
solely used by the Genode::Timer on base-hw as substitute for the
timestamp. This is because on ARM, the timestamp function uses the ARM
performance counter that stops counting when the WFI (wait for
interrupt) instruction is active. This instruction, however is used by
the base-hw idle contexts that get active when no user thread needs to
be scheduled. Thus, the ARM performance counter is not a good choice for
time interpolation and we use the kernel internal time instead.
With this commit, the timeout library becomes a basic library. That means
that it is linked against the LDSO which then provides it to the program it
serves. Furthermore, you can't use the timeout library anymore without the
LDSO because through the kernel-dependent LDSO make-files we can achieve a
kernel-dependent timeout implementation.
This commit introduces a structured Duration type that shall successively
replace the use of Microseconds, Milliseconds, and integer types for duration
values.
Open issues:
* The timeout test fails on Raspberry PI because of precision errors in the
first stage. However, this does not render the framework unusable in general
on the RPI but merely is an issue when speaking of microseconds precision.
* If we run on ARM with another Kernel than HW the timestamp speed may
continuously vary from almost 0 up to CPU speed. The Timer, however,
only uses interpolation if the timestamp speed remained stable (12.5%
tolerance) for at least 3 observation periods. Currently, one period is
100ms, so its 300ms. As long as this is not the case,
Timer_session::elapsed_ms is called instead.
Anyway, it might happen that the CPU load was stable for some time so
interpolation becomes active and now the timestamp speed drops. In the
worst case, we would now have 100ms of slowed down time. The bad thing
about it would be, that this also affects the timeout of the period.
Thus, it might "freeze" the local time for more than 100ms.
On the other hand, if the timestamp speed suddenly raises after some
stable time, interpolated time can get too fast. This would shorten the
period but nonetheless may result in drifting away into the far future.
Now we would have the problem that we can't deliver the real time
anymore until it has caught up because the output of Timer::curr_time
shall be monotone. So, effectively local time might "freeze" again for
more than 100ms.
It would be a solution to not use the Trace::timestamp on ARM w/o HW but
a function whose return value causes the Timer to never use
interpolation because of its stability policy.
Fixes #2400
2017-04-22 00:52:23 +02:00
|
|
|
time_t Cpu_job::time() const { return _cpu->time(); }
|
|
|
|
|
|
|
|
|
2016-05-18 12:20:04 +02:00
|
|
|
time_t Cpu_job::timeout_max_us() const
|
|
|
|
{
|
|
|
|
return _cpu->timeout_max_us();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_job::timeout(Timeout * const timeout, time_t const us)
|
|
|
|
{
|
|
|
|
_cpu->set_timeout(timeout, us);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 15:10:33 +01:00
|
|
|
void Cpu_job::_activate_own_share() { _cpu->schedule(this); }
|
2014-10-10 16:13:52 +02:00
|
|
|
|
|
|
|
|
2014-12-01 15:10:33 +01:00
|
|
|
void Cpu_job::_deactivate_own_share()
|
2014-10-10 16:13:52 +02:00
|
|
|
{
|
|
|
|
assert(_cpu->id() == Cpu::executing_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
|
|
|
_cpu->scheduler().unready(this);
|
2014-10-10 16:13:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cpu_job::_yield()
|
|
|
|
{
|
|
|
|
assert(_cpu->id() == Cpu::executing_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
|
|
|
_cpu->scheduler().yield();
|
2014-10-10 16:13:52 +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 Cpu_job::_interrupt(unsigned const /* cpu_id */)
|
2014-10-10 16:13:52 +02:00
|
|
|
{
|
|
|
|
/* determine handling for specific interrupt */
|
|
|
|
unsigned irq_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
|
|
|
if (pic().take_request(irq_id))
|
2014-10-10 16:13:52 +02:00
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
/* is the interrupt a cpu-local one */
|
|
|
|
if (!_cpu->interrupt(irq_id)) {
|
2014-10-10 16:13:52 +02:00
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
/* it needs to be a user interrupt */
|
|
|
|
User_irq * irq = User_irq::object(irq_id);
|
|
|
|
if (irq) irq->occurred();
|
2016-10-10 16:22:43 +02:00
|
|
|
else Genode::warning("Unknown interrupt ", irq_id);
|
2014-10-10 16:13:52 +02:00
|
|
|
}
|
2015-02-18 14:23:54 +01:00
|
|
|
|
2014-10-10 16:13:52 +02:00
|
|
|
/* end interrupt request at controller */
|
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
|
|
|
pic().finish_request();
|
2014-10-10 16:13:52 +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_job::affinity(Cpu &cpu)
|
2014-10-10 16:13:52 +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
|
|
|
_cpu = &cpu;
|
|
|
|
_cpu->scheduler().insert(this);
|
2014-10-10 16:13:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-20 09:22:02 +01:00
|
|
|
void Cpu_job::quota(unsigned const q)
|
|
|
|
{
|
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 (_cpu) { _cpu->scheduler().quota(this, q); }
|
2015-03-20 09:22:02 +01:00
|
|
|
else { Cpu_share::quota(q); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
Cpu_job::Cpu_job(Cpu_priority const p, unsigned const q)
|
2016-05-18 12:20:04 +02:00
|
|
|
:
|
|
|
|
Cpu_share(p, q), _cpu(0) { }
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
Cpu_job::~Cpu_job()
|
|
|
|
{
|
|
|
|
if (!_cpu) { return; }
|
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
|
|
|
_cpu->scheduler().remove(this);
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 16:13:52 +02:00
|
|
|
/*********
|
|
|
|
** Cpu **
|
|
|
|
*********/
|
|
|
|
|
2017-10-05 16:11:24 +02:00
|
|
|
extern "C" void idle_thread_main(void);
|
|
|
|
|
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
|
|
|
Cpu::Idle_thread::Idle_thread(Cpu &cpu)
|
2017-10-05 16:11:24 +02:00
|
|
|
: Thread("idle")
|
|
|
|
{
|
|
|
|
regs->ip = (addr_t)&idle_thread_main;
|
|
|
|
|
|
|
|
affinity(cpu);
|
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::_pd = &core_pd();
|
2017-10-05 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-18 12:20:04 +02:00
|
|
|
void Cpu::set_timeout(Timeout * const timeout, time_t const duration_us) {
|
2017-03-23 03:06:53 +01:00
|
|
|
_timer.set_timeout(timeout, _timer.us_to_ticks(duration_us)); }
|
2016-05-18 12:20:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
time_t Cpu::timeout_age_us(Timeout const * const timeout) const {
|
2017-03-23 03:06:53 +01:00
|
|
|
return _timer.timeout_age_us(timeout); }
|
2016-05-18 12:20:04 +02:00
|
|
|
|
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
time_t Cpu::timeout_max_us() const { return _timer.timeout_max_us(); }
|
2016-05-18 12:20:04 +02:00
|
|
|
|
|
|
|
|
2014-10-10 16:13:52 +02:00
|
|
|
void Cpu::schedule(Job * const job)
|
|
|
|
{
|
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
|
|
|
if (_id == executing_id()) { _scheduler.ready(&job->share()); }
|
|
|
|
else if (_scheduler.ready_check(&job->share())) { trigger_ip_interrupt(); }
|
2014-10-10 16:13:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
bool Cpu::interrupt(unsigned const irq_id)
|
|
|
|
{
|
|
|
|
Irq * const irq = object(irq_id);
|
|
|
|
if (!irq) return false;
|
|
|
|
irq->occurred();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-09 12:02:00 +01:00
|
|
|
Cpu_job & Cpu::schedule()
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
|
|
|
/* update scheduler */
|
2016-05-18 12:20:04 +02:00
|
|
|
Job & old_job = scheduled_job();
|
2017-10-06 12:02:36 +02:00
|
|
|
old_job.exception(*this);
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2019-02-20 15:26:56 +01:00
|
|
|
if (_scheduler.need_to_schedule()) {
|
|
|
|
time_t quota = _timer.update_time();
|
|
|
|
_timer.process_timeouts();
|
|
|
|
_scheduler.update(quota);
|
|
|
|
quota = _scheduler.head_quota();
|
|
|
|
_timer.set_timeout(this, quota);
|
|
|
|
_timer.schedule_timeout();
|
|
|
|
}
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2015-12-09 12:02:00 +01:00
|
|
|
/* return new job */
|
2019-02-20 15:26:56 +01:00
|
|
|
return scheduled_job();
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-06 12:02:36 +02:00
|
|
|
Genode::size_t kernel_stack_size = Cpu::KERNEL_STACK_SIZE;
|
|
|
|
Genode::uint8_t kernel_stack[NR_OF_CPUS][Cpu::KERNEL_STACK_SIZE]
|
|
|
|
__attribute__((aligned(Genode::get_page_size())));
|
|
|
|
|
|
|
|
|
|
|
|
addr_t Cpu::stack_start() {
|
|
|
|
return (addr_t)&kernel_stack + KERNEL_STACK_SIZE * (_id+1); }
|
|
|
|
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu::Cpu(unsigned const id, Pic & pic,
|
|
|
|
Inter_processor_work_list & global_work_list)
|
2016-05-18 12:20:04 +02:00
|
|
|
:
|
2019-02-20 15:26:56 +01:00
|
|
|
_id(id), _pic(pic), _timer(*this),
|
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
|
|
|
_scheduler(&_idle, _quota(), _fill()), _idle(*this),
|
2019-02-20 15:26:56 +01:00
|
|
|
_ipi_irq(*this),
|
2018-11-26 11:18:57 +01:00
|
|
|
_global_work_list(global_work_list)
|
|
|
|
{ _arch_init(); }
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**************
|
|
|
|
** Cpu_pool **
|
|
|
|
**************/
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
bool Cpu_pool::initialize(Pic & pic)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2018-11-26 11:18:57 +01:00
|
|
|
unsigned id = Cpu::executing_id();
|
|
|
|
_cpus[id].construct(id, pic, _global_work_list);
|
|
|
|
return --_initialized == 0;
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu & Cpu_pool::cpu(unsigned const id)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2018-11-26 11:18:57 +01:00
|
|
|
assert(id < _count && _cpus[id].constructed());
|
|
|
|
return *_cpus[id];
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu_pool::Cpu_pool()
|
|
|
|
: _count(reinterpret_cast<Hw::Boot_info*>(Hw::Mm::boot_info().base)->cpus) { }
|