[dpdk-dev] [PATCH v3 1/2] lib/librte_meter: add RFC4115 trTCM meter support

Dumitrescu, Cristian cristian.dumitrescu at intel.com
Fri Dec 21 17:15:53 CET 2018


Hi Eelco,

<snip>

> 
> +/** trTCM parameters per metered traffic flow. The CIR, EIT, CBS and EBS

Small typo here: EIT to be replaced by EIR.

> +parameters only count bytes of IP packets and do not include link specific
> +headers. The CBS and EBS need to be greater than zero if CIR and EIR are
> +none-zero respectively.*/
> +struct rte_meter_trtcm_rfc4115_params {
> +	uint64_t cir; /**< Committed Information Rate (CIR). Measured in
> bytes per second. */
> +	uint64_t eir; /**< Excess Information Rate (EIR). Measured in bytes
> per second. */
> +	uint64_t cbs; /**< Committed Burst Size (CBS). Measured in bytes.
> */
> +	uint64_t ebs; /**< Excess Burst Size (EBS). Measured in bytes. */
> +};
> +

<snip>

> +static inline enum rte_meter_color __rte_experimental
> +rte_meter_trtcm_rfc4115_color_blind_check(
> +	struct rte_meter_trtcm_rfc4115 *m,
> +	struct rte_meter_trtcm_rfc4115_profile *p,
> +	uint64_t time,
> +	uint32_t pkt_len)
> +{
> +	uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc,
> te;
> +
> +	/* Bucket update */
> +	time_diff_tc = time - m->time_tc;
> +	time_diff_te = time - m->time_te;
> +	n_periods_tc = time_diff_tc / p->cir_period;
> +	n_periods_te = time_diff_te / p->eir_period;
> +	m->time_tc += n_periods_tc * p->cir_period;
> +	m->time_te += n_periods_te * p->eir_period;
> +
> +	tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
> +	if (tc > p->cbs)
> +		tc = p->cbs;
> +
> +	te = m->te + n_periods_te * p->eir_bytes_per_period;
> +	if (te > p->ebs)
> +		te = p->ebs;
> +
> +	/* Color logic */
> +	if (tc >= pkt_len) {
> +		m->tc = tc - pkt_len;
> +		m->te = te;
> +		return e_RTE_METER_GREEN;
> +	} else if (te >= pkt_len) {
> +		m->tc = tc;
> +		m->te = te - pkt_len;
> +		return e_RTE_METER_YELLOW;
> +	}
> +
> +	/* If we end up here the color is RED */
> +	m->tc = tc;
> +	m->te = te;
> +	return e_RTE_METER_RED;
> +}
> +

Since the branch (tc >= pkt_len) == TRUE always returns, I suggest we remove the following "else", as it is redundant:

	/* Color logic */
	if (tc >= pkt_len) {
		m->tc = tc - pkt_len;
		m->te = te;
		return e_RTE_METER_GREEN;
	}

	if (te >= pkt_len) {
		m->tc = tc;
		m->te = te - pkt_len;
		return e_RTE_METER_YELLOW;
	}

	/* If we end up here the color is RED */
	m->tc = tc;
	m->te = te;
	return e_RTE_METER_RED;


> +static inline enum rte_meter_color __rte_experimental
> +rte_meter_trtcm_rfc4115_color_aware_check(
> +	struct rte_meter_trtcm_rfc4115 *m,
> +	struct rte_meter_trtcm_rfc4115_profile *p,
> +	uint64_t time,
> +	uint32_t pkt_len,
> +	enum rte_meter_color pkt_color)
> +{
> +	uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc,
> te;
> +
> +	/* Bucket update */
> +	time_diff_tc = time - m->time_tc;
> +	time_diff_te = time - m->time_te;
> +	n_periods_tc = time_diff_tc / p->cir_period;
> +	n_periods_te = time_diff_te / p->eir_period;
> +	m->time_tc += n_periods_tc * p->cir_period;
> +	m->time_te += n_periods_te * p->eir_period;
> +
> +	tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
> +	if (tc > p->cbs)
> +		tc = p->cbs;
> +
> +	te = m->te + n_periods_te * p->eir_bytes_per_period;
> +	if (te > p->ebs)
> +		te = p->ebs;
> +
> +	/* Color logic */
> +	if (pkt_color == e_RTE_METER_GREEN) {
> +		if (tc >= pkt_len) {
> +			m->tc = tc - pkt_len;
> +			m->te = te;
> +			return e_RTE_METER_GREEN;
> +		} else if (te >= pkt_len) {
> +			m->tc = tc;
> +			m->te = te - pkt_len;
> +			return e_RTE_METER_YELLOW;
> +		}
> +	} else if (pkt_color == e_RTE_METER_YELLOW && te >= pkt_len) {
> +		m->tc = tc;
> +		m->te = te - pkt_len;
> +		return e_RTE_METER_YELLOW;
> +	}
> +
> +	/* If we end up here the color is RED */
> +	m->tc = tc;
> +	m->te = te;
> +	return e_RTE_METER_RED;
> +}
> +
> +

I suggest we follow the logic from the diagram in the RFC rather than the logic in the text preceding the diagram. Although the two descriptions are equivalent (after a bit of thinking), the diagram seems more optimal to me:

	/* Color logic */
	if ((pkt_color == e_RTE_METER_GREEN) && (tc >= pkt_len)) {
		m->tc = tc - pkt_len;
		m->te = te;
		return e_RTE_METER_GREEN;
	}

	if ((pkt_color != e_RTE_METER_RED) && (te >= pkt_len)) {
		m->tc = tc;
		m->te = te - pkt_len;
		return e_RTE_METER_YELLOW;
	}

	/* If we end up here the color is RED */
	m->tc = tc;
	m->te = te;
	return e_RTE_METER_RED;

<snip>

Thanks,
Cristian



More information about the dev mailing list