[v2,7/8] common/mlx5: add debug mode indicator

Message ID 20240612162426.978117-8-dsosnowski@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: flow fast path validation |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dariusz Sosnowski June 12, 2024, 4:24 p.m. UTC
  Add mlx5_fp_debug_enabled() function which:

- returns true if RTE_LIBRTE_MLX5_DEBUG is defined,
- returns false otherwise.

This allows for conditional execution of code meant to be executed only
when mlx5 debug mode is enabled, without adding conditional compilation
guards inside source code.
When mlx5 debug mode is disabled, any code running if
mlx5_fp_debug_enabled() returns true will be removed by optimizing
compiler due to dead code elimination.

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
---
 drivers/common/mlx5/mlx5_common.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Patch

diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 14c70edbef..1abd1e8239 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -109,6 +109,19 @@  pmd_drv_log_basename(const char *s)
 
 #endif /* RTE_LIBRTE_MLX5_DEBUG */
 
+/**
+ * Returns true if debug mode is enabled for fast path operations.
+ */
+static inline bool
+mlx5_fp_debug_enabled(void)
+{
+#ifdef RTE_LIBRTE_MLX5_DEBUG
+	return true;
+#else
+	return false;
+#endif
+}
+
 /* Allocate a buffer on the stack and fill it with a printf format string. */
 #define MKSTR(name, ...) \
 	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \