Skip to content

Commit f7bfc14

Browse files
Suzuki K Poulosewildea01
authored andcommitted
arm64: capabilities: Optimize this_cpu_has_cap
Make use of the sorted capability list to access the capability entry in this_cpu_has_cap() to avoid iterating over the two tables. Reviewed-by: Vladimir Murzin <[email protected]> Tested-by: Vladimir Murzin <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 82a3a21 commit f7bfc14

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,25 +1512,6 @@ static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps)
15121512
cap_set_elf_hwcap(hwcaps);
15131513
}
15141514

1515-
/*
1516-
* Check if the current CPU has a given feature capability.
1517-
* Should be called from non-preemptible context.
1518-
*/
1519-
static bool __this_cpu_has_cap(const struct arm64_cpu_capabilities *cap_array,
1520-
unsigned int cap)
1521-
{
1522-
const struct arm64_cpu_capabilities *caps;
1523-
1524-
if (WARN_ON(preemptible()))
1525-
return false;
1526-
1527-
for (caps = cap_array; caps->matches; caps++)
1528-
if (caps->capability == cap)
1529-
return caps->matches(caps, SCOPE_LOCAL_CPU);
1530-
1531-
return false;
1532-
}
1533-
15341515
static void __update_cpu_capabilities(const struct arm64_cpu_capabilities *caps,
15351516
u16 scope_mask, const char *info)
15361517
{
@@ -1780,10 +1761,16 @@ static void __init mark_const_caps_ready(void)
17801761
static_branch_enable(&arm64_const_caps_ready);
17811762
}
17821763

1783-
bool this_cpu_has_cap(unsigned int cap)
1764+
bool this_cpu_has_cap(unsigned int n)
17841765
{
1785-
return (__this_cpu_has_cap(arm64_features, cap) ||
1786-
__this_cpu_has_cap(arm64_errata, cap));
1766+
if (!WARN_ON(preemptible()) && n < ARM64_NCAPS) {
1767+
const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n];
1768+
1769+
if (cap)
1770+
return cap->matches(cap, SCOPE_LOCAL_CPU);
1771+
}
1772+
1773+
return false;
17871774
}
17881775

17891776
static void __init setup_system_capabilities(void)

0 commit comments

Comments
 (0)