From patchwork Fri Oct 31 13:39:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 39891 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4CB5C202FE for ; Fri, 31 Oct 2014 13:40:22 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id ex7sf622762wid.8 for ; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=7xIsDbvk5dlOGxz922klJ7LyRwf053CdaUZxPJ1x4MM=; b=RsQtHRpLbQh7cFyMTHCsV4mStfDOJHWMgv1S+/NGsI2P6n09TE37JbaX0KZaM2O2GC iYBJLr3UbPDTaF0TXBx0w5W3b2x8RsftK2xtQU66TKMkiewFjhTnJinxR0WiKI+AmV70 dkRODfU9E3FnttfaZB0rPHnDa6d3/3FWCMUTbjNMkH06a8OLGL2QSA3iqZ180siey6vW fWMdgpk5+sprt3amfQtEG0z00iFH+OLnn+OTPgM053nGFF0XOT05JAGW70jTIYLJrcyX trGbZDD8WctptwYMmu7CYavoAok2/F87UmvGAk704jCk7BTpEbIwOp6LbiSOkLXi7YGx gc9A== X-Gm-Message-State: ALoCoQmzln99vJzleWe0aRw0jMSQYLG3wvytZfiDNc88DHrOiau9ipp7ua5htXSd0DFoZ2MBO9Kw X-Received: by 10.194.91.208 with SMTP id cg16mr368276wjb.5.1414762821541; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.11.132 with SMTP id ei4ls489671lad.109.gmail; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) X-Received: by 10.112.166.1 with SMTP id zc1mr26150668lbb.90.1414762821377; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id xt8si16683146lac.122.2014.10.31.06.40.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:40:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z11so4051526lbi.21 for ; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) X-Received: by 10.112.189.10 with SMTP id ge10mr26112244lbc.23.1414762821282; Fri, 31 Oct 2014 06:40:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp203590lbz; Fri, 31 Oct 2014 06:40:20 -0700 (PDT) X-Received: by 10.140.109.102 with SMTP id k93mr18879087qgf.83.1414762813228; Fri, 31 Oct 2014 06:40:13 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id l44si17137251qgl.30.2014.10.31.06.40.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:40:13 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XkCR0-0001Ne-NU; Fri, 31 Oct 2014 13:40:10 +0000 Received: from mail-qg0-f54.google.com ([209.85.192.54]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XkCQu-0001MX-0k for lng-odp@lists.linaro.org; Fri, 31 Oct 2014 13:40:04 +0000 Received: by mail-qg0-f54.google.com with SMTP id q108so5652927qgd.13 for ; Fri, 31 Oct 2014 06:39:58 -0700 (PDT) X-Received: by 10.224.74.135 with SMTP id u7mr17946181qaj.41.1414762798663; Fri, 31 Oct 2014 06:39:58 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id u14sm1554281qag.32.2014.10.31.06.39.56 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:39:57 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Fri, 31 Oct 2014 15:39:38 +0200 Message-Id: <1414762778-12515-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.1.1 X-Topics: patch Subject: [lng-odp] [PATCH] Removed odp_atomic_int_t X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Integer version is not needed. Unsigned 32 and 64 bit atomics are used instead. If signed 32/64 bits can be added later on need basis. Signed-off-by: Petri Savolainen --- platform/linux-generic/include/api/odp_atomic.h | 115 --------------------- platform/linux-generic/include/api/odp_barrier.h | 4 +- .../linux-generic/include/odp_buffer_internal.h | 2 +- platform/linux-generic/odp_barrier.c | 6 +- platform/linux-generic/odp_thread.c | 6 +- test/api_test/odp_atomic_test.c | 80 ++------------ test/api_test/odp_atomic_test.h | 9 -- 7 files changed, 16 insertions(+), 206 deletions(-) diff --git a/platform/linux-generic/include/api/odp_atomic.h b/platform/linux-generic/include/api/odp_atomic.h index 213c81f..5c83b39 100644 --- a/platform/linux-generic/include/api/odp_atomic.h +++ b/platform/linux-generic/include/api/odp_atomic.h @@ -26,10 +26,6 @@ extern "C" { * @{ */ -/** - * Atomic integer - */ -typedef volatile int32_t odp_atomic_int_t; /** * Atomic unsigned integer 64 bits @@ -43,117 +39,6 @@ typedef volatile uint32_t odp_atomic_u32_t; /** - * Initialize atomic integer - * - * @param ptr An integer atomic variable - * - * @note The operation is not synchronized with other threads - */ -static inline void odp_atomic_init_int(odp_atomic_int_t *ptr) -{ - *ptr = 0; -} - -/** - * Load value of atomic integer - * - * @param ptr An atomic variable - * - * @return atomic integer value - * - * @note The operation is not synchronized with other threads - */ -static inline int odp_atomic_load_int(odp_atomic_int_t *ptr) -{ - return *ptr; -} - -/** - * Store value to atomic integer - * - * @param ptr An atomic variable - * @param new_value Store new_value to a variable - * - * @note The operation is not synchronized with other threads - */ -static inline void odp_atomic_store_int(odp_atomic_int_t *ptr, int new_value) -{ - *ptr = new_value; -} - -/** - * Fetch and add atomic integer - * - * @param ptr An atomic variable - * @param value A value to be added to the variable - * - * @return Value of the variable before the operation - */ -static inline int odp_atomic_fetch_add_int(odp_atomic_int_t *ptr, int value) -{ - return __sync_fetch_and_add(ptr, value); -} - -/** - * Fetch and subtract atomic integer - * - * @param ptr An atomic integer variable - * @param value A value to be subtracted from the variable - * - * @return Value of the variable before the operation - */ -static inline int odp_atomic_fetch_sub_int(odp_atomic_int_t *ptr, int value) -{ - return __sync_fetch_and_sub(ptr, value); -} - -/** - * Fetch and increment atomic integer by 1 - * - * @param ptr An atomic variable - * - * @return Value of the variable before the operation - */ -static inline int odp_atomic_fetch_inc_int(odp_atomic_int_t *ptr) -{ - return odp_atomic_fetch_add_int(ptr, 1); -} - -/** - * Increment atomic integer by 1 - * - * @param ptr An atomic variable - * - */ -static inline void odp_atomic_inc_int(odp_atomic_int_t *ptr) -{ - odp_atomic_fetch_add_int(ptr, 1); -} - -/** - * Fetch and decrement atomic integer by 1 - * - * @param ptr An atomic int variable - * - * @return Value of the variable before the operation - */ -static inline int odp_atomic_fetch_dec_int(odp_atomic_int_t *ptr) -{ - return odp_atomic_fetch_sub_int(ptr, 1); -} - -/** - * Decrement atomic integer by 1 - * - * @param ptr An atomic variable - * - */ -static inline void odp_atomic_dec_int(odp_atomic_int_t *ptr) -{ - odp_atomic_fetch_sub_int(ptr, 1); -} - -/** * Initialize atomic uint32 * * @param ptr An atomic variable diff --git a/platform/linux-generic/include/api/odp_barrier.h b/platform/linux-generic/include/api/odp_barrier.h index 866648f..fb02a9d 100644 --- a/platform/linux-generic/include/api/odp_barrier.h +++ b/platform/linux-generic/include/api/odp_barrier.h @@ -31,8 +31,8 @@ extern "C" { * ODP execution barrier */ typedef struct odp_barrier_t { - int count; /**< @private Thread count */ - odp_atomic_int_t bar; /**< @private Barrier counter */ + uint32_t count; /**< @private Thread count */ + odp_atomic_u32_t bar; /**< @private Barrier counter */ } odp_barrier_t; diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index 2002b51..0027bfc 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -88,7 +88,7 @@ typedef struct odp_buffer_hdr_t { uint32_t index; /* buf index in the pool */ size_t size; /* max data size */ size_t cur_offset; /* current offset */ - odp_atomic_int_t ref_count; /* reference count */ + odp_atomic_u32_t ref_count; /* reference count */ odp_buffer_scatter_t scatter; /* Scatter/gather list */ int type; /* type of next header */ odp_buffer_pool_t pool_hdl; /* buffer pool handle */ diff --git a/platform/linux-generic/odp_barrier.c b/platform/linux-generic/odp_barrier.c index a82b294..f4a87c8 100644 --- a/platform/linux-generic/odp_barrier.c +++ b/platform/linux-generic/odp_barrier.c @@ -11,7 +11,7 @@ void odp_barrier_init_count(odp_barrier_t *barrier, int count) { barrier->count = count; - barrier->bar = 0; + barrier->bar = 0; odp_sync_stores(); } @@ -30,12 +30,12 @@ void odp_barrier_init_count(odp_barrier_t *barrier, int count) void odp_barrier_sync(odp_barrier_t *barrier) { - int count; + uint32_t count; int wasless; odp_sync_stores(); wasless = barrier->bar < barrier->count; - count = odp_atomic_fetch_inc_int(&barrier->bar); + count = odp_atomic_fetch_inc_u32(&barrier->bar); if (count == 2*barrier->count-1) { barrier->bar = 0; diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c index b869b27..dcb893d 100644 --- a/platform/linux-generic/odp_thread.c +++ b/platform/linux-generic/odp_thread.c @@ -31,7 +31,7 @@ typedef struct { typedef struct { thread_state_t thr[ODP_CONFIG_MAX_THREADS]; - odp_atomic_int_t num; + odp_atomic_u32_t num; } thread_globals_t; @@ -64,10 +64,10 @@ int odp_thread_init_global(void) static int thread_id(void) { - int id; + uint32_t id; int cpu; - id = odp_atomic_fetch_add_int(&thread_globals->num, 1); + id = odp_atomic_fetch_inc_u32(&thread_globals->num); if (id >= ODP_CONFIG_MAX_THREADS) { ODP_ERR("Too many threads\n"); diff --git a/test/api_test/odp_atomic_test.c b/test/api_test/odp_atomic_test.c index d92a8c1..3ca7674 100644 --- a/test/api_test/odp_atomic_test.c +++ b/test/api_test/odp_atomic_test.c @@ -10,17 +10,14 @@ #include #include -static odp_atomic_int_t a32; static odp_atomic_u32_t a32u; static odp_atomic_u64_t a64u; -static odp_atomic_int_t numthrds; +static odp_atomic_u32_t numthrds; static const char * const test_name[] = { "dummy", "test atomic basic ops add/sub/inc/dec", - "test atomic inc/dec of signed word", - "test atomic add/sub of signed word", "test atomic inc/dec of unsigned word", "test atomic add/sub of unsigned word", "test atomic inc/dec of unsigned double word", @@ -34,12 +31,10 @@ static void usage(void) printf("\n./odp_atomic -t -n ,\n\n" "\t is\n" "\t\t1 - Test mix(does inc,dec,add,sub on 32/64 bit)\n" - "\t\t2 - Test inc dec of signed word\n" - "\t\t3 - Test add sub of signed word\n" - "\t\t4 - Test inc dec of unsigned word\n" - "\t\t5 - Test add sub of unsigned word\n" - "\t\t6 - Test inc dec of double word\n" - "\t\t7 - Test add sub of double word\n" + "\t\t2 - Test inc dec of unsigned word\n" + "\t\t3 - Test add sub of unsigned word\n" + "\t\t4 - Test inc dec of double word\n" + "\t\t5 - Test add sub of double word\n" "\t is optional\n" "\t\t<1 - 31> - no of pthreads to start\n" "\t\tif user doesn't specify this option, then\n" @@ -50,13 +45,6 @@ static void usage(void) "\t\t./odp_atomic -t 3 -n 12\n"); } -void test_atomic_inc_32(void) -{ - int i; - - for (i = 0; i < CNT; i++) - odp_atomic_inc_int(&a32); -} void test_atomic_inc_u32(void) { @@ -74,14 +62,6 @@ void test_atomic_inc_64(void) odp_atomic_inc_u64(&a64u); } -void test_atomic_dec_32(void) -{ - int i; - - for (i = 0; i < CNT; i++) - odp_atomic_dec_int(&a32); -} - void test_atomic_dec_u32(void) { int i; @@ -98,14 +78,6 @@ void test_atomic_dec_64(void) odp_atomic_dec_u64(&a64u); } -void test_atomic_add_32(void) -{ - int i; - - for (i = 0; i < (CNT / ADD_SUB_CNT); i++) - odp_atomic_fetch_add_int(&a32, ADD_SUB_CNT); -} - void test_atomic_add_u32(void) { int i; @@ -122,14 +94,6 @@ void test_atomic_add_64(void) odp_atomic_fetch_add_u64(&a64u, ADD_SUB_CNT); } -void test_atomic_sub_32(void) -{ - int i; - - for (i = 0; i < (CNT / ADD_SUB_CNT); i++) - odp_atomic_fetch_sub_int(&a32, ADD_SUB_CNT); -} - void test_atomic_sub_u32(void) { int i; @@ -146,18 +110,6 @@ void test_atomic_sub_64(void) odp_atomic_fetch_sub_u64(&a64u, ADD_SUB_CNT); } -void test_atomic_inc_dec_32(void) -{ - test_atomic_inc_32(); - test_atomic_dec_32(); -} - -void test_atomic_add_sub_32(void) -{ - test_atomic_add_32(); - test_atomic_sub_32(); -} - void test_atomic_inc_dec_u32(void) { test_atomic_inc_u32(); @@ -188,11 +140,6 @@ void test_atomic_add_sub_64(void) */ void test_atomic_basic(void) { - test_atomic_inc_32(); - test_atomic_dec_32(); - test_atomic_add_32(); - test_atomic_sub_32(); - test_atomic_inc_u32(); test_atomic_dec_u32(); test_atomic_add_u32(); @@ -206,25 +153,18 @@ void test_atomic_basic(void) void test_atomic_init(void) { - odp_atomic_init_int(&a32); odp_atomic_init_u32(&a32u); odp_atomic_init_u64(&a64u); } void test_atomic_store(void) { - odp_atomic_store_int(&a32, S32_INIT_VAL); odp_atomic_store_u32(&a32u, U32_INIT_VAL); odp_atomic_store_u64(&a64u, U64_INIT_VAL); } int test_atomic_validate(void) { - if (odp_atomic_load_int(&a32) != S32_INIT_VAL) { - ODP_ERR("Atomic signed 32 usual functions failed\n"); - return -1; - } - if (odp_atomic_load_u32(&a32u) != U32_INIT_VAL) { ODP_ERR("Atomic u32 usual functions failed\n"); return -1; @@ -247,7 +187,7 @@ static void *run_thread(void *arg) ODP_DBG("Thread %i starts\n", thr); - odp_atomic_inc_int(&numthrds); + odp_atomic_inc_u32(&numthrds); /* Wait here until all pthreads are created */ while (*(volatile int *)&numthrds < parg->numthrds) @@ -259,12 +199,6 @@ static void *run_thread(void *arg) case TEST_MIX: test_atomic_basic(); break; - case TEST_INC_DEC_S32: - test_atomic_inc_dec_32(); - break; - case TEST_ADD_SUB_S32: - test_atomic_add_sub_32(); - break; case TEST_INC_DEC_U32: test_atomic_inc_dec_u32(); break; @@ -328,7 +262,7 @@ int main(int argc, char *argv[]) if (pthrdnum == 0) pthrdnum = odp_sys_core_count(); - odp_atomic_init_int(&numthrds); + odp_atomic_init_u32(&numthrds); test_atomic_init(); test_atomic_store(); diff --git a/test/api_test/odp_atomic_test.h b/test/api_test/odp_atomic_test.h index 7814da5..aaa9d34 100644 --- a/test/api_test/odp_atomic_test.h +++ b/test/api_test/odp_atomic_test.h @@ -18,14 +18,11 @@ #define ADD_SUB_CNT 5 #define CNT 500000 -#define S32_INIT_VAL (1UL << 10) #define U32_INIT_VAL (1UL << 10) #define U64_INIT_VAL (1ULL << 33) typedef enum { TEST_MIX = 1, /* Must be first test case num */ - TEST_INC_DEC_S32, - TEST_ADD_SUB_S32, TEST_INC_DEC_U32, TEST_ADD_SUB_U32, TEST_INC_DEC_64, @@ -34,16 +31,10 @@ typedef enum { } odp_test_atomic_t; -void test_atomic_inc_dec_32(void); -void test_atomic_add_sub_32(void); void test_atomic_inc_dec_u32(void); void test_atomic_add_sub_u32(void); void test_atomic_inc_dec_64(void); void test_atomic_add_sub_64(void); -void test_atomic_inc_32(void); -void test_atomic_dec_32(void); -void test_atomic_add_32(void); -void test_atomic_sub_32(void); void test_atomic_inc_u32(void); void test_atomic_dec_u32(void); void test_atomic_add_u32(void);