SBI implementations may encounter situations where virtual harts are ready to run, but must be withheld from running. These situations may be, for example, when multiple SBI domains share processors or when an SBI implementation is a hypervisor and guest contexts share processors with other guest contexts or host tasks. When virtual harts are at times withheld from running, observers within the contexts of the virtual harts may need a way to account for less progress than would otherwise be expected. The time a virtual hart was ready, but had to wait, is called "stolen time" and the tracking of it is referred to as steal-time accounting. The Steal-time Accounting (STA) extension defines the mechanism in which an SBI implementation provides steal-time and preemption information, for each virtual hart, to supervisor-mode software.
struct sbiret sbi_steal_time_set_shmem(unsigned long shmem_phys_lo,
unsigned long shmem_phys_hi,
unsigned long flags)
Set the shared memory physical base address for steal-time accounting of the calling virtual hart and enable the SBI implementation’s steal-time information reporting.
If shmem_phys_lo
and shmem_phys_hi
are not all-ones bitwise, then
shmem_phys_lo
specifies the lower XLEN bits and shmem_phys_hi
specifies the
upper XLEN bits of the shared memory physical base address. shmem_phys_lo
MUST be 64-byte aligned. The size of the shared memory must be at least 64
bytes. The SBI implementation MUST zero the first 64 bytes of the shared memory
before returning from the SBI call.
If shmem_phys_lo
and shmem_phys_hi
are all-ones bitwise, the SBI
implementation will stop reporting steal-time information for the virtual hart.
The flags
parameter is reserved for future use and MUST be zero.
It is not expected for the shared memory to be written by the supervisor-mode software while it is in use for steal-time accounting. However, the SBI implementation MUST not misbehave if a write from supervisor-mode software occurs, however, in that case, it MAY leave the shared memory filled with inconsistent data.
The SBI implementation MUST stop writing to the shared memory when the supervisor-mode software is not runnable, such as upon system reset or system suspend.
Note
|
Not writing to the shared memory when the supervisor-mode software is not runnable avoids unnecessary work and supports repeatable capture of a system image while the supervisor-mode software is suspended. |
The shared memory layout is defined in STA Shared Memory Structure
Name | Offset | Size | Description |
---|---|---|---|
sequence |
0 |
4 |
The SBI implementation MUST increment this field
to an odd value before writing the |
flags |
4 |
4 |
Always zero. |
steal |
8 |
8 |
The amount of time in which this virtual hart was not idle and scheduled out, in nanoseconds. The time during which the virtual hart is idle will not be reported as steal-time. |
preempted |
16 |
1 |
An advisory flag indicating whether the virtual
hart which registered this structure is running or
not. A non-zero value MAY be written by the
SBI implementation if the virtual hart has been
preempted (i.e. while the |
pad |
17 |
47 |
Pad with zeros to a 64 byte boundary. |
sbiret.value
is set to zero and the possible error codes returned
in sbiret.error
are shown in STA Set Steal-time Shared Memory Address Errors
below.
Error code | Description |
---|---|
SBI_SUCCESS |
The steal-time shared memory physical base address was set or cleared successfully. |
SBI_ERR_INVALID_PARAM |
The |
SBI_ERR_INVALID_ADDRESS |
The shared memory pointed to by the |
SBI_ERR_FAILED |
The request failed for unspecified or unknown other reasons. |