From: Ken Steele Date: Tue, 10 Sep 2013 18:04:40 +0000 (-0400) Subject: Support for Tile Gx atomic instructions X-Git-Tag: suricata-2.0beta2~374 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b08ddfa7f1bd38034423a1006bf2a6cb4ca8cbfd;p=thirdparty%2Fsuricata.git Support for Tile Gx atomic instructions Tilera's GCC supports the GCC __sync_ intrinsics. Increase the size of some atomic variables for better performance on Tile. The Tile-Gx architecture has native support for 32-bit and 64-bit atomic operations, but not 8-bit and 16-bit, which are emulated using 32-bit atomics, so changing some 16-bit and 8-bit atomic into ints improves performance. Increasing the size of the atomic variables modified in this change does not increase the total size of the structures in which they reside because of existing padding requirements. The one case that would increase the size of the structure (Flow_) was confitionalized to only change the size on Tile. --- diff --git a/src/defrag.h b/src/defrag.h index b5ba29c728..6d4b399275 100644 --- a/src/defrag.h +++ b/src/defrag.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -111,7 +111,7 @@ typedef struct DefragTracker_ { uint32_t timeout; /**< When this tracker will timeout. */ /** use cnt, reference counter */ - SC_ATOMIC_DECLARE(unsigned short, use_cnt); + SC_ATOMIC_DECLARE(unsigned int, use_cnt); TAILQ_HEAD(frag_tailq, Frag_) frags; /**< Head of list of fragments. */ diff --git a/src/flow-hash.c b/src/flow-hash.c index 1a80a30f0d..9b20b9c807 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2012 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -45,7 +45,7 @@ #define FLOW_DEFAULT_FLOW_PRUNE 5 SC_ATOMIC_EXTERN(unsigned int, flow_prune_idx); -SC_ATOMIC_EXTERN(unsigned char, flow_flags); +SC_ATOMIC_EXTERN(unsigned int, flow_flags); static Flow *FlowGetUsedFlow(void); diff --git a/src/flow-manager.c b/src/flow-manager.c index 0f57430dd7..c1906f685e 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2012 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -67,7 +67,7 @@ /* Run mode selected at suricata.c */ extern int run_mode; -SC_ATOMIC_EXTERN(unsigned char, flow_flags); +SC_ATOMIC_EXTERN(unsigned int, flow_flags); /* 1 seconds */ #define FLOW_NORMAL_MODE_UPDATE_DELAY_SEC 1 diff --git a/src/flow.c b/src/flow.c index 2b24d3298f..52c405115a 100644 --- a/src/flow.c +++ b/src/flow.c @@ -80,7 +80,7 @@ SC_ATOMIC_DECLARE(unsigned int, flow_prune_idx); /** atomic flags */ -SC_ATOMIC_DECLARE(unsigned char, flow_flags); +SC_ATOMIC_DECLARE(unsigned int, flow_flags); void FlowRegisterTests(void); void FlowInitFlowProto(); diff --git a/src/flow.h b/src/flow.h index b94882cd7a..98080626d0 100644 --- a/src/flow.h +++ b/src/flow.h @@ -247,6 +247,13 @@ typedef struct FlowAddress_ { #define addr_data16 address.address_un_data16 #define addr_data8 address.address_un_data8 +#ifdef __tile__ +/* Atomic Ints performance better on Tile. */ +typedef unsigned int FlowRefCount; +#else +typedef unsigned short FlowRefCount; +#endif + /** * \brief Flow data structure. * @@ -290,7 +297,7 @@ typedef struct Flow_ * On receiving a packet the counter is incremented while the flow * bucked is locked, which is also the case on timeout pruning. */ - SC_ATOMIC_DECLARE(unsigned short, use_cnt); + SC_ATOMIC_DECLARE(FlowRefCount, use_cnt); /** flow queue id, used with autofp */ SC_ATOMIC_DECLARE(int, autofp_tmqh_flow_qid); diff --git a/src/host.h b/src/host.h index 9f8d0c5dd2..2616b4b35b 100644 --- a/src/host.h +++ b/src/host.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2012 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -63,7 +63,7 @@ typedef struct Host_ { Address a; /** use cnt, reference counter */ - SC_ATOMIC_DECLARE(unsigned short, use_cnt); + SC_ATOMIC_DECLARE(unsigned int, use_cnt); /** pointers to iprep storage */ void *iprep; diff --git a/src/threadvars.h b/src/threadvars.h index c589cc4c59..58581a0f79 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -60,7 +60,7 @@ typedef struct ThreadVars_ { char *name; char *thread_group_name; - SC_ATOMIC_DECLARE(unsigned short, flags); + SC_ATOMIC_DECLARE(unsigned int, flags); /** aof(action on failure) determines what should be done with the thread when it encounters certain conditions like failures */ diff --git a/src/util-atomic.h b/src/util-atomic.h index 650bf7deda..cbcfc86873 100644 --- a/src/util-atomic.h +++ b/src/util-atomic.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -42,8 +42,11 @@ #define __UTIL_ATOMIC_H__ /* test if we have atomic operations support */ -#if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || \ - !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) +#if (!defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || \ + !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)) && \ + !defined(__tile__) + +/* Do not have atomic operations support, so implement them with locks. */ /** * \brief wrapper to declare an atomic variable including a (spin) lock