From patchwork Fri Sep 30 17:48: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: 9358689 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 19401600C8 for ; Fri, 30 Sep 2016 17:49:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1041F2A11C for ; Fri, 30 Sep 2016 17:49:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 054772A131; Fri, 30 Sep 2016 17:49:17 +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 9A5552A11C for ; Fri, 30 Sep 2016 17:49:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 34D946EAAC; Fri, 30 Sep 2016 17:49: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 715FA6E23F for ; Fri, 30 Sep 2016 17:49:10 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id b184so4454370wma.3 for ; Fri, 30 Sep 2016 10:49:10 -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=AHHDNjnThIcNs0xcVP5G6pZuEHjkuBC4ATkNYPA5Z94=; b=Tk7HCXNr3PUTHPrfdzZj9smbSYObGMrDVP81v0jsPblEFhqHpNeuP1wPDstJvxfQqY lwLQit1XwX7pgUMhJNk6VD30OgRYpgMrQjb+qyQnqYa2sYf5ktqDoK5GJQHe4D9D9ONf JPd+kKQWJvW2GIOqsEHUOQh7C5gc1loyXF9Je0TWwMpJGlzAoSsrr7ywWvYYA/9hqjkH yKWHJK7Fck8Q9J/IbL48TgtmdueG2VpnLxPFCfynwqrKKVLnAgKJLRavv5uihSR5Ju2r xaT9+1l/7m90lro4SuSEcbb/aCMqSkrjBEzprNJDVsaErVGLtX8cFMsgd9U4ncSgIXAf YLxQ== 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=AHHDNjnThIcNs0xcVP5G6pZuEHjkuBC4ATkNYPA5Z94=; b=Tv8hkjGhrNKkNq6RsTokDkhRZ3z0avEVSzZNx2Z0+KecCiJsSX0sVMYv1Ywjycf3Hq PhSv34/1LIanX9Dmn0h93/rruPdJ44NAsxlli5c2Fyic1aSUQHieoY5ko5rugT5Oxf9A /hHVQd8zZbcQpDio0/blNKHrng+9+W0wmRB3BoSU7cttSSLndTzDMBzku0iuNKNB1lRE bFw64h7wvoOb9TKHsN5No+zTi+4wFhZ2+jvdUffqCFN1jYR417JB2WPEUDtMi9jQlZQN qx5ltG4n0JsPNeJj0KH6P/LqppTNFeKLzV0ctWnvPEmca3al2EHgMxaqB3kOVO7Q5A14 u+ug== X-Gm-Message-State: AA6/9RkUiFCsPPjpn12dNFG2wbKcCmzErVChqtSLgPV6nP6k5Tv6qhtjvt6Hc0RpWlvdoQ== X-Received: by 10.194.98.205 with SMTP id ek13mr8306059wjb.158.1475257748963; Fri, 30 Sep 2016 10:49:08 -0700 (PDT) Received: from e31.Home ([2a02:c7d:9b6d:e300:916a:6cab:ac67:71c2]) by smtp.gmail.com with ESMTPSA id a1sm246125wjl.28.2016.09.30.10.49.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 10:49:08 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 30 Sep 2016 18:48:49 +0100 Message-Id: <1475257729-11283-15-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475257729-11283-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1475257729-11283-1-git-send-email-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH 14/14] drm/i915: Inline binary search 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 using bsearch library function make a local generator macro out of it so the comparison callback can be inlined. Signed-off-by: Tvrtko Ursulin Suggested-by: Chris Wilson --- drivers/gpu/drm/i915/intel_uncore.c | 56 ++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 70a7fef79846..8e5357bdd914 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -26,7 +26,6 @@ #include "i915_vgpu.h" #include -#include #define FORCEWAKE_ACK_TIMEOUT_MS 50 @@ -582,11 +581,8 @@ void assert_forcewakes_inactive(struct drm_i915_private *dev_priv) __fwd; \ }) -static int fw_range_cmp(const void *key, const void *elt) +static int fw_range_cmp(u32 offset, const struct intel_forcewake_range *entry) { - const struct intel_forcewake_range *entry = elt; - u32 offset = (u32)((unsigned long)key); - if (offset < entry->start) return -1; else if (offset > entry->end) @@ -595,17 +591,33 @@ static int fw_range_cmp(const void *key, const void *elt) return 0; } +/* Copied and "macroized" from lib/bsearch.c */ +#define BSEARCH(key, base, num, cmp) ({ \ + unsigned int start__ = 0, end__ = (num); \ + typeof(base) result__ = NULL; \ + while (start__ < end__) { \ + unsigned int mid__ = start__ + (end__ - start__) / 2; \ + int ret__ = (cmp)((key), (base) + mid__); \ + if (ret__ < 0) { \ + end__ = mid__; \ + } else if (ret__ > 0) { \ + start__ = mid__ + 1; \ + } else { \ + result__ = (base) + mid__; \ + break; \ + } \ + } \ + result__; \ +}) + static enum forcewake_domains find_fw_domain(struct drm_i915_private *dev_priv, u32 offset) { - const struct intel_forcewake_range *table, *entry; - unsigned int num_entries; - - table = dev_priv->uncore.fw_domains_table; - num_entries = dev_priv->uncore.fw_domains_table_entries; + const struct intel_forcewake_range *entry; - entry = bsearch((void *)(unsigned long)offset, (const void *)table, - num_entries, sizeof(struct intel_forcewake_range), + entry = BSEARCH(offset, + dev_priv->uncore.fw_domains_table, + dev_priv->uncore.fw_domains_table_entries, fw_range_cmp); return entry ? entry->domains : 0; @@ -689,14 +701,13 @@ static void intel_shadow_table_check(void) #endif } -static int mmio_reg_cmp(const void *key, const void *elt) +static int mmio_reg_cmp(u32 key, const i915_reg_t *reg) { - u32 offset = (u32)(unsigned long)key; - i915_reg_t *reg = (i915_reg_t *)elt; + u32 offset = i915_mmio_reg_offset(*reg); - if (offset < i915_mmio_reg_offset(*reg)) + if (key < offset) return -1; - else if (offset > i915_mmio_reg_offset(*reg)) + else if (key > offset) return 1; else return 0; @@ -704,15 +715,10 @@ static int mmio_reg_cmp(const void *key, const void *elt) static bool is_gen8_shadowed(u32 offset) { - i915_reg_t *reg; - - reg = bsearch((void *)(unsigned long)offset, - (const void *)gen8_shadowed_regs, - ARRAY_SIZE(gen8_shadowed_regs), - sizeof(i915_reg_t), - mmio_reg_cmp); + const i915_reg_t *regs = gen8_shadowed_regs; - return reg; + return BSEARCH(offset, regs, ARRAY_SIZE(gen8_shadowed_regs), + mmio_reg_cmp); } #define __gen8_reg_write_fw_domains(offset) \