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

Victor Julien lists at inliniac.net
Fri Nov 30 15:33:27 UTC 2018


On 30-11-18 16:30, Ming Fu wrote:
> 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.
> 

Hi Ming, we'd be happy to consider pull requests for things like this.
Please see https://github.com/OISF/suricata#contributing

-- 
---------------------------------------------
Victor Julien
http://www.inliniac.net/
PGP: http://www.inliniac.net/victorjulien.asc
---------------------------------------------



More information about the Oisf-users mailing list