-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Migrate Metrics and the Serial device to EventManager (polly) #1494
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
Migrate Metrics and the Serial device to EventManager (polly) #1494
Conversation
@alexandruag @iulianbarbu @sandreim please review the integration of I still need to add tests before this PR is merge-able. |
018d6d2
to
e635475
Compare
@alexandruag @aghecenco @iulianbarbu I've also added tests, this PR is now complete. Please review. |
23b5f98
to
9a0e310
Compare
Both LOGGER and METRICS are Firecracker specific, not Vmm specific, and thus should not be tied to the Vmm. Logger has already been taken out of Vmm, now take the metrics periodic logging logic out of the Vmm as well. A PeriodicMetrics object is defined in the firecracker crate, which uses polly to drive periodic reporting of METRICS. Signed-off-by: Adrian Catangiu <[email protected]>
// Start the metrics. | ||
firecracker_metrics | ||
.lock() | ||
.expect("Unlock failed.") |
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: a more specific panic message would be nice.
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
} | ||
|
||
// Only used in tests, but has virtually no cost in production. | ||
self.flush_counter += 1; |
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: #[cfg(test)]
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.
error[E0658]: attributes on expressions are experimental
this is a simple counter with just increments on every flush (every 60s) so it's no runtimecost. Its purpose is to enable testing, without it we would have to drop the unittest..
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.
You can wrap it in a code block instead:
#[cfg(test)] {
self.flush_counter += 1;
}
src/vmm/src/builder.rs
Outdated
let interrupt_evt = EventFd::new(libc::EFD_NONBLOCK) | ||
.map_err(Error::EventFd) | ||
.map_err(StartMicrovmError::Internal)?; | ||
let protected_serial = EventManager::wrap_handler(devices::legacy::Serial::new_in_out( |
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: Unnecessary overhead in naming the serial as protected_serial
, serial
would do just fine.
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/polly/src/event_manager.rs
Outdated
let wrapped_handler = Arc::new(Mutex::new(handler)); | ||
self.register_protected(wrapped_handler.clone())?; | ||
Ok(wrapped_handler) | ||
pub fn wrap_handler<T: EventHandler + 'static>(handler: T) -> Arc<Mutex<T>> { |
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.
Since this only appears to call Arc::new(Mutex::new(...))
, is it really needed? It looks like invoking that sequence ourselves is also a bit shorter and clearer than writing EventManager::wrap_handler(...)
.
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
Signed-off-by: Adrian Catangiu <[email protected]>
The serial device no longer has to be injected with input from some external component. It can now be created with any input object that is 'dyn std::io::Read + std::os::unix::io::AsRawFd' and because the serial implements the EventHandler trait, it can internally handle all input. Removed the EpollDispatch::Stdin previously handled by the Vmm. The builder can build a Serial device with any input and/or output sources. Signed-off-by: Adrian Catangiu <[email protected]>
'register()' shouldn't take ownership of the handler because it could fail and on the Err path it would drop the handler. Instead of taking ownership and wrapping it then returning it in an Arc<Mutex>, just take an Arc<Mutex>. This way, the caller has maximum flexibility and can choose to provide a simple clone and doesn't lose the handler in an error case. Signed-off-by: Adrian Catangiu <[email protected]>
Remove the `RawIOHandler` trait exposed by `bus.rs`. This was previously used to get a handle on the Serial device to be able to externally inject raw input in it. With the new Serial design, that is no longer necessary, the Serial device itself can be built with any input/output sources and it will handle input and output on them internally. Signed-off-by: Adrian Catangiu <[email protected]>
Signed-off-by: Adrian Catangiu <[email protected]>
Reason for This PR
Another step in migrating Firecracker to the new
polly
event manager.Fixes #1522
Fixes #1523
Description of Changes
Metrics
Both
LOGGER
andMETRICS
are Firecracker specific, notVmm
specific, and thus should not be tied to theVmm
.Logger has already been taken out of
Vmm
, now take the metrics periodic logging logic out of theVmm
as well.A
PeriodicMetrics
object is defined in the firecracker crate, which usesEventManager
to drive periodic reporting ofMETRICS
.Serial
The serial device no longer has to be injected with input from some external component. It can now be created with any input object that is
dyn std::io::Read + std::os::unix::io::AsRawFd
.Because the serial now implements the
EventHandler
trait, it can internally handle all input.Removed the
EpollDispatch::Stdin
previously handled by theVmm
.The builder can now build a
Serial
device with any input and/or output sources.License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.