2013-12-17 18:10:02 +01:00
|
|
|
/*
|
2014-10-10 16:13:52 +02:00
|
|
|
* \brief Class for kernel data that is needed to manage a specific CPU
|
2013-12-17 18:10:02 +01:00
|
|
|
* \author Martin Stein
|
hw: restrict processor broadcast to TLB flushing
Removes the generic processor broadcast function call. By now, that call
was used for cross processor TLB maintance operations only. When core/kernel
gets its memory mapped on demand, and unmapped again, the previous cross
processor flush routine doesn't work anymore, because of a hen-egg problem.
The previous cross processor broadcast is realized using a thread constructed
by core running on top of each processor core. When constructing threads in
core, a dataspace for its thread context is constructed. Each constructed
RAM dataspace gets attached, zeroed out, and detached again. The detach
routine requires a TLB flush operation executed on each processor core.
Instead of executing a thread on each processor core, now a thread waiting
for a global TLB flush is removed from the scheduler queue, and gets attached
to a TLB flush queue of each processor. The processor local queue gets checked
whenever the kernel is entered. The last processor, which executed the TLB
flush, re-attaches the blocked thread to its scheduler queue again.
To ease uo the above described mechanism, a platform thread is now directly
associated with a platform pd object, instead of just associate it with the
kernel pd's id.
Ref #723
2014-04-28 20:36:00 +02:00
|
|
|
* \author Stefan Kalkowski
|
2013-12-17 18:10:02 +01:00
|
|
|
* \date 2014-01-14
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2013-12-17 18:10:02 +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.
|
2013-12-17 18:10:02 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#ifndef _CORE__KERNEL__CPU_H_
|
|
|
|
#define _CORE__KERNEL__CPU_H_
|
2013-12-17 18:10:02 +01:00
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
#include <util/reconstructible.h>
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
/* core includes */
|
2019-07-10 13:30:54 +02:00
|
|
|
#include <board.h>
|
2019-09-26 14:24:28 +02:00
|
|
|
#include "cpu_context.h"
|
|
|
|
#include "irq.h"
|
|
|
|
#include "inter_processor_work.h"
|
|
|
|
#include "thread.h"
|
2014-08-21 15:14:26 +02:00
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
namespace Kernel
|
|
|
|
{
|
|
|
|
/**
|
2014-10-10 16:13:52 +02:00
|
|
|
* Class for kernel data that is needed to manage a specific CPU
|
2013-12-17 18:10:02 +01:00
|
|
|
*/
|
2014-10-10 16:13:52 +02:00
|
|
|
class Cpu;
|
2014-08-21 15:14:26 +02:00
|
|
|
|
|
|
|
/**
|
2014-10-10 16:13:52 +02:00
|
|
|
* Provides a CPU object for every available CPU
|
2014-08-21 15:14:26 +02:00
|
|
|
*/
|
2014-10-10 16:13:52 +02:00
|
|
|
class Cpu_pool;
|
2014-08-21 15:14:26 +02:00
|
|
|
|
|
|
|
/**
|
2014-10-10 16:13:52 +02:00
|
|
|
* Return singleton of CPU pool
|
2014-08-21 15:14:26 +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_pool &cpu_pool();
|
2013-12-17 18:10:02 +01: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
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'Cpu' class violates the "Effective C++" practices because it publicly
|
|
|
|
* inherits the 'Genode::Cpu' base class, which does not have a virtual
|
|
|
|
* destructor. Since 'Cpu' implements the 'Timeout' interface, however, it has
|
|
|
|
* a vtable.
|
|
|
|
*
|
|
|
|
* Adding a virtual destructor in the base class would be unnatural as the base
|
|
|
|
* class hierarchy does not represent an abstract interface.
|
|
|
|
*
|
|
|
|
* Inheriting the 'Genode::Cpu' class privately is not an option because the
|
|
|
|
* user of 'Cpu' class expects architecture-specific register definitions to be
|
|
|
|
* provided by 'Cpu'. Hence, all those architecture- specific definitions would
|
|
|
|
* end up as 'using' clauses in the generic class.
|
|
|
|
*
|
|
|
|
* XXX Remove the disabled warning, e.g., by one of the following approaches:
|
|
|
|
*
|
|
|
|
* * Prevent 'Cpu' to have virtual methods by making 'Timeout' a member instead
|
|
|
|
* of a base class.
|
|
|
|
*
|
|
|
|
* * Change the class hierarchy behind 'Genode::Cpu' such that
|
|
|
|
* architecture-specific bits do no longer need to implicitly become part
|
|
|
|
* of the public interface of 'Cpu'. For example, register-definition types
|
|
|
|
* could all be embedded in an 'Arch_regs' type, which the 'Cpu' class could
|
|
|
|
* publicly provide via a 'typedef Genode::Cpu::Arch_regs Arch_regs'.
|
|
|
|
* Then, the 'Genode::Cpu' could be inherited privately.
|
|
|
|
*/
|
2019-09-26 12:36:05 +02:00
|
|
|
#pragma GCC diagnostic push
|
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
|
|
|
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
|
|
|
|
|
|
|
class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
|
2013-12-17 18:10:02 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2014-10-09 14:24:27 +02:00
|
|
|
typedef Cpu_job Job;
|
2014-05-21 15:52:05 +02:00
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
/**
|
|
|
|
* Inter-processor-interrupt object of the cpu
|
|
|
|
*/
|
|
|
|
struct Ipi : Irq
|
|
|
|
{
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu & cpu;
|
|
|
|
bool pending { false };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param cpu cpu this IPI belongs to
|
|
|
|
*/
|
|
|
|
Ipi(Cpu & cpu);
|
2015-02-18 14:23:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
** Irq interface **
|
|
|
|
*********************/
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void occurred() override;
|
2015-02-18 14:23:54 +01:00
|
|
|
};
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
friend void Ipi::occurred(void);
|
2017-10-05 16:11:24 +02:00
|
|
|
|
|
|
|
struct Idle_thread : Kernel::Thread
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Construct idle context for CPU '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
|
|
|
Idle_thread(Cpu &cpu);
|
2017-10-05 16:11:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-09 14:24:27 +02:00
|
|
|
unsigned const _id;
|
2019-07-10 13:30:54 +02:00
|
|
|
Board::Pic &_pic;
|
2017-03-23 03:06:53 +01:00
|
|
|
Timer _timer;
|
2014-10-09 14:24:27 +02:00
|
|
|
Cpu_scheduler _scheduler;
|
2017-10-05 16:11:24 +02:00
|
|
|
Idle_thread _idle;
|
2015-12-09 12:02:00 +01:00
|
|
|
Ipi _ipi_irq;
|
2014-06-20 17:44:09 +02:00
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
Inter_processor_work_list &_global_work_list;
|
|
|
|
Inter_processor_work_list _local_work_list {};
|
|
|
|
|
|
|
|
void _arch_init();
|
2017-03-23 03:06:53 +01:00
|
|
|
unsigned _quota() const { return _timer.us_to_ticks(cpu_quota_us); }
|
|
|
|
unsigned _fill() const { return _timer.us_to_ticks(cpu_fill_us); }
|
2013-12-17 18:10:02 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-06-30 12:00:27 +02:00
|
|
|
enum { KERNEL_STACK_SIZE = 16 * 1024 * sizeof(Genode::addr_t) };
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
/**
|
2017-03-23 03:06:53 +01:00
|
|
|
* Construct object for CPU 'id'
|
2013-12-17 18:10:02 +01:00
|
|
|
*/
|
2019-07-10 13:30:54 +02:00
|
|
|
Cpu(unsigned const id, Board::Pic & pic,
|
2018-11-26 11:18:57 +01:00
|
|
|
Inter_processor_work_list & global_work_list);
|
2015-12-09 12:02:00 +01:00
|
|
|
|
2019-03-22 14:23:07 +01:00
|
|
|
static inline unsigned primary_id() { return 0; }
|
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Raise the IPI of the CPU
|
2014-04-28 21:31:57 +02:00
|
|
|
*/
|
2018-11-26 11:18:57 +01:00
|
|
|
void trigger_ip_interrupt();
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2014-03-11 12:53:42 +01:00
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Deliver interrupt to the CPU
|
|
|
|
*
|
|
|
|
* \param irq_id id of the interrupt that occured
|
|
|
|
* \returns true if the interrupt belongs to this CPU, otherwise false
|
2014-03-11 12:53:42 +01:00
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
bool interrupt(unsigned const irq_id);
|
2014-03-11 12:53:42 +01:00
|
|
|
|
|
|
|
/**
|
2014-10-09 14:24:27 +02:00
|
|
|
* Schedule 'job' at this CPU
|
2014-03-11 12:53:42 +01:00
|
|
|
*/
|
2014-10-09 14:24:27 +02:00
|
|
|
void schedule(Job * const job);
|
2014-03-11 12:53:42 +01:00
|
|
|
|
2014-05-21 15:52:05 +02:00
|
|
|
/**
|
2015-12-09 12:02:00 +01:00
|
|
|
* Return the job that should be executed at next
|
2014-05-21 15:52:05 +02:00
|
|
|
*/
|
2015-12-09 12:02:00 +01:00
|
|
|
Cpu_job& schedule();
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2019-07-10 13:30:54 +02:00
|
|
|
Board::Pic & pic() { return _pic; }
|
|
|
|
Timer & timer() { return _timer; }
|
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
|
|
|
|
2017-10-06 12:02:36 +02:00
|
|
|
addr_t stack_start();
|
2013-12-17 18:10:02 +01:00
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
/**
|
|
|
|
* Returns the currently active job
|
|
|
|
*/
|
2015-12-09 12:02:00 +01:00
|
|
|
Job & scheduled_job() const {
|
|
|
|
return *static_cast<Job *>(_scheduler.head())->helping_sink(); }
|
2015-02-18 14:23:54 +01:00
|
|
|
|
2014-03-06 13:55:56 +01:00
|
|
|
unsigned id() const { return _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 &scheduler() { return _scheduler; }
|
2017-03-23 03:06:53 +01: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
|
|
|
Irq::Pool &irq_pool() { return *this; }
|
2018-11-26 11:18:57 +01:00
|
|
|
|
|
|
|
Inter_processor_work_list & work_list() {
|
|
|
|
return _local_work_list; }
|
2013-12-17 18:10:02 +01: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
|
|
|
|
|
|
|
/*
|
|
|
|
* See the comment above the 'Cpu' class definition.
|
|
|
|
*/
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
|
2014-10-10 16:13:52 +02:00
|
|
|
class Kernel::Cpu_pool
|
2014-08-21 15:14:26 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-07-10 13:30:54 +02:00
|
|
|
Board::Pic _pic {};
|
2018-11-26 11:18:57 +01:00
|
|
|
Inter_processor_work_list _global_work_list {};
|
|
|
|
unsigned _count;
|
|
|
|
unsigned _initialized { _count };
|
|
|
|
Genode::Constructible<Cpu> _cpus[NR_OF_CPUS];
|
2014-08-21 15:14:26 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
Cpu_pool();
|
2014-08-21 15:14:26 +02:00
|
|
|
|
2019-07-10 13:30:54 +02:00
|
|
|
bool initialize();
|
2018-11-26 11:18:57 +01:00
|
|
|
|
2014-08-21 15:14:26 +02:00
|
|
|
/**
|
2014-10-10 16:13:52 +02:00
|
|
|
* Return object of CPU 'id'
|
2014-08-21 15:14:26 +02:00
|
|
|
*/
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu & cpu(unsigned const id);
|
2014-08-21 15:14:26 +02:00
|
|
|
|
|
|
|
/**
|
2014-10-10 16:13:52 +02:00
|
|
|
* Return object of primary CPU
|
2014-08-21 15:14:26 +02:00
|
|
|
*/
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu & primary_cpu() { return cpu(Cpu::primary_id()); }
|
2014-10-16 11:15:46 +02:00
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
/**
|
|
|
|
* Return object of current CPU
|
|
|
|
*/
|
2018-11-26 11:18:57 +01:00
|
|
|
Cpu & executing_cpu() { return cpu(Cpu::executing_id()); }
|
2015-02-18 14:23:54 +01:00
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
template <typename FUNC>
|
2018-11-26 11:18:57 +01:00
|
|
|
void for_each_cpu(FUNC const &func)
|
2017-03-23 03:06:53 +01:00
|
|
|
{
|
2018-11-26 11:18:57 +01:00
|
|
|
for (unsigned i = 0; i < _count; i++) func(cpu(i));
|
2017-03-23 03:06:53 +01:00
|
|
|
}
|
2018-11-26 11:18:57 +01:00
|
|
|
|
|
|
|
Inter_processor_work_list & work_list() {
|
|
|
|
return _global_work_list; }
|
2014-08-21 15:14:26 +02:00
|
|
|
};
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#endif /* _CORE__KERNEL__CPU_H_ */
|