From patchwork Fri Aug 31 12:18:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10583649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 518A95A4 for ; Fri, 31 Aug 2018 12:19:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CFC72BCE6 for ; Fri, 31 Aug 2018 12:19:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 213D52BD08; Fri, 31 Aug 2018 12:19:10 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 251FF2BCE6 for ; Fri, 31 Aug 2018 12:19:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BA3E36E8D6; Fri, 31 Aug 2018 12:19:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id CECB66E8D3; Fri, 31 Aug 2018 12:19:06 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 13438675-1500050 for multiple; Fri, 31 Aug 2018 13:18:55 +0100 From: Chris Wilson To: igt-dev@lists.freedesktop.org Date: Fri, 31 Aug 2018 13:18:53 +0100 Message-Id: <20180831121853.18786-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.19.0.rc1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] lib: Stop caching __drm_device_id X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP In a multi-device system there is no guarantee that the fd being probed in intel_get_drm_devid() is the same as was opened earlier. Any cache may outlive the fd, so is frought with lifetime issues. The primary reason for caching the devid was to avoid extra ioctls in the dmesg/strace, but hopefully all users now grab the id in their fixture and not inside every function. Signed-off-by: Chris Wilson Cc: Katarzyna Dec Reviewed-by: Rodrigo Vivi --- lib/drmtest.c | 3 --- lib/intel_chipset.c | 14 +++++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index fae6f86f2..ecb535f5d 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -75,8 +75,6 @@ * and [batchbuffer](igt-gpu-tools-intel-batchbuffer.html) libraries as dependencies. */ -uint16_t __drm_device_id; - static int __get_drm_device_name(int fd, char *name) { drm_version_t version; @@ -142,7 +140,6 @@ static bool has_known_intel_chipset(int fd) if (!intel_gen(devid)) return false; - __drm_device_id = devid; return true; } diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c index ab35fa70c..4748a3fb8 100644 --- a/lib/intel_chipset.c +++ b/lib/intel_chipset.c @@ -112,8 +112,6 @@ intel_get_pci_device(void) return pci_dev; } -extern uint16_t __drm_device_id; - /** * intel_get_drm_devid: * @fd: open i915 drm file descriptor @@ -127,16 +125,22 @@ extern uint16_t __drm_device_id; uint32_t intel_get_drm_devid(int fd) { + struct drm_i915_getparam gp; const char *override; + int devid = 0; igt_assert(is_i915_device(fd)); - igt_assert(__drm_device_id); override = getenv("INTEL_DEVID_OVERRIDE"); if (override) return strtol(override, NULL, 0); - else - return __drm_device_id; + + memset(&gp, 0, sizeof(gp)); + gp.param = I915_PARAM_CHIPSET_ID; + gp.value = &devid; + ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)); + + return devid; } /**