enic: Add support for adaptive interrupt coalescing
Subsystems (3)
PATCH v2 1/2 enic: Add support for adaptive interrupt coalescing
From: Sujith Sankar <[email protected]>
This patch adds support for adaptive interrupt coalescing.
For small pkts with low pkt rate, we can decrease the coalescing interrupt dynamically which decreases the latency. This however increases the cpu utilization. Based on testing with different coal intr and pkt rate we came up with a table(mod_table) with rx_rate and coalescing interrupt value where we get low latency without significant increase in cpu. mod_table table stores the coalescing timer percentage value for different throughputs.
Function enic_calc_int_moderation() calculates the desired coalescing intr timer value. This function is called in driver rx napi_poll. The actual value is set by enic_set_int_moderation() which is called when napi_poll is complete. i.e when we unmask the rx intr.
Adaptive coal intr is support only when driver is using msix intr. Because intr is not shared.
Struct mod_range is used to store only the default adaptive coalescing intr value.
Adaptive coal intr calue is calculated by
timer = range_start + ((rx_coal->range_end - range_start) *
mod_table[index].range_percent / 100);
rx_coal->range_end is the rx-usecs-high value set using ethtool. range_start is rx-usecs-low, set using ethtool, if rx_small_pkt_bytes_cnt is greater than 2 * rx_large_pkt_bytes_cnt. i.e small pkts are dominant. Else its rx-usecs-low + 3.
--- drivers/net/ethernet/cisco/enic/enic.h | 30 +++++ drivers/net/ethernet/cisco/enic/enic_ethtool.c | 61 +++++++++- drivers/net/ethernet/cisco/enic/enic_main.c | 150 +++++++++++++++++++++++++ drivers/net/ethernet/cisco/enic/vnic_cq.h | 9 ++ 4 files changed, 244 insertions(+), 6 deletions(-)
drivers/net/ethernet/cisco/enic/enic.h +30 -0
@@ -43,6 +43,8 @@#define ENIC_CQ_MAX (ENIC_WQ_MAX + ENIC_RQ_MAX)#define ENIC_INTR_MAX (ENIC_CQ_MAX + 2) +#define ENIC_AIC_LARGE_PKT_DIFF 3 +struct enic_msix_entry {int requested;char devname[IFNAMSIZ ];
@@ -50,6 +52,33 @@ struct enic_msix_entry {void *devid; }; +/* Store only the lower range. Higher range is given by fw. */ +struct enic_intr_mod_range { +u32 small_pkt_range_start; +u32 large_pkt_range_start; +}; + +struct enic_intr_mod_table { +u32 rx_rate; +u32 range_percent; +}; + +#define ENIC_MAX_LINK_SPEEDS 3 +#define ENIC_LINK_SPEED_10G 10000 +#define ENIC_LINK_SPEED_4G 4000 +#define ENIC_LINK_40G_INDEX 2 +#define ENIC_LINK_10G_INDEX 1 +#define ENIC_LINK_4G_INDEX 0 +#define ENIC_RX_COALESCE_RANGE_END 125 +#define ENIC_AIC_TS_BREAK 100 + +struct enic_rx_coal { +u32 small_pkt_range_start; +u32 large_pkt_range_start; +u32 range_end; +u32 use_adaptive_rx_coalesce; +}; +/* priv_flags */ #define ENIC_SRIOV_ENABLED (1 << 0)
@@ -92,6 +121,7 @@ struct enic {unsigned int mc_count;unsigned int uc_count;u32 port_mtu; +struct enic_rx_coal rx_coalesce_setting;u32 rx_coalesce_usecs;u32 tx_coalesce_usecs;#ifdef CONFIG_PCI_IOV
drivers/net/ethernet/cisco/enic/enic_ethtool.c +55 -6
105 lines not on this page · raw message
drivers/net/ethernet/cisco/enic/enic_main.c +150 -0
216 lines not on this page · raw message
drivers/net/ethernet/cisco/enic/vnic_cq.h +9 -0
@@ -50,6 +50,11 @@ struct vnic_cq_ctrl {u32 pad10; }; +struct vnic_rx_bytes_counter { +unsigned int small_pkt_bytes_cnt; +unsigned int large_pkt_bytes_cnt; +}; +struct vnic_cq {unsigned int index;struct vnic_dev *vdev;
@@ -58,6 +63,10 @@ struct vnic_cq {unsigned int to_clean;unsigned int last_color;unsigned int interrupt_offset; +struct vnic_rx_bytes_counter pkt_size_counter; +unsigned int cur_rx_coal_timeval; +unsigned int tobe_rx_coal_timeval; +ktime_t prev_ts; }; static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
Signature · 1 line
1.9.2
On Tue, 2014-05-20 at 03:14 +0530, Govindarajulu Varadarajan wrote:
[...]
Quoted 21 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +11
-2@@ -191,17 +207,31 @@ static int enic_set_coalesce(struct net_device *netdev,struct enic *enic =netdev_priv (netdev);u32 tx_coalesce_usecs;u32 rx_coalesce_usecs; +u32 rx_coalesce_usecs_low; +u32 rx_coalesce_usecs_high; +u32 coalesce_usecs_max;unsigned int i, intr; +struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting; + coalesce_usecs_max =vnic_dev_get_intr_coal_timer_max (enic->vdev); tx_coalesce_usecs =min_t (u32, ecmd->tx_coalesce_usecs, -vnic_dev_get_intr_coal_timer_max (enic->vdev)); + coalesce_usecs_max); rx_coalesce_usecs =min_t (u32, ecmd->rx_coalesce_usecs, -vnic_dev_get_intr_coal_timer_max (enic->vdev)); + coalesce_usecs_max); + + rx_coalesce_usecs_low =min_t (u32, ecmd->rx_coalesce_usecs_low, + coalesce_usecs_max); + rx_coalesce_usecs_high = min_t(u32, ecmd->rx_coalesce_usecs_high,
drivers/net/ethernet/cisco/enic/enic_ethtool.c static int enic_set_coalesce(struct net_device *netdev, · line 234
Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +5
-0+ coalesce_usecs_max);switch (vnic_dev_get_intr_mode (enic->vdev)) {case VNIC_DEV_INTR_MODE_INTX :if (tx_coalesce_usecs != rx_coalesce_usecs)return -EINVAL ; +if (ecmd->use_adaptive_rx_coalesce || + ecmd->rx_coalesce_usecs_low || + ecmd->rx_coalesce_usecs_high) +return -EOPNOTSUPP ;
-EINVAL, please. The operation (set coalescing parameters) is supported, just not these particular arguments.
drivers/net/ethernet/cisco/enic/enic_ethtool.c static int enic_set_coalesce(struct net_device *netdev, · line 246
Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +4
-0intr =enic_legacy_io_intr (); vnic_intr_coalescing_timer_set(&enic->intr[intr],@@ -210,6 +240,10 @@ static int enic_set_coalesce(struct net_device *netdev,case VNIC_DEV_INTR_MODE_MSI :if (tx_coalesce_usecs != rx_coalesce_usecs)return -EINVAL ; +if (ecmd->use_adaptive_rx_coalesce || + ecmd->rx_coalesce_usecs_low || + ecmd->rx_coalesce_usecs_high) +return -EOPNOTSUPP ;
-EINVAL again.
Quoted 11 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +1
-4vnic_intr_coalescing_timer_set (&enic->intr[0 ], tx_coalesce_usecs);@@ -221,12 +255,27 @@ static int enic_set_coalesce(struct net_device *netdev, tx_coalesce_usecs); } -for (i =0 ; i < enic->rq_count; i++) { - intr =enic_msix_rq_intr (enic, i); -vnic_intr_coalescing_timer_set (&enic->intr[intr], - rx_coalesce_usecs); +if (rxcoal->use_adaptive_rx_coalesce) {
drivers/net/ethernet/cisco/enic/enic_ethtool.c static int enic_set_coalesce(struct net_device *netdev, · line 268
Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +9
-0+if (!ecmd->use_adaptive_rx_coalesce) { + rxcoal->use_adaptive_rx_coalesce =0 ; +enic_intr_coal_set_rx (enic, rx_coalesce_usecs); + } + }else { +if (ecmd->use_adaptive_rx_coalesce) + rxcoal->use_adaptive_rx_coalesce =1 ; +else +enic_intr_coal_set_rx (enic, rx_coalesce_usecs); }
This seems to be an overly complicated way of writing:
rxcoal->use_adaptive_rx_coalesce = !!ecmd->use_adaptive_rx_coalesce; if (!rxcoal->use_adaptive_rx_coalesce) enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
drivers/net/ethernet/cisco/enic/enic_ethtool.c static int enic_set_coalesce(struct net_device *netdev, · line 273
Quoted 4 lines
drivers/net/ethernet/cisco/enic/enic_ethtool.c +4
-0+if (ecmd->rx_coalesce_usecs_high) { +if (rx_coalesce_usecs_high < + (rx_coalesce_usecs_low +ENIC_AIC_LARGE_PKT_DIFF )) +return -EINVAL ;
[...]
It's a bit late to detect invalid arguments when you've already started applying changes.
Ben.
Signature · 2 lines
Ben Hutchings Humans are not rational beings; they are rationalising beings.