Skip to content

Conversation

@aerosouund
Copy link
Contributor

@aerosouund aerosouund commented Dec 29, 2025

Changes

Building on the original PR and addressing the reviewer comments.
With the following remarks:

  • Vsock device metrics are keyed in the btreemap by the guest CID which is hardcoded for test instance to be 52. if the desire is to run the tests in a given file, it may be needed to not hardcode it
  • Entropy device metrics use a random generated UUID as the key of the map, because entropy devices don't have a unique identifier in the system that distinguishes them from one another (if one exists, let me know about it)

Reason

Closes #4709

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@aerosouund aerosouund force-pushed the vmm-parallel branch 4 times, most recently from 756a589 to ddcbe7a Compare December 29, 2025 20:06
to allow for running vmm tests in parallel

Signed-off-by: aerosouund <[email protected]>
@aerosouund aerosouund marked this pull request as ready for review December 29, 2025 20:26
Copy link
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contibution!

I only had a quick look, but I think we can simplify the logic for devices that only allow a single instance. Maybe a simple RwLock<Arc<Metrics>> would do the job.

Once we align on the solution for single-entity devices, we should also tackle all other devices using global metrics (like mem and pmem which we recently added), and simplify their unit tests as well.

Please keep different devices in different commits for clarity (and feel free to tackle one at a time if you prefer).

I'm also not a big fan of the current per-device metrics for net and block sharing the same metrics Arc if the ID happens to be the same, which defeats the purpose of not sharing metrics. As in real life we can't have devices with the same ID, I'd rather have the device create the object and replace whatever is in the hashmap rather than the other way around.

Comment on lines -246 to +256
assert_eq!(b"tap0\0\0\0\0\0\0\0\0\0\0\0\0", &tap.if_name);
assert_eq!("tap0", tap.if_name_as_str());
let tap_name_str = tap.if_name_as_str();

// Check that it starts with "tap" and the remainder is numeric.
assert!(
Regex::new(r"^tap\d+$").unwrap().is_match(tap_name_str),
"Generated tap name '{}' does not match expected pattern",
tap_name_str
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change looks unrelated. Why is it needed?

Comment on lines +58 to +80
pub struct EntropyMetricsPerDevice {
pub metrics: BTreeMap<String, Arc<EntropyDeviceMetrics>>,
}

impl EntropyMetricsPerDevice {
pub fn alloc(device_id: String) -> Arc<EntropyDeviceMetrics> {
Arc::clone(
METRICS
.write()
.unwrap()
.metrics
.entry(device_id)
.or_insert_with(|| Arc::new(EntropyDeviceMetrics::default())),
)
}
}

static METRICS: RwLock<EntropyMetricsPerDevice> = RwLock::new(EntropyMetricsPerDevice {
metrics: BTreeMap::new(),
});

#[derive(Debug, Serialize, Default)]
pub struct EntropyDeviceMetrics {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should copy the whole "PerDevice" pattern for devices that only support a single instance.
The main idea of the change is correct: decoupling the device object from the global METRICS so unit tests are independent. However, we can probably simplify this part to just hold a single Arc in the RwLock, with the Arc being created by the device (and not the other way around like in net and block, as that will make it being reused).

Comment on lines 544 to 548
check_metric_after_block!(
&METRICS.entropy_event_fails,
&dev.metrics.entropy_event_fails,
1,
dev.process_rate_limiter_event()
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need this macro hack anymore, and we could simplify this code block back to just checking the metric is now 1.

dev.process_rate_limiter_event();
assert_eq!(dev.metrics.entropy_event_fails, 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Running vmm Unittests in Parallel

2 participants