From patchwork Wed Aug 19 11:12:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 52539 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id A2649218CB for ; Wed, 19 Aug 2015 11:13:05 +0000 (UTC) Received: by lbbpd10 with SMTP id pd10sf418759lbb.3 for ; Wed, 19 Aug 2015 04:13:04 -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:cc: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=WCKeawqW3jk7S5Kmoj3ujdQd2+ohiyiNe6rDHljqcbo=; b=S/mYJQ3YocBHy0xOld/5kSl1lAPq3EN61VXrDkz+tnnO8JLGQuyR/lqkMmIC3xcrwc 0vRjV9xyEX1rn7liNLHCLhg4e+nJJvhY5XQ4GhMZBFdNcta/r5eUDtOd8osn/DPPJu0S VrkpSUZbOV7/ajotDnYa7QklWas1hX1XQzLz1JWy+0RjMU7+gWx5JclYZLavNb3LzVi5 KMZoGoP1ZFm9jwf8bsjN3kU076WmftsVP8ky5anKBn/YX0WH3yKL2/v9+tzdNC1HQkHy cEG1b1Nb0bQ7vJ9pQE77LuQRBq2Ex4vS3g6eyBiNfkt+QYofF8Wkx0W5/FnW5R2P0rQV pbwQ== X-Gm-Message-State: ALoCoQkZyWEdHsvwdY0eax55RaDJZvMzSFlvkDSNN18vhxkUI9K3IOvzpKFrxiRDbit14nYt9utW X-Received: by 10.152.6.103 with SMTP id z7mr3151677laz.8.1439982784587; Wed, 19 Aug 2015 04:13:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.166 with SMTP id n6ls12749laf.86.gmail; Wed, 19 Aug 2015 04:13:04 -0700 (PDT) X-Received: by 10.112.199.5 with SMTP id jg5mr2313281lbc.57.1439982784309; Wed, 19 Aug 2015 04:13:04 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id ao2si251426lac.69.2015.08.19.04.13.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Aug 2015 04:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbsx3 with SMTP id sx3so843772lbb.0 for ; Wed, 19 Aug 2015 04:13:04 -0700 (PDT) X-Received: by 10.152.28.193 with SMTP id d1mr10738965lah.72.1439982784069; Wed, 19 Aug 2015 04:13:04 -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.162.200 with SMTP id yc8csp294804lbb; Wed, 19 Aug 2015 04:13:02 -0700 (PDT) X-Received: by 10.50.136.134 with SMTP id qa6mr950762igb.13.1439982781615; Wed, 19 Aug 2015 04:13:01 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g99si402472iod.173.2015.08.19.04.13.00; Wed, 19 Aug 2015 04:13:01 -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 8BB0C61F6A; Wed, 19 Aug 2015 11:13:00 +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 9A63B61B1D; Wed, 19 Aug 2015 11:12:54 +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 9468061E41; Wed, 19 Aug 2015 11:12:52 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id 46FCD61840 for ; Wed, 19 Aug 2015 11:12:51 +0000 (UTC) Received: by lbcbn3 with SMTP id bn3so817667lbc.2 for ; Wed, 19 Aug 2015 04:12:50 -0700 (PDT) X-Received: by 10.152.5.40 with SMTP id p8mr10855777lap.10.1439982770177; Wed, 19 Aug 2015 04:12:50 -0700 (PDT) Received: from elxahtkds32.localdomain (host-95-192-103-42.mobileonline.telia.com. [95.192.103.42]) by smtp.gmail.com with ESMTPSA id lb5sm108063lbc.45.2015.08.19.04.12.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Aug 2015 04:12:49 -0700 (PDT) From: "Balakrishna.Garapati" To: stuart.haslam@linaro.org, maxim.uvarov@linaro.org Date: Wed, 19 Aug 2015 13:12:44 +0200 Message-Id: <1439982764-27781-1-git-send-email-balakrishna.garapati@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCHv9] example:generator:option to supply core mask 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: balakrishna.garapati@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.169 as permitted sender) smtp.mailfrom=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 Signed-off-by: Balakrishna.Garapati Reviewed-by: Stuart Haslam --- v8: Ignore this patch as the chnages were not included by mistake. v9: moved optional args from MANDATORY to OPTIONAL options fixed the comment section "core mask" to "CPU maski". example/generator/odp_generator.c | 80 +++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index bdee222..f398aaf 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -43,6 +43,7 @@ */ typedef struct { int cpu_count; /**< system CPU count */ + const char *mask; /**< CPU mask */ int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ char *if_str; /**< Storage for interface names */ @@ -645,18 +646,26 @@ int main(int argc, char *argv[]) if (args->appl.cpu_count) num_workers = args->appl.cpu_count; - /* ping mode need two worker */ - if (args->appl.mode == APPL_MODE_PING) - num_workers = 2; - - /* Get default worker cpumask */ num_workers = odp_cpumask_def_worker(&cpumask, num_workers); + if (args->appl.mask) { + odp_cpumask_from_str(&cpumask, args->appl.mask); + num_workers = odp_cpumask_count(&cpumask); + } + (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); + /* ping mode need two workers */ + if (args->appl.mode == APPL_MODE_PING) { + if (num_workers < 2) { + EXAMPLE_ERR("Need at least two worker threads\n"); + exit(EXIT_FAILURE); + } + } + /* Create packet pool */ memset(¶ms, 0, sizeof(params)); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; @@ -704,12 +713,13 @@ int main(int argc, char *argv[]) memset(thread_tbl, 0, sizeof(thread_tbl)); if (args->appl.mode == APPL_MODE_PING) { - odp_cpumask_t cpu0_mask; + odp_cpumask_t cpu_mask; odp_queue_t tq; + int cpu_first, cpu_next; - /* Previous code forced both threads to CPU 0 */ - odp_cpumask_zero(&cpu0_mask); - odp_cpumask_set(&cpu0_mask, 0); + odp_cpumask_zero(&cpu_mask); + cpu_first = odp_cpumask_first(&cpumask); + odp_cpumask_set(&cpu_mask, cpu_first); tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); if (tq == ODP_QUEUE_INVALID) @@ -725,7 +735,7 @@ int main(int argc, char *argv[]) if (args->thread[1].tmo_ev == ODP_TIMEOUT_INVALID) abort(); args->thread[1].mode = args->appl.mode; - odph_linux_pthread_create(&thread_tbl[1], &cpu0_mask, + odph_linux_pthread_create(&thread_tbl[1], &cpu_mask, gen_recv_thread, &args->thread[1]); tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); @@ -742,7 +752,10 @@ int main(int argc, char *argv[]) if (args->thread[0].tmo_ev == ODP_TIMEOUT_INVALID) abort(); args->thread[0].mode = args->appl.mode; - odph_linux_pthread_create(&thread_tbl[0], &cpu0_mask, + cpu_next = odp_cpumask_next(&cpumask, cpu_first); + odp_cpumask_zero(&cpu_mask); + odp_cpumask_set(&cpu_mask, cpu_next); + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, gen_send_thread, &args->thread[0]); /* only wait send thread to join */ @@ -820,15 +833,17 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) int long_index; char *token; size_t len; - int i; + odp_cpumask_t cpumask, cpumask_args, cpumask_and; + int i, num_workers; static struct option longopts[] = { {"interface", required_argument, NULL, 'I'}, {"workers", required_argument, NULL, 'w'}, + {"cpumask", required_argument, NULL, 'c'}, {"srcmac", required_argument, NULL, 'a'}, {"dstmac", required_argument, NULL, 'b'}, - {"srcip", required_argument, NULL, 'c'}, + {"srcip", required_argument, NULL, 's'}, {"dstip", required_argument, NULL, 'd'}, - {"packetsize", required_argument, NULL, 's'}, + {"packetsize", required_argument, NULL, 'p'}, {"mode", required_argument, NULL, 'm'}, {"count", required_argument, NULL, 'n'}, {"timeout", required_argument, NULL, 't'}, @@ -843,8 +858,8 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) appl_args->timeout = -1; while (1) { - opt = getopt_long(argc, argv, "+I:a:b:c:d:s:i:m:n:t:w:h", - longopts, &long_index); + opt = getopt_long(argc, argv, "+I:a:b:s:d:p:i:m:n:t:w:c:h", + longopts, &long_index); if (opt == -1) break; /* No more options */ @@ -852,6 +867,18 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'w': appl_args->cpu_count = atoi(optarg); break; + case 'c': + appl_args->mask = optarg; + odp_cpumask_from_str(&cpumask_args, args->appl.mask); + num_workers = odp_cpumask_def_worker(&cpumask, 0); + odp_cpumask_and(&cpumask_and, &cpumask_args, &cpumask); + if (odp_cpumask_count(&cpumask_and) < + odp_cpumask_count(&cpumask_args)) { + EXAMPLE_ERR("Wrong cpu mask, max cpu's:%d\n", + num_workers); + exit(EXIT_FAILURE); + } + break; /* parse packet-io interface names */ case 'I': len = strlen(optarg); @@ -920,7 +947,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) } break; - case 'c': + case 's': if (scan_ip(optarg, &appl_args->srcip) != 1) { EXAMPLE_ERR("wrong src ip:%s\n", optarg); exit(EXIT_FAILURE); @@ -934,7 +961,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) } break; - case 's': + case 'p': appl_args->payload = atoi(optarg); break; @@ -1027,20 +1054,15 @@ static void usage(char *progname) " 2.receive udp packets\n" " odp_generator -I eth0 -m r\n" " 3.work likes ping\n" - " odp_generator -I eth0 --srcmac fe:0f:97:c9:e0:44 --dstmac 32:cb:9b:27:2f:1a --srcip 192.168.0.1 --dstip 192.168.0.2 -m p\n" + " odp_generator -I eth0 --srcmac fe:0f:97:c9:e0:44 --dstmac 32:cb:9b:27:2f:1a --srcip 192.168.0.1 --dstip 192.168.0.2 --cpumask 0xc -m p\n" "\n" "Mandatory OPTIONS:\n" " -I, --interface Eth interfaces (comma-separated, no spaces)\n" " -a, --srcmac src mac address\n" " -b, --dstmac dst mac address\n" - " -c, --srcip src ip address\n" + " -s, --srcip src ip address\n" " -d, --dstip dst ip address\n" - " -s, --packetsize payload length of the packets\n" " -m, --mode work mode: send udp(u), receive(r), send icmp(p)\n" - " -n, --count the number of packets to be send\n" - " -t, --timeout only for ping mode, wait ICMP reply timeout seconds\n" - " -i, --interval wait interval ms between sending each packet\n" - " default is 1000ms. 0 for flood mode\n" "\n" "Optional OPTIONS\n" " -h, --help Display help and exit.\n" @@ -1048,6 +1070,14 @@ static void usage(char *progname) " ODP_PKTIO_DISABLE_SOCKET_MMSG\n" " ODP_PKTIO_DISABLE_SOCKET_BASIC\n" " can be used to advanced pkt I/O selection for linux-generic\n" + " -p, --packetsize payload length of the packets\n" + " -t, --timeout only for ping mode, wait ICMP reply timeout seconds\n" + " -i, --interval wait interval ms between sending each packet\n" + " default is 1000ms. 0 for flood mode\n" + " -w, --workers specify number of workers need to be assigned to application\n" + " default is to assign all\n" + " -n, --count the number of packets to be send\n" + " -c, --cpumask to set on cores\n" "\n", NO_PATH(progname), NO_PATH(progname) ); }