-
Notifications
You must be signed in to change notification settings - Fork 25
add RtcState object #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
09c5d73
to
43c33f3
Compare
b938fd1
to
ef4d66f
Compare
src/rtc_pl031.rs
Outdated
/// Creates a new `AMBA PL031 RTC` instance from a given `state` and invokes the `rtc_events` | ||
/// implementation of `RtcEvents` during operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also add a comment about wanting to start from a clean state, in which case people should use with_events
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/rtc_pl031.rs
Outdated
/// Creates a new `AMBA PL031 RTC` instance and invokes the `rtc_events` | ||
/// implementation of `RtcEvents` during operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part about "invokes the rtc_events
" sounds like a implementation detail, and it shouldn't be part of the interface documentation. How about: "Creates a new AMBA PL031 RTC
instance that is able to track events during operation using the passed rtc_events
object." We should also add a paragraph about the state being the default one or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the documentation for with_events
and new
.
// Check that the restored `Rtc` doesn't keep the state of the old `metrics` object. | ||
assert_eq!(rtc_from_state.events.invalid_write_count.count(), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For the sake of the example, maybe it would be a good idea to have a "test as an example" where the metrics are saved as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an example, it's a bit weird though :-?.
crates/vm-superio/src/rtc_pl031.rs
Outdated
@@ -210,7 +210,7 @@ impl<EV: RtcEvents> Rtc<EV> { | |||
ris: state.ris, | |||
// A struct implementing RtcEvents for tracking the occurrence of | |||
// significant events. | |||
events, | |||
events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should not be part of the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it.
1d2b5f9
to
52ec6a3
Compare
@@ -134,6 +134,20 @@ pub struct Rtc<EV: RtcEvents> { | |||
events: EV, | |||
} | |||
|
|||
/// The state of the Rtc device. | |||
pub struct RtcState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we derive Debug
, Clone
, and PartialEq
on this structure? It would help with testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might also help to have a derive Default, but I am not sure what should be the implementation of that. Maybe we can implement default ourselves and have everything as 0s expect the LR which we can initialize as the current time on host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is already implemented for RtcState. I was using derive
initially, but switched to a manual implementation to be on the safe side, and it also helped to have a clearer documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added derives for Debug, Clone and PartialEq. I also realized now that RtcStateSer
was deriving Default. I removed the derive, we can add a manual implementation if we think it's useful, but it doesn't seem so, at least for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a Default
impl, it would look a bit awkward to convert with From
from an RtcState::default() in the consumer code in case a default RtcStateSer is needed.
impl Rtc<NoEvents> { | ||
/// Creates a new `AMBA PL031 RTC` instance without any metric capabilities. The instance is | ||
/// created from the default state. | ||
pub fn new() -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to also add a from state constructor here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, we can postpone this a bit until we have a nice idea to avoid weird naming.
531b958
to
2e8dbb0
Compare
src/rtc_pl031.rs
Outdated
assert_eq!(rtc_from_state.events.invalid_write_count.count(), 1); | ||
|
||
let state2 = rtc_from_state.state(); | ||
let metrics2 = metrics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can rename this to saved_metrics
and add a comment here that we are mimicking saving the metrics for the sake of the example so that it is a bit less weird 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
} | ||
|
||
impl RtcStateSer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for implementing new
here, and from for the reversed operation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not really, I think I was under the impression I can't implement From
here. I replaced with From
.
RtcState represents the state of the Rtc device, and is storing the state needed for restoring the device (no implementation detailis). The generic `events` object is not stored due to complexity reasons. More details in the design proposal: rust-vmm/community#118. Signed-off-by: Laura Loghin <lauralg@amazon.com>
This crate provides state objects that add serialization and versionize capabilities to the ones from vm-superio. Signed-off-by: Laura Loghin <lauralg@amazon.com>
This provides serialization capabilities to RTCState, and is defined in the vm-superio-ser crate. RtcStateSer mirrors the state structure from vm-superio and derives the required (de)serialization/versioning traits (i.e. Serialize, Deserialize, Versionize). Signed-off-by: Laura Loghin <lauralg@amazon.com>
Signed-off-by: Laura Loghin <lauralg@amazon.com>
Since now the offset & LR can be set from outside of the Rtc implementation, we need to add a checked add when computing the value of the RTC. Added a test & fix for the overflow. Signed-off-by: Andreea Florescu <fandree@amazon.com>
This PR is adding support for saving and restoring the state of the RTC device. We are starting to add this support in rust-vmm to enable snapshot use cases, such as live migration, and to unblock the consumption of components (e.g. virtio devices, legacy devices).
This is also converting vm-superio to a workspace, in which the base
vm-superio
provides the functionality required to get/set the state of the device, andvm-superio-ser
defines theRtcStateSer
object (and in the future the...StateSer
objects for the other devices).RtcStateSer
mirrors the state structure fromvm-superio
, and derives the required (de)serialization/versioning traits (i.e.Serialize
,Deserialize
,Versionize
). If we later change the state of the component, this one will have to be updated as well (by also adding the required version constraints on it).