From patchwork Fri Sep 30 17:48:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9358695 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 5A3D9600C8 for ; Fri, 30 Sep 2016 17:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51F1B2A11C for ; Fri, 30 Sep 2016 17:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46EB02A12F; Fri, 30 Sep 2016 17:49:22 +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 3F9D72A11C for ; Fri, 30 Sep 2016 17:49:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D19616EAB2; 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-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77A496E23F for ; Fri, 30 Sep 2016 17:49:04 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id p138so4462693wmb.0 for ; Fri, 30 Sep 2016 10:49:04 -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=wFOLDvS2N5lpUwaAuS1yG9OMcFL+NzYVsKP4GeLW5R8=; b=qD6tNR40cRD15v8fsguy+Kiv88/5nNtPDkPVln0iFVi5wBn40aeQLERuPdbSZa5Q8J fJT2HkZpXtACBzt2yux1OOVXItT+BueJpT9kcnT9D1fa+80fS3mEr59OfrKqdrO4XyLc RJBrOTCB+iAd5pfmL+uLKZmuxGCpwIb0374gRlCoiktx2aLVgrMnfk26XIrP5niJbdOc 6fxAoLxVAST8EVUGAoeX/sMl9J2jAs7c2Q3T0OYIi8WMircKGklMUXI8GAJN5ViAeakV noMyeV6CsyJ/ruDjwQkRb8afUMUHDnogfK2cnMw9RlxlbSW+tAfti9P85f84riuy8W03 Xu1w== 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=wFOLDvS2N5lpUwaAuS1yG9OMcFL+NzYVsKP4GeLW5R8=; b=GAx3SVi77wWU8ce8QD+77bM9WT7MuIMv1H9OhvQaTm1xNeY+4DDkoPPFARy+UmiOH4 nBuujgVeux+IPm/bzE3aXaeMsaCObp048FZuOtzc6vhr/Ixu8uhkzUE2LBM4c71IVt6c 20fQnn2NCihu5iPBE2WfEIS2luP26M8SHDpjXn8EnqBw9LZkiQiheniik6GpZhv0pVYp KWNm8L03XFLItGii5A/vY2TExBg7S0nmUhvXsbAIIIjl0XhZ+RwT4lrzaM8ODdy9UkGp KXfda28+5zG8quQA0S84mPE+DoSTQCLSjTQB/D+WuYwci/XF+Zgg8oPle2PtFmI9Tky2 7FtA== X-Gm-Message-State: AA6/9Rn9SQXTnj682Y37ngonXEBmJZvCMxXPIZwYEBHUa999kkhMuAL1brHFM3EXbt4nHg== X-Received: by 10.28.67.2 with SMTP id q2mr5352256wma.123.1475257742804; Fri, 30 Sep 2016 10:49:02 -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.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 10:49:02 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 30 Sep 2016 18:48:41 +0100 Message-Id: <1475257729-11283-7-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 06/14] 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. v2: Removed const cast away. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/intel_uncore.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 5ca65de340b7..60fe796fdd0c 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,30 @@ struct intel_forcewake_range enum forcewake_domains domains; }; +static int fw_range_cmp(const void *key, const void *elt) +{ + const struct intel_forcewake_range *entry = 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