[dpdk-dev,v2] meter: fix excess token bucket update in srtcm implementation
Commit Message
As per srTCM RFC 2697, we should be updating the E bucket only after the
C bucket overflows. This patch fixes the current DPDK implementation,
where we are updating both the buckets simultaneously at the same rate
(CIR) which results in token accumulation rate of (2*CIR).
Signed-off-by: Nikhil Jagtap <nikhil.jagtap@gmail.com>
---
v2:
Removed the else part and instead added a default initialization of te.
---
lib/librte_meter/rte_meter.h | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
Comments
> -----Original Message-----
> From: Nikhil Jagtap [mailto:nikhil.jagtap@gmail.com]
> Sent: Wednesday, September 21, 2016 6:58 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org; Ramia, Kannan Babu <kannan.babu.ramia@intel.com>;
> Nikhil Jagtap <nikhil.jagtap@gmail.com>
> Subject: [PATCH v2] meter: fix excess token bucket update in srtcm
> implementation
>
> As per srTCM RFC 2697, we should be updating the E bucket only after the
> C bucket overflows. This patch fixes the current DPDK implementation,
> where we are updating both the buckets simultaneously at the same rate
> (CIR) which results in token accumulation rate of (2*CIR).
>
> Signed-off-by: Nikhil Jagtap <nikhil.jagtap@gmail.com>
> ---
>
> v2:
> Removed the else part and instead added a default initialization of te.
>
> ---
> lib/librte_meter/rte_meter.h | 24 ++++++++++++++----------
> 1 files changed, 14 insertions(+), 10 deletions(-)
>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Thanks, Nikhil!
> > As per srTCM RFC 2697, we should be updating the E bucket only after the
> > C bucket overflows. This patch fixes the current DPDK implementation,
> > where we are updating both the buckets simultaneously at the same rate
> > (CIR) which results in token accumulation rate of (2*CIR).
> >
> > Signed-off-by: Nikhil Jagtap <nikhil.jagtap@gmail.com>
>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Applied, thanks
@@ -232,13 +232,15 @@ rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
n_periods = time_diff / m->cir_period;
m->time += n_periods * m->cir_period;
+ /* Put the tokens overflowing from tc into te bucket */
tc = m->tc + n_periods * m->cir_bytes_per_period;
- if (tc > m->cbs)
+ te = m->te;
+ if (tc > m->cbs) {
+ te += (tc - m->cbs);
+ if (te > m->ebs)
+ te = m->ebs;
tc = m->cbs;
-
- te = m->te + n_periods * m->cir_bytes_per_period;
- if (te > m->ebs)
- te = m->ebs;
+ }
/* Color logic */
if (tc >= pkt_len) {
@@ -271,13 +273,15 @@ rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
n_periods = time_diff / m->cir_period;
m->time += n_periods * m->cir_period;
+ /* Put the tokens overflowing from tc into te bucket */
tc = m->tc + n_periods * m->cir_bytes_per_period;
- if (tc > m->cbs)
+ te = m->te;
+ if (tc > m->cbs) {
+ te += (tc - m->cbs);
+ if (te > m->ebs)
+ te = m->ebs;
tc = m->cbs;
-
- te = m->te + n_periods * m->cir_bytes_per_period;
- if (te > m->ebs)
- te = m->ebs;
+ }
/* Color logic */
if ((pkt_color == e_RTE_METER_GREEN) && (tc >= pkt_len)) {