From patchwork Fri Sep 30 17:48:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9358693 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 B2EB46086A for ; Fri, 30 Sep 2016 17:49:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAD082A12A for ; Fri, 30 Sep 2016 17:49:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F7642A131; Fri, 30 Sep 2016 17:49:20 +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 5C4D52A12A for ; Fri, 30 Sep 2016 17:49:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCB006EAAF; Fri, 30 Sep 2016 17:49:19 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAE926E23F for ; Fri, 30 Sep 2016 17:49:10 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id p197so2989108wmg.1 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=6TU0YpF3MquwNo39Zxvbb5+OfOiqYEi/w/wsaErR8Io=; b=zztyTDSR2nXBGYpBzJviOu9BqeBbESvZFkm/mhy1tfqI9zReWS+zVP2it3QSz0JOaa LR3qmbZWCeePq9dfHc2Jk4qQEOm74i+2A1POEb8JKukQGVmR5kJmxhqSbg1T5VIwhls6 dxFNJ7nKtavqHarIIy8jC/JAqqgcZrAYMzggXQlrfj45xoIMxEsitDrdO18u3PuaxrjI W43lTLPjF6V5rwCEv9uknd75jOT5q9mmifYFmV3eNaI6tkK20qfxafM1aONQHl/UfyLM PPASN2MM5qfNdlQV5C6DuNwHp7CrOBxL7IGI9r12ybxK3LqeupaGXkI6x1DzGEl03lPd cstg== 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=6TU0YpF3MquwNo39Zxvbb5+OfOiqYEi/w/wsaErR8Io=; b=IPkCpSkgWjAwTgUQIhu4/lvijraBuFhKAE7cmg2x44/lc6I6uWFTwYLUzYsrh6E89z Zks+YRNJ8O58tXlJwpvPhr/x5/vP/Hsbb/4gYG38qpQ0MhdQkkqgWOmPkJxkl57zrlOx 3cPACxGyGJQ1bnBw8cQ7+9mBHDBflnXFZB0x7PlPzw0vaK3PCTAXPsN03WHi0ALEIBZV cR2qyNRs11PmOzGrb56Uo3Tdh+4VTTThmCIXeXpF8FTW4LO3+exQguIXZdgpqkSlsmT/ 6ztXnE+8+0yUpo4XpbsuUfDixs7URYS8mCBBlJjKuAq8f2IIn4B6F+JQSlJwUU7Nr7/8 BTGw== X-Gm-Message-State: AA6/9RlGWYs9RfDbN35xNwb05GoaddamT6lku9ZIb8j2uvb2BfczuQZxlpxOh5LbX4pbYg== X-Received: by 10.28.222.213 with SMTP id v204mr5382347wmg.55.1475257748235; 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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 10:49:07 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 30 Sep 2016 18:48:48 +0100 Message-Id: <1475257729-11283-14-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 13/14] drm/i915: Use binary search when looking for shadowed registers 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 Simply replace the linear search with the kernel's binary search implementation. There is only six registers currently in that table so this may not be that interesting. It adds a function call so hopefully remains performance neutral for now. v2: No need for manual conversion to bool for return. (Joonas Lahtinen) Signed-off-by: Tvrtko Ursulin Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/intel_uncore.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 10b21516a7de..70a7fef79846 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -689,14 +689,30 @@ static void intel_shadow_table_check(void) #endif } +static int mmio_reg_cmp(const void *key, const void *elt) +{ + u32 offset = (u32)(unsigned long)key; + i915_reg_t *reg = (i915_reg_t *)elt; + + if (offset < i915_mmio_reg_offset(*reg)) + return -1; + else if (offset > i915_mmio_reg_offset(*reg)) + return 1; + else + return 0; +} + static bool is_gen8_shadowed(u32 offset) { - int i; - for (i = 0; i < ARRAY_SIZE(gen8_shadowed_regs); i++) - if (offset == gen8_shadowed_regs[i].reg) - return true; + i915_reg_t *reg; - return false; + reg = bsearch((void *)(unsigned long)offset, + (const void *)gen8_shadowed_regs, + ARRAY_SIZE(gen8_shadowed_regs), + sizeof(i915_reg_t), + mmio_reg_cmp); + + return reg; } #define __gen8_reg_write_fw_domains(offset) \