From patchwork Tue Jul 3 19:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10505017 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 3D765601D3 for ; Tue, 3 Jul 2018 19:17:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B46328C60 for ; Tue, 3 Jul 2018 19:17:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D36528C7F; Tue, 3 Jul 2018 19:17:40 +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=BAD_ENC_HEADER,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 B926928C60 for ; Tue, 3 Jul 2018 19:17:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F06266E8EF; Tue, 3 Jul 2018 19:16:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0067.outbound.protection.outlook.com [104.47.36.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id D6D9B6E8E6 for ; Tue, 3 Jul 2018 19:16:53 +0000 (UTC) Received: from fedoratest.localdomain (155.4.205.56) by DM6PR05MB4587.namprd05.prod.outlook.com (2603:10b6:5:9f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.11; Tue, 3 Jul 2018 19:16:50 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org Subject: [PATCH -next 13/15] drm/vmwgfx: Reorganize the fence wait loop Date: Tue, 3 Jul 2018 21:14:58 +0200 Message-Id: <20180703191500.2374-14-thellstrom@vmware.com> X-Mailer: git-send-email 2.18.0.rc1 In-Reply-To: <20180703191500.2374-1-thellstrom@vmware.com> References: <20180703191500.2374-1-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: DM5PR21CA0042.namprd21.prod.outlook.com (2603:10b6:3:ed::28) To DM6PR05MB4587.namprd05.prod.outlook.com (2603:10b6:5:9f::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d7971ce-9c26-4c73-8e51-08d5e119881a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM6PR05MB4587; X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4587; 3:Nf+FX6UCQAf1HJC81R9tElsg4wm2q2YQscbGg+5fkd2c113IeFRNhrGx9flEpxSM8WI18C4L9OBhI0y3N5ym0BhTCcIPhoLuetna2Wo/6scHFwAwV3ePWynQCMKYQCECWRqFn6uZ72cFJJmxIoASRQARBUBqWSSM21/ZYLuVFAqFpWnzfwvGn3ACmJx0P9NsuEC/qEh4CmoG3F4tf1ifH4VIobXTxD4VV8EsanRTOb97j//FVBk9o4YFqtoGh0cR; 25:xmU0gi3Jjj9iMHn2JnWOevUvFzHo6Z7oxs8M5bXrrKfXWAFs6HEtm/Zzxm4vnrqsHYiFgOe0WKJSwZvcZA/dPRPJXhbdgVh2e8JV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YQpDnVlS5T6li+hQ1xOclacHmKwmSxcuHyThR+PC/VE4DIyqj6; 4:OWX6guXBS+r42PG2/rZPVYQRa1dJYK1NUhMQNAIX7CvcHP3hA367Jgq3aEwnrAxiEwyNbHlYuBoQ0cm14pfyK4z0+g75EMvrdoUK5h7tq5fUcUse05Gz3++MjmA4FwogS1HHs6LPeXQF7QNBfv+OUcGLD5SiOp8KjGo8G+T5wbVHOyX081//Eo42ztXWiDWysOwcc8U7frYm0YBr35tUMqeSmN6PoYn97GBH1bXyjCKHPcsPdz/l/u06S8jaaLIgUUcpdLzjW7NjgGDkCivqloEyBj8OAKxlQxMWgwiil8y1c4luwvED7isQxni4Kids X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DM6PR05MB4587; BCL:0; PCL:0; RULEID:; SRVR:DM6PR05MB4587; X-Forefront-PRVS: 0722981D2A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(366004)(39860400002)(396003)(376002)(346002)(199004)(189003)(2361001)(53936002)(76176011)(68736007)(52116002)(51416003)(47776003)(26005)(2351001)(50226002)(16526019)(97736004)(86362001)(386003)(2906002)(6506007)(66066001)(186003)(316002)(16586007)(48376002)(446003)(6486002)(50466002)(14444005)(11346002)(2616005)(1076002)(956004)(6116002)(6512007)(476003)(81166006)(8676002)(81156014)(36756003)(3846002)(5660300001)(486006)(107886003)(106356001)(305945005)(25786009)(7736002)(4326008)(478600001)(6916009)(105586002)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR05MB4587; H:fedoratest.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR05MB4587; 23:ENGA5IXrDSiem77HxtRFXlH+vTg1MahjegDtBR7WB?= =?us-ascii?Q?D8a4razEbep6RXFLRF6blCjGZGIX6bzssXRMY9ApSnxnYZudW+3M3SMNr70K?= =?us-ascii?Q?DuyH3f6X5/WvUNyQv0cz8RyN5Wo/Z96Vh2pHYUBIcvOxkIVUZ+WPesJc+tLX?= =?us-ascii?Q?zzGwZmIw18w0jIn7nz6itrVeIKHfLOu0TB8msFuJPzc9FhHj4I0ykR2qP02/?= =?us-ascii?Q?vXRkny7giUPkZV87ErNmnOuk0sMSprLnJXZZ/izrTFC9/52f7WUvSy16+wEk?= =?us-ascii?Q?HgSEx+nY2cFCDnlMTm23aqCL0ad4Uy76uexHTPM95X5Sn3vueLrjoBkip7Yg?= =?us-ascii?Q?Rwe86u/U7oPCc75babNDtc0g9AJJ/6cfwadK0DXTe812tFblhcv9rDXXk2t1?= =?us-ascii?Q?WDbUz5hbXy0+LFhtq+qpZL8k3hQUf4aAd4weUFPOUK3eO0dDYQ8rxr/2XTz8?= =?us-ascii?Q?RAQN48apskeaISZlBgBKni7pnM/4H13MN3C/sRMXBZMBBvO9SXrAVXz305nd?= =?us-ascii?Q?zrYsaEZqTm1zsm6ik5L4BobJwhAnja3mMgYimBs4agI7F8Z7+mVl3fajVgXQ?= =?us-ascii?Q?p8vWPelQVzpdhm4F/3hjUmBp/h/+D3w8yPOr8bpZYgH4FXoChqaufWxXM/JC?= =?us-ascii?Q?5kMkh0Je/QddrwnCOy/vWnpTrLBCCmtt75LZG5zWAAfByqxV++piNsW829pP?= =?us-ascii?Q?rZAkmaGRrDBBZ6AorD95vbE6fxyaPY4ray/UG9pLeEytLBCN7RdpJCrtQ0wV?= =?us-ascii?Q?XjlO+jcRMaQ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REoDskNnRmD9hYaIykjxxCX/qkunhKeVotyAmVzoB+hVKQ8ogNHu3RKx4AjMr6RyOw2K4Zt3E4GS1sFGL18JQ2cXMwSG4YkM/4SFbN6itvfVEexumd+AFR1zLZ6BU/WA= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2018 19:16:50.9752 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d7971ce-9c26-4c73-8e51-08d5e119881a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR05MB4587 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , linux-graphics-maintainer@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reorganize the fence wait loop somewhat to make it look more like the examples in set_current_state() kerneldoc, and add some code comments. Also if we're about to time out, make sure we check again whether the fence is actually signaled. Signed-off-by: Thomas Hellstrom Reviewed-by: Brian Paul Reviewed-by: Deepak Rawat --- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 38 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c index 9ed544f8958f..ea41d74d8341 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c @@ -175,7 +175,6 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout) struct vmw_private *dev_priv = fman->dev_priv; struct vmwgfx_wait_cb cb; long ret = timeout; - unsigned long irq_flags; if (likely(vmw_fence_obj_signaled(fence))) return timeout; @@ -183,7 +182,7 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout) vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC); vmw_seqno_waiter_add(dev_priv); - spin_lock_irqsave(f->lock, irq_flags); + spin_lock(f->lock); if (intr && signal_pending(current)) { ret = -ERESTARTSYS; @@ -194,30 +193,45 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout) cb.task = current; list_add(&cb.base.node, &f->cb_list); - while (ret > 0) { + for (;;) { __vmw_fences_update(fman); - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) - break; + /* + * We can use the barrier free __set_current_state() since + * DMA_FENCE_FLAG_SIGNALED_BIT + wakeup is protected by the + * fence spinlock. + */ if (intr) __set_current_state(TASK_INTERRUPTIBLE); else __set_current_state(TASK_UNINTERRUPTIBLE); - spin_unlock_irqrestore(f->lock, irq_flags); - ret = schedule_timeout(ret); + if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) { + if (ret == 0 && timeout > 0) + ret = 1; + break; + } - spin_lock_irqsave(f->lock, irq_flags); - if (ret > 0 && intr && signal_pending(current)) + if (intr && signal_pending(current)) { ret = -ERESTARTSYS; - } + break; + } + if (ret == 0) + break; + + spin_unlock(f->lock); + + ret = schedule_timeout(ret); + + spin_lock(f->lock); + } + __set_current_state(TASK_RUNNING); if (!list_empty(&cb.base.node)) list_del(&cb.base.node); - __set_current_state(TASK_RUNNING); out: - spin_unlock_irqrestore(f->lock, irq_flags); + spin_unlock(f->lock); vmw_seqno_waiter_remove(dev_priv);