From patchwork Mon Dec 21 11:51:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 58811 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp2547502lbb; Mon, 21 Dec 2015 03:56:18 -0800 (PST) X-Received: by 10.140.86.38 with SMTP id o35mr24193651qgd.56.1450698978413; Mon, 21 Dec 2015 03:56:18 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v20si29137402qge.51.2015.12.21.03.56.17; Mon, 21 Dec 2015 03:56:18 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C48736172C; Mon, 21 Dec 2015 11:56:17 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=PXoIWrxu; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 ED87F616CA; Mon, 21 Dec 2015 11:52:51 +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 F0DD2616BD; Mon, 21 Dec 2015 11:52:45 +0000 (UTC) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by lists.linaro.org (Postfix) with ESMTPS id 2E52F616BD for ; Mon, 21 Dec 2015 11:52:08 +0000 (UTC) Received: by mail-lb0-f181.google.com with SMTP id bc4so13836942lbc.2 for ; Mon, 21 Dec 2015 03:52:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s46CRJk7Ug5Dh6MNFA/6jIpcNJSRRvLPrZ1lYTHHsL0=; b=PXoIWrxu5YnDVciQswzChRinZ/BK99FN32SVJs2d10CFZMSGpilwp+nZGW9bS8sNmo J0I5LFTdlwxKvAS5pC2s6cpCFuF85wJzuUNzNaCIYRTceKJDyb2rGe6y7tKeohQv538T KGFqIFmSUE26czNzohkrsUc3guuL+0tR1KZEA= 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=s46CRJk7Ug5Dh6MNFA/6jIpcNJSRRvLPrZ1lYTHHsL0=; b=Lkh+dU2eYqPukYvCINh4Dk7HRlzwZ/+dLXfx0BFuheqMVYg0ydPp5/ae7Fu4WXIGr6 Uk0pmfHo28CodJGUob5K87lBcZQ3QI/RrWsTXiZ9S3fBQJ7xJYlq4N9geFFCBuRrJFbD xP/GKrXO3/+qw9rIpAVK6Cmeff1XsaLxOLkrscWexdTzy4LZeYCqEF4ns47w0BXNjmj8 6qzTvS++letaAP85LaY8l2a58nUCdYngluIEhWxdYRZsiaaVylRS9BJUemw2OQyyMLOS FFMCMlimrWAhGR7mFdHs8BG1+UgJiqHwBjrZDm4ZxmcwKk0k7flmyagu9Y65F7eU2131 d8UA== X-Gm-Message-State: ALoCoQnlm1+ZWWop/UHl6qXaXWnNm7TsuN211/rlQTfxc9t9cFhZG0eXFr6b0eDSDjpBrfhWmbKwh6p4tJzDWggbxwu/ch++9Q== X-Received: by 10.112.16.162 with SMTP id h2mr4988963lbd.89.1450698727065; Mon, 21 Dec 2015 03:52:07 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id px9sm4774337lbb.4.2015.12.21.03.52.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 03:52:06 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 21 Dec 2015 14:51:51 +0300 Message-Id: <1450698711-8413-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450698711-8413-1-git-send-email-maxim.uvarov@linaro.org> References: <1450698711-8413-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 5/5] validation: implement pktio statistics counters 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" Signed-off-by: Maxim Uvarov --- test/validation/pktio/pktio.c | 166 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 4de3ff8..a9a435e 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -23,6 +23,8 @@ #define TEST_SEQ_MAGIC 0x92749451 #define TX_BATCH_LEN 4 +#undef DEBUG_STATS + /** interface names used for testing */ static const char *iface_name[MAX_NUM_IFACES]; @@ -724,6 +726,168 @@ void pktio_test_inq(void) CU_ASSERT(odp_pktio_close(pktio) == 0); } +#ifdef DEBUG_STATS +static void _print_pktio_stats(odp_pktio_stats_t *s, const char *name) +{ + fprintf(stderr, "\n%s:\n" + " in_octets %"PRIu64"\n" + " in_ucast_pkts %"PRIu64"\n" + " in_discards %"PRIu64"\n" + " in_errors %"PRIu64"\n" + " in_unknown_protos %"PRIu64"\n" + " out_octets %"PRIu64"\n" + " out_ucast_pkts %"PRIu64"\n" + " out_discards %"PRIu64"\n" + " out_errors %"PRIu64"\n", + name, + s->in_octets, + s->in_ucast_pkts, + s->in_discards, + s->in_errors, + s->in_unknown_protos, + s->out_octets, + s->out_ucast_pkts, + s->out_discards, + s->out_errors); +} +#endif + +/* some pktio like netmap support various methods to + * get statistics counters. ethtool strings are not standardised + * and sysfs may not be supported. skip pktio_stats test until + * we will solve that.*/ +static int pktio_check_statistics_counters(void) +{ + odp_pktio_t pktio; + odp_pktio_stats_t stats; + int ret; + odp_pktio_param_t pktio_param; + const char *iface = iface_name[0]; + + odp_pktio_param_init(&pktio_param); + pktio_param.in_mode = ODP_QUEUE_TYPE_SCHED; + + pktio = odp_pktio_open(iface, pool[0], &pktio_param); + if (pktio == ODP_PKTIO_INVALID) + return -1; + + ret = odp_pktio_stats(pktio, &stats); + (void)odp_pktio_close(pktio); + + if (ret == 0) + return 1; /* supported, need test */ + + return 0; +} + +static void pktio_test_statistics_counters(void) +{ + odp_pktio_t pktio[MAX_NUM_IFACES]; + odp_packet_t pkt; + odp_event_t tx_ev[1000]; + odp_event_t ev; + int i, pkts, ret, alloc = 0; + odp_queue_t outq; + uint64_t wait = odp_schedule_wait_time(ODP_TIME_MSEC_IN_NS); + odp_pktio_stats_t stats[2]; + + for (i = 0; i < num_ifaces; i++) { + pktio[i] = create_pktio(i, ODP_PKTIN_MODE_SCHED, + ODP_PKTOUT_MODE_SEND); + + CU_ASSERT_FATAL(pktio[i] != ODP_PKTIO_INVALID); + create_inq(pktio[i], ODP_QUEUE_TYPE_SCHED); + } + + outq = odp_pktio_outq_getdef(pktio[0]); + + ret = odp_pktio_start(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_start(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* flush packets with magic number in pipes */ + for (i = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) + odp_event_free(ev); + } + + /* alloc */ + for (alloc = 0; alloc < 1000; alloc++) { + pkt = odp_packet_alloc(default_pkt_pool, packet_len); + if (pkt == ODP_PACKET_INVALID) + break; + pktio_init_packet(pkt); + tx_ev[alloc] = odp_packet_to_event(pkt); + } + + ret = odp_pktio_stats_reset(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_stats_reset(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* send */ + for (pkts = 0; pkts != alloc; ) { + ret = odp_queue_enq_multi(outq, &tx_ev[pkts], alloc - pkts); + if (ret < 0) { + CU_FAIL("unable to enqueue packet\n"); + break; + } + pkts += ret; + } + + /* get */ + for (i = 0, pkts = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) { + if (odp_event_type(ev) == ODP_EVENT_PACKET) { + pkt = odp_packet_from_event(ev); + if (pktio_pkt_seq(pkt) != TEST_SEQ_INVALID) + pkts++; + } + odp_event_free(ev); + } + } + + ret = odp_pktio_stats(pktio[0], &stats[0]); + CU_ASSERT(ret == 0); + + if (num_ifaces > 1) { + ret = odp_pktio_stats(pktio[1], &stats[1]); + CU_ASSERT(ret == 0); + CU_ASSERT(stats[1].in_ucast_pkts >= (uint64_t)pkts); + CU_ASSERT(stats[0].out_ucast_pkts == stats[1].in_ucast_pkts); + CU_ASSERT(stats[0].out_octets == stats[1].in_octets); + CU_ASSERT(stats[0].out_octets >= + (PKT_LEN_NORMAL * (uint64_t)pkts)); + } else { + CU_ASSERT(stats[0].in_ucast_pkts == (uint64_t)pkts); + CU_ASSERT(stats[0].in_octets == + (PKT_LEN_NORMAL * (uint64_t)pkts)); + } + + CU_ASSERT(pkts == alloc); + CU_ASSERT(0 == stats[0].in_discards); + CU_ASSERT(0 == stats[0].in_errors); + CU_ASSERT(0 == stats[0].in_unknown_protos); + CU_ASSERT(0 == stats[0].out_discards); + CU_ASSERT(0 == stats[0].out_errors); + + for (i = 0; i < num_ifaces; i++) { + CU_ASSERT(odp_pktio_stop(pktio[i]) == 0); +#ifdef DEBUG_STATS + _print_pktio_stats(&stats[i], iface_name[i]); +#endif + destroy_inq(pktio[i]); + CU_ASSERT(odp_pktio_close(pktio[i]) == 0); + } +} + static void pktio_test_start_stop(void) { odp_pktio_t pktio[MAX_NUM_IFACES]; @@ -1220,6 +1384,8 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_start_stop), ODP_TEST_INFO(pktio_test_recv_on_wonly), ODP_TEST_INFO(pktio_test_send_on_ronly), + ODP_TEST_INFO_CONDITIONAL(pktio_test_statistics_counters, + pktio_check_statistics_counters), ODP_TEST_INFO_NULL };