[PATCH i-g-t v7 2/5] tools/gputop.src/utils: Add clamp macro to remove dependency on lib/xe/*

Soham Purkait
2026-01-30T09:58:38Z

Add clamp helper macro to utils.h to remove dependency on lib/xe/*

Signed-off-by: Soham Purkait <soham.purkait@intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
tools/gputop.src/utils.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/gputop.src/utils.h b/tools/gputop.src/utils.h
index 00befed56..7f3e2ac76 100644
--- a/tools/gputop.src/utils.h
+++ b/tools/gputop.src/utils.h
@@ -6,7 +6,6 @@
#ifndef COMMON_GPUTOP_H
#define COMMON_GPUTOP_H

-#include <glib.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
@@ -19,6 +18,16 @@

#define PERCLIENT_ENGINE_WIDTH 8

+#ifndef clamp
+#define clamp(val, lo, hi) \
+({ \
+ __typeof__(val) _v = (val); \
+ __typeof__(lo) _lo = (lo); \
+ __typeof__(hi) _hi = (hi); \
+ _v < _lo ? _lo : (_v > _hi ? _hi : _v); \
+})
+#endif
+
/**
* struct gputop_driver
*
--
2.34.1