Commit ceca4a5e authored by Yunsheng Lin's avatar Yunsheng Lin Committed by David S. Miller

net: hns3: minor optimization for datapath

This patch adds a likely case for hns3_fill_desc and
limits the local variables' scope as much as possible,
also avoid div operation when the tqp_vector->num_tqps
is one.
Signed-off-by: default avatarYunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: default avatarPeng Li <lipeng321@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0aa3d88a
...@@ -1012,7 +1012,6 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, ...@@ -1012,7 +1012,6 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
struct hns3_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use]; struct hns3_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use];
struct hns3_desc *desc = &ring->desc[ring->next_to_use]; struct hns3_desc *desc = &ring->desc[ring->next_to_use];
struct device *dev = ring_to_dev(ring); struct device *dev = ring_to_dev(ring);
u16 bdtp_fe_sc_vld_ra_ri = 0;
struct skb_frag_struct *frag; struct skb_frag_struct *frag;
unsigned int frag_buf_num; unsigned int frag_buf_num;
int k, sizeoflast; int k, sizeoflast;
...@@ -1080,12 +1079,30 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, ...@@ -1080,12 +1079,30 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
desc_cb->length = size; desc_cb->length = size;
if (likely(size <= HNS3_MAX_BD_SIZE)) {
u16 bdtp_fe_sc_vld_ra_ri = 0;
desc_cb->priv = priv;
desc_cb->dma = dma;
desc_cb->type = type;
desc->addr = cpu_to_le64(dma);
desc->tx.send_size = cpu_to_le16(size);
hns3_set_txbd_baseinfo(&bdtp_fe_sc_vld_ra_ri, frag_end);
desc->tx.bdtp_fe_sc_vld_ra_ri =
cpu_to_le16(bdtp_fe_sc_vld_ra_ri);
ring_ptr_move_fw(ring, next_to_use);
return 0;
}
frag_buf_num = hns3_tx_bd_count(size); frag_buf_num = hns3_tx_bd_count(size);
sizeoflast = size & HNS3_TX_LAST_SIZE_M; sizeoflast = size & HNS3_TX_LAST_SIZE_M;
sizeoflast = sizeoflast ? sizeoflast : HNS3_MAX_BD_SIZE; sizeoflast = sizeoflast ? sizeoflast : HNS3_MAX_BD_SIZE;
/* When frag size is bigger than hardware limit, split this frag */ /* When frag size is bigger than hardware limit, split this frag */
for (k = 0; k < frag_buf_num; k++) { for (k = 0; k < frag_buf_num; k++) {
u16 bdtp_fe_sc_vld_ra_ri = 0;
/* The txbd's baseinfo of DESC_TYPE_PAGE & DESC_TYPE_SKB */ /* The txbd's baseinfo of DESC_TYPE_PAGE & DESC_TYPE_SKB */
desc_cb->priv = priv; desc_cb->priv = priv;
desc_cb->dma = dma + HNS3_MAX_BD_SIZE * k; desc_cb->dma = dma + HNS3_MAX_BD_SIZE * k;
...@@ -2891,7 +2908,7 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget) ...@@ -2891,7 +2908,7 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
struct hns3_enet_tqp_vector *tqp_vector = struct hns3_enet_tqp_vector *tqp_vector =
container_of(napi, struct hns3_enet_tqp_vector, napi); container_of(napi, struct hns3_enet_tqp_vector, napi);
bool clean_complete = true; bool clean_complete = true;
int rx_budget; int rx_budget = budget;
if (unlikely(test_bit(HNS3_NIC_STATE_DOWN, &priv->state))) { if (unlikely(test_bit(HNS3_NIC_STATE_DOWN, &priv->state))) {
napi_complete(napi); napi_complete(napi);
...@@ -2905,6 +2922,7 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget) ...@@ -2905,6 +2922,7 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
hns3_clean_tx_ring(ring); hns3_clean_tx_ring(ring);
/* make sure rx ring budget not smaller than 1 */ /* make sure rx ring budget not smaller than 1 */
if (tqp_vector->num_tqps > 1)
rx_budget = max(budget / tqp_vector->num_tqps, 1); rx_budget = max(budget / tqp_vector->num_tqps, 1);
hns3_for_each_ring(ring, tqp_vector->rx_group) { hns3_for_each_ring(ring, tqp_vector->rx_group) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment