From patchwork Tue Aug 25 14:39:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 52673 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 9872C22E8F for ; Tue, 25 Aug 2015 14:39:52 +0000 (UTC) Received: by lbbpd10 with SMTP id pd10sf52037207lbb.3 for ; Tue, 25 Aug 2015 07:39:51 -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=OjJ0/fvsMDUPvVeNlhcTPAho1CJbTNROO4wlaTKpFL4=; b=J1aDrqSATobf25LgNQnNDLBad7l+FdhmfoM+u6ACbWLZFrB6V/WbRaMY9FwgOaLPmj YO1r16emw1OxucZKMunoETjjAhvOtK9E8aD1v0bEZyQHQ5dOVlQMywDneYng2cIlfBQP eu8QDj+0nFM8nYExTz7vjqlfmVpSJw8wmRFRDA+pI1OF4/IgSDOJTMWNYZJFmCbBxxHp RiEoCQSVFpaw3SuDVtEPEHq4n9hX1Gq+7XAnvJvFn2hp9I3YGDv3uXVJ+mcPAMi81oaa 8uk1+g/wwtUPN3gR6sNlfdj3edBs+It0f8/qSDWy1k0slrHMKboOqf+eyaOQOK2nofPU NpIQ== X-Gm-Message-State: ALoCoQln6HfWHnefQU/3ey4YkP5BtFIwPkDDSqWxv8Exi9odXc2ssBoGaxHrCBzbxGi+nBCNMenp X-Received: by 10.112.54.166 with SMTP id k6mr8519034lbp.0.1440513591567; Tue, 25 Aug 2015 07:39:51 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.227 with SMTP id n3ls738051lan.0.gmail; Tue, 25 Aug 2015 07:39:51 -0700 (PDT) X-Received: by 10.112.170.129 with SMTP id am1mr26268872lbc.116.1440513591403; Tue, 25 Aug 2015 07:39:51 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id w9si16168686laj.54.2015.08.25.07.39.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Aug 2015 07:39:51 -0700 (PDT) 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 lbbsx3 with SMTP id sx3so101100916lbb.0 for ; Tue, 25 Aug 2015 07:39:51 -0700 (PDT) X-Received: by 10.152.42.132 with SMTP id o4mr2096187lal.88.1440513591245; Tue, 25 Aug 2015 07:39:51 -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 yc8csp3224446lbb; Tue, 25 Aug 2015 07:39:49 -0700 (PDT) X-Received: by 10.50.79.167 with SMTP id k7mr3015416igx.28.1440513589384; Tue, 25 Aug 2015 07:39:49 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k6si1163565igx.41.2015.08.25.07.39.48; Tue, 25 Aug 2015 07:39:49 -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 233F961F0F; Tue, 25 Aug 2015 14:39:48 +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 A60F461F04; Tue, 25 Aug 2015 14:39:39 +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 4635F61F07; Tue, 25 Aug 2015 14:39:38 +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 EB08861F02 for ; Tue, 25 Aug 2015 14:39:32 +0000 (UTC) Received: by lbbpu9 with SMTP id pu9so101192863lbb.3 for ; Tue, 25 Aug 2015 07:39:31 -0700 (PDT) X-Received: by 10.112.63.138 with SMTP id g10mr11083977lbs.106.1440513571645; Tue, 25 Aug 2015 07:39:31 -0700 (PDT) Received: from elxahtkds32.localdomain (host-95-192-36-92.mobileonline.telia.com. [95.192.36.92]) by smtp.gmail.com with ESMTPSA id lb8sm6010775lab.16.2015.08.25.07.39.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Aug 2015 07:39:31 -0700 (PDT) From: "Balakrishna.Garapati" To: stuart.haslam@linaro.org, maxim.uvarov@linaro.org Date: Tue, 25 Aug 2015 16:39:21 +0200 Message-Id: <1440513561-7717-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] [PATCHv7] example:generator:move verbose from worker to control 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.178 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 --- v5:Fixed race condition with workers removed print infor for UDP mode removed send, receive print info from send thread removed hard coded num_workers = 1 for ping mode introduced condtion check for ping mode for receive thread to exit v6: moved prev_pkt = pkts to if condition. v7: Fixed num_workers = 2 in PING mode to break infinite loop in print_global_stats example/generator/odp_generator.c | 105 ++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index f9f219d..601cf94 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -102,6 +102,7 @@ static void usage(char *progname); static int scan_ip(char *buf, unsigned int *paddr); static int scan_mac(char *in, odph_ethaddr_t *des); static void tv_sub(struct timeval *recvtime, struct timeval *sendtime); +static void print_global_stats(int num_workers); /** * Sleep for the specified amount of milliseconds @@ -372,7 +373,6 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) static void *gen_send_thread(void *arg) { int thr; - uint64_t start, now, diff; odp_pktio_t pktio; thread_args_t *thr_args; odp_queue_t outq_def; @@ -394,7 +394,6 @@ static void *gen_send_thread(void *arg) return NULL; } - start = odp_time_cycles(); printf(" [%02i] created mode: SEND\n", thr); for (;;) { int err; @@ -435,15 +434,6 @@ static void *gen_send_thread(void *arg) >= (unsigned int)args->appl.number) { break; } - - now = odp_time_cycles(); - diff = odp_time_diff_cycles(start, now); - if (odp_time_cycles_to_ns(diff) > 20 * ODP_TIME_SEC) { - start = odp_time_cycles(); - printf(" [%02i] total send: %ju\n", - thr, odp_atomic_load_u64(&counters.seq)); - fflush(stdout); - } } /* receive number of reply pks until timeout */ @@ -461,15 +451,6 @@ static void *gen_send_thread(void *arg) } } - /* print info */ - if (args->appl.mode == APPL_MODE_UDP) { - printf(" [%02i] total send: %ju\n", - thr, odp_atomic_load_u64(&counters.seq)); - } else if (args->appl.mode == APPL_MODE_PING) { - printf(" [%02i] total send: %ju total receive: %ju\n", - thr, odp_atomic_load_u64(&counters.seq), - odp_atomic_load_u64(&counters.icmp)); - } return arg; } @@ -485,7 +466,6 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) odp_packet_t pkt; char *buf; odph_ipv4hdr_t *ip; - odph_udphdr_t *udp; odph_icmphdr_t *icmp; struct timeval tvrecv; struct timeval tvsend; @@ -503,20 +483,13 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) continue; odp_atomic_inc_u64(&counters.ip); - rlen += sprintf(msg, "receive Packet proto:IP "); buf = odp_packet_data(pkt); ip = (odph_ipv4hdr_t *)(buf + odp_packet_l3_offset(pkt)); - rlen += sprintf(msg + rlen, "id %d ", - odp_be_to_cpu_16(ip->id)); offset = odp_packet_l4_offset(pkt); /* udp */ if (ip->proto == ODPH_IPPROTO_UDP) { odp_atomic_inc_u64(&counters.udp); - udp = (odph_udphdr_t *)(buf + offset); - rlen += sprintf(msg + rlen, "UDP payload %d ", - odp_be_to_cpu_16(udp->length) - - ODPH_UDPHDR_LEN); } /* icmp */ @@ -540,10 +513,10 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) rlen += sprintf(msg + rlen, "Icmp Echo Request"); } - } - msg[rlen] = '\0'; - printf(" [%02i] %s\n", thr, msg); + msg[rlen] = '\0'; + printf(" [%02i] %s\n", thr, msg); + } } } @@ -573,6 +546,12 @@ static void *gen_recv_thread(void *arg) printf(" [%02i] created mode: RECEIVE\n", thr); for (;;) { + if (args->appl.number != -1 && + odp_atomic_load_u64(&counters.icmp) >= + (unsigned int)args->appl.number) { + break; + } + /* Use schedule to get buf from any input queue */ ev = odp_schedule(NULL, ODP_SCHED_WAIT); @@ -590,6 +569,64 @@ static void *gen_recv_thread(void *arg) return arg; } + +/** + * printing verbose statistics + * + */ +static void print_global_stats(int num_workers) +{ + uint64_t start, now, diff; + uint64_t pkts, pkts_prev = 0, pps, maximum_pps = 0; + int verbose_interval = 20; + odp_thrmask_t thrd_mask; + + while (odp_thrmask_worker(&thrd_mask) < num_workers) + continue; + + start = odp_time_cycles(); + + while (odp_thrmask_worker(&thrd_mask) == num_workers) { + if (args->appl.number != -1 && + odp_atomic_load_u64(&counters.seq) >= + (unsigned int)args->appl.number) { + break; + } + + now = odp_time_cycles(); + diff = odp_time_diff_cycles(start, now); + if (odp_time_cycles_to_ns(diff) < + verbose_interval * ODP_TIME_SEC) { + continue; + } + + start = odp_time_cycles(); + + if (args->appl.mode == APPL_MODE_RCV) { + pkts = odp_atomic_load_u64(&counters.udp); + printf(" total receive(UDP: %" PRIu64 ")\n", pkts); + continue; + } + + if (args->appl.mode == APPL_MODE_PING) { + pkts = odp_atomic_load_u64(&counters.icmp); + printf(" total receive(ICMP: %" PRIu64 ")\n", pkts); + } + + pkts = odp_atomic_load_u64(&counters.seq); + printf(" total sent: %" PRIu64 "\n", pkts); + + if (args->appl.mode == APPL_MODE_UDP) { + pps = (pkts - pkts_prev) / verbose_interval; + if (pps > maximum_pps) + maximum_pps = pps; + printf(" %" PRIu64 " pps, %" PRIu64 " max pps\n", + pps, maximum_pps); + pkts_prev = pkts; + } + } +} + /** * ODP packet example main function */ @@ -663,6 +700,8 @@ int main(int argc, char *argv[]) if (num_workers < 2) { EXAMPLE_ERR("Need at least two worker threads\n"); exit(EXIT_FAILURE); + } else { + num_workers = 2; } } @@ -758,8 +797,6 @@ int main(int argc, char *argv[]) odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, gen_send_thread, &args->thread[0]); - /* only wait send thread to join */ - num_workers = 1; } else { int cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { @@ -809,6 +846,8 @@ int main(int argc, char *argv[]) } } + print_global_stats(num_workers); + /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers);