From patchwork Fri Aug 22 10:49:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 35794 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D5EA20540 for ; Fri, 22 Aug 2014 10:49:32 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id uq10sf47344688igb.11 for ; Fri, 22 Aug 2014 03:49:31 -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=m5ZZ23kk4J82qdwFe/bQ7y1+nYLT4qF/CCl9y8Chww0=; b=lfapYrwwR99Nx+0KRMbk9dhlIOKrlgyhHaqDrJmIVJVI/J8TFpfKJPhuNujgHLAcXG B4rhLjcukcFEuAShp4kzQlRjhUSEgW5mX+ynQNY/Ovjhx1HKOsrjs8EHlg92V6eGcJOX vEEwYeqLXMKfjN2P4He+mAGA+p7hHmssKRGog93qm2LtpVURib7Xr0SrgHyMMoYdgziM ms9WS9BWA7zPwgkwVE45/4Cw+XCwLjICLlM7nkCiEGjRDtzvY9DD2t/yE6X1zm/2CxpE GPf2Dqlz4AQaL2tT0yOB5dRoylsMRoKoc3bI5CmFefSPjIt6IWum36fxEXloeJrCW5TM K4+Q== X-Gm-Message-State: ALoCoQlNVPmXGggFpA+7paTmJn5jZcfehhsObp+UzLDlO5Uq1V6N9nx1d4tLmves30RlBPLpgIIr X-Received: by 10.182.81.161 with SMTP id b1mr2750752oby.1.1408704571562; Fri, 22 Aug 2014 03:49:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.11 with SMTP id y11ls1150266qgy.23.gmail; Fri, 22 Aug 2014 03:49:31 -0700 (PDT) X-Received: by 10.52.30.2 with SMTP id o2mr3049014vdh.12.1408704571411; Fri, 22 Aug 2014 03:49:31 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id sf7si13314101vdb.19.2014.08.22.03.49.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Aug 2014 03:49:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so12217888vcb.3 for ; Fri, 22 Aug 2014 03:49:31 -0700 (PDT) X-Received: by 10.52.228.67 with SMTP id sg3mr3001357vdc.6.1408704571321; Fri, 22 Aug 2014 03:49:31 -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.221.45.67 with SMTP id uj3csp6906vcb; Fri, 22 Aug 2014 03:49:30 -0700 (PDT) X-Received: by 10.140.84.21 with SMTP id k21mr6185579qgd.70.1408704570681; Fri, 22 Aug 2014 03:49:30 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id f94si41825689qgd.22.2014.08.22.03.49.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 22 Aug 2014 03:49:30 -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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKmPR-0005Iq-1Q; Fri, 22 Aug 2014 10:49:29 +0000 Received: from mail-qc0-f174.google.com ([209.85.216.174]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKmPL-0005IQ-5t for lng-odp@lists.linaro.org; Fri, 22 Aug 2014 10:49:23 +0000 Received: by mail-qc0-f174.google.com with SMTP id l6so10531469qcy.5 for ; Fri, 22 Aug 2014 03:49:17 -0700 (PDT) X-Received: by 10.140.41.38 with SMTP id y35mr5957750qgy.69.1408704557884; Fri, 22 Aug 2014 03:49:17 -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 80sm32399824qgs.12.2014.08.22.03.49.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Aug 2014 03:49:16 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Fri, 22 Aug 2014 13:49:51 +0300 Message-Id: <1408704591-27440-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: timers patch Subject: [lng-odp] [PATCH] Timer example arguments 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.220.172 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 Use arguments instead of hard coded values. Signed-off-by: Petri Savolainen Reviewed-by: Stuart Haslam --- example/timer/odp_timer_test.c | 118 ++++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 31 deletions(-) diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index dbe0e5b..bf1d7df 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -26,9 +26,19 @@ #define MAX_WORKERS 32 /**< Max worker threads */ #define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ +/* Nanoseconds */ +#define USEC 1000UL +#define MSEC 1000000UL +#define SEC 1000000000UL + /** Test arguments */ typedef struct { - int core_count; /**< Core count*/ + int core_count; /**< Core count*/ + int resolution_us; /**< Timeout resolution in usec*/ + int min_us; /**< Minimum timeout in usec*/ + int max_us; /**< Maximum timeout in usec*/ + int period_us; /**< Timeout period in usec*/ + int tmo_count; /**< Timeout count*/ } test_args_t; @@ -40,26 +50,39 @@ static odp_timer_t test_timer; /** @private test timeout */ -static void test_timeouts(int thr) +static void test_abs_timeouts(int thr, test_args_t *args) { uint64_t tick; + uint64_t period; + uint64_t period_ns; odp_queue_t queue; odp_buffer_t buf; - int num = 10; + int num; ODP_DBG(" [%i] test_timeouts\n", thr); queue = odp_queue_lookup("timer_queue"); - tick = odp_timer_current_tick(test_timer); + period_ns = args->period_us*USEC; + period = odp_timer_ns_to_tick(test_timer, period_ns); - tick += 100; + ODP_DBG(" [%i] period %"PRIu64" ticks, %"PRIu64" ns\n", thr, + period, period_ns); - odp_timer_absolute_tmo(test_timer, tick, - queue, ODP_BUFFER_INVALID); + tick = odp_timer_current_tick(test_timer); ODP_DBG(" [%i] current tick %"PRIu64"\n", thr, tick); + tick += period; + + if (odp_timer_absolute_tmo(test_timer, tick, queue, ODP_BUFFER_INVALID) + == ODP_TIMER_TMO_INVALID){ + ODP_DBG("Timeout request failed\n"); + return; + } + + num = args->tmo_count; + while (1) { odp_timeout_t tmo; @@ -77,7 +100,7 @@ static void test_timeouts(int thr) if (num == 0) break; - tick += 100; + tick += period; odp_timer_absolute_tmo(test_timer, tick, queue, ODP_BUFFER_INVALID); @@ -91,28 +114,22 @@ static void test_timeouts(int thr) /** * @internal Worker thread * - * @param arg Arguments + * @param ptr Pointer to test arguments * - * @return NULL on failure + * @return Pointer to exit status */ -static void *run_thread(void *arg) +static void *run_thread(void *ptr) { int thr; odp_buffer_pool_t msg_pool; + test_args_t *args; - thr = odp_thread_id(); + args = ptr; + thr = odp_thread_id(); printf("Thread %i starts on core %i\n", thr, odp_thread_core()); /* - * Test barriers back-to-back - */ - odp_barrier_sync(&test_barrier); - odp_barrier_sync(&test_barrier); - odp_barrier_sync(&test_barrier); - odp_barrier_sync(&test_barrier); - - /* * Find the buffer pool */ msg_pool = odp_buffer_pool_lookup("msg_pool"); @@ -124,12 +141,12 @@ static void *run_thread(void *arg) odp_barrier_sync(&test_barrier); - test_timeouts(thr); + test_abs_timeouts(thr, args); printf("Thread %i exits\n", thr); fflush(NULL); - return arg; + return NULL; } @@ -141,6 +158,11 @@ static void print_usage(void) printf("\n\nUsage: ./odp_example [options]\n"); printf("Options:\n"); printf(" -c, --count core count, core IDs start from 1\n"); + printf(" -r, --resolution timeout resolution in usec\n"); + printf(" -m, --min minimum timeout in usec\n"); + printf(" -x, --max maximum timeout in usec\n"); + printf(" -p, --period timeout period in usec\n"); + printf(" -t, --timeouts timeout repeat count\n"); printf(" -h, --help this help\n"); printf("\n\n"); } @@ -159,13 +181,27 @@ static void parse_args(int argc, char *argv[], test_args_t *args) int long_index; static struct option longopts[] = { - {"count", required_argument, NULL, 'c'}, - {"help", no_argument, NULL, 'h'}, + {"count", required_argument, NULL, 'c'}, + {"resolution", required_argument, NULL, 'r'}, + {"min", required_argument, NULL, 'm'}, + {"max", required_argument, NULL, 'x'}, + {"period", required_argument, NULL, 'p'}, + {"timeouts", required_argument, NULL, 't'}, + {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; + /* defaults */ + args->core_count = 0; /* all cores */ + args->resolution_us = 10000; + args->min_us = args->resolution_us; + args->max_us = 100000000; + args->period_us = 1000000; + args->tmo_count = 30; + while (1) { - opt = getopt_long(argc, argv, "+c:h", longopts, &long_index); + opt = getopt_long(argc, argv, "+c:r:m:x:p:t:h", + longopts, &long_index); if (opt == -1) break; /* No more options */ @@ -174,7 +210,21 @@ static void parse_args(int argc, char *argv[], test_args_t *args) case 'c': args->core_count = atoi(optarg); break; - + case 'r': + args->resolution_us = atoi(optarg); + break; + case 'm': + args->min_us = atoi(optarg); + break; + case 'x': + args->max_us = atoi(optarg); + break; + case 'p': + args->period_us = atoi(optarg); + break; + case 't': + args->tmo_count = atoi(optarg); + break; case 'h': print_usage(); exit(EXIT_SUCCESS); @@ -203,7 +253,7 @@ int main(int argc, char *argv[]) uint64_t cycles, ns; odp_queue_param_t param; - printf("\nODP example starts\n"); + printf("\nODP timer example starts\n"); memset(&args, 0, sizeof(args)); parse_args(argc, argv, &args); @@ -248,6 +298,11 @@ int main(int argc, char *argv[]) first_core = 0; printf("first core: %i\n", first_core); + printf("resolution: %i usec\n", args.resolution_us); + printf("min timeout: %i usec\n", args.min_us); + printf("max timeout: %i usec\n", args.max_us); + printf("period: %i usec\n", args.period_us); + printf("timeouts: %i\n", args.tmo_count); /* * Init this thread. It makes also ODP calls when @@ -288,8 +343,9 @@ int main(int argc, char *argv[]) } test_timer = odp_timer_create("test_timer", pool, - 1000000, 1000000, 1000000000000UL); - + args.resolution_us*USEC, + args.min_us*USEC, + args.max_us*USEC); odp_shm_print_all(); @@ -302,7 +358,7 @@ int main(int argc, char *argv[]) printf(" %12"PRIu64" cycles -> %12"PRIu64" ns\n", cycles, odp_time_cycles_to_ns(cycles)); - for (ns = 1; ns <= 100000000000UL; ns *= 10) { + for (ns = 1; ns <= 100*SEC; ns *= 10) { cycles = odp_time_ns_to_cycles(ns); printf(" %12"PRIu64" ns -> %12"PRIu64" cycles\n", ns, @@ -318,7 +374,7 @@ int main(int argc, char *argv[]) /* Create and launch worker threads */ odp_linux_pthread_create(thread_tbl, num_workers, first_core, - run_thread, NULL); + run_thread, &args); /* Wait for worker threads to exit */ odp_linux_pthread_join(thread_tbl, num_workers);