[03/20] common/cnxk: adjust shaper rates to lower boundaries

Message ID 20220207072932.22409-3-ndabilpuram@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series [01/20] common/cnxk: increase resource count for bitmap alloc |

Commit Message

Nithin Dabilpuram Feb. 7, 2022, 7:29 a.m. UTC
  From: Satha Rao <skoteshwar@marvell.com>

New api to get floor values for a requested shaper rate, which can assure
packets should never be transmitted at a rate higher than configured.

Keep the old api to get HW suggested values.
And introduce new parameter to select appropriate api.

Signed-off-by: Satha Rao <skoteshwar@marvell.com>
---
 drivers/common/cnxk/roc_nix.h          |  1 +
 drivers/common/cnxk/roc_nix_priv.h     |  4 +-
 drivers/common/cnxk/roc_nix_tm_ops.c   | 10 ++--
 drivers/common/cnxk/roc_nix_tm_utils.c | 90 ++++++++++++++++++++++++++++++++--
 4 files changed, 96 insertions(+), 9 deletions(-)
  

Comments

Jerin Jacob Feb. 17, 2022, 1:20 p.m. UTC | #1
On Mon, Feb 7, 2022 at 1:00 PM Nithin Dabilpuram
<ndabilpuram@marvell.com> wrote:
>
> From: Satha Rao <skoteshwar@marvell.com>
>
> New api to get floor values for a requested shaper rate, which can assure

Since it is internal API, no need to mention in the comment log

> packets should never be transmitted at a rate higher than configured.
>
> Keep the old api to get HW suggested values.
> And introduce new parameter to select appropriate api.

api -> API

>
> Signed-off-by: Satha Rao <skoteshwar@marvell.com>
> ---
> +static uint64_t
> +nix_tm_shaper_rate_conv_floor(uint64_t value, uint64_t *exponent_p,
> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
> +{
> +       uint64_t div_exp, exponent, mantissa;
> +
> +       /* Boundary checks */
> +       if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE)
> +               return 0;
> +
> +       if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) {
> +               /* Calculate rate div_exp and mantissa using
> +                * the following formula:
> +                *
> +                * value = (2E6 * (256 + mantissa)
> +                *              / ((1 << div_exp) * 256))
> +                */
> +               div_exp = 0;
> +               exponent = 0;
> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
> +
> +               while (value <= (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp)))
> +                       div_exp += 1;
> +
> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) /
> +                                ((1 << div_exp) * 256)))
> +                       mantissa -= 1;

Please move this as another static function.


> +       } else {
> +               /* Calculate rate exponent and mantissa using
> +                * the following formula:
> +                *
> +                * value = (2E6 * ((256 + mantissa) << exponent)) / 256
> +                *
> +                */
> +               div_exp = 0;
> +               exponent = NIX_TM_MAX_RATE_EXPONENT;
> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
> +
> +               while (value <= (NIX_TM_SHAPER_RATE_CONST * (1 << exponent)))
> +                       exponent -= 1;
> +
> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST *
> +                                 ((256 + mantissa) << exponent)) /
> +                                256))
> +                       mantissa -= 1;

Please move this as another static function.

> +       }
> +
> +       if (div_exp > NIX_TM_MAX_RATE_DIV_EXP ||
> +           exponent > NIX_TM_MAX_RATE_EXPONENT ||
> +           mantissa > NIX_TM_MAX_RATE_MANTISSA)
> +               return 0;
> +
> +       if (div_exp_p)
> +               *div_exp_p = div_exp;
> +       if (exponent_p)
> +               *exponent_p = exponent;
> +       if (mantissa_p)
> +               *mantissa_p = mantissa;
> +
> +       /* Calculate real rate value */
> +       return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
> +}
> +
> +static uint64_t
> +nix_tm_shaper_rate_conv_exact(uint64_t value, uint64_t *exponent_p,
> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
>  {
>         uint64_t div_exp, exponent, mantissa;
>
> @@ -188,6 +251,23 @@ nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
>         return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
>  }
>
> +/* With zero accuracy we will tune parameters as defined by HW,
> + * non zero accuracy will keep the parameters close to lower values
> + * and make sure long term shaper rate will not exceed requested rate.

long-term
requested -> the requested
  
Nithin Dabilpuram Feb. 22, 2022, 6:19 p.m. UTC | #2
Please see inline.

On 2/17/22 6:50 PM, Jerin Jacob wrote:
> On Mon, Feb 7, 2022 at 1:00 PM Nithin Dabilpuram
> <ndabilpuram@marvell.com> wrote:
>>
>> From: Satha Rao <skoteshwar@marvell.com>
>>
>> New api to get floor values for a requested shaper rate, which can assure
> 
> Since it is internal API, no need to mention in the comment log
> 
>> packets should never be transmitted at a rate higher than configured.
>>
>> Keep the old api to get HW suggested values.
>> And introduce new parameter to select appropriate api.
> 
> api -> API
> 
>>
>> Signed-off-by: Satha Rao <skoteshwar@marvell.com>
>> ---
>> +static uint64_t
>> +nix_tm_shaper_rate_conv_floor(uint64_t value, uint64_t *exponent_p,
>> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
>> +{
>> +       uint64_t div_exp, exponent, mantissa;
>> +
>> +       /* Boundary checks */
>> +       if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE)
>> +               return 0;
>> +
>> +       if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) {
>> +               /* Calculate rate div_exp and mantissa using
>> +                * the following formula:
>> +                *
>> +                * value = (2E6 * (256 + mantissa)
>> +                *              / ((1 << div_exp) * 256))
>> +                */
>> +               div_exp = 0;
>> +               exponent = 0;
>> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
>> +
>> +               while (value <= (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp)))
>> +                       div_exp += 1;
>> +
>> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) /
>> +                                ((1 << div_exp) * 256)))
>> +                       mantissa -= 1;
> 
> Please move this as another static function.
This is not same as the non-floor function though it looks same. The 
while loops terminate in <= in this function. Do you still need sub 
functions for these ?
> 
> 
>> +       } else {
>> +               /* Calculate rate exponent and mantissa using
>> +                * the following formula:
>> +                *
>> +                * value = (2E6 * ((256 + mantissa) << exponent)) / 256
>> +                *
>> +                */
>> +               div_exp = 0;
>> +               exponent = NIX_TM_MAX_RATE_EXPONENT;
>> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
>> +
>> +               while (value <= (NIX_TM_SHAPER_RATE_CONST * (1 << exponent)))
>> +                       exponent -= 1;
>> +
>> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST *
>> +                                 ((256 + mantissa) << exponent)) /
>> +                                256))
>> +                       mantissa -= 1;
> 
> Please move this as another static function.
Same comment as above.
> 
>> +       }
>> +
>> +       if (div_exp > NIX_TM_MAX_RATE_DIV_EXP ||
>> +           exponent > NIX_TM_MAX_RATE_EXPONENT ||
>> +           mantissa > NIX_TM_MAX_RATE_MANTISSA)
>> +               return 0;
>> +
>> +       if (div_exp_p)
>> +               *div_exp_p = div_exp;
>> +       if (exponent_p)
>> +               *exponent_p = exponent;
>> +       if (mantissa_p)
>> +               *mantissa_p = mantissa;
>> +
>> +       /* Calculate real rate value */
>> +       return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
>> +}
>> +
>> +static uint64_t
>> +nix_tm_shaper_rate_conv_exact(uint64_t value, uint64_t *exponent_p,
>> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
>>   {
>>          uint64_t div_exp, exponent, mantissa;
>>
>> @@ -188,6 +251,23 @@ nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
>>          return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
>>   }
>>
>> +/* With zero accuracy we will tune parameters as defined by HW,
>> + * non zero accuracy will keep the parameters close to lower values
>> + * and make sure long term shaper rate will not exceed requested rate.
> 
> long-term
> requested -> the requested
  
Jerin Jacob Feb. 22, 2022, 6:21 p.m. UTC | #3
On Tue, Feb 22, 2022 at 11:49 PM Nithin Kumar Dabilpuram
<ndabilpuram@marvell.com> wrote:
>
> Please see inline.
>
> On 2/17/22 6:50 PM, Jerin Jacob wrote:
> > On Mon, Feb 7, 2022 at 1:00 PM Nithin Dabilpuram
> > <ndabilpuram@marvell.com> wrote:
> >>
> >> From: Satha Rao <skoteshwar@marvell.com>
> >>
> >> New api to get floor values for a requested shaper rate, which can assure
> >
> > Since it is internal API, no need to mention in the comment log
> >
> >> packets should never be transmitted at a rate higher than configured.
> >>
> >> Keep the old api to get HW suggested values.
> >> And introduce new parameter to select appropriate api.
> >
> > api -> API
> >
> >>
> >> Signed-off-by: Satha Rao <skoteshwar@marvell.com>
> >> ---
> >> +static uint64_t
> >> +nix_tm_shaper_rate_conv_floor(uint64_t value, uint64_t *exponent_p,
> >> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
> >> +{
> >> +       uint64_t div_exp, exponent, mantissa;
> >> +
> >> +       /* Boundary checks */
> >> +       if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE)
> >> +               return 0;
> >> +
> >> +       if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) {
> >> +               /* Calculate rate div_exp and mantissa using
> >> +                * the following formula:
> >> +                *
> >> +                * value = (2E6 * (256 + mantissa)
> >> +                *              / ((1 << div_exp) * 256))
> >> +                */
> >> +               div_exp = 0;
> >> +               exponent = 0;
> >> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
> >> +
> >> +               while (value <= (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp)))
> >> +                       div_exp += 1;
> >> +
> >> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) /
> >> +                                ((1 << div_exp) * 256)))
> >> +                       mantissa -= 1;
> >
> > Please move this as another static function.
> This is not same as the non-floor function though it looks same. The
> while loops terminate in <= in this function. Do you still need sub
> functions for these ?

No. It is fine.

> >
> >
> >> +       } else {
> >> +               /* Calculate rate exponent and mantissa using
> >> +                * the following formula:
> >> +                *
> >> +                * value = (2E6 * ((256 + mantissa) << exponent)) / 256
> >> +                *
> >> +                */
> >> +               div_exp = 0;
> >> +               exponent = NIX_TM_MAX_RATE_EXPONENT;
> >> +               mantissa = NIX_TM_MAX_RATE_MANTISSA;
> >> +
> >> +               while (value <= (NIX_TM_SHAPER_RATE_CONST * (1 << exponent)))
> >> +                       exponent -= 1;
> >> +
> >> +               while (value <= ((NIX_TM_SHAPER_RATE_CONST *
> >> +                                 ((256 + mantissa) << exponent)) /
> >> +                                256))
> >> +                       mantissa -= 1;
> >
> > Please move this as another static function.
> Same comment as above.
> >
> >> +       }
> >> +
> >> +       if (div_exp > NIX_TM_MAX_RATE_DIV_EXP ||
> >> +           exponent > NIX_TM_MAX_RATE_EXPONENT ||
> >> +           mantissa > NIX_TM_MAX_RATE_MANTISSA)
> >> +               return 0;
> >> +
> >> +       if (div_exp_p)
> >> +               *div_exp_p = div_exp;
> >> +       if (exponent_p)
> >> +               *exponent_p = exponent;
> >> +       if (mantissa_p)
> >> +               *mantissa_p = mantissa;
> >> +
> >> +       /* Calculate real rate value */
> >> +       return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
> >> +}
> >> +
> >> +static uint64_t
> >> +nix_tm_shaper_rate_conv_exact(uint64_t value, uint64_t *exponent_p,
> >> +                             uint64_t *mantissa_p, uint64_t *div_exp_p)
> >>   {
> >>          uint64_t div_exp, exponent, mantissa;
> >>
> >> @@ -188,6 +251,23 @@ nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
> >>          return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
> >>   }
> >>
> >> +/* With zero accuracy we will tune parameters as defined by HW,
> >> + * non zero accuracy will keep the parameters close to lower values
> >> + * and make sure long term shaper rate will not exceed requested rate.
> >
> > long-term
> > requested -> the requested
  

Patch

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 755212c..250e1c0 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -531,6 +531,7 @@  struct roc_nix_tm_shaper_profile {
 	uint64_t peak_sz;
 	int32_t pkt_len_adj;
 	bool pkt_mode;
+	int8_t accuracy;
 	/* Function to free this memory */
 	void (*free_fn)(void *profile);
 };
diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h
index 4d2a7d8..ec6f106 100644
--- a/drivers/common/cnxk/roc_nix_priv.h
+++ b/drivers/common/cnxk/roc_nix_priv.h
@@ -95,6 +95,7 @@  struct nix_tm_shaper_profile {
 	int32_t pkt_mode_adj;
 	bool pkt_mode;
 	uint32_t id;
+	int8_t accuracy;
 	void (*free_fn)(void *profile);
 
 	uint32_t ref_cnt;
@@ -399,7 +400,8 @@  uint32_t nix_tm_check_rr(struct nix *nix, uint32_t parent_id,
 			 uint32_t *max_prio);
 uint64_t nix_tm_shaper_profile_rate_min(struct nix *nix);
 uint64_t nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
-				 uint64_t *mantissa_p, uint64_t *div_exp_p);
+				 uint64_t *mantissa_p, uint64_t *div_exp_p,
+				 int8_t accuracy);
 uint64_t nix_tm_shaper_burst_conv(uint64_t value, uint64_t *exponent_p,
 				  uint64_t *mantissa_p);
 bool nix_tm_child_res_valid(struct nix_tm_node_list *list,
diff --git a/drivers/common/cnxk/roc_nix_tm_ops.c b/drivers/common/cnxk/roc_nix_tm_ops.c
index 3d81247..a1f5f0e 100644
--- a/drivers/common/cnxk/roc_nix_tm_ops.c
+++ b/drivers/common/cnxk/roc_nix_tm_ops.c
@@ -173,8 +173,8 @@  nix_tm_shaper_profile_add(struct roc_nix *roc_nix,
 	if (commit_rate || commit_sz) {
 		if (commit_sz < min_burst || commit_sz > max_burst)
 			return NIX_ERR_TM_INVALID_COMMIT_SZ;
-		else if (!nix_tm_shaper_rate_conv(commit_rate, NULL, NULL,
-						  NULL))
+		else if (!nix_tm_shaper_rate_conv(commit_rate, NULL, NULL, NULL,
+						  profile->accuracy))
 			return NIX_ERR_TM_INVALID_COMMIT_RATE;
 	}
 
@@ -182,7 +182,8 @@  nix_tm_shaper_profile_add(struct roc_nix *roc_nix,
 	if (peak_sz || peak_rate) {
 		if (peak_sz < min_burst || peak_sz > max_burst)
 			return NIX_ERR_TM_INVALID_PEAK_SZ;
-		else if (!nix_tm_shaper_rate_conv(peak_rate, NULL, NULL, NULL))
+		else if (!nix_tm_shaper_rate_conv(peak_rate, NULL, NULL, NULL,
+						  profile->accuracy))
 			return NIX_ERR_TM_INVALID_PEAK_RATE;
 	}
 
@@ -230,6 +231,7 @@  roc_nix_tm_shaper_profile_add(struct roc_nix *roc_nix,
 	profile->pkt_len_adj = roc_profile->pkt_len_adj;
 	profile->pkt_mode = roc_profile->pkt_mode;
 	profile->free_fn = roc_profile->free_fn;
+	profile->accuracy = roc_profile->accuracy;
 
 	return nix_tm_shaper_profile_add(roc_nix, profile, 0);
 }
@@ -246,6 +248,8 @@  roc_nix_tm_shaper_profile_update(struct roc_nix *roc_nix,
 	profile->peak.rate = roc_profile->peak_rate;
 	profile->commit.size = roc_profile->commit_sz;
 	profile->peak.size = roc_profile->peak_sz;
+	profile->pkt_len_adj = roc_profile->pkt_len_adj;
+	profile->accuracy = roc_profile->accuracy;
 
 	return nix_tm_shaper_profile_add(roc_nix, profile, 1);
 }
diff --git a/drivers/common/cnxk/roc_nix_tm_utils.c b/drivers/common/cnxk/roc_nix_tm_utils.c
index 9e80c2a..4ba0752 100644
--- a/drivers/common/cnxk/roc_nix_tm_utils.c
+++ b/drivers/common/cnxk/roc_nix_tm_utils.c
@@ -125,9 +125,72 @@  nix_tm_node_search(struct nix *nix, uint32_t node_id, enum roc_nix_tm_tree tree)
 	return NULL;
 }
 
-uint64_t
-nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
-			uint64_t *mantissa_p, uint64_t *div_exp_p)
+static uint64_t
+nix_tm_shaper_rate_conv_floor(uint64_t value, uint64_t *exponent_p,
+			      uint64_t *mantissa_p, uint64_t *div_exp_p)
+{
+	uint64_t div_exp, exponent, mantissa;
+
+	/* Boundary checks */
+	if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE)
+		return 0;
+
+	if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) {
+		/* Calculate rate div_exp and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * (256 + mantissa)
+		 *              / ((1 << div_exp) * 256))
+		 */
+		div_exp = 0;
+		exponent = 0;
+		mantissa = NIX_TM_MAX_RATE_MANTISSA;
+
+		while (value <= (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp)))
+			div_exp += 1;
+
+		while (value <= ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) /
+				 ((1 << div_exp) * 256)))
+			mantissa -= 1;
+	} else {
+		/* Calculate rate exponent and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
+		 *
+		 */
+		div_exp = 0;
+		exponent = NIX_TM_MAX_RATE_EXPONENT;
+		mantissa = NIX_TM_MAX_RATE_MANTISSA;
+
+		while (value <= (NIX_TM_SHAPER_RATE_CONST * (1 << exponent)))
+			exponent -= 1;
+
+		while (value <= ((NIX_TM_SHAPER_RATE_CONST *
+				  ((256 + mantissa) << exponent)) /
+				 256))
+			mantissa -= 1;
+	}
+
+	if (div_exp > NIX_TM_MAX_RATE_DIV_EXP ||
+	    exponent > NIX_TM_MAX_RATE_EXPONENT ||
+	    mantissa > NIX_TM_MAX_RATE_MANTISSA)
+		return 0;
+
+	if (div_exp_p)
+		*div_exp_p = div_exp;
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	/* Calculate real rate value */
+	return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
+}
+
+static uint64_t
+nix_tm_shaper_rate_conv_exact(uint64_t value, uint64_t *exponent_p,
+			      uint64_t *mantissa_p, uint64_t *div_exp_p)
 {
 	uint64_t div_exp, exponent, mantissa;
 
@@ -188,6 +251,23 @@  nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
 	return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
 }
 
+/* With zero accuracy we will tune parameters as defined by HW,
+ * non zero accuracy will keep the parameters close to lower values
+ * and make sure long term shaper rate will not exceed requested rate.
+ */
+uint64_t
+nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
+			uint64_t *mantissa_p, uint64_t *div_exp_p,
+			int8_t accuracy)
+{
+	if (!accuracy)
+		return nix_tm_shaper_rate_conv_exact(value, exponent_p,
+						     mantissa_p, div_exp_p);
+
+	return nix_tm_shaper_rate_conv_floor(value, exponent_p, mantissa_p,
+					     div_exp_p);
+}
+
 uint64_t
 nix_tm_shaper_burst_conv(uint64_t value, uint64_t *exponent_p,
 			 uint64_t *mantissa_p)
@@ -245,13 +325,13 @@  nix_tm_shaper_conf_get(struct nix_tm_shaper_profile *profile,
 	if (profile->commit.rate)
 		cir->rate = nix_tm_shaper_rate_conv(
 			profile->commit.rate, &cir->exponent, &cir->mantissa,
-			&cir->div_exp);
+			&cir->div_exp, profile->accuracy);
 
 	/* Calculate PIR exponent and mantissa */
 	if (profile->peak.rate)
 		pir->rate = nix_tm_shaper_rate_conv(
 			profile->peak.rate, &pir->exponent, &pir->mantissa,
-			&pir->div_exp);
+			&pir->div_exp, profile->accuracy);
 
 	/* Calculate CIR burst exponent and mantissa */
 	if (profile->commit.size)