Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2307516ybi; Mon, 17 Jun 2019 02:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTxVUyBUvHLhcR0BKkLhOcOutDpG70N0RbbvQXLxVS2J/y+ddOdNBxL9q7ZxJLcPVa3P80 X-Received: by 2002:a17:90a:24e4:: with SMTP id i91mr26327056pje.9.1560763949261; Mon, 17 Jun 2019 02:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560763949; cv=none; d=google.com; s=arc-20160816; b=GnobqE4Vy7zIljD0zMQvK1+Hj0go12bDxZhIRU161B8UrCkgbfma3uaBuoADymA/i/ JiGDflASPHAtjX2Ct5p/ie9UNgYsmnsAZdgRPhPL1GxqJlRBsh2NbgsI0auga5deZdkw 6vYXi8qlO9ISlOvCvuDKRnB7fpUOO6OqryTz1iRWAISULI3l4VDfkYQpEFR6/6K4RzYo rRHs7OjvxBRCd+ytH/bmS0WRB6wb+O1wrziOQPI/ivrO4neGI7Gmm57prZUbLSebg/Np qOfAFxw7/IhbG/JkaDD14kZ7PUkcPlefsuk3JABxcVjuhI22VvgqJA9Sq4/QbC7Z8MwV WPMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dkim-signature; bh=hGy+FSJRzToSeoyUsvQaQYFoLBq93m5qcKw5Lz5P/as=; b=wMcHmlHfsQC673Lr8Qgy/KnA25UNfYb07OeiCcsTWv3VsE3w8DC8HqjfMy9snUCnhS I1TzDWBUM3p1Rv1CQvF1uDZrR/ELNYHcS55U/6foZkmDfCp2ITg7jvUd1GII39RmdnPH 7f5b6TzteKe+TMOc0Hto35/S7iH1d3mZ4TphQWc3njyKx09gzpGfhZ17C7neb+CuwRK1 Wkj12vjc5dk3corICUoDwwDJ6KMZGABH52mAylezcN+FAlBq6ApEwbYVfUyi3x/bBH2m Czud0dRn5WIBdJqJxdgzitpxowQFYkAaJR6cYhRY0TFi++O80uzawpt4DmodUWAXry0c vydA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="F60ERVd/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si10256608pfp.180.2019.06.17.02.32.12; Mon, 17 Jun 2019 02:32:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="F60ERVd/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728167AbfFQJaw (ORCPT + 99 others); Mon, 17 Jun 2019 05:30:52 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52080 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbfFQJaw (ORCPT ); Mon, 17 Jun 2019 05:30:52 -0400 Received: by mail-wm1-f67.google.com with SMTP id 207so8463923wma.1 for ; Mon, 17 Jun 2019 02:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=hGy+FSJRzToSeoyUsvQaQYFoLBq93m5qcKw5Lz5P/as=; b=F60ERVd/hdyLx8RkvS+tUuVoOJCT4bbcqGeQftgadh71HU605jvy7+avRbGBSrNhoJ 1keSHnOnl1ku6hUHqHp8Yox/P3ICEsxA7UPoWoo1f9WHKWLkV/RwfycdjI4kOzml8fQf 5mylKL44bJ1IW0AxZ/6GNbuXkVv1WuGyoQySInYmoX141ojNSY9KSOEgJevGuL3grgY+ bhF6o5VqoOVwA1i+XBT0tVEOOqElJwyCeeHUqyr1K+1l7DGf0VF8/RPloApCnkLXhEdU wUIRpnGvue7vKNzG4hqCItM5q8GYfUGHaQQs3DmutNABXH2anO0k3MpuopjZqm02RWLb GzMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=hGy+FSJRzToSeoyUsvQaQYFoLBq93m5qcKw5Lz5P/as=; b=R1UdJFg/6TqRR1KnVZ/pxF3jnzLHcrZy2OIqOqzwwFRXIhDj68kX2JK1EowkdHps+6 J4OWszvL4FUQ6JaIdM58TCuJT4viCckxhyMduj2UaAfqU/0uuYMSKygjw0kWZJW7AXyf HBscTRtItLzlUnMsXVOkU2gjyIKddxqSE9JriG5+bPKbzSdenrRl7Jte0/us1cCUKS0F 7owHRmP382foWBtE1tLYSDG0k1eBJO9tosOJIgC9iRnL1VgRw+FqvoLJ5mMjzlMGa6mo 6YzwNGGYlS3G75m8UQif8+jVDlifVxYjRb/+aflwfRDxV0fZPy1lN43Erdw4e0MlN4ui NF7Q== X-Gm-Message-State: APjAAAUxz4ozTbDFBSjr7drshhKFuKEDSS690deo3/gdUNKI2W7jGUJT CbBJRQDlgFN/znH5EZyYoRM= X-Received: by 2002:a1c:2dc2:: with SMTP id t185mr18175091wmt.52.1560763849022; Mon, 17 Jun 2019 02:30:49 -0700 (PDT) Received: from ?IPv6:2a02:908:1252:fb60:be8a:bd56:1f94:86e7? ([2a02:908:1252:fb60:be8a:bd56:1f94:86e7]) by smtp.gmail.com with ESMTPSA id z5sm9895972wrh.16.2019.06.17.02.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 02:30:48 -0700 (PDT) Reply-To: christian.koenig@amd.com Subject: Re: [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros To: Daniel Vetter , =?UTF-8?Q?Christian_K=c3=b6nig?= Cc: Thomas Hellstrom , lima@lists.freedesktop.org, Peter Zijlstra , Linux Kernel Mailing List , dri-devel , The etnaviv authors , Qiang Yu , Russell King References: <20190614124125.124181-1-christian.koenig@amd.com> <20190614124125.124181-4-christian.koenig@amd.com> <20190614131916.GQ3436@hirez.programming.kicks-ass.net> <20190614152242.GC23020@phenom.ffwll.local> <094da0f7-a0f0-9ed4-d2da-8c6e6d165380@gmail.com> <20190614203040.GE23020@phenom.ffwll.local> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <16adcdac-b3e7-02f1-e56b-9b4ad68e146e@gmail.com> Date: Mon, 17 Jun 2019 11:30:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 15.06.19 um 15:56 schrieb Daniel Vetter: > On Fri, Jun 14, 2019 at 10:30 PM Daniel Vetter wrote: >> On Fri, Jun 14, 2019 at 08:51:11PM +0200, Christian König wrote: >>> Am 14.06.19 um 20:24 schrieb Daniel Vetter: >>>> On Fri, Jun 14, 2019 at 8:10 PM Christian König wrote: >>>>> [SNIP] >>>>> WW_MUTEX_LOCK_BEGIN() >>>>> >>>>> lock(lru_lock); >>>>> >>>>> while (bo = list_first(lru)) { >>>>> if (kref_get_unless_zero(bo)) { >>>>> unlock(lru_lock); >>>>> WW_MUTEX_LOCK(bo->ww_mutex); >>>>> lock(lru_lock); >>>>> } else { >>>>> /* bo is getting freed, steal it from the freeing process >>>>> * or just ignore */ >>>>> } >>>>> } >>>>> unlock(lru_lock) >>>>> >>>>> WW_MUTEX_LOCK_END; >>> Ah, now I know what you mean. And NO, that approach doesn't work. >>> >>> See for the correct ww_mutex dance we need to use the iterator multiple >>> times. >>> >>> Once to give us the BOs which needs to be locked and another time to give us >>> the BOs which needs to be unlocked in case of a contention. >>> >>> That won't work with the approach you suggest here. >> A right, drat. >> >> Maybe give up on the idea to make this work for ww_mutex in general, and >> just for drm_gem_buffer_object? I'm just about to send out a patch series >> which makes sure that a lot more drivers set gem_bo.resv correctly (it >> will alias with ttm_bo.resv for ttm drivers ofc). Then we could add a >> list_head to gem_bo (won't really matter, but not something we can do with >> ww_mutex really), so that the unlock walking doesn't need to reuse the >> same iterator. That should work I think ... >> >> Also, it would almost cover everything you want to do. For ttm we'd need >> to make ttm_bo a subclass of gem_bo (and maybe not initialize that >> embedded gem_bo for vmwgfx and shadow bo and driver internal stuff). >> >> Just some ideas, since copypasting the ww_mutex dance into all drivers is >> indeed not great. > Even better we don't need to force everyone to use drm_gem_object, the > hard work is already done with the reservation_object. We could add a > list_head there for unwinding, and then the locking helpers would look > a lot cleaner and simpler imo. reservation_unlock_all() would even be > a real function! And if we do this then I think we should also have a > reservation_acquire_ctx, to store the list_head and maybe anything > else. > > Plus all the code you want to touch is dealing with > reservation_object, so that's all covered. And it mirros quite a bit > what we've done with struct drm_modeset_lock, to wrap ww_mutex is > something easier to deal with for kms. That's a rather interesting idea. I wouldn't use a list_head cause that has a rather horrible caching footprint for something you want to use during CS, but apart from that the idea sounds like it would also solve a bunch of problem during eviction. Going to give that a try, Christian. > -Daniel >