From patchwork Tue May 28 14:35:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 2625221 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 9424A3FDBC for ; Tue, 28 May 2013 14:40:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D55DE61BA for ; Tue, 28 May 2013 07:40:08 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [143.182.124.37]) by gabe.freedesktop.org (Postfix) with ESMTP id BE9F7E61B0 for ; Tue, 28 May 2013 07:35:52 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by azsmga102.ch.intel.com with ESMTP; 28 May 2013 07:35:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,758,1363158000"; d="scan'208";a="341355025" Received: from intelbox.fi.intel.com (HELO localhost) ([10.237.72.70]) by fmsmga001.fm.intel.com with ESMTP; 28 May 2013 07:35:44 -0700 From: Imre Deak To: intel-gfx@lists.freedesktop.org Date: Tue, 28 May 2013 17:35:32 +0300 Message-Id: <1369751732-19173-1-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1369750978-6040-2-git-send-email-imre.deak@intel.com> References: <1369750978-6040-2-git-send-email-imre.deak@intel.com> Subject: [Intel-gfx] [i-g-t PATCH v3 2/2] tests/lib: make sure the GPU is idle at test start and exit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64270 v2: - Make sure also that the GPU is idle at start and error exit of any test using drm_open_any(). (Daniel) v3: - actually call gem_quiescent_gpu() at exit Signed-off-by: Imre Deak --- lib/drmtest.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index 2d37fb6..d17dbb0 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -228,7 +228,7 @@ int drm_get_card(int master) } /** Open the first DRM device we can find, searching up to 16 device nodes */ -int drm_open_any(void) +static int __drm_open_any(void) { char *name; int ret, fd; @@ -248,6 +248,31 @@ int drm_open_any(void) return fd; } +static void quiescent_gpu_at_exit(int sig) +{ + int fd; + + fd = __drm_open_any(); + if (fd >= 0) { + gem_quiescent_gpu(fd); + close(fd); + } +} + +int drm_open_any(void) +{ + static int open_count; + int fd = __drm_open_any(); + + if (fd < 0 || __sync_fetch_and_add(&open_count, 1)) + return fd; + + gem_quiescent_gpu(fd); + drmtest_install_exit_handler(quiescent_gpu_at_exit); + + return fd; +} + /** * Open the first DRM device we can find where we end up being the master. */