[PATCH i-g-t v3 09/13] lib/igt_drm_clients: Move engine fields to substruct
Lucas De Marchi
lucas.demarchi at intel.com
Sat May 4 06:46:39 UTC 2024
Instead of keep adding arrays, move all the arrays indexed by engine to
a substruct.
Signed-off-by: Lucas De Marchi <lucas.demarchi at 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 80bc94be4..aa88a8021 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -208,7 +208,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
More information about the igt-dev
mailing list