[Intel-gfx] [PATCH i-g-t 2/8] libdrmfdinfo: Allow specifying custom engine map
From: Tvrtko Ursulin 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 | 18 +--- lib/igt_drm_clients.h | 3 ++- lib/igt_drm_fdinfo.c| 48 +++-- lib/igt_drm_fdinfo.h| 15 ++--- tests/i915/drm_fdinfo.c | 19 tools/intel_gpu_top.c | 16 +++--- 6 files changed, 89 insertions(+), 30 deletions(-) diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c index 45de2d0f1cc5..eabd43773f2d 100644 --- a/lib/igt_drm_clients.c +++ b/lib/igt_drm_clients.c @@ -302,14 +302,26 @@ static bool is_drm_fd(int fd_dir, const char *name) * igt_drm_clients_scan: * @clients: Previously initialised clients object * @filter_client: Callback for client filtering + * @name_map: Array of engine name strings + * @map_entries: Number of items in the @name_map array * * Scan all open file descriptors from all processes in order to find all DRM * clients and manage our internal list. + * + * If @name_map is provided each found engine in the fdinfo struct must + * correspond to one of the provided names. In this case the index of the engine + * stats tracked in struct igt_drm_client will be tracked under the same index + * as the engine name provided. + * + * If @name_map is not provided engine names will be auto-detected (this is + * less performant) and indices will correspond with auto-detected names as + * listed int clients->engine_class[]. */ 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; @@ -385,8 +397,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients, continue; if (!__igt_parse_drm_fdinfo(dirfd(fdinfo_dir), - fdinfo_dent->d_name, - )) + fdinfo_dent->d_name, , + name_map, map_entries)) continue; if (filter_client && !filter_client(clients, )) diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h index 969793d5b51e..bced19adb055 100644 --- a/lib/igt_drm_clients.h +++ b/lib/igt_drm_clients.h @@ -76,7 +76,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_clients * igt_drm_clients_sort(struct igt_drm_clients *clients, diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c index 250d9e8917f2..68c89ad2c17e 100644 --- a/lib/igt_drm_fdinfo.c +++ b/lib/igt_drm_fdinfo.c @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -53,14 +54,10 @@ static size_t read_fdinfo(char *buf, const size_t sz, int at, const char *name) } static int parse_engine(char *line, struct drm_client_fdinfo *info, - size_t prefix_len, uint64_t *val) + size_t prefix_len, + const char **name_map, unsigned int map_entries, + uint64_t *val) { - static const char *e2class[] = { - "render", - "copy", - "video", - "video-enhance", - }; ssize_t name_len; char *name, *p; int found = -1; @@ -76,10 +73,26 @@ static int parse_engine(char *line, struct drm_client_fdinfo *info, name = line + prefix_len; - for (i = 0; i < ARRAY_SIZE(e2class); i++) { - if (!strncmp(name, e2class[i], name_len)) { - found = i; - break; + if (name_map) { + for (i = 0; i < map_entries; i++) { + if (!strncmp(name, name_map[i], name_len)) { + found = i; + break; + } + } + } else { + for (i = 0; i < info->num_engines; i++) { + if (!strncmp(name, info->names[i], name_len)) { + found = i; + break; + }
[Intel-gfx] [PATCH i-g-t 2/8] libdrmfdinfo: Allow specifying custom engine map
From: Tvrtko Ursulin 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 | 18 +--- lib/igt_drm_clients.h | 3 ++- lib/igt_drm_fdinfo.c| 48 +++-- lib/igt_drm_fdinfo.h| 15 ++--- tests/i915/drm_fdinfo.c | 19 tools/intel_gpu_top.c | 16 +++--- 6 files changed, 89 insertions(+), 30 deletions(-) diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c index 45de2d0f1cc5..eabd43773f2d 100644 --- a/lib/igt_drm_clients.c +++ b/lib/igt_drm_clients.c @@ -302,14 +302,26 @@ static bool is_drm_fd(int fd_dir, const char *name) * igt_drm_clients_scan: * @clients: Previously initialised clients object * @filter_client: Callback for client filtering + * @name_map: Array of engine name strings + * @map_entries: Number of items in the @name_map array * * Scan all open file descriptors from all processes in order to find all DRM * clients and manage our internal list. + * + * If @name_map is provided each found engine in the fdinfo struct must + * correspond to one of the provided names. In this case the index of the engine + * stats tracked in struct igt_drm_client will be tracked under the same index + * as the engine name provided. + * + * If @name_map is not provided engine names will be auto-detected (this is + * less performant) and indices will correspond with auto-detected names as + * listed int clients->engine_class[]. */ 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; @@ -385,8 +397,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients, continue; if (!__igt_parse_drm_fdinfo(dirfd(fdinfo_dir), - fdinfo_dent->d_name, - )) + fdinfo_dent->d_name, , + name_map, map_entries)) continue; if (filter_client && !filter_client(clients, )) diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h index 969793d5b51e..bced19adb055 100644 --- a/lib/igt_drm_clients.h +++ b/lib/igt_drm_clients.h @@ -76,7 +76,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_clients * igt_drm_clients_sort(struct igt_drm_clients *clients, diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c index 250d9e8917f2..68c89ad2c17e 100644 --- a/lib/igt_drm_fdinfo.c +++ b/lib/igt_drm_fdinfo.c @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -53,14 +54,10 @@ static size_t read_fdinfo(char *buf, const size_t sz, int at, const char *name) } static int parse_engine(char *line, struct drm_client_fdinfo *info, - size_t prefix_len, uint64_t *val) + size_t prefix_len, + const char **name_map, unsigned int map_entries, + uint64_t *val) { - static const char *e2class[] = { - "render", - "copy", - "video", - "video-enhance", - }; ssize_t name_len; char *name, *p; int found = -1; @@ -76,10 +73,26 @@ static int parse_engine(char *line, struct drm_client_fdinfo *info, name = line + prefix_len; - for (i = 0; i < ARRAY_SIZE(e2class); i++) { - if (!strncmp(name, e2class[i], name_len)) { - found = i; - break; + if (name_map) { + for (i = 0; i < map_entries; i++) { + if (!strncmp(name, name_map[i], name_len)) { + found = i; + break; + } + } + } else { + for (i = 0; i < info->num_engines; i++) { + if (!strncmp(name, info->names[i], name_len)) { + found = i; + break; + }
[Intel-gfx] [PATCH i-g-t 2/8] libdrmfdinfo: Allow specifying custom engine map
From: Tvrtko Ursulin 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. Signed-off-by: Tvrtko Ursulin --- lib/igt_drm_clients.c | 18 +--- lib/igt_drm_clients.h | 3 ++- lib/igt_drm_fdinfo.c| 48 +++-- lib/igt_drm_fdinfo.h| 15 ++--- tests/i915/drm_fdinfo.c | 18 tools/intel_gpu_top.c | 13 +-- 6 files changed, 86 insertions(+), 29 deletions(-) diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c index 658c684b8fb0..c42ce1dbc43f 100644 --- a/lib/igt_drm_clients.c +++ b/lib/igt_drm_clients.c @@ -294,14 +294,26 @@ static bool is_drm_fd(int fd_dir, const char *name) * igt_drm_clients_scan: * @clients: Previously initialised clients object * @filter_client: Callback for client filtering + * @name_map: Array of engine name strings + * @map_entries: Number of items in the @name_map array * * Scan all open file descriptors from all processes in order to find all DRM * clients and manage our internal list. + * + * If @name_map is provided each found engine in the fdinfo struct must + * correspond to one of the provided names. In this case the index of the engine + * stats tracked in struct igt_drm_client will be tracked under the same index + * as the engine name provided. + * + * If @name_map is not provided engine names will be auto-detected (this is + * less performant) and indices will correspond with auto-detected names as + * listed int clients->engine_class[]. */ 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; @@ -379,8 +391,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients, memset(, 0, sizeof(info)); if (!__igt_parse_drm_fdinfo(dirfd(fdinfo_dir), - fdinfo_dent->d_name, - )) + fdinfo_dent->d_name, , + name_map, map_entries)) continue; if (filter_client && !filter_client(clients, )) diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h index 969793d5b51e..bced19adb055 100644 --- a/lib/igt_drm_clients.h +++ b/lib/igt_drm_clients.h @@ -76,7 +76,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_clients * igt_drm_clients_sort(struct igt_drm_clients *clients, diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c index b422f67a4ace..9b5c81a9b68d 100644 --- a/lib/igt_drm_fdinfo.c +++ b/lib/igt_drm_fdinfo.c @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -53,14 +54,10 @@ static size_t read_fdinfo(char *buf, const size_t sz, int at, const char *name) } static int parse_engine(char *line, struct drm_client_fdinfo *info, - size_t prefix_len, uint64_t *val) + size_t prefix_len, + const char **name_map, unsigned int map_entries, + uint64_t *val) { - static const char *e2class[] = { - "render", - "copy", - "video", - "video-enhance", - }; ssize_t name_len; char *name, *p; int found = -1; @@ -76,10 +73,26 @@ static int parse_engine(char *line, struct drm_client_fdinfo *info, name = line + prefix_len; - for (i = 0; i < ARRAY_SIZE(e2class); i++) { - if (!strncmp(name, e2class[i], name_len)) { - found = i; - break; + if (name_map) { + for (i = 0; i < map_entries; i++) { + if (!strncmp(name, name_map[i], name_len)) { + found = i; + break; + } + } + } else { + for (i = 0; i < info->num_engines; i++) { + if (!strncmp(name, info->names[i], name_len)) { + found = i; +