Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dpif-netdev: Call cpuid for x86 isa availability.
DPIF AVX512 optimizations currently rely on DPDK availability while they can be used without DPDK. Besides, checking for availability of some isa only has to be done once and won't change while a OVS process runs. Resolve isa availability in constructors by using a simplified query based on cpuid API that comes from the compiler. Note: this also fixes the check on BMI2 availability: DPDK had a bug for this isa, see https://git.dpdk.org/dpdk/commit/?id=aae3037ab1e0. Suggested-by: Ilya Maximets <i.maximets@ovn.org> Signed-off-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
- Loading branch information
1 parent
1144138
commit b366fa2
Showing
9 changed files
with
119 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2021, Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <config.h> | ||
|
||
#include "cpu.h" | ||
#include "openvswitch/compiler.h" | ||
|
||
#ifdef __x86_64__ | ||
#include <cpuid.h> | ||
#include <inttypes.h> | ||
|
||
#include "openvswitch/util.h" | ||
|
||
enum x86_reg { | ||
EAX, | ||
EBX, | ||
ECX, | ||
EDX, | ||
}; | ||
#define X86_LEAF_MASK 0x80000000 | ||
#define X86_EXT_FEATURES_LEAF 0x00000007 | ||
static bool x86_has_isa(uint32_t leaf, enum x86_reg reg, uint32_t bit) | ||
{ | ||
uint32_t regs[4]; | ||
|
||
ovs_assert(__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) >= leaf); | ||
|
||
__cpuid_count(leaf, 0, regs[EAX], regs[EBX], regs[ECX], regs[EDX]); | ||
return (regs[reg] & ((uint32_t) 1 << bit)) != 0; | ||
} | ||
|
||
static bool x86_isa[OVS_CPU_ISA_X86_LAST - OVS_CPU_ISA_X86_FIRST + 1]; | ||
#define X86_ISA(leaf, reg, bit, name) \ | ||
OVS_CONSTRUCTOR(cpu_isa_ ## name) { \ | ||
x86_isa[name - OVS_CPU_ISA_X86_FIRST] = x86_has_isa(leaf, reg, bit); \ | ||
} | ||
X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 8, OVS_CPU_ISA_X86_BMI2) | ||
X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 16, OVS_CPU_ISA_X86_AVX512F) | ||
X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 30, OVS_CPU_ISA_X86_AVX512BW) | ||
X86_ISA(X86_EXT_FEATURES_LEAF, ECX, 1, OVS_CPU_ISA_X86_AVX512VBMI) | ||
X86_ISA(X86_EXT_FEATURES_LEAF, ECX, 14, OVS_CPU_ISA_X86_VPOPCNTDQ) | ||
#endif | ||
|
||
bool | ||
cpu_has_isa(enum ovs_cpu_isa isa OVS_UNUSED) | ||
{ | ||
#ifdef __x86_64__ | ||
if (isa >= OVS_CPU_ISA_X86_FIRST && | ||
isa <= OVS_CPU_ISA_X86_LAST) { | ||
return x86_isa[isa - OVS_CPU_ISA_X86_FIRST]; | ||
} | ||
#endif | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2021, Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef CPU_H | ||
#define CPU_H 1 | ||
|
||
#include <stdbool.h> | ||
|
||
enum ovs_cpu_isa { | ||
OVS_CPU_ISA_X86_FIRST, | ||
OVS_CPU_ISA_X86_BMI2 = OVS_CPU_ISA_X86_FIRST, | ||
OVS_CPU_ISA_X86_AVX512F, | ||
OVS_CPU_ISA_X86_AVX512BW, | ||
OVS_CPU_ISA_X86_AVX512VBMI, | ||
OVS_CPU_ISA_X86_VPOPCNTDQ, | ||
OVS_CPU_ISA_X86_LAST = OVS_CPU_ISA_X86_VPOPCNTDQ, | ||
}; | ||
|
||
bool cpu_has_isa(enum ovs_cpu_isa); | ||
|
||
#endif /* CPU_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters