]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: make static variables thread_local
authorLukas Sismis <lsismis@oisf.net>
Sat, 23 Mar 2024 22:10:41 +0000 (23:10 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 10 Apr 2024 05:03:07 +0000 (07:03 +0200)
Per a newly obtained knowledge, static variables in functions
are not thread-safe and as a result thread_local attribute was
added.

src/source-dpdk.c

index 84a860f3fdc79a8ca565fa11184d9ac01cf48eaa..6bf5917c32b9f0efad639cd909fd64bfd2918630 100644 (file)
@@ -414,7 +414,7 @@ static TmEcode ReceiveDPDKLoopInit(ThreadVars *tv, DPDKThreadVars *ptv)
 
 static inline void LoopHandleTimeoutOnIdle(ThreadVars *tv)
 {
-    static uint64_t last_timeout_msec = 0;
+    static thread_local uint64_t last_timeout_msec = 0;
     SCTime_t t = DPDKSetTimevalReal(&machine_start_time);
     uint64_t msecs = SCTIME_MSECS(t);
     if (msecs > last_timeout_msec + 100) {
@@ -429,7 +429,7 @@ static inline void LoopHandleTimeoutOnIdle(ThreadVars *tv)
  */
 static inline bool RXPacketCountHeuristic(ThreadVars *tv, DPDKThreadVars *ptv, uint16_t nb_rx)
 {
-    static uint32_t zero_pkt_polls_cnt = 0;
+    static thread_local uint32_t zero_pkt_polls_cnt = 0;
 
     if (nb_rx > 0) {
         zero_pkt_polls_cnt = 0;
@@ -508,7 +508,7 @@ static inline Packet *PacketInitFromMbuf(DPDKThreadVars *ptv, struct rte_mbuf *m
 
 static inline void DPDKSegmentedMbufWarning(struct rte_mbuf *mbuf)
 {
-    static bool segmented_mbufs_warned = false;
+    static thread_local bool segmented_mbufs_warned = false;
     if (!segmented_mbufs_warned && !rte_pktmbuf_is_contiguous(mbuf)) {
         char warn_s[] = "Segmented mbufs detected! Redmine Ticket #6012 "
                         "Check your configuration or report the issue";
@@ -552,7 +552,7 @@ static void HandleShutdown(DPDKThreadVars *ptv)
 
 static void PeriodicDPDKDumpCounters(DPDKThreadVars *ptv)
 {
-    static time_t last_dump = 0;
+    static thread_local time_t last_dump = 0;
     time_t current_time = DPDKGetSeconds();
     /* Trigger one dump of stats every second */
     if (current_time != last_dump) {