From patchwork Tue Nov 1 18:15:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 9407807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B92F460585 for ; Tue, 1 Nov 2016 18:15:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B014828285 for ; Tue, 1 Nov 2016 18:15:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A513328A8B; Tue, 1 Nov 2016 18:15:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD2E428285 for ; Tue, 1 Nov 2016 18:15:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D0706E265; Tue, 1 Nov 2016 18:15:23 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 967846E03E for ; Tue, 1 Nov 2016 18:15:21 +0000 (UTC) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP; 01 Nov 2016 11:15:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,580,1473145200"; d="scan'208";a="26264164" Received: from ivy.ld.intel.com ([10.103.238.158]) by fmsmga005.fm.intel.com with ESMTP; 01 Nov 2016 11:15:07 -0700 From: Lionel Landwerlin To: intel-gfx@lists.freedesktop.org Date: Tue, 1 Nov 2016 18:15:07 +0000 Message-Id: <20161101181508.22698-1-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161004142111.20370-1-lionel.g.landwerlin@intel.com> References: <20161004142111.20370-1-lionel.g.landwerlin@intel.com> Subject: [Intel-gfx] [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This makes parsing options less complicated and easier to extend. v2: Fix device id parsing (atoi -> sscanf) (Sirisha) Combine with previous commit moving init function (Sirisha) v3: Fix behavior change between bash 4.3 & 4.4 in <<< with \n characters (Lionel) Signed-off-by: Lionel Landwerlin Reviewed-by: Sirisha Gandikota --- tools/aubdump.c | 58 ++++++++++++++++++++++++++++++++++++-------------- tools/intel_aubdump.in | 24 +++++++++++++++------ 2 files changed, 59 insertions(+), 23 deletions(-) -- 2.10.2 diff --git a/tools/aubdump.c b/tools/aubdump.c index 30dc742..f2cd2c1 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -426,6 +426,46 @@ close(int fd) return libc_close(fd); } +static void +maybe_init(void) +{ + static bool initialized = false; + FILE *config; + char *key, *value; + + if (initialized) + return; + + initialized = true; + + config = fdopen(3, "r"); + while (fscanf(config, "%m[^=]=%m[^\n]\n", &key, &value) != EOF) { + if (!strcmp(key, "verbose")) { + verbose = 1; + } else if (!strcmp(key, "device")) { + fail_if(sscanf(value, "%i", &device) != 1, + "intel_aubdump: failed to parse device id '%s'", + value); + device_override = true; + } else if (!strcmp(key, "file")) { + filename = value; + file = fopen(filename, "w+"); + fail_if(file == NULL, + "intel_aubdump: failed to open file '%s'\n", + filename); + } else { + fprintf(stderr, "intel_aubdump: unknown option '%s'\n", key); + } + + free(key); + free(value); + } + fclose(config); + + bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); + fail_if(bos == NULL, "intel_aubdump: out of memory\n"); +} + int ioctl(int fd, unsigned long request, ...) { @@ -447,6 +487,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 +592,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 diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in index feee23a..18fd03b 100644 --- a/tools/intel_aubdump.in +++ b/tools/intel_aubdump.in @@ -21,29 +21,38 @@ EOF exit 0 } -verbose=0 -device=0 +args="" +command="" +file="" + +function add_arg() { + arg=$1 + args="$args$arg\n" +} while true; do case "$1" in -o) file=$2 + add_arg "file=${f:-$(basename ${f}).aub}" shift 2 ;; -v) - verbose=1 + add_arg "verbose=1" shift 1 ;; -o*) file=${1##-o} + add_arg "file=${file:-$(basename ${file}).aub}" shift ;; --output=*) file=${1##--output=} + add_arg "file=${file:-$(basename ${file}).aub}" shift ;; --device=*) - device=${1##--device=} + add_arg "device=${1##--device=}" shift ;; --help) @@ -66,12 +75,13 @@ done [ -z $1 ] && show_help -file=${file:-$(basename $1).aub} +[ -z $file ] && add_arg "file=intel.aub" prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \ - INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \ - exec -- "$@" + exec -- "$@" 3<