Message ID | 20161006151635.28573-1-lionel.g.landwerlin@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
>-----Original Message----- >From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf Of >Lionel Landwerlin >Sent: Thursday, October 06, 2016 8:17 AM >To: intel-gfx@lists.freedesktop.org >Subject: [Intel-gfx] [PATCH i-g-t 1/3] tools: intel_aubdump: avoid initializing >multiple times > >For some reason init() seems to be called multiple times. Let's move the >initialization to the first ioctl(). > >Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> >--- > tools/aubdump.c | 44 ++++++++++++++++++++++++++++---------------- > 1 file changed, 28 insertions(+), 16 deletions(-) > >diff --git a/tools/aubdump.c b/tools/aubdump.c index 30dc742..a2ac7f1 100644 >--- a/tools/aubdump.c >+++ b/tools/aubdump.c >@@ -426,6 +426,32 @@ close(int fd) > return libc_close(fd); > } > >+static void >+maybe_init(void) >+{ >+ static bool initialized = false; >+ const char *args = getenv("INTEL_AUBDUMP_ARGS"); >+ >+ if (initialized) >+ return; >+ >+ initialized = true; >+ >+ if (sscanf(args, "verbose=%d;file=%m[^;];device=%i", >+ &verbose, &filename, &device) != 3) >+ filename = strdup("intel.aub"); >+ fail_if(filename == NULL, "intel_aubdump: out of memory\n"); >+ >+ if (device) >+ device_override = true; >+ >+ bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); >+ fail_if(bos == NULL, "intel_aubdump: out of memory\n"); >+ >+ file = fopen(filename, "w+"); >+ fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", >+filename); } >+ [SG] Since you are adding a new method anyway, I would combine patches 1 and 2 and send only 1 patch instead. Patch 2 is also working on the same new method with few additional changes. Additionally, please verify if intel_aubdump works with --device=<pccid> option. It failed for me for 0x1602 (bdw) but works without device option on system (hsw in my case). > int > ioctl(int fd, unsigned long request, ...) { @@ -447,6 +473,8 @@ ioctl(int fd, >unsigned long request, ...) > } > > if (fd == drm_fd) { >+ maybe_init(); >+ > switch (request) { > case DRM_IOCTL_I915_GETPARAM: { > struct drm_i915_getparam *getparam = argp; @@ - >550,26 +578,10 @@ ioctl(int fd, unsigned long request, ...) static void > init(void) > { >- const char *args = getenv("INTEL_AUBDUMP_ARGS"); >- > libc_close = dlsym(RTLD_NEXT, "close"); > libc_ioctl = dlsym(RTLD_NEXT, "ioctl"); > fail_if(libc_close == NULL || libc_ioctl == NULL, > "intel_aubdump: failed to get libc ioctl or close\n"); >- >- if (sscanf(args, "verbose=%d;file=%m[^;];device=%i", >- &verbose, &filename, &device) != 3) >- filename = strdup("intel.aub"); >- fail_if(filename == NULL, "intel_aubdump: out of memory\n"); >- >- if (device) >- device_override = true; >- >- bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); >- fail_if(bos == NULL, "intel_aubdump: out of memory\n"); >- >- file = fopen(filename, "w+"); >- fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", >filename); > } > > static int >-- >2.9.3 > >_______________________________________________ >Intel-gfx mailing list >Intel-gfx@lists.freedesktop.org >https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff --git a/tools/aubdump.c b/tools/aubdump.c index 30dc742..a2ac7f1 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -426,6 +426,32 @@ close(int fd) return libc_close(fd); } +static void +maybe_init(void) +{ + static bool initialized = false; + const char *args = getenv("INTEL_AUBDUMP_ARGS"); + + if (initialized) + return; + + initialized = true; + + if (sscanf(args, "verbose=%d;file=%m[^;];device=%i", + &verbose, &filename, &device) != 3) + filename = strdup("intel.aub"); + fail_if(filename == NULL, "intel_aubdump: out of memory\n"); + + if (device) + device_override = true; + + bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); + fail_if(bos == NULL, "intel_aubdump: out of memory\n"); + + file = fopen(filename, "w+"); + fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename); +} + int ioctl(int fd, unsigned long request, ...) { @@ -447,6 +473,8 @@ ioctl(int fd, unsigned long request, ...) } if (fd == drm_fd) { + maybe_init(); + switch (request) { case DRM_IOCTL_I915_GETPARAM: { struct drm_i915_getparam *getparam = argp; @@ -550,26 +578,10 @@ ioctl(int fd, unsigned long request, ...) static void init(void) { - const char *args = getenv("INTEL_AUBDUMP_ARGS"); - libc_close = dlsym(RTLD_NEXT, "close"); libc_ioctl = dlsym(RTLD_NEXT, "ioctl"); fail_if(libc_close == NULL || libc_ioctl == NULL, "intel_aubdump: failed to get libc ioctl or close\n"); - - if (sscanf(args, "verbose=%d;file=%m[^;];device=%i", - &verbose, &filename, &device) != 3) - filename = strdup("intel.aub"); - fail_if(filename == NULL, "intel_aubdump: out of memory\n"); - - if (device) - device_override = true; - - bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); - fail_if(bos == NULL, "intel_aubdump: out of memory\n"); - - file = fopen(filename, "w+"); - fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename); } static int
For some reason init() seems to be called multiple times. Let's move the initialization to the first ioctl(). Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> --- tools/aubdump.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-)