]> git.proxmox.com Git - mirror_ovs.git/blob - lib/dpif-netdev-lookup.c
ovsdb-idl: Improve prototypes.
[mirror_ovs.git] / lib / dpif-netdev-lookup.c
1 /*
2 * Copyright (c) 2020 Intel Corporation.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <config.h>
18 #include <errno.h>
19 #include "dpif-netdev-lookup.h"
20
21 #include "openvswitch/vlog.h"
22
23 VLOG_DEFINE_THIS_MODULE(dpif_netdev_lookup);
24
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.
32 */
33 #ifdef DPCLS_AUTOVALIDATOR_DEFAULT
34 { .prio = 255,
35 #else
36 { .prio = 0,
37 #endif
38 .probe = dpcls_subtable_autovalidator_probe,
39 .name = "autovalidator", },
40
41 /* The default scalar C code implementation. */
42 { .prio = 1,
43 .probe = dpcls_subtable_generic_probe,
44 .name = "generic", },
45
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. */
48 { .prio = 0,
49 .probe = dpcls_subtable_avx512_gather_probe,
50 .name = "avx512_gather", },
51 #else
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
63 */
64 #endif
65 };
66
67 int32_t
68 dpcls_subtable_lookup_info_get(struct dpcls_subtable_lookup_info_t **out_ptr)
69 {
70 if (out_ptr == NULL) {
71 return -1;
72 }
73
74 *out_ptr = subtable_lookups;
75 return ARRAY_SIZE(subtable_lookups);
76 }
77
78 /* sets the priority of the lookup function with "name". */
79 int32_t
80 dpcls_subtable_set_prio(const char *name, uint8_t priority)
81 {
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",
86 name, priority);
87 return 0;
88 }
89 }
90 VLOG_WARN("Subtable function '%s' not found, failed to set priority\n",
91 name);
92 return -EINVAL;
93 }
94
95 dpcls_subtable_lookup_func
96 dpcls_subtable_get_best_impl(uint32_t u0_bit_count, uint32_t u1_bit_count)
97 {
98 /* Iter over each subtable impl, and get highest priority one. */
99 int32_t prio = -1;
100 const char *name = NULL;
101 dpcls_subtable_lookup_func best_func = NULL;
102
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,
108 u1_bit_count);
109 if (probed_func) {
110 best_func = probed_func;
111 prio = probed_prio;
112 name = subtable_lookups[i].name;
113 }
114 }
115 }
116
117 VLOG_DBG("Subtable lookup function '%s' with units (%d,%d), priority %d\n",
118 name, u0_bit_count, u1_bit_count, prio);
119
120 /* Programming error - we must always return a valid func ptr. */
121 ovs_assert(best_func != NULL);
122
123 return best_func;
124 }