[PATCH i-g-t 08/12] lib/igt_drm_fdinfo: Store 2 counters for "ticks" unit

Lucas De Marchi lucas.demarchi at intel.com
Fri Apr 5 06:00:52 UTC 2024


When using "ticks" as the unit for engine busyness, 2 counters are
expected. Add the second counter and store it inside the info, together
with the unit.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_drm_fdinfo.c | 39 ++++++++++++++++++++++++++++-----------
 lib/igt_drm_fdinfo.h |  7 +++++++
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index 1541a62c9..12da1d699 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -63,7 +63,7 @@ static const char *ignore_space(const char *s)
 
 static int parse_engine(const char *name, struct drm_client_fdinfo *info,
 			const char **name_map, unsigned int map_entries,
-			uint64_t *val, const char **unit)
+			uint64_t *val, uint64_t *val2, const char **unit)
 {
 	const char *p;
 	char *end_ptr;
@@ -111,6 +111,11 @@ static int parse_engine(const char *name, struct drm_client_fdinfo *info,
 	if (p == end_ptr)
 		return -1;
 
+	if (val2) {
+		p = end_ptr;
+		*val2 = strtoull(p, &end_ptr, 10);
+	}
+
 	if (unit)
 		*unit = end_ptr;
 
@@ -218,7 +223,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
 		return 0;
 
 	while ((l = strtok_r(_buf, "\n", &ctx))) {
-		uint64_t val = 0;
+		uint64_t val = 0, val2 = 0;
 		size_t keylen;
 		const char *v, *unit;
 		char *end_ptr;
@@ -245,21 +250,33 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
 			strncpy(info->pdev, v, sizeof(info->pdev) - 1);
 		} else if (strstartswith(l, "drm-engine-capacity-", &keylen)) {
 			idx = parse_engine(l + keylen, info,
-					   name_map, map_entries, &val, NULL);
+					   name_map, map_entries, &val, NULL, NULL);
 			if (idx >= 0) {
 				info->capacity[idx] = val;
 				num_capacity++;
 			}
 		} else if (strstartswith(l, "drm-engine-", &keylen)) {
 			idx = parse_engine(l + keylen, info,
-					   name_map, map_entries, &val, &unit);
-			if (idx >= 0 && !strcmp(unit, " ns")) {
-				if (!info->capacity[idx])
-					info->capacity[idx] = 1;
-				info->busy[idx] = val;
-				info->num_engines++;
-				if (idx > info->last_engine_index)
-					info->last_engine_index = idx;
+					   name_map, map_entries, &val, &val2, &unit);
+			if (idx >= 0) {
+			       if (!strcmp(unit, " ns")) {
+				       if (!info->capacity[idx])
+					       info->capacity[idx] = 1;
+				       info->busy[idx] = val;
+				       info->unit[idx] = DRM_CLIENT_ENGINE_UNIT_NS;
+				       info->num_engines++;
+				       if (idx > info->last_engine_index)
+					       info->last_engine_index = idx;
+			       } else if (!strcmp(unit, " ticks")) {
+				       if (!info->capacity[idx])
+					       info->capacity[idx] = 1;
+				       info->busy[idx] = val;
+				       info->busy2[idx] = val2;
+				       info->unit[idx] = DRM_CLIENT_ENGINE_UNIT_TICKS;
+				       info->num_engines++;
+				       if (idx > info->last_engine_index)
+					       info->last_engine_index = idx;
+			       }
 			}
 		} else if (strstartswith(l, "drm-total-", &keylen)) {
 			idx = parse_region(l + keylen, info,
diff --git a/lib/igt_drm_fdinfo.h b/lib/igt_drm_fdinfo.h
index 1999c4f2b..7f5bafd2a 100644
--- a/lib/igt_drm_fdinfo.h
+++ b/lib/igt_drm_fdinfo.h
@@ -41,6 +41,11 @@ struct drm_client_meminfo {
 	uint64_t active;
 };
 
+enum drm_client_engine_unit {
+	DRM_CLIENT_ENGINE_UNIT_NS = 0,
+	DRM_CLIENT_ENGINE_UNIT_TICKS,
+};
+
 struct drm_client_fdinfo {
 	char driver[128];
 	char pdev[128];
@@ -51,6 +56,8 @@ struct drm_client_fdinfo {
 	unsigned int capacity[DRM_CLIENT_FDINFO_MAX_ENGINES];
 	char names[DRM_CLIENT_FDINFO_MAX_ENGINES][256];
 	uint64_t busy[DRM_CLIENT_FDINFO_MAX_ENGINES];
+	uint64_t busy2[DRM_CLIENT_FDINFO_MAX_ENGINES];
+	uint8_t unit[DRM_CLIENT_FDINFO_MAX_ENGINES];
 
 	unsigned int num_regions;
 	unsigned int last_region_index;
-- 
2.44.0



More information about the igt-dev mailing list