diff options
author | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2016-10-04 09:29:21 +0100 |
---|---|---|
committer | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2016-10-04 11:09:59 +0100 |
commit | 91e630b9e636954708e933015e7f02f8bcd8b320 (patch) | |
tree | 74768d392f61452f913ca529bb4153f1d641bab7 /drivers/gpu | |
parent | b008123966a45bfda9ef71d35a0b76957d639291 (diff) | |
download | op-kernel-dev-91e630b9e636954708e933015e7f02f8bcd8b320.zip op-kernel-dev-91e630b9e636954708e933015e7f02f8bcd8b320.tar.gz |
drm/i915: Use binary search when looking up forcewake domains
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 <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/drm/i915/intel_uncore.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index aa84c40..aa89815 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 <linux/pm_runtime.h> +#include <linux/bsearch.h> #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 |