fix: collect eth stats under the mutex #113
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andrte_eth_xstats_get
are end with callingice_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.