From patchwork Fri Dec 12 18:35:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 42195 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E645B26C77 for ; Fri, 12 Dec 2014 18:35:34 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf5263503wgh.1 for ; Fri, 12 Dec 2014 10:35:34 -0800 (PST) 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:in-reply-to :references: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=4pmV6jkVPooHPw8AFTly6mVutwMItHMXUVn1MgyFliQ=; b=iuZ6mYUVyOM+aGUW2qc4yuoz0udYGODvTdPfXO0MzZLTqro0pK8bbn4qmYQSudl4pV LpodBVkfHAOc2FcK40hWOFvIIRRMn3ESL7IBNH9LfPRJYw/YGPeZcA4rYbtGFHi+j2+x ae9QL6dNRoxwKoIh7i/EBcmSFQGVKeei/mKdDynhFOxdvsZU6vpaCBJg6gz9DrHUtJM3 mNBFbLGGLx4Z2skUI4YPp6WceehvjICtS1RBUBobf0F/vXiTEYG4t/FzFQMvxYN4oGqm HHBQ6wMtF+9z1P20yQAo9DHQQ/I/HVbMgaNrkSoxErTq6KelcMFy6MuQ7oW32oLlTkDt Jx+w== X-Gm-Message-State: ALoCoQkNeAuPfHb8aDDcZYMd3y7j4aR68BkY4F9KLJ3aH/wVAXTBJXitKu414n3RDSeJUr6cMKTm X-Received: by 10.194.176.106 with SMTP id ch10mr159434wjc.6.1418409334124; Fri, 12 Dec 2014 10:35:34 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.176 with SMTP id az16ls382833lab.87.gmail; Fri, 12 Dec 2014 10:35:33 -0800 (PST) X-Received: by 10.152.5.226 with SMTP id v2mr5897721lav.34.1418409333758; Fri, 12 Dec 2014 10:35:33 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id lc1si2237408lab.57.2014.12.12.10.35.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 12 Dec 2014 10:35:33 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so6982615lbj.37 for ; Fri, 12 Dec 2014 10:35:33 -0800 (PST) X-Received: by 10.112.135.197 with SMTP id pu5mr16847306lbb.22.1418409333584; Fri, 12 Dec 2014 10:35:33 -0800 (PST) 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.142.69 with SMTP id ru5csp61134lbb; Fri, 12 Dec 2014 10:35:32 -0800 (PST) X-Received: by 10.140.21.106 with SMTP id 97mr31359736qgk.61.1418409331742; Fri, 12 Dec 2014 10:35:31 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u103si2311857qgu.103.2014.12.12.10.35.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 12 Dec 2014 10:35:31 -0800 (PST) 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 1XzV3n-0000Lk-B9; Fri, 12 Dec 2014 18:35:27 +0000 Received: from mail-qa0-f54.google.com ([209.85.216.54]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XzV3d-0000LH-6R for lng-odp@lists.linaro.org; Fri, 12 Dec 2014 18:35:17 +0000 Received: by mail-qa0-f54.google.com with SMTP id i13so5430887qae.41 for ; Fri, 12 Dec 2014 10:35:12 -0800 (PST) X-Received: by 10.224.121.142 with SMTP id h14mr33602603qar.80.1418409312007; Fri, 12 Dec 2014 10:35:12 -0800 (PST) Received: from fedora1.holmesfamily.ws ([98.221.136.245]) by mx.google.com with ESMTPSA id b1sm2091690qac.24.2014.12.12.10.35.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Dec 2014 10:35:11 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Fri, 12 Dec 2014 13:35:03 -0500 Message-Id: <1418409304-1924-3-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1418409304-1924-1-git-send-email-mike.holmes@linaro.org> References: <1418409304-1924-1-git-send-email-mike.holmes@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH 2/3] example: odp_timer_test: delete bad example 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: 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.217.178 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 The timer example is actually named odp_timer_test indicating it is not an example. It is widely regarded as a poor example and not a great test. It now attempts to use odp_schedule_one which has been removed from the API. This test should be removed and replaced with a better example written from scratch. Signed-off-by: Mike Holmes --- example/Makefile.am | 2 +- example/timer/.gitignore | 1 - example/timer/Makefile.am | 7 - example/timer/odp_timer_test.c | 389 ----------------------------------------- 4 files changed, 1 insertion(+), 398 deletions(-) delete mode 100644 example/timer/.gitignore delete mode 100644 example/timer/Makefile.am delete mode 100644 example/timer/odp_timer_test.c diff --git a/example/Makefile.am b/example/Makefile.am index b2a22a3..b933653 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1 +1 @@ -SUBDIRS = generator ipsec l2fwd odp_example packet timer +SUBDIRS = generator ipsec l2fwd odp_example packet diff --git a/example/timer/.gitignore b/example/timer/.gitignore deleted file mode 100644 index eb59265..0000000 --- a/example/timer/.gitignore +++ /dev/null @@ -1 +0,0 @@ -odp_timer_test diff --git a/example/timer/Makefile.am b/example/timer/Makefile.am deleted file mode 100644 index dffd4eb..0000000 --- a/example/timer/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -include $(top_srcdir)/example/Makefile.inc - -bin_PROGRAMS = odp_timer_test -odp_timer_test_LDFLAGS = $(AM_LDFLAGS) -static -odp_timer_test_CFLAGS = $(AM_CFLAGS) -I../ - -dist_odp_timer_test_SOURCES = odp_timer_test.c diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c deleted file mode 100644 index 9968bfe..0000000 --- a/example/timer/odp_timer_test.c +++ /dev/null @@ -1,389 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * @example odp_timer_test.c ODP timer example application - */ - -#include -#include - -#include - -/* ODP main header */ -#include - -/* ODP helper for Linux apps */ -#include - -/* GNU lib C */ -#include - - -#define MAX_WORKERS 32 /**< Max worker threads */ -#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ - - -/** Test arguments */ -typedef struct { - 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; - - -/** @private Barrier for test synchronisation */ -static odp_barrier_t test_barrier; - -/** @private Timer handle*/ -static odp_timer_t test_timer; - - -/** @private test timeout */ -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; - - EXAMPLE_DBG(" [%i] test_timeouts\n", thr); - - queue = odp_queue_lookup("timer_queue"); - - period_ns = args->period_us*ODP_TIME_USEC; - period = odp_timer_ns_to_tick(test_timer, period_ns); - - EXAMPLE_DBG(" [%i] period %"PRIu64" ticks, %"PRIu64" ns\n", thr, - period, period_ns); - - tick = odp_timer_current_tick(test_timer); - - EXAMPLE_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){ - EXAMPLE_DBG("Timeout request failed\n"); - return; - } - - num = args->tmo_count; - - while (1) { - odp_timeout_t tmo; - - buf = odp_schedule_one(&queue, ODP_SCHED_WAIT); - - tmo = odp_timeout_from_buffer(buf); - tick = odp_timeout_tick(tmo); - - EXAMPLE_DBG(" [%i] timeout, tick %"PRIu64"\n", thr, tick); - - odp_buffer_free(buf); - - num--; - - if (num == 0) - break; - - tick += period; - - odp_timer_absolute_tmo(test_timer, tick, - queue, ODP_BUFFER_INVALID); - } - - if (odp_queue_sched_type(queue) == ODP_SCHED_SYNC_ATOMIC) - odp_schedule_release_atomic(); -} - - -/** - * @internal Worker thread - * - * @param ptr Pointer to test arguments - * - * @return Pointer to exit status - */ -static void *run_thread(void *ptr) -{ - int thr; - odp_buffer_pool_t msg_pool; - test_args_t *args; - - args = ptr; - thr = odp_thread_id(); - - printf("Thread %i starts on core %i\n", thr, odp_thread_core()); - - /* - * Find the buffer pool - */ - msg_pool = odp_buffer_pool_lookup("msg_pool"); - - if (msg_pool == ODP_BUFFER_POOL_INVALID) { - EXAMPLE_ERR(" [%i] msg_pool not found\n", thr); - return NULL; - } - - odp_barrier_wait(&test_barrier); - - test_abs_timeouts(thr, args); - - - printf("Thread %i exits\n", thr); - fflush(NULL); - return NULL; -} - - -/** - * @internal Print help - */ -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"); -} - - -/** - * @internal Parse arguments - * - * @param argc Argument count - * @param argv Argument vector - * @param args Test arguments - */ -static void parse_args(int argc, char *argv[], test_args_t *args) -{ - int opt; - int long_index; - - static struct option longopts[] = { - {"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 = 10000000; - args->period_us = 1000000; - args->tmo_count = 30; - - while (1) { - opt = getopt_long(argc, argv, "+c:r:m:x:p:t:h", - longopts, &long_index); - - if (opt == -1) - break; /* No more options */ - - switch (opt) { - 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); - break; - - default: - break; - } - } -} - - -/** - * Test main function - */ -int main(int argc, char *argv[]) -{ - odph_linux_pthread_t thread_tbl[MAX_WORKERS]; - test_args_t args; - int num_workers; - odp_buffer_pool_t pool; - void *pool_base; - odp_queue_t queue; - int first_core; - uint64_t cycles, ns; - odp_queue_param_t param; - odp_shm_t shm; - - printf("\nODP timer example starts\n"); - - memset(&args, 0, sizeof(args)); - parse_args(argc, argv, &args); - - memset(thread_tbl, 0, sizeof(thread_tbl)); - - if (odp_init_global(NULL, NULL)) { - printf("ODP global init failed.\n"); - return -1; - } - - /* Init this thread. */ - if (odp_init_local()) { - printf("ODP local init failed.\n"); - return -1; - } - - printf("\n"); - printf("ODP system info\n"); - printf("---------------\n"); - printf("ODP API version: %s\n", odp_version_api_str()); - printf("CPU model: %s\n", odp_sys_cpu_model_str()); - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); - printf("Cache line size: %i\n", odp_sys_cache_line_size()); - printf("Max core count: %i\n", odp_sys_core_count()); - - printf("\n"); - - /* A worker thread per core */ - num_workers = odp_sys_core_count(); - - if (args.core_count) - num_workers = args.core_count; - - /* force to max core count */ - if (num_workers > MAX_WORKERS) - num_workers = MAX_WORKERS; - - printf("num worker threads: %i\n", num_workers); - - /* - * By default core #0 runs Linux kernel background tasks. - * Start mapping thread from core #1 - */ - first_core = 1; - - if (odp_sys_core_count() == 1) - 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); - - /* - * Create message pool - */ - shm = odp_shm_reserve("msg_pool", - MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); - - pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, - 0, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_TIMEOUT); - - if (pool == ODP_BUFFER_POOL_INVALID) { - EXAMPLE_ERR("Pool create failed.\n"); - return -1; - } - - /* - * Create a queue for timer test - */ - memset(¶m, 0, sizeof(param)); - param.sched.prio = ODP_SCHED_PRIO_DEFAULT; - param.sched.sync = ODP_SCHED_SYNC_NONE; - param.sched.group = ODP_SCHED_GROUP_DEFAULT; - - queue = odp_queue_create("timer_queue", ODP_QUEUE_TYPE_SCHED, ¶m); - - if (queue == ODP_QUEUE_INVALID) { - EXAMPLE_ERR("Timer queue create failed.\n"); - return -1; - } - - test_timer = odp_timer_create("test_timer", pool, - args.resolution_us*ODP_TIME_USEC, - args.min_us*ODP_TIME_USEC, - args.max_us*ODP_TIME_USEC); - - if (test_timer == ODP_TIMER_INVALID) { - EXAMPLE_ERR("Timer create failed.\n"); - return -1; - } - - - odp_shm_print_all(); - - printf("CPU freq %"PRIu64" hz\n", odp_sys_cpu_hz()); - printf("Cycles vs nanoseconds:\n"); - ns = 0; - cycles = odp_time_ns_to_cycles(ns); - - printf(" %12"PRIu64" ns -> %12"PRIu64" cycles\n", ns, cycles); - printf(" %12"PRIu64" cycles -> %12"PRIu64" ns\n", cycles, - odp_time_cycles_to_ns(cycles)); - - for (ns = 1; ns <= 100*ODP_TIME_SEC; ns *= 10) { - cycles = odp_time_ns_to_cycles(ns); - - printf(" %12"PRIu64" ns -> %12"PRIu64" cycles\n", ns, - cycles); - printf(" %12"PRIu64" cycles -> %12"PRIu64" ns\n", cycles, - odp_time_cycles_to_ns(cycles)); - } - - printf("\n"); - - /* Barrier to sync test case execution */ - odp_barrier_init(&test_barrier, num_workers); - - /* Create and launch worker threads */ - odph_linux_pthread_create(thread_tbl, num_workers, first_core, - run_thread, &args); - - /* Wait for worker threads to exit */ - odph_linux_pthread_join(thread_tbl, num_workers); - - printf("ODP timer test complete\n\n"); - - return 0; -}