diff mbox series

[ovs-dev,v2,02/11] dpdk: cache result of CPU ISA checks

Message ID 20201030190647.1839197-3-harry.van.haaren@intel.com
State Superseded
Headers show
Series DPIF Function Pointer Refactor + AVX512 impl | expand

Commit Message

Van Haaren, Harry Oct. 30, 2020, 7:06 p.m. UTC
As a small optimization, this patch caches the result of a CPU ISA
check from DPDK. Particularly in the case of running the DPCLS
autovalidator (which repeatedly probes subtables) this reduces
the amount of CPU ISA lookups from the DPDK level.

By caching them at the OVS/dpdk.c level, the ISA checks remain
runtime for the CPU where they are executed, but subsequent checks
for the same ISA feature become much cheaper.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

In theory it is also possible to do the caching of the supported
ISA at the usage site (aka, the DPCLS subtable search implementation)
however that would cause a lot of code-duplication. By caching in
the lower level, we get almost all the benefit with no code duplication.
---
 lib/dpdk.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Comments

0-day Robot Oct. 30, 2020, 8:05 p.m. UTC | #1
Bleep bloop.  Greetings Harry van Haaren, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
ERROR: Inappropriate bracing around statement
#50 FILE: lib/dpdk.c:635:
                if (has_isa)                                            \

ERROR: Inappropriate bracing around statement
#53 FILE: lib/dpdk.c:638:
            if (isa_check_##RTE_CPUFLAG & ISA_AVAILABLE_BIT)            \

Lines checked: 60, Warnings: 0, Errors: 2


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/dpdk.c b/lib/dpdk.c
index 2f235a742..02629f44f 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -614,13 +614,29 @@  print_dpdk_version(void)
     puts(rte_version());
 }
 
+/* Avoid calling rte_cpu_get_flag_enabled() excessively, by caching the
+ * result of the call for each CPU flag in a static variable. To avoid
+ * allocating large numbers of static variables, use a uint8 as a bitfield.
+ * Note the macro must only return if the ISA check done and is available.
+ */
+#define ISA_CHECK_DONE_BIT (1 << 0)
+#define ISA_AVAILABLE_BIT  (1 << 1)
+
 #define CHECK_CPU_FEATURE(feature, name_str, RTE_CPUFLAG)               \
     do {                                                                \
         if (strncmp(feature, name_str, strlen(name_str)) == 0) {        \
-            int has_isa = rte_cpu_get_flag_enabled(RTE_CPUFLAG);        \
-            VLOG_DBG("CPU flag %s, available %s\n", name_str,           \
-                      has_isa ? "yes" : "no");                          \
-            return true;                                                \
+            static uint8_t isa_check_##RTE_CPUFLAG;                     \
+            int check = isa_check_##RTE_CPUFLAG & ISA_CHECK_DONE_BIT;   \
+            if (OVS_UNLIKELY(!check)) {                                 \
+                int has_isa = rte_cpu_get_flag_enabled(RTE_CPUFLAG);    \
+                VLOG_DBG("CPU flag %s, available %s\n",                 \
+                         name_str, has_isa ? "yes" : "no");             \
+                isa_check_##RTE_CPUFLAG = ISA_CHECK_DONE_BIT;           \
+                if (has_isa)                                            \
+                    isa_check_##RTE_CPUFLAG |= ISA_AVAILABLE_BIT;       \
+            }                                                           \
+            if (isa_check_##RTE_CPUFLAG & ISA_AVAILABLE_BIT)            \
+                return true;                                            \
         }                                                               \
     } while (0)