From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by dpdk.org (Postfix) with ESMTP id 6C9485A31 for ; Mon, 11 May 2015 19:07:55 +0200 (CEST) Received: by pacyx8 with SMTP id yx8so114558180pac.1 for ; Mon, 11 May 2015 10:07:54 -0700 (PDT) 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=jvpKOW/Sv3dlPxqoYWl4qxP5XRjS992JgJEATPwjXKc=; b=XJltVOli0vVwpzC3FOzjw75i+5x0UOFHgdMD+JNE20osLkAxXYT9ueVGyXamgE8kub skMKqPAzTn3A9hHaG9cwL4WI3Uvvp5KWysddKvleGb4SxIx7biyeQeD2Mf4HBgSz3fCX NybqZLKFCpR33aeFop7C5ZhDojpTyTMcEK3kQh/r2P7Su6gny+ERfowViFwaPnAkOJqf NMz9aYvqn6T214eH8vRz7YOLTTGdh2tkucBuqFib7hp4qstkhSvSv4hQx7K7iOzHKW9r hjtAQGN2cmhCe2dFQ2H7Fe9yPp7fUrmeQTfioB/TB3qCg5cMuyk41ieqskc75eMVG5Hu ohDw== X-Gm-Message-State: ALoCoQnwal9Zgi3v5jIzjuHnPpMeU1TqljMSVeM6E08ULvsN+0KJ44FT58SGF8nl+JmMVzY1RZ/T X-Received: by 10.66.66.108 with SMTP id e12mr21096539pat.155.1431364074683; Mon, 11 May 2015 10:07:54 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id hv7sm13650018pdb.86.2015.05.11.10.07.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 May 2015 10:07:53 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Date: Mon, 11 May 2015 10:07:49 -0700 Message-Id: <1431364071-27298-5-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1431364071-27298-1-git-send-email-stephen@networkplumber.org> References: <1431364071-27298-1-git-send-email-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 4/6] rte_sched: allow reading without clearing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2015 17:07:56 -0000 The rte_sched statistics API should allow reading statistics without clearing. Make auto-clear optional. Signed-off-by: Stephen Hemminger --- app/test/test_sched.c | 4 ++-- examples/qos_sched/stats.c | 22 +++++++++++++++------- lib/librte_sched/rte_sched.c | 44 ++++++++++++++++++++++---------------------- lib/librte_sched/rte_sched.h | 18 ++++++++++-------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/app/test/test_sched.c b/app/test/test_sched.c index c7239f8..1526ad7 100644 --- a/app/test/test_sched.c +++ b/app/test/test_sched.c @@ -198,13 +198,13 @@ test_sched(void) struct rte_sched_subport_stats subport_stats; uint32_t tc_ov; - rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov); + rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov, 1); #if 0 TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport stats\n"); #endif struct rte_sched_queue_stats queue_stats; uint16_t qlen; - rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen); + rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen, 1); #if 0 TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n"); #endif diff --git a/examples/qos_sched/stats.c b/examples/qos_sched/stats.c index b4db7b5..a6d05ab 100644 --- a/examples/qos_sched/stats.c +++ b/examples/qos_sched/stats.c @@ -61,7 +61,7 @@ qavg_q(uint8_t port_id, uint32_t subport_id, uint32_t pipe_id, uint8_t tc, uint8 average = 0; for (count = 0; count < qavg_ntimes; count++) { - rte_sched_queue_read_stats(port, queue_id, &stats, &qlen); + rte_sched_queue_read_stats(port, queue_id, &stats, &qlen, 1); average += qlen; usleep(qavg_period); } @@ -99,7 +99,9 @@ qavg_tcpipe(uint8_t port_id, uint32_t subport_id, uint32_t pipe_id, uint8_t tc) for (count = 0; count < qavg_ntimes; count++) { part_average = 0; for (i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { - rte_sched_queue_read_stats(port, queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + i), &stats, &qlen); + rte_sched_queue_read_stats(port, + queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + i), + &stats, &qlen, 1); part_average += qlen; } average += part_average / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; @@ -138,7 +140,8 @@ qavg_pipe(uint8_t port_id, uint32_t subport_id, uint32_t pipe_id) for (count = 0; count < qavg_ntimes; count++) { part_average = 0; for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { - rte_sched_queue_read_stats(port, queue_id + i, &stats, &qlen); + rte_sched_queue_read_stats(port, queue_id + i, + &stats, &qlen, 1); part_average += qlen; } average += part_average / (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS); @@ -178,7 +181,9 @@ qavg_tcsubport(uint8_t port_id, uint32_t subport_id, uint8_t tc) queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + i); for (j = 0; j < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) { - rte_sched_queue_read_stats(port, queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), &stats, &qlen); + rte_sched_queue_read_stats(port, + queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), + &stats, &qlen, 1); part_average += qlen; } } @@ -220,7 +225,8 @@ qavg_subport(uint8_t port_id, uint32_t subport_id) queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + i); for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) { - rte_sched_queue_read_stats(port, queue_id + j, &stats, &qlen); + rte_sched_queue_read_stats(port, queue_id + j, + &stats, &qlen, 1); part_average += qlen; } } @@ -254,7 +260,7 @@ subport_stat(uint8_t port_id, uint32_t subport_id) port = qos_conf[i].sched_port; memset (tc_ov, 0, sizeof(tc_ov)); - rte_sched_subport_read_stats(port, subport_id, &stats, tc_ov); + rte_sched_subport_read_stats(port, subport_id, &stats, tc_ov, 0); printf("\n"); printf("+----+-------------+-------------+-------------+-------------+-------------+\n"); @@ -300,7 +306,9 @@ pipe_stat(uint8_t port_id, uint32_t subport_id, uint32_t pipe_id) for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) { for (j = 0; j < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) { - rte_sched_queue_read_stats(port, queue_id + (i * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), &stats, &qlen); + rte_sched_queue_read_stats(port, + queue_id + (i * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), + &stats, &qlen, 0); printf("| %d | %d | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11i |\n", i, j, stats.n_pkts, stats.n_pkts_dropped, stats.n_bytes, stats.n_bytes_dropped, qlen); diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c index c044c09..74b3111 100644 --- a/lib/librte_sched/rte_sched.c +++ b/lib/librte_sched/rte_sched.c @@ -909,56 +909,56 @@ rte_sched_pipe_config(struct rte_sched_port *port, int rte_sched_subport_read_stats(struct rte_sched_port *port, - uint32_t subport_id, - struct rte_sched_subport_stats *stats, - uint32_t *tc_ov) + uint32_t subport_id, + struct rte_sched_subport_stats *stats, + uint32_t *tc_ov, int clear) { struct rte_sched_subport *s; /* Check user parameters */ - if ((port == NULL) || - (subport_id >= port->n_subports_per_port) || - (stats == NULL) || - (tc_ov == NULL)) { + if (port == NULL || subport_id >= port->n_subports_per_port) return -1; - } + s = port->subport + subport_id; /* Copy subport stats and clear */ - memcpy(stats, &s->stats, sizeof(struct rte_sched_subport_stats)); - memset(&s->stats, 0, sizeof(struct rte_sched_subport_stats)); + if (stats) + *stats = s->stats; + if (clear) + memset(&s->stats, 0, sizeof(struct rte_sched_subport_stats)); /* Subport TC ovesubscription status */ - *tc_ov = s->tc_ov; + if (tc_ov) + *tc_ov = s->tc_ov; return 0; } int rte_sched_queue_read_stats(struct rte_sched_port *port, - uint32_t queue_id, - struct rte_sched_queue_stats *stats, - uint16_t *qlen) + uint32_t queue_id, + struct rte_sched_queue_stats *stats, + uint16_t *qlen, int clear) { struct rte_sched_queue *q; struct rte_sched_queue_extra *qe; /* Check user parameters */ - if ((port == NULL) || - (queue_id >= rte_sched_port_queues_per_port(port)) || - (stats == NULL) || - (qlen == NULL)) { + if (port == NULL || queue_id >= rte_sched_port_queues_per_port(port)) return -1; - } + q = port->queue + queue_id; qe = port->queue_extra + queue_id; /* Copy queue stats and clear */ - memcpy(stats, &qe->stats, sizeof(struct rte_sched_queue_stats)); - memset(&qe->stats, 0, sizeof(struct rte_sched_queue_stats)); + if (stats) + *stats = qe->stats; + if (clear) + memset(&qe->stats, 0, sizeof(struct rte_sched_queue_stats)); /* Queue length */ - *qlen = q->qw - q->qr; + if (qlen) + *qlen = q->qw - q->qr; return 0; } diff --git a/lib/librte_sched/rte_sched.h b/lib/librte_sched/rte_sched.h index 3fd1fe1..dff7f85 100644 --- a/lib/librte_sched/rte_sched.h +++ b/lib/librte_sched/rte_sched.h @@ -308,14 +308,15 @@ rte_sched_port_get_memory_footprint(struct rte_sched_port_params *params); * @param tc_ov * Pointer to pre-allocated 4-entry array where the oversubscription status for * each of the 4 subport traffic classes should be stored. + * @parm clear + * Reset statistics after read * @return * 0 upon success, error code otherwise */ int -rte_sched_subport_read_stats(struct rte_sched_port *port, - uint32_t subport_id, - struct rte_sched_subport_stats *stats, - uint32_t *tc_ov); +rte_sched_subport_read_stats(struct rte_sched_port *port, uint32_t subport_id, + struct rte_sched_subport_stats *stats, + uint32_t *tc_ov, int clear); /** * Hierarchical scheduler queue statistics read @@ -329,14 +330,15 @@ rte_sched_subport_read_stats(struct rte_sched_port *port, * counters should be stored * @param qlen * Pointer to pre-allocated variable where the current queue length should be stored. + * @parm clear + * Reset statistics after read * @return * 0 upon success, error code otherwise */ int -rte_sched_queue_read_stats(struct rte_sched_port *port, - uint32_t queue_id, - struct rte_sched_queue_stats *stats, - uint16_t *qlen); +rte_sched_queue_read_stats(struct rte_sched_port *port, uint32_t queue_id, + struct rte_sched_queue_stats *stats, + uint16_t *qlen, int clear); /* * Run-time -- 2.1.4