sta.rs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. use sbi_spec::binary::{SbiRet, SharedPtr};
  2. /// Steal-time Accounting extension.
  3. ///
  4. /// SBI implementations may encounter situations where virtual harts are ready to
  5. /// run, but must be withheld from running. These situations may be, for example,
  6. /// when multiple SBI domains share processors or when an SBI implementation is a
  7. /// hypervisor and guest contexts share processors with other guest contexts or
  8. /// host tasks. When virtual harts are at times withheld from running, observers
  9. /// within the contexts of the virtual harts may need a way to account for less
  10. /// progress than would otherwise be expected. The time a virtual hart was ready,
  11. /// but had to wait, is called "stolen time" and the tracking of it is referred to
  12. /// as steal-time accounting. The Steal-time Accounting (STA) extension defines the
  13. /// mechanism in which an SBI implementation provides steal-time and preemption
  14. /// information, for each virtual hart, to supervisor-mode software.
  15. pub trait Sta {
  16. /// Set Steal-time Shared Memory Address.
  17. ///
  18. /// Set the shared memory physical base address for steal-time accounting of the
  19. /// calling virtual hart and enable the SBI implementation's steal-time information
  20. /// reporting.
  21. ///
  22. /// If physical address of `shmem` are not all-ones bitwise, then the `shmem` pointer
  23. /// specifies the shared memory physical base address. The physical address of `shmem`
  24. /// MUST be 64-byte aligned. The size of the shared memory must be 64 bytes.
  25. /// The SBI implementation MUST zero the shared memory before returning from the SBI
  26. /// call.
  27. ///
  28. /// If physical address of `shmem` are all-ones bitwise, the SBI
  29. /// implementation will stop reporting steal-time information for the virtual hart.
  30. ///
  31. /// The `flags` parameter is reserved for future use and MUST be zero.
  32. ///
  33. /// It is not expected for the shared memory to be written by the supervisor-mode
  34. /// software while it is in use for steal-time accounting. However, the SBI
  35. /// implementation MUST not misbehave if a write from supervisor-mode software
  36. /// occurs, however, in that case, it MAY leave the shared memory filled with
  37. /// inconsistent data.
  38. ///
  39. /// The SBI implementation MUST stop writing to the shared memory when the
  40. /// supervisor-mode software is not runnable, such as upon system reset or system
  41. /// suspend.
  42. ///
  43. /// *NOTE:* Not writing to the shared memory when the supervisor-mode software is
  44. /// not runnable avoids unnecessary work and supports repeatable capture of a
  45. /// system image while the supervisor-mode software is suspended.
  46. ///
  47. /// # Return value
  48. ///
  49. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  50. ///
  51. /// | Return code | Description
  52. /// |:----------------------------|:----------------------------------------------
  53. /// | `SbiRet::success()` | The steal-time shared memory physical base address was set or cleared successfully.
  54. /// | `SbiRet::invalid_param()` | The `flags` parameter is not zero or the `shmem` is not 64-byte aligned.
  55. /// | `SbiRet::invalid_address()` | The shared memory pointed to by the `shmem` parameter is not writable or does not satisfy other requirements of shared memory physical address range.
  56. /// | `SbiRet::failed()` | The request failed for unspecified or unknown other reasons.
  57. fn set_shmem(&self, shmem: SharedPtr<[u8; 64]>, flags: usize) -> SbiRet;
  58. }
  59. impl<T: Sta> Sta for &T {
  60. #[inline]
  61. fn set_shmem(&self, shmem: SharedPtr<[u8; 64]>, flags: usize) -> SbiRet {
  62. T::set_shmem(self, shmem, flags)
  63. }
  64. }