Separating the code of updating rq stats. This is prepare for separating the code of ethtool. Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> --- drivers/net/virtio/virtnet.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/net/virtio/virtnet.c b/drivers/net/virtio/virtnet.c index 84b90333dc77..36c747e43b3f 100644 --- a/drivers/net/virtio/virtnet.c +++ b/drivers/net/virtio/virtnet.c @@ -1550,6 +1550,21 @@ static void refill_work(struct work_struct *work) } } +static void virtnet_rq_update_stats(struct virtnet_rq *rq, struct virtnet_rq_stats *stats) +{ + int i; + + u64_stats_update_begin(&rq->stats.syncp); + for (i = 0; i < VIRTNET_RQ_STATS_LEN; i++) { + size_t offset = virtnet_rq_stats_desc[i].offset; + u64 *item; + + item = (u64 *)((u8 *)&rq->stats + offset); + *item += *(u64 *)((u8 *)stats + offset); + } + u64_stats_update_end(&rq->stats.syncp); +} + static int virtnet_receive(struct virtnet_rq *rq, int budget, unsigned int *xdp_xmit) { @@ -1557,7 +1572,6 @@ static int virtnet_receive(struct virtnet_rq *rq, int budget, struct virtnet_rq_stats stats = {}; unsigned int len; void *buf; - int i; if (!vi->big_packets || vi->mergeable_rx_bufs) { void *ctx; @@ -1584,15 +1598,7 @@ static int virtnet_receive(struct virtnet_rq *rq, int budget, } } - u64_stats_update_begin(&rq->stats.syncp); - for (i = 0; i < VIRTNET_RQ_STATS_LEN; i++) { - size_t offset = virtnet_rq_stats_desc[i].offset; - u64 *item; - - item = (u64 *)((u8 *)&rq->stats + offset); - *item += *(u64 *)((u8 *)&stats + offset); - } - u64_stats_update_end(&rq->stats.syncp); + virtnet_rq_update_stats(rq, &stats); return stats.packets; } -- 2.32.0.3.g01195cf9f