Skip to content
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

fix: collect eth stats under the mutex #113

Merged
merged 1 commit into from
Feb 7, 2024
Merged

Conversation

3Hren
Copy link
Member

@3Hren 3Hren commented Feb 6, 2024

DPDK's interface for collecting device statistics is not thread-safe. However, we can easily achieve a situation when multiple threads try to collect stats for its purposes, because, for example, we spawn a separate thread for each CP-DP connection. Such thread-unsafety results in device statistics skewness, and maybe other more serious bugs. Things get even worse if we try to trace the call graph from DPDK to the drivers.

For example, both rte_eth_stats_get and rte_eth_xstats_get are end with calling ice_stats_get for ICE driver, which is also not thread-safe.

As we have these calls scattered across the entire dataplane - some of them under the "global" mutex, some are not - we have two possible ways how to solve the issue above. The first one is to protect all branches under the same mutex, but it makes the code even harder to understand. Mutext hell. The second one - is to serialize API calls, making them execute in a single thread, this is better, but requires massive code refactoring.

This PR follows the first way. Add the mutex. Pray to not be caught by deadlocks.

DPDK's interface for collecting device statistics is not thread-safe. However, we can easily achieve a situation when multiple threads try to collect stats for its purposes, because, for example, we spawn a separate thread for each CP-DP connection.
Such thread-unsafety results in device statistics skewness, and maybe other more serious bugs.
Things get even worse if we try to trace the call graph from DPDK to the drivers.

For example, both `rte_eth_stats_get` and `rte_eth_xstats_get` are end with calling `ice_stats_get` for ICE driver, which is also not thread-safe.

As we have these calls scattered across the entire dataplane - some of them under the "global" mutex, some are not - we have two possible ways how to solve the issue above. The first one is to protect all branches under the same mutex, but it makes the code even harder to understand. Mutext hell. The second one - is to serialize API calls, making them execute in a single thread, this is better, but requires massive code refactoring.

This PR follows the first way. Add the mutex. Pray to not be caught by deadlocks.
for (const auto& [portId, port] : dataPlane->ports)
{
(void)port;

rte_eth_stats stats;
memset(&stats, 0, sizeof(stats));
Copy link
Member Author

Choose a reason for hiding this comment

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

This is no longer needed, since DPDK zeroes stats for us.

@3Hren 3Hren marked this pull request as ready for review February 6, 2024 08:18
@3Hren 3Hren merged commit 43400d9 into main Feb 7, 2024
9 checks passed
@3Hren 3Hren deleted the eth-stats-thread-safety branch February 7, 2024 08:31
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.

2 participants