yanet-platform / yanet

A high performance framework for forwarding traffic based on DPDK
Other
171 stars 18 forks source link

fix: collect eth stats under the mutex #113

Closed 3Hren closed 7 months ago

3Hren commented 8 months ago

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.