Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Guide/src/reference/devices/virtio/rtc.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ the [Virtio 1.4 RTC protocol][spec] (device ID 17).

## Clock and requests

The device exposes clock ID 0 with type `UTC_MAYBE_SMEARED`. Readings use
host `SystemTime` and are returned as little-endian 64-bit nanoseconds since
the Unix epoch. The host's leap-second policy is unspecified. Nanosecond
units do not imply nanosecond accuracy, and host clock adjustments can move
the reported time forward or backward.
The device exposes clock ID 0 with type `UTC_SMEARED` and an unspecified
smearing variant. Readings use host `SystemTime` and are returned as
little-endian 64-bit nanoseconds since the Unix epoch. No device-side
smearing is applied. Nanosecond units do not imply nanosecond accuracy, and
host clock adjustments can move the reported time forward or backward.

Supported requests discover the clock count, query clock capabilities, and
read the clock. Cross-timestamp capability queries succeed with no supported
Expand Down Expand Up @@ -42,11 +42,12 @@ topology requirements.

## Guest support

The guest needs a Virtio RTC driver. Linux requires `CONFIG_VIRTIO_RTC` and
`CONFIG_VIRTIO_RTC_PTP` for this clock, together with the PTP subsystem.
Linux exposes it through the associated `/dev/ptpN` clock, read using
`clock_gettime()` with the device's dynamic clock ID, not through a legacy
CMOS RTC or the guest's system clock. Providing the device does not
automatically synchronize guest system time.
Linux can register an RTC-class device with `CONFIG_VIRTIO_RTC_CLASS`.
For kernel boot-time wall-clock initialization, build in the driver with
`CONFIG_VIRTIO_RTC=y`, enable `CONFIG_RTC_HCTOSYS`, and set
`CONFIG_RTC_HCTOSYS_DEVICE` to the assigned RTC name (for example, `rtc0`).
With `CONFIG_VIRTIO_RTC_PTP` and the PTP subsystem, Linux also exposes the
clock through `/dev/ptpN`, read using `clock_gettime()` with the device's
dynamic clock ID.

[spec]: https://docs.oasis-open.org/virtio/virtio/v1.4/virtio-v1.4.html
2 changes: 1 addition & 1 deletion Guide/src/reference/openvmm/management/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describes the source definitions.
values are `auto`, `mmio`, `pci`, `pcie:PORT`, and `vpci`. Defaults to
`auto`. `--virtio-rng-pcie-port` overrides this option.
* `--virtio-rtc [bus=BUS]`: Add a Virtio 1.4 RTC device with one read-only
`UTC_MAYBE_SMEARED` clock backed by host wall time. Readings use nanosecond
`UTC_SMEARED` clock backed by host wall time. Readings use nanosecond
units; cross-timestamping and alarms are not supported. The guest needs a
Virtio RTC driver. The optional `bus` accepts `auto`, `mmio`, `pci`,
`pcie:PORT`, or `vpci`; bare `--virtio-rtc` uses `auto`. No device is added
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtio_rtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn handle_request(mem: &GuestMemory, work: &VirtioQueueCallbackWork) -> u32 {
}
let response = spec::RespClockCap {
head: ok_head(),
clock_type: spec::CLOCK_UTC_MAYBE_SMEARED,
clock_type: spec::CLOCK_UTC_SMEARED,
leap_second_smearing: spec::SMEAR_UNSPECIFIED,
flags: 0,
reserved: [0; 5],
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtio_rtc/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const S_ENODEV: u8 = 3;
pub const S_EINVAL: u8 = 4;
pub const S_EIO: u8 = 5;

pub const CLOCK_UTC_MAYBE_SMEARED: u8 = 4;
pub const CLOCK_UTC_SMEARED: u8 = 3;
pub const SMEAR_UNSPECIFIED: u8 = 0;

pub const COUNTER_ARM_VCT: u8 = 0;
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtio_rtc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async fn rtc_reports_clock_capabilities(driver: DefaultDriver) {
assert_eq!(written, size_of::<spec::RespClockCap>() as u32);
let response = spec::RespClockCap::read_from_bytes(&response).unwrap();
assert_eq!(response.head.status, spec::S_OK);
assert_eq!(response.clock_type, spec::CLOCK_UTC_MAYBE_SMEARED);
assert_eq!(response.clock_type, spec::CLOCK_UTC_SMEARED);
assert_eq!(response.leap_second_smearing, spec::SMEAR_UNSPECIFIED);
assert_eq!(response.flags, 0);
assert_eq!(response.reserved, [0; 5]);
Expand Down
Loading