All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guangbin Huang <huangguangbin2@huawei.com>
To: <davem@davemloft.net>, <kuba@kernel.org>
Cc: <edumazet@google.com>, <pabeni@redhat.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<huangguangbin2@huawei.com>, <lipeng321@huawei.com>,
	<lanhao@huawei.com>, <shenjian15@huawei.com>
Subject: [PATCH net-next 2/4] net: hns3: optimize converting dscp to priority process of hns3_nic_select_queue()
Date: Fri, 16 Sep 2022 10:38:01 +0800	[thread overview]
Message-ID: <20220916023803.23756-3-huangguangbin2@huawei.com> (raw)
In-Reply-To: <20220916023803.23756-1-huangguangbin2@huawei.com>

Currently, when function hns3_nic_select_queue() converts dscp to priority,
it calls an indirect callback ae_algo->ops->get_dscp_prio to get priority.

However as function hns3_nic_select_queue() is in fast path, the indirect
call may cause degradation of performance. For optimization, this patch
moves dscp_app_cnt and dscp_prio from struct hclge_tm_info to struct
hnae3_knic_private_info, so they can be used in both hclge and hns3 layers.

Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   |  4 +++
 .../net/ethernet/hisilicon/hns3/hns3_enet.c   | 13 ++++-----
 .../hisilicon/hns3/hns3pf/hclge_dcb.c         | 28 +++++++++----------
 .../hisilicon/hns3/hns3pf/hclge_debugfs.c     | 17 +++++------
 .../hisilicon/hns3/hns3pf/hclge_main.c        | 11 +++-----
 .../hisilicon/hns3/hns3pf/hclge_main.h        |  4 ---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 18 ++++++------
 7 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 30a76f44a819..0179fc288f5f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -798,6 +798,8 @@ struct hnae3_tc_info {
 	bool mqprio_active;
 };
 
+#define HNAE3_MAX_DSCP			64
+#define HNAE3_PRIO_ID_INVALID		0xff
 struct hnae3_knic_private_info {
 	struct net_device *netdev; /* Set by KNIC client when init instance */
 	u16 rss_size;		   /* Allocated RSS queues */
@@ -809,6 +811,8 @@ struct hnae3_knic_private_info {
 
 	struct hnae3_tc_info tc_info;
 	u8 tc_map_mode;
+	u8 dscp_app_cnt;
+	u8 dscp_prio[HNAE3_MAX_DSCP];
 
 	u16 num_tqps;		  /* total number of TQPs in this handle */
 	struct hnae3_queue **tqp;  /* array base of all TQPs in this instance */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index db099549e511..39b75b68474c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2987,22 +2987,19 @@ static u16 hns3_nic_select_queue(struct net_device *netdev,
 				 struct net_device *sb_dev)
 {
 	struct hnae3_handle *h = hns3_get_handle(netdev);
-	u8 dscp, priority;
-	int ret;
+	u8 dscp;
 
 	if (h->kinfo.tc_map_mode != HNAE3_TC_MAP_MODE_DSCP ||
 	    !h->ae_algo->ops->get_dscp_prio)
 		goto out;
 
 	dscp = hns3_get_skb_dscp(skb);
-	if (unlikely(dscp == HNS3_INVALID_DSCP))
-		goto out;
-
-	ret = h->ae_algo->ops->get_dscp_prio(h, dscp, NULL, &priority);
-	if (ret)
+	if (unlikely(dscp >= HNAE3_MAX_DSCP))
 		goto out;
 
-	skb->priority = priority;
+	skb->priority = h->kinfo.dscp_prio[dscp];
+	if (skb->priority == HNAE3_PRIO_ID_INVALID)
+		skb->priority = 0;
 
 out:
 	return netdev_pick_tx(netdev, skb, sb_dev);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
index fbb159f48b6c..c4aded65e848 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
@@ -368,14 +368,14 @@ static int hclge_ieee_setapp(struct hnae3_handle *h, struct dcb_app *app)
 	int ret;
 
 	if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP ||
-	    app->protocol >= HCLGE_MAX_DSCP ||
+	    app->protocol >= HNAE3_MAX_DSCP ||
 	    app->priority >= HNAE3_MAX_USER_PRIO)
 		return -EINVAL;
 
 	dev_info(&hdev->pdev->dev, "setapp dscp=%u priority=%u\n",
 		 app->protocol, app->priority);
 
-	if (app->priority == hdev->tm_info.dscp_prio[app->protocol])
+	if (app->priority == h->kinfo.dscp_prio[app->protocol])
 		return 0;
 
 	ret = dcb_ieee_setapp(netdev, app);
@@ -384,21 +384,21 @@ static int hclge_ieee_setapp(struct hnae3_handle *h, struct dcb_app *app)
 
 	old_app.selector = IEEE_8021QAZ_APP_SEL_DSCP;
 	old_app.protocol = app->protocol;
-	old_app.priority = hdev->tm_info.dscp_prio[app->protocol];
+	old_app.priority = h->kinfo.dscp_prio[app->protocol];
 
-	hdev->tm_info.dscp_prio[app->protocol] = app->priority;
+	h->kinfo.dscp_prio[app->protocol] = app->priority;
 	ret = hclge_dscp_to_tc_map(hdev);
 	if (ret) {
 		dev_err(&hdev->pdev->dev,
 			"failed to set dscp to tc map, ret = %d\n", ret);
-		hdev->tm_info.dscp_prio[app->protocol] = old_app.priority;
+		h->kinfo.dscp_prio[app->protocol] = old_app.priority;
 		(void)dcb_ieee_delapp(netdev, app);
 		return ret;
 	}
 
 	vport->nic.kinfo.tc_map_mode = HNAE3_TC_MAP_MODE_DSCP;
-	if (old_app.priority == HCLGE_PRIO_ID_INVALID)
-		hdev->tm_info.dscp_app_cnt++;
+	if (old_app.priority == HNAE3_PRIO_ID_INVALID)
+		h->kinfo.dscp_app_cnt++;
 	else
 		ret = dcb_ieee_delapp(netdev, &old_app);
 
@@ -413,9 +413,9 @@ static int hclge_ieee_delapp(struct hnae3_handle *h, struct dcb_app *app)
 	int ret;
 
 	if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP ||
-	    app->protocol >= HCLGE_MAX_DSCP ||
+	    app->protocol >= HNAE3_MAX_DSCP ||
 	    app->priority >= HNAE3_MAX_USER_PRIO ||
-	    app->priority != hdev->tm_info.dscp_prio[app->protocol])
+	    app->priority != h->kinfo.dscp_prio[app->protocol])
 		return -EINVAL;
 
 	dev_info(&hdev->pdev->dev, "delapp dscp=%u priority=%u\n",
@@ -425,20 +425,20 @@ static int hclge_ieee_delapp(struct hnae3_handle *h, struct dcb_app *app)
 	if (ret)
 		return ret;
 
-	hdev->tm_info.dscp_prio[app->protocol] = HCLGE_PRIO_ID_INVALID;
+	h->kinfo.dscp_prio[app->protocol] = HNAE3_PRIO_ID_INVALID;
 	ret = hclge_dscp_to_tc_map(hdev);
 	if (ret) {
 		dev_err(&hdev->pdev->dev,
 			"failed to del dscp to tc map, ret = %d\n", ret);
-		hdev->tm_info.dscp_prio[app->protocol] = app->priority;
+		h->kinfo.dscp_prio[app->protocol] = app->priority;
 		(void)dcb_ieee_setapp(netdev, app);
 		return ret;
 	}
 
-	if (hdev->tm_info.dscp_app_cnt)
-		hdev->tm_info.dscp_app_cnt--;
+	if (h->kinfo.dscp_app_cnt)
+		h->kinfo.dscp_app_cnt--;
 
-	if (!hdev->tm_info.dscp_app_cnt) {
+	if (!h->kinfo.dscp_app_cnt) {
 		vport->nic.kinfo.tc_map_mode = HNAE3_TC_MAP_MODE_PRIO;
 		ret = hclge_up_to_tc_map(hdev);
 	}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 55f696d071e5..142415c84c6b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -1158,17 +1158,18 @@ static int hclge_dbg_dump_qos_pri_map(struct hclge_dev *hdev, char *buf,
 static int hclge_dbg_dump_qos_dscp_map(struct hclge_dev *hdev, char *buf,
 				       int len)
 {
+	struct hnae3_knic_private_info *kinfo = &hdev->vport[0].nic.kinfo;
 	struct hclge_desc desc[HCLGE_DSCP_MAP_TC_BD_NUM];
 	u8 *req0 = (u8 *)desc[0].data;
 	u8 *req1 = (u8 *)desc[1].data;
-	u8 dscp_tc[HCLGE_MAX_DSCP];
+	u8 dscp_tc[HNAE3_MAX_DSCP];
 	int pos, ret;
 	u8 i, j;
 
 	pos = scnprintf(buf, len, "tc map mode: %s\n",
-			tc_map_mode_str[hdev->vport[0].nic.kinfo.tc_map_mode]);
+			tc_map_mode_str[kinfo->tc_map_mode]);
 
-	if (hdev->vport[0].nic.kinfo.tc_map_mode != HNAE3_TC_MAP_MODE_DSCP)
+	if (kinfo->tc_map_mode != HNAE3_TC_MAP_MODE_DSCP)
 		return 0;
 
 	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_QOS_MAP, true);
@@ -1184,8 +1185,8 @@ static int hclge_dbg_dump_qos_dscp_map(struct hclge_dev *hdev, char *buf,
 	pos += scnprintf(buf + pos, len - pos, "\nDSCP  PRIO  TC\n");
 
 	/* The low 32 dscp setting use bd0, high 32 dscp setting use bd1 */
-	for (i = 0; i < HCLGE_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM; i++) {
-		j = i + HCLGE_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM;
+	for (i = 0; i < HNAE3_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM; i++) {
+		j = i + HNAE3_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM;
 		/* Each dscp setting has 4 bits, so each byte saves two dscp
 		 * setting
 		 */
@@ -1195,12 +1196,12 @@ static int hclge_dbg_dump_qos_dscp_map(struct hclge_dev *hdev, char *buf,
 		dscp_tc[j] &= HCLGE_DBG_TC_MASK;
 	}
 
-	for (i = 0; i < HCLGE_MAX_DSCP; i++) {
-		if (hdev->tm_info.dscp_prio[i] == HCLGE_PRIO_ID_INVALID)
+	for (i = 0; i < HNAE3_MAX_DSCP; i++) {
+		if (kinfo->dscp_prio[i] == HNAE3_PRIO_ID_INVALID)
 			continue;
 
 		pos += scnprintf(buf + pos, len - pos, " %2u    %u    %u\n",
-				 i, hdev->tm_info.dscp_prio[i], dscp_tc[i]);
+				 i, kinfo->dscp_prio[i], dscp_tc[i]);
 	}
 
 	return 0;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d7278d9a4939..66436801fb8e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -12981,17 +12981,14 @@ static void hclge_clean_vport_config(struct hnae3_ae_dev *ae_dev, int num_vfs)
 static int hclge_get_dscp_prio(struct hnae3_handle *h, u8 dscp, u8 *tc_mode,
 			       u8 *priority)
 {
-	struct hclge_vport *vport = hclge_get_vport(h);
-	struct hclge_dev *hdev = vport->back;
-
-	if (dscp >= HCLGE_MAX_DSCP)
+	if (dscp >= HNAE3_MAX_DSCP)
 		return -EINVAL;
 
 	if (tc_mode)
-		*tc_mode = vport->nic.kinfo.tc_map_mode;
+		*tc_mode = h->kinfo.tc_map_mode;
 	if (priority)
-		*priority = hdev->tm_info.dscp_prio[dscp] == HCLGE_PRIO_ID_INVALID ? 0 :
-			    hdev->tm_info.dscp_prio[dscp];
+		*priority = h->kinfo.dscp_prio[dscp] == HNAE3_PRIO_ID_INVALID ? 0 :
+			    h->kinfo.dscp_prio[dscp];
 
 	return 0;
 }
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 163240adbcce..495b639b0dc2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -351,15 +351,11 @@ struct hclge_cfg {
 	u16 umv_space;
 };
 
-#define HCLGE_MAX_DSCP			64
-#define HCLGE_PRIO_ID_INVALID		0xff
 struct hclge_tm_info {
 	u8 num_tc;
 	u8 num_pg;      /* It must be 1 if vNET-Base schd */
-	u8 dscp_app_cnt;
 	u8 pg_dwrr[HCLGE_PG_NUM];
 	u8 prio_tc[HNAE3_MAX_USER_PRIO];
-	u8 dscp_prio[HCLGE_MAX_DSCP];
 	struct hclge_pg_info pg_info[HCLGE_PG_NUM];
 	struct hclge_tc_info tc_info[HNAE3_MAX_TC];
 	enum hclge_fc_mode fc_mode;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 7630d1f01e04..4a33f65190e2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -271,9 +271,9 @@ static void hclge_dscp_to_prio_map_init(struct hclge_dev *hdev)
 	u8 i;
 
 	hdev->vport[0].nic.kinfo.tc_map_mode = HNAE3_TC_MAP_MODE_PRIO;
-	hdev->tm_info.dscp_app_cnt = 0;
-	for (i = 0; i < HCLGE_MAX_DSCP; i++)
-		hdev->tm_info.dscp_prio[i] = HCLGE_PRIO_ID_INVALID;
+	hdev->vport[0].nic.kinfo.dscp_app_cnt = 0;
+	for (i = 0; i < HNAE3_MAX_DSCP; i++)
+		hdev->vport[0].nic.kinfo.dscp_prio[i] = HNAE3_PRIO_ID_INVALID;
 }
 
 int hclge_dscp_to_tc_map(struct hclge_dev *hdev)
@@ -288,18 +288,18 @@ int hclge_dscp_to_tc_map(struct hclge_dev *hdev)
 	hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_QOS_MAP, false);
 
 	/* The low 32 dscp setting use bd0, high 32 dscp setting use bd1 */
-	for (i = 0; i < HCLGE_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM; i++) {
-		pri_id = hdev->tm_info.dscp_prio[i];
-		pri_id = pri_id == HCLGE_PRIO_ID_INVALID ? 0 : pri_id;
+	for (i = 0; i < HNAE3_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM; i++) {
+		pri_id = hdev->vport[0].nic.kinfo.dscp_prio[i];
+		pri_id = pri_id == HNAE3_PRIO_ID_INVALID ? 0 : pri_id;
 		tc_id = hdev->tm_info.prio_tc[pri_id];
 		/* Each dscp setting has 4 bits, so each byte saves two dscp
 		 * setting
 		 */
 		req0[i >> 1] |= tc_id << HCLGE_DSCP_TC_SHIFT(i);
 
-		j = i + HCLGE_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM;
-		pri_id = hdev->tm_info.dscp_prio[j];
-		pri_id = pri_id == HCLGE_PRIO_ID_INVALID ? 0 : pri_id;
+		j = i + HNAE3_MAX_DSCP / HCLGE_DSCP_MAP_TC_BD_NUM;
+		pri_id = hdev->vport[0].nic.kinfo.dscp_prio[j];
+		pri_id = pri_id == HNAE3_PRIO_ID_INVALID ? 0 : pri_id;
 		tc_id = hdev->tm_info.prio_tc[pri_id];
 		req1[i >> 1] |= tc_id << HCLGE_DSCP_TC_SHIFT(i);
 	}
-- 
2.33.0


  parent reply	other threads:[~2022-09-16  2:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16  2:37 [PATCH net-next 0/4] net: hns3: updates for -next Guangbin Huang
2022-09-16  2:38 ` [PATCH net-next 1/4] net: hns3: add support for external loopback test Guangbin Huang
2022-09-16  2:38 ` Guangbin Huang [this message]
2022-09-16  2:38 ` [PATCH net-next 3/4] net: hns3: refactor function hclge_mbx_handler() Guangbin Huang
2022-09-16  2:38 ` [PATCH net-next 4/4] net: hns3: add judge fd ability for sync and clear process of flow director Guangbin Huang
2022-09-21  2:59 ` [PATCH net-next 0/4] net: hns3: updates for -next huangguangbin (A)
2022-09-21 12:37   ` Jakub Kicinski
2022-09-21 23:00 ` patchwork-bot+netdevbpf

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=20220916023803.23756-3-huangguangbin2@huawei.com \
    --to=huangguangbin2@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=lanhao@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lipeng321@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shenjian15@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.