Per client GPU utilisation
Subsystems (2)
cover Per client GPU utilisation
From: Tvrtko Ursulin <[email protected]>
This series contains four main components:
1. Per client support for intel_gpu_top.
2. IGT test for per client data exposed via fdinfo from i915.
3. Extracting intel_gpu_top code into shared IGT libraries - which makes possible to write:
4. Vendor agnostic rudimentary gputop tool.
Since I had the intel_gpu_top code for years, this flow of the series is what I ended up with. But it also makes sense since we can have a cut point after intel_gpu_top, in case the common drm fdinfo specification does not end up getting enough traction. I other words, first three patches are enough for i915 side of things while the rest are optional.
Example of the intel_gpu_top output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intel-gpu-top: Intel Tigerlake (Gen12) @ /dev/dri/card0 - 220/ 221 MHz
70% RC6; 0.62/ 7.08 W; 760 irqs/s
ENGINES BUSY MI_SEMA MI_WAIT
Render/3D 23.06% |██████▊ | 0% 0%
Blitter 0.00% | | 0% 0%
Video 5.40% |█▋ | 0% 0%
VideoEnhance 20.67% |██████ | 0% 0%
PID NAME Render/3D Blitter Video VideoEnhance
3082 mpv | || ||▌ ||██ |
3117 neverball |█▉ || || || |
1 systemd |▍ || || || |
2338 gnome-shell | || || || |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example of the gputop output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DRM minor 0
PID NAME render copy video
3816 kwin_x11 |███▎ || || || |
3523 Xorg |▊ || || || |
1120449 mpv | || ||▋ || |
1120529 glxgears |▋ || || || |
1120449 mpv |▍ || || || |
3860 plasmashell |▏ || || || |
4764 krunner | || || || |
575206 chrome | || || || |
833481 firefox | || || || |
892924 thunderbird | || || || |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tvrtko Ursulin (12):
lib: Helper library for parsing i915 fdinfo output tests/i915/drm_fdinfo: Basic and functional tests for GPU busyness
exported via fdinfo
intel-gpu-top: Add support for per client stats
lib: Extract igt_drm_clients from intel_gpu_top
libdrmfdinfo: Allow specifying custom engine map
libdrmclients: Record client drm minor
libdrmclient: Support multiple DRM cards
libdrmfdinfo: Track largest engine index libdrmclient/intel_gpu_top: Decouple hardcoded engine assumptions
libdrmclient: Enforce client status sort order in the library
libdrmclient: Unexport igt_drm_client_update
gputop: Basic vendor agnostic GPU top tool
lib/igt_drm_clients.c | 443 +++++++++++++++++++++++++++++++ lib/igt_drm_clients.h | 101 +++++++ lib/igt_drm_fdinfo.c | 203 +++++++++++++++ lib/igt_drm_fdinfo.h | 54 ++++ lib/meson.build | 15 ++ man/intel_gpu_top.rst | 4 + tests/i915/drm_fdinfo.c | 565 ++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 8 + tools/gputop.c | 276 ++++++++++++++++++++ tools/intel_gpu_top.c | 497 ++++++++++++++++++++++++++++++++++- tools/meson.build | 7 +- 11 files changed, 2161 insertions(+), 12 deletions(-) create mode 100644 lib/igt_drm_clients.c create mode 100644 lib/igt_drm_clients.h create mode 100644 lib/igt_drm_fdinfo.c create mode 100644 lib/igt_drm_fdinfo.h create mode 100644 tests/i915/drm_fdinfo.c create mode 100644 tools/gputop.c
Signature · 1 line
2.32.0
PATCH 1/12 lib: Helper library for parsing i915 fdinfo output
From: Tvrtko Ursulin <[email protected]>
Tests and intel_gpu_top will share common code for parsing this file.
v2:
* Fix key-value parsing if valid key line ends with ':'.
* Add DRM_CLIENT_FDINFO_MAX_ENGINES. (Umesh)
* Always zero terminate read buffer. (Umesh)
--- lib/igt_drm_fdinfo.c | 186 +++++++++++++++++++++++++++++++++++++++++++ lib/igt_drm_fdinfo.h | 50 ++++++++++++ lib/meson.build | 7 ++ 3 files changed, 243 insertions(+) create mode 100644 lib/igt_drm_fdinfo.c create mode 100644 lib/igt_drm_fdinfo.h
lib/igt_drm_fdinfo.c new file +186 -0
@@ -0,0 +1,186 @@ +/* +* Copyright © 2022 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +*/ + +#include <ctype.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include "drmtest.h" + +#include "igt_drm_fdinfo.h" + +static size_t read_fdinfo (char *buf,const size_t sz,int at,const char *name) +{ +size_t count; +int fd; + + fd =openat (at, name,O_RDONLY ); +if (fd <0 ) +return 0 ; + + buf[sz -1 ] =0 ; + count =read (fd, buf, sz); + buf[sz -1 ] =0 ; +close (fd); + +return count; +} + +static int parse_engine (char *line,struct drm_client_fdinfo *info, +size_t prefix_len,uint64_t *val) +{ +static const char *e2class[] = { +"render" , +"copy" , +"video" , +"video-enhance" , + }; +ssize_t name_len; +char *name, *p; +int found =-1 ; +unsigned int i; + + p =index (line,':' ); +if (!p || p == line) +return -1 ; + + name_len = p - line - prefix_len; +if (name_len <1 ) +return -1 ; + + name = line + prefix_len; + +for (i =0 ; i <ARRAY_SIZE (e2class); i++) { +if (!strncmp (name, e2class[i], name_len)) { + found = i; +break ; + } + } + +if (found >=0 ) { +while (*++p &&isspace (*p)); + *val =strtoull (p,NULL ,10 ); + } + +return found; +} + +static const char *find_kv (const char *buf,const char *key,size_t keylen) +{ +const char *p = buf; + +if (strncmp (buf, key, keylen)) +return NULL ; + + p =index (buf,':' ); +if (!p || p == buf) +return NULL ; +if ((p - buf) != keylen) +return NULL ; + + p++; +while (*p &&isspace (*p)) + p++; + +return *p ? p :NULL ; +} + +bool +__igt_parse_drm_fdinfo (int dir,const char *fd,struct drm_client_fdinfo *info) +{ +char buf[4096 ], *_buf = buf; +char *l, *ctx =NULL ; +unsigned int good =0 ; +size_t count; + + count =read_fdinfo (buf,sizeof (buf), dir, fd); +if (!count) +return false; + +while ((l =strtok_r (_buf,"\n" , &ctx))) { +uint64_t val =0 ; +const char *v; +int idx; + + _buf =NULL ; + +if ((v =find_kv (l,"drm-driver" ,strlen ("drm-driver" )))) { +strncpy (info->driver, v,sizeof (info->driver) -1 ); + good++; + }else if ((v =find_kv (l,"drm-pdev" ,strlen ("drm-pdev" )))) { +strncpy (info->pdev, v,sizeof (info->pdev) -1 ); + }else if ((v =find_kv (l,"drm-client-id" , +strlen ("drm-client-id" )))) { + info->id =atol (v); + good++; + }else if (!strncmp (l,"drm-engine-" ,11 ) && +strncmp (l,"drm-engine-capacity-" ,20 )) { + idx =parse_engine (l, info,strlen ("drm-engine-" ), + &val); +if (idx >=0 ) { +if (!info->capacity[idx]) + info->capacity[idx] =1 ; + info->busy[idx] = val; + info->num_engines++; + } + }else if (!strncmp (l,"drm-engine-capacity-" ,20 )) { + idx =parse_engine (l, info, +strlen ("drm-engine-capacity-" ), + &val); +if (idx >=0 ) + info->capacity[idx] = val; + } + } + +if (good <2 || !info->num_engines) +return false;/* fdinfo format not as expected */ + +return true; +} + +bool igt_parse_drm_fdinfo (int drm_fd,struct drm_client_fdinfo *info) +{ +char fd[64 ]; +int dir, ret; +bool res; + + ret =snprintf (fd,sizeof (fd),"%u" , drm_fd); +if (ret <0 || ret ==sizeof (fd)) +return false; + + dir =open ("/proc/self/fdinfo" ,O_DIRECTORY |O_RDONLY ); +if (dir <0 ) +return false; + + res =__igt_parse_drm_fdinfo (dir, fd, info); + +close (dir); + +return res; +}
lib/igt_drm_fdinfo.h new file +50 -0
50 lines not on this page · raw message
lib/meson.build +7 -0
@@ -18,6 +18,7 @@ lib_sources = [ 'igt_debugfs.c', 'igt_device.c', 'igt_device_scan.c', + 'igt_drm_fdinfo.c', 'igt_aux.c', 'igt_gt.c', 'igt_halffloat.c',
@@ -218,6 +219,12 @@ lib_igt_device_scan_build = static_library('igt_device_scan', lib_igt_device_scan = declare_dependency(link_with : lib_igt_device_scan_build, include_directories : inc) +lib_igt_drm_fdinfo_build = static_library('igt_drm_fdinfo', + ['igt_drm_fdinfo.c'], + include_directories : inc) + +lib_igt_drm_fdinfo = declare_dependency(link_with : lib_igt_drm_fdinfo_build, + include_directories : inc) i915_perf_files = [ 'igt_list.c', 'i915/perf.c',
Signature · 1 line
2.32.0
PATCH 2/12 tests/i915/drm_fdinfo: Basic and functional tests for GPU busyness exported via fdinfo
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Mostly inherited from the perf_pmu, some basic tests, and some tests to verify exported GPU busyness is as expected.
--- tests/i915/drm_fdinfo.c | 555 ++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 8 + 2 files changed, 563 insertions(+) create mode 100644 tests/i915/drm_fdinfo.c
tests/i915/drm_fdinfo.c new file +555 -0
@@ -0,0 +1,555 @@ +/* +* Copyright © 2022 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +*/ + +#include "igt.h" +#include "igt_core.h" +#include "igt_device.h" +#include "igt_drm_fdinfo.h" +#include "i915/gem.h" +#include "intel_ctx.h" + +IGT_TEST_DESCRIPTION ("Test the i915 drm fdinfo data" ); + +const double tolerance =0.05f ; +const unsigned long batch_duration_ns =500e6 ; + +#define __assert_within_epsilon (x, ref, tol_up, tol_down) \ + igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ + (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \ + "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n",\ + #x, #ref, (double)(x), \ + (tol_up) * 100.0, (tol_down) * 100.0, \ + (double)(ref)) + +#define assert_within_epsilon (x, ref, tolerance) \ + __assert_within_epsilon(x, ref, tolerance, tolerance) + +static void basics (int i915,unsigned int num_classes) +{ +struct drm_client_fdinfo info = { }; +bool ret; + + ret =igt_parse_drm_fdinfo (i915, &info); +igt_assert (ret); + +igt_assert (!strcmp (info.driver,"i915" )); + +igt_assert_eq (info.num_engines, num_classes); +} + +/* +* Helper for cases where we assert on time spent sleeping (directly or +* indirectly), so make it more robust by ensuring the system sleep time +* is within test tolerance to start with. +*/ +static unsigned int measured_usleep (unsigned int usec) +{ +struct timespec ts = { }; +unsigned int slept; + + slept =igt_nsec_elapsed (&ts); +igt_assert (slept ==0 ); +do { +usleep (usec - slept); + slept =igt_nsec_elapsed (&ts) /1000 ; + }while (slept < usec); + +return igt_nsec_elapsed (&ts); +} + +#define TEST_BUSY (1) +#define FLAG_SYNC (2) +#define TEST_TRAILING_IDLE (4) +#define FLAG_HANG (8) +#define TEST_ISOLATION (16) + +static igt_spin_t *__spin_poll (int fd,uint64_t ahnd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e) +{ +struct igt_spin_factory opts = { + .ahnd = ahnd, + .ctx = ctx, + .engine = e->flags, + }; + +if (gem_class_can_store_dword (fd, e->class)) + opts.flags |=IGT_SPIN_POLL_RUN ; + +return __igt_spin_factory (fd, &opts); +} + +static unsigned long __spin_wait (int fd,igt_spin_t *spin) +{ +struct timespec start = { }; + +igt_nsec_elapsed (&start); + +if (igt_spin_has_poll (spin)) { +unsigned long timeout =0 ; + +while (!igt_spin_has_started (spin)) { +unsigned long t =igt_nsec_elapsed (&start); + +igt_assert (gem_bo_busy (fd, spin->handle)); +if ((t - timeout) >250e6 ) { + timeout = t; +igt_warn ("Spinner not running after %.2fms\n" , + (double )t /1e6 ); +igt_assert (t <2e9 ); + } + } + }else { +igt_debug ("__spin_wait - usleep mode\n" ); +usleep (500e3 );/* Better than nothing! */ + } + +igt_assert (gem_bo_busy (fd, spin->handle)); +return igt_nsec_elapsed (&start); +} + +static igt_spin_t *__spin_sync (int fd,uint64_t ahnd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e) +{ +igt_spin_t *spin =__spin_poll (fd, ahnd, ctx, e); + +__spin_wait (fd, spin); + +return spin; +} + +static igt_spin_t *spin_sync (int fd,uint64_t ahnd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e) +{ +igt_require_gem (fd); + +return __spin_sync (fd, ahnd, ctx, e); +} + +static void end_spin (int fd,igt_spin_t *spin,unsigned int flags) +{ +if (!spin) +return ; + +igt_spin_end (spin); + +if (flags &FLAG_SYNC ) +gem_sync (fd, spin->handle); + +if (flags &TEST_TRAILING_IDLE ) { +unsigned long t, timeout =0 ; +struct timespec start = { }; + +igt_nsec_elapsed (&start); + +do { + t =igt_nsec_elapsed (&start); + +if (gem_bo_busy (fd, spin->handle) && + (t - timeout) >10e6 ) { + timeout = t; +igt_warn ("Spinner not idle after %.2fms\n" , + (double )t /1e6 ); + } + +usleep (1e3 ); + }while (t < batch_duration_ns /5 ); + } +} + +static uint64_t read_busy (int i915,unsigned int class) +{ +struct drm_client_fdinfo info = { }; + +igt_assert (igt_parse_drm_fdinfo (i915, &info)); + +return info.busy[class]; +} + +static void +single (int gem_fd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e,unsigned int flags) +{ +unsigned long slept; +igt_spin_t *spin; +uint64_t val; +int spin_fd; +uint64_t ahnd; + +if (flags &TEST_ISOLATION ) { + spin_fd =gem_reopen_driver (gem_fd); + ctx =intel_ctx_create_all_physical (spin_fd); + }else { + spin_fd = gem_fd; + } + + ahnd =get_reloc_ahnd (spin_fd, ctx->id); + +if (flags &TEST_BUSY ) + spin =spin_sync (spin_fd, ahnd, ctx, e); +else + spin =NULL ; + + val =read_busy (gem_fd, e->class); + slept =measured_usleep (batch_duration_ns /1000 ); +if (flags &TEST_TRAILING_IDLE ) +end_spin (spin_fd, spin, flags); + val =read_busy (gem_fd, e->class) - val; + +if (flags &FLAG_HANG ) +igt_force_gpu_reset (spin_fd); +else +end_spin (spin_fd, spin,FLAG_SYNC ); + +assert_within_epsilon (val, + (flags &TEST_BUSY ) && !(flags &TEST_ISOLATION ) ? + slept :0.0f , + tolerance); + +/* Check for idle after hang. */ +if (flags &FLAG_HANG ) { +gem_quiescent_gpu (spin_fd); +igt_assert (!gem_bo_busy (spin_fd, spin->handle)); + + val =read_busy (gem_fd, e->class); + slept =measured_usleep (batch_duration_ns /1000 ); + val =read_busy (gem_fd, e->class) - val; + +assert_within_epsilon (val,0 , tolerance); + } + +igt_spin_free (spin_fd, spin); +put_ahnd (ahnd); + +gem_quiescent_gpu (spin_fd); +} + +static void log_busy (unsigned int num_engines,uint64_t *val) +{ +char buf[1024 ]; +int rem =sizeof (buf); +unsigned int i; +char *p = buf; + +for (i =0 ; i < num_engines; i++) { +int len; + + len =snprintf (p, rem,"%u=%" PRIu64"\n" , i, val[i]); +igt_assert (len >0 ); + rem -= len; + p += len; + } + +igt_info ("%s" , buf); +} + +static void read_busy_all (int i915,uint64_t *val) +{ +struct drm_client_fdinfo info = { }; + +igt_assert (igt_parse_drm_fdinfo (i915, &info)); + +memcpy (val, info.busy,sizeof (info.busy)); +} + +static void +busy_check_all (int gem_fd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e, +const unsigned int num_engines, +const unsigned int classes[16 ],const unsigned int num_classes, +unsigned int flags) +{ +uint64_t ahnd =get_reloc_ahnd (gem_fd, ctx->id); +uint64_t tval[2 ][16 ]; +unsigned long slept; +uint64_t val[16 ]; +igt_spin_t *spin; +unsigned int i; + +memset (tval,0 ,sizeof (tval)); + + spin =spin_sync (gem_fd, ahnd, ctx, e); + +read_busy_all (gem_fd, tval[0 ]); + slept =measured_usleep (batch_duration_ns /1000 ); +if (flags &TEST_TRAILING_IDLE ) +end_spin (gem_fd, spin, flags); +read_busy_all (gem_fd, tval[1 ]); + +end_spin (gem_fd, spin,FLAG_SYNC ); +igt_spin_free (gem_fd, spin); +put_ahnd (ahnd); + +for (i =0 ; i < num_classes; i++) + val[i] = tval[1 ][i] - tval[0 ][i]; + +log_busy (num_classes, val); + +for (i =0 ; i < num_classes; i++) { +double target = i == e->class ? slept :0.0f ; + +assert_within_epsilon (val[i], target, tolerance); + } + +gem_quiescent_gpu (gem_fd); +} + +static void +__submit_spin (int gem_fd,igt_spin_t *spin, +const struct intel_execution_engine2 *e, +int offset) +{ +struct drm_i915_gem_execbuffer2 eb = spin->execbuf; + + eb.flags &= ~(0x3f |I915_EXEC_BSD_MASK ); + eb.flags |= e->flags |I915_EXEC_NO_RELOC ; + eb.batch_start_offset += offset; + +gem_execbuf (gem_fd, &eb); +} + +static void +most_busy_check_all (int gem_fd,const intel_ctx_t *ctx, +const struct intel_execution_engine2 *e, +const unsigned int num_engines, +const unsigned int classes[16 ], +const unsigned int num_classes, +unsigned int flags) +{ +uint64_t ahnd =get_reloc_ahnd (gem_fd, ctx->id); +unsigned int busy_class[num_classes]; +struct intel_execution_engine2 *e_; +igt_spin_t *spin =NULL ; +uint64_t tval[2 ][16 ]; +unsigned long slept; +uint64_t val[16 ]; +unsigned int i; + +memset (busy_class,0 ,sizeof (busy_class)); +memset (tval,0 ,sizeof (tval)); + +for_each_ctx_engine (gem_fd, ctx, e_) { +if (e->class == e_->class && e->instance == e_->instance) { +continue ; + }else if (spin) { +__submit_spin (gem_fd, spin, e_,64 ); + busy_class[e_->class]++; + }else { + spin =__spin_poll (gem_fd, ahnd, ctx, e_); + busy_class[e_->class]++; + } + } +igt_require (spin);/* at least one busy engine */ + +/* Small delay to allow engines to start. */ +usleep (__spin_wait (gem_fd, spin) * num_engines /1e3 ); + +read_busy_all (gem_fd, tval[0 ]); + slept =measured_usleep (batch_duration_ns /1000 ); +if (flags &TEST_TRAILING_IDLE ) +end_spin (gem_fd, spin, flags); +read_busy_all (gem_fd, tval[1 ]); + +end_spin (gem_fd, spin,FLAG_SYNC ); +igt_spin_free (gem_fd, spin); +put_ahnd (ahnd); + +for (i =0 ; i < num_classes; i++) + val[i] = tval[1 ][i] - tval[0 ][i]; + +log_busy (num_classes, val); + +for (i =0 ; i < num_classes; i++) { +double target = slept * busy_class[i]; + +assert_within_epsilon (val[i], target, tolerance); + } +gem_quiescent_gpu (gem_fd); +} + +static void +all_busy_check_all (int gem_fd,const intel_ctx_t *ctx, +const unsigned int num_engines, +const unsigned int classes[16 ], +const unsigned int num_classes, +unsigned int flags) +{ +uint64_t ahnd =get_reloc_ahnd (gem_fd, ctx->id); +unsigned int busy_class[num_classes]; +struct intel_execution_engine2 *e; +igt_spin_t *spin =NULL ; +uint64_t tval[2 ][16 ]; +unsigned long slept; +uint64_t val[16 ]; +unsigned int i; + +memset (busy_class,0 ,sizeof (busy_class)); +memset (tval,0 ,sizeof (tval)); + +for_each_ctx_engine (gem_fd, ctx, e) { +if (spin) +__submit_spin (gem_fd, spin, e,64 ); +else + spin =__spin_poll (gem_fd, ahnd, ctx, e); + busy_class[e->class]++; + } + +/* Small delay to allow engines to start. */ +usleep (__spin_wait (gem_fd, spin) * num_engines /1e3 ); + +read_busy_all (gem_fd, tval[0 ]); + slept =measured_usleep (batch_duration_ns /1000 ); +if (flags &TEST_TRAILING_IDLE ) +end_spin (gem_fd, spin, flags); +read_busy_all (gem_fd, tval[1 ]); + +end_spin (gem_fd, spin,FLAG_SYNC ); +igt_spin_free (gem_fd, spin); +put_ahnd (ahnd); + +for (i =0 ; i < num_classes; i++) + val[i] = tval[1 ][i] - tval[0 ][i]; + +log_busy (num_classes, val); + +for (i =0 ; i < num_classes; i++) { +double target = slept * busy_class[i]; + +assert_within_epsilon (val[i], target, tolerance); + } +gem_quiescent_gpu (gem_fd); +} + +#define test_each_engine (T , i915, ctx, e) \ + igt_subtest_with_dynamic(T) for_each_ctx_engine(i915, ctx, e) \ + igt_dynamic_f("%s", e->name) + +igt_main +{ +unsigned int num_engines =0 , num_classes =0 ; +const struct intel_execution_engine2 *e; +unsigned int classes[16 ] = { }; +const intel_ctx_t *ctx =NULL ; +int i915 =-1 ; + + igt_fixture { +unsigned int i; + + i915 =__drm_open_driver (DRIVER_INTEL ); + +igt_require_gem (i915); + + ctx =intel_ctx_create_all_physical (i915); + +for_each_ctx_engine (i915, ctx, e) { + num_engines++; +igt_assert (e->class <ARRAY_SIZE (classes)); + classes[e->class]++; + } +igt_require (num_engines); + +for (i =0 ; i <ARRAY_SIZE (classes); i++) { +if (classes[i]) + num_classes++; + } +igt_assert (num_classes); + } + +/** +* Test basic fdinfo content. +*/ + igt_subtest("basics") +basics (i915, num_classes); + +/** +* Test that engines show no load when idle. +*/ + test_each_engine("idle", i915, ctx, e) +single (i915, ctx, e,0 ); + +/** +* Test that a single engine reports load correctly. +*/ + test_each_engine("busy", i915, ctx, e) +single (i915, ctx, e,TEST_BUSY ); + + test_each_engine("busy-idle", i915, ctx, e) +single (i915, ctx, e,TEST_BUSY |TEST_TRAILING_IDLE ); + + test_each_engine("busy-hang", i915, ctx, e) { +igt_hang_t hang =igt_allow_hang (i915, ctx->id,0 ); + +single (i915, ctx, e,TEST_BUSY |FLAG_HANG ); + +igt_disallow_hang (i915, hang); + } + +/** +* Test that when one engine is loaded other report no +* load. +*/ + test_each_engine("busy-check-all", i915, ctx, e) +busy_check_all (i915, ctx, e, num_engines, classes, num_classes, +TEST_BUSY ); + + test_each_engine("busy-idle-check-all", i915, ctx, e) +busy_check_all (i915, ctx, e, num_engines, classes, num_classes, +TEST_BUSY |TEST_TRAILING_IDLE ); + +/** +* Test that when all except one engine are loaded all +* loads are correctly reported. +*/ + test_each_engine("most-busy-check-all", i915, ctx, e) +most_busy_check_all (i915, ctx, e, num_engines, + classes, num_classes, +TEST_BUSY ); + + test_each_engine("most-busy-idle-check-all", i915, ctx, e) +most_busy_check_all (i915, ctx, e, num_engines, + classes, num_classes, +TEST_BUSY |TEST_TRAILING_IDLE ); + +/** +* Test that when all engines are loaded all loads are +* correctly reported. +*/ + igt_subtest("all-busy-check-all") +all_busy_check_all (i915, ctx, num_engines, classes, num_classes, +TEST_BUSY ); + + igt_subtest("all-busy-idle-check-all") +all_busy_check_all (i915, ctx, num_engines, classes, num_classes, +TEST_BUSY |TEST_TRAILING_IDLE ); + +/** +* Test for no cross-client contamination. +*/ + test_each_engine("isolation", i915, ctx, e) +single (i915, ctx, e,TEST_BUSY |TEST_ISOLATION ); + + igt_fixture { +intel_ctx_destroy (i915, ctx); +close (i915); + } +}
tests/meson.build +8 -0
@@ -293,6 +293,14 @@ foreach prog : i915_progs test_list += prog endforeach +test_executables += executable('drm_fdinfo', + join_paths('i915', 'drm_fdinfo.c'), + dependencies : test_deps + [ lib_igt_drm_fdinfo ], + install_dir : libexecdir, + install_rpath : libexecdir_rpathdir, + install : true) +test_list += 'drm_fdinfo' + test_executables += executable('dumb_buffer', 'dumb_buffer.c', dependencies : test_deps + [ libatomic ], install_dir : libexecdir,
Signature · 1 line
2.32.0
PATCH 3/12 intel-gpu-top: Add support for per client stats
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Use the i915 exported data in /proc/<pid>/fdinfo to show GPU utilization per DRM client.
Example of the output:
intel-gpu-top: Intel Tigerlake (Gen12) @ /dev/dri/card0 - 220/ 221 MHz
70% RC6; 0.62/ 7.08 W; 760 irqs/s
ENGINES BUSY MI_SEMA MI_WAIT
Render/3D 23.06% |██████▊ | 0% 0%
Blitter 0.00% | | 0% 0%
Video 5.40% |█▋ | 0% 0%
VideoEnhance 20.67% |██████ | 0% 0%
PID NAME Render/3D Blitter Video VideoEnhance
3082 mpv | || ||▌ ||██ |
3117 neverball |█▉ || || || |
1 systemd |▍ || || || |
2338 gnome-shell | || || || |--- man/intel_gpu_top.rst | 4 + tools/intel_gpu_top.c | 801 +++++++++++++++++++++++++++++++++++++++++- tools/meson.build | 2 +- 3 files changed, 804 insertions(+), 3 deletions(-)
man/intel_gpu_top.rst +4 -0
@@ -56,6 +56,10 @@ Supported keys: 'q' Exit from the tool. 'h' Show interactive help. '1' Toggle between aggregated engine class and physical engine mode. + 'n' Toggle display of numeric client busyness overlay. + 's' Toggle between sort modes (runtime, total runtime, pid, client id). + 'i' Toggle display of clients which used no GPU time. + 'H' Toggle between per PID aggregation and individual clients. DEVICE SELECTION ================
tools/intel_gpu_top.c +799 -2
892 lines not on this page · raw message
tools/meson.build +1 -1
@@ -91,7 +91,7 @@ install_subdir('registers', install_dir : datadir) executable('intel_gpu_top', 'intel_gpu_top.c', install : true, install_rpath : bindir_rpathdir, - dependencies : [lib_igt_perf,lib_igt_device_scan,math]) + dependencies : [lib_igt_perf,lib_igt_device_scan,lib_igt_drm_fdinfo,math]) executable('amd_hdmi_compliance', 'amd_hdmi_compliance.c', dependencies : [tool_deps],
Signature · 1 line
2.32.0
PATCH 4/12 lib: Extract igt_drm_clients from intel_gpu_top
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Code movement with some improvements to prepare for further work in making a vendor agnostic gputop tool possible.
--- lib/igt_drm_clients.c | 386 +++++++++++++++++++++++++++++++ lib/igt_drm_clients.h | 102 +++++++++ lib/meson.build | 8 + tools/intel_gpu_top.c | 516 ++++++------------------------------------ tools/meson.build | 2 +- 5 files changed, 570 insertions(+), 444 deletions(-) create mode 100644 lib/igt_drm_clients.c create mode 100644 lib/igt_drm_clients.h
lib/igt_drm_clients.c new file +386 -0
@@ -0,0 +1,386 @@ +/* +* Copyright © 2022 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +*/ + +#include <assert.h> +#include <ctype.h> +#include <dirent.h> +#include <fcntl.h> +#include <stdbool.h> +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <sys/types.h> +#include <unistd.h> + +#include "igt_drm_clients.h" +#include "igt_drm_fdinfo.h" + +struct igt_drm_clients *igt_drm_clients_init (void *private_data) +{ +struct igt_drm_clients *clients; + + clients =malloc (sizeof (*clients)); +if (!clients) +return NULL ; + +memset (clients,0 ,sizeof (*clients)); + + clients->private_data = private_data; + +return clients; +} + +struct igt_drm_client * +igt_drm_clients_find (struct igt_drm_clients *clients, +enum igt_drm_client_status status, +unsigned int id) +{ +unsigned int start, num; +struct igt_drm_client *c; + + start = status ==IGT_DRM_CLIENT_FREE ? clients->active_clients :0 ;/* Free block at the end. */ + num = clients->num_clients - start; + +for (c = &clients->client[start]; num; c++, num--) { +if (status != c->status) +continue ; + +if (status ==IGT_DRM_CLIENT_FREE || c->id == id) +return c; + } + +return NULL ; +} + +void +igt_drm_client_update (struct igt_drm_client *c,unsigned int pid,char *name, +uint64_t val[16 ]) +{ +unsigned int i; + +if (c->pid != pid) + c->pid = pid; + +if (strcmp (c->name, name)) { +char *p; + +strncpy (c->name, name,sizeof (c->name) -1 ); +strncpy (c->print_name, name,sizeof (c->print_name) -1 ); + + p = c->print_name; +while (*p) { +if (!isprint (*p)) + *p ='*' ; + p++; + } + } + + c->last_runtime =0 ; + c->total_runtime =0 ; + +for (i =0 ; i < c->clients->num_classes; i++) { +if (val[i] < c->last[i]) +continue ;/* It will catch up soon. */ + + c->total_runtime += val[i]; + c->val[i] = val[i] - c->last[i]; + c->last_runtime += c->val[i]; + c->last[i] = val[i]; + } + + c->samples++; + c->status =IGT_DRM_CLIENT_ALIVE ; +} + +void +igt_drm_client_add (struct igt_drm_clients *clients,unsigned int id, +unsigned int pid,char *name,uint64_t busy[16 ]) +{ +struct igt_drm_client *c; + +assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , id)); + + c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_FREE ,0 ); +if (!c) { +unsigned int idx = clients->num_clients; + + clients->num_clients += (clients->num_clients +2 ) /2 ; + clients->client =realloc (clients->client, + clients->num_clients *sizeof (*c)); +assert (clients->client); + + c = &clients->client[idx]; +memset (c,0 , (clients->num_clients - idx) *sizeof (*c)); + } + + c->id = id; + c->clients = clients; + c->val =calloc (clients->num_classes,sizeof (c->val)); + c->last =calloc (clients->num_classes,sizeof (c->last)); +assert (c->val && c->last); + +igt_drm_client_update (c, pid, name, busy); +} + +void igt_drm_client_free (struct igt_drm_client *c) +{ +free (c->val); +free (c->last); +memset (c,0 ,sizeof (*c)); +} + +struct igt_drm_clients * +igt_drm_clients_sort (struct igt_drm_clients *clients, +int (*cmp)(const void *,const void *)) +{ +unsigned int active, free; +struct igt_drm_client *c; +int tmp; + +if (!clients) +return clients; + +qsort (clients->client, clients->num_clients,sizeof (*clients->client), + cmp); + +/* Trim excessive array space. */ + active =0 ; +igt_for_each_drm_client (clients, c, tmp) { +if (c->status !=IGT_DRM_CLIENT_ALIVE ) +break ;/* Active clients are first in the array. */ + active++; + } + + clients->active_clients = active; + + free = clients->num_clients - active; +if (free > clients->num_clients /2 ) { + active = clients->num_clients - free /2 ; +if (active != clients->num_clients) { + clients->num_clients = active; + clients->client =realloc (clients->client, + clients->num_clients * +sizeof (*c)); + } + } + +return clients; +} + +void igt_drm_clients_free (struct igt_drm_clients *clients) +{ +struct igt_drm_client *c; +unsigned int tmp; + +igt_for_each_drm_client (clients, c, tmp) +igt_drm_client_free (c); + +free (clients->client); +free (clients); +} + +static DIR *opendirat (int at,const char *name) +{ +DIR *dir; +int fd; + + fd =openat (at, name,O_DIRECTORY ); +if (fd <0 ) +return NULL ; + + dir =fdopendir (fd); +if (!dir) +close (fd); + +return dir; +} + +static size_t readat2buf (char *buf,const size_t sz,int at,const char *name) +{ +size_t count; +int fd; + + fd =openat (at, name,O_RDONLY ); +if (fd <0 ) +return 0 ; + + buf[sz -1 ] =0 ; + count =read (fd, buf, sz); +close (fd); + +return count; +} + +static bool get_task_name (const char *buffer,char *out,unsigned long sz) +{ +char *s =index (buffer,'(' ); +char *e =rindex (buffer,')' ); +unsigned int len; + +if (!s || !e) +return false; + + len = --e - ++s +1 ; +if (!len || (len +1 ) >= sz) +return false; + +strncpy (out, s, len); + out[len] =0 ; + +return true; +} + +static bool is_drm_fd (int fd_dir,const char *name) +{ +struct stat stat; +int ret; + + ret =fstatat (fd_dir, name, &stat,0 ); + +return ret ==0 && + (stat.st_mode &S_IFMT ) ==S_IFCHR && +major (stat.st_rdev) ==226 ; +} + +struct igt_drm_clients * +igt_drm_clients_scan (struct igt_drm_clients *clients, +bool (*filter_client)(const struct igt_drm_clients *, +const struct drm_client_fdinfo *)) +{ +struct dirent *proc_dent; +struct igt_drm_client *c; +DIR *proc_dir; +int tmp; + +if (!clients) +return clients; + +igt_for_each_drm_client (clients, c, tmp) { +assert (c->status !=IGT_DRM_CLIENT_PROBE ); +if (c->status ==IGT_DRM_CLIENT_ALIVE ) + c->status =IGT_DRM_CLIENT_PROBE ; +else +break ;/* Free block at the end of array. */ + } + + proc_dir =opendir ("/proc" ); +if (!proc_dir) +return clients; + +while ((proc_dent =readdir (proc_dir)) !=NULL ) { +int pid_dir =-1 , fd_dir =-1 ; +struct dirent *fdinfo_dent; +char client_name[64 ] = { }; +unsigned int client_pid; +DIR *fdinfo_dir =NULL ; +char buf[4096 ]; +size_t count; + +if (proc_dent->d_type !=DT_DIR ) +continue ; +if (!isdigit (proc_dent->d_name[0 ])) +continue ; + + pid_dir =openat (dirfd (proc_dir), proc_dent->d_name, +O_DIRECTORY |O_RDONLY ); +if (pid_dir <0 ) +continue ; + + count =readat2buf (buf,sizeof (buf), pid_dir,"stat" ); +if (!count) + goto next; + + client_pid =atoi (buf); +if (!client_pid) + goto next; + +if (!get_task_name (buf, client_name,sizeof (client_name))) + goto next; + + fd_dir =openat (pid_dir,"fd" ,O_DIRECTORY |O_RDONLY ); +if (fd_dir <0 ) + goto next; + + fdinfo_dir =opendirat (pid_dir,"fdinfo" ); +if (!fdinfo_dir) + goto next; + +while ((fdinfo_dent =readdir (fdinfo_dir)) !=NULL ) { +struct drm_client_fdinfo info; + +if (fdinfo_dent->d_type !=DT_REG ) +continue ; +if (!isdigit (fdinfo_dent->d_name[0 ])) +continue ; + +if (!is_drm_fd (fd_dir, fdinfo_dent->d_name)) +continue ; + +memset (&info,0 ,sizeof (info)); + +if (!__igt_parse_drm_fdinfo (dirfd (fdinfo_dir), + fdinfo_dent->d_name, + &info)) +continue ; + +if (filter_client && !filter_client (clients, &info)) +continue ; + +if (igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , + info.id)) +continue ;/* Skip duplicate fds. */ + + c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_PROBE , + info.id); +if (!c) +igt_drm_client_add (clients, info.id, client_pid, + client_name, info.busy); +else +igt_drm_client_update (c, client_pid, + client_name, info.busy); + } + +next: +if (fdinfo_dir) +closedir (fdinfo_dir); +if (fd_dir >=0 ) +close (fd_dir); +if (pid_dir >=0 ) +close (pid_dir); + } + +closedir (proc_dir); + +igt_for_each_drm_client (clients, c, tmp) { +if (c->status ==IGT_DRM_CLIENT_PROBE ) +igt_drm_client_free (c); +else if (c->status ==IGT_DRM_CLIENT_FREE ) +break ; + } + +return clients; +}
lib/igt_drm_clients.h new file +102 -0
102 lines not on this page · raw message
lib/meson.build +8 -0
@@ -18,6 +18,7 @@ lib_sources = [ 'igt_debugfs.c', 'igt_device.c', 'igt_device_scan.c', + 'igt_drm_clients.h', 'igt_drm_fdinfo.c', 'igt_aux.c', 'igt_gt.c',
@@ -219,6 +220,13 @@ lib_igt_device_scan_build = static_library('igt_device_scan', lib_igt_device_scan = declare_dependency(link_with : lib_igt_device_scan_build, include_directories : inc) +lib_igt_drm_clients_build = static_library('igt_drm_clients', + ['igt_drm_clients.c'], + include_directories : inc) + +lib_igt_drm_clients = declare_dependency(link_with : lib_igt_drm_clients_build, + include_directories : inc) + lib_igt_drm_fdinfo_build = static_library('igt_drm_fdinfo', ['igt_drm_fdinfo.c'], include_directories : inc)
tools/intel_gpu_top.c +73 -443
731 lines not on this page · raw message
tools/meson.build +1 -1
@@ -91,7 +91,7 @@ install_subdir('registers', install_dir : datadir) executable('intel_gpu_top', 'intel_gpu_top.c', install : true, install_rpath : bindir_rpathdir, - dependencies : [lib_igt_perf,lib_igt_device_scan,lib_igt_drm_fdinfo,math]) + dependencies : [lib_igt_perf,lib_igt_device_scan,lib_igt_drm_clients,lib_igt_drm_fdinfo,math]) executable('amd_hdmi_compliance', 'amd_hdmi_compliance.c', dependencies : [tool_deps],
Signature · 1 line
2.32.0
PATCH 5/12 libdrmfdinfo: Allow specifying custom engine map
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Instead of hard coding the engine names, allow a map of names to indices to either be passed in or it gets auto-detected (less efficient) while parsing.
--- lib/igt_drm_clients.c | 7 +++--- lib/igt_drm_clients.h | 3 ++- lib/igt_drm_fdinfo.c | 47 +++++++++++++++++++++++++++-------------- lib/igt_drm_fdinfo.h | 7 ++++-- tests/i915/drm_fdinfo.c | 16 +++++++++++--- tools/intel_gpu_top.c | 13 ++++++++++-- 6 files changed, 66 insertions(+), 27 deletions(-)
lib/igt_drm_clients.c +4 -3
@@ -269,7 +269,8 @@ static bool is_drm_fd(int fd_dir, const char *name)struct igt_drm_clients *igt_drm_clients_scan (struct igt_drm_clients *clients,bool (*filter_client)(const struct igt_drm_clients *, -const struct drm_client_fdinfo *)) +const struct drm_client_fdinfo *), +const char **name_map,unsigned int map_entries) {struct dirent *proc_dent;struct igt_drm_client *c;
@@ -343,8 +344,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,memset (&info,0 ,sizeof (info));if (!__igt_parse_drm_fdinfo (dirfd (fdinfo_dir), - fdinfo_dent->d_name, - &info)) + fdinfo_dent->d_name, &info, + name_map, map_entries))continue ;if (filter_client && !filter_client (clients, &info))
lib/igt_drm_clients.h +2 -1
@@ -80,7 +80,8 @@ void igt_drm_clients_free(struct igt_drm_clients *clients);struct igt_drm_clients *igt_drm_clients_scan (struct igt_drm_clients *clients,bool (*filter_client)(const struct igt_drm_clients *, -const struct drm_client_fdinfo *)); +const struct drm_client_fdinfo *), +const char **name_map,unsigned int map_entries);struct igt_drm_client * igt_drm_clients_find(struct igt_drm_clients *clients,
lib/igt_drm_fdinfo.c +31 -16
96 lines not on this page · raw message
lib/igt_drm_fdinfo.h +5 -2
@@ -39,12 +39,15 @@ struct drm_client_fdinfo {unsigned int num_engines;unsigned int capacity[DRM_CLIENT_FDINFO_MAX_ENGINES ]; +char names[DRM_CLIENT_FDINFO_MAX_ENGINES ][256 ]; uint64_t busy[DRM_CLIENT_FDINFO_MAX_ENGINES]; }; -bool igt_parse_drm_fdinfo (int drm_fd,struct drm_client_fdinfo *info); +bool igt_parse_drm_fdinfo (int drm_fd,struct drm_client_fdinfo *info, +const char **name_map,unsigned int map_entries);bool __igt_parse_drm_fdinfo (int dir,const char *fd, -struct drm_client_fdinfo *info); +struct drm_client_fdinfo *info, +const char **name_map,unsigned int map_entries);#endif /* IGT_DRM_FDINFO_H */
tests/i915/drm_fdinfo.c +13 -3
@@ -34,6 +34,13 @@ IGT_TEST_DESCRIPTION("Test the i915 drm fdinfo data");const double tolerance =0.05f ;const unsigned long batch_duration_ns =500e6 ; +static const char *engine_map[] = { +"render" , +"copy" , +"video" , +"video-enhance" , +}; +#define __assert_within_epsilon (x, ref, tol_up, tol_down) \ igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \
@@ -50,7 +57,8 @@ static void basics(int i915, unsigned int num_classes)struct drm_client_fdinfo info = { };bool ret; - ret =igt_parse_drm_fdinfo (i915, &info); + ret =igt_parse_drm_fdinfo (i915, &info, engine_map, +ARRAY_SIZE (engine_map));igt_assert (ret);igt_assert (!strcmp (info.driver,"i915" ));
@@ -181,7 +189,8 @@ static uint64_t read_busy(int i915, unsigned int class) {struct drm_client_fdinfo info = { }; -igt_assert (igt_parse_drm_fdinfo (i915, &info)); +igt_assert (igt_parse_drm_fdinfo (i915, &info, engine_map, +ARRAY_SIZE (engine_map)));return info.busy[class]; }
@@ -267,7 +276,8 @@ static void read_busy_all(int i915, uint64_t *val) {struct drm_client_fdinfo info = { }; -igt_assert (igt_parse_drm_fdinfo (i915, &info)); +igt_assert (igt_parse_drm_fdinfo (i915, &info, engine_map, +ARRAY_SIZE (engine_map)));memcpy (val, info.busy,sizeof (info.busy)); }
tools/intel_gpu_top.c +11 -2
@@ -2030,6 +2030,12 @@ int main(int argc, char **argv) {unsigned int period_us =DEFAULT_PERIOD_MS *1000 ;struct igt_drm_clients *clients =NULL ; +static const char *engine_map[] = { +"render" , +"copy" , +"video" , +"video-enhance" , + };int con_w =-1 , con_h =-1 ;char *output_path =NULL ;struct engines *engines;
@@ -2177,7 +2183,8 @@ int main(int argc, char **argv) }pmu_sample (engines); -igt_drm_clients_scan (clients, client_match); +igt_drm_clients_scan (clients, client_match, engine_map, +ARRAY_SIZE (engine_map)); codename =igt_device_get_pretty_name (&card, false);while (!stop_top) {
@@ -2206,7 +2213,9 @@ int main(int argc, char **argv) disp_clients =display_clients (igt_drm_clients_scan (clients, - client_match)); + client_match, + engine_map, +ARRAY_SIZE (engine_map)));if (stop_top)break ;
Signature · 1 line
2.32.0
PATCH 6/12 libdrmclients: Record client drm minor
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Prepare for supporting clients belonging to multiple DRM cards by storing the DRM minor in the client record.
--- lib/igt_drm_clients.c | 33 ++++++++++++++++++++------------- lib/igt_drm_clients.h | 6 ++++-- 2 files changed, 24 insertions(+), 15 deletions(-)
lib/igt_drm_clients.c +20 -13
@@ -117,12 +117,13 @@ igt_drm_client_update(struct igt_drm_client *c, unsigned int pid, char *name, }void -igt_drm_client_add (struct igt_drm_clients *clients,unsigned int id, -unsigned int pid,char *name,uint64_t busy[16 ]) +igt_drm_client_add (struct igt_drm_clients *clients, +struct drm_client_fdinfo *info, +unsigned int pid,char *name,unsigned int drm_minor) {struct igt_drm_client *c; -assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , id)); +assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , info->id)); c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_FREE ,0 );if (!c) {
@@ -137,13 +138,14 @@ igt_drm_client_add(struct igt_drm_clients *clients, unsigned int id,memset (c,0 , (clients->num_clients - idx) *sizeof (*c)); } - c->id = id; + c->id = info->id; + c->drm_minor = drm_minor; c->clients = clients; c->val =calloc (clients->num_classes,sizeof (c->val)); c->last =calloc (clients->num_classes,sizeof (c->last));assert (c->val && c->last); -igt_drm_client_update (c, pid, name, busy); +igt_drm_client_update (c, pid, name, info->busy); }void igt_drm_client_free (struct igt_drm_client *c)
@@ -254,16 +256,21 @@ static bool get_task_name(const char *buffer, char *out, unsigned long sz)return true; } -static bool is_drm_fd (int fd_dir,const char *name) +static bool is_drm_fd (int fd_dir,const char *name,unsigned int *minor) {struct stat stat;int ret; ret =fstatat (fd_dir, name, &stat,0 ); -return ret ==0 && - (stat.st_mode &S_IFMT ) ==S_IFCHR && -major (stat.st_rdev) ==226 ; +if (ret ==0 && + (stat.st_mode &S_IFMT ) ==S_IFCHR && +major (stat.st_rdev) ==226 ) { + *minor =minor (stat.st_rdev); +return true; + } + +return false; } struct igt_drm_clients *
@@ -293,10 +300,10 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,return clients;while ((proc_dent =readdir (proc_dir)) !=NULL ) { +unsigned int client_pid, minor =0 ;int pid_dir =-1 , fd_dir =-1 ;struct dirent *fdinfo_dent;char client_name[64 ] = { }; -unsigned int client_pid;DIR *fdinfo_dir =NULL ;char buf[4096 ];size_t count;
@@ -338,7 +345,7 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,if (!isdigit (fdinfo_dent->d_name[0 ]))continue ; -if (!is_drm_fd (fd_dir, fdinfo_dent->d_name)) +if (!is_drm_fd (fd_dir, fdinfo_dent->d_name, &minor))continue ;memset (&info,0 ,sizeof (info));
@@ -358,8 +365,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients, c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_PROBE , info.id);if (!c) -igt_drm_client_add (clients, info.id, client_pid, - client_name, info.busy); +igt_drm_client_add (clients, &info, client_pid, + client_name, minor);else igt_drm_client_update (c, client_pid, client_name, info.busy);
lib/igt_drm_clients.h +4 -2
@@ -48,6 +48,7 @@ struct igt_drm_client {enum igt_drm_client_status status;unsigned int id; +unsigned int drm_minor;unsigned int pid;char name[24 ];char print_name[24 ];
@@ -95,8 +96,9 @@ igt_drm_clients_sort(struct igt_drm_clients *clients,void igt_drm_client_update (struct igt_drm_client *c,unsigned int pid,char *name,uint64_t val[16 ]); -void igt_drm_client_add (struct igt_drm_clients *clients,unsigned int id, -unsigned int pid,char *name,uint64_t busy[16 ]); +void igt_drm_client_add (struct igt_drm_clients *clients, +struct drm_client_fdinfo *, +unsigned int pid,char *name,unsigned int drm_minor);void igt_drm_client_free (struct igt_drm_client *c);
Signature · 1 line
2.32.0
PATCH 7/12 libdrmclient: Support multiple DRM cards
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Require DRM minor match during client lookup.
--- lib/igt_drm_clients.c | 14 ++++++++------ lib/igt_drm_clients.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-)
lib/igt_drm_clients.c +8 -6
@@ -57,7 +57,7 @@ struct igt_drm_clients *igt_drm_clients_init(void *private_data)struct igt_drm_client *igt_drm_clients_find (struct igt_drm_clients *clients,enum igt_drm_client_status status, -unsigned int id) +unsigned int drm_minor,unsigned int id) {unsigned int start, num;struct igt_drm_client *c;
@@ -69,7 +69,8 @@ igt_drm_clients_find(struct igt_drm_clients *clients,if (status != c->status)continue ; -if (status ==IGT_DRM_CLIENT_FREE || c->id == id) +if (status ==IGT_DRM_CLIENT_FREE || + (drm_minor == c->drm_minor && c->id == id))return c; }
@@ -123,9 +124,10 @@ igt_drm_client_add(struct igt_drm_clients *clients, {struct igt_drm_client *c; -assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , info->id)); +assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , + drm_minor, info->id)); - c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_FREE ,0 ); + c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_FREE ,0 ,0 );if (!c) {unsigned int idx = clients->num_clients;
@@ -359,11 +361,11 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,continue ;if (igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , - info.id)) + minor, info.id))continue ;/* Skip duplicate fds. */ c =igt_drm_clients_find (clients,IGT_DRM_CLIENT_PROBE , - info.id); + minor, info.id);if (!c)igt_drm_client_add (clients, &info, client_pid, client_name, minor);
lib/igt_drm_clients.h +1 -1
@@ -87,7 +87,7 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,struct igt_drm_client *igt_drm_clients_find (struct igt_drm_clients *clients,enum igt_drm_client_status status, -unsigned int id); +unsigned int drm_minor,unsigned int id);struct igt_drm_clients * igt_drm_clients_sort(struct igt_drm_clients *clients,
Signature · 1 line
2.32.0
PATCH 8/12 libdrmfdinfo: Track largest engine index
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Prep code for incoming work.
--- lib/igt_drm_fdinfo.c | 2 ++ lib/igt_drm_fdinfo.h | 1 + 2 files changed, 3 insertions(+)
lib/igt_drm_fdinfo.c +2 -0
@@ -162,6 +162,8 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info, info->capacity[idx] =1 ; info->busy[idx] = val; info->num_engines++; +if (idx > info->last_engine_index) + info->last_engine_index = idx; } }else if (!strncmp (l,"drm-engine-capacity-" ,20 )) { idx = parse_engine(l, info,
lib/igt_drm_fdinfo.h +1 -0
@@ -38,6 +38,7 @@ struct drm_client_fdinfo {unsigned long id;unsigned int num_engines; +unsigned int last_engine_index;unsigned int capacity[DRM_CLIENT_FDINFO_MAX_ENGINES ];char names[DRM_CLIENT_FDINFO_MAX_ENGINES ][256 ];uint64_t busy[DRM_CLIENT_FDINFO_MAX_ENGINES ];
Signature · 1 line
2.32.0
PATCH 9/12 libdrmclient/intel_gpu_top: Decouple hardcoded engine assumptions
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Intel_gpu_top gets it's main engine configuration data via PMU probe and uses that for per client view as well. Furthemore code so far assumed only clients belonging from a single DRM card would be tracked in a single clients list.
Break this inter-dependency by moving the engine data to be per client and also have libdrmclient probe the engine configuration independently using the previously added libdrmfdinfo facilities.
--- lib/igt_drm_clients.c | 34 +++++++++++-- lib/igt_drm_clients.h | 11 ++--- tools/intel_gpu_top.c | 112 ++++++++++++++++++++++++++++++------------ 3 files changed, 117 insertions(+), 40 deletions(-)
lib/igt_drm_clients.c +31 -3
@@ -103,7 +103,7 @@ igt_drm_client_update(struct igt_drm_client *c, unsigned int pid, char *name, c->last_runtime =0 ; c->total_runtime =0 ; -for (i =0 ; i < c->clients->num_classes; i++) { +for (i =0 ; i <= c->engines->max_engine_id; i++) {if (val[i] < c->last[i])continue ;/* It will catch up soon. */
@@ -123,6 +123,7 @@ igt_drm_client_add(struct igt_drm_clients *clients, unsigned int pid, char *name, unsigned int drm_minor) { struct igt_drm_client *c; +unsigned int i;assert (!igt_drm_clients_find (clients,IGT_DRM_CLIENT_ALIVE , drm_minor, info->id));
@@ -143,8 +144,28 @@ igt_drm_client_add(struct igt_drm_clients *clients, c->id = info->id; c->drm_minor = drm_minor; c->clients = clients; - c->val =calloc (clients->num_classes,sizeof (c->val)); - c->last =calloc (clients->num_classes,sizeof (c->last)); + c->engines =malloc (sizeof (*c->engines)); +assert (c->engines); +memset (c->engines,0 ,sizeof (*c->engines)); + c->engines->capacity =calloc (info->last_engine_index +1 , +sizeof (*c->engines->capacity)); +assert (c->engines->capacity); + c->engines->names =calloc (info->last_engine_index +1 , +sizeof (*c->engines->names)); +assert (c->engines->names); + +for (i =0 ; i <= info->last_engine_index; i++) { +if (!info->capacity[i]) +continue ; + + c->engines->capacity[i] = info->capacity[i]; + c->engines->names[i] =strdup (info->names[i]); +assert (c->engines->names[i]); + c->engines->num_engines++; + c->engines->max_engine_id = i; + } + c->val =calloc (c->engines->max_engine_id +1 ,sizeof (c->val)); + c->last =calloc (c->engines->max_engine_id +1 ,sizeof (c->last));assert (c->val && c->last);igt_drm_client_update (c, pid, name, info->busy);
@@ -152,6 +173,13 @@ igt_drm_client_add(struct igt_drm_clients *clients,void igt_drm_client_free (struct igt_drm_client *c) { +unsigned int i; + +for (i =0 ; i <= c->engines->max_engine_id; i++) +free (c->engines->names[i]); +free (c->engines->capacity); +free (c->engines->names); +free (c->engines);free (c->val);free (c->last);memset (c,0 ,sizeof (*c));
lib/igt_drm_clients.h +5 -6
@@ -35,10 +35,11 @@ enum igt_drm_client_status { IGT_DRM_CLIENT_PROBE }; -struct igt_drm_client_engine_class { -unsigned int engine_class; -const char *name; +struct igt_drm_client_engines {unsigned int num_engines; +unsigned int max_engine_id; +unsigned int *capacity; +char **names; };struct igt_drm_clients ;
@@ -47,6 +48,7 @@ struct igt_drm_client {struct igt_drm_clients *clients;enum igt_drm_client_status status; +struct igt_drm_client_engines *engines;unsigned int id;unsigned int drm_minor;unsigned int pid;
@@ -63,9 +65,6 @@ struct igt_drm_clients {unsigned int num_clients;unsigned int active_clients; -unsigned int num_classes; -struct igt_drm_client_engine_class *engine_class; -void *private_data;struct igt_drm_client *client;/* Must be last. */
tools/intel_gpu_top.c +81 -31
258 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 10/12 libdrmclient: Enforce client status sort order in the library
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Some libdrmclient operations require that inactive clients are last in the list. Rather than relying on callers of the library sort routine to implement their comparison callbacks correctly, enforce this order directly in the library and let callers comparison callbacks concern themselves only with ordering they are interested in.
--- lib/igt_drm_clients.c | 25 +++++++++++-- lib/igt_drm_clients.h | 2 +- tools/intel_gpu_top.c | 81 +++++++++++++++++++------------------------ 3 files changed, 58 insertions(+), 50 deletions(-)
lib/igt_drm_clients.c +22 -3
@@ -185,10 +185,29 @@ void igt_drm_client_free(struct igt_drm_client *c)memset (c,0 ,sizeof (*c)); } +struct sort_context +{ +int (*user_cmp)(const void *,const void *,void *); +}; + +static int sort_cmp (const void *_a,const void *_b,void *_ctx) +{ +const struct sort_context *ctx = _ctx; +const struct igt_drm_client *a = _a; +const struct igt_drm_client *b = _b; +int cmp = b->status - a->status; + +if (cmp ==0 ) +return ctx->user_cmp (_a, _b, _ctx); +else +return cmp; +} +struct igt_drm_clients *igt_drm_clients_sort (struct igt_drm_clients *clients, -int (*cmp)(const void *,const void *)) +int (*cmp)(const void *,const void *,void *)) { +struct sort_context ctx = { .user_cmp = cmp };unsigned int active, free;struct igt_drm_client *c;int tmp;
@@ -196,8 +215,8 @@ igt_drm_clients_sort(struct igt_drm_clients *clients,if (!clients)return clients; -qsort (clients->client, clients->num_clients,sizeof (*clients->client), - cmp); +qsort_r (clients->client, clients->num_clients,sizeof (*clients->client), + sort_cmp, &ctx);/* Trim excessive array space. */ active =0 ;
lib/igt_drm_clients.h +1 -1
@@ -90,7 +90,7 @@ igt_drm_clients_find(struct igt_drm_clients *clients,struct igt_drm_clients *igt_drm_clients_sort (struct igt_drm_clients *clients, -int (*cmp)(const void *,const void *)); +int (*cmp)(const void *,const void *,void *));void igt_drm_client_update (struct igt_drm_client *c,unsigned int pid,char *name,uint64_t val[16 ]);
tools/intel_gpu_top.c +35 -46
127 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 11/12 libdrmclient: Unexport igt_drm_client_update
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
It is currently unused so no need to export it as API for now.
Also change the signature to take struct drm_client_fdinfo in order to avoid needing to pass in a sized array.
--- lib/igt_drm_clients.c | 16 ++++++++-------- lib/igt_drm_clients.h | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-)
lib/igt_drm_clients.c +8 -8
@@ -77,9 +77,9 @@ igt_drm_clients_find(struct igt_drm_clients *clients,return NULL ; } -void +static void igt_drm_client_update (struct igt_drm_client *c,unsigned int pid,char *name, -uint64_t val[16 ]) +const struct drm_client_fdinfo *info) {unsigned int i;
@@ -104,13 +104,13 @@ igt_drm_client_update(struct igt_drm_client *c, unsigned int pid, char *name, c->total_runtime =0 ;for (i =0 ; i <= c->engines->max_engine_id; i++) { -if (val[i] < c->last[i]) +if (info->busy[i] < c->last[i])continue ;/* It will catch up soon. */ - c->total_runtime += val[i]; - c->val[i] = val[i] - c->last[i]; + c->total_runtime += info->busy[i]; + c->val[i] = info->busy[i] - c->last[i]; c->last_runtime += c->val[i]; - c->last[i] = val[i]; + c->last[i] = info->busy[i]; } c->samples++;
@@ -168,7 +168,7 @@ igt_drm_client_add(struct igt_drm_clients *clients, c->last =calloc (c->engines->max_engine_id +1 ,sizeof (c->last));assert (c->val && c->last); -igt_drm_client_update (c, pid, name, info->busy); +igt_drm_client_update (c, pid, name, info); }void igt_drm_client_free (struct igt_drm_client *c)
@@ -418,7 +418,7 @@ igt_drm_clients_scan(struct igt_drm_clients *clients, client_name, minor); else igt_drm_client_update(c, client_pid, - client_name, info.busy); + client_name, &info); } next:
lib/igt_drm_clients.h +0 -3
@@ -92,9 +92,6 @@ struct igt_drm_clients * igt_drm_clients_sort(struct igt_drm_clients *clients, int (*cmp)(const void *, const void *, void *)); -void igt_drm_client_update (struct igt_drm_client *c, -unsigned int pid,char *name,uint64_t val[16 ]); -void igt_drm_client_add (struct igt_drm_clients *clients,struct drm_client_fdinfo *,unsigned int pid,char *name,unsigned int drm_minor);
Signature · 1 line
2.32.0
PATCH 12/12 gputop: Basic vendor agnostic GPU top tool
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Rudimentary vendor agnostic example of how lib_igt_drm_clients can be used to display a sorted by card and usage list of processes using GPUs.
--- tools/gputop.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 5 + 2 files changed, 281 insertions(+) create mode 100644 tools/gputop.c
tools/gputop.c new file +276 -0
@@ -0,0 +1,276 @@ +/* +* Copyright © 2022 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include <assert.h> +#include <ctype.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <limits.h> +#include <locale.h> +#include <math.h> +#include <poll.h> +#include <signal.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <termios.h> +#include <sys/sysmacros.h> +#include <stdbool.h> + +#include "igt_drm_clients.h" +#include "igt_drm_fdinfo.h" + +#define ARRAY_SIZE (arr) (sizeof(arr)/sizeof(arr[0])) + +static const char *bars[] = {" " ,"▏" ,"▎" ,"▍" ,"▌" ,"▋" ,"▊" ,"▉" ,"█" }; + +static void n_spaces (const unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) +putchar (' ' ); +} + +static void print_percentage_bar (double percent,int max_len) +{ +int bar_len, i, len = max_len -2 ; +const int w =8 ; + +assert (max_len >0 ); + + bar_len =ceil (w * percent * len /100.0 ); +if (bar_len > w * len) + bar_len = w * len; + +putchar ('|' ); + +for (i = bar_len; i >= w; i -= w) +printf ("%s" , bars[w]); +if (i) +printf ("%s" , bars[i]); + + len -= (bar_len + (w -1 )) / w; +n_spaces (len); + +putchar ('|' ); +} + +static int +print_client_header (struct igt_drm_client *c,int lines,int con_w,int con_h, +int *engine_w) +{ +const char *pidname =" PID NAME " ; +int ret, len =strlen (pidname); + +if (lines++ >= con_h || len >= con_w) +return lines; +printf ("\033[7m" ); + ret =printf ("DRM minor %u" , c->drm_minor); +n_spaces (con_w - ret); + +if (lines++ >= con_h) +return lines; +printf ("\n%s" , pidname); + +if (c->engines->num_engines) { +unsigned int i; +int width; + + *engine_w = width = (con_w - len) / c->engines->num_engines; + +for (i =0 ; i <= c->engines->max_engine_id; i++) { +const char *name = c->engines->names[i]; +int name_len =strlen (name); +int pad = (width - name_len) /2 ; +int spaces = width - pad - name_len; + +if (!name) +continue ; + +if (pad <0 || spaces <0 ) +continue ; + +n_spaces (pad); +printf ("%s" , name); +n_spaces (spaces); + len += pad + name_len + spaces; + } + } + +n_spaces (con_w - len); +printf ("\033[0m\n" ); + +return lines; +} + + +static bool +newheader (const struct igt_drm_client *c,const struct igt_drm_client *pc) +{ +return !pc || c->drm_minor != pc->drm_minor; +} + +static bool filter_idle = true; + +static int +print_client (struct igt_drm_client *c,struct igt_drm_client **prevc, +double t,int lines,int con_w,int con_h, +unsigned int period_us,int *engine_w) +{ +unsigned int i; + +if (filter_idle && (!c->total_runtime || c->samples <2 )) +return lines; + +if (newheader (c, *prevc)) { + lines =print_client_header (c, lines, con_w, con_h, engine_w); +if (lines >= con_h) +return lines; + } + + *prevc = c; + +printf ("%8u %17s " , c->pid, c->print_name); + lines++; + +for (i =0 ; c->samples >1 && i <= c->engines->max_engine_id; i++) { +double pct; + +if (!c->engines->capacity[i]) +continue ; + + pct = (double )c->val[i] / period_us /1e3 *100 / + c->engines->capacity[i]; + +/* +* Guard against possible time-drift between sampling +* client data and time we obtained our time-delta from +* PMU. +*/ +if (pct >100.0 ) + pct =100.0 ; + +print_percentage_bar (pct, *engine_w); + } + +putchar ('\n' ); + +return lines; +} + +static int +__client_id_cmp (const struct igt_drm_client *a, +const struct igt_drm_client *b) +{ +if (a->id > b->id) +return 1 ; +else if (a->id < b->id) +return -1 ; +else +return 0 ; +} + +static int client_cmp (const void *_a,const void *_b,void *unused) +{ +const struct igt_drm_client *a = _a; +const struct igt_drm_client *b = _b; +long val_a, val_b; + + val_a = a->drm_minor; + val_b = b->drm_minor; +if (val_a > val_b) +return 1 ; +else if (val_b > val_a) +return -1 ; + + val_a = a->last_runtime; + val_b = b->last_runtime; +if (val_a == val_b) +return __client_id_cmp (a, b); +else if (val_b > val_a) +return 1 ; +else +return -1 ; + +} + +int main (int argc,char **argv) +{ +unsigned int period_us =2e6 ; +struct igt_drm_clients *clients =NULL ; +int con_w =-1 , con_h =-1 ; + + clients =igt_drm_clients_init (NULL ); +if (!clients) +exit (1 ); + +igt_drm_clients_scan (clients,NULL ,NULL ,0 ); + +for (;;) { +struct igt_drm_client *c, *prevc =NULL ; +int i, engine_w =0 , lines =0 ; +struct winsize ws; + +if (ioctl (0 ,TIOCGWINSZ , &ws) !=-1 ) { + con_w = ws.ws_col; + con_h = ws.ws_row; +if (con_w ==0 && con_h ==0 ) { +/* Serial console. */ + con_w =80 ; + con_h =24 ; + } + } + +igt_drm_clients_scan (clients,NULL ,NULL ,0 ); +igt_drm_clients_sort (clients, client_cmp); + +printf ("\033[H\033[J" ); + +igt_for_each_drm_client (clients, c, i) { +assert (c->status !=IGT_DRM_CLIENT_PROBE ); +if (c->status !=IGT_DRM_CLIENT_ALIVE ) +break ;/* Active clients are first in the array. */ + + lines =print_client (c, &prevc, (double )period_us /1e6 , + lines, con_w, con_h, period_us, + &engine_w); +if (lines >= con_h) +break ; + } + +if (lines++ < con_h) +printf ("\n" ); + +usleep (period_us); + } + +return 0 ; +}
tools/meson.build +5 -0
@@ -69,6 +69,11 @@ if libudev.found() install : true) endif +executable('gputop', 'gputop.c', + install : true, + install_rpath : bindir_rpathdir, + dependencies : [lib_igt_drm_clients,lib_igt_drm_fdinfo,math]) + intel_l3_parity_src = [ 'intel_l3_parity.c', 'intel_l3_udev_listener.c' ] executable('intel_l3_parity', sources : intel_l3_parity_src, dependencies : tool_deps,
Signature · 1 line
2.32.0
Patchwork
CI[igt-dev] ✗ GitLab.Pipeline: warning for Per client GPU utilisation (rev2)
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: Per client GPU utilisation (rev2)
URL : https://patchwork.freedesktop.org/series/100571/
State : warning
== Summary ==
Pipeline status: FAILED.
see https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/547021 for the overview.
test:ninja-test-arm64 has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/20568232):
Ok: 22
Expected Fail: 3
Fail: 288
Unexpected Pass: 0 Skipped: 0 Timeout: 0
Full log written to /builds/gfx-ci/igt-ci-tags/build/meson-logs/testlog.txt section_end:1648745778:step_script
section_start:1648745778:upload_artifacts_on_failure
Uploading artifacts for failed job
Uploading artifacts...
build: found 1729 matching files and directories
Uploading artifacts as "archive" to coordinator... 201 Created id=20568232 responseStatus=201 Created token=cvtm6eCL section_end:1648745788:upload_artifacts_on_failure
section_start:1648745788:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1648745788:cleanup_file_variables
ERROR: Job failed: exit code 1
test:ninja-test-armhf has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/20568233):
Ok: 22
Expected Fail: 3
Fail: 288
Unexpected Pass: 0 Skipped: 0 Timeout: 0
Full log written to /builds/gfx-ci/igt-ci-tags/build/meson-logs/testlog.txt section_end:1648745783:step_script
section_start:1648745783:upload_artifacts_on_failure
Uploading artifacts for failed job
Uploading artifacts...
build: found 1728 matching files and directories
Uploading artifacts as "archive" to coordinator... 201 Created id=20568233 responseStatus=201 Created token=BmgKsm5T section_end:1648745792:upload_artifacts_on_failure
section_start:1648745792:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1648745792:cleanup_file_variables
ERROR: Job failed: exit code 1
== Logs ==
For more details see: https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/547021
Patchwork
CI[igt-dev] ✗ Fi.CI.BAT: failure for Per client GPU utilisation (rev2)
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: Per client GPU utilisation (rev2)
URL : https://patchwork.freedesktop.org/series/100571/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_11435 -> IGTPW_6850
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with IGTPW_6850 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in IGTPW_6850, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/index.html
Participating hosts (44 -> 45)
------------------------------
Additional (4): fi-kbl-soraka bat-adlm-1 fi-icl-u2 bat-dg2-9
Missing (3): bat-dg2-8 fi-bsw-cyan fi-bdw-samus
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in IGTPW_6850:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@gt_heartbeat:
- fi-tgl-1115g4: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-tgl-1115g4/igt@i915_selftest@live@gt_heartbeat.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-tgl-1115g4/igt@i915_selftest@live@gt_heartbeat.html
* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
- fi-snb-2600: [PASS][3] -> [DMESG-WARN][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-snb-2600/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-snb-2600/igt@[email protected]
#### Suppressed ####
The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.
* igt@i915_pm_rpm@basic-rte:
- {bat-adlm-1}: NOTRUN -> [INCOMPLETE][5]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/bat-adlm-1/igt@[email protected]
Known issues
------------
Here are the changes found in IGTPW_6850 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@amdgpu/amd_cs_nop@fork-gfx0:
- fi-icl-u2: NOTRUN -> [SKIP][6] ([fdo#109315]) +17 similar issues
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@amdgpu/[email protected]
* igt@gem_exec_fence@basic-busy@bcs0:
- fi-kbl-soraka: NOTRUN -> [SKIP][7] ([fdo#109271]) +9 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@gem_exec_fence@[email protected]
* igt@gem_huc_copy@huc-copy:
- fi-kbl-soraka: NOTRUN -> [SKIP][8] ([fdo#109271] / [i915#2190])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@[email protected]
- fi-icl-u2: NOTRUN -> [SKIP][9] ([i915#2190])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@gem_lmem_swapping@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][10] ([fdo#109271] / [i915#4613]) +3 similar issues
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@[email protected]
* igt@gem_lmem_swapping@parallel-random-engines:
- fi-icl-u2: NOTRUN -> [SKIP][11] ([i915#4613]) +3 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@i915_selftest@live@gt_pm:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][12] ([i915#1886])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html
* igt@i915_selftest@live@hangcheck:
- fi-hsw-4770: [PASS][13] -> [INCOMPLETE][14] ([i915#4785])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-hsw-4770/igt@i915_selftest@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-hsw-4770/igt@i915_selftest@[email protected]
- bat-dg1-6: NOTRUN -> [DMESG-FAIL][15] ([i915#4494] / [i915#4957])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/bat-dg1-6/igt@i915_selftest@[email protected]
* igt@kms_chamelium@common-hpd-after-suspend:
- fi-kbl-soraka: NOTRUN -> [SKIP][16] ([fdo#109271] / [fdo#111827]) +8 similar issues
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@[email protected]
* igt@kms_chamelium@hdmi-hpd-fast:
- fi-icl-u2: NOTRUN -> [SKIP][17] ([fdo#111827]) +8 similar issues
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- fi-icl-u2: NOTRUN -> [SKIP][18] ([fdo#109278]) +2 similar issues
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@kms_flip@basic-flip-vs-modeset@a-edp1:
- fi-tgl-u2: [PASS][19] -> [DMESG-WARN][20] ([i915#402]) +1 similar issue
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-tgl-u2/igt@kms_flip@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-tgl-u2/igt@kms_flip@[email protected]
* igt@kms_force_connector_basic@force-load-detect:
- fi-icl-u2: NOTRUN -> [SKIP][21] ([fdo#109285])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
- fi-kbl-soraka: NOTRUN -> [SKIP][22] ([fdo#109271] / [i915#533])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-kbl-soraka/igt@[email protected]
* igt@kms_setmode@basic-clone-single-crtc:
- fi-icl-u2: NOTRUN -> [SKIP][23] ([i915#3555])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@prime_vgem@basic-userptr:
- fi-icl-u2: NOTRUN -> [SKIP][24] ([i915#3301])
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-icl-u2/igt@[email protected]
* igt@runner@aborted:
- fi-hsw-4770: NOTRUN -> [FAIL][25] ([fdo#109271] / [i915#1436] / [i915#2722] / [i915#4312])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-hsw-4770/igt@[email protected]
#### Possible fixes ####
* igt@i915_selftest@live@gt_engines:
- bat-dg1-6: [INCOMPLETE][26] ([i915#4418]) -> [PASS][27]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/bat-dg1-6/igt@i915_selftest@live@gt_engines.html
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/bat-dg1-6/igt@i915_selftest@live@gt_engines.html
* igt@i915_selftest@live@objects:
- {fi-tgl-dsi}: [INCOMPLETE][28] -> [PASS][29]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-tgl-dsi/igt@i915_selftest@[email protected]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-tgl-dsi/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@requests:
- fi-rkl-guc: [DMESG-WARN][30] -> [PASS][31]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-rkl-guc/igt@i915_selftest@[email protected]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-rkl-guc/igt@i915_selftest@[email protected]
* igt@kms_flip@basic-flip-vs-wf_vblank@a-edp1:
- fi-tgl-u2: [DMESG-WARN][32] ([i915#402]) -> [PASS][33]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11435/fi-tgl-u2/igt@kms_flip@[email protected]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/fi-tgl-u2/igt@kms_flip@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109315]: https://bugs.freedesktop.org/show_bug.cgi?id=109315
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1155]: https://gitlab.freedesktop.org/drm/intel/issues/1155
[i915#1436]: https://gitlab.freedesktop.org/drm/intel/issues/1436
[i915#1886]: https://gitlab.freedesktop.org/drm/intel/issues/1886
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#2575]: https://gitlab.freedesktop.org/drm/intel/issues/2575
[i915#2722]: https://gitlab.freedesktop.org/drm/intel/issues/2722
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3301]: https://gitlab.freedesktop.org/drm/intel/issues/3301
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3576]: https://gitlab.freedesktop.org/drm/intel/issues/3576
[i915#3595]: https://gitlab.freedesktop.org/drm/intel/issues/3595
[i915#402]: https://gitlab.freedesktop.org/drm/intel/issues/402
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4212]: https://gitlab.freedesktop.org/drm/intel/issues/4212
[i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213
[i915#4215]: https://gitlab.freedesktop.org/drm/intel/issues/4215
[i915#4312]: https://gitlab.freedesktop.org/drm/intel/issues/4312
[i915#4418]: https://gitlab.freedesktop.org/drm/intel/issues/4418
[i915#4494]: https://gitlab.freedesktop.org/drm/intel/issues/4494
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4785]: https://gitlab.freedesktop.org/drm/intel/issues/4785
[i915#4957]: https://gitlab.freedesktop.org/drm/intel/issues/4957
[i915#5068]: https://gitlab.freedesktop.org/drm/intel/issues/5068
[i915#5190]: https://gitlab.freedesktop.org/drm/intel/issues/5190
[i915#5193]: https://gitlab.freedesktop.org/drm/intel/issues/5193
[i915#5195]: https://gitlab.freedesktop.org/drm/intel/issues/5195
[i915#5274]: https://gitlab.freedesktop.org/drm/intel/issues/5274
[i915#533]: https://gitlab.freedesktop.org/drm/intel/issues/533
[i915#5482]: https://gitlab.freedesktop.org/drm/intel/issues/5482
Build changes
-------------
* CI: CI-20190529 -> None
* IGT: IGT_6403 -> IGTPW_6850
CI-20190529: 20190529
CI_DRM_11435: 4a744c1934fd55c3f705bab1ce6f96f6688c96e2 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_6850: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/index.html
IGT_6403: bc3f6833a12221a46659535dac06ebb312490eb4 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
== Testlist changes ==
+igt@drm_fdinfo@all-busy-check-all
+igt@drm_fdinfo@all-busy-idle-check-all
+igt@drm_fdinfo@basics
+igt@drm_fdinfo@busy
+igt@drm_fdinfo@busy-check-all
+igt@drm_fdinfo@busy-hang
+igt@drm_fdinfo@busy-idle
+igt@drm_fdinfo@busy-idle-check-all
+igt@drm_fdinfo@idle
+igt@drm_fdinfo@isolation
+igt@drm_fdinfo@most-busy-check-all
+igt@drm_fdinfo@most-busy-idle-check-all
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_6850/index.html