Message ID | 20230811065512.22190-7-hengqi@linux.alibaba.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | virtio-net: support dynamic notification coalescing moderation | expand |
Hi Heng, kernel test robot noticed the following build errors: [auto build test ERROR on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Heng-Qi/virtio-net-initially-change-the-value-of-tx-frames/20230811-150529 base: net-next/main patch link: https://lore.kernel.org/r/20230811065512.22190-7-hengqi%40linux.alibaba.com patch subject: [PATCH net-next 6/8] virtio-net: support rx netdim config: i386-randconfig-i011-20230811 (https://download.01.org/0day-ci/archive/20230811/202308112234.AWbpPmUV-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230811/202308112234.AWbpPmUV-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202308112234.AWbpPmUV-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-kworld-315u.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-kworld-pc150u.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-leadtek-y04g0051.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-lme2510.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-manli.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-mecool-kiii-pro.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-mecool-kii-pro.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-medion-x10.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-minix-neo.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-msi-digivox-iii.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-msi-digivox-ii.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-msi-tvanywhere.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-nebula.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-norwood.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-npgtech.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-odroid.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pctv-sedna.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pine64.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pinnacle-color.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pinnacle-grey.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pixelview-002t.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pixelview-mk12.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pixelview-new.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pixelview.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-powercolor-real-angel.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-proteus-2309.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-purpletv.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-pv951.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-rc6-mce.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-real-audio-220-32-keys.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-reddo.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-snapstream-firefly.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-streamzap.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-su3000.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tanix-tx3mini.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tanix-tx5max.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tbs-nec.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-technisat-ts35.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-technisat-usb2.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-terratec-cinergy-c-pci.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-terratec-cinergy-s2-hd.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-terratec-cinergy-xs.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-terratec-slim-2.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-terratec-slim.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tevii-nec.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tivo.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-total-media-in-hand-02.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-total-media-in-hand.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-trekstor.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-tt-1500.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-twinhan1027.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-twinhan-dtv-cab-ci.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-vega-s9x.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-videomate-m1f.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-videomate-s350.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-videomate-tv-pvr.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-videostrong-kii-pro.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-wetek-hub.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-wetek-play2.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-winfast.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-x96max.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-xbox-360.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-xbox-dvd.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/keymaps/rc-zx-irdec.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/rc-core.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-async.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-fwnode.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/radio/si470x/radio-si470x-common.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/watchdog/twl4030_wdt.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/watchdog/menz69_wdt.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/host/of_mmc_spi.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/mmc_core.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/pwrseq_simple.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/firmware/google/vpd-sysfs.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-light.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-log.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-vibrator.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_powersave.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_u-boot-env.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/parport/parport.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/chips/cfi_util.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/maps/map_funcs.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pcmcia/pcmcia_rsrc.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/buffer/kfifo_buf.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-core.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-aspeed.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-scom.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mtty.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mbochs.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/bytestream-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/dma-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/inttype-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/record-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kmemleak/kmemleak-test.o >> ERROR: modpost: "net_dim_get_rx_moderation" [drivers/net/virtio_net.ko] undefined! >> ERROR: modpost: "net_dim" [drivers/net/virtio_net.ko] undefined!
On Fri, Aug 11, 2023 at 02:55:10PM +0800, Heng Qi wrote: > By comparing the traffic information in the complete napi processes, > let the virtio-net driver automatically adjust the coalescing > moderation parameters of each receive queue. > > Signed-off-by: Heng Qi <hengqi@linux.alibaba.com> > --- > drivers/net/virtio_net.c | 124 +++++++++++++++++++++++++++++++++------ > 1 file changed, 106 insertions(+), 18 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 0318113bd8c2..3fb801a7a785 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -19,6 +19,7 @@ > #include <linux/average.h> > #include <linux/filter.h> > #include <linux/kernel.h> > +#include <linux/dim.h> > #include <net/route.h> > #include <net/xdp.h> > #include <net/net_failover.h> > @@ -168,8 +169,17 @@ struct receive_queue { > > struct virtnet_rq_stats stats; > > + /* The number of rx notifications */ > + u16 calls; > + > + /* Is dynamic interrupt moderation enabled? */ > + bool dim_enabled; > + > struct virtnet_interrupt_coalesce intr_coal; > > + /* Dynamic Iterrupt Moderation */ Hi Heng Qi, nit: Iterrupt -> interrupt Also, elsewhere in this patchset. ./checkpatch.pl --codespell is your friend here > + struct dim dim; > + > /* Chain pages by the private ptr. */ > struct page *pages; > ...
在 2023/8/13 上午1:34, Simon Horman 写道: > On Fri, Aug 11, 2023 at 02:55:10PM +0800, Heng Qi wrote: >> By comparing the traffic information in the complete napi processes, >> let the virtio-net driver automatically adjust the coalescing >> moderation parameters of each receive queue. >> >> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com> >> --- >> drivers/net/virtio_net.c | 124 +++++++++++++++++++++++++++++++++------ >> 1 file changed, 106 insertions(+), 18 deletions(-) >> >> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c >> index 0318113bd8c2..3fb801a7a785 100644 >> --- a/drivers/net/virtio_net.c >> +++ b/drivers/net/virtio_net.c >> @@ -19,6 +19,7 @@ >> #include <linux/average.h> >> #include <linux/filter.h> >> #include <linux/kernel.h> >> +#include <linux/dim.h> >> #include <net/route.h> >> #include <net/xdp.h> >> #include <net/net_failover.h> >> @@ -168,8 +169,17 @@ struct receive_queue { >> >> struct virtnet_rq_stats stats; >> >> + /* The number of rx notifications */ >> + u16 calls; >> + >> + /* Is dynamic interrupt moderation enabled? */ >> + bool dim_enabled; >> + >> struct virtnet_interrupt_coalesce intr_coal; >> >> + /* Dynamic Iterrupt Moderation */ > Hi Heng Qi, > > nit: Iterrupt -> interrupt Hi, Will fix in the next version ^^ > > Also, elsewhere in this patchset. > > ./checkpatch.pl --codespell is your friend here Ok. I will try this. Thanks! > >> + struct dim dim; >> + >> /* Chain pages by the private ptr. */ >> struct page *pages; >> > ...
Hi Heng, kernel test robot noticed the following build errors: [auto build test ERROR on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Heng-Qi/virtio-net-initially-change-the-value-of-tx-frames/20230811-150529 base: net-next/main patch link: https://lore.kernel.org/r/20230811065512.22190-7-hengqi%40linux.alibaba.com patch subject: [PATCH net-next 6/8] virtio-net: support rx netdim config: microblaze-randconfig-r081-20230814 (https://download.01.org/0day-ci/archive/20230814/202308142100.l4cN4g6z-lkp@intel.com/config) compiler: microblaze-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230814/202308142100.l4cN4g6z-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202308142100.l4cN4g6z-lkp@intel.com/ All errors (new ones prefixed by >>): microblaze-linux-ld: drivers/net/virtio_net.o: in function `virtnet_rx_dim_work': >> drivers/net/virtio_net.c:3269: undefined reference to `net_dim_get_rx_moderation' microblaze-linux-ld: drivers/net/virtio_net.o: in function `virtnet_rx_dim_update': >> drivers/net/virtio_net.c:1985: undefined reference to `net_dim' vim +3269 drivers/net/virtio_net.c 3258 3259 static void virtnet_rx_dim_work(struct work_struct *work) 3260 { 3261 struct dim *dim = container_of(work, struct dim, work); 3262 struct receive_queue *rq = container_of(dim, 3263 struct receive_queue, dim); 3264 struct virtnet_info *vi = rq->vq->vdev->priv; 3265 struct net_device *dev = vi->dev; 3266 struct dim_cq_moder update_moder; 3267 int qnum = rq - vi->rq, err; 3268 > 3269 update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); 3270 err = virtnet_send_rx_notf_coal_vq_cmd(vi, qnum, 3271 update_moder.usec, 3272 update_moder.pkts); 3273 if (err) 3274 pr_debug("%s: Failed to send dim parameters on rxq%d\n", 3275 dev->name, (int)(rq - vi->rq)); 3276 3277 dim->state = DIM_START_MEASURE; 3278 } 3279
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0318113bd8c2..3fb801a7a785 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -19,6 +19,7 @@ #include <linux/average.h> #include <linux/filter.h> #include <linux/kernel.h> +#include <linux/dim.h> #include <net/route.h> #include <net/xdp.h> #include <net/net_failover.h> @@ -168,8 +169,17 @@ struct receive_queue { struct virtnet_rq_stats stats; + /* The number of rx notifications */ + u16 calls; + + /* Is dynamic interrupt moderation enabled? */ + bool dim_enabled; + struct virtnet_interrupt_coalesce intr_coal; + /* Dynamic Iterrupt Moderation */ + struct dim dim; + /* Chain pages by the private ptr. */ struct page *pages; @@ -1927,6 +1937,7 @@ static void skb_recv_done(struct virtqueue *rvq) struct virtnet_info *vi = rvq->vdev->priv; struct receive_queue *rq = &vi->rq[vq2rxq(rvq)]; + rq->calls++; virtqueue_napi_schedule(&rq->napi, rvq); } @@ -2064,6 +2075,21 @@ static void virtnet_poll_cleantx(struct receive_queue *rq) } } +static void virtnet_rx_dim_work(struct work_struct *work); + +static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq) +{ + struct virtnet_rq_stats *stats = &rq->stats; + struct dim_sample cur_sample = {}; + + u64_stats_update_begin(&rq->stats.syncp); + dim_update_sample(rq->calls, stats->packets, + stats->bytes, &cur_sample); + u64_stats_update_end(&rq->stats.syncp); + + net_dim(&rq->dim, cur_sample); +} + static int virtnet_poll(struct napi_struct *napi, int budget) { struct receive_queue *rq = @@ -2072,6 +2098,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget) struct send_queue *sq; unsigned int received; unsigned int xdp_xmit = 0; + bool napi_complete; virtnet_poll_cleantx(rq); @@ -2081,8 +2108,11 @@ static int virtnet_poll(struct napi_struct *napi, int budget) xdp_do_flush(); /* Out of packets? */ - if (received < budget) - virtqueue_napi_complete(napi, rq->vq, received); + if (received < budget) { + napi_complete = virtqueue_napi_complete(napi, rq->vq, received); + if (napi_complete && rq->dim_enabled) + virtnet_rx_dim_update(vi, rq); + } if (xdp_xmit & VIRTIO_XDP_TX) { sq = virtnet_xdp_get_sq(vi); @@ -2102,6 +2132,7 @@ static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) virtnet_napi_tx_disable(&vi->sq[qp_index].napi); napi_disable(&vi->rq[qp_index].napi); xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); + cancel_work_sync(&vi->rq[qp_index].dim.work); } static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) @@ -2119,6 +2150,9 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) if (err < 0) goto err_xdp_reg_mem_model; + INIT_WORK(&vi->rq[qp_index].dim.work, virtnet_rx_dim_work); + vi->rq[qp_index].dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; + virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); @@ -3183,20 +3217,37 @@ static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) { + bool rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; struct scatterlist sgs_rx; + int i; - vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); - vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); - sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); - - if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, - VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, - &sgs_rx)) + if (rx_ctrl_dim_on && (ec->rx_coalesce_usecs != vi->intr_coal_rx.max_usecs || + ec->rx_max_coalesced_frames != vi->intr_coal_rx.max_packets)) return -EINVAL; - /* Save parameters */ - vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; - vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; + if (rx_ctrl_dim_on) { + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) + for (i = 0; i < vi->max_queue_pairs; i++) + vi->rq[i].dim_enabled = true; + else + return -EOPNOTSUPP; + } else { + for (i = 0; i < vi->max_queue_pairs; i++) + vi->rq[i].dim_enabled = false; + + vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); + vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); + sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); + + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, + VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, + &sgs_rx)) + return -EINVAL; + + /* Save parameters */ + vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; + vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; + } return 0; } @@ -3275,14 +3326,28 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec, u16 queue) { + bool rx_ctrl_dim_on; + u32 max_usecs, max_packets; int err; if (ec->rx_coalesce_usecs || ec->rx_max_coalesced_frames) { - err = virtnet_send_rx_notf_coal_vq_cmd(vi, queue, - ec->rx_coalesce_usecs, - ec->rx_max_coalesced_frames); - if (err) - return err; + rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; + max_usecs = vi->rq[queue].intr_coal.max_usecs; + max_packets = vi->rq[queue].intr_coal.max_packets; + if (rx_ctrl_dim_on && (ec->rx_coalesce_usecs != max_usecs || + ec->rx_max_coalesced_frames != max_packets)) + return -EINVAL; + + if (rx_ctrl_dim_on) { + vi->rq[queue].dim_enabled = true; + } else { + vi->rq[queue].dim_enabled = false; + err = virtnet_send_rx_notf_coal_vq_cmd(vi, queue, + ec->rx_coalesce_usecs, + ec->rx_max_coalesced_frames); + if (err) + return err; + } } if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { @@ -3296,6 +3361,27 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, return 0; } +static void virtnet_rx_dim_work(struct work_struct *work) +{ + struct dim *dim = container_of(work, struct dim, work); + struct receive_queue *rq = container_of(dim, + struct receive_queue, dim); + struct virtnet_info *vi = rq->vq->vdev->priv; + struct net_device *dev = vi->dev; + struct dim_cq_moder update_moder; + int qnum = rq - vi->rq, err; + + update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); + err = virtnet_send_rx_notf_coal_vq_cmd(vi, qnum, + update_moder.usec, + update_moder.pkts); + if (err) + pr_debug("%s: Failed to send dim parameters on rxq%d\n", + dev->name, (int)(rq - vi->rq)); + + dim->state = DIM_START_MEASURE; +} + static int virtnet_coal_params_supported(struct ethtool_coalesce *ec) { /* usecs coalescing is supported only if VIRTIO_NET_F_NOTF_COAL @@ -3377,6 +3463,7 @@ static int virtnet_get_coalesce(struct net_device *dev, ec->tx_coalesce_usecs = vi->intr_coal_tx.max_usecs; ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; + ec->use_adaptive_rx_coalesce = vi->rq[0].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3434,6 +3521,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; + ec->use_adaptive_rx_coalesce = vi->rq[queue].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3559,7 +3647,7 @@ static int virtnet_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info) static const struct ethtool_ops virtnet_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_MAX_FRAMES | - ETHTOOL_COALESCE_USECS, + ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_USE_ADAPTIVE_RX, .get_drvinfo = virtnet_get_drvinfo, .get_link = ethtool_op_get_link, .get_ringparam = virtnet_get_ringparam,
By comparing the traffic information in the complete napi processes, let the virtio-net driver automatically adjust the coalescing moderation parameters of each receive queue. Signed-off-by: Heng Qi <hengqi@linux.alibaba.com> --- drivers/net/virtio_net.c | 124 +++++++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 18 deletions(-)