From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3997AA034C; Tue, 22 Feb 2022 20:35:38 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC2AB41151; Tue, 22 Feb 2022 20:35:28 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 17C074114E for ; Tue, 22 Feb 2022 20:35:25 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21MIm8r4019939 for ; Tue, 22 Feb 2022 11:35:25 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=uxbQnZ2GhvZyO3XBiAszou3o1a83+uM3MsB0jZ4dnWs=; b=VCr578bhPsNj6TBKsrma4XfZTjJETEnCX/DOWkciJiNcPgLJj7c1VWwtw7mdSXqDXs9y VZZBwQ6hL04QARzTkkRAFBOKDYQas0wwdR9Owm9/BcNDdKvUGt+v0v6zm+dq4t7seMgp vMPL0s8V5bzRS0zuuHls2DFUUU9KmTqgxV6QXFGVic/QTb6qsVbhb+GTNcn+KHE46jIZ Un68bcEVG00V0htN+A42JA4oIgtQEtLmX8/ZsoBzoKwDKZ1S4mMuF7tI/hHbtu0SgPif 2uibpS7DXsw0AUqI0BiyBCmM4t7Je5foJ1CxglBi9NGiG2xhncFVex9gjtdRG6FjU0JS oQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3ecwaxar10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 22 Feb 2022 11:35:25 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 22 Feb 2022 11:35:23 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 22 Feb 2022 11:35:23 -0800 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id BB4553F707E; Tue, 22 Feb 2022 11:35:21 -0800 (PST) From: Nithin Dabilpuram To: , Nithin Dabilpuram , "Kiran Kumar K" , Sunil Kumar Kori , Satha Rao CC: Subject: [PATCH v2 03/21] common/cnxk: adjust shaper rates to lower boundaries Date: Wed, 23 Feb 2022 01:04:54 +0530 Message-ID: <20220222193512.19292-3-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20220222193512.19292-1-ndabilpuram@marvell.com> References: <20220207072932.22409-1-ndabilpuram@marvell.com> <20220222193512.19292-1-ndabilpuram@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: PxI8wXSF62yPP3-gGtRQs2QkLrxgR7rk X-Proofpoint-ORIG-GUID: PxI8wXSF62yPP3-gGtRQs2QkLrxgR7rk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-22_06,2022-02-21_02,2021-12-02_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Satha Rao Provide a method 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 --- 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(-) 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..bcdf990 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 the 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) -- 2.8.4