From patchwork Fri Oct 7 10:00:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 9365919 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 0E09260752 for ; Fri, 7 Oct 2016 10:01:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21F42948B for ; Fri, 7 Oct 2016 10:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E61B42948D; Fri, 7 Oct 2016 10:01:05 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 8CC6A2948B for ; Fri, 7 Oct 2016 10:01:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3F0C46EB5A; Fri, 7 Oct 2016 10:01:00 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C0896EB5A for ; Fri, 7 Oct 2016 10:00:59 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id 123so2142570wmb.3 for ; Fri, 07 Oct 2016 03:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ffnyCRsGw6wTHH7oiwIsivlA3IcPOipLGbK2YtAlXE0=; b=EVX+pDl09S6Xd7Dz4ByDJV5dRmHwweORKdvxEyAWc5JVL5nkZXqgzFEEc982dXcPUf F0EMJH+xYzKkOdYMUhVsq+JyzXNFVDoUME0FZHsDHbh+G2jwMhIagHvSnPDWk0GjXsIj G/3wC1XxkhDz8iPPPSF3KLu1+9hgwmgnVklLie99E75rJkY6jT3CpfOYNlnMHSYnMNiA swvxTUuCmpKlHvcJdVz+XaQY62o3KoGym5smhg1jswhbyDAton54kApbpTxCNmFRGWs6 +RKmE2NQxkchpcnNuBRUG+tW9YXJH5BFi9U6G00RDkJUhJEnk0Flo2Ok36y/Elb8eASd rcrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ffnyCRsGw6wTHH7oiwIsivlA3IcPOipLGbK2YtAlXE0=; b=TlDXn2uYra0ZCbVsKr8SOdY7Bp9A6lMm4Py9H3D3fy6d67h31A9vuP4mi922GgckTC CUDmhGrOKaoecQFpzwpz1tmcIClfUDaAAAyiSNEX5RbqcFqBQKh7O+0m9bBNIFOXna0p 9CAqBxsOEqoF0AhyMb1Dt3T9tAAxQTbZslTYPa2YMrnfmhFmsyF2t4dxwhjT3uLCQ3/S KtdVkDnThTTnDPTMATH7NHUUNcogbPdTbyOL+6ldcTNtn+WTqTLU42O6Bx1uCqIuinp5 L2ubq22F34cJBkKEiyQyU059MUcFH9djQbI2iZKWvL2sNSTIBB7OSE9yUqC1kHnwLcfg gXUw== X-Gm-Message-State: AA6/9RlNf5OAiPOSuTsMTtdPbs6AE/avJrw5QMd9dEWCnv75G3+nD/LXvf1gzQEB8We0Cg== X-Received: by 10.28.39.133 with SMTP id n127mr19843886wmn.6.1475834457550; Fri, 07 Oct 2016 03:00:57 -0700 (PDT) Received: from localhost.localdomain ([192.198.151.61]) by smtp.googlemail.com with ESMTPSA id jr3sm18810863wjb.13.2016.10.07.03.00.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Oct 2016 03:00:56 -0700 (PDT) From: Lionel Landwerlin X-Google-Original-From: Lionel Landwerlin To: intel-gfx@lists.freedesktop.org Date: Fri, 7 Oct 2016 11:00:54 +0100 Message-Id: <20161007100054.17016-1-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <31499A302E3099449587C4E11284CEE1ABCBD522@ORSMSX103.amr.corp.intel.com> References: <31499A302E3099449587C4E11284CEE1ABCBD522@ORSMSX103.amr.corp.intel.com> Subject: [Intel-gfx] [PATCH v2 i-g-t] 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) Signed-off-by: Lionel Landwerlin --- tools/aubdump.c | 58 ++++++++++++++++++++++++++++++++++++-------------- tools/intel_aubdump.in | 22 +++++++++++++------ 2 files changed, 57 insertions(+), 23 deletions(-) -- 2.9.3 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..445b60f 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,11 @@ 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<<< `printf '%b' "$args"`