2 * Copyright (c) 2020 Intel Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "dpif-netdev-lookup.h"
21 #include "openvswitch/vlog.h"
23 VLOG_DEFINE_THIS_MODULE(dpif_netdev_lookup
);
25 /* Actual list of implementations goes here */
26 static struct dpcls_subtable_lookup_info_t subtable_lookups
[] = {
27 /* The autovalidator implementation will not be used by default, it must
28 * be enabled at compile time to be the default lookup implementation. The
29 * user may enable it at runtime using the normal "prio-set" command if
30 * desired. The compile time default switch is here to enable all unit
31 * tests to transparently run with the autovalidator.
33 #ifdef DPCLS_AUTOVALIDATOR_DEFAULT
38 .probe
= dpcls_subtable_autovalidator_probe
,
39 .name
= "autovalidator", },
41 /* The default scalar C code implementation. */
43 .probe
= dpcls_subtable_generic_probe
,
46 #if (__x86_64__ && HAVE_AVX512F && HAVE_LD_AVX512_GOOD && __SSE4_2__)
47 /* Only available on x86_64 bit builds with SSE 4.2 used for OVS core. */
49 .probe
= dpcls_subtable_avx512_gather_probe
,
50 .name
= "avx512_gather", },
52 /* Disabling AVX512 at compile time, as compile time requirements not met.
53 * This could be due to a number of reasons:
54 * 1) core OVS is not compiled with SSE4.2 instruction set.
55 * The SSE42 instructions are required to use CRC32 ISA for high-
56 * performance hashing. Consider ./configure of OVS with -msse42 (or
57 * newer) to enable CRC32 hashing and higher performance.
58 * 2) The assembler in binutils versions 2.30 and 2.31 has bugs in AVX512
59 * assembly. Compile time probes check for this assembler issue, and
60 * disable the HAVE_LD_AVX512_GOOD check if an issue is detected.
61 * Please upgrade binutils, or backport this binutils fix commit:
62 * 2069ccaf8dc28ea699bd901fdd35d90613e4402a
68 dpcls_subtable_lookup_info_get(struct dpcls_subtable_lookup_info_t
**out_ptr
)
70 if (out_ptr
== NULL
) {
74 *out_ptr
= subtable_lookups
;
75 return ARRAY_SIZE(subtable_lookups
);
78 /* sets the priority of the lookup function with "name". */
80 dpcls_subtable_set_prio(const char *name
, uint8_t priority
)
82 for (int i
= 0; i
< ARRAY_SIZE(subtable_lookups
); i
++) {
83 if (strcmp(name
, subtable_lookups
[i
].name
) == 0) {
84 subtable_lookups
[i
].prio
= priority
;
85 VLOG_INFO("Subtable function '%s' set priority to %d\n",
90 VLOG_WARN("Subtable function '%s' not found, failed to set priority\n",
95 dpcls_subtable_lookup_func
96 dpcls_subtable_get_best_impl(uint32_t u0_bit_count
, uint32_t u1_bit_count
)
98 /* Iter over each subtable impl, and get highest priority one. */
100 const char *name
= NULL
;
101 dpcls_subtable_lookup_func best_func
= NULL
;
103 for (int i
= 0; i
< ARRAY_SIZE(subtable_lookups
); i
++) {
104 int32_t probed_prio
= subtable_lookups
[i
].prio
;
105 if (probed_prio
> prio
) {
106 dpcls_subtable_lookup_func probed_func
;
107 probed_func
= subtable_lookups
[i
].probe(u0_bit_count
,
110 best_func
= probed_func
;
112 name
= subtable_lookups
[i
].name
;
117 VLOG_DBG("Subtable lookup function '%s' with units (%d,%d), priority %d\n",
118 name
, u0_bit_count
, u1_bit_count
, prio
);
120 /* Programming error - we must always return a valid func ptr. */
121 ovs_assert(best_func
!= NULL
);