Commit Graph

34845 Commits

Author SHA1 Message Date
Sebastian Huber
6d20f0c525 score: Add node to insert to Chain_Node_order
This allows to use additional members of the nodes for comparision.

Update #4534.
2021-11-23 11:00:28 +01:00
Sebastian Huber
ff20bc9816 score: Rework idle handling in SMP schedulers
This patch fixes an issue with the idle thread handling in the SMP
scheduler framework used for the MrsP locking protocol.  The approach to
use a simple chain of unused idle threads is broken for schedulers which
support thread to processor affinity.  The reason is that the thread to
processor affinity introduces another ordering indicator which may under
certain conditions lead to a reordering of idle threads in the scheduled
chain.  This reordering is not propagated to the chain of unused idle
threads.  This could lead to use an idle thread for a sticky scheduler
node which is already in use.  This locks up the system in infinite
loops in the thread context switch procedure.

To fix this, the SMP scheduler implementations must now provide
callbacks to get and release an unused idle thread.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
3d6ebde1ac score: Add SMP scheduler make/clean sticky
This patch fixes the following broken behaviour:

  While a thread is scheduled on a helping scheduler, while it does not
  own a MrsP semaphore, if it obtains a MrsP semaphore, then no
  scheduler node using an idle thread and the ceiling priority of the
  semaphore is unblocked for the home scheduler.

This could lead to priority inversion issues and is not in line
with the MrsP protocol.

Introduce two new scheduler operations which are only enabled if
RTEMS_SMP is defined.  The operations are used to make the scheduler
node of the home scheduler sticky and to clean the sticky property.
This helps to keep the sticky handing out of the frequently used
priority update operation.

Close #4532.
2021-11-23 11:00:28 +01:00
Sebastian Huber
3781709f28 score: Add SMP scheduler idle exchange callback
Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
75527ef386 score: Optimize SMP EDF move to ready operation
If a node is moved from the scheduled chain to the ready queue, then we
know that it is the highest priority ready node.  So, it can be
prepended to the ready queue without doing any comparisons.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
9d3e821279 score: Rework affine ready queue handling
Rework the handling of the affine ready queue for the EDF SMP scheduler.
Do the queue handling in the node insert, move, and extract operations.
Remove the queue handling from _Scheduler_EDF_SMP_Allocate_processor().

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
a53229bbb6 score: Use extract from scheduled callbacks
Use the extract from scheduled callback provided by the scheduler
implementation in the SMP scheduler framework.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
757a10964f score: Remove return value from enqueue scheduled
The return value was unused.  Remove it.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
6286a40aa3 score: Scheduler insert after move
Insert nodes after moving the second node to reduce the items in the
data structure for the insert operation.  This also avoids having two
nodes for the same processor inserted into the scheduled chain.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
81659420b0 score: Add missing idle thread exchanges
Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
e787091764 score: Add missing idle thread releases
Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
bd55f69f5b score: Simplify _Scheduler_Exchange_idle_thread()
Remove superfluous idle parameter.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
f0f60a1ec3 score: Change _Scheduler_Try_to_schedule_node()
Add the victim node as parameter instead of the idle thread.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
7ae4f56929 score: Not set CPU in _Scheduler_Use_idle_thread()
Do not set the CPU of the idle thread in _Scheduler_Use_idle_thread().  This
helps to use _Scheduler_Try_to_schedule_node() under more general conditions in
the future, for example in case the owner and user of a node are not the same.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
45e942d1ae score: Rename _Scheduler_Set_idle_thread()
Rename _Scheduler_Set_idle_thread() in _Scheduler_Node_set_idle_user() and move
it to <rtems/score/schedulernodeimpl.h>.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
577262a737 score: Add red-black tree append/prepend
These functions are a faster alternative to _RBTree_Insert_inline() if
it is known that the new node is the maximum/minimum node.

Update #4531.
2021-11-23 11:00:28 +01:00
Sebastian Huber
3c0760414e score: Simplify _Scheduler_Generic_block()
If we block the executing thread and it is not the heir thread, then there is
no need to run the schedule operation.  The scheduler already selected a new
heir.
2021-11-23 11:00:28 +01:00
Kinsey Moore
1eb266bb0b cpukit: Consistize OAR copyright headers
These two OAR copyright headers are the only two in the codebase with
a format that differs from the typical OAR copyright header. This makes
all of the OAR copyright headers consistent.
2021-11-22 15:51:40 -06:00
Kinsey Moore
50cf19320d cpukit: Enable debug for SMP AArch64
Ensure when both RTEMS_DEBUG is specified and pointers are large that
enough space is allocated to accomodate the Per_CPU_Control structure.
This changes the calculation to be more compositional instead of trying
to list out every permutation of options possible.
2021-11-22 15:51:40 -06:00
Sebastian Huber
18484f02ad rtems: Add external functions
These external functions rtems_scheduler_get_processor() and
rtems_scheduler_get_processor_maximum() which may be used by bindings
for languages other than C/C++.
2021-11-18 20:06:17 +01:00
Sebastian Huber
9b6362da71 rtems: Use RTEMS_WHO_AM_I for rtems_task_ident() 2021-11-18 19:59:14 +01:00
Sebastian Huber
99fdfcdd87 rtems: Add signal header to implementation group 2021-11-17 20:10:05 +01:00
Sebastian Huber
c47daf6f68 config: Fix IO driver table initialization
Check all IO driver table configuration options which are used to initialize
_IO_Driver_address_table[].  Checks for the following settings were missing:

* CONFIGURE_BSP_PREREQUISITE_DRIVERS

* CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS

* CONFIGURE_APPLICATION_NEEDS_WATCHDOG_DRIVER

* CONFIGURE_APPLICATION_EXTRA_DRIVERS

Update #3875.
2021-11-17 09:16:17 +01:00
Sebastian Huber
32cee88357 config: CONFIGURE_DISABLE_BSP_SETTINGS
Evaluate CONFIGURE_DISABLE_BSP_SETTINGS for each affected application
configuration option.  This makes the code easier to review since the influence
of CONFIGURE_DISABLE_BSP_SETTINGS is locally visible in the code.

Update #3875.
2021-11-17 09:16:17 +01:00
Sebastian Huber
c1395ca056 build: Add --rtems-version command line option
Update #4548.
2021-11-17 09:16:13 +01:00
Sebastian Huber
f06dd3e176 build: Optional __RTEMS_MAJOR__ via command line
Update #4548.
2021-11-16 07:46:45 +01:00
Sebastian Huber
a0650f5f32 build: Support command line specified options
Update #4548.
2021-11-16 07:46:16 +01:00
Sebastian Huber
9551f340d0 Revert "optvermaj.yml: Allow __RTEMS_MAJOR__ to be overridden so RTEMS 7 tools can be tested"
This reverts commit d1bbfbea5f.
2021-11-15 11:14:12 +01:00
Sebastian Huber
ccbcfb679d rtems: Add new clock manager directives
Update #4527.
2021-11-15 11:14:12 +01:00
Sebastian Huber
1b5db7926b rtems: Simplify rtems_semaphore_set_priority()
Do not write to the object referenced by old_priority in error paths.
This is in line with other directives.
2021-11-15 11:14:12 +01:00
Sebastian Huber
ee57a7f1a1 score: Fix _CORE_ceiling_mutex_Set_priority()
We have to use a second thread queue context to acquire and release the
thread wait lock.

Close #4356.
2021-11-15 09:53:17 +01:00
Sebastian Huber
16b50ac63c score: Always check if a prio ceiling is defined
Priority ceiling semaphores (in contrast to MrsP semaphores) have only
one priority ceiling which is defined for the home scheduler of the task
which created the semaphore.  Always check during a semaphore seize that
the home scheduler of the calling task is equal to this scheduler.

This avoids a scheduler mismatch if the semphore is acquired after the
calling thread blocked on the semaphore.
2021-11-15 09:53:17 +01:00
Sebastian Huber
7a591d0cd4 score: Fix thread pinning assertions 2021-11-15 09:53:17 +01:00
Sebastian Huber
ffb8833dd2 score: Add _Timecounter_Set_NTP_update_second()
Allow the installation of an NTP update second handler which may be used by an
NTP service.

Update #2348.
2021-11-15 08:56:54 +01:00
Sebastian Huber
b936ce5a8c score: Optimize timehand updates for non-SMP
In uniprocessor configurations, the timehand updates are done with
interrupts disabled.  So, it is impossible to observe a generation
number of zero.
2021-11-15 08:56:54 +01:00
Sebastian Huber
52c53a5914 score: Port large time delta support to RTEMS 2021-11-15 08:56:54 +01:00
Sebastian Huber
b88d9cb3e1 score: Initialize timehand generation to UINT_MAX
This leads to a timehand generation overflow right at the system start
and helps to get code coverage in test programs.
2021-11-15 08:56:54 +01:00
Mark Johnston
c3a68059d8 timecounter: Load the currently selected tc once in tc_windup()
Reported by:	Sebastian Huber <sebastian.huber@embedded-brains.de>
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32729
2021-11-15 08:56:54 +01:00
Sebastian Huber
346755874b kern_tc.c: Scaling/large delta recalculation
This change is a slight performance optimization for systems with a slow
64-bit division.

The th->th_scale and th->th_large_delta values only depend on the
timecounter frequency and the th->th_adjustment. The timecounter
frequency of a timehand only changes when a new timecounter is activated
for the timehand. The th->th_adjustment is only changed by the NTP
second update. The NTP second update is not done for every call of
tc_windup().

Move the code block to recalculate the scaling factor and
the large delta of a timehand to the new helper function
recalculate_scaling_factor_and_large_delta().

Call recalculate_scaling_factor_and_large_delta() when a new timecounter
is activated and a NTP second update occurred.

MFC after:	1 week
2021-11-15 08:56:54 +01:00
Mark Johnston
ea389aaadd timecounter: Lock the timecounter list
Timecounter registration is dynamic, i.e., there is no requirement that
timecounters must be registered during single-threaded boot.  Loadable
drivers may in principle register timecounters (which can be switched to
automatically).  Timecounters cannot be unregistered, though this could
be implemented.

Registered timecounters belong to a global linked list.  Add a mutex to
synchronize insertions and the traversals done by (mpsafe) sysctl
handlers.  No functional change intended.

Reviewed by:	imp, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32511
2021-11-15 08:56:54 +01:00
Mark Johnston
66d4077c98 timecounter: Let kern.timecounter.stepwarnings be set as a tunable
MFC after:	1 week
2021-11-15 08:56:54 +01:00
Ed Maste
d84e3b6ed7 Remove "All Rights Reserved" from
FreeBSD Foundation sys/ copyrights

These ones were unambiguous cases where the Foundation was the only
listed copyright holder (in the associated license block).

Sponsored by:	The FreeBSD Foundation
2021-11-15 08:56:54 +01:00
Warner Losh
87d7a6e54b kern: clarify boot time
In FreeBSD, the current time is computed from uptime + boottime. Uptime
is a continuous, smooth function that's monotonically increasing. To
effect changes to the current time, boottime is adjusted.  boottime is
mutable and shouldn't be cached against future need. Document the
current implementation, with the caveat that we may stop stepping
boottime on resume in the future and will step uptime instead (noted in
the commit message, but not in the code).

Sponsored by:		Netflix
Reviewed by:		phk, rpokala
Differential Revision:	https://reviews.freebsd.org/D30116
2021-11-15 08:56:54 +01:00
Konstantin Belousov
8d5fc57e65 Make kern.timecounter.hardware tunable
Noted and reviewed by:	kevans
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D29122
2021-11-15 08:56:54 +01:00
Konstantin Belousov
570e58e4fe Add ddb 'show timecounter' command.
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-11-15 08:56:54 +01:00
Robert Watson
4b384f318c Changes that improve DTrace FBT reliability
on freebsd/arm64:

- Implement a dtrace_getnanouptime(), matching the existing
  dtrace_getnanotime(), to avoid DTrace calling out to a potentially
  instrumentable function.

  (These should probably both be under KDTRACE_HOOKS.  Also, it's not clear
  to me that they are correct implementations for the DTrace thread time
  functions they are used in .. fixes for another commit.)

- Don't allow FBT to instrument functions involved in EL1 exception handling
  that are involved in FBT trap processing: handle_el1h_sync() and
  do_el1h_sync().

- Don't allow FBT to instrument DDB and KDB functions, as that makes it
  rather harder to debug FBT problems.

Prior to these changes, use of FBT on FreeBSD/arm64 rapidly led to kernel
panics due to recursion in DTrace.

Reliable FBT on FreeBSD/arm64 is reliant on another change from @andrew to
have the aarch64 instrumentor more carefully check that instructions it
replaces are against the stack pointer, which can otherwise lead to memory
corruption.  That change remains under review.

MFC after:	2 weeks
Reviewed by:	andrew, kp, markj (earlier version), jrtc27 (earlier version)
Differential revision:	https://reviews.freebsd.org/D27766
2021-11-15 08:56:54 +01:00
Konstantin Belousov
18e6686d10 Remove double-calls to tc_get_timecount()
to warm timecounters.

It seems that second call does not add any useful state change for all
implemented timecounters.

Discussed with:	bde
Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
2021-11-15 08:56:54 +01:00
Pawel Biernacki
df77572247 Mark more nodes as CTLFLAG_MPSAFE
or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2021-11-15 08:56:54 +01:00
Konstantin Belousov
9fcf785d81 Consolidate read code for timecounters
and fix possible overflow in bintime()/binuptime().

The algorithm to read the consistent snapshot of current timehand is
repeated in each accessor, including the details proper rollup
detection and synchronization with the writer.  In fact there are only
two different kind of readers: one for bintime()/binuptime() which has
to do the in-place calculation, and another kind which fetches some
member from struct timehand.

Extract the logic into type-checked macros, GETTHBINTIME() for bintime
calculation, and GETTHMEMBER() for safe read of a structure' member.
This way, the synchronization is only written in bintime_off() and
getthmember().

In bintime_off(), use overflow-safe calculation of th_scale *
delta(timecounter).  In tc_windup, pre-calculate the min delta value
which overflows and require slow algorithm, into the new timehands
th_large_delta member.

This part with overflow fix was written by Bruce Evans.

Reported by:	Mark Millard <marklmi@yahoo.com> (the overflow issue)
Tested by:	pho
Discussed with:	emaste
Sponsored by:	The FreeBSD Foundation (kib)
MFC after:	3 weeks
2021-11-15 08:56:54 +01:00
Mateusz Guzik
ae5b0b29cf Remove duplicated empty lines from kern/*.c
No functional changes.
2021-11-15 08:56:54 +01:00