From patchwork Mon Aug 18 07:41:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shukla X-Patchwork-Id: 35480 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 50CB020676 for ; Mon, 18 Aug 2014 07:41:56 +0000 (UTC) Received: by mail-oi0-f72.google.com with SMTP id a141sf29181683oig.11 for ; Mon, 18 Aug 2014 00:41:55 -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=Xe0qVxgvo+Oy0dS8KNKks3Y8x65lbAAr5h9VSEWR6LY=; b=SU5VrqiUUyG6oV+Byb3XxNmuwo3AvVLHJ6Q2OEFy5dc7VwPDnMJh7vAyeN3E+zY1F/ OZd4twe5VLAUlMtmscMZDi/6A8KHkVOzQFXH3M+5wqwJxscxT0aEd0Hy/unW/cal07eY HzNWrLlOUhoTD1kShFgXT75Zakim9XNQTsufWv24Ww8J1yvFUrU7RSdwzccKJ51O6CDZ In6SbLajZ6YV8gt55oFyEHRyGNprBMU9yc07xrr3Z0i0FGKQ31rrpXFrsQcATh3A7rLw TC4usOOUPC50HOGxM0Z3HZFfi3YRzPm1M5eDbPzwKu+Dc0pegS8zFYsWdQ7WZaRwef7z fYfw== X-Gm-Message-State: ALoCoQkVxqCJiUuCxZzNT13lLYa2UwlRd1cFKovg+7uk/zaFPzLejZBTrqf4qT+xxPiWaWte0Em8 X-Received: by 10.182.171.67 with SMTP id as3mr17635262obc.34.1408347715932; Mon, 18 Aug 2014 00:41:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.106 with SMTP id 97ls2258985qgq.26.gmail; Mon, 18 Aug 2014 00:41:55 -0700 (PDT) X-Received: by 10.220.182.1 with SMTP id ca1mr23808388vcb.21.1408347715814; Mon, 18 Aug 2014 00:41:55 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id h13si6920047vdj.81.2014.08.18.00.41.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 00:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so5394247vcb.11 for ; Mon, 18 Aug 2014 00:41:55 -0700 (PDT) X-Received: by 10.53.12.225 with SMTP id et1mr24698136vdd.5.1408347715662; Mon, 18 Aug 2014 00:41:55 -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.37.5 with SMTP id tc5csp131471vcb; Mon, 18 Aug 2014 00:41:55 -0700 (PDT) X-Received: by 10.224.168.13 with SMTP id s13mr53823656qay.80.1408347714861; Mon, 18 Aug 2014 00:41:54 -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 cc7si23051395qcb.14.2014.08.18.00.41.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 18 Aug 2014 00:41:54 -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 1XJHZf-0002vn-2R; Mon, 18 Aug 2014 07:41:51 +0000 Received: from mail-pd0-f173.google.com ([209.85.192.173]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XJHZZ-0002vi-CA for lng-odp@lists.linaro.org; Mon, 18 Aug 2014 07:41:45 +0000 Received: by mail-pd0-f173.google.com with SMTP id w10so7056833pde.4 for ; Mon, 18 Aug 2014 00:41:39 -0700 (PDT) X-Received: by 10.68.114.65 with SMTP id je1mr33212356pbb.124.1408347697955; Mon, 18 Aug 2014 00:41:37 -0700 (PDT) Received: from santosh-Latitude-E5530-non-vPro.mvista.com ([111.93.218.67]) by mx.google.com with ESMTPSA id da14sm55994855pac.24.2014.08.18.00.41.34 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 00:41:36 -0700 (PDT) From: Santosh Shukla To: lng-odp@lists.linaro.org Date: Mon, 18 Aug 2014 13:11:00 +0530 Message-Id: <1408347660-22842-1-git-send-email-santosh.shukla@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] isolation : initial odp isolation example app 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: santosh.shukla@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.180 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 Test application to run odp dummy dp thread on no_hz_full kernel mode for few seconds. - Create 2 threads, running in loop for few seconds. - Mask timer thread. Signed-off-by: Santosh Shukla --- Note : - Patch set based on Maxim's v2 patch under discussion "implement-odp_init_global-init-mask.patch" - Open for review feedback however wont merge due above dependancy. - More isolation specific changes seen at https://git.linaro.org/people/santosh.shukla/odp.git configure.ac | 1 + example/Makefile.am | 2 +- example/isolation/Makefile.am | 5 + example/isolation/odp_isolation.c | 232 +++++++++++++++++++++++++++++++++++++ 4 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 example/isolation/Makefile.am create mode 100644 example/isolation/odp_isolation.c diff --git a/configure.ac b/configure.ac index 74713a7..2b6758b 100644 --- a/configure.ac +++ b/configure.ac @@ -142,6 +142,7 @@ AC_CONFIG_FILES([Makefile example/packet/Makefile example/packet_netmap/Makefile example/timer/Makefile + example/isolation/Makefile test/Makefile test/api_test/Makefile pkgconfig/libodp.pc]) diff --git a/example/Makefile.am b/example/Makefile.am index 01a3305..4cb4a23 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1 +1 @@ -SUBDIRS = generator l2fwd odp_example packet packet_netmap timer +SUBDIRS = generator l2fwd odp_example packet packet_netmap timer isolation diff --git a/example/isolation/Makefile.am b/example/isolation/Makefile.am new file mode 100644 index 0000000..7e39773 --- /dev/null +++ b/example/isolation/Makefile.am @@ -0,0 +1,5 @@ +include $(top_srcdir)/example/Makefile.inc + +bin_PROGRAMS = odp_isolation + +dist_odp_isolation_SOURCES = odp_isolation.c diff --git a/example/isolation/odp_isolation.c b/example/isolation/odp_isolation.c new file mode 100644 index 0000000..8d8fffc --- /dev/null +++ b/example/isolation/odp_isolation.c @@ -0,0 +1,232 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * @example odp_isol_test.c ODP isolation example application + */ + +#include +#include + +/* ODP main header */ +#include + +/* ODP helper for Linux apps */ +#include + +/* GNU lib C */ +#include + +#define MAX_WORKERS 32 /**< Max worker threads */ + +/** + * Parsed command line application arguments + */ +typedef struct { + int core_count; /**< Core count*/ + char **core_name; /**< Array of pointers to core name */ +} appl_args_t; + +/** + * @internal Print help + */ +static void print_usage(void) +{ + printf("\n\nUsage: ./odp_isolation [options]\n"); + printf("Options:\n"); + printf(" -l, --cpulist \n"); + printf(" -h, --help this help\n"); + printf("\n\n"); +} + +/** + * @internal Worker thread + * + * @param arg Arguments + * + * @return NULL on failure + */ +static void *run_thread(void *arg) +{ + int thr; + unsigned long long tick = 0; + int counter = 0; + + thr = odp_thread_id(); + + printf("Thread %i starts on core %i\n", thr, odp_thread_core()); + + /* loop for some duration then exit */ + do { + tick++; + + if (tick > 10000000) { + + tick = 0; + counter++; + } + + if (counter == 1000) + break; + } while (1); + + return arg; +} + +/** + * @internal Parse arguments + * + * @param argc Argument count + * @param argv Argument vector + * @param args Test arguments + */ +static void parse_args(int argc, char *argv[], appl_args_t *args) +{ + int opt; + int long_index; + char *names, *str, *token, *save; + size_t len; + int i; + + static struct option longopts[] = { + {"cpulists", required_argument, NULL, 'l'}, /* return 'l' */ + {"help", no_argument, NULL, 'h'}, /* return 'h' */ + {NULL, 0, NULL, 0} + }; + + while (1) { + opt = getopt_long(argc, argv, "+l:h", longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + case 'l': + len = strlen(optarg); + if (len == 0) { + print_usage(); + exit(EXIT_FAILURE); + } + len += 1; /* add room for '\0' */ + + names = malloc(len); + if (names == NULL) { + print_usage(); + exit(EXIT_FAILURE); + } + + /* count the number of tokens separated by ',' */ + strcpy(names, optarg); + for (str = names, i = 0;; str = NULL, i++) { + token = strtok_r(str, ",", &save); + if (token == NULL) + break; + } + args->core_count = i; + + if (args->core_count == 0) { + print_usage(); + exit(EXIT_FAILURE); + } + /* allocate storage for the if names */ + args->core_name = + calloc(args->core_count, sizeof(char *)); + + /* store the if names (reset names string) */ + strcpy(names, optarg); + for (str = names, i = 0;; str = NULL, i++) { + token = strtok_r(str, ",", &save); + if (token == NULL) + break; + args->core_name[i] = token; + } + break; + + case 'h': + print_usage(); + exit(EXIT_SUCCESS); + break; + + default: + break; + } + } +} + +/** + * Isolation test application + */ +int main(int argc, char *argv[]) +{ + odp_linux_pthread_t thread_tbl[MAX_WORKERS]; + appl_args_t args; + int thr_id; + int num_workers; + int first_core; + int i; + + printf("\nODP isolation test application\n"); + + memset(&args, 0, sizeof(args)); + parse_args(argc, argv, &args); + + memset(thread_tbl, 0, sizeof(thread_tbl)); + + /* + * Don't need timer init for isolation, so mask them. + */ + if (odp_init_global(ODP_INIT_F_ALL & ~ODP_INIT_F_TIMER)) { + printf("ODP global 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); + + /* + * Init this thread. + * */ + thr_id = odp_thread_create(0); + odp_init_local(thr_id); + + for (i=0; i