Skip to contentSkip to conversation

rte_sched: release enqueued mbufs on rte_sched_port_free()

PATCH Superseded Simon Kagstrom 2 participants 4 messages Oct 28, 2015 – Nov 17, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rte_sched: release enqueued mbufs on rte_sched_port_free()

Otherwise mbufs will leak when the port is destroyed. The rte_sched_port_qbase() and rte_sched_port_qsize() functions are used in free now, so move them up.

---
 lib/librte_sched/rte_sched.c | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)
lib/librte_sched/rte_sched.c +27 -17
index 9c9419d..81462cd 100644
@@ -312,6 +312,23 @@ rte_sched_port_queues_per_port(struct rte_sched_port *port)
 	return RTE_SCHED_QUEUES_PER_PIPE * port->n_pipes_per_subport * port->n_subports_per_port;
 }
 
+static inline struct rte_mbuf **
+rte_sched_port_qbase(struct rte_sched_port *port, uint32_t qindex)
+{
+	uint32_t pindex = qindex >> 4;
+	uint32_t qpos = qindex & 0xF;
+
+	return (port->queue_array + pindex * port->qsize_sum + port->qsize_add[qpos]);
+}
+
+static inline uint16_t
+rte_sched_port_qsize(struct rte_sched_port *port, uint32_t qindex)
+{
+	uint32_t tc = (qindex >> 2) & 0x3;
+
+	return port->qsize[tc];
+}
+
 static int
 rte_sched_port_check_params(struct rte_sched_port_params *params)
 {
@@ -717,11 +734,21 @@ rte_sched_port_config(struct rte_sched_port_params *params)
 void
 rte_sched_port_free(struct rte_sched_port *port)
 {
+	unsigned int queue;
 	/* Check user parameters */
 	if (port == NULL){
 		return;
 	}
 
+	/* Free enqueued mbufs */
+	for (queue = 0; queue < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; queue++) {
+		unsigned int i;
+		struct rte_mbuf **mbufs = rte_sched_port_qbase(port, queue);
+
+		for (i = 0; i < rte_sched_port_qsize(port, queue); i++)
+			rte_pktmbuf_free(mbufs[i]);
+	}
+
 	rte_bitmap_free(port->bmp);
 	rte_free(port);
 }
@@ -1032,23 +1059,6 @@ rte_sched_port_qindex(struct rte_sched_port *port, uint32_t subport, uint32_t pi
 	return result;
 }
 
-static inline struct rte_mbuf **
-rte_sched_port_qbase(struct rte_sched_port *port, uint32_t qindex)
-{
-	uint32_t pindex = qindex >> 4;
-	uint32_t qpos = qindex & 0xF;
-
-	return (port->queue_array + pindex * port->qsize_sum + port->qsize_add[qpos]);
-}
-
-static inline uint16_t
-rte_sched_port_qsize(struct rte_sched_port *port, uint32_t qindex)
-{
-	uint32_t tc = (qindex >> 2) & 0x3;
-
-	return port->qsize[tc];
-}
-
 #if RTE_SCHED_DEBUG
 
 static inline int
Signature · 1 line
1.9.1
#1 lore raw

Ping?

(CC:ing Stephen Hemminger as well)

// Simon

Quoted 84 lines · Simon Kagstrom

Otherwise mbufs will leak when the port is destroyed. The rte_sched_port_qbase() and rte_sched_port_qsize() functions are used in free now, so move them up.

---
 lib/librte_sched/rte_sched.c | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)
lib/librte_sched/rte_sched.c +27 -17
index 9c9419d..81462cd 100644
@@ -312,6 +312,23 @@ rte_sched_port_queues_per_port(struct rte_sched_port *port)
 	return RTE_SCHED_QUEUES_PER_PIPE * port->n_pipes_per_subport * port->n_subports_per_port;
 }
 
+static inline struct rte_mbuf **
+rte_sched_port_qbase(struct rte_sched_port *port, uint32_t qindex)
+{
+	uint32_t pindex = qindex >> 4;
+	uint32_t qpos = qindex & 0xF;
+
+	return (port->queue_array + pindex * port->qsize_sum + port->qsize_add[qpos]);
+}
+
+static inline uint16_t
+rte_sched_port_qsize(struct rte_sched_port *port, uint32_t qindex)
+{
+	uint32_t tc = (qindex >> 2) & 0x3;
+
+	return port->qsize[tc];
+}
+
 static int
 rte_sched_port_check_params(struct rte_sched_port_params *params)
 {
@@ -717,11 +734,21 @@ rte_sched_port_config(struct rte_sched_port_params *params)
 void
 rte_sched_port_free(struct rte_sched_port *port)
 {
+	unsigned int queue;
 	/* Check user parameters */
 	if (port == NULL){
 		return;
 	}
 
+	/* Free enqueued mbufs */
+	for (queue = 0; queue < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; queue++) {
+		unsigned int i;
+		struct rte_mbuf **mbufs = rte_sched_port_qbase(port, queue);
+
+		for (i = 0; i < rte_sched_port_qsize(port, queue); i++)
+			rte_pktmbuf_free(mbufs[i]);
+	}
+
 	rte_bitmap_free(port->bmp);
 	rte_free(port);
 }
@@ -1032,23 +1059,6 @@ rte_sched_port_qindex(struct rte_sched_port *port, uint32_t subport, uint32_t pi
 	return result;
 }
 
-static inline struct rte_mbuf **
-rte_sched_port_qbase(struct rte_sched_port *port, uint32_t qindex)
-{
-	uint32_t pindex = qindex >> 4;
-	uint32_t qpos = qindex & 0xF;
-
-	return (port->queue_array + pindex * port->qsize_sum + port->qsize_add[qpos]);
-}
-
-static inline uint16_t
-rte_sched_port_qsize(struct rte_sched_port *port, uint32_t qindex)
-{
-	uint32_t tc = (qindex >> 2) & 0x3;
-
-	return port->qsize[tc];
-}
-
 #if RTE_SCHED_DEBUG
 
 static inline int
#2 lore raw
In reply to Simon Kagstrom
Quoted 5 lines · On Wed, 28 Oct 2015 10:56:33 +0100 Simon Kagstrom…

Otherwise mbufs will leak when the port is destroyed. The rte_sched_port_qbase() and rte_sched_port_qsize() functions are used in free now, so move them up.

Overall it looks good, and fixes a long standing bug. Maybe good to expose it as a API function rte_sched_port_flush to allow use from applications.

lib/librte_sched/rte_sched.c rte_sched_port_queues_per_port(struct rte_sched_port *port) · line 321

Quoted 7 lines
lib/librte_sched/rte_sched.c +7 -0
+static inline struct rte_mbuf **
+rte_sched_port_qbase(struct rte_sched_port *port, uint32_t qindex)
+{
+	uint32_t pindex = qindex >> 4;
+	uint32_t qpos = qindex & 0xF;
+
+	return (port->queue_array + pindex * port->qsize_sum + port->qsize_add[qpos]);

Please long expression over 80 characters onto multiple lines.

lib/librte_sched/rte_sched.c rte_sched_port_config(struct rte_sched_port_params *params) · line 741

Quoted 12 lines

static int
rte_sched_port_check_params(struct rte_sched_port_params *params) {

lib/librte_sched/rte_sched.c +1 -0
@@ -717,11 +734,21 @@ rte_sched_port_config(struct rte_sched_port_params *params)
 void
 rte_sched_port_free(struct rte_sched_port *port)
 {
+	unsigned int queue;
 	/* Check user parameters */
 	if (port == NULL){
 		return;
 	}

Please add blank line after declaration.

Ps: the rte_sched needs to be run through a reformatter. lots of whitespace issues.

#3 lore raw
Quoted 7 lines · Stephen Hemminger
Quoted 4 lines · On Wed, 28 Oct 2015 10:56:33 +0100 Simon Kagstrom…

Otherwise mbufs will leak when the port is destroyed. The rte_sched_port_qbase() and rte_sched_port_qsize() functions are used in free now, so move them up.

Quoted 5 lines
Quoted 1 line

Overall it looks good, and fixes a long standing bug. Maybe good to expose it as a API function rte_sched_port_flush to allow use from applications.

I'm sorry, I missed this reply! I will fix the issues you point to and repost.

// Simon