Commit graph

74 commits

Author SHA1 Message Date
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
Japheth Lim
7ee63f9eb7 ARM boot: add MODE_RESERVED to MAX_NUM_FREEMEM_REG
This accounts for the ASID PD hole splitting the main memory region.
2019-07-05 10:19:00 +10:00
Anna Lyons
cb7cbd84dc boot: allocate rootserver objects last
This change allows us to know, from just the kernel and dtb, where user
level untyped objects start being allocated from.

- allocate rootserver objects from last available freemem region.
- move create_rootserver_objects call into init_freemem.
2019-06-20 14:11:50 +10:00
Japheth Lim
e42700a444 ARM boot: MAX_NUM_FREEMEM_REG++ for new allocator
Previously, the boot allocator would do dynamic calculations to
minimise fragmentation, then throw away the smallest regions.
With the new boot allocator, we can reasonably predict that
fragmentation will create at most one extra region, so this commit
adds one freemem slot for ARM.
2019-06-20 14:11:50 +10:00
Anna Lyons
8586b7f2b8 boot: refactor allocation of rootserver objects
Prior to this change, the boot process would dynamically allocate
memory for root server objects based on the order of initialisation.
Allocation was a best-fit algorithm.

This change preallocates all memory for root server objects to an
aligned untyped just after the user image. By allocating the objects in
order of size, allocation is greatly simplified and the ability to
reproduce the allocation offline based on the kernel and user image
sizes is increased.
2019-06-20 14:11:50 +10:00
Adrian Danis
7c1a705336 SELFOUR-1198: correct restart PC
Fixes a case where a thread can go from Running->Inactive->Restart and use a restart PC
that is out of date. An out of date restart PC occurs when a thread was transitioned to
running after being in a blocked state, but was never scheduled and so did not execute
the traps code that updates the restart PC.

A 'more correct' fix would be to update the restart PC when a thread is first transitioned
to Running, but this results in lots of unnecessary update as
 * Frequently immediately schedule a thread after it is transitioned to running, making
   the update to restart PC completely redundant as it gets immediately overwritten
 * Rarely suspend threads making all the updates a 'high' cost for fixing an infrequent
   operation

As a result this solution lazily fixes the restart PC only when we enter a state where
we might need a correct restart PC, which currently in the kernel is only when we
go from Running->Inactive, which can only happen in `suspend`
2019-05-31 14:45:47 +10:00
Anna Lyons
e3a83035f8 boot: consolidate init_freemem
init_freemem sets up available regions of memory for the hardware that
seL4 is booting on. Previously this function was duplicated across
architectures, with minor duplication.

This change provides a top-level init_freemem suitable for all
architectures.

- arm/riscv: change get_avail_p_reg to return whole p_reg array
- update all architectures to use new init_freemem.
- wrap init_freemem calls with arch_init_freemem for each arch, where
arch_init_freemem sets up the available and reserved regions of memory
which are passed to init_freemem.
2019-05-15 14:03:40 +10:00
Anna Lyons
a6b4cf739d boot: allocate irq cnode statically
The memory used for the irq cnode is never available to the user. As a
result this memory can be allocated statically, simplifying the
bootcode.

- remove allocation of irq cnode
- add static init
- generate irq cnode size from cmake for arm
- add static constants for riscv, x86 as there is no variability at the
moment.
2019-05-03 16:18:39 +10:00
Anna Lyons
7fc45c4ef1 style: set code width to 120 2019-03-19 14:05:44 +11:00
Anna Lyons
d0930f67de style: consistently attach return type
Add attach-return-type to astyle
2019-03-19 14:05:36 +11:00
Anna Lyons
761006e03b style: consistently align pointer with name
Run astyle with align-pointer=name
2019-03-19 14:04:54 +11:00
Simon Shields
3dc0cb0a8d Ensure we always have enough freemem regions on ARM 2019-01-15 11:16:53 +11:00
Thibaut Perami
3df00ea4d7 SELFOUR-6: Add GrantReply to the rights system.
GrantReply is a new access right added to endpoint capabilities, which
allows seL4_Call to be used on those capabilities (specifically, it
allows reply caps *only* to be granted across endpoints).

Prior to the addition of GrantReply, endpoint capabilities required the
Grant access right, which allowed any arbitrary capabilitiy to be
transferred over an endpoint. Using GrantReply, systems can now be
constructed where threads using seL4_Call over an endpoint do not need to be in the same
security subsystem.
2018-12-12 14:04:28 +11:00
Adrian Danis
a2a6be95ca Define more freemem regions on all architectures except ARM
2 freemem regions is far to prohibitive on platforms that have fragmented initial
memory. Ultimately ARM should be changed to also have more than 2, but is being
deferred for now as it will result in trivial verification breakage.
2018-04-18 10:10:14 +10:00
Adrian Danis
5505266a74 Remove irrelavant changes from riscv commit to non riscv arch code 2018-04-18 10:10:14 +10:00
Hesham Almatary
83ba084713 [SELFOUR-1156] RISC-V Port
Experimental release that supports both RV32 and RV64
2018-04-18 10:10:14 +10:00
Bruce Mitchener
b942a50441 Fix trivial comment typos. 2018-03-27 10:51:26 +11:00
Adrian Danis
8639dbcaea Abstractly declare a threads registers have changed
This removes an #ifdef for x86-64 that was in generic code by declaring the generic
mechanism that is being used as an Arch_ function
2017-12-13 12:09:14 +11:00
Adrian Danis
8028066a65 ksSchedulerAction contains candidate thread instead of target thread
Instead of switching to the thread contained in `ksSchedulerAction` on a `schedule` we
instead decide between the 'candidate' contained in `ksSchedulerAction`, the current thread
or potentially neither if the candidate is deemed invalid and the current thread is blocked.

A consequence of this change is that it is no longer meaningful to have a distinction between
`switchIfRequiredTo` and `attemptSwitchTo`. Now both these cases simply identify a candidate,
which may or may not be picked in `schedule`. Part of the distinction of `switchIfRequiredTo`
was to not avoid switching if possible when performing notifications. This is now handled by
prefering the current thread over the candidate if the current thread has not blocked.

This change is largely semantic preserving overall, with the exception of non-blocking
synchronous sends now acting like notifications and also preferring to resume running the
current thread.

The motivation for this change was to make it much easier for verification to show
correspondence between the fastpath changes introduced in the previous commit and the
slowpath scheduler.
2017-11-28 10:18:35 +11:00
Adrian Danis
780b13dad9 Provide isHighestPrio helper 2017-11-28 10:18:35 +11:00
Adrian Danis
d40868b933 Invert priority order of scheduler bitmap
Provides better cache performance for high priority threads
2017-11-28 10:18:35 +11:00
Adrian Danis
a2409b9888 getHighestPrio calculation as a wrapper
Moves the logic from chooseThread into a dedicated helper function
2017-11-28 10:18:35 +11:00
Anna Lyons
40c61e5c18 Fix licenses (the rest) 2017-06-22 15:29:12 +10:00
Adrian Danis
b861f28498 Move isRunnable from thread.c to thread.h
This helper function is useful beyond just thread.c
2017-04-26 09:36:43 +10:00
Anna Lyons
f42d63631b refactor: initialise common core state in one place 2017-03-16 11:15:04 +11:00
Adrian Danis
c43954252c Remove assumption on 32-bit memory offsets
On 64-bit platforms physical address could be >2^32 offset from a virtual address. This
changes offsets to match the word size of the target architecture
2017-02-28 08:28:01 +11:00
Adrian Danis
eccaae51dc s/D61/DATA61/ in license headers for consistency 2017-02-21 16:38:51 +11:00
Adrian Danis
c574f4fc48 Helper for allocating the extra boot info region 2017-02-16 14:34:52 +11:00
Adrian Danis
4f52aca5b1 Remove multiple stack definitions
This commit changes the stack so that it is declared a single time in stack.c,
with the correct attributes and alignment, instead of being declared in stack.h
and relying on the linker to collapse the multiple declarations.
2017-02-06 15:42:37 +11:00
Hesham Almatary
c156c9dddd Merge pull request #607 in SEL4/sel4 from ~HALMATARY/sel4:KernelStacks to master
* commit 'be77963e5bb4c5c28ad3ebd8746c292e7b5876f6':
  Define CONFIG_MAX_NUM_NODES and CONFIG_KERNEL_STACK_BITS in plat/autoconf.h
  Unify kernel stack definition/declaration and share it between architecures/modes
2017-01-18 12:43:34 +11:00
Hesham Almatary
e9922b7456 Unify kernel stack definition/declaration and share it between architecures/modes
Rather than defining a kernel stack in random places for each
architecure for each mode (32/64) and for single/SMP modes, make the
stack definition shareable between all of the above. This is also useful
for the future ARM SMP work.
2017-01-17 15:52:58 +11:00
Hesham Almatary
af02927b69 SMP: move lock.h to architecture-independent include/smp
s/__sync_lock_test_and_set/__atomic_exchange_n in lock.h
2017-01-16 15:21:50 +11:00
Anna Lyons
b827ad37ba SELFOUR-413: refactor libsel4 fault API
This is a *breaking API change*

This commit:

* makes seL4_Fault_tag_t common between the kernel and libsel4
* deprecates the existing functions from sel4/messages.h includes
* introduces a new fault API in sel4/faults.h and
* sel4/sel4_arch/faults.h
* deprecates seL4_GetTag(), as the function did not work without
  the user calling seL4_SetTag() first (seL4_MessageInfo is passed
  in registers and not set in the IPC buffer)
* removes previously deprecated functions (deprecated prior to 3.0.0)
* updates the seL4 manual to reflect the changes
2016-11-25 12:29:07 +11:00