Commit graph

106 commits

Author SHA1 Message Date
Axel Heider
f46aac30b8 boot: remove ndks_boot.slot_pos_max
- The field 'slot_pos_max' from 'ndks_boot' is not needed, the value
  stored there is the constant BIT(CONFIG_ROOT_CNODE_SIZE_BITS).
- Improve the error message if the limit has been reached

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-09-02 08:44:24 +10:00
Gerwin Klein
02ddcd110a mcs: Remove domain time check from preemptionPoint
This removes the operations that trigger a reschedule or reprogram the
timer from `preemptionPoint` to ensure the relevant state updates in
the proof occur where they are easier to verify.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2021-08-24 10:22:33 +10:00
Gerwin Klein
56098195f2 mcs: sc_active not always true in sc_sporadic
Turns out the invariant 17109eb8c9 refers to is hard to prove
because it is not true, and the runtime check is necessary. This
assertion fails in sel4test SCHED_CONTEXT_0003 (Basic
api_sc_bind/UnbindObject testing).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2021-08-20 16:52:12 +10:00
Curtis Millar
17109eb8c9 mcs: Explicitly check that sporadic scs are active
Easier to check this explicitly than prove the invariant.

Signed-off-by: Curtis Millar <curtis@curtism.me>
2021-08-20 13:59:07 +10:00
Axel Heider
74b81ede92 boot: make functions static
The functions insert_region() and create_rootserver_objects() are not
used outside of boot.c, so there is no reason to make it publicly
available.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-08-18 08:55:48 +10:00
Axel Heider
89a5b8fd31 boot: move create_untypeds() to generic code
Also merge create_device_untypeds() and create_kernel_untypeds() into
create_untypeds() to simplify the code.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-30 08:46:12 +10:00
Axel Heider
d1a456bebd remove redundant defines
These defines are set up in the architecture specific bootinho.h.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 11:19:43 +10:00
Axel Heider
938c1c9557 boot: fail boot if region configuration is invalid
Also make the output more verbose in case of errors, which is
helpful when porting the kernel to new platforms.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-01 10:48:47 +10:00
Axel Heider
adbd374370 boot: make create_untypeds_for_region() static
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-01 10:48:47 +10:00
Axel Heider
138e809e72 use const qualifier
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-01 10:48:47 +10:00
Curtis Millar
2f35873885 mcs: Add debug assert to check scheduling correct
The scheduler cannot correctly schedule once the timestamp exceeds
MAX_RELEASE_TIME as releases beyond this point may be subject to
overflow. For most systems this should still allow a great many years if
the timestamp starts from 0 at system boot.

Some systems currently start with a random initial timestamp and my
begin with a timestamp that prvents correct budgeting. This assert helps
to catch cases where scheduling becomes invalid due to the timestamp
exceeding the give bound.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-05-17 10:06:58 +10:00
Curtis Millar
dc959bad4d Default MAX_BUDGET_US to allow for system uptime
The proofs currently only guarantee that the system scheduler is correct
while the current time is less than INT64_MAX - 3 * MAX_PERIOD ticks.
With the MAX_PERIOD configured to almost INT64_MAX, this would imply
that the system scheduler is never correct.

To ensure that we get a large duration where the system is correct, we
take 1/8th of the TOTAL representable time as the MAX_PERIOD, ensuring
that 3 * MAX_PERIOD is still less than half of all representable time.
For a system with a 1MHz scheduling clock, this produces a valid
execution time on the order of 2^19 years.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-05-17 10:06:58 +10:00
Curtis Millar
263a2b95bb mcs: Account for overrun up to integer overflow
This re-introduces the overrun handling but bounds charging of budget
such that we never calculate a refill with a start using an integer
overflow.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-05-17 10:06:58 +10:00
Kent McLeod
e2ca0b6119 mcs: Remove refill_full check from checkBudget
A refill can still be charged if the refill list is full. This means
that we only require sufficient capacity to continue a timeslice.

Signed-off-by: Kent McLeod <kent@kry10.com>
Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-05-17 10:06:58 +10:00
Curtis Millar
c5c4eae1f5 mcs: Use single function to charge budget to SC
This replaces the refill_split_check and refill_budget_check with a
single function that chanrges the provided usage to an SC and updates
the refills.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-05-17 10:06:58 +10:00
Kent McLeod
fa4f1baeb7 mcs: Update ksDomainTime in updateTimestamp
When ksDomainTime reaches 0 the current domain expires and the next
domain is switched to. This change performs the domain time accounting
in one place, in updateTimestamp, and avoids situations where ksConsumed
is reset without also updating ksDomainTime such as in chargeBudget.

Calling rescheduleRequired in the domain expires ensures that a new
thread will be chosen in the scheduler after the domain has been
advanced.  Any remaining ksConsumed will be charged to the outgoing
scheduling context when it is switched away from.

Signed-off-by: Kent McLeod <kent@kry10.com>
2021-04-30 12:16:09 +10:00
Curtis Millar
8373f0a0a6 mcs: Defer charging budget in preempted invocation
Rather than charge consumed time to the current thread at the point
where it is exhausted in a long-running syscall, we only check whether
checkBudget would fail and raise an exception if it would. We then
always charge after handleInvocation rather than avoid-double charging.

This is done as it is easier to add the exhaustion case in the abstract
spec in this manner (without also adding changes to the current SC).

Signed-off-by: Curtis Millar <curtis@curtism.me>
2021-04-30 12:16:09 +10:00
Curtis Millar
295a5b2818 Rename MAX_BUDGET to MAX_PERIOD
As this variable bounds both the period and the budget and the period
itself bounds the budget, the name for this variable would be more
appropriately named 'MAX_PERIOD'

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-04-29 11:51:54 +10:00
Curtis Millar
afbea15710 mcs: Add sporadic flag to SchedControl_Configure
This adds a flags parameter to SchedControl_Configure to enable
configuration of a sporadic SC.

This also allows flags to be added in the future as needed without
breaking the API.

This allows the user to configure an SC either to be constrained as a
sporadic task where accumulated time is only delayed to when a task has
become runnable (implementing the sporadic server algorithm) or
whenever the task becomes the current executing task (implementing the
sliding-window constraint as in constant-bandwidth servers).

This can be used to prevent non-realtime tasks from exceeding bandwidth
under any circumstances, even in an over-committed configuration, whilst
also allowing work-conserving tasks to be configured in the same system.

To implement sporadic servers, we need to ensure that the suspension of
a task cannot be used as a mechanism to amplify budget of a task by
granting that task access to effectively multiple periods worth of
replenishments within a single period.

To align the implementation of SCs with the model of sporadic servers we
must delay available time until the release of a task. Within seL4, a
release would be any time where an SC changes from not being associated
with a Running, RunningVM, or Restart thread to one that is.

This can occur when an SC is bound to a new thread in such a state or
when a thread changes to such a state from any non-running states.

Critically, replenishments should not be delayed at the point when an SC
becomes the current SC (as was the case prior to this commit). This has
the effect of enforcing a continuous, constant bandwidth which is a
restriction that is incompatible with standard scheduling logic.

Accounting for this requires inserting a new refill_unblock_check
call whenever a sporadic SC is unblocked and removing the
refill_unblock_check call from when said SC is scheduled.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-04-14 15:24:40 +10:00
Curtis Millar
c9538a2b20 mcs: add functions sc_released, sc_active
A 'released' SC is one that has been configured with its head refill in
the past.

An 'active' checking function checks for whether an SC has been
configured.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-02-26 15:00:22 +11:00
Curtis Millar
a00c2c16cf
Make kernel log buffer derived from cmake config
This removes the explicit CMake configuration for the kernel log buffer
and replaces it with a #define that is enabled for the required
configurations.

Signed-off-by: Curtis Millar <curtis@curtism.me>
2020-11-10 16:24:43 +11:00
Mitchell Buckley
036ffc1895 mcs: update commitTime
It is possible for consumed time to be larger than domain time.

Signed-off-by: Mitchell Buckley <mitchell.buckley@data61.csiro.au>
2020-09-08 19:49:38 +10:00
Matthew Brecknell
4522d895d7 mcs: return pointer from refill_head and others
A previous commit produced some build errors, since it converted the
`REFILL_HEAD` and `REFILL_TAIL` macros to functions returning
`refill_t`, and the results were used as lvalues. This commit returns
pointers instead, and also converts `REFILL_INDEX` to a function.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2020-09-03 18:56:49 +10:00
Edward Pierzchalski
b181184d75 mcs: change REFILL_HEAD, REFILL_TAIL to functions
SimplExportAndRefine can't handle the level of pointer arithmetic being
performed by `REFILL_INDEX` if it's literally inlined into a function,
however it *can* handle that arithmetic if it's in a separate function.

Signed-off-by: Edward Pierzchalski <ed.pierzchalski@data61.csiro.au>
2020-09-01 16:47:21 +10:00
Curtis Millar
0fbf2f7da3 mcs: Don't pass capacity through calls
The capacity does not need to be passed as an argument to
refill_check_budget as all information that it was being used for can be
dertermined from the usage directly.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-07-24 12:29:06 +10:00
Anna Lyons
c06a6c9a93 mcs: add MAX_BUDGET_US
We need to bound the time the user provides to configure scheduling
contexts to avoid malicious or erraneous overflows of the scheduling
math. Make the max period/budget 1 hour.

1 hour is sufficiently small that it will fit in a 32-bit error message.

1 week is sufficiently small for 64-bit platforms.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-07-24 12:28:58 +10:00
Kent McLeod
88a7d138c4 KernelBenchmarksTrackUtilisation: Add more stats
For each thread also track number of times scheduled, number of kernel
entries and amount of cycles spent inside the kernel.  Also add
core-wide totals for each.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-07-15 15:15:27 +10:00
Curtis Millar
d5d54a0d55 introduce isStopped and change isBlocked
This changes the semantics if `isBlocked` to not include the 'inactive'
state when it returns true. The old semantics for isBlocked are provided
by `isStopped`.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-06 15:49:33 +10:00
Curtis Millar
95ddb55629 mcs: Compare with time in assigned core
All time for an SC should be relative to its assigned core. Any
operations which may occur on an SC on a remote core must explicitly
refer to that core.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-04 11:58:42 +10:00
Curtis Millar
1d419f6904 mcs: SC time relative to assigned core
The starting and ready times for any SC should be relative to the core
on which the SC is running rather than the current core.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-04 11:58:42 +10:00
Qian Ge
512a0200de replacing all ifndef with pargma once
All the kernel header files now use pargma once rather than the ifndef,
as the pre-processed C files do not change while header files
are protected with pargma once. This will also solve any naming issues
caused by ifndef.
2020-03-23 11:04:46 +11:00
Gerwin Klein
79da079239 Convert license tags to SPDX identifiers
This commit also converts our own copyright headers to directly use
SPDX, but leaves all other copyright header intact, only adding the
SPDX ident. As far as possible this commit also merges multiple
Data61 copyright statements/headers into one for consistency.
2020-03-09 13:21:49 +08:00
Simon Shields
eb2bdf8463 trivial: remove duplicate macro definition 2019-11-19 16:37:51 +11:00
Simon Shields
b5c56244f1 Create device untypeds at boot for all arches
Currently on x86 device untypeds are generated by passing the entire
address space minus any parts that are reserved by the kernel or that
are "real" memory (e.g. kernel image, physical RAM).

On ARM and RISC-V, device untypeds were generated at compile-time from
a device tree. This patch moves ARM and RISC-V to use the same approach
as x86, and moves the code from x86 into a common location that's
shared between the three architectures.

Co-Authored-By: Anna Lyons <anna@gh.st>
2019-11-12 16:20:07 +11:00
Curtis Millar
c25e5445fb mcs: Don't rollback time when not rescheduling
This allows ksCurTime to be monotonically increasing making proofs much
easier to construct.
2019-09-23 16:49:07 +10:00
Anna Lyons
b33d4680f2 mcs: Avoid charging invalid scheduling contexts
ChargeBudget can be called after a preemption, but the preemption may
have deleted the scheduling context. Do not charge scheduling contexts
that have been deleted (check scRefillMax).
2019-08-22 11:22:41 +10:00
Anna Lyons
86e50d0703 mcs: Avoid missing a timer tick
Preemption can be via the timer interrupt. In this case we need to
update the timestamp so we can reprogram the timer for the next timeout
and guarantee it is in the future, otherwise we will end up setting a
timeout in the past.
2019-08-22 11:22:41 +10:00
Anna Lyons
b358a1c59c trivial: move isSchedulable to header 2019-08-22 11:22:41 +10:00
Anna Lyons
257a62c73f mcs: explicitly use ksCurSC
- in refill_[budget|split]_check.
- This simplifies the code and the proofs.
2019-08-22 11:22:41 +10:00
Anna Lyons
483f0ae22f mcs: SchedControlConfigure: charge correct core
Previously this code would incorrectly call chargeBudget twice, where it
was intended to be charging a specific core.
2019-08-22 11:22:39 +10:00
Adrian Danis
4768465027 mcs: allow kernel WCET estimate to be scaled
This configuration option allows for building images destined for
simulators, which may not simulate as fast as hardware, to still be
used.
2019-08-22 11:22:39 +10:00
Anna Lyons
a38e62f2f9 mcs: timeout exceptions
- Add seL4_TCB_SetTimeoutEndpoint
- implement timeout exceptions
2019-08-22 11:22:38 +10:00
Anna Lyons
c405ef53d2 mcs: install fault endpoint into tcb cnode
- seL4_TCB_Configure no longer takes a fault endpoint.
- seL4_TCB_SetSpace takes a cap in the callers cspace for the
  fault endpoint, not the target tcbs.
- seL4_TCB_SetSchedParams now also takes a fault endpoint as above.

This change installs the fault endpoint cap into the tcb cnode
first validating it.

This means either of the functions that set it will now return an error
if the cap is not either a null cap or an endpoint with send and
grant rights.

Significantly, the cap passed to the function should be in the callers
cspace, not the target tcbs.
2019-08-22 11:22:38 +10:00
Anna Lyons
106b893ee0 mcs: configurable scheduling context size
This allows users to define custom amounts of refills without
increasing the scheduling context size system wide.

also add libsel4 functions for refill size
2019-08-22 11:22:38 +10:00
Anna Lyons
96798066f6 mcs: avoid rolling back time if acted upon
Otherwise strange things can happen where threads are in the future.
2019-08-22 11:22:37 +10:00
Anna Lyons
9253704d2c mcs: update refills based on spec
This is a list of fixes that came up while working on the verification
spec for the mcs changes.

- trigger a timer tick if we are unable to split a refill
due to the refill list being full.
- make refill_ordered more useful
- pull the thread out of the scheduler before updating it
- simplify refill logic at verifications request
- Add unused to refill_sum
- Don't refill_split_check if consumed is empty
- sched_control: fix double increment bug
- sched-control: charge before reconfiguring ksCurSC
- Charge round robin threads differently

Sporadic server refill rules do not behave correctly for round robin
threads, instead, change the logic. Round robin threads have 2 refills:
current and next.
2019-08-22 11:22:37 +10:00
Anna Lyons
554f812da3 mcs: scheduling context donation over ipc
After this commit, threads blocked on an endpoint can recieve a
scheduling context from the thread that wakes the blocked thread.
2019-08-22 11:22:37 +10:00
Anna Lyons
34c1f920b1 mcs: add periodic scheduling
This commit adds periodic scheduling with sporadic servers.
2019-08-22 11:22:35 +10:00
Anna Lyons
7124449936 mcs: tickless scheduler implementation
This changes the budget/remaining fields in scheduling contexts
to contain timer ticks, not number of abstract sel4ticks.

seL4_SchedControl_Configure now takes microseconds, not ticks.

This commit is plat-independant - the platform and arch specific
timer code follows in later commits.
2019-08-22 11:22:34 +10:00
Anna Lyons
952134d1b8 mcs: Add a scheduling context object
This is the first part of the seL4 MCS. This commit:

    * adds a scheduling context object. Threads without scheduling
      context objects cannot be scheduled.
    * replaces tcbTimeSlice with the scheduling context object
    * adds seL4_SchedControl caps for each core
    * adds seL4_SchedControl_Configure which allows users to configure
      amount of ticks a scheduling context has, and set a core for the
      scheduling context.
    * adds seL4_SchedContext_Bind, Unbind and UnbindObject, which allows
      a tcb to be bound to a scheduling context.
2019-08-22 11:22:34 +10:00