From patchwork Wed May 11 16:41:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 67563 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp295717qge; Wed, 11 May 2016 08:50:29 -0700 (PDT) X-Received: by 10.140.103.237 with SMTP id y100mr4346706qge.60.1462981829677; Wed, 11 May 2016 08:50:29 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y133si5604864qha.49.2016.05.11.08.50.29; Wed, 11 May 2016 08:50:29 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0ED796164F; Wed, 11 May 2016 15:50:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 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 [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id DE6006164A; Wed, 11 May 2016 15:45:35 +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 6E66C6164A; Wed, 11 May 2016 15:45:31 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id C22626164C for ; Wed, 11 May 2016 15:44:13 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id m64so53855526lfd.1 for ; Wed, 11 May 2016 08:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IJgXB8MK0u9G1yW4z3n5C55DPE0ZyOGHEtB2uwoQJlM=; b=GKebBi2QsPFFAbCM1gq8XjuVhtH69tKoQoquGaqaZN3MklrjJ3jVhQBZwc6CO7oJ3l 1tvhEA8MHxcN9ABauE+vROskbBzFvnkd2iRqYuAlZf124W2MQ7ZEAMcC+P7xrjQXLcL+ GsPn92LYTlHi5PkmLFNfPvqFq5UC73f7MOqWJKEP5wsZz8XaLMRdYdvz4jxz3QSMlLLo zKIRB+0fXzFPuAe6hAtnLskQkXT12diGFAM1EMxve84pyMCfwyj+5RhagLGgYMWyNFIn oiQSOENpZasj+cnLK1lhgD1Djs0oWQuIcgAnhzJqI3LsEMvzxN4A4kUtwhHGM+0KPhjd Ui4Q== X-Gm-Message-State: AOPr4FW4AYEEupLphZrhaF20cS5etDyzjROdHaFXcnaHBxwoDaUreBY+SIe3y60bLUFICMcJKtw= X-Received: by 10.112.95.114 with SMTP id dj18mr1945844lbb.136.1462981452557; Wed, 11 May 2016 08:44:12 -0700 (PDT) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id n37sm1421164lfg.46.2016.05.11.08.44.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 08:44:11 -0700 (PDT) From: Christophe Milard To: brian.brooks@linaro.org, mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 11 May 2016 18:41:50 +0200 Message-Id: <1462984942-53326-7-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> References: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv6 06/38] helper: test: adding odpthread functions tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Simple tests testing odph_odpthreads_create() and odph_odpthreads_join() are added. A single test binary, odpthreads, is added. This program creates odp threads as pthreads or linux processes, dependng on its calling args. Three calling scripts are added to create ODP threads as either processes, threads or both (mixed). Signed-off-by: Christophe Milard --- helper/test/.gitignore | 1 + helper/test/Makefile.am | 8 ++- helper/test/odpthreads.c | 100 ++++++++++++++++++++++++++++++++++++ helper/test/odpthreads_as_mixed | 15 ++++++ helper/test/odpthreads_as_processes | 15 ++++++ helper/test/odpthreads_as_pthreads | 15 ++++++ 6 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 helper/test/odpthreads.c create mode 100755 helper/test/odpthreads_as_mixed create mode 100755 helper/test/odpthreads_as_processes create mode 100755 helper/test/odpthreads_as_pthreads diff --git a/helper/test/.gitignore b/helper/test/.gitignore index e232753..5ce3c3b 100644 --- a/helper/test/.gitignore +++ b/helper/test/.gitignore @@ -1,6 +1,7 @@ *.trs *.log chksum +odpthreads parse process table diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am index 7f0b67d..4ec561b 100644 --- a/helper/test/Makefile.am +++ b/helper/test/Makefile.am @@ -11,9 +11,11 @@ EXECUTABLES = chksum$(EXEEXT) \ process$(EXEEXT)\ table$(EXEEXT) -COMPILE_ONLY = +COMPILE_ONLY = odpthreads -TESTSCRIPTS = +TESTSCRIPTS = odpthreads_as_mixed \ + odpthreads_as_processes \ + odpthreads_as_pthreads if test_helper TESTS = $(EXECUTABLES) $(TESTSCRIPTS) @@ -25,6 +27,8 @@ bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) dist_chksum_SOURCES = chksum.c +dist_odpthreads_SOURCES = odpthreads.c +odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la dist_thread_SOURCES = thread.c thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la dist_process_SOURCES = process.c diff --git a/helper/test/odpthreads.c b/helper/test/odpthreads.c new file mode 100644 index 0000000..369da62 --- /dev/null +++ b/helper/test/odpthreads.c @@ -0,0 +1,100 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * This program tests the ability of the linux helper to create ODP threads, + * either implemented as linux pthreads or as linux processes, depending on + * the option passed to the program (--odph_proc, --odph_thread or both) + */ + +#include +#include +#include + +#define NUMBER_WORKERS 16 +static int worker_fn(void *arg TEST_UNUSED) +{ + /* depend on the odp helper to call odp_init_local */ + + printf("Worker thread on CPU %d\n", odp_cpu_id()); + + /* depend on the odp helper to call odp_term_local */ + + return 0; +} + +/* Create additional dataplane opdthreads */ +int main(int argc, char *argv[]) +{ + odp_instance_t instance; + odph_odpthread_params_t thr_params; + odph_odpthread_t thread_tbl[NUMBER_WORKERS]; + odp_cpumask_t cpu_mask; + int num_workers; + int cpu; + int ret; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + + /* let helper collect its own arguments (e.g. --odph_proc) */ + odph_parse_options(argc, argv); + + if (odp_init_global(&instance, NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local(instance, ODP_THREAD_CONTROL)) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* discover how many opdthreads this system can support */ + num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); + if (num_workers < NUMBER_WORKERS) { + printf("System can only support %d threads and not the %d requested\n", + num_workers, NUMBER_WORKERS); + } + + /* generate a summary for the user */ + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("default cpu mask: %s\n", cpumaskstr); + printf("default num worker threads: %i\n", num_workers); + + cpu = odp_cpumask_first(&cpu_mask); + printf("the first CPU: %i\n", cpu); + + /* reserve cpu 0 for the control plane so remove it from + * the default mask */ + odp_cpumask_clr(&cpu_mask, 0); + num_workers = odp_cpumask_count(&cpu_mask); + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("new cpu mask: %s\n", cpumaskstr); + printf("new num worker threads: %i\n\n", num_workers); + + memset(&thr_params, 0, sizeof(thr_params)); + thr_params.start = worker_fn; + thr_params.arg = NULL; + thr_params.thr_type = ODP_THREAD_WORKER; + thr_params.instance = instance; + + odph_odpthreads_create(&thread_tbl[0], &cpu_mask, &thr_params); + + ret = odph_odpthreads_join(thread_tbl); + if (ret < 0) + exit(EXIT_FAILURE); + + if (odp_term_local()) { + LOG_ERR("Error: ODP local term failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_term_global(instance)) { + LOG_ERR("Error: ODP global term failed.\n"); + exit(EXIT_FAILURE); + } + + return 0; +} diff --git a/helper/test/odpthreads_as_mixed b/helper/test/odpthreads_as_mixed new file mode 100755 index 0000000..61fdad1 --- /dev/null +++ b/helper/test/odpthreads_as_mixed @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (c) 2016, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +PATH=$(dirname $0):$PATH +PATH=.:$PATH + +# when both "--odph_thread" and "--odph_process" are given, every second odp +# thread is created as a linux process. +odpthreads --odph_thread --odph_process + diff --git a/helper/test/odpthreads_as_processes b/helper/test/odpthreads_as_processes new file mode 100755 index 0000000..e3636fb --- /dev/null +++ b/helper/test/odpthreads_as_processes @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (c) 2016, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +PATH=$(dirname $0):$PATH +PATH=.:$PATH + +# The odpthreads test recognise the "--odph_process" option to create +# odp threads as linux process: +odpthreads --odph_process + diff --git a/helper/test/odpthreads_as_pthreads b/helper/test/odpthreads_as_pthreads new file mode 100755 index 0000000..3d1fe29 --- /dev/null +++ b/helper/test/odpthreads_as_pthreads @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (c) 2016, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +PATH=$(dirname $0):$PATH +PATH=.:$PATH + +# The odpthreads test recognise the "--odph_thread" option to create +# odp threads as linux pthreads: +odpthreads --odph_thread +