net: provides dim profile fine-tuning channels
Subsystems (5)
cover net: provides dim profile fine-tuning channels
The NetDIM library provides excellent acceleration for many modern network cards. However, the default profiles of DIM limits its maximum capabilities for different NICs, so providing a channel through which the NIC can be custom configured is necessary.
Please review, thank you very much!
Heng Qi (2):
net: add sysfs attributes for customized dim profile management
virtio-net: support net sysfs to fine-tune dim profile
Documentation/ABI/testing/sysfs-class-net | 17 +++ drivers/net/virtio_net.c | 64 ++++++++++- include/linux/dim.h | 7 ++ include/linux/netdevice.h | 35 ++++++ lib/dim/net_dim.c | 6 -- net/core/net-sysfs.c | 172 ++++++++++++++++++++++++++++++ 6 files changed, 294 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH 1/2 net: add sysfs attributes for customized dim profile management
The NetDIM library, currently leveraged by an array of NICs, delivers excellent acceleration benefits. Nevertheless, NICs vary significantly in their dim profile list prerequisites.
Specifically, virtio-net backends may present diverse sw or hw device implementation, making a one-size-fits-all parameter list impractical. On Alibaba Cloud, the virtio DPU's performance under the default DIM profile falls short of expectations, partly due to a mismatch in parameter configuration.
I also noticed that ice/idpf/ena and other NICs have customized profilelist or placed some restrictions on dim capabilities.
Motivated by this, I tried adding new sysfs attributes that provides a per-device control to modify and access a device's interrupt parameters.
Usage
========
1. Query the currently customized list of the device
$ cat dim_profs
The profiles of (RX, EQE):
{.usec = 1, .pkts = 256, .comps = 0,},
{.usec = 8, .pkts = 256, .comps = 0,},
{.usec = 64, .pkts = 256, .comps = 0,},
{.usec = 128, .pkts = 256, .comps = 0,},
{.usec = 256, .pkts = 256, .comps = 0,}
The profiles of (TX, EQE):
{.usec = 1, .pkts = 256, .comps = 0,},
{.usec = 2, .pkts = 256, .comps = 0,},
{.usec = 3, .pkts = 256, .comps = 0,},
{.usec = 4, .pkts = 256, .comps = 0,},
{.usec = 5, .pkts = 256, .comps = 0,}2. Tune
$ echo "RX EQE 8,8,0 16,16,0 32,32,0 64,64,0 128,128,0" > dim_profs
$ echo " TX EQE 0,2,0 1,3,0 2,4,0 3,5,0 4,6,0 " > dim_profs
$ cat dim_profs
The profiles of (RX, EQE):
{.usec = 8, .pkts = 8, .comps = 0,},
{.usec = 16, .pkts = 16, .comps = 0,},
{.usec = 32, .pkts = 32, .comps = 0,},
{.usec = 64, .pkts = 64, .comps = 0,},
{.usec = 128, .pkts = 128, .comps = 0,}
The profiles of (TX, EQE):
{.usec = 0, .pkts = 2, .comps = 0,},
{.usec = 1, .pkts = 3, .comps = 0,},
{.usec = 2, .pkts = 4, .comps = 0,},
{.usec = 3, .pkts = 5, .comps = 0,},
{.usec = 4, .pkts = 6, .comps = 0,}3. Warn
If the device does not support .ndo_dim_moder_{set, get}, the following warning will response:
"Profile is default and not customized by the device."
--- Documentation/ABI/testing/sysfs-class-net | 17 +++ include/linux/dim.h | 7 ++ include/linux/netdevice.h | 35 ++++++ lib/dim/net_dim.c | 6 -- net/core/net-sysfs.c | 172 ++++++++++++++++++++++++++++++ 5 files changed, 231 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-class-net +17 -0
@@ -352,3 +352,20 @@ Description: 0 threaded mode disabled for this dev 1 threaded mode enabled for this dev == ================================== + +What: /sys/class/net/<iface>/dim_profs +Date: Mar 2024 +KernelVersion: 6.8 +Contact: [email protected] +Description: + String value to control the profile list of DIM per device. User could + set this value to tune the profile list for RX/TX direction and EQE/CQE + mode respectively. + + Possible values: + ================================================ ========================== + RX EQE 1,1,0 2,2,0 3,3,0 4,4,0 5,5,0 tune RX + EQE profile list + RX CQE 8,8,0 16,16,0 32,32,0 64,64,0 128,128,0 tune RX + CQE profile list + TX EQE 16,8,0 2,16,0 16,8,0 32,64,0 128,64,0 tune TX + EQE profile list + TX CQE 8,5,0 8,16,0 32,12,0 128,64,0 256,128,0 tune TX + CQE profile list + ================================================ ==========================
include/linux/dim.h +7 -0
@@ -10,6 +10,13 @@#include <linux/types.h> #include <linux/workqueue.h> +/* Number of DIM profiles and period mode. */ +#define NET_DIM_PARAMS_NUM_PROFILES 5 +#define NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE 256 +#define NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE 128 +#define NET_DIM_DEF_PROFILE_CQE 1 +#define NET_DIM_DEF_PROFILE_EQE 1 +/* * Number of events between DIM iterations. * Causes a moderation of the algorithm run.
include/linux/netdevice.h +35 -0
@@ -49,6 +49,7 @@#include <uapi/linux/netdev.h> #include <linux/hashtable.h> #include <linux/rbtree.h> +#include <linux/dim.h> #include <net/net_trackers.h> #include <net/net_debug.h> #include <net/dropreason-core.h>
@@ -998,6 +999,27 @@ struct netdev_net_notifier {struct notifier_block *nb; }; +enum dim_direction { +DIM_RX_DIRECTION =0x0 , +DIM_TX_DIRECTION =0x1 , +DIM_NUM_DIRECTIONS +}; +/** +* struct dim_profs_list - Structure for dim sysfs configuration. +* Used to exchange profile list between the sysfs and the driver. +* +* @direction: RX or TX dim information +* @mode: CQ period count mode (from CQE/EQE) +* @num: the number of profs array +* @profs: dim profile list +*/ +struct dim_profs_list { +u8 direction; +u8 mode; +u8 num; +struct dim_cq_moder profs[]; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -1351,6 +1373,14 @@ struct netdev_net_notifier {* struct kernel_hwtstamp_config *kernel_config, * struct netlink_ext_ack *extack); * Change the hardware timestamping parameters for NIC device. +* +* int (*ndo_dim_moder_get)(struct net_device *dev, +* struct dim_profs_list *list); +* Get dim profiles list from the NIC device. +* +* int (*ndo_dim_moder_set)(struct net_device *dev, +* struct dim_profs_list *list); +* Configure dim profiles list for the NIC device. */ struct net_device_ops {int (*ndo_init)(struct net_device *dev);
@@ -1595,6 +1625,11 @@ struct net_device_ops {int (*ndo_hwtstamp_set)(struct net_device *dev,struct kernel_hwtstamp_config *kernel_config,struct netlink_ext_ack *extack); +int (*ndo_dim_moder_get)(struct net_device *dev, +struct dim_profs_list *list); + +int (*ndo_dim_moder_set)(struct net_device *dev, +struct dim_profs_list *list); };/**
lib/dim/net_dim.c +0 -6
@@ -11,12 +11,6 @@* There are different set of profiles for RX/TX CQs. * Each profile size must be of NET_DIM_PARAMS_NUM_PROFILES */ -#define NET_DIM_PARAMS_NUM_PROFILES 5 -#define NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE 256 -#define NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE 128 -#define NET_DIM_DEF_PROFILE_CQE 1 -#define NET_DIM_DEF_PROFILE_EQE 1 -#define NET_DIM_RX_EQE_PROFILES { \ {.usec = 1, .pkts = NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE,}, \ {.usec = 8, .pkts = NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE,}, \
net/core/net-sysfs.c +172 -0
190 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH 2/2 virtio-net: support net sysfs to fine-tune dim profile
In reply to Heng QiVirtio-net has different types of back-end device implementations. In order to effectively optimize the dim library's gains for different device implementations, let's use the interface provided by net-sysfs to fine-tune the profile list.
--- drivers/net/virtio_net.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +63 -1
@@ -57,6 +57,16 @@#define VIRTNET_DRIVER_VERSION "1.0.0" +/* This is copied from NET_DIM_RX_EQE_PROFILES in DIM library */ +#define VIRTNET_DIM_RX_PKTS 256 +static struct dim_cq_moder rx_itr_conf[] = { + {.usec =1 , .pkts =VIRTNET_DIM_RX_PKTS ,}, + {.usec =8 , .pkts =VIRTNET_DIM_RX_PKTS ,}, + {.usec =64 , .pkts =VIRTNET_DIM_RX_PKTS ,}, + {.usec =128 , .pkts =VIRTNET_DIM_RX_PKTS ,}, + {.usec =256 , .pkts =VIRTNET_DIM_RX_PKTS ,} +}; +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,
@@ -3584,7 +3594,10 @@ static void virtnet_rx_dim_work(struct work_struct *work)if (!rq->dim_enabled)continue ; - update_moder =net_dim_get_rx_moderation (dim->mode, dim->profile_ix); +if (dim->profile_ix >=ARRAY_SIZE (rx_itr_conf)) + dim->profile_ix =ARRAY_SIZE (rx_itr_conf) -1 ; + + update_moder = rx_itr_conf[dim->profile_ix];if (update_moder.usec != rq->intr_coal.max_usecs || update_moder.pkts != rq->intr_coal.max_packets) { err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, qnum,
@@ -4170,6 +4183,53 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); } +static int virtnet_dim_moder_valid (struct net_device *dev,struct dim_profs_list *list) +{ +struct virtnet_info *vi =netdev_priv (dev); + +if (!virtio_has_feature (vi->vdev,VIRTIO_NET_F_VQ_NOTF_COAL )) +return -EOPNOTSUPP ; + +if (!list || list->direction !=DIM_RX_DIRECTION || + list->num !=NET_DIM_PARAMS_NUM_PROFILES || + list->mode !=DIM_CQ_PERIOD_MODE_START_FROM_EQE ) { +return -EINVAL ; + } + +return 0 ; +} + +static int virtnet_dim_moder_get (struct net_device *dev,struct dim_profs_list *list) +{ +int ret; + + ret =virtnet_dim_moder_valid (dev, list); +if (ret) +return ret; + +memcpy (list->profs, rx_itr_conf,sizeof (*list->profs) * list->num); + +return 0 ; +} + +static int virtnet_dim_moder_set (struct net_device *dev,struct dim_profs_list *list) +{ +int i, ret; + + ret =virtnet_dim_moder_valid (dev, list); +if (ret) +return ret; + +for (i =0 ; i < list->num; i++) { + rx_itr_conf[i].usec = list->profs[i].usec; + rx_itr_conf[i].pkts = list->profs[i].pkts; +if (list->profs[i].comps) +return -EINVAL ; + } + +return 0 ; +} +static const struct net_device_ops virtnet_netdev = { .ndo_open = virtnet_open, .ndo_stop = virtnet_close,
@@ -4186,6 +4246,8 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) .ndo_get_phys_port_name = virtnet_get_phys_port_name, .ndo_set_features = virtnet_set_features, .ndo_tx_timeout = virtnet_tx_timeout, + .ndo_dim_moder_get = virtnet_dim_moder_get, + .ndo_dim_moder_set = virtnet_dim_moder_set, };static void virtnet_config_changed_work (struct work_struct *work)
Signature · 1 line
1.8.3.1
Jakub Kicinski
maintainerQuoted 4 lines · On Thu, 14 Mar 2024 21:09:31 +0800 Heng Qi wrote:
The NetDIM library provides excellent acceleration for many modern network cards. However, the default profiles of DIM limits its maximum capabilities for different NICs, so providing a channel through which the NIC can be custom configured is necessary.
Given that DIM is currently enabled and disable via ethtool why are you putting the API is sysfs and ops in ndo?
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 14 Mar 2024 21:09:31 +0800 Heng Qi wrote:
The NetDIM library provides excellent acceleration for many modern network cards. However, the default profiles of DIM limits its maximum capabilities for different NICs, so providing a channel through which the NIC can be custom configured is necessary.
Given that DIM is currently enabled and disable via ethtool why are you putting the API is sysfs and ops in ndo?
Hi Jakub,
Thank you for reaching out. We're flexible regarding configuration methods and are open to using either sysfs or ethtool, depending on what's most appropriate for the task at hand.
If the ethtool is favored, I am happy to proceed with it!
Best regards,
Heng