From patchwork Thu Sep 29 15:35:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9356581 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 117E4600C8 for ; Thu, 29 Sep 2016 15:36:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 034F429B5C for ; Thu, 29 Sep 2016 15:36:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC0DA29B7A; Thu, 29 Sep 2016 15:36:16 +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_SIGNED, 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 A024829B5C for ; Thu, 29 Sep 2016 15:36:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1E666E87A; Thu, 29 Sep 2016 15:36:15 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id B734F6E87A for ; Thu, 29 Sep 2016 15:36:13 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id b4so11348041wmb.2 for ; Thu, 29 Sep 2016 08:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sorPLhuy05dtUWXW8nUioWh4Yovo+49/IQCclpiO+vY=; b=qwAdMpElX6CvqXemjg0zBosV9miGJOktKXaT3zYHxREBtCGdHcdDHJHypmN+LknKOt dfA8ujaz3mRjilkT597SPV//RjiT76FX/WqnkFzFuEBla1hoX3ZY3ITdKnsC6odPlBFY A6xnSd2AgGk36Hyl7l0gGYj9E8nV2Qhn741iLAx+dFnBbA/EeOC8n9wU3CSWI8ig5JZo /tkD5sgOlIGapWjtTU0IOraQxB1xhi5VgOXzSv4V+Xsi9HjyFleqJTTrFbVeKxBR19af NMz24vkvK+V0nXAnMegAugLzPDn6pYzJv7PnP1ZpN72EUeK2cQiiUNSe1GtxrglQ3fqj DRwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sorPLhuy05dtUWXW8nUioWh4Yovo+49/IQCclpiO+vY=; b=HsAx+ZFKFot8BzBseAqtTxqG1XxT+4ZGvHwkRYXkR8WMCUirQVUnEfcU5vCThvHcZr AV+g/wD5AqiOgFP1HAd53w8wdwpcp0ESfCK5uyuJLqPIFcypEBQMNM6yDU7xIB6+CRLX QPjz8su1EPiW849TCa3PGakMwZHJfHK+1laB0VKjBj2bXOh4KirbDRuQ8+tm0AEmHQqy s1WqiuHmSgESjhdWczlyt3VVmCnDzXre3XGfCOwnf1a+TzYYjSz1NGMCRM6+RytJGCnj lI9XWiFQV0xsU668fqfGCIUoc2GIomT+ps0GIFNM3X/ZLx32x/2omA7dJjaM8MNLgZNO BGFg== X-Gm-Message-State: AA6/9Rl27btiLLgMqGqtketxCBuA6bWdvTnlk2WlGhRfUU0tlCSP8ZG+O4jHVZ830Ks2xA== X-Received: by 10.194.205.2 with SMTP id lc2mr2023279wjc.175.1475163372039; Thu, 29 Sep 2016 08:36:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:9b6d:e300:916a:6cab:ac67:71c2]) by smtp.gmail.com with ESMTPSA id s7sm14781924wjc.34.2016.09.29.08.36.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2016 08:36:11 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Thu, 29 Sep 2016 16:35:49 +0100 Message-Id: <1475163356-3463-7-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475163356-3463-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1475163356-3463-1-git-send-email-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH 06/13] drm/i915: Use binary search when looking up forcewake domains X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Instead of the existing linear seach, now that we have sorted range tables, we can do a binary search on them for some potential miniscule performance gain, but more importantly for elegance and code size. Hopefully the perfomance gain is sufficient to offset the function calls which were not there before. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/intel_uncore.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index bee1482a5ece..ae5edaea16f7 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -26,6 +26,7 @@ #include "i915_vgpu.h" #include +#include #define FORCEWAKE_ACK_TIMEOUT_MS 50 @@ -589,20 +590,31 @@ struct intel_forcewake_range enum forcewake_domains domains; }; +static int fw_range_cmp(const void *key, const void *elt) +{ + struct intel_forcewake_range *entry = + (struct intel_forcewake_range *)elt; + u32 offset = (u32)((unsigned long)key); + + if (offset < entry->start) + return -1; + else if (offset > entry->end) + return 1; + else + return 0; +} + static enum forcewake_domains find_fw_domain(u32 offset, const struct intel_forcewake_range *ranges, unsigned int num_ranges) { - unsigned int i; - struct intel_forcewake_range *entry = - (struct intel_forcewake_range *)ranges; + struct intel_forcewake_range *entry; - for (i = 0; i < num_ranges; i++, entry++) { - if (offset >= entry->start && offset <= entry->end) - return entry->domains; - } + entry = bsearch((void *)(unsigned long)offset, (const void *)ranges, + num_ranges, sizeof(struct intel_forcewake_range), + fw_range_cmp); - return -1; + return entry ? entry->domains : -1; } static void