Commit d7ee2878 authored by David S. Miller's avatar David S. Miller

Merge tag 'blk-dim-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux

Saeed Mamameed says:

====================
Generic DIM

From: Tal Gilboa and Yamin Fridman

Implement net DIM over a generic DIM library, add RDMA DIM

dim.h lib exposes an implementation of the DIM algorithm for
dynamically-tuned interrupt moderation for networking interfaces.

We want a similar functionality for other protocols, which might need to
optimize interrupts differently. Main motivation here is DIM for NVMf
storage protocol.

Current DIM implementation prioritizes reducing interrupt overhead over
latency. Also, in order to reduce DIM's own overhead, the algorithm might
take some time to identify it needs to change profiles. While this is
acceptable for networking, it might not work well on other scenarios.

Here we propose a new structure to DIM. The idea is to allow a slightly
modified functionality without the risk of breaking Net DIM behavior for
netdev. We verified there are no degradations in current DIM behavior with
the modified solution.

Suggested solution:
- Common logic is implemented in lib/dim/dim.c
- Net DIM (existing) logic is implemented in lib/dim/net_dim.c, which uses
  the common logic in dim.c
- Any new DIM logic will be implemented in "lib/dim/new_dim.c".
  This new implementation will expose modified versions of profiles,
  dim_step() and dim_decision().
- DIM API is declared in include/linux/dim.h for all implementations.

Pros for this solution are:
- Zero impact on existing net_dim implementation and usage
- Relatively more code reuse (compared to two separate solutions)
- Increased extensibility
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a653f2f5 398c2b05
...@@ -5602,7 +5602,8 @@ F: include/linux/dynamic_debug.h ...@@ -5602,7 +5602,8 @@ F: include/linux/dynamic_debug.h
DYNAMIC INTERRUPT MODERATION DYNAMIC INTERRUPT MODERATION
M: Tal Gilboa <talgi@mellanox.com> M: Tal Gilboa <talgi@mellanox.com>
S: Maintained S: Maintained
F: include/linux/net_dim.h F: include/linux/dim.h
F: lib/dim/
DZ DECSTATION DZ11 SERIAL DRIVER DZ DECSTATION DZ11 SERIAL DRIVER
M: "Maciej W. Rozycki" <macro@linux-mips.org> M: "Maciej W. Rozycki" <macro@linux-mips.org>
......
...@@ -8,6 +8,7 @@ config NET_VENDOR_BROADCOM ...@@ -8,6 +8,7 @@ config NET_VENDOR_BROADCOM
default y default y
depends on (SSB_POSSIBLE && HAS_DMA) || PCI || BCM63XX || \ depends on (SSB_POSSIBLE && HAS_DMA) || PCI || BCM63XX || \
SIBYTE_SB1xxx_SOC SIBYTE_SB1xxx_SOC
select DIMLIB
---help--- ---help---
If you have a network (Ethernet) chipset belonging to this class, If you have a network (Ethernet) chipset belonging to this class,
say Y. say Y.
......
...@@ -609,7 +609,7 @@ static int bcm_sysport_set_coalesce(struct net_device *dev, ...@@ -609,7 +609,7 @@ static int bcm_sysport_set_coalesce(struct net_device *dev,
struct ethtool_coalesce *ec) struct ethtool_coalesce *ec)
{ {
struct bcm_sysport_priv *priv = netdev_priv(dev); struct bcm_sysport_priv *priv = netdev_priv(dev);
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
u32 usecs, pkts; u32 usecs, pkts;
unsigned int i; unsigned int i;
...@@ -992,7 +992,7 @@ static int bcm_sysport_poll(struct napi_struct *napi, int budget) ...@@ -992,7 +992,7 @@ static int bcm_sysport_poll(struct napi_struct *napi, int budget)
{ {
struct bcm_sysport_priv *priv = struct bcm_sysport_priv *priv =
container_of(napi, struct bcm_sysport_priv, napi); container_of(napi, struct bcm_sysport_priv, napi);
struct net_dim_sample dim_sample; struct dim_sample dim_sample;
unsigned int work_done = 0; unsigned int work_done = 0;
work_done = bcm_sysport_desc_rx(priv, budget); work_done = bcm_sysport_desc_rx(priv, budget);
...@@ -1016,7 +1016,7 @@ static int bcm_sysport_poll(struct napi_struct *napi, int budget) ...@@ -1016,7 +1016,7 @@ static int bcm_sysport_poll(struct napi_struct *napi, int budget)
} }
if (priv->dim.use_dim) { if (priv->dim.use_dim) {
net_dim_sample(priv->dim.event_ctr, priv->dim.packets, dim_update_sample(priv->dim.event_ctr, priv->dim.packets,
priv->dim.bytes, &dim_sample); priv->dim.bytes, &dim_sample);
net_dim(&priv->dim.dim, dim_sample); net_dim(&priv->dim.dim, dim_sample);
} }
...@@ -1087,16 +1087,16 @@ static void bcm_sysport_resume_from_wol(struct bcm_sysport_priv *priv) ...@@ -1087,16 +1087,16 @@ static void bcm_sysport_resume_from_wol(struct bcm_sysport_priv *priv)
static void bcm_sysport_dim_work(struct work_struct *work) static void bcm_sysport_dim_work(struct work_struct *work)
{ {
struct net_dim *dim = container_of(work, struct net_dim, work); struct dim *dim = container_of(work, struct dim, work);
struct bcm_sysport_net_dim *ndim = struct bcm_sysport_net_dim *ndim =
container_of(dim, struct bcm_sysport_net_dim, dim); container_of(dim, struct bcm_sysport_net_dim, dim);
struct bcm_sysport_priv *priv = struct bcm_sysport_priv *priv =
container_of(ndim, struct bcm_sysport_priv, dim); container_of(ndim, struct bcm_sysport_priv, dim);
struct net_dim_cq_moder cur_profile = struct dim_cq_moder cur_profile = net_dim_get_rx_moderation(dim->mode,
net_dim_get_rx_moderation(dim->mode, dim->profile_ix); dim->profile_ix);
bcm_sysport_set_rx_coalesce(priv, cur_profile.usec, cur_profile.pkts); bcm_sysport_set_rx_coalesce(priv, cur_profile.usec, cur_profile.pkts);
dim->state = NET_DIM_START_MEASURE; dim->state = DIM_START_MEASURE;
} }
/* RX and misc interrupt routine */ /* RX and misc interrupt routine */
...@@ -1437,7 +1437,7 @@ static void bcm_sysport_init_dim(struct bcm_sysport_priv *priv, ...@@ -1437,7 +1437,7 @@ static void bcm_sysport_init_dim(struct bcm_sysport_priv *priv,
struct bcm_sysport_net_dim *dim = &priv->dim; struct bcm_sysport_net_dim *dim = &priv->dim;
INIT_WORK(&dim->dim.work, cb); INIT_WORK(&dim->dim.work, cb);
dim->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; dim->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
dim->event_ctr = 0; dim->event_ctr = 0;
dim->packets = 0; dim->packets = 0;
dim->bytes = 0; dim->bytes = 0;
...@@ -1446,7 +1446,7 @@ static void bcm_sysport_init_dim(struct bcm_sysport_priv *priv, ...@@ -1446,7 +1446,7 @@ static void bcm_sysport_init_dim(struct bcm_sysport_priv *priv,
static void bcm_sysport_init_rx_coalesce(struct bcm_sysport_priv *priv) static void bcm_sysport_init_rx_coalesce(struct bcm_sysport_priv *priv)
{ {
struct bcm_sysport_net_dim *dim = &priv->dim; struct bcm_sysport_net_dim *dim = &priv->dim;
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
u32 usecs, pkts; u32 usecs, pkts;
usecs = priv->rx_coalesce_usecs; usecs = priv->rx_coalesce_usecs;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/net_dim.h> #include <linux/dim.h>
/* Receive/transmit descriptor format */ /* Receive/transmit descriptor format */
#define DESC_ADDR_HI_STATUS_LEN 0x00 #define DESC_ADDR_HI_STATUS_LEN 0x00
...@@ -702,7 +702,7 @@ struct bcm_sysport_net_dim { ...@@ -702,7 +702,7 @@ struct bcm_sysport_net_dim {
u16 event_ctr; u16 event_ctr;
unsigned long packets; unsigned long packets;
unsigned long bytes; unsigned long bytes;
struct net_dim dim; struct dim dim;
}; };
/* Software view of the TX ring */ /* Software view of the TX ring */
......
...@@ -2130,9 +2130,9 @@ static int bnxt_poll(struct napi_struct *napi, int budget) ...@@ -2130,9 +2130,9 @@ static int bnxt_poll(struct napi_struct *napi, int budget)
} }
} }
if (bp->flags & BNXT_FLAG_DIM) { if (bp->flags & BNXT_FLAG_DIM) {
struct net_dim_sample dim_sample; struct dim_sample dim_sample;
net_dim_sample(cpr->event_ctr, dim_update_sample(cpr->event_ctr,
cpr->rx_packets, cpr->rx_packets,
cpr->rx_bytes, cpr->rx_bytes,
&dim_sample); &dim_sample);
...@@ -7813,7 +7813,7 @@ static void bnxt_enable_napi(struct bnxt *bp) ...@@ -7813,7 +7813,7 @@ static void bnxt_enable_napi(struct bnxt *bp)
if (bp->bnapi[i]->rx_ring) { if (bp->bnapi[i]->rx_ring) {
INIT_WORK(&cpr->dim.work, bnxt_dim_work); INIT_WORK(&cpr->dim.work, bnxt_dim_work);
cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; cpr->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
} }
napi_enable(&bp->bnapi[i]->napi); napi_enable(&bp->bnapi[i]->napi);
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <net/devlink.h> #include <net/devlink.h>
#include <net/dst_metadata.h> #include <net/dst_metadata.h>
#include <net/xdp.h> #include <net/xdp.h>
#include <linux/net_dim.h> #include <linux/dim.h>
struct tx_bd { struct tx_bd {
__le32 tx_bd_len_flags_type; __le32 tx_bd_len_flags_type;
...@@ -810,7 +810,7 @@ struct bnxt_cp_ring_info { ...@@ -810,7 +810,7 @@ struct bnxt_cp_ring_info {
u64 rx_bytes; u64 rx_bytes;
u64 event_ctr; u64 event_ctr;
struct net_dim dim; struct dim dim;
union { union {
struct tx_cmp *cp_desc_ring[MAX_CP_PAGES]; struct tx_cmp *cp_desc_ring[MAX_CP_PAGES];
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
#include "bnxt_hsi.h" #include "bnxt_hsi.h"
#include <linux/net_dim.h> #include <linux/dim.h>
#include "bnxt.h" #include "bnxt.h"
#include "bnxt_debugfs.h" #include "bnxt_debugfs.h"
...@@ -21,7 +21,7 @@ static ssize_t debugfs_dim_read(struct file *filep, ...@@ -21,7 +21,7 @@ static ssize_t debugfs_dim_read(struct file *filep,
char __user *buffer, char __user *buffer,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct net_dim *dim = filep->private_data; struct dim *dim = filep->private_data;
int len; int len;
char *buf; char *buf;
...@@ -61,7 +61,7 @@ static const struct file_operations debugfs_dim_fops = { ...@@ -61,7 +61,7 @@ static const struct file_operations debugfs_dim_fops = {
.read = debugfs_dim_read, .read = debugfs_dim_read,
}; };
static struct dentry *debugfs_dim_ring_init(struct net_dim *dim, int ring_idx, static struct dentry *debugfs_dim_ring_init(struct dim *dim, int ring_idx,
struct dentry *dd) struct dentry *dd)
{ {
static char qname[16]; static char qname[16];
......
...@@ -7,26 +7,25 @@ ...@@ -7,26 +7,25 @@
* the Free Software Foundation. * the Free Software Foundation.
*/ */
#include <linux/net_dim.h> #include <linux/dim.h>
#include "bnxt_hsi.h" #include "bnxt_hsi.h"
#include "bnxt.h" #include "bnxt.h"
void bnxt_dim_work(struct work_struct *work) void bnxt_dim_work(struct work_struct *work)
{ {
struct net_dim *dim = container_of(work, struct net_dim, struct dim *dim = container_of(work, struct dim, work);
work);
struct bnxt_cp_ring_info *cpr = container_of(dim, struct bnxt_cp_ring_info *cpr = container_of(dim,
struct bnxt_cp_ring_info, struct bnxt_cp_ring_info,
dim); dim);
struct bnxt_napi *bnapi = container_of(cpr, struct bnxt_napi *bnapi = container_of(cpr,
struct bnxt_napi, struct bnxt_napi,
cp_ring); cp_ring);
struct net_dim_cq_moder cur_moder = struct dim_cq_moder cur_moder =
net_dim_get_rx_moderation(dim->mode, dim->profile_ix); net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
cpr->rx_ring_coal.coal_ticks = cur_moder.usec; cpr->rx_ring_coal.coal_ticks = cur_moder.usec;
cpr->rx_ring_coal.coal_bufs = cur_moder.pkts; cpr->rx_ring_coal.coal_bufs = cur_moder.pkts;
bnxt_hwrm_set_ring_coal(bnapi->bp, bnapi); bnxt_hwrm_set_ring_coal(bnapi->bp, bnapi);
dim->state = NET_DIM_START_MEASURE; dim->state = DIM_START_MEASURE;
} }
...@@ -640,7 +640,7 @@ static void bcmgenet_set_rx_coalesce(struct bcmgenet_rx_ring *ring, ...@@ -640,7 +640,7 @@ static void bcmgenet_set_rx_coalesce(struct bcmgenet_rx_ring *ring,
static void bcmgenet_set_ring_rx_coalesce(struct bcmgenet_rx_ring *ring, static void bcmgenet_set_ring_rx_coalesce(struct bcmgenet_rx_ring *ring,
struct ethtool_coalesce *ec) struct ethtool_coalesce *ec)
{ {
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
u32 usecs, pkts; u32 usecs, pkts;
ring->rx_coalesce_usecs = ec->rx_coalesce_usecs; ring->rx_coalesce_usecs = ec->rx_coalesce_usecs;
...@@ -1895,7 +1895,7 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget) ...@@ -1895,7 +1895,7 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget)
{ {
struct bcmgenet_rx_ring *ring = container_of(napi, struct bcmgenet_rx_ring *ring = container_of(napi,
struct bcmgenet_rx_ring, napi); struct bcmgenet_rx_ring, napi);
struct net_dim_sample dim_sample; struct dim_sample dim_sample;
unsigned int work_done; unsigned int work_done;
work_done = bcmgenet_desc_rx(ring, budget); work_done = bcmgenet_desc_rx(ring, budget);
...@@ -1906,7 +1906,7 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget) ...@@ -1906,7 +1906,7 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget)
} }
if (ring->dim.use_dim) { if (ring->dim.use_dim) {
net_dim_sample(ring->dim.event_ctr, ring->dim.packets, dim_update_sample(ring->dim.event_ctr, ring->dim.packets,
ring->dim.bytes, &dim_sample); ring->dim.bytes, &dim_sample);
net_dim(&ring->dim.dim, dim_sample); net_dim(&ring->dim.dim, dim_sample);
} }
...@@ -1916,16 +1916,16 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget) ...@@ -1916,16 +1916,16 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget)
static void bcmgenet_dim_work(struct work_struct *work) static void bcmgenet_dim_work(struct work_struct *work)
{ {
struct net_dim *dim = container_of(work, struct net_dim, work); struct dim *dim = container_of(work, struct dim, work);
struct bcmgenet_net_dim *ndim = struct bcmgenet_net_dim *ndim =
container_of(dim, struct bcmgenet_net_dim, dim); container_of(dim, struct bcmgenet_net_dim, dim);
struct bcmgenet_rx_ring *ring = struct bcmgenet_rx_ring *ring =
container_of(ndim, struct bcmgenet_rx_ring, dim); container_of(ndim, struct bcmgenet_rx_ring, dim);
struct net_dim_cq_moder cur_profile = struct dim_cq_moder cur_profile =
net_dim_get_rx_moderation(dim->mode, dim->profile_ix); net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
bcmgenet_set_rx_coalesce(ring, cur_profile.usec, cur_profile.pkts); bcmgenet_set_rx_coalesce(ring, cur_profile.usec, cur_profile.pkts);
dim->state = NET_DIM_START_MEASURE; dim->state = DIM_START_MEASURE;
} }
/* Assign skb to RX DMA descriptor. */ /* Assign skb to RX DMA descriptor. */
...@@ -2082,7 +2082,7 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring, ...@@ -2082,7 +2082,7 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring,
struct bcmgenet_net_dim *dim = &ring->dim; struct bcmgenet_net_dim *dim = &ring->dim;
INIT_WORK(&dim->dim.work, cb); INIT_WORK(&dim->dim.work, cb);
dim->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; dim->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
dim->event_ctr = 0; dim->event_ctr = 0;
dim->packets = 0; dim->packets = 0;
dim->bytes = 0; dim->bytes = 0;
...@@ -2091,7 +2091,7 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring, ...@@ -2091,7 +2091,7 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring,
static void bcmgenet_init_rx_coalesce(struct bcmgenet_rx_ring *ring) static void bcmgenet_init_rx_coalesce(struct bcmgenet_rx_ring *ring)
{ {
struct bcmgenet_net_dim *dim = &ring->dim; struct bcmgenet_net_dim *dim = &ring->dim;
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
u32 usecs, pkts; u32 usecs, pkts;
usecs = ring->rx_coalesce_usecs; usecs = ring->rx_coalesce_usecs;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <linux/mii.h> #include <linux/mii.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/net_dim.h> #include <linux/dim.h>
/* total number of Buffer Descriptors, same for Rx/Tx */ /* total number of Buffer Descriptors, same for Rx/Tx */
#define TOTAL_DESC 256 #define TOTAL_DESC 256
...@@ -578,7 +578,7 @@ struct bcmgenet_net_dim { ...@@ -578,7 +578,7 @@ struct bcmgenet_net_dim {
u16 event_ctr; u16 event_ctr;
unsigned long packets; unsigned long packets;
unsigned long bytes; unsigned long bytes;
struct net_dim dim; struct dim dim;
}; };
struct bcmgenet_rx_ring { struct bcmgenet_rx_ring {
......
...@@ -34,6 +34,7 @@ config MLX5_CORE_EN ...@@ -34,6 +34,7 @@ config MLX5_CORE_EN
depends on NETDEVICES && ETHERNET && INET && PCI && MLX5_CORE depends on NETDEVICES && ETHERNET && INET && PCI && MLX5_CORE
depends on IPV6=y || IPV6=n || MLX5_CORE=m depends on IPV6=y || IPV6=n || MLX5_CORE=m
select PAGE_POOL select PAGE_POOL
select DIMLIB
default n default n
---help--- ---help---
Ethernet support in Mellanox Technologies ConnectX-4 NIC. Ethernet support in Mellanox Technologies ConnectX-4 NIC.
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#include <linux/rhashtable.h> #include <linux/rhashtable.h>
#include <net/switchdev.h> #include <net/switchdev.h>
#include <net/xdp.h> #include <net/xdp.h>
#include <linux/net_dim.h> #include <linux/dim.h>
#include <linux/bits.h> #include <linux/bits.h>
#include "wq.h" #include "wq.h"
#include "mlx5_core.h" #include "mlx5_core.h"
...@@ -238,9 +238,9 @@ struct mlx5e_params { ...@@ -238,9 +238,9 @@ struct mlx5e_params {
u16 num_channels; u16 num_channels;
u8 num_tc; u8 num_tc;
bool rx_cqe_compress_def; bool rx_cqe_compress_def;
struct net_dim_cq_moder rx_cq_moderation;
struct net_dim_cq_moder tx_cq_moderation;
bool tunneled_offload_en; bool tunneled_offload_en;
struct dim_cq_moder rx_cq_moderation;
struct dim_cq_moder tx_cq_moderation;
bool lro_en; bool lro_en;
u8 tx_min_inline_mode; u8 tx_min_inline_mode;
bool vlan_strip_disable; bool vlan_strip_disable;
...@@ -356,7 +356,7 @@ struct mlx5e_txqsq { ...@@ -356,7 +356,7 @@ struct mlx5e_txqsq {
/* dirtied @completion */ /* dirtied @completion */
u16 cc; u16 cc;
u32 dma_fifo_cc; u32 dma_fifo_cc;
struct net_dim dim; /* Adaptive Moderation */ struct dim dim; /* Adaptive Moderation */
/* dirtied @xmit */ /* dirtied @xmit */
u16 pc ____cacheline_aligned_in_smp; u16 pc ____cacheline_aligned_in_smp;
...@@ -596,7 +596,7 @@ struct mlx5e_rq { ...@@ -596,7 +596,7 @@ struct mlx5e_rq {
int ix; int ix;
unsigned int hw_mtu; unsigned int hw_mtu;
struct net_dim dim; /* Dynamic Interrupt Moderation */ struct dim dim; /* Dynamic Interrupt Moderation */
/* XDP */ /* XDP */
struct bpf_prog *xdp_prog; struct bpf_prog *xdp_prog;
......
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <linux/net_dim.h> #include <linux/dim.h>
#include "en.h" #include "en.h"
static void static void
mlx5e_complete_dim_work(struct net_dim *dim, struct net_dim_cq_moder moder, mlx5e_complete_dim_work(struct dim *dim, struct dim_cq_moder moder,
struct mlx5_core_dev *mdev, struct mlx5_core_cq *mcq) struct mlx5_core_dev *mdev, struct mlx5_core_cq *mcq)
{ {
mlx5_core_modify_cq_moderation(mdev, mcq, moder.usec, moder.pkts); mlx5_core_modify_cq_moderation(mdev, mcq, moder.usec, moder.pkts);
dim->state = NET_DIM_START_MEASURE; dim->state = DIM_START_MEASURE;
} }
void mlx5e_rx_dim_work(struct work_struct *work) void mlx5e_rx_dim_work(struct work_struct *work)
{ {
struct net_dim *dim = container_of(work, struct net_dim, work); struct dim *dim = container_of(work, struct dim, work);
struct mlx5e_rq *rq = container_of(dim, struct mlx5e_rq, dim); struct mlx5e_rq *rq = container_of(dim, struct mlx5e_rq, dim);
struct net_dim_cq_moder cur_moder = struct dim_cq_moder cur_moder =
net_dim_get_rx_moderation(dim->mode, dim->profile_ix); net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
mlx5e_complete_dim_work(dim, cur_moder, rq->mdev, &rq->cq.mcq); mlx5e_complete_dim_work(dim, cur_moder, rq->mdev, &rq->cq.mcq);
...@@ -53,9 +53,9 @@ void mlx5e_rx_dim_work(struct work_struct *work) ...@@ -53,9 +53,9 @@ void mlx5e_rx_dim_work(struct work_struct *work)
void mlx5e_tx_dim_work(struct work_struct *work) void mlx5e_tx_dim_work(struct work_struct *work)
{ {
struct net_dim *dim = container_of(work, struct net_dim, work); struct dim *dim = container_of(work, struct dim, work);
struct mlx5e_txqsq *sq = container_of(dim, struct mlx5e_txqsq, dim); struct mlx5e_txqsq *sq = container_of(dim, struct mlx5e_txqsq, dim);
struct net_dim_cq_moder cur_moder = struct dim_cq_moder cur_moder =
net_dim_get_tx_moderation(dim->mode, dim->profile_ix); net_dim_get_tx_moderation(dim->mode, dim->profile_ix);
mlx5e_complete_dim_work(dim, cur_moder, sq->cq.mdev, &sq->cq.mcq); mlx5e_complete_dim_work(dim, cur_moder, sq->cq.mdev, &sq->cq.mcq);
......
...@@ -466,7 +466,7 @@ static int mlx5e_set_channels(struct net_device *dev, ...@@ -466,7 +466,7 @@ static int mlx5e_set_channels(struct net_device *dev,
int mlx5e_ethtool_get_coalesce(struct mlx5e_priv *priv, int mlx5e_ethtool_get_coalesce(struct mlx5e_priv *priv,
struct ethtool_coalesce *coal) struct ethtool_coalesce *coal)
{ {
struct net_dim_cq_moder *rx_moder, *tx_moder; struct dim_cq_moder *rx_moder, *tx_moder;
if (!MLX5_CAP_GEN(priv->mdev, cq_moderation)) if (!MLX5_CAP_GEN(priv->mdev, cq_moderation))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -521,7 +521,7 @@ mlx5e_set_priv_channels_coalesce(struct mlx5e_priv *priv, struct ethtool_coalesc ...@@ -521,7 +521,7 @@ mlx5e_set_priv_channels_coalesce(struct mlx5e_priv *priv, struct ethtool_coalesc
int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv, int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
struct ethtool_coalesce *coal) struct ethtool_coalesce *coal)
{ {
struct net_dim_cq_moder *rx_moder, *tx_moder; struct dim_cq_moder *rx_moder, *tx_moder;
struct mlx5_core_dev *mdev = priv->mdev; struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {}; struct mlx5e_channels new_channels = {};
int err = 0; int err = 0;
......
...@@ -586,11 +586,11 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, ...@@ -586,11 +586,11 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
switch (params->rx_cq_moderation.cq_period_mode) { switch (params->rx_cq_moderation.cq_period_mode) {
case MLX5_CQ_PERIOD_MODE_START_FROM_CQE: case MLX5_CQ_PERIOD_MODE_START_FROM_CQE:
rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE; rq->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_CQE;
break; break;
case MLX5_CQ_PERIOD_MODE_START_FROM_EQE: case MLX5_CQ_PERIOD_MODE_START_FROM_EQE:
default: default:
rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; rq->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
} }
rq->page_cache.head = 0; rq->page_cache.head = 0;
...@@ -1568,7 +1568,7 @@ static void mlx5e_destroy_cq(struct mlx5e_cq *cq) ...@@ -1568,7 +1568,7 @@ static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
} }
static int mlx5e_open_cq(struct mlx5e_channel *c, static int mlx5e_open_cq(struct mlx5e_channel *c,
struct net_dim_cq_moder moder, struct dim_cq_moder moder,
struct mlx5e_cq_param *param, struct mlx5e_cq_param *param,
struct mlx5e_cq *cq) struct mlx5e_cq *cq)
{ {
...@@ -1773,7 +1773,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix, ...@@ -1773,7 +1773,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
struct mlx5e_channel **cp) struct mlx5e_channel **cp)
{ {
int cpu = cpumask_first(mlx5_comp_irq_get_affinity_mask(priv->mdev, ix)); int cpu = cpumask_first(mlx5_comp_irq_get_affinity_mask(priv->mdev, ix));
struct net_dim_cq_moder icocq_moder = {0, 0}; struct dim_cq_moder icocq_moder = {0, 0};
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
struct mlx5e_channel *c; struct mlx5e_channel *c;
unsigned int irq; unsigned int irq;
...@@ -2150,7 +2150,7 @@ static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv, ...@@ -2150,7 +2150,7 @@ static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
mlx5e_build_common_cq_param(priv, param); mlx5e_build_common_cq_param(priv, param);
param->cq_period_mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; param->cq_period_mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
} }
static void mlx5e_build_icosq_param(struct mlx5e_priv *priv, static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
...@@ -4418,9 +4418,9 @@ static bool slow_pci_heuristic(struct mlx5_core_dev *mdev) ...@@ -4418,9 +4418,9 @@ static bool slow_pci_heuristic(struct mlx5_core_dev *mdev)
link_speed > MLX5E_SLOW_PCI_RATIO * pci_bw; link_speed > MLX5E_SLOW_PCI_RATIO * pci_bw;
} }
static struct net_dim_cq_moder mlx5e_get_def_tx_moderation(u8 cq_period_mode) static struct dim_cq_moder mlx5e_get_def_tx_moderation(u8 cq_period_mode)
{ {
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
moder.cq_period_mode = cq_period_mode; moder.cq_period_mode = cq_period_mode;
moder.pkts = MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS; moder.pkts = MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
...@@ -4431,9 +4431,9 @@ static struct net_dim_cq_moder mlx5e_get_def_tx_moderation(u8 cq_period_mode) ...@@ -4431,9 +4431,9 @@ static struct net_dim_cq_moder mlx5e_get_def_tx_moderation(u8 cq_period_mode)
return moder; return moder;
} }
static struct net_dim_cq_moder mlx5e_get_def_rx_moderation(u8 cq_period_mode) static struct dim_cq_moder mlx5e_get_def_rx_moderation(u8 cq_period_mode)
{ {
struct net_dim_cq_moder moder; struct dim_cq_moder moder;
moder.cq_period_mode = cq_period_mode; moder.cq_period_mode = cq_period_mode;
moder.pkts = MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS; moder.pkts = MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
...@@ -4447,8 +4447,8 @@ static struct net_dim_cq_moder mlx5e_get_def_rx_moderation(u8 cq_period_mode) ...@@ -4447,8 +4447,8 @@ static struct net_dim_cq_moder mlx5e_get_def_rx_moderation(u8 cq_period_mode)
static u8 mlx5_to_net_dim_cq_period_mode(u8 cq_period_mode) static u8 mlx5_to_net_dim_cq_period_mode(u8 cq_period_mode)
{ {
return cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE ? return cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE ?
NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE : DIM_CQ_PERIOD_MODE_START_FROM_CQE :
NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; DIM_CQ_PERIOD_MODE_START_FROM_EQE;
} }
void mlx5e_set_tx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode) void mlx5e_set_tx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode)
......
...@@ -48,26 +48,24 @@ static inline bool mlx5e_channel_no_affinity_change(struct mlx5e_channel *c) ...@@ -48,26 +48,24 @@ static inline bool mlx5e_channel_no_affinity_change(struct mlx5e_channel *c)
static void mlx5e_handle_tx_dim(struct mlx5e_txqsq *sq) static void mlx5e_handle_tx_dim(struct mlx5e_txqsq *sq)
{ {
struct mlx5e_sq_stats *stats = sq->stats; struct mlx5e_sq_stats *stats = sq->stats;
struct net_dim_sample dim_sample; struct dim_sample dim_sample;
if (unlikely(!test_bit(MLX5E_SQ_STATE_AM, &sq->state))) if (unlikely(!test_bit(MLX5E_SQ_STATE_AM, &sq->state)))
return; return;
net_dim_sample(sq->cq.event_ctr, stats->packets, stats->bytes, dim_update_sample(sq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample);
&dim_sample);
net_dim(&sq->dim, dim_sample); net_dim(&sq->dim, dim_sample);
} }
static void mlx5e_handle_rx_dim(struct mlx5e_rq *rq) static void mlx5e_handle_rx_dim(struct mlx5e_rq *rq)
{ {
struct mlx5e_rq_stats *stats = rq->stats; struct mlx5e_rq_stats *stats = rq->stats;
struct net_dim_sample dim_sample; struct dim_sample dim_sample;
if (unlikely(!test_bit(MLX5E_RQ_STATE_AM, &rq->state))) if (unlikely(!test_bit(MLX5E_RQ_STATE_AM, &rq->state)))
return; return;
net_dim_sample(rq->cq.event_ctr, stats->packets, stats->bytes, dim_update_sample(rq->cq.event_ctr, stats->packets, stats->bytes, &dim_sample);
&dim_sample);
net_dim(&rq->dim, dim_sample); net_dim(&rq->dim, dim_sample);
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -562,6 +562,14 @@ config SIGNATURE ...@@ -562,6 +562,14 @@ config SIGNATURE
Digital signature verification. Currently only RSA is supported. Digital signature verification. Currently only RSA is supported.
Implementation is done using GnuPG MPI library Implementation is done using GnuPG MPI library
config DIMLIB
bool "DIM library"
default y
help
Dynamic Interrupt Moderation library.
Implements an algorithm for dynamically change CQ modertion values
according to run time performance.
# #
# libfdt files, only selected if needed. # libfdt files, only selected if needed.
# #
......
...@@ -202,6 +202,7 @@ obj-$(CONFIG_GLOB) += glob.o ...@@ -202,6 +202,7 @@ obj-$(CONFIG_GLOB) += glob.o
obj-$(CONFIG_GLOB_SELFTEST) += globtest.o obj-$(CONFIG_GLOB_SELFTEST) += globtest.o
obj-$(CONFIG_MPILIB) += mpi/ obj-$(CONFIG_MPILIB) += mpi/
obj-$(CONFIG_DIMLIB) += dim/
obj-$(CONFIG_SIGNATURE) += digsig.o obj-$(CONFIG_SIGNATURE) += digsig.o
lib-$(CONFIG_CLZ_TAB) += clz_tab.o lib-$(CONFIG_CLZ_TAB) += clz_tab.o
......
#
# DIM Dynamic Interrupt Moderation library
#
obj-$(CONFIG_DIMLIB) = net_dim.o
net_dim-y = \
dim.o \
net_dim.o
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/*
* Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
*/
#include <linux/dim.h>
bool dim_on_top(struct dim *dim)
{
switch (dim->tune_state) {
case DIM_PARKING_ON_TOP:
case DIM_PARKING_TIRED:
return true;
case DIM_GOING_RIGHT:
return (dim->steps_left > 1) && (dim->steps_right == 1);
default: /* DIM_GOING_LEFT */
return (dim->steps_right > 1) && (dim->steps_left == 1);
}
}
EXPORT_SYMBOL(dim_on_top);
void dim_turn(struct dim *dim)
{
switch (dim->tune_state) {
case DIM_PARKING_ON_TOP:
case DIM_PARKING_TIRED:
break;
case DIM_GOING_RIGHT:
dim->tune_state = DIM_GOING_LEFT;
dim->steps_left = 0;
break;
case DIM_GOING_LEFT:
dim->tune_state = DIM_GOING_RIGHT;
dim->steps_right = 0;
break;
}
}
EXPORT_SYMBOL(dim_turn);
void dim_park_on_top(struct dim *dim)
{
dim->steps_right = 0;
dim->steps_left = 0;
dim->tired = 0;
dim->tune_state = DIM_PARKING_ON_TOP;
}
EXPORT_SYMBOL(dim_park_on_top);
void dim_park_tired(struct dim *dim)
{
dim->steps_right = 0;
dim->steps_left = 0;
dim->tune_state = DIM_PARKING_TIRED;
}
EXPORT_SYMBOL(dim_park_tired);
void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
struct dim_stats *curr_stats)
{
/* u32 holds up to 71 minutes, should be enough */
u32 delta_us = ktime_us_delta(end->time, start->time);
u32 npkts = BIT_GAP(BITS_PER_TYPE(u32), end->pkt_ctr, start->pkt_ctr);
u32 nbytes = BIT_GAP(BITS_PER_TYPE(u32), end->byte_ctr,
start->byte_ctr);
u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
start->comp_ctr);
if (!delta_us)
return;
curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
delta_us);
curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
if (curr_stats->epms != 0)
curr_stats->cpe_ratio =
(curr_stats->cpms * 100) / curr_stats->epms;
else
curr_stats->cpe_ratio = 0;
}
EXPORT_SYMBOL(dim_calc_stats);
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/*
* Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
*/
#include <linux/dim.h>
struct dim_cq_moder
net_dim_get_rx_moderation(u8 cq_period_mode, int ix)
{
struct dim_cq_moder cq_moder = rx_profile[cq_period_mode][ix];
cq_moder.cq_period_mode = cq_period_mode;
return cq_moder;
}
EXPORT_SYMBOL(net_dim_get_rx_moderation);
struct dim_cq_moder
net_dim_get_def_rx_moderation(u8 cq_period_mode)
{
u8 profile_ix = cq_period_mode == DIM_CQ_PERIOD_MODE_START_FROM_CQE ?
NET_DIM_DEF_PROFILE_CQE : NET_DIM_DEF_PROFILE_EQE;
return net_dim_get_rx_moderation(cq_period_mode, profile_ix);
}
EXPORT_SYMBOL(net_dim_get_def_rx_moderation);
struct dim_cq_moder
net_dim_get_tx_moderation(u8 cq_period_mode, int ix)
{
struct dim_cq_moder cq_moder = tx_profile[cq_period_mode][ix];
cq_moder.cq_period_mode = cq_period_mode;
return cq_moder;
}
EXPORT_SYMBOL(net_dim_get_tx_moderation);
struct dim_cq_moder
net_dim_get_def_tx_moderation(u8 cq_period_mode)
{
u8 profile_ix = cq_period_mode == DIM_CQ_PERIOD_MODE_START_FROM_CQE ?
NET_DIM_DEF_PROFILE_CQE : NET_DIM_DEF_PROFILE_EQE;
return net_dim_get_tx_moderation(cq_period_mode, profile_ix);
}
EXPORT_SYMBOL(net_dim_get_def_tx_moderation);
static int net_dim_step(struct dim *dim)
{
if (dim->tired == (NET_DIM_PARAMS_NUM_PROFILES * 2))
return DIM_TOO_TIRED;
switch (dim->tune_state) {
case DIM_PARKING_ON_TOP:
case DIM_PARKING_TIRED:
break;
case DIM_GOING_RIGHT:
if (dim->profile_ix == (NET_DIM_PARAMS_NUM_PROFILES - 1))
return DIM_ON_EDGE;
dim->profile_ix++;
dim->steps_right++;
break;
case DIM_GOING_LEFT:
if (dim->profile_ix == 0)
return DIM_ON_EDGE;
dim->profile_ix--;
dim->steps_left++;
break;
}
dim->tired++;
return DIM_STEPPED;
}
static void net_dim_exit_parking(struct dim *dim)
{
dim->tune_state = dim->profile_ix ? DIM_GOING_LEFT : DIM_GOING_RIGHT;
net_dim_step(dim);
}
static int net_dim_stats_compare(struct dim_stats *curr,
struct dim_stats *prev)
{
if (!prev->bpms)
return curr->bpms ? DIM_STATS_BETTER : DIM_STATS_SAME;
if (IS_SIGNIFICANT_DIFF(curr->bpms, prev->bpms))
return (curr->bpms > prev->bpms) ? DIM_STATS_BETTER :
DIM_STATS_WORSE;
if (!prev->ppms)
return curr->ppms ? DIM_STATS_BETTER :
DIM_STATS_SAME;
if (IS_SIGNIFICANT_DIFF(curr->ppms, prev->ppms))
return (curr->ppms > prev->ppms) ? DIM_STATS_BETTER :
DIM_STATS_WORSE;
if (!prev->epms)
return DIM_STATS_SAME;
if (IS_SIGNIFICANT_DIFF(curr->epms, prev->epms))
return (curr->epms < prev->epms) ? DIM_STATS_BETTER :
DIM_STATS_WORSE;
return DIM_STATS_SAME;
}
static bool net_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
{
int prev_state = dim->tune_state;
int prev_ix = dim->profile_ix;
int stats_res;
int step_res;
switch (dim->tune_state) {
case DIM_PARKING_ON_TOP:
stats_res = net_dim_stats_compare(curr_stats,
&dim->prev_stats);
if (stats_res != DIM_STATS_SAME)
net_dim_exit_parking(dim);
break;
case DIM_PARKING_TIRED:
dim->tired--;
if (!dim->tired)
net_dim_exit_parking(dim);
break;
case DIM_GOING_RIGHT:
case DIM_GOING_LEFT:
stats_res = net_dim_stats_compare(curr_stats,
&dim->prev_stats);
if (stats_res != DIM_STATS_BETTER)
dim_turn(dim);
if (dim_on_top(dim)) {
dim_park_on_top(dim);
break;
}
step_res = net_dim_step(dim);
switch (step_res) {
case DIM_ON_EDGE:
dim_park_on_top(dim);
break;
case DIM_TOO_TIRED:
dim_park_tired(dim);
break;
}
break;
}
if (prev_state != DIM_PARKING_ON_TOP ||
dim->tune_state != DIM_PARKING_ON_TOP)
dim->prev_stats = *curr_stats;
return dim->profile_ix != prev_ix;
}
void net_dim(struct dim *dim, struct dim_sample end_sample)
{
struct dim_stats curr_stats;
u16 nevents;
switch (dim->state) {
case DIM_MEASURE_IN_PROGRESS:
nevents = BIT_GAP(BITS_PER_TYPE(u16),
end_sample.event_ctr,
dim->start_sample.event_ctr);
if (nevents < DIM_NEVENTS)
break;
dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats);
if (net_dim_decision(&curr_stats, dim)) {
dim->state = DIM_APPLY_NEW_PROFILE;
schedule_work(&dim->work);
break;
}
/* fall through */
case DIM_START_MEASURE:
dim_update_sample(end_sample.event_ctr, end_sample.pkt_ctr,
end_sample.byte_ctr, &dim->start_sample);
dim->state = DIM_MEASURE_IN_PROGRESS;
break;
case DIM_APPLY_NEW_PROFILE:
break;
}
}
EXPORT_SYMBOL(net_dim);
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