[Oisf-users] Intel icc optimize away reload of variable

Ming Fu Ming.Fu at esentire.com
Fri Nov 30 15:30:59 UTC 2018


Hi, 

The Intel compiler -O2 and higher can optimize away the reloading of the flags in function

Int TmThreadsCheckFlag( volatile ThreadVars *tv, uint16_t flag)
{
  return (SC_ATOMIC_GET(tv->flags) & flag) ? 1 : 0;
}

The test will never return 1 if the function is called in a tight loop. 

The following patch fixed the problem by using a memory barrier call. 

--- suricata-4.0.5/src/util-atomic.h	2018-07-17 14:43:02.000000000 +0000
+++ suricata-4.0.5-X/src/util-atomic.h	2018-11-30 15:12:39.691993974 +0000
@@ -456,7 +456,7 @@
  *  \retval var value
  */
 #define SC_ATOMIC_GET(name) \
-    (name ## _sc_atomic__)
+  SCAtomicFetchAndOr(&(name ## _sc_atomic__), (0))
 
 /**
  *  \brief Set the value for the atomic variable.

Regards,
Ming



More information about the Oisf-users mailing list