DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Eelco Chaudron" <echaudro@redhat.com>
To: "Dumitrescu, Cristian" <cristian.dumitrescu@intel.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v3 1/2] lib/librte_meter: add RFC4115 trTCM meter support
Date: Fri, 04 Jan 2019 15:03:10 +0100	[thread overview]
Message-ID: <EDDB3D8F-CDD5-4E71-A5B3-08D51F571A35@redhat.com> (raw)
In-Reply-To: <3EB4FA525960D640B5BDFFD6A3D891268E81857C@IRSMSX108.ger.corp.intel.com>



On 21 Dec 2018, at 17:15, Dumitrescu, Cristian wrote:

> 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

Asking all comments, sent out a V4.

//Eelco

  reply	other threads:[~2019-01-04 14:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-18 15:38 [dpdk-dev] [PATCH v3 0/2] " Eelco Chaudron
2018-12-18 15:38 ` [dpdk-dev] [PATCH v3 1/2] " Eelco Chaudron
2018-12-21 16:15   ` Dumitrescu, Cristian
2019-01-04 14:03     ` Eelco Chaudron [this message]
2018-12-18 15:38 ` [dpdk-dev] [PATCH v3 2/2] test/test_meter: update meter test to include RFC4115 meters Eelco Chaudron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EDDB3D8F-CDD5-4E71-A5B3-08D51F571A35@redhat.com \
    --to=echaudro@redhat.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).