intel-gpu-top: Adapt for fdinfo stats
RFC 1/1 intel-gpu-top: Adapt for fdinfo stats
From: Tvrtko Ursulin <[email protected]>
Quick implementation of how per client stats could be parsed if exported via drm fdinfo.
--- tools/intel_gpu_top.c | 367 ++++++++++++++++++++++-------------------- 1 file changed, 196 insertions(+), 171 deletions(-)
tools/intel_gpu_top.c +196 -171
@@ -43,6 +43,7 @@#include <sys/types.h> #include <unistd.h> #include <termios.h> +#include <sys/sysmacros.h> #include "igt_perf.h"
@@ -309,7 +310,8 @@ static int engine_cmp(const void *__a, const void *__b)return a->instance - b->instance; } -#define is_igpu_pci (x) (strcmp(x, "0000:00:02.0") == 0) +#define IGPU_PCI "0000:00:02.0" +#define is_igpu_pci (x) (strcmp(x, IGPU_PCI) == 0)#define is_igpu (x) (strcmp(x, "i915") == 0)static struct engines *discover_engines (char *device)
@@ -639,8 +641,6 @@ struct client {struct clients *clients;enum client_status status; -int sysfs_root; -int busy_root;unsigned int id;unsigned int pid;char name[24 ];
@@ -660,7 +660,7 @@ struct clients {unsigned int num_classes;struct engine_class *class; -char sysfs_root[128 ]; +char pci_slot[64 ];struct client *client; };
@@ -669,12 +669,9 @@ struct clients {for ((tmp) = (clients)->num_clients, c = (clients)->client; \ (tmp >0 ); (tmp)--, (c)++) -static struct clients *init_clients(const char *drm_card) +static struct clients *init_clients(const char *pci_slot) {struct clients *clients; -const char *slash; -ssize_t ret; -int dir; clients =malloc (sizeof (*clients));if (!clients)
@@ -682,107 +679,11 @@ static struct clients *init_clients(const char *drm_card)memset (clients,0 ,sizeof (*clients)); -if (drm_card) { - slash =rindex (drm_card,'/' ); -assert (slash); - }else { - slash ="card0" ; - } - - ret =snprintf (clients->sysfs_root,sizeof (clients->sysfs_root), -"/sys/class/drm/%s/clients/" , slash); -assert (ret >0 && ret <sizeof (clients->sysfs_root)); - - dir =open (clients->sysfs_root,O_DIRECTORY |O_RDONLY ); -if (dir <0 ) { -free (clients); - clients =NULL ; - }else { -close (dir); - } +strncpy (clients->pci_slot, pci_slot,sizeof (clients->pci_slot));return clients; } -static int __read_to_buf (int fd,char *buf,unsigned int bufsize) -{ -ssize_t ret; -int err; - - ret =read (fd, buf, bufsize -1 ); - err = errno; -if (ret <1 ) { - errno = ret <0 ? err :ENOMSG ; - -return -1 ; - } - -if (ret >1 && buf[ret -1 ] =='\n' ) - buf[ret -1 ] ='\0' ; -else - buf[ret] ='\0' ; - -return 0 ; -} - -static int -__read_client_field (int root,const char *field,char *buf,unsigned int bufsize) -{ -int fd, ret; - - fd =openat (root, field,O_RDONLY ); -if (fd <0 ) -return -1 ; - - ret =__read_to_buf (fd, buf, bufsize); - -close (fd); - -return ret; -} - -static uint64_t -read_client_busy (struct client *client,unsigned int class) -{ -const char *class_str[] = {"0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" }; -char buf[256 ], *b; -int ret; - -assert (class <ARRAY_SIZE (class_str)); -if (class >=ARRAY_SIZE (class_str)) -return 0 ; - -assert (client->sysfs_root >=0 ); -if (client->sysfs_root <0 ) -return 0 ; - -if (client->busy_root <0 ) - client->busy_root =openat (client->sysfs_root,"busy" , -O_RDONLY |O_DIRECTORY ); - -assert (client->busy_root); -if (client->busy_root <0 ) -return 0 ; - - ret =__read_client_field (client->busy_root, class_str[class], buf, -sizeof (buf)); -if (ret) { -close (client->busy_root); - client->busy_root =-1 ; -return 0 ; - } - -/* -* Handle both single integer and key=value formats by skipping -* leading non-digits. -*/ - b = buf; -while (*b && !isdigit (*b)) - b++; - -return strtoull (b,NULL ,10 ); -} -static struct client *find_client (struct clients *clients,enum client_status status,unsigned int id) {
@@ -803,9 +704,9 @@ find_client(struct clients *clients, enum client_status status, unsigned int id)return NULL ; } -static void update_client (struct client *c,unsigned int pid,char *name) +static void +update_client (struct client *c,unsigned int pid,char *name,uint64_t val[16 ]) { -uint64_t val[c->clients->num_classes];unsigned int i;if (c->pid != pid)
@@ -825,9 +726,6 @@ static void update_client(struct client *c, unsigned int pid, char *name) } } -for (i =0 ; i < c->clients->num_classes; i++) - val[i] =read_client_busy (c, c->clients->class[i].class); - c->last_runtime =0 ; c->total_runtime =0 ;
@@ -847,7 +745,7 @@ static void update_client(struct client *c, unsigned int pid, char *name)static void add_client (struct clients *clients,unsigned int id,unsigned int pid, -char *name,int sysfs_root) +char *name,uint64_t busy[16 ]) {struct client *c;
@@ -866,52 +764,22 @@ add_client(struct clients *clients, unsigned int id, unsigned int pid,memset (c,0 , (clients->num_clients - idx) *sizeof (*c)); } - c->sysfs_root = sysfs_root; - c->busy_root =-1 ; 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); -update_client (c, pid, name); +update_client (c, pid, name, busy); }static void free_client (struct client *c) { -if (c->sysfs_root >=0 ) -close (c->sysfs_root); -if (c->busy_root >=0 ) -close (c->busy_root);free (c->val);free (c->last);memset (c,0 ,sizeof (*c)); } -static int -read_client_sysfs (char *buf,int bufsize,const char *sysfs_root, -unsigned int id,const char *field,int *client_root) -{ -ssize_t ret; - -if (*client_root <0 ) { -char namebuf[256 ]; - - ret =snprintf (namebuf,sizeof (namebuf),"%s/%u" , - sysfs_root, id); -assert (ret >0 && ret <sizeof (namebuf)); -if (ret <=0 || ret ==sizeof (namebuf)) -return -1 ; - - *client_root =open (namebuf,O_RDONLY |O_DIRECTORY ); - } - -if (*client_root <0 ) -return -1 ; - -return __read_client_field (*client_root, field, buf, bufsize); -} -static int client_last_cmp (const void *_a,const void *_b) {const struct client *a = _a;
@@ -1069,8 +937,6 @@ static struct clients *display_clients(struct clients *clients) ac->status =ALIVE ; ac->id = -c->pid; ac->pid = c->pid; - ac->busy_root =-1 ; - ac->sysfs_root =-1 ;strcpy (ac->name, c->name);strcpy (ac->print_name, c->print_name); ac->engines = c->engines;
@@ -1116,13 +982,24 @@ static void free_clients(struct clients *clients)free (clients); } +static bool drm_fd (DIR *fd_dir,const char *name) +{ +struct stat stat; +int ret; + + ret =fstatat (dirfd (fd_dir), name, &stat,0 ); + +return ret ==0 && + (stat.st_mode &S_IFMT ) ==S_IFCHR && +major (stat.st_rdev) ==226 ; +} +static struct clients *scan_clients (struct clients *clients) { -struct dirent *dent; +struct dirent *proc_dent;struct client *c; -unsigned int id; +DIR *proc_dir;int tmp; -DIR *d;if (!clients)return clients;
@@ -1135,43 +1012,190 @@ static struct clients *scan_clients(struct clients *clients)break ;/* Free block at the end of array. */ } - d =opendir (clients->sysfs_root); -if (!d) + proc_dir =opendir ("/proc" ); +if (!proc_dir)return clients; -while ((dent =readdir (d)) !=NULL ) { -char name[24 ], pid[24 ]; -int ret, root =-1 , *pr; +while ((proc_dent =readdir (proc_dir)) !=NULL ) { +DIR *pid_dir, *fd_dir, *fdinfo_dir; +struct dirent *fdinfo_dent; +int fd; -if (dent->d_type !=DT_DIR ) +if (proc_dent->d_type !=DT_DIR )continue ; -if (!isdigit (dent->d_name[0 ])) +if (!isdigit (proc_dent->d_name[0 ]))continue ; - id =atoi (dent->d_name); + fd =openat (dirfd (proc_dir), proc_dent->d_name,O_DIRECTORY ); +if (fd <0 ) +continue ; - c =find_client (clients,PROBE , id); + pid_dir =fdopendir (fd); +if (!pid_dir) { +close (fd); +continue ; + } -if (c) - pr = &c->sysfs_root; -else - pr = &root; + fd =openat (dirfd (pid_dir),"fd" ,O_DIRECTORY ); +if (fd <0 ) { +closedir (pid_dir); +continue ; + } + + fd_dir =fdopendir (fd); +if (!fd_dir) { +close (fd); +closedir (pid_dir); +continue ; + } + + fd =openat (dirfd (pid_dir),"fdinfo" ,O_DIRECTORY ); +if (fd <0 ) { +closedir (fd_dir); +closedir (pid_dir); +continue ; + } + + fdinfo_dir =fdopendir (fd); +if (!fdinfo_dir) { +close (fd); +closedir (fd_dir); +closedir (pid_dir); +continue ; + } + +while ((fdinfo_dent =readdir (fdinfo_dir)) !=NULL ) { +char buffer[4096 ], *line, *ctx, *buf; +unsigned int client_id, client_pid; +unsigned int is_client =0 ; +char client_name[64 ] = { }; +uint64_t busy[16 ] = { }; +char driver[128 ] = { }; +char pdev[128 ] = { }; +size_t count; +FILE *f; + +if (fdinfo_dent->d_type !=DT_REG ) +continue ; +if (!isdigit (fdinfo_dent->d_name[0 ])) +continue ; + +if (!drm_fd (fd_dir, fdinfo_dent->d_name)) +continue ; + + fd =openat (dirfd (fdinfo_dir), fdinfo_dent->d_name, +O_RDONLY ); +if (fd <0 ) +continue ; + + f =fdopen (fd,"r" ); +if (!f) { +close (fd); +continue ; + } + +memset (buffer,0 ,sizeof (buffer)); + count =fread (buffer,1 ,sizeof (buffer), f); +fclose (f); +if (!count) +continue ; + + ctx =NULL ; + buf = buffer; +while ((line =strtok_r (buf,"\n" , &ctx))) { +static const char *e2class[] = { +"render" , +"copy" , +"video" , +"video-enhance" , + }; +char ename[256 ]; +unsigned int i; +uint64_t val; + + buf =NULL ; + +if (sscanf (line,"drm-driver:\t%s" , driver)) { + is_client++; +continue ; + } + +if (sscanf (line,"drm-pdev:\t%s" , pdev)) { + is_client++; +continue ; + } + +if (sscanf (line,"drm-client-id:\t%u" , + &client_id) ==1 ) { + is_client++; +continue ; + } + +if (sscanf (line,"drm-client-pid:\t%u" , + &client_pid) ==1 ) { + is_client++; +continue ; + } + +if (sscanf (line,"drm-client-name:\t%s" , + client_name) ==1 ) { + is_client++; +continue ; + } + +if (!strncmp (line,"drm-engine-" ,11 )) { +char *t; + +/* FIXME horrible.. */ + + t = line; +while (!isdigit (*t)) + t++; + val =strtoull (t,NULL ,10 ); + + t = line; +while (*t !=':' ) + t++; + *t =0 ; + +if (sscanf (line,"drm-engine-%s" , + ename) !=1 ) +continue ; + + is_client++; +for (i =0 ; i <ARRAY_SIZE (e2class); + i++) { +if (!strcmp (ename, e2class[i])) { + busy[i] = val; +break ; + } + } +continue ; + } + } + +if (is_client <6 ) +continue ;/* Not drm fd or other error. */ +if (strcmp (driver,"i915" )) +continue ; +if (strcmp (pdev, clients->pci_slot)) +continue ; + + c =find_client (clients,PROBE , client_id); - ret =read_client_sysfs (name,sizeof (name), clients->sysfs_root, - id,"name" , pr); - ret |=read_client_sysfs (pid,sizeof (pid), clients->sysfs_root, - id,"pid" , pr); -if (!ret) {if (!c) -add_client (clients, id,atoi (pid), name, root); +add_client (clients, client_id, client_pid, + client_name, busy);else -update_client (c,atoi (pid), name); - }else if (c) { - c->status =PROBE ;/* Will be deleted below. */ +update_client (c, client_pid, client_name, busy); } + +closedir (fdinfo_dir); +closedir (fd_dir); +closedir (pid_dir); } -closedir (d); +closedir (proc_dir);for_each_client (clients, c, tmp) {if (c->status ==PROBE )
@@ -2530,7 +2554,8 @@ int main(int argc, char **argv) ret =EXIT_SUCCESS ; - clients =init_clients (card.pci_slot_name[0 ] ? card.card :NULL ); + clients =init_clients (card.pci_slot_name[0 ] ? + card.pci_slot_name :IGPU_PCI );init_engine_classes (engines);if (clients) { clients->num_classes = engines->num_classes;
Signature · 6 lines
2.30.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[igt-dev] ✓ Fi.CI.BAT: success for intel-gpu-top: Adapt for fdinfo stats
== Series Details ==
== Series Details ==
Series: intel-gpu-top: Adapt for fdinfo stats
URL : https://patchwork.freedesktop.org/series/90464/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_10125 -> IGTPW_5837
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/index.html
Known issues
------------
Here are the changes found in IGTPW_5837 that come from known issues:
### IGT changes ###
#### Possible fixes ####
* igt@kms_frontbuffer_tracking@basic:
- fi-icl-u2: [FAIL][1] ([i915#49]) -> [PASS][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-icl-u2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-icl-u2/igt@[email protected]
#### Warnings ####
* igt@i915_selftest@live@execlists:
- fi-icl-u2: [INCOMPLETE][3] ([i915#2782] / [i915#3462]) -> [DMESG-FAIL][4] ([i915#3462])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-icl-u2/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-icl-u2/igt@i915_selftest@[email protected]
* igt@runner@aborted:
- fi-cfl-8700k: [FAIL][5] ([i915#3363]) -> [FAIL][6] ([i915#2426] / [i915#3363])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-cfl-8700k/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-cfl-8700k/igt@[email protected]
- fi-icl-u2: [FAIL][7] ([i915#2782] / [i915#3363]) -> [FAIL][8] ([i915#2426] / [i915#2782] / [i915#3363])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-icl-u2/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-icl-u2/igt@[email protected]
- fi-kbl-r: [FAIL][9] ([i915#1436] / [i915#3363]) -> [FAIL][10] ([i915#1569] / [i915#192] / [i915#193] / [i915#194] / [i915#3363])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-kbl-r/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-kbl-r/igt@[email protected]
- fi-kbl-soraka: [FAIL][11] ([i915#1436] / [i915#2426] / [i915#3363]) -> [FAIL][12] ([i915#1436] / [i915#3363])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-kbl-soraka/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-kbl-soraka/igt@[email protected]
- fi-cfl-guc: [FAIL][13] ([i915#2426] / [i915#3363]) -> [FAIL][14] ([i915#3363])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10125/fi-cfl-guc/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/fi-cfl-guc/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1222]: https://gitlab.freedesktop.org/drm/intel/issues/1222
[i915#1436]: https://gitlab.freedesktop.org/drm/intel/issues/1436
[i915#1569]: https://gitlab.freedesktop.org/drm/intel/issues/1569
[i915#192]: https://gitlab.freedesktop.org/drm/intel/issues/192
[i915#193]: https://gitlab.freedesktop.org/drm/intel/issues/193
[i915#194]: https://gitlab.freedesktop.org/drm/intel/issues/194
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#2426]: https://gitlab.freedesktop.org/drm/intel/issues/2426
[i915#2782]: https://gitlab.freedesktop.org/drm/intel/issues/2782
[i915#3012]: https://gitlab.freedesktop.org/drm/intel/issues/3012
[i915#3276]: https://gitlab.freedesktop.org/drm/intel/issues/3276
[i915#3277]: https://gitlab.freedesktop.org/drm/intel/issues/3277
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3283]: https://gitlab.freedesktop.org/drm/intel/issues/3283
[i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
[i915#3301]: https://gitlab.freedesktop.org/drm/intel/issues/3301
[i915#3363]: https://gitlab.freedesktop.org/drm/intel/issues/3363
[i915#3462]: https://gitlab.freedesktop.org/drm/intel/issues/3462
[i915#49]: https://gitlab.freedesktop.org/drm/intel/issues/49
[i915#533]: https://gitlab.freedesktop.org/drm/intel/issues/533
Participating hosts (40 -> 37)
------------------------------
Additional (1): fi-rkl-11500t
Missing (4): fi-dg1-1 fi-bsw-cyan fi-bdw-samus fi-bsw-n3050
Build changes
-------------
* CI: CI-20190529 -> None
* IGT: IGT_6092 -> IGTPW_5837
CI-20190529: 20190529
CI_DRM_10125: 2581fff866b8af5127d259934684293cd729c844 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_5837: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/index.html
IGT_6092: d87087c321da07035d4f96d98c34e451b3ccb809 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5837/index.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for intel-gpu-top: Adapt for fdinfo stats
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: intel-gpu-top: Adapt for fdinfo stats
URL : https://patchwork.freedesktop.org/series/90463/
State : failure
== Summary ==
Applying: intel-gpu-top: Adapt for fdinfo stats
error: sha1 information is lacking or useless (tools/intel_gpu_top.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 intel-gpu-top: Adapt for fdinfo stats When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx