From patchwork Fri Jun 12 21:36:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 49836 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 836E920C81 for ; Fri, 12 Jun 2015 21:36:36 +0000 (UTC) Received: by wgv5 with SMTP id 5sf12177783wgv.0 for ; Fri, 12 Jun 2015 14:36:35 -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:delivered-to:from:to:date :message-id:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=TbdBCi636OvYEKTAffeWA3sClDWUCW5ncJfMB6o7uyU=; b=keHYifvOHaoXUaXcOyPMTlc2sVvQFJwBOEyp1G4W9vT+U7ygrnOU695iiCTtwGG+33 jsq2Stz+mnk0fGz4zEtcogul1olxmJPHBiYBgA1uglowV4tIJ8zbqqabZFCLEn79bH5l tHm9MsYsVZvIe4tkbcTkrsF6lCaXvZkE28kM8yy32016peBXNu2P0e6aP3deEOWNdBFA PZhBAOXcpXC81iE17WsKATTJKX5StwfnB7j/MwsFRD/loVynaax5LN7vefzptrZlKV8F N8rmFZNKZc6vV8QWrcZHo3CvFa0K07O5S/0j9GrIRM762Wd6LsZL5EXl85iJnGvNLnaD Wbpg== X-Gm-Message-State: ALoCoQlqC/w7pjVD3MBMiplW9YI8c+YLALeS6fSGsGHS4aV4f+H6ZHhf7K0wexhi5ROaSF6myTl1 X-Received: by 10.194.5.229 with SMTP id v5mr16311398wjv.0.1434144995736; Fri, 12 Jun 2015 14:36:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.245.43 with SMTP id xl11ls659381lac.21.gmail; Fri, 12 Jun 2015 14:36:35 -0700 (PDT) X-Received: by 10.112.170.167 with SMTP id an7mr17020130lbc.103.1434144995540; Fri, 12 Jun 2015 14:36:35 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id e10si4381989lae.15.2015.06.12.14.36.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 14:36:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by laew7 with SMTP id w7so27829258lae.1 for ; Fri, 12 Jun 2015 14:36:35 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr17150942laa.106.1434144995202; Fri, 12 Jun 2015 14:36:35 -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.108.230 with SMTP id hn6csp827607lbb; Fri, 12 Jun 2015 14:36:33 -0700 (PDT) X-Received: by 10.55.16.200 with SMTP id 69mr34461075qkq.98.1434144993513; Fri, 12 Jun 2015 14:36:33 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f29si1515403qki.74.2015.06.12.14.36.32; Fri, 12 Jun 2015 14:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id 4C46E62111; Fri, 12 Jun 2015 21:36:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id B8878620C5; Fri, 12 Jun 2015 21:36:25 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 71570620DD; Fri, 12 Jun 2015 21:36:17 +0000 (UTC) Received: from mail-vn0-f51.google.com (mail-vn0-f51.google.com [209.85.216.51]) by lists.linaro.org (Postfix) with ESMTPS id 20954620B7 for ; Fri, 12 Jun 2015 21:36:16 +0000 (UTC) Received: by vnbg129 with SMTP id g129so8002266vnb.11 for ; Fri, 12 Jun 2015 14:36:15 -0700 (PDT) X-Received: by 10.52.116.162 with SMTP id jx2mr29299488vdb.80.1434144975837; Fri, 12 Jun 2015 14:36:15 -0700 (PDT) Received: from mike-desktop.?.holmesfamily.ws (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by mx.google.com with ESMTPSA id cj9sm5840098vdd.14.2015.06.12.14.36.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 14:36:14 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Fri, 12 Jun 2015 17:36:06 -0400 Message-Id: <1434144966-21462-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [PATCH] remove helper dependence on ODP internals X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@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.215.47 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 Remove the helpers dependence on internal implementation details, implementations should only have to implement the public API. Signed-off-by: Mike Holmes --- helper/linux.c | 32 ++++++------- helper/odph_debug.h | 93 ++++++++++++++++++++++++++++++++++++++ helper/odph_pause.h | 54 ++++++++++++++++++++++ helper/ring.c | 43 +++++++++--------- platform/linux-generic/Makefile.am | 4 +- 5 files changed, 187 insertions(+), 39 deletions(-) create mode 100644 helper/odph_debug.h create mode 100644 helper/odph_pause.h diff --git a/helper/linux.c b/helper/linux.c index be1ea13..3659be0 100644 --- a/helper/linux.c +++ b/helper/linux.c @@ -17,12 +17,10 @@ #include #include -#include #include #include #include -#include - +#include "odph_debug.h" int odph_linux_cpumask_default(odp_cpumask_t *mask, int num) { @@ -32,7 +30,7 @@ int odph_linux_cpumask_default(odp_cpumask_t *mask, int num) ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); if (ret != 0) - ODP_ABORT("failed to read CPU affinity value\n"); + ODPH_ABORT("failed to read CPU affinity value\n"); odp_cpumask_zero(mask); @@ -61,16 +59,16 @@ static void *odp_run_start_routine(void *arg) /* ODP thread local init */ if (odp_init_local()) { - ODP_ERR("Local init failed\n"); + ODPH_ERR("Local init failed\n"); return NULL; } void *ret_ptr = start_args->start_routine(start_args->arg); int ret = odp_term_local(); if (ret < 0) - ODP_ERR("Local term failed\n"); + ODPH_ERR("Local term failed\n"); else if (ret == 0 && odp_term_global()) - ODP_ERR("Global term failed\n"); + ODPH_ERR("Global term failed\n"); return ret_ptr; } @@ -95,8 +93,8 @@ int odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, cpu_count = odp_cpu_count(); if (num < 1 || num > cpu_count) { - ODP_ERR("Invalid number of threads: %d (%d cores available)\n", - num, cpu_count); + ODPH_ERR("Invalid number of threads: %d (%d cores available)\n", + num, cpu_count); return 0; } @@ -116,7 +114,7 @@ int odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, thread_tbl[i].start_args = malloc(sizeof(odp_start_args_t)); if (thread_tbl[i].start_args == NULL) - ODP_ABORT("Malloc failed"); + ODPH_ABORT("Malloc failed"); thread_tbl[i].start_args->start_routine = start_routine; thread_tbl[i].start_args->arg = arg; @@ -124,7 +122,7 @@ int odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, ret = pthread_create(&thread_tbl[i].thread, &thread_tbl[i].attr, odp_run_start_routine, thread_tbl[i].start_args); if (ret != 0) { - ODP_ERR("Failed to start thread on cpu #%d\n", cpu); + ODPH_ERR("Failed to start thread on cpu #%d\n", cpu); free(thread_tbl[i].start_args); break; } @@ -167,7 +165,7 @@ int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, cpu_count = odp_cpu_count(); if (num < 1 || num > cpu_count) { - ODP_ERR("Bad num\n"); + ODPH_ERR("Bad num\n"); return -1; } @@ -181,7 +179,7 @@ int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, pid = fork(); if (pid < 0) { - ODP_ERR("fork() failed\n"); + ODPH_ERR("fork() failed\n"); return -1; } @@ -196,12 +194,12 @@ int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, /* Child process */ if (sched_setaffinity(0, sizeof(cpu_set_t), &proc_mask.set)) { - ODP_ERR("sched_setaffinity() failed\n"); + ODPH_ERR("sched_setaffinity() failed\n"); return -2; } if (odp_init_local()) { - ODP_ERR("Local init failed\n"); + ODPH_ERR("Local init failed\n"); return -2; } @@ -232,7 +230,7 @@ int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) pid = wait(&status); if (pid < 0) { - ODP_ERR("wait() failed\n"); + ODPH_ERR("wait() failed\n"); return -1; } @@ -244,7 +242,7 @@ int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) } if (j == num) { - ODP_ERR("Bad pid\n"); + ODPH_ERR("Bad pid\n"); return -1; } } diff --git a/helper/odph_debug.h b/helper/odph_debug.h new file mode 100644 index 0000000..9c216cd --- /dev/null +++ b/helper/odph_debug.h @@ -0,0 +1,93 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +/** + * @file + * + * HELPER debug + */ + +#ifndef HELPER_DEBUG_H_ +#define HELPER_DEBUG_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ODPH_DEBUG_PRINT +#define ODPH_DEBUG_PRINT 1 +#endif + +/** + * log level. + */ +typedef enum HELPER_log_level { + ODPH_LOG_DBG, + ODPH_LOG_ERR, + ODPH_LOG_ABORT +} HELPER_log_level_e; + +/** + * default LOG macro. + */ +#define ODPH_LOG(level, fmt, ...) \ +do { \ + switch (level) { \ + case ODPH_LOG_ERR: \ + fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \ + __LINE__, __func__, ##__VA_ARGS__); \ + break; \ + case ODPH_LOG_DBG: \ + if (ODPH_DEBUG_PRINT == 1) \ + fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \ + __LINE__, __func__, ##__VA_ARGS__); \ + break; \ + case ODPH_LOG_ABORT: \ + fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \ + __LINE__, __func__, ##__VA_ARGS__); \ + abort(); \ + break; \ + default: \ + fprintf(stderr, "Unknown LOG level"); \ + break;\ + } \ +} while (0) + +/** + * Debug printing macro, which prints output when DEBUG flag is set. + */ +#define ODPH_DBG(fmt, ...) \ + ODPH_LOG(ODPH_LOG_DBG, fmt, ##__VA_ARGS__) + +/** + * Print output to stderr (file, line and function). + */ +#define ODPH_ERR(fmt, ...) \ + ODPH_LOG(ODPH_LOG_ERR, fmt, ##__VA_ARGS__) + +/** + * Print output to stderr (file, line and function), + * then abort. + */ +#define ODPH_ABORT(fmt, ...) \ + ODPH_LOG(ODPH_LOG_ABORT, fmt, ##__VA_ARGS__) + +/** + * @} + */ + +/** + * Mark intentionally unused argument for functions + */ +#define ODPH_UNUSED __attribute__((__unused__)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/helper/odph_pause.h b/helper/odph_pause.h new file mode 100644 index 0000000..5618f1f --- /dev/null +++ b/helper/odph_pause.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODPH_PAUSE_H_ +#define ODPH_PAUSE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Spin loop for helper internal use + */ +static inline void odph_pause(void) +{ +#if defined __x86_64__ || defined __i386__ + +#ifdef __SSE2__ + __asm__ __volatile__ ("pause"); +#else + __asm__ __volatile__ ("rep; nop"); +#endif + +#elif defined __arm__ + +#if __ARM_ARCH == 7 + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); +#endif + +#elif defined __OCTEON__ + + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + +#endif +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/helper/ring.c b/helper/ring.c index 67fece9..107e47c 100644 --- a/helper/ring.c +++ b/helper/ring.c @@ -70,20 +70,20 @@ ***************************************************************************/ #include -#include -#include -#include #include +#include "odph_pause.h" #include #include #include #include -#include +#include "odph_debug.h" #include #include static TAILQ_HEAD(, odph_ring) odp_ring_list; +#define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) + /* * the enqueue of pointers on the ring. */ @@ -161,9 +161,10 @@ odph_ring_create(const char *name, unsigned count, unsigned flags) odp_shm_t shm; /* count must be a power of 2 */ - if (!ODP_VAL_IS_POWER_2(count) || (count > ODPH_RING_SZ_MASK)) { - ODP_ERR("Requested size is invalid, must be power of 2, and do not exceed the size limit %u\n", - ODPH_RING_SZ_MASK); + if (!RING_VAL_IS_POWER_2(count) || (count > ODPH_RING_SZ_MASK)) { + ODPH_ERR("Requested size is invalid, must be power of 2," + "and do not exceed the size limit %u\n", + ODPH_RING_SZ_MASK); return NULL; } @@ -194,7 +195,7 @@ odph_ring_create(const char *name, unsigned count, unsigned flags) TAILQ_INSERT_TAIL(&odp_ring_list, r, next); } else { - ODP_ERR("Cannot reserve memory\n"); + ODPH_ERR("Cannot reserve memory\n"); } odp_rwlock_write_unlock(&qlock); @@ -283,7 +284,7 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, * we need to wait for them to complete */ while (odp_unlikely(r->prod.tail != prod_head)) - odp_spin(); + odph_pause(); /* Release our entries and the memory they refer to */ __atomic_thread_fence(__ATOMIC_RELEASE); @@ -400,7 +401,7 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, * we need to wait for them to complete */ while (odp_unlikely(r->cons.tail != cons_head)) - odp_spin(); + odph_pause(); /* Release our entries and the memory they refer to */ __atomic_thread_fence(__ATOMIC_RELEASE); @@ -532,19 +533,19 @@ unsigned odph_ring_free_count(const odph_ring_t *r) /* dump the status of the ring on the console */ void odph_ring_dump(const odph_ring_t *r) { - ODP_DBG("ring <%s>@%p\n", r->name, r); - ODP_DBG(" flags=%x\n", r->flags); - ODP_DBG(" size=%"PRIu32"\n", r->prod.size); - ODP_DBG(" ct=%"PRIu32"\n", r->cons.tail); - ODP_DBG(" ch=%"PRIu32"\n", r->cons.head); - ODP_DBG(" pt=%"PRIu32"\n", r->prod.tail); - ODP_DBG(" ph=%"PRIu32"\n", r->prod.head); - ODP_DBG(" used=%u\n", odph_ring_count(r)); - ODP_DBG(" avail=%u\n", odph_ring_free_count(r)); + ODPH_DBG("ring <%s>@%p\n", r->name, r); + ODPH_DBG(" flags=%x\n", r->flags); + ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); + ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); + ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); + ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); + ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); + ODPH_DBG(" used=%u\n", odph_ring_count(r)); + ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); if (r->prod.watermark == r->prod.size) - ODP_DBG(" watermark=0\n"); + ODPH_DBG(" watermark=0\n"); else - ODP_DBG(" watermark=%"PRIu32"\n", r->prod.watermark); + ODPH_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); } /* dump the status of all rings on the console */ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index b8f93c7..4f2063f 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -137,7 +137,9 @@ subdirheaders_HEADERS = \ $(top_srcdir)/helper/include/odp/helper/linux.h \ $(top_srcdir)/helper/include/odp/helper/ring.h \ $(top_srcdir)/helper/include/odp/helper/tcp.h \ - $(top_srcdir)/helper/include/odp/helper/udp.h + $(top_srcdir)/helper/include/odp/helper/udp.h \ + $(top_srcdir)/helper/odph_debug.h \ + $(top_srcdir)/helper/odph_pause.h __LIB__libodp_la_SOURCES = \ odp_barrier.c \