Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [CI 2/6] lib/igt_drm_clients: Move engine fields to substruct
Date: Tue, 21 May 2024 09:15:21 -0700	[thread overview]
Message-ID: <20240521161525.159720-2-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20240521161525.159720-1-lucas.demarchi@intel.com>

Instead of keep adding arrays, move all the arrays indexed by engine to
a substruct.

Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Link: https://lore.kernel.org/r/20240504064643.25863-10-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/igt_drm_clients.c | 20 +++++++++-----------
 lib/igt_drm_clients.h | 12 ++++++++----
 tools/gputop.c        |  2 +-
 tools/intel_gpu_top.c | 14 +++++++-------
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c
index 3f4265015..91d71a7bd 100644
--- a/lib/igt_drm_clients.c
+++ b/lib/igt_drm_clients.c
@@ -109,13 +109,14 @@ igt_drm_client_update(struct igt_drm_client *c, unsigned int pid, char *name,
 	for (i = 0; i <= c->engines->max_engine_id; i++) {
 		assert(i < ARRAY_SIZE(info->engine_time));
 
-		if (info->engine_time[i] < c->last_engine_time[i])
+		if (info->engine_time[i] < c->utilization[i].last_engine_time)
 			continue; /* It will catch up soon. */
 
 		c->total_engine_time += info->engine_time[i];
-		c->delta_engine_time[i] = info->engine_time[i] - c->last_engine_time[i];
-		c->agg_delta_engine_time += c->delta_engine_time[i];
-		c->last_engine_time[i] = info->engine_time[i];
+		c->utilization[i].delta_engine_time =
+			info->engine_time[i] - c->utilization[i].last_engine_time;
+		c->agg_delta_engine_time += c->utilization[i].delta_engine_time;
+		c->utilization[i].last_engine_time = info->engine_time[i];
 	}
 
 	/* Memory regions */
@@ -183,11 +184,9 @@ igt_drm_client_add(struct igt_drm_clients *clients,
 		c->engines->max_engine_id = i;
 	}
 
-	c->delta_engine_time = calloc(c->engines->max_engine_id + 1,
-			       sizeof(*c->delta_engine_time));
-	c->last_engine_time = calloc(c->engines->max_engine_id + 1,
-			      sizeof(*c->last_engine_time));
-	assert(c->delta_engine_time && c->last_engine_time);
+	c->utilization = calloc(c->engines->max_engine_id + 1,
+				sizeof(*c->utilization));
+	assert(c->utilization);
 
 	/* Memory regions */
 	c->regions = calloc(1, sizeof(*c->regions));
@@ -225,8 +224,7 @@ void igt_drm_client_free(struct igt_drm_client *c, bool clear)
 	}
 	free(c->engines);
 
-	free(c->delta_engine_time);
-	free(c->last_engine_time);
+	free(c->utilization);
 
 	if (c->regions) {
 		for (i = 0; i <= c->regions->max_region_id; i++)
diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h
index f2ff13182..d44daa6dc 100644
--- a/lib/igt_drm_clients.h
+++ b/lib/igt_drm_clients.h
@@ -63,10 +63,14 @@ struct igt_drm_client {
 	char name[24]; /* Process name of the owning PID. */
 	char print_name[24]; /* Name without any non-printable characters. */
 	unsigned int samples; /* Count of times scanning updated this client. */
-	unsigned long total_engine_time; /* Aggregate of @agg_delta_engine_time, i.e. engine time on all engines since client start. */
-	unsigned long agg_delta_engine_time; /* Aggregate of @delta_engine_time, i.e. engine time on all engines since previous scan. */
-	unsigned long *delta_engine_time; /* Array of engine time data, relative to previous scan. */
-	uint64_t *last_engine_time; /* Array of engine time data as parsed from fdinfo. */
+
+	unsigned long total_engine_time; /* Aggregate of @utilization.agg_delta_engine_time, i.e. engine time on all engines since client start. */
+	unsigned long agg_delta_engine_time; /* Aggregate of @utilization.delta_engine_time, i.e. engine time on all engines since previous scan. */
+	struct igt_drm_client_utilization {
+		unsigned long delta_engine_time; /* Engine time data, relative to previous scan. */
+		uint64_t last_engine_time; /* Engine time data as parsed from fdinfo. */
+	} *utilization; /* Array of engine utilization */
+
 	struct drm_client_meminfo *memory; /* Array of region memory utilisation as parsed from fdinfo. */
 };
 
diff --git a/tools/gputop.c b/tools/gputop.c
index 43147e42f..c06cbe738 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -211,7 +211,7 @@ print_client(struct igt_drm_client *c, struct igt_drm_client **prevc,
 		if (!c->engines->capacity[i])
 			continue;
 
-		pct = (double)c->delta_engine_time[i] / period_us / 1e3 * 100 /
+		pct = (double)c->utilization[i].delta_engine_time / period_us / 1e3 * 100 /
 		      c->engines->capacity[i];
 
 		/*
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 35122493c..9b65ae4eb 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -893,9 +893,9 @@ static struct igt_drm_clients *display_clients(struct igt_drm_clients *clients)
 			strcpy(ac->pid_str, c->pid_str);
 			strcpy(ac->print_name, c->print_name);
 			ac->engines = c->engines;
-			ac->delta_engine_time = calloc(c->engines->max_engine_id + 1,
-						sizeof(ac->delta_engine_time[0]));
-			assert(ac->delta_engine_time);
+			ac->utilization = calloc(c->engines->max_engine_id + 1,
+						 sizeof(*ac->utilization));
+			assert(ac->utilization);
 			ac->regions = c->regions;
 			ac->memory = calloc(c->regions->max_region_id + 1,
 					    sizeof(ac->memory[0]));
@@ -912,7 +912,7 @@ static struct igt_drm_clients *display_clients(struct igt_drm_clients *clients)
 		ac->agg_delta_engine_time += c->agg_delta_engine_time;
 
 		for (i = 0; i <= c->engines->max_engine_id; i++)
-			ac->delta_engine_time[i] += c->delta_engine_time[i];
+			ac->utilization[i].delta_engine_time += c->utilization[i].delta_engine_time;
 
 		for (i = 0; i <= c->regions->max_region_id; i++) {
 			ac->memory[i].total += c->memory[i].total;
@@ -946,7 +946,7 @@ static void free_display_clients(struct igt_drm_clients *clients)
 	 * or borrowed fields which we don't want the library to try and free.
 	 */
 	igt_for_each_drm_client(clients, c, tmp) {
-		free(c->delta_engine_time);
+		free(c->utilization);
 		free(c->memory);
 	}
 
@@ -2161,7 +2161,7 @@ print_client(struct igt_drm_client *c, struct engines *engines, double t, int li
 				continue;
 			}
 
-			pct = (double)c->delta_engine_time[i] / period_us / 1e3 * 100;
+			pct = (double)c->utilization[i].delta_engine_time / period_us / 1e3 * 100;
 
 			/*
 			 * Guard against possible time-drift between sampling
@@ -2235,7 +2235,7 @@ print_client(struct igt_drm_client *c, struct engines *engines, double t, int li
 					 iclients->classes.names[i]);
 				pops->open_struct(buf);
 
-				pct = (double)c->delta_engine_time[i] / period_us / 1e3 * 100;
+				pct = (double)c->utilization[i].delta_engine_time / period_us / 1e3 * 100;
 				snprintf(buf, sizeof(buf), "%f", pct);
 				__json_add_member("busy", buf);
 
-- 
2.43.0


  reply	other threads:[~2024-05-21 16:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21 16:15 [CI 1/6] treewide: Rename engine busyness variables Lucas De Marchi
2024-05-21 16:15 ` Lucas De Marchi [this message]
2024-05-21 16:15 ` [CI 3/6] lib/igt_drm_clients: Record drm-cycles Lucas De Marchi
2024-05-21 16:15 ` [CI 4/6] lib/igt_drm_fdinfo: Parse drm-total-cycles Lucas De Marchi
2024-05-21 16:15 ` [CI 5/6] lib/igt_drm_clients: Record total cycles Lucas De Marchi
2024-05-21 16:15 ` [CI 6/6] gputop: Add support to drm-cycles/drm-total-cycles Lucas De Marchi
2024-05-21 19:00 ` ✓ Fi.CI.BAT: success for series starting with [CI,1/6] treewide: Rename engine busyness variables Patchwork
2024-05-21 19:41 ` ✗ CI.xeBAT: failure " Patchwork
2024-05-22  2:15 ` ✗ CI.xeFULL: " Patchwork
2024-05-22  8:01 ` ✓ Fi.CI.IGT: success " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240521161525.159720-2-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox