From patchwork Mon Apr 3 10:00:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 96606 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp23003qgd; Mon, 3 Apr 2017 03:01:55 -0700 (PDT) X-Received: by 10.200.45.137 with SMTP id p9mr15434554qta.201.1491213715329; Mon, 03 Apr 2017 03:01:55 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p26si11500547qtf.84.2017.04.03.03.01.53; Mon, 03 Apr 2017 03:01:55 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 7115263D0E; Mon, 3 Apr 2017 10:01:53 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 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 6AA7463D38; Mon, 3 Apr 2017 10:01:40 +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 C061B63D39; Mon, 3 Apr 2017 10:01:33 +0000 (UTC) Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) by lists.linaro.org (Postfix) with ESMTPS id 5BA7960AD0 for ; Mon, 3 Apr 2017 10:01:27 +0000 (UTC) Received: by mail-wr0-f181.google.com with SMTP id w43so161338481wrb.0 for ; Mon, 03 Apr 2017 03:01:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qj9KZlNIOO8ai0T68rBtxNQEYf0xZNlyVUF3KM9WlY0=; b=qp5CS9D0OuD9ceL0flC3BsXIv6/sNV7lXlk5hz1t3gvQFH3IP0Wjcb9w32hgTnAuCm o5HNppE9RnmsHyqulnmfs0vCfqP9b6AdHdW6Ul3cMDt+P4ejoVp35C5nSaheqbPzSfzf XT6UsNNIakERU3o+vOSdZLTYVQOkM09bi1hpVzoN8s7R5mwi35VJuywLXN1w3a5h5QTD HgjkYN86hp+v15rERy7v9Dqcn63kr0JhyEYaqlb1IaOGqt9Ik3buuTPSKQAQT9CxTpTV T1qcN1NlF1cCOcYOnEZlkpywVQuAsXYIbynJ0uV7gCygXRSzoPbtxz5FoBGWfL/suVo7 IIaQ== X-Gm-Message-State: AFeK/H1Y8BdfD9MqNGoFQcsjlBqiscPrJwcIaz5yVsNYbdnC4L01P3hD Gh4DCJBzTdsStQNUT44= X-Received: by 10.28.16.78 with SMTP id 75mr5346068wmq.24.1491213686252; Mon, 03 Apr 2017 03:01:26 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id 24sm17491194wrw.46.2017.04.03.03.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 03:01:25 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Mon, 3 Apr 2017 13:00:57 +0300 Message-Id: <1491213657-23183-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491213657-23183-1-git-send-email-bogdan.pricope@linaro.org> References: <1491213657-23183-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCH] test: generator: replace gettimeofday() with ODP API calls 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 89 ++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 48 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 95fb543..9c49d94 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -119,7 +119,6 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname); static int scan_ip(char *buf, unsigned int *paddr); -static void tv_sub(struct timeval *recvtime, struct timeval *sendtime); static void print_global_stats(int num_workers); /** @@ -348,7 +347,7 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) char *buf; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; - struct timeval tval; + uint64_t tval; uint8_t *tval_d; unsigned short seq; @@ -372,12 +371,12 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) /* icmp */ icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); icmp->un.echo.sequence = ip->id; + tval_d = (uint8_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ICMPHDR_LEN); - /* TODO This should be changed to use an - * ODP timer API once one exists. */ - gettimeofday(&tval, NULL); - memcpy(tval_d, &tval, sizeof(struct timeval)); + tval = odp_time_to_ns(odp_time_local()); + memcpy(tval_d, &tval, sizeof(uint64_t)); + icmp->chksum = 0; icmp->chksum = odph_chksum(icmp, args->appl.payload + ODPH_ICMPHDR_LEN); @@ -594,6 +593,40 @@ static int gen_send_thread(void *arg) } /** + * Process icmp packets + * + * @param icmp icmp header address + * @param msg output buffer + */ + +static void process_icmp_pkt(odph_icmphdr_t *icmp, char *msg) +{ + uint64_t trecv; + uint64_t tsend; + uint64_t rtt_ms, rtt_us; + + msg[0] = 0; + + if (icmp->type == ICMP_ECHOREPLY) { + odp_atomic_inc_u64(&counters.icmp); + + memcpy(&tsend, (uint8_t *)icmp + ODPH_ICMPHDR_LEN, + sizeof(uint64_t)); + trecv = odp_time_to_ns(odp_time_local()); + rtt_ms = (trecv - tsend) / ODP_TIME_MSEC_IN_NS; + rtt_us = (trecv - tsend) / ODP_TIME_USEC_IN_NS - + 1000 * rtt_ms; + sprintf(msg, + "ICMP Echo Reply seq %d time %" + PRIu64 ".%.03" PRIu64" ms", + odp_be_to_cpu_16(icmp->un.echo.sequence), + rtt_ms, rtt_us); + } else if (icmp->type == ICMP_ECHO) { + sprintf(msg, "Icmp Echo Request"); + } +} + +/** * Print odp packets * * @param thr worker id @@ -606,16 +639,12 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) char *buf; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; - struct timeval tvrecv; - struct timeval tvsend; - double rtt; unsigned i; size_t offset; char msg[1024]; - int rlen; + for (i = 0; i < len; ++i) { pkt = pkt_tbl[i]; - rlen = 0; /* only ip pkts */ if (!odp_packet_has_ipv4(pkt)) @@ -634,26 +663,8 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) /* icmp */ if (ip->proto == ODPH_IPPROTO_ICMP) { icmp = (odph_icmphdr_t *)(buf + offset); - /* echo reply */ - if (icmp->type == ICMP_ECHOREPLY) { - odp_atomic_inc_u64(&counters.icmp); - memcpy(&tvsend, buf + offset + ODPH_ICMPHDR_LEN, - sizeof(struct timeval)); - /* TODO This should be changed to use an - * ODP timer API once one exists. */ - gettimeofday(&tvrecv, NULL); - tv_sub(&tvrecv, &tvsend); - rtt = tvrecv.tv_sec*1000 + tvrecv.tv_usec/1000; - rlen += sprintf(msg + rlen, - "ICMP Echo Reply seq %d time %.1f ", - odp_be_to_cpu_16(icmp->un.echo.sequence) - , rtt); - } else if (icmp->type == ICMP_ECHO) { - rlen += sprintf(msg + rlen, - "Icmp Echo Request"); - } - msg[rlen] = '\0'; + process_icmp_pkt(icmp, msg); printf(" [%02i] %s\n", thr, msg); } } @@ -1392,21 +1403,3 @@ static void usage(char *progname) "\n", NO_PATH(progname), NO_PATH(progname) ); } -/** - * calc time period - * - *@param recvtime start time - *@param sendtime end time -*/ -static void tv_sub(struct timeval *recvtime, struct timeval *sendtime) -{ - long sec = recvtime->tv_sec - sendtime->tv_sec; - long usec = recvtime->tv_usec - sendtime->tv_usec; - if (usec >= 0) { - recvtime->tv_sec = sec; - recvtime->tv_usec = usec; - } else { - recvtime->tv_sec = sec - 1; - recvtime->tv_usec = -usec; - } -}