examples/qos_sched: fixup colors value overrun
PATCH 1/2 examples/qos_sched: fixup colors value overrun
'3' is not valid RTE_COLOR_ enum value.
--- examples/qos_sched/app_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
examples/qos_sched/app_thread.c +1 -1
@@ -53,7 +53,7 @@ get_pkt_sched(struct rte_mbuf *m, uint32_t *subport, uint32_t *pipe, *queue = pipe_queue - *traffic_class;/* Color (Destination IP) */ - *color = pdata[COLOR_OFFSET ] &0x03 ; + *color = pdata[COLOR_OFFSET ] %RTE_COLORS ;return 0 ; }
Signature · 1 line
2.26.2
PATCH 2/2 qos: rearrange enqueue procedure
Rework rte_sched_port_enqueue() to do actual fetch of all mbufs metadata as a first stage of that function.
That helps to avoid load stalls at futher stages of enqueue() and improves overall enqueue perfomance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles redunction
--- lib/librte_sched/rte_sched.c | 233 +++++++---------------------------- 1 file changed, 45 insertions(+), 188 deletions(-)
lib/librte_sched/rte_sched.c +45 -188
@@ -1861,24 +1861,29 @@ debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,#endif /* RTE_SCHED_DEBUG */ static inline struct rte_sched_subport * -rte_sched_port_subport (struct rte_sched_port *port, -struct rte_mbuf *pkt) +sched_port_subport (const struct rte_sched_port *port,struct rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); +uint32_t queue_id = sch.queue_id;uint32_t subport_id = queue_id >> (port->n_pipes_per_subport_log2 +4 );return port->subports[subport_id]; } +static inline struct rte_sched_subport * +rte_sched_port_subport (const struct rte_sched_port *port,struct rte_mbuf *pkt) +{ +return sched_port_subport (port, pkt->hash.sched); +} +static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0 (struct rte_sched_subport *subport, -struct rte_mbuf *pkt,uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0 (const struct rte_sched_subport *subport, +struct rte_mbuf_sched sch,uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id;
@@ -1891,6 +1896,14 @@ rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport *subport,return subport_queue_id; } +static inline uint32_t +rte_sched_port_enqueue_qptrs_prefetch0 (const struct rte_sched_subport *subport, +struct rte_mbuf *pkt,uint32_t subport_qmask) +{ +return sched_port_enqueue_qptrs_prefetch0 (subport, pkt->hash.sched, + subport_qmask); +} + static inline void rte_sched_port_enqueue_qwa_prefetch0(struct rte_sched_port *port, struct rte_sched_subport *subport,
@@ -1971,197 +1984,41 @@ int rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts) { - struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; -struct rte_mbuf **q00_base, **q01_base, **q10_base, **q11_base, - **q20_base, **q21_base, **q30_base, **q31_base, **q_last_base; -struct rte_sched_subport *subport00, *subport01, *subport10, *subport11, - *subport20, *subport21, *subport30, *subport31, *subport_last; -uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask; uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0 (subports[i], - pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =rte_sched_subport_pipe_qbase (subports[i], q[i]); -rte_sched_port_enqueue_qwa_prefetch0 (port, subports[i], - q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched; -/* Write each packet to its queue */ -for (i =0 ; i < n_pkts; i++) - result +=rte_sched_port_enqueue_qwa (port, subports[i], - q[i], q_base[i], pkts[i]); +/* Prefetch the subport structure for each packet */ +for (i =0 ; i < n_pkts; i++) + subports[i] =sched_port_subport (port, sch[i]); -return result; - } +/* Prefetch the queue structure for each queue */ +for (i =0 ; i < n_pkts; i++) + q[i] =sched_port_enqueue_qptrs_prefetch0 (subports[i], + sch[i], subport_qmask); -/* Feed the first 3 stages of the pipeline (6 packets needed) */ - pkt20 = pkts[0 ]; - pkt21 = pkts[1 ]; -rte_prefetch0 (pkt20); -rte_prefetch0 (pkt21); - - pkt10 = pkts[2 ]; - pkt11 = pkts[3 ]; -rte_prefetch0 (pkt10); -rte_prefetch0 (pkt11); - - subport20 =rte_sched_port_subport (port, pkt20); - subport21 =rte_sched_port_subport (port, pkt21); - q20 =rte_sched_port_enqueue_qptrs_prefetch0 (subport20, - pkt20, subport_qmask); - q21 =rte_sched_port_enqueue_qptrs_prefetch0 (subport21, - pkt21, subport_qmask); - - pkt00 = pkts[4 ]; - pkt01 = pkts[5 ]; -rte_prefetch0 (pkt00); -rte_prefetch0 (pkt01); - - subport10 =rte_sched_port_subport (port, pkt10); - subport11 =rte_sched_port_subport (port, pkt11); - q10 =rte_sched_port_enqueue_qptrs_prefetch0 (subport10, - pkt10, subport_qmask); - q11 =rte_sched_port_enqueue_qptrs_prefetch0 (subport11, - pkt11, subport_qmask); - - q20_base =rte_sched_subport_pipe_qbase (subport20, q20); - q21_base =rte_sched_subport_pipe_qbase (subport21, q21); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport20, q20, q20_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport21, q21, q21_base); - -/* Run the pipeline */ -for (i =6 ; i < (n_pkts & (~1 )); i +=2 ) { -/* Propagate stage inputs */ - pkt30 = pkt20; - pkt31 = pkt21; - pkt20 = pkt10; - pkt21 = pkt11; - pkt10 = pkt00; - pkt11 = pkt01; - q30 = q20; - q31 = q21; - q20 = q10; - q21 = q11; - subport30 = subport20; - subport31 = subport21; - subport20 = subport10; - subport21 = subport11; - q30_base = q20_base; - q31_base = q21_base; - -/* Stage 0: Get packets in */ - pkt00 = pkts[i]; - pkt01 = pkts[i +1 ]; -rte_prefetch0 (pkt00); -rte_prefetch0 (pkt01); - -/* Stage 1: Prefetch subport and queue structure storing queue pointers */ - subport10 =rte_sched_port_subport (port, pkt10); - subport11 =rte_sched_port_subport (port, pkt11); - q10 =rte_sched_port_enqueue_qptrs_prefetch0 (subport10, - pkt10, subport_qmask); - q11 =rte_sched_port_enqueue_qptrs_prefetch0 (subport11, - pkt11, subport_qmask); - -/* Stage 2: Prefetch queue write location */ - q20_base =rte_sched_subport_pipe_qbase (subport20, q20); - q21_base =rte_sched_subport_pipe_qbase (subport21, q21); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport20, q20, q20_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport21, q21, q21_base); - -/* Stage 3: Write packet to queue and activate queue */ - r30 =rte_sched_port_enqueue_qwa (port, subport30, - q30, q30_base, pkt30); - r31 =rte_sched_port_enqueue_qwa (port, subport31, - q31, q31_base, pkt31); - result += r30 + r31; - } - -/* -* Drain the pipeline (exactly 6 packets). -* Handle the last packet in the case -* of an odd number of input packets. -*/ - pkt_last = pkts[n_pkts -1 ]; -rte_prefetch0 (pkt_last); - - subport00 =rte_sched_port_subport (port, pkt00); - subport01 =rte_sched_port_subport (port, pkt01); - q00 =rte_sched_port_enqueue_qptrs_prefetch0 (subport00, - pkt00, subport_qmask); - q01 =rte_sched_port_enqueue_qptrs_prefetch0 (subport01, - pkt01, subport_qmask); - - q10_base =rte_sched_subport_pipe_qbase (subport10, q10); - q11_base =rte_sched_subport_pipe_qbase (subport11, q11); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport10, q10, q10_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport11, q11, q11_base); - - r20 =rte_sched_port_enqueue_qwa (port, subport20, - q20, q20_base, pkt20); - r21 =rte_sched_port_enqueue_qwa (port, subport21, - q21, q21_base, pkt21); - result += r20 + r21; - - subport_last =rte_sched_port_subport (port, pkt_last); - q_last =rte_sched_port_enqueue_qptrs_prefetch0 (subport_last, - pkt_last, subport_qmask); - - q00_base =rte_sched_subport_pipe_qbase (subport00, q00); - q01_base =rte_sched_subport_pipe_qbase (subport01, q01); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport00, q00, q00_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport01, q01, q01_base); - - r10 =rte_sched_port_enqueue_qwa (port, subport10, q10, - q10_base, pkt10); - r11 =rte_sched_port_enqueue_qwa (port, subport11, q11, - q11_base, pkt11); - result += r10 + r11; - - q_last_base =rte_sched_subport_pipe_qbase (subport_last, q_last); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport_last, - q_last, q_last_base); - - r00 =rte_sched_port_enqueue_qwa (port, subport00, q00, - q00_base, pkt00); - r01 =rte_sched_port_enqueue_qwa (port, subport01, q01, - q01_base, pkt01); - result += r00 + r01; - -if (n_pkts &1 ) { - r_last =rte_sched_port_enqueue_qwa (port, subport_last, - q_last, q_last_base, pkt_last); - result += r_last; +/* Prefetch the write pointer location of each queue */ +for (i =0 ; i < n_pkts; i++) { + q_base[i] =rte_sched_subport_pipe_qbase (subports[i], q[i]); +rte_sched_port_enqueue_qwa_prefetch0 (port, subports[i], + q[i], q_base[i]); } +/* Write each packet to its queue */ +for (i =0 ; i < n_pkts; i++) + result +=rte_sched_port_enqueue_qwa (port, subports[i], + q[i], q_base[i], pkts[i]);return result; }
Signature · 1 line
2.26.2
PATCH v2 1/2 examples/qos_sched: fixup colors value overrun
In reply to Konstantin Ananyev'3' is not valid RTE_COLOR_ enum value.
--- examples/qos_sched/app_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
examples/qos_sched/app_thread.c +1 -1
@@ -53,7 +53,7 @@ get_pkt_sched(struct rte_mbuf *m, uint32_t *subport, uint32_t *pipe, *queue = pipe_queue - *traffic_class;/* Color (Destination IP) */ - *color = pdata[COLOR_OFFSET ] &0x03 ; + *color = pdata[COLOR_OFFSET ] %RTE_COLORS ;return 0 ; }
Signature · 1 line
2.25.1
PATCH v2 2/2 qos: rearrange enqueue procedure
In many usage scenarios input mbufs for rte_sched_port_enqueue() are not yet in the CPU cache(s). That causes quite significant stalls due to memory latency. Current implementation tries to migitate it using SW pipeline and SW prefetch techniques, but stalls are still present. Rework rte_sched_port_enqueue() to do actual fetch of all mbufs metadata as a first stage of that function.
That helps to minimise load stalls at further stages of enqueue() and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache
(one core doing RX, QOS and TX).
With such scenario, on all mentioned above IA boxes
no performance drop was observed.
---
v2: fix clang and checkpatch complains
--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)
lib/librte_sched/rte_sched.c +31 -188
@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,#endif /* RTE_SCHED_DEBUG */ static inline struct rte_sched_subport * -rte_sched_port_subport (struct rte_sched_port *port, -struct rte_mbuf *pkt) +sched_port_subport (const struct rte_sched_port *port,struct rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); +uint32_t queue_id = sch.queue_id;uint32_t subport_id = queue_id >> (port->n_pipes_per_subport_log2 +4 );return port->subports[subport_id]; }static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0 (struct rte_sched_subport *subport, -struct rte_mbuf *pkt,uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0 (const struct rte_sched_subport *subport, +struct rte_mbuf_sched sch,uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id;
@@ -1971,197 +1970,41 @@ int rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts) { - struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; -struct rte_mbuf **q00_base, **q01_base, **q10_base, **q11_base, - **q20_base, **q21_base, **q30_base, **q31_base, **q_last_base; -struct rte_sched_subport *subport00, *subport01, *subport10, *subport11, - *subport20, *subport21, *subport30, *subport31, *subport_last; -uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask; uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0 (subports[i], - pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =rte_sched_subport_pipe_qbase (subports[i], q[i]); -rte_sched_port_enqueue_qwa_prefetch0 (port, subports[i], - q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched; -/* Write each packet to its queue */ -for (i =0 ; i < n_pkts; i++) - result +=rte_sched_port_enqueue_qwa (port, subports[i], - q[i], q_base[i], pkts[i]); +/* Prefetch the subport structure for each packet */ +for (i =0 ; i < n_pkts; i++) + subports[i] =sched_port_subport (port, sch[i]); -return result; - } +/* Prefetch the queue structure for each queue */ +for (i =0 ; i < n_pkts; i++) + q[i] =sched_port_enqueue_qptrs_prefetch0 (subports[i], + sch[i], subport_qmask); -/* Feed the first 3 stages of the pipeline (6 packets needed) */ - pkt20 = pkts[0 ]; - pkt21 = pkts[1 ]; -rte_prefetch0 (pkt20); -rte_prefetch0 (pkt21); - - pkt10 = pkts[2 ]; - pkt11 = pkts[3 ]; -rte_prefetch0 (pkt10); -rte_prefetch0 (pkt11); - - subport20 =rte_sched_port_subport (port, pkt20); - subport21 =rte_sched_port_subport (port, pkt21); - q20 =rte_sched_port_enqueue_qptrs_prefetch0 (subport20, - pkt20, subport_qmask); - q21 =rte_sched_port_enqueue_qptrs_prefetch0 (subport21, - pkt21, subport_qmask); - - pkt00 = pkts[4 ]; - pkt01 = pkts[5 ]; -rte_prefetch0 (pkt00); -rte_prefetch0 (pkt01); - - subport10 =rte_sched_port_subport (port, pkt10); - subport11 =rte_sched_port_subport (port, pkt11); - q10 =rte_sched_port_enqueue_qptrs_prefetch0 (subport10, - pkt10, subport_qmask); - q11 =rte_sched_port_enqueue_qptrs_prefetch0 (subport11, - pkt11, subport_qmask); - - q20_base =rte_sched_subport_pipe_qbase (subport20, q20); - q21_base =rte_sched_subport_pipe_qbase (subport21, q21); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport20, q20, q20_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport21, q21, q21_base); - -/* Run the pipeline */ -for (i =6 ; i < (n_pkts & (~1 )); i +=2 ) { -/* Propagate stage inputs */ - pkt30 = pkt20; - pkt31 = pkt21; - pkt20 = pkt10; - pkt21 = pkt11; - pkt10 = pkt00; - pkt11 = pkt01; - q30 = q20; - q31 = q21; - q20 = q10; - q21 = q11; - subport30 = subport20; - subport31 = subport21; - subport20 = subport10; - subport21 = subport11; - q30_base = q20_base; - q31_base = q21_base; - -/* Stage 0: Get packets in */ - pkt00 = pkts[i]; - pkt01 = pkts[i +1 ]; -rte_prefetch0 (pkt00); -rte_prefetch0 (pkt01); - -/* Stage 1: Prefetch subport and queue structure storing queue pointers */ - subport10 =rte_sched_port_subport (port, pkt10); - subport11 =rte_sched_port_subport (port, pkt11); - q10 =rte_sched_port_enqueue_qptrs_prefetch0 (subport10, - pkt10, subport_qmask); - q11 =rte_sched_port_enqueue_qptrs_prefetch0 (subport11, - pkt11, subport_qmask); - -/* Stage 2: Prefetch queue write location */ - q20_base =rte_sched_subport_pipe_qbase (subport20, q20); - q21_base =rte_sched_subport_pipe_qbase (subport21, q21); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport20, q20, q20_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport21, q21, q21_base); - -/* Stage 3: Write packet to queue and activate queue */ - r30 =rte_sched_port_enqueue_qwa (port, subport30, - q30, q30_base, pkt30); - r31 =rte_sched_port_enqueue_qwa (port, subport31, - q31, q31_base, pkt31); - result += r30 + r31; - } - -/* -* Drain the pipeline (exactly 6 packets). -* Handle the last packet in the case -* of an odd number of input packets. -*/ - pkt_last = pkts[n_pkts -1 ]; -rte_prefetch0 (pkt_last); - - subport00 =rte_sched_port_subport (port, pkt00); - subport01 =rte_sched_port_subport (port, pkt01); - q00 =rte_sched_port_enqueue_qptrs_prefetch0 (subport00, - pkt00, subport_qmask); - q01 =rte_sched_port_enqueue_qptrs_prefetch0 (subport01, - pkt01, subport_qmask); - - q10_base =rte_sched_subport_pipe_qbase (subport10, q10); - q11_base =rte_sched_subport_pipe_qbase (subport11, q11); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport10, q10, q10_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport11, q11, q11_base); - - r20 =rte_sched_port_enqueue_qwa (port, subport20, - q20, q20_base, pkt20); - r21 =rte_sched_port_enqueue_qwa (port, subport21, - q21, q21_base, pkt21); - result += r20 + r21; - - subport_last =rte_sched_port_subport (port, pkt_last); - q_last =rte_sched_port_enqueue_qptrs_prefetch0 (subport_last, - pkt_last, subport_qmask); - - q00_base =rte_sched_subport_pipe_qbase (subport00, q00); - q01_base =rte_sched_subport_pipe_qbase (subport01, q01); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport00, q00, q00_base); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport01, q01, q01_base); - - r10 =rte_sched_port_enqueue_qwa (port, subport10, q10, - q10_base, pkt10); - r11 =rte_sched_port_enqueue_qwa (port, subport11, q11, - q11_base, pkt11); - result += r10 + r11; - - q_last_base =rte_sched_subport_pipe_qbase (subport_last, q_last); -rte_sched_port_enqueue_qwa_prefetch0 (port, subport_last, - q_last, q_last_base); - - r00 =rte_sched_port_enqueue_qwa (port, subport00, q00, - q00_base, pkt00); - r01 =rte_sched_port_enqueue_qwa (port, subport01, q01, - q01_base, pkt01); - result += r00 + r01; - -if (n_pkts &1 ) { - r_last =rte_sched_port_enqueue_qwa (port, subport_last, - q_last, q_last_base, pkt_last); - result += r_last; +/* Prefetch the write pointer location of each queue */ +for (i =0 ; i < n_pkts; i++) { + q_base[i] =rte_sched_subport_pipe_qbase (subports[i], q[i]); +rte_sched_port_enqueue_qwa_prefetch0 (port, subports[i], + q[i], q_base[i]); } +/* Write each packet to its queue */ +for (i =0 ; i < n_pkts; i++) + result +=rte_sched_port_enqueue_qwa (port, subports[i], + q[i], q_base[i], pkts[i]);return result; }
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedure
Quoted 132 lines
-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Thursday, March 18, 2021 11:56 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; Ananyev, Konstantin <[email protected]>
Subject: [PATCH v2 2/2] qos: rearrange enqueue procedureIn many usage scenarios input mbufs for
rte_sched_port_enqueue()are not yet in the CPU cache(s). That causes quite significant stalls due to memory latency. Current implementation tries to migitate it using SW pipeline and SW prefetch techniques, but stalls are still present.
Reworkrte_sched_port_enqueue()to do actual fetch of all mbufs metadata as a first stage of that function.
That helps to minimise load stalls at further stages ofenqueue()and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache (one core doing RX, QOS and TX).
With such scenario, on all mentioned above IA boxes no performance drop was observed.Signed-off-by Konstantin Ananyev <[email protected]>---
v2: fix clang and checkpatch complains--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)lib/librte_sched/rte_sched.c index renamed from lib/librte_sched/rte_sched.c +0
-0
7c5688068..41ef147e0100644lib/librte_sched/rte_sched.c +0
-0@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct
rte_sched_subport*subport,uint32_tbmp_pos, #endif /*RTE_SCHED_DEBUG*/static inline struct
rte_sched_subport* -rte_sched_port_subport(structrte_sched_port*port,lib/librte_sched/rte_sched.c +3
-2- struct rte_mbuf *pkt) +sched_port_subport(const struct rte_sched_port *port, struct +rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); + uint32_t queue_id = sch.queue_id; uint32_t subport_id = queue_id >> (port-Quoted 1 line
n_pipes_per_subport_log2+ 4);lib/librte_sched/rte_sched.c +0
-1return port->subports[subport_id]; } static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +1
-1- struct rte_mbuf *pkt, uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0(const struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +2
-1+ struct rte_mbuf_sched sch, uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id; @@ -1971,197 +1970,41@@ int rte_sched_port_enqueue(struct
rte_sched_port*port, structrte_mbuf**pkts,lib/librte_sched/rte_sched.c +0
-3uint32_t n_pkts) { -struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; - struct rte_mbuf **q00_base, **q01_base, **q10_base,**q11_base,
lib/librte_sched/rte_sched.c +0
-1- **q20_base, **q21_base, **q30_base, **q31_base,**q_last_base;
lib/librte_sched/rte_sched.c +0
-1- struct rte_sched_subport *subport00, *subport01, *subport10,*subport11,
lib/librte_sched/rte_sched.c +0
-1- *subport20, *subport21, *subport30, *subport31,
*subport_last;lib/librte_sched/rte_sched.c +7
-24-uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask;uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
lib/librte_sched/rte_sched.c +0
-5- pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =
rte_sched_subport_pipe_qbase(subports[i], q[i]);lib/librte_sched/rte_sched.c +0
-1- rte_sched_port_enqueue_qwa_prefetch0(port,subports[i],
lib/librte_sched/rte_sched.c int · line 1986
Quoted 5 lines
lib/librte_sched/rte_sched.c +3
-2- q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched;
Hi Konstantin, thanks for the patch. In above case, all packets are touched straight with any prefetch. If we consider the input burst size of 64 pkts, it means 512 bytes of packet addresses (8 cache-lines) which is likely to be available in cache. For larger size burst, e.g. 128 or 256, there might be instances when some addresses are not available the cache, may stall core. How about adding explicit prefetch before starting to iterate through the packets if that helps?
Re: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedure
Quoted 152 lines
-----Original Message-----
From: Singh, Jasvinder <[email protected]>
Sent: Friday, April 2, 2021 3:15 PM
To: Ananyev, Konstantin <[email protected]>; [email protected]
Cc: Dumitrescu, Cristian <[email protected]>
Subject: RE: [PATCH v2 2/2] qos: rearrange enqueue procedureQuoted 10 lines
-----Original Message-----
From: Ananyev, Konstantin <[email protected]>
Sent: Thursday, March 18, 2021 11:56 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; Ananyev, Konstantin <[email protected]>
Subject: [PATCH v2 2/2] qos: rearrange enqueue procedureIn many usage scenarios input mbufs for
rte_sched_port_enqueue()arenot
Quoted 2 lines
yet in the CPU cache(s). That causes quite significant stalls due to memory latency. Current implementation tries to migitate it using SW pipeline and
SW
Quoted 2 lines
prefetch techniques, but stalls are still present. Rework
rte_sched_port_enqueue()to do actual fetch of all mbufsmetadata
Quoted 7 lines
as a first stage of that function.
That helps to minimise load stalls at further stages ofenqueue()and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache (one core doing RX, QOSand
lib/librte_sched/rte_sched.c
Quoted 12 lines
TX).
With such scenario, on all mentioned above IA boxes no performance drop was observed.Signed-off-by Konstantin Ananyev <[email protected]>---
v2: fix clang and checkpatch complains--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)lib/librte_sched/rte_sched.c +0
-0index
Quoted 97 lines
7c5688068..41ef147e0100644lib/librte_sched/rte_sched.c +0
-0@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct
rte_sched_subport*subport,uint32_tbmp_pos, #endif /*RTE_SCHED_DEBUG*/static inline struct
rte_sched_subport* -rte_sched_port_subport(structrte_sched_port*port,lib/librte_sched/rte_sched.c +3
-2- struct rte_mbuf *pkt) +sched_port_subport(const struct rte_sched_port *port, struct +rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); + uint32_t queue_id = sch.queue_id; uint32_t subport_id = queue_id >> (port-Quoted 1 line
n_pipes_per_subport_log2+ 4);lib/librte_sched/rte_sched.c +0
-1return port->subports[subport_id]; } static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +1
-1- struct rte_mbuf *pkt, uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0(const struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +2
-1+ struct rte_mbuf_sched sch, uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id; @@ -1971,197 +1970,41@@ int rte_sched_port_enqueue(struct
rte_sched_port*port, structrte_mbuf**pkts,lib/librte_sched/rte_sched.c +0
-3uint32_t n_pkts) { -struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; - struct rte_mbuf **q00_base, **q01_base, **q10_base,**q11_base,
lib/librte_sched/rte_sched.c +0
-1- **q20_base, **q21_base, **q30_base, **q31_base,**q_last_base;
lib/librte_sched/rte_sched.c +0
-1- struct rte_sched_subport *subport00, *subport01, *subport10,*subport11,
lib/librte_sched/rte_sched.c +0
-1- *subport20, *subport21, *subport30, *subport31,
*subport_last;lib/librte_sched/rte_sched.c +7
-24-uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask;uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
lib/librte_sched/rte_sched.c +0
-5- pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =
rte_sched_subport_pipe_qbase(subports[i], q[i]);lib/librte_sched/rte_sched.c +0
-1- rte_sched_port_enqueue_qwa_prefetch0(port,subports[i],
lib/librte_sched/rte_sched.c int · line 1986
Quoted 5 lines
lib/librte_sched/rte_sched.c +3
-2- q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched;
Quoted 7 lines
Hi Konstantin, thanks for the patch. In above case, all packets are touched straight with any prefetch. If we consider the input burst size of 64 pkts, it means 512 bytes of packet addresses (8 cache-lines) which is likely to be available in cache. For larger size burst, e.g. 128 or 256, there might be instances when some addresses are not available the cache, may stall core. How about adding explicit prefetch before starting to iterate through the packets if that helps?
Exactly. Konstantin, you might not be a fan of prefetches, but the current enqueue implementation (as well as the dequeue) uses a prefetch state machine. Please keep the prefetch state machine in the scalar code. Even if the examples/qos_sched might not show an advantage, this is just a sample app and there are some more relevant use-cases as well.
Thanks,
Cristian
Re: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedure
Hi guys,
Quoted 131 lines
Quoted 131 lines
Quoted 1 line
In many usage scenarios input mbufs for
rte_sched_port_enqueue()arenot
Quoted 2 lines
yet in the CPU cache(s). That causes quite significant stalls due to memory latency. Current implementation tries to migitate it using SW pipeline and
SW
Quoted 2 lines
prefetch techniques, but stalls are still present. Rework
rte_sched_port_enqueue()to do actual fetch of all mbufsmetadata
Quoted 7 lines
as a first stage of that function.
That helps to minimise load stalls at further stages ofenqueue()and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache (one core doing RX, QOSand
lib/librte_sched/rte_sched.c
Quoted 12 lines
TX).
With such scenario, on all mentioned above IA boxes no performance drop was observed.Signed-off-by Konstantin Ananyev <[email protected]>---
v2: fix clang and checkpatch complains--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)lib/librte_sched/rte_sched.c +0
-0index
Quoted 102 lines
7c5688068..41ef147e0100644lib/librte_sched/rte_sched.c +0
-0@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct
rte_sched_subport*subport,uint32_tbmp_pos, #endif /*RTE_SCHED_DEBUG*/static inline struct
rte_sched_subport* -rte_sched_port_subport(structrte_sched_port*port,lib/librte_sched/rte_sched.c +3
-2- struct rte_mbuf *pkt) +sched_port_subport(const struct rte_sched_port *port, struct +rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); + uint32_t queue_id = sch.queue_id; uint32_t subport_id = queue_id >> (port-Quoted 1 line
n_pipes_per_subport_log2+ 4);lib/librte_sched/rte_sched.c +0
-1return port->subports[subport_id]; } static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +1
-1- struct rte_mbuf *pkt, uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0(const struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +2
-1+ struct rte_mbuf_sched sch, uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id; @@ -1971,197 +1970,41@@ int rte_sched_port_enqueue(struct
rte_sched_port*port, structrte_mbuf**pkts,lib/librte_sched/rte_sched.c +0
-3uint32_t n_pkts) { -struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; - struct rte_mbuf **q00_base, **q01_base, **q10_base,**q11_base,
lib/librte_sched/rte_sched.c +0
-1- **q20_base, **q21_base, **q30_base, **q31_base,**q_last_base;
lib/librte_sched/rte_sched.c +0
-1- struct rte_sched_subport *subport00, *subport01, *subport10,*subport11,
lib/librte_sched/rte_sched.c +0
-1- *subport20, *subport21, *subport30, *subport31,
*subport_last;lib/librte_sched/rte_sched.c +7
-24-uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask;uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
lib/librte_sched/rte_sched.c +0
-5- pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =
rte_sched_subport_pipe_qbase(subports[i], q[i]);lib/librte_sched/rte_sched.c +0
-1- rte_sched_port_enqueue_qwa_prefetch0(port,subports[i],
lib/librte_sched/rte_sched.c +3
-2- q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched;
Quoted 8 lines
Quoted 8 lines
Hi Konstantin, thanks for the patch. In above case, all packets are touched straight with any prefetch. If we consider the input burst size of 64 pkts, it means 512 bytes of packet addresses (8 cache-lines) which is likely to be available in cache. For larger size burst, e.g. 128 or 256, there might be instances when some addresses are not available the cache, may stall core. How about adding explicit prefetch before starting to iterate through the packets if that helps?
I don't think we need any prefetch here.
pkts[] is a sequential array, HW prefetcher should be able to do good job here. Again in majority of use-cases pkts[] contents will already present in the cache. Though there is a valid concern here: n_pkts can be big, in that case we probably don't want to store too much on the stack and read too much from pkts[]. It is better to work in some fixed chunks (64 or so).
I can prepare v2 with these changes, if there still is an interest in this patch.
Quoted 2 lines
Exactly. Konstantin, you might not be a fan of prefetches, but the current enqueue implementation (as well as the dequeue) uses a prefetch state machine. Please keep the prefetch state machine in the scalar code.
It is not about our own preferences.
From my measurements new version is faster and it is definitely simpler.
Quoted 2 lines
Even if the examples/qos_sched might not show an advantage,
this is just a sample app and there are some more relevant use-cases as well.
Well, I hope that examples/qos_sched reflects at least some real-world use-cases for QOS library. Otherwise why do we have it inside DPDK codebase?
About 'more relevant use-cases': if you do know such, can you try them with the patch? I would really appreciate that.
In fact, it is an ask not only to Cristian, but to all other interested parties:
if your app does use librte_sched - please try this patch and provide the feedback. If some tests would flag a regression - I am absolutely ok to drop the patch. Konstantin
Re: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedure
Hi all,
What is the conclusion for this patch and the number 1/2?
04/04/2021 01:53, Ananyev, Konstantin:
Quoted 168 lines
Hi guys,
Quoted 131 lines
Quoted 131 lines
Quoted 1 line
In many usage scenarios input mbufs for
rte_sched_port_enqueue()arenot
Quoted 2 lines
yet in the CPU cache(s). That causes quite significant stalls due to memory latency. Current implementation tries to migitate it using SW pipeline and
SW
Quoted 2 lines
prefetch techniques, but stalls are still present. Rework
rte_sched_port_enqueue()to do actual fetch of all mbufsmetadata
Quoted 7 lines
as a first stage of that function.
That helps to minimise load stalls at further stages ofenqueue()and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache (one core doing RX, QOSand
lib/librte_sched/rte_sched.c
Quoted 12 lines
TX).
With such scenario, on all mentioned above IA boxes no performance drop was observed.Signed-off-by Konstantin Ananyev <[email protected]>---
v2: fix clang and checkpatch complains--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)lib/librte_sched/rte_sched.c +0
-0index
Quoted 102 lines
7c5688068..41ef147e0100644lib/librte_sched/rte_sched.c +0
-0@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct
rte_sched_subport*subport,uint32_tbmp_pos, #endif /*RTE_SCHED_DEBUG*/static inline struct
rte_sched_subport* -rte_sched_port_subport(structrte_sched_port*port,lib/librte_sched/rte_sched.c +3
-2- struct rte_mbuf *pkt) +sched_port_subport(const struct rte_sched_port *port, struct +rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); + uint32_t queue_id = sch.queue_id; uint32_t subport_id = queue_id >> (port-Quoted 1 line
n_pipes_per_subport_log2+ 4);lib/librte_sched/rte_sched.c +0
-1return port->subports[subport_id]; } static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0(struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +1
-1- struct rte_mbuf *pkt, uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0(const struct rte_sched_subport*subport,
lib/librte_sched/rte_sched.c +2
-1+ struct rte_mbuf_sched sch, uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex; q = subport->queue + subport_queue_id; @@ -1971,197 +1970,41@@ int rte_sched_port_enqueue(struct
rte_sched_port*port, structrte_mbuf**pkts,lib/librte_sched/rte_sched.c +0
-3uint32_t n_pkts) { -struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20, *pkt21, - *pkt30, *pkt31, *pkt_last; - struct rte_mbuf **q00_base, **q01_base, **q10_base,**q11_base,
lib/librte_sched/rte_sched.c +0
-1- **q20_base, **q21_base, **q30_base, **q31_base,**q_last_base;
lib/librte_sched/rte_sched.c +0
-1- struct rte_sched_subport *subport00, *subport01, *subport10,*subport11,
lib/librte_sched/rte_sched.c +0
-1- *subport20, *subport21, *subport30, *subport31,
*subport_last;lib/librte_sched/rte_sched.c +7
-24-uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask;uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ; -/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ]; -struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] =rte_sched_port_subport (port, pkts[i]); - -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
lib/librte_sched/rte_sched.c +0
-5- pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */ -for (i =0 ; i < n_pkts; i++) { - q_base[i] =
rte_sched_subport_pipe_qbase(subports[i], q[i]);lib/librte_sched/rte_sched.c +0
-1- rte_sched_port_enqueue_qwa_prefetch0(port,subports[i],
lib/librte_sched/rte_sched.c +3
-2- q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched;Quoted 8 lines
Quoted 8 lines
Hi Konstantin, thanks for the patch. In above case, all packets are touched straight with any prefetch. If we consider the input burst size of 64 pkts, it means 512 bytes of packet addresses (8 cache-lines) which is likely to be available in cache. For larger size burst, e.g. 128 or 256, there might be instances when some addresses are not available the cache, may stall core. How about adding explicit prefetch before starting to iterate through the packets if that helps?
I don't think we need any prefetch here.
pkts[] is a sequential array, HW prefetcher should be able to do good job here. Again in majority of use-cases pkts[] contents will already present in the cache. Though there is a valid concern here:n_pktscan be big, in that case we probably don't want to store too much on the stack and read too much from pkts[]. It is better to work in some fixed chunks (64 or so).
I can prepare v2 with these changes, if there still is an interest in this patch.Quoted 2 lines
Exactly. Konstantin, you might not be a fan of prefetches, but the current enqueue implementation (as well as the dequeue) uses a prefetch state machine. Please keep the prefetch state machine in the scalar code.
It is not about our own preferences.
From my measurements new version is faster and it is definitely simpler.Quoted 2 lines
Even if the examples/qos_sched might not show an advantage,
this is just a sample app and there are some more relevant use-cases as well.Well, I hope that examples/qos_sched reflects at least some real-world use-cases for QOS library. Otherwise why do we have it inside DPDK codebase?
About 'more relevant use-cases': if you do know such, can you try them with the patch? I would really appreciate that.
In fact, it is an ask not only to Cristian, but to all other interested parties:
if your app does uselibrte_sched- please try this patch and provide the feedback. If some tests would flag a regression - I am absolutely ok to drop the patch. Konstantin
RE: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedure
Quoted 203 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 17, 2021 10:33 AM
To: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; Ananyev, Konstantin <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/2] qos: rearrange enqueue procedureHi all,
What is the conclusion for this patch and the number 1/2?04/04/2021 01:53, Ananyev, Konstantin:
Quoted 4 lines
Hi guys,
Quoted 1 line
Quoted 1 line
Quoted 1 line
In many usage scenarios input mbufs for
rte_sched_port_enqueue()are
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
not
Quoted 1 line
yet in the CPU cache(s). That causes quite significant stalls due to
memory
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
latency. Current implementation tries to migitate it using SW pipeline
and
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
SW
Quoted 2 lines
prefetch techniques, but stalls are still present. Rework
rte_sched_port_enqueue()to do actual fetch of all mbufsmetadata
Quoted 7 lines
as a first stage of that function.
That helps to minimise load stalls at further stages ofenqueue()and improves overall enqueue performance.
With examples/qos_sched I observed:
on ICX box: up to 30% cycles reduction
on CSX AND BDX: 20-15% cycles reduction
I also run tests with mbufs already in the cache (one core doing RX,QOS
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
and
Quoted 2 lines
TX).
With such scenario, on all mentioned above IA boxes no performancedrop
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Review
Quoted 10 lines
was observed.
Signed-off-by Konstantin Ananyev <[email protected]>---
v2: fix clang and checkpatch complains--- lib/librte_sched/rte_sched.c | 219 +++++------------------------------ 1 file changed, 31 insertions(+), 188 deletions(-)(quoted diff) +0
-0
b/lib/librte_sched/rte_sched.cQuoted 9 lines
Quoted 9 lines
Quoted 9 lines
index
Quoted 8 lines
7c5688068..41ef147e0100644lib/librte_sched/rte_sched.c +0
-0@@ -1861,24 +1861,23 @@ debug_check_queue_slab(struct
rte_sched_subport*subport,uint32_tbmp_pos, #endif /*RTE_SCHED_DEBUG*/static inline struct
rte_sched_subport* -rte_sched_port_subport(struct
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
rte_sched_port*port,lib/librte_sched/rte_sched.c +3
-2- struct rte_mbuf *pkt) +sched_port_subport(const struct rte_sched_port *port, struct +rte_mbuf_sched sch) { -uint32_t queue_id =rte_mbuf_sched_queue_get (pkt); + uint32_t queue_id = sch.queue_id; uint32_t subport_id = queue_id >> (port-Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_sched/rte_sched.c debug_check_queue_slab(struct rte_sched_subport *subport, uint32_t bmp_pos,
Quoted 7 lines
Quoted 1 line
n_pipes_per_subport_log2+ 4);lib/librte_sched/rte_sched.c +0
-1return port->subports[subport_id]; } static inline uint32_t -rte_sched_port_enqueue_qptrs_prefetch0(struct
rte_sched_subportQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/librte_sched/rte_sched.c
Quoted 3 lines
*subport,
lib/librte_sched/rte_sched.c +1
-1- struct rte_mbuf *pkt, uint32_t subport_qmask) +sched_port_enqueue_qptrs_prefetch0(const struct
rte_sched_subportQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
*subport,
lib/librte_sched/rte_sched.c +2
-1+ struct rte_mbuf_sched sch, uint32_t subport_qmask) {struct rte_sched_queue *q;#ifdef RTE_SCHED_COLLECT_STATS struct rte_sched_queue_extra *qe;#endif -uint32_t qindex =rte_mbuf_sched_queue_get (pkt); +uint32_t qindex = sch.queue_id;uint32_t subport_queue_id = subport_qmask & qindex;Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
q =
subport->queue+subport_queue_id; @@ -1971,197+1970,41
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
@@ int rte_sched_port_enqueue(struct
rte_sched_port*port,struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_sched/rte_sched.c int
Quoted 4 lines
rte_mbuf**pkts,lib/librte_sched/rte_sched.c +0
-1uint32_t n_pkts) { - struct rte_mbuf *pkt00, *pkt01, *pkt10, *pkt11, *pkt20,*pkt21,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/librte_sched/rte_sched.c
Quoted 6 lines
lib/librte_sched/rte_sched.c +0
-2- *pkt30, *pkt31, *pkt_last; - struct rte_mbuf **q00_base, **q01_base, **q10_base,**q11_base,
lib/librte_sched/rte_sched.c +0
-1- **q20_base, **q21_base, **q30_base, **q31_base,**q_last_base;
lib/librte_sched/rte_sched.c +0
-1- struct rte_sched_subport *subport00, *subport01,*subport10,
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
*subport11,
lib/librte_sched/rte_sched.c +0
-1- *subport20, *subport21, *subport30, *subport31,
*subport_last;lib/librte_sched/rte_sched.c +7
-3-uint32_t q00, q01, q10, q11, q20, q21, q30, q31, q_last; -uint32_t r00, r01, r10, r11, r20, r21, r30, r31, r_last; -uint32_t subport_qmask;uint32_t result, i; +struct rte_mbuf_sched sch[n_pkts]; +struct rte_sched_subport *subports[n_pkts]; +struct rte_mbuf **q_base[n_pkts]; +uint32_t q[n_pkts]; + +const uint32_t subport_qmask = + (1 << (port->n_pipes_per_subport_log2 +4 )) -1 ;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
lib/librte_sched/rte_sched.c
Quoted 2 lines
lib/librte_sched/rte_sched.c +0
-1result =0 ; - subport_qmask = (1 << (port->n_pipes_per_subport_log2 +4)) - 1;
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 7 lines
lib/librte_sched/rte_sched.c +0
-6-/* -* Less then 6 input packets available, which is not enough to -* feed the pipeline -*/ -if (unlikely (n_pkts <6 )) { -struct rte_sched_subport *subports[5 ];lib/librte_sched/rte_sched.c int
Quoted 10 lines
lib/librte_sched/rte_sched.c +0
-10-struct rte_mbuf **q_base[5 ]; -uint32_t q[5 ]; - -/* Prefetch the mbuf structure of each packet */ -for (i =0 ; i < n_pkts; i++) -rte_prefetch0 (pkts[i]); - -/* Prefetch the subport structure for each packet */ -for (i =0 ; i < n_pkts; i++) - subports[i] = rte_sched_port_subport(port,pkts[i]);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_sched/rte_sched.c int
Quoted 8 lines
lib/librte_sched/rte_sched.c +0
-4- -/* Prefetch the queue structure for each queue */ -for (i =0 ; i < n_pkts; i++) - q[i] =rte_sched_port_enqueue_qptrs_prefetch0(subports[i],
lib/librte_sched/rte_sched.c +0
-3- pkts[i], subport_qmask); - -/* Prefetch the write pointer location of each queue */
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_sched/rte_sched.c +0
-2-for (i =0 ; i < n_pkts; i++) { - q_base[i] =
rte_sched_subport_pipe_qbase(subports[i], q[i]);
-rte_sched_port_enqueue_qwa_prefetch0(port,
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
lib/librte_sched/rte_sched.c int · line 1986
Quoted 7 lines
subports[i],
lib/librte_sched/rte_sched.c +3
-2- q[i], q_base[i]); - } +/* Prefetch the mbuf structure of each packet */ +for (i =0 ; i < n_pkts; i++) + sch[i] = pkts[i]->hash.sched;Hi Konstantin, thanks for the patch. In above case, all packets are
touched
Quoted 1 line
Quoted 1 line
Quoted 1 line
straight with any prefetch. If we consider the input burst size of 64 pkts,
it
Quoted 1 line
Quoted 1 line
Quoted 1 line
means 512 bytes of packet addresses (8 cache-lines) which is likely to
be
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
available in cache. For larger size burst, e.g. 128 or 256, there might be instances when some addresses are not available the cache, may stall
core.
Quoted 1 line
Quoted 1 line
Quoted 1 line
How about adding explicit prefetch before starting to iterate through
the
Quoted 4 lines
Quoted 1 line
Quoted 1 line
packets if that helps?
I don't think we need any prefetch here.
pkts[] is a sequential array, HW prefetcher should be able to do good jobhere.
Quoted 1 line
Again in majority of use-cases pkts[] contents will already present in the
cache.
Quoted 1 line
Though there is a valid concern here:
n_pktscan be big, in that case weprobably
Quoted 5 lines
don't want to store too much on the stack and read too much from pkts[]. It is better to work in some fixed chunks (64 or so).
I can prepare v2 with these changes, if there still is an interest in this patch.Quoted 1 line
Exactly. Konstantin, you might not be a fan of prefetches, but the current
enqueue implementation (as well as the dequeue) uses a prefetch
Quoted 7 lines
Quoted 1 line
state machine. Please keep the prefetch state machine in the scalar code.
It is not about our own preferences.
From my measurements new version is faster and it is definitely simpler.Quoted 2 lines
Even if the examples/qos_sched might not show an advantage, this is just a sample app and there are some more relevant use-cases as
well.
Quoted 2 lines
Well, I hope that examples/qos_sched reflects at least some real-world
Quoted 13 lines
use-cases for QOS library.
Quoted 2 lines
Otherwise why do we have it inside DPDK codebase?
About 'more relevant use-cases': if you do know such, can you try themwith the patch?
Quoted 3 lines
I would really appreciate that.
In fact, it is an ask not only to Cristian, but to all other interested parties:
if your app does uselibrte_sched- please try this patch and provide thefeedback.
Quoted 2 lines
If some tests would flag a regression - I am absolutely ok to drop the patch. Konstantin
Hi Thomas,
We are not going ahead with this at this moment.
Regards,
Cristian