From patchwork Wed Nov 15 12:31:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10059299 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 5B43660231 for ; Wed, 15 Nov 2017 12:32:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51DC229F58 for ; Wed, 15 Nov 2017 12:32:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DBAD29F55; Wed, 15 Nov 2017 12:32:01 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 DECC629F55 for ; Wed, 15 Nov 2017 12:32:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4471E6E4D7; Wed, 15 Nov 2017 12:31:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA1D36E11A; Wed, 15 Nov 2017 12:31:57 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id p96so20295838wrb.7; Wed, 15 Nov 2017 04:31:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uQKNJLbVIA50hkIeEFznH5ENvH/PMlSN1IN/tBUqv7E=; b=TncBLWOTJJ2yf1WqFSXeM7SCnTfvmsNeuqwcHVEOO7YTf1rrWxwnD2tOe806HW05ta qyWQgctbns9nCDuEDTbzd9UwXsI1pukJTfjB46wfxCGQJ0KqkIolimVrgoje7TlerkVC Sb/ZWg+jqq8596pBs5SFgO1AwoyiuObrabmHV8BwxAkhX5kwEHbjXIvBr/sfaUqRGEqF KBvETPnWm7xM1jgSqUUehYjSvvqVUA03OVIo7WDq2DPXeKmIf3GGvYkzitDciI4cvOXH NsNAZoyZu5cjiWqHPMhASNFEjg6B5dwfXAdoQ6BcgsNo9m449EFoK/JENYU8ojw+80Wm dhLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQKNJLbVIA50hkIeEFznH5ENvH/PMlSN1IN/tBUqv7E=; b=F8jYVwm10kw82RPlXz5ltTdIuxquHaoGo7U8yTU5ikJaRUGlsGB3/ouxoRt4Cne/WG YTSTuMaGKC50351WqqZvPhCTTnCrnPc/UkIQyxonRxBjNaI9jwtTZu+r4glH7RDF5ZvX Y+mPzU8sFxzCMim0G6aT/EIu8AibQAxyhFdIcf8R/p5ih1MYmMBXaH2LjTezwt94ztJJ SUnQiUrJV4nbeKtwFpGcRpqjl+z4knbPIYrQ5Gdes9ltBFbtJZeQAAqG9cgQWRX8gYqJ nf07a44ht6q1tR4Z263n++jwA3F01+dngCGvMSKxlkUTYjiuEqny4k6zx6jQjHCxvIvA P6qQ== X-Gm-Message-State: AJaThX6g3qCggWu/U/9EkIjSN3MohDRWI7x0MRaWJSgOn6Oazt9WBnOH gabLBK2bAU2S5Wr3q2PYMIq8Yw== X-Google-Smtp-Source: AGs4zMbYrWVRNhm9AqbzTLaCfI1/yyafZzNh/xRsVFBzfLTqCGDNYr82pXVHp4pYyn1B3ivOrie7Aw== X-Received: by 10.223.135.143 with SMTP id b15mr11892933wrb.278.1510749116106; Wed, 15 Nov 2017 04:31:56 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:9494:e3ad:b2a6:adce]) by smtp.gmail.com with ESMTPSA id r63sm9749023wmg.13.2017.11.15.04.31.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 04:31:55 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/ttm: completely rework ttm_bo_delayed_delete Date: Wed, 15 Nov 2017 13:31:51 +0100 Message-Id: <20171115123151.3038-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171115123151.3038-1-christian.koenig@amd.com> References: <20171115123151.3038-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP There is no guarantee that the next entry on the ddelete list stays on the list when we drop the locks. Completely rework this mess by moving processed entries on a temporary list. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 77 ++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 7c1eac4f4b4b..ad0afdd71f21 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -572,71 +572,47 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo, * Traverse the delayed list, and call ttm_bo_cleanup_refs on all * encountered buffers. */ - -static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) +static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) { struct ttm_bo_global *glob = bdev->glob; - struct ttm_buffer_object *entry = NULL; - int ret = 0; - - spin_lock(&glob->lru_lock); - if (list_empty(&bdev->ddestroy)) - goto out_unlock; + struct list_head removed; + bool empty; - entry = list_first_entry(&bdev->ddestroy, - struct ttm_buffer_object, ddestroy); - kref_get(&entry->list_kref); + INIT_LIST_HEAD(&removed); - for (;;) { - struct ttm_buffer_object *nentry = NULL; - - if (entry->ddestroy.next != &bdev->ddestroy) { - nentry = list_first_entry(&entry->ddestroy, - struct ttm_buffer_object, ddestroy); - kref_get(&nentry->list_kref); - } - - ret = reservation_object_trylock(entry->resv) ? 0 : -EBUSY; - if (remove_all && ret) { - spin_unlock(&glob->lru_lock); - ret = reservation_object_lock(entry->resv, NULL); - spin_lock(&glob->lru_lock); - } + spin_lock(&glob->lru_lock); + while (!list_empty(&bdev->ddestroy)) { + struct ttm_buffer_object *bo; - if (!ret) - ret = ttm_bo_cleanup_refs(entry, false, !remove_all, - true); - else - spin_unlock(&glob->lru_lock); + bo = list_first_entry(&bdev->ddestroy, struct ttm_buffer_object, + ddestroy); + kref_get(&bo->list_kref); + list_move_tail(&bo->ddestroy, &removed); + spin_unlock(&glob->lru_lock); - kref_put(&entry->list_kref, ttm_bo_release_list); - entry = nentry; + reservation_object_lock(bo->resv, NULL); - if (ret || !entry) - goto out; + spin_lock(&glob->lru_lock); + ttm_bo_cleanup_refs(bo, false, !remove_all, true); + kref_put(&bo->list_kref, ttm_bo_release_list); spin_lock(&glob->lru_lock); - if (list_empty(&entry->ddestroy)) - break; } - -out_unlock: + list_splice_tail(&removed, &bdev->ddestroy); + empty = list_empty(&bdev->ddestroy); spin_unlock(&glob->lru_lock); -out: - if (entry) - kref_put(&entry->list_kref, ttm_bo_release_list); - return ret; + + return empty; } static void ttm_bo_delayed_workqueue(struct work_struct *work) { struct ttm_bo_device *bdev = container_of(work, struct ttm_bo_device, wq.work); + unsigned long delay = ((HZ / 100) < 1) ? 1 : HZ / 100; - if (ttm_bo_delayed_delete(bdev, false)) { - schedule_delayed_work(&bdev->wq, - ((HZ / 100) < 1) ? 1 : HZ / 100); - } + if (!ttm_bo_delayed_delete(bdev, false)) + schedule_delayed_work(&bdev->wq, delay); } static void ttm_bo_release(struct kref *kref) @@ -1573,13 +1549,10 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) cancel_delayed_work_sync(&bdev->wq); - while (ttm_bo_delayed_delete(bdev, true)) - ; - - spin_lock(&glob->lru_lock); - if (list_empty(&bdev->ddestroy)) + if (ttm_bo_delayed_delete(bdev, true)) TTM_DEBUG("Delayed destroy list was clean\n"); + spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) if (list_empty(&bdev->man[0].lru[0])) TTM_DEBUG("Swap list %d was clean\n", i);