blob: e2b5b71b9ba0fca330fad7af111f2555a9003885 [file] [log] [blame] [view]
Andrew Walbran6e524d72019-11-12 17:36:57 +00001# Scheduler VM expectations
2
3Hafnium requires there to be a special 'primary' or 'scheduler' VM which is
4responsible for scheduling the other VMs. There are some particular expectations
5on this VM that are required for the rest of the system to function normally.
6
Andrew Walbranb7849972019-11-15 15:23:43 +00007[TOC]
8
Andrew Walbran6e524d72019-11-12 17:36:57 +00009## Scheduling
10
11The scheduler VM is responsible for scheduling the vCPUs of all the other VMs.
12It should request information about the VMs in the system using the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010013`FFA_PARTITION_INFO_GET` function, and then schedule their vCPUs as it wishes.
Andrew Walbran6e524d72019-11-12 17:36:57 +000014The recommended way of doing this is to create a kernel thread for each vCPU,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010015which will repeatedly run that vCPU by calling `FFA_RUN`.
Andrew Walbran6e524d72019-11-12 17:36:57 +000016
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010017`FFA_RUN` will return one of several possible functions, which must be handled
Andrew Walbran6e524d72019-11-12 17:36:57 +000018as follows:
19
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010020### `FFA_INTERRUPT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000021
22The vCPU has been preempted but still has work to do. If the scheduling quantum
Andrew Walbrana0e30b02020-10-22 15:55:45 +010023has not expired, the scheduler MUST call `FFA_RUN` on the vCPU to allow it to
24continue.
Andrew Walbran6e524d72019-11-12 17:36:57 +000025
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010026### `FFA_YIELD`
Andrew Walbran6e524d72019-11-12 17:36:57 +000027
28The vCPU has voluntarily yielded the CPU. The scheduler SHOULD take a scheduling
Andrew Walbrana0e30b02020-10-22 15:55:45 +010029decision to give cycles to those that need them but MUST call `FFA_RUN` on the
30vCPU at a later point.
Andrew Walbran6e524d72019-11-12 17:36:57 +000031
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010032### `FFA_MSG_WAIT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000033
34The vCPU is blocked waiting for a message. The scheduler MUST take it off the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010035run queue and not call `FFA_RUN` on the vCPU until it has either:
Andrew Walbran6e524d72019-11-12 17:36:57 +000036
37* injected an interrupt
38* sent it a message
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010039* received `HF_FFA_RUN_WAKE_UP` for it from another vCPU
40* the timeout provided in `w2` is not `FFA_SLEEP_INDEFINITE` and the
Andrew Walbran6e524d72019-11-12 17:36:57 +000041 specified duration has expired.
42
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010043### `FFA_MSG_SEND`
Andrew Walbran6e524d72019-11-12 17:36:57 +000044
45A message has been sent by the vCPU. If the recipient is the scheduler VM itself
46then it can handle it as it pleases. Otherwise the scheduler MUST run a vCPU
47from the recipient VM and priority SHOULD be given to those vCPUs that are
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010048waiting for a message. The scheduler should call FFA_RUN again on the sending
Andrew Walbran6e524d72019-11-12 17:36:57 +000049VM as usual.
50
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010051### `FFA_RX_RELEASE`
Andrew Walbran6e524d72019-11-12 17:36:57 +000052
53The vCPU has made the mailbox writable and there are pending waiters. The
54scheduler MUST call `hf_mailbox_waiter_get()` repeatedly and notify all waiters
55by injecting an `HF_MAILBOX_WRITABLE_INTID` interrupt. The scheduler should call
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010056FFA_RUN again on the sending VM as usual.
Andrew Walbran6e524d72019-11-12 17:36:57 +000057
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010058### `HF_FFA_RUN_WAIT_FOR_INTERRUPT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000059
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010060_This is a Hafnium-specific function not part of the FF-A standard._
Andrew Walbran6e524d72019-11-12 17:36:57 +000061
62The vCPU is blocked waiting for an interrupt. The scheduler MUST take it off the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010063run queue and not call `FFA_RUN` on the vCPU until it has either:
Andrew Walbran6e524d72019-11-12 17:36:57 +000064
65* injected an interrupt
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010066* received `HF_FFA_RUN_WAKE_UP` for it from another vCPU
67* the timeout provided in `w2` is not `FFA_SLEEP_INDEFINITE` and the
Andrew Walbran6e524d72019-11-12 17:36:57 +000068 specified duration has expired.
69
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010070### `HF_FFA_RUN_WAKE_UP`
Andrew Walbran6e524d72019-11-12 17:36:57 +000071
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010072_This is a Hafnium-specific function not part of the FF-A standard._
Andrew Walbran6e524d72019-11-12 17:36:57 +000073
74Hafnium would like `hf_vcpu_run` to be called on another vCPU, specified by
75`hf_vcpu_run_return.wake_up`. The scheduler MUST either wake the vCPU in
76question up if it is blocked, or preempt and re-run it if it is already running
77somewhere. This gives Hafnium a chance to update any CPU state which might have
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010078changed. The scheduler should call FFA_RUN again on the sending VM as usual.
Andrew Walbran6e524d72019-11-12 17:36:57 +000079
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010080### `FFA_ERROR`
Andrew Walbran6e524d72019-11-12 17:36:57 +000081
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010082#### `FFA_ABORTED`
Andrew Walbran6e524d72019-11-12 17:36:57 +000083
84The vCPU has aborted triggering the whole VM to abort. The scheduler MUST treat
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010085this the same as `HF_FFA_RUN_WAKE_UP` for all the other vCPUs of the VM. For
86this vCPU the scheduler SHOULD either never call FFA_RUN on the vCPU again, or
87treat it the same as `HF_FFA_RUN_WAIT_FOR_INTERRUPT`.
Andrew Walbran6e524d72019-11-12 17:36:57 +000088
89#### Any other error code
90
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010091This should not happen if the scheduler VM has called `FFA_RUN` correctly, but
Andrew Walbran6e524d72019-11-12 17:36:57 +000092in case there is some other error it should be logged. The scheduler SHOULD
93either try again or suspend the vCPU indefinitely.
94
95## Interrupt handling
96
97The scheduler VM is responsible for handling all hardware interrupts. Many of
98these will be intended for the scheduler VM itself and it can handle them as
99usual. However, it must also:
100
101* Enable, handle and ignore interrupts for the non-secure hypervisor physical
102 timer (PPI 10, IRQ 26).
103* Forward interrupts intended for secondary VMs to an appropriate vCPU of the
104 VM by calling `hf_interrupt_inject` and then running the vCPU as usual with
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100105 `FFA_RUN`. (If the vCPU is already running at the time that
Andrew Walbran6e524d72019-11-12 17:36:57 +0000106 `hf_interrupt_inject` is called then it must be preempted and run again so
107 that Hafnium can inject the interrupt.)