From patchwork Wed Nov 18 09:34:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56925 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2456723lbb; Wed, 18 Nov 2015 01:38:32 -0800 (PST) X-Received: by 10.140.249.9 with SMTP id u9mr439899qhc.53.1447839512435; Wed, 18 Nov 2015 01:38:32 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m206si1547543qhb.126.2015.11.18.01.38.32; Wed, 18 Nov 2015 01:38:32 -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.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 1AC5D61D83; Wed, 18 Nov 2015 09:38:32 +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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,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 B7D0E61D91; Wed, 18 Nov 2015 09:35:07 +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 650BF61E56; Wed, 18 Nov 2015 09:35:04 +0000 (UTC) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) by lists.linaro.org (Postfix) with ESMTPS id 078A661D8F for ; Wed, 18 Nov 2015 09:34:37 +0000 (UTC) Received: by lbblt2 with SMTP id lt2so20998805lbb.3 for ; Wed, 18 Nov 2015 01:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YlbuDOrTCYQ6In3vQ37vPAXRQbw/8mlmtIngNSuZEDU=; b=aTzWpANOmOgK40tB9JmIg05/AwR3FzK+m8bU9JJ5SWtEXKoyFALvDJfVWc+vRlKqPA wQAtvjx51KDX22GnzNNaBYZidhlFGt6Emq875FEURJpWM4sbAag02vgJjF8OQ5op2J6C oK2hFhtnmbrR64FNvOF4+n65Fc3tBRiPCGR4HfrDyLUavOWlDIb2wLsfK9oO3q1gGwKY oQXKE0zro8FLcjnSxsnHuYyTiI83bjkFQRtqgkSrzQYC83Bk7NJYpqhjWri8vp34cW1O F2hMQVvD9EDM2/w/wJMYCwt1ziVX6YIIecdzdfuIssEeTOowtyIQSAnzT5/NgA++hMG9 8o7g== 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=YlbuDOrTCYQ6In3vQ37vPAXRQbw/8mlmtIngNSuZEDU=; b=gisN1jJ32zifeTccKmyGcfImrL9A77090EipscJ6+QdLRa/DQv/BgsNur1GWAHnPK8 OMML73iKJVMzjJC9f76SVUlMRMUF3HbiJYnCqZ3D5NArlfW2A51MDuEG111nOTCVdhJC qatJkKmLsfu1feudwLhxS9KNdeYkjAfxlGz7qqw/KQnw0Kn16wv0sDDUddNxZFTSRusg wkhzyyO+kmHx+EBH2PHlgW8uR/evUwGLD8+slsonOq4niDESKu9bZ7ATtD3d7RfOE8nr 82xVaX1zrbq9N0bHj3e3dD0QLqlDK/Yuk/oo3sRglWzZ7X0LJKYLRPBiJkZbq+gtch4N FRBg== X-Gm-Message-State: ALoCoQlcig7kCTbRlndrE4HSMr/IbyhLY9s4O2xYoQJZ388R97+bTGRPXFXNgcvd8Msx3gZFoVWd X-Received: by 10.112.130.138 with SMTP id oe10mr238618lbb.54.1447839276741; Wed, 18 Nov 2015 01:34:36 -0800 (PST) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id o199sm297894lfa.12.2015.11.18.01.34.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Nov 2015 01:34:36 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 18 Nov 2015 12:34:28 +0300 Message-Id: <1447839268-20423-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447839268-20423-1-git-send-email-maxim.uvarov@linaro.org> References: <1447839268-20423-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 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 | 134 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 6320b77..9f05392 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]; @@ -690,6 +692,137 @@ 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 + +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); + odp_pktio_stats_t stats[2]; + + for (i = 0; i < num_ifaces; i++) { + pktio[i] = create_pktio(i, ODP_PKTIN_MODE_SCHED); + 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++) { +#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]; @@ -1057,6 +1190,7 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_mac), ODP_TEST_INFO(pktio_test_inq_remdef), ODP_TEST_INFO(pktio_test_start_stop), + ODP_TEST_INFO(pktio_test_statistics_counters), ODP_TEST_INFO_NULL };