From patchwork Mon Mar 27 11:08:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ander Conselvan de Oliveira X-Patchwork-Id: 9646433 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 5A6DE602D6 for ; Mon, 27 Mar 2017 11:08:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D76F28249 for ; Mon, 27 Mar 2017 11:08:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F6F927F85; Mon, 27 Mar 2017 11:08:34 +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_SIGNED, 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 C179827F85 for ; Mon, 27 Mar 2017 11:08:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 637D26E1C2; Mon, 27 Mar 2017 11:08:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 721326E1C2 for ; Mon, 27 Mar 2017 11:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490612912; x=1522148912; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=XSPXt0yulrJ2VrUYJIBLoN4G9gT0K0t1WBR3FPTxpTA=; b=WyNNssIx9gMdan1yPZ0ZxVDRc2zXFPGuNC5VMaIFZyJFTQMKuyWZNpVh U/5oUT+KXCp8WtcMQAqTtF73K7ZkLQ==; Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2017 04:08:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,231,1486454400"; d="scan'208";a="65463277" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP; 27 Mar 2017 04:08:31 -0700 Received: from localhost (aconselv-mobl3.fi.intel.com [10.237.66.54]) by linux.intel.com (Postfix) with ESMTP id 9F0CA6A4080; Mon, 27 Mar 2017 04:08:24 -0700 (PDT) From: Ander Conselvan de Oliveira To: intel-gfx@lists.freedesktop.org Date: Mon, 27 Mar 2017 14:08:28 +0300 Message-Id: <20170327110828.9102-1-ander.conselvan.de.oliveira@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170327090930.GA25571@nuc-i3427.alporthouse.com> References: <20170327090930.GA25571@nuc-i3427.alporthouse.com> Cc: Ander Conselvan de Oliveira Subject: [Intel-gfx] [PATCH i-g-t] lib/dummyload: Handle timeout in a new thread instead of signal handler 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 Currently, the main thread needs to wakeup to run the signal handler that ends a spin batch. When testing whether a function call succesfully waits for a batch to complete, this behavior is undesired. It actually invalidates the test. Fix this by spawning a new thread to handle the timeout. v2: Get rid of mutexes. (Chris) Cc: Chris Wilson Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Chris Wilson --- lib/igt_dummyload.c | 45 ++++++--------------------------------------- lib/igt_dummyload.h | 1 - 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index 019c1fb..b25e023 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -174,27 +174,11 @@ igt_spin_batch_new(int fd, int engine, unsigned int dep_handle) return spin; } -static void clear_sig_handler(int sig) +static void notify(union sigval arg) { - struct sigaction act; + igt_spin_t *spin = arg.sival_ptr; - memset(&act, 0, sizeof(act)); - act.sa_handler = SIG_DFL; - igt_assert(sigaction(sig, &act, NULL) == 0); -} - -static void sig_handler(int sig, siginfo_t *info, void *arg) -{ - struct igt_spin *iter; - - igt_list_for_each(iter, &spin_list, link) { - if (iter->signo == info->si_signo) { - igt_spin_batch_end(iter); - return; - } - } - - clear_sig_handler(sig); + igt_spin_batch_end(spin); } /** @@ -208,10 +192,8 @@ static void sig_handler(int sig, siginfo_t *info, void *arg) */ void igt_spin_batch_set_timeout(igt_spin_t *spin, int64_t ns) { - static int spin_signo = 48; /* Midpoint of SIGRTMIN, SIGRTMAX */ timer_t timer; struct sigevent sev; - struct sigaction act, oldact; struct itimerspec its; igt_assert(ns > 0); @@ -220,25 +202,13 @@ void igt_spin_batch_set_timeout(igt_spin_t *spin, int64_t ns) igt_assert(!spin->timer); - /* SIGRTMAX is used by valgrind, SIGRTMAX - 1 by igt_fork_hang_detector */ - if (spin_signo >= SIGRTMAX - 2) - spin_signo = SIGRTMIN; - spin->signo = ++spin_signo; - memset(&sev, 0, sizeof(sev)); - sev.sigev_notify = SIGEV_SIGNAL | SIGEV_THREAD_ID; - sev.sigev_notify_thread_id = gettid(); - sev.sigev_signo = spin->signo; + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_value.sival_ptr = spin; + sev.sigev_notify_function = notify; igt_assert(timer_create(CLOCK_MONOTONIC, &sev, &timer) == 0); igt_assert(timer); - memset(&oldact, 0, sizeof(oldact)); - memset(&act, 0, sizeof(act)); - act.sa_sigaction = sig_handler; - act.sa_flags = SA_SIGINFO; - igt_assert(sigaction(spin->signo, &act, &oldact) == 0); - igt_assert(oldact.sa_sigaction == NULL); - memset(&its, 0, sizeof(its)); its.it_value.tv_sec = ns / NSEC_PER_SEC; its.it_value.tv_nsec = ns % NSEC_PER_SEC; @@ -260,9 +230,6 @@ void igt_spin_batch_end(igt_spin_t *spin) *spin->batch = MI_BATCH_BUFFER_END; __sync_synchronize(); - - if (spin->signo) - clear_sig_handler(spin->signo); } /** diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h index 2adfadf..41125e3 100644 --- a/lib/igt_dummyload.h +++ b/lib/igt_dummyload.h @@ -33,7 +33,6 @@ typedef struct igt_spin { unsigned int handle; timer_t timer; - int signo; struct igt_list link; uint32_t *batch; } igt_spin_t;