From patchwork Sun Aug 28 16:37:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9302803 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 15C72607D6 for ; Sun, 28 Aug 2016 16:37:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 071752869C for ; Sun, 28 Aug 2016 16:37:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFC9B28781; Sun, 28 Aug 2016 16:37:55 +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 85FF92869C for ; Sun, 28 Aug 2016 16:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751AbcH1Qhy (ORCPT ); Sun, 28 Aug 2016 12:37:54 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36816 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755745AbcH1Qhx (ORCPT ); Sun, 28 Aug 2016 12:37:53 -0400 Received: by mail-wm0-f66.google.com with SMTP id i138so6448524wmf.3 for ; Sun, 28 Aug 2016 09:37:52 -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; bh=ADxa9J5H6WXaamWoFDoYwfGNaNVo+8Ui1jXW63NgjPk=; b=rmXXyh8+lRiuWtXjyRTus0Ze+iCZgyc6KrQDeQgipLhmFl+DsRVJ+ANW2oq0a7fAND SoHH18uOqp34DMo9B/ZCwiQfjs+Vjd4Y+r54/Ct+6i6yRpnnsBEOoXVuntUGFPVyMrRh NMC1P+LpounoVCFZ45A4gYXzHNIF/T/bA+ufjzRb6ZJGfeY8O8wm4rVlu8tiO8kVy4H5 botP3URQe0qwt6M+riTOzqO8Wz3yo7vyrEGbbn967/9nUY3t/X4IPfGkiXhkzAFPdRzA ZoYKVwxZtbGXc/a2CAtLFMHOKGrOiBjmbzC/4czZCGo91KhmBP2gWmQA0R+fOWLpMPMH JK2A== 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; bh=ADxa9J5H6WXaamWoFDoYwfGNaNVo+8Ui1jXW63NgjPk=; b=C1jw6wWJc1z8CKyK63FwLx0bY/fDsXPA+O8DCeVpg9jXvCRLJYIycDTnyOb6CFh1e6 ecaD+hoRqEwlZLeW6MJgUayARFuEuM6dEUToO5YHkctmdHGOdnwWmIZ3ceRFwdFZklYP az5bHoFhhnz3XT6bpXVERS/6Y2zLh8u7iDWPwIGuFV8+VWw7+i9xD2IBe4vSovQbNa1n Q24M0lw+Kop99/3BhAR5ov86UhO7AdTAjghJ3P8Uh1AWdb15YEMVZgnWzl0m6fayJlX7 biJFbdZKstKU0z847MKNIl53SkK/io0w4tJSDSG93pPTQMQpOCoX0JMtCu3HOi7D9xp7 24VA== X-Gm-Message-State: AE9vXwNk6Etu9Ad++58ptUZ4ifseX/1Ib9u6mdg0+VH/00K1NNdFcCtO9TEBd8FRTHmHsg== X-Received: by 10.195.12.77 with SMTP id eo13mr12038459wjd.142.1472402271802; Sun, 28 Aug 2016 09:37:51 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id g1sm30171896wjy.5.2016.08.28.09.37.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Aug 2016 09:37:50 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Cc: Chris Wilson , Sumit Semwal , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH] dma-buf: Do a fast lockless check for poll with timeout=0 Date: Sun, 28 Aug 2016 17:37:47 +0100 Message-Id: <20160828163747.32751-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.9.3 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();