From patchwork Fri Dec 15 10:30:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10114689 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 17A3960231 for ; Fri, 15 Dec 2017 10:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 084A429E36 for ; Fri, 15 Dec 2017 10:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFFF829E38; Fri, 15 Dec 2017 10:30:30 +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.2 required=2.0 tests=BAYES_00, 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 B5BCF29E36 for ; Fri, 15 Dec 2017 10:30:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 17B7D6E7D1; Fri, 15 Dec 2017 10:30:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1944A6E7D1 for ; Fri, 15 Dec 2017 10:30:28 +0000 (UTC) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.84_2) (envelope-from ) id 1ePnG6-0002cx-Qb; Fri, 15 Dec 2017 11:30:26 +0100 From: Lucas Stach To: etnaviv@lists.freedesktop.org Subject: [PATCH libdrm] etnaviv: fix BO cache to properly work with different flags Date: Fri, 15 Dec 2017 11:30:26 +0100 Message-Id: <20171215103026.25702-1-l.stach@pengutronix.de> X-Mailer: git-send-email 2.11.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: dri-devel@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently if the oldest BO in a bucket has different flags than what we look for we'll miss the cache.Fix this by iterating over the cached BOs until we find the oldest one with matching flags. This improves the hit ratio for some of the buckets. Signed-off-by: Lucas Stach Reviewed-by: Philipp Zabel Reviewed-by: Christian Gmeiner --- etnaviv/etnaviv_bo_cache.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/etnaviv/etnaviv_bo_cache.c b/etnaviv/etnaviv_bo_cache.c index 8924651f0cd8..6208230dc81a 100644 --- a/etnaviv/etnaviv_bo_cache.c +++ b/etnaviv/etnaviv_bo_cache.c @@ -124,20 +124,32 @@ static int is_idle(struct etna_bo *bo) static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, uint32_t flags) { - struct etna_bo *bo = NULL; + struct etna_bo *bo = NULL, *tmp; pthread_mutex_lock(&table_lock); - while (!LIST_IS_EMPTY(&bucket->list)) { - bo = LIST_ENTRY(struct etna_bo, bucket->list.next, list); - if (bo->flags == flags && is_idle(bo)) { - list_del(&bo->list); - break; + if (LIST_IS_EMPTY(&bucket->list)) + goto out_unlock; + + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bucket->list, list) { + /* skip BOs with different flags */ + if (bo->flags != flags) + continue; + + /* check if the first BO with matching flags is idle */ + if (is_idle(bo)) { + list_delinit(&bo->list); + goto out_unlock; } - bo = NULL; + /* If the oldest BO is still busy, don't try younger ones */ break; } + + /* There was no matching buffer found */ + bo = NULL; + +out_unlock: pthread_mutex_unlock(&table_lock); return bo;