From patchwork Mon Aug 29 07:08:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9303199 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 54CB96077C for ; Mon, 29 Aug 2016 07:25:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42D1426E54 for ; Mon, 29 Aug 2016 07:25:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3768328736; Mon, 29 Aug 2016 07:25:42 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E1A26E54 for ; Mon, 29 Aug 2016 07:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756489AbcH2HZh (ORCPT ); Mon, 29 Aug 2016 03:25:37 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34289 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889AbcH2HZg (ORCPT ); Mon, 29 Aug 2016 03:25:36 -0400 Received: by mail-wm0-f65.google.com with SMTP id q128so8258758wma.1 for ; Mon, 29 Aug 2016 00:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=RrdtNPrq/zTeHE4AQe/NIatyCokTwubYsKXI2PwC0Ww=; b=xdUAAEwkWKuvAfgWjn4tuMHZ6VDXb3K6MUecAjX4o070yVQJj9LeY96QjlLRCZox1j mQafjkDeHNeiTr5KcHEGd+GcCimFgaGOKSzDmlXhew4Xyi8oGghqrgI2rCZ9GU9KsYo4 4QBGrCbb58cbEIkdEVsirb407EurgxfMjhFjj8S+zWuGmHqJnZdmyW0jc8smj4Ela3VY i4U4GifgBqqQ4wWn2FSxqlOyqe4w9hJ8NW9/Pmic53sOeDjObYw40IiBz26n7bnvlkuY F1pelMptPMy2SIN9wKHA4/lp9pLutGYasgMSCCAWNZfnqZcmzcw7qtWXAEr0XVcZQcRI jCdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=RrdtNPrq/zTeHE4AQe/NIatyCokTwubYsKXI2PwC0Ww=; b=DGMdTL61FgdbZeimsaTqaRq8gMS4KSiotLYU6rTxA+vZeaTCFh1FO5bQnk5nCH+le2 JIvsTiMLCjlp8JkiPV8lnDGm0oijAV0u+zqGpjihQ9lN0QJ+hV2j4xAeZ28mppXem4pR zeAUKwgsZO64f3hjLev68guqRC6/WVZYn/8YBbtvGWhAQ2/cehCpjWEPBA8VLlKl4Rri BQup+eyvKcKWXgbLqcLHljowvFooMvrrvYWWX++jaSC8gFiiV+5J+hK1I4vNctegruoe uWDyVIGAaa2xON3U2PAP1uJqNe4/gSNF5Obllef2ylmVbcG7xsy/U7bu1NnNeVNewSJs DTkg== X-Gm-Message-State: AE9vXwMMmzoBQdexWVlw51fonmU59EB94vmgjZVMgJbQdagg+L61JtzbEueN/tcGhCgIrA== X-Received: by 10.194.173.4 with SMTP id bg4mr13843265wjc.28.1472454533499; Mon, 29 Aug 2016 00:08:53 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v203sm11954826wmv.2.2016.08.29.00.08.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 00:08:52 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , Sumit Semwal , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 11/11] dma-buf: Do a fast lockless check for poll with timeout=0 Date: Mon, 29 Aug 2016 08:08:34 +0100 Message-Id: <20160829070834.22296-11-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160829070834.22296-1-chris@chris-wilson.co.uk> References: <20160829070834.22296-1-chris@chris-wilson.co.uk> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we install a callback for performing poll on a dma-buf, irrespective of the timeout. This involves taking a spinlock, as well as unnecessary work, and greatly reduces scaling of poll(.timeout=0) across multiple threads. We can query whether the poll will block prior to installing the callback to make the busy-query fast. Single thread: 60% faster 8 threads on 4 (+4 HT) cores: 600% faster Still not quite the perfect scaling we get with a native busy ioctl, but poll(dmabuf) is faster due to the quicker lookup of the object and avoiding drm_ioctl(). Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Reviewed-by: Daniel Vetter --- drivers/dma-buf/dma-buf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index cf04d249a6a4..c7a7bc579941 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -156,6 +156,18 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll) if (!events) return 0; + if (poll_does_not_wait(poll)) { + if (events & POLLOUT && + !reservation_object_test_signaled_rcu(resv, true)) + events &= ~(POLLOUT | POLLIN); + + if (events & POLLIN && + !reservation_object_test_signaled_rcu(resv, false)) + events &= ~POLLIN; + + return events; + } + retry: seq = read_seqcount_begin(&resv->seq); rcu_read_lock();