blob: f27e58771847258abf2d529f40aaac1050ced6a6 [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 Walbran6e524d72019-11-12 17:36:57 +00007## Scheduling
8
9The scheduler VM is responsible for scheduling the vCPUs of all the other VMs.
10It should request information about the VMs in the system using the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010011`FFA_PARTITION_INFO_GET` function, and then schedule their vCPUs as it wishes.
Andrew Walbran6e524d72019-11-12 17:36:57 +000012The recommended way of doing this is to create a kernel thread for each vCPU,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010013which will repeatedly run that vCPU by calling `FFA_RUN`.
Andrew Walbran6e524d72019-11-12 17:36:57 +000014
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010015`FFA_RUN` will return one of several possible functions, which must be handled
Andrew Walbran6e524d72019-11-12 17:36:57 +000016as follows:
17
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010018### `FFA_INTERRUPT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000019
20The vCPU has been preempted but still has work to do. If the scheduling quantum
Andrew Walbrana0e30b02020-10-22 15:55:45 +010021has not expired, the scheduler MUST call `FFA_RUN` on the vCPU to allow it to
22continue.
Andrew Walbran6e524d72019-11-12 17:36:57 +000023
Andrew Walbran7e824602020-10-22 16:51:40 +010024If `w1` is non-zero, then Hafnium would like `FFA_RUN` to be called on the vCPU
25specified there. The scheduler MUST either wake the vCPU in question up if it is
26blocked, or preempt and re-run it if it is already running somewhere. This gives
27Hafnium a chance to update any CPU state which might have changed. The scheduler
28should call `FFA_RUN` again on the sending VM as usual.
29
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010030### `FFA_YIELD`
Andrew Walbran6e524d72019-11-12 17:36:57 +000031
32The vCPU has voluntarily yielded the CPU. The scheduler SHOULD take a scheduling
Andrew Walbrana0e30b02020-10-22 15:55:45 +010033decision to give cycles to those that need them but MUST call `FFA_RUN` on the
34vCPU at a later point.
Andrew Walbran6e524d72019-11-12 17:36:57 +000035
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010036### `FFA_MSG_WAIT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000037
38The vCPU is blocked waiting for a message. The scheduler MUST take it off the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010039run queue and not call `FFA_RUN` on the vCPU until it has either:
Andrew Walbran6e524d72019-11-12 17:36:57 +000040
41* injected an interrupt
42* sent it a message
Andrew Walbran7e824602020-10-22 16:51:40 +010043* received `FFA_INTERRUPT` for it from another vCPU
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010044* the timeout provided in `w2` is not `FFA_SLEEP_INDEFINITE` and the
Andrew Walbran6e524d72019-11-12 17:36:57 +000045 specified duration has expired.
46
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010047### `FFA_MSG_SEND`
Andrew Walbran6e524d72019-11-12 17:36:57 +000048
49A message has been sent by the vCPU. If the recipient is the scheduler VM itself
50then it can handle it as it pleases. Otherwise the scheduler MUST run a vCPU
51from the recipient VM and priority SHOULD be given to those vCPUs that are
Demi Marie Obenour1a55b772023-02-15 10:38:26 -050052waiting for a message. The scheduler should call `FFA_RUN` again on the sending
Andrew Walbran6e524d72019-11-12 17:36:57 +000053VM as usual.
54
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010055### `FFA_RX_RELEASE`
Andrew Walbran6e524d72019-11-12 17:36:57 +000056
57The vCPU has made the mailbox writable and there are pending waiters. The
58scheduler MUST call `hf_mailbox_waiter_get()` repeatedly and notify all waiters
59by injecting an `HF_MAILBOX_WRITABLE_INTID` interrupt. The scheduler should call
Demi Marie Obenour1a55b772023-02-15 10:38:26 -050060`FFA_RUN` again on the sending VM as usual.
Andrew Walbran6e524d72019-11-12 17:36:57 +000061
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010062### `HF_FFA_RUN_WAIT_FOR_INTERRUPT`
Andrew Walbran6e524d72019-11-12 17:36:57 +000063
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010064_This is a Hafnium-specific function not part of the FF-A standard._
Andrew Walbran6e524d72019-11-12 17:36:57 +000065
66The vCPU is blocked waiting for an interrupt. The scheduler MUST take it off the
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010067run queue and not call `FFA_RUN` on the vCPU until it has either:
Andrew Walbran6e524d72019-11-12 17:36:57 +000068
69* injected an interrupt
Andrew Walbran7e824602020-10-22 16:51:40 +010070* received `FFA_INTERRUPT` for it from another vCPU
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010071* the timeout provided in `w2` is not `FFA_SLEEP_INDEFINITE` and the
Andrew Walbran6e524d72019-11-12 17:36:57 +000072 specified duration has expired.
73
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010074### `FFA_ERROR`
Andrew Walbran6e524d72019-11-12 17:36:57 +000075
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010076#### `FFA_ABORTED`
Andrew Walbran6e524d72019-11-12 17:36:57 +000077
78The vCPU has aborted triggering the whole VM to abort. The scheduler MUST treat
Andrew Walbran7e824602020-10-22 16:51:40 +010079this the same as `FFA_INTERRUPT` for all the other vCPUs of the VM. For this
Demi Marie Obenour1a55b772023-02-15 10:38:26 -050080vCPU the scheduler SHOULD either never call `FFA_RUN` on the vCPU again, or treat
Andrew Walbran7e824602020-10-22 16:51:40 +010081it the same as `HF_FFA_RUN_WAIT_FOR_INTERRUPT`.
Andrew Walbran6e524d72019-11-12 17:36:57 +000082
83#### Any other error code
84
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010085This should not happen if the scheduler VM has called `FFA_RUN` correctly, but
Andrew Walbran6e524d72019-11-12 17:36:57 +000086in case there is some other error it should be logged. The scheduler SHOULD
87either try again or suspend the vCPU indefinitely.
88
89## Interrupt handling
90
91The scheduler VM is responsible for handling all hardware interrupts. Many of
92these will be intended for the scheduler VM itself and it can handle them as
93usual. However, it must also:
94
95* Enable, handle and ignore interrupts for the non-secure hypervisor physical
96 timer (PPI 10, IRQ 26).
97* Forward interrupts intended for secondary VMs to an appropriate vCPU of the
98 VM by calling `hf_interrupt_inject` and then running the vCPU as usual with
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010099 `FFA_RUN`. (If the vCPU is already running at the time that
Andrew Walbran6e524d72019-11-12 17:36:57 +0000100 `hf_interrupt_inject` is called then it must be preempted and run again so
101 that Hafnium can inject the interrupt.)