Commit 282faf61 authored by Arthur Kiyanovski's avatar Arthur Kiyanovski Committed by David S. Miller

net: ena: switch to dim algorithm for rx adaptive interrupt moderation

Use the dim library for the rx adaptive interrupt moderation implementation
Signed-off-by: default avatarArthur Kiyanovski <akiyano@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 15619e72
...@@ -2839,9 +2839,7 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev) ...@@ -2839,9 +2839,7 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev)
delay_resolution = get_resp.u.intr_moderation.intr_delay_resolution; delay_resolution = get_resp.u.intr_moderation.intr_delay_resolution;
ena_com_update_intr_delay_resolution(ena_dev, delay_resolution); ena_com_update_intr_delay_resolution(ena_dev, delay_resolution);
/* Disable adaptive moderation by default - can be enabled from /* Disable adaptive moderation by default - can be enabled later */
* ethtool
*/
ena_com_disable_adaptive_moderation(ena_dev); ena_com_disable_adaptive_moderation(ena_dev);
return 0; return 0;
......
...@@ -196,6 +196,7 @@ static void ena_init_io_rings(struct ena_adapter *adapter) ...@@ -196,6 +196,7 @@ static void ena_init_io_rings(struct ena_adapter *adapter)
rxr->smoothed_interval = rxr->smoothed_interval =
ena_com_get_nonadaptive_moderation_interval_rx(ena_dev); ena_com_get_nonadaptive_moderation_interval_rx(ena_dev);
rxr->empty_rx_queue = 0; rxr->empty_rx_queue = 0;
adapter->ena_napi[i].dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
} }
} }
...@@ -712,6 +713,7 @@ static void ena_destroy_all_rx_queues(struct ena_adapter *adapter) ...@@ -712,6 +713,7 @@ static void ena_destroy_all_rx_queues(struct ena_adapter *adapter)
for (i = 0; i < adapter->num_queues; i++) { for (i = 0; i < adapter->num_queues; i++) {
ena_qid = ENA_IO_RXQ_IDX(i); ena_qid = ENA_IO_RXQ_IDX(i);
cancel_work_sync(&adapter->ena_napi[i].dim.work);
ena_com_destroy_io_queue(adapter->ena_dev, ena_qid); ena_com_destroy_io_queue(adapter->ena_dev, ena_qid);
} }
} }
...@@ -1155,23 +1157,35 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi, ...@@ -1155,23 +1157,35 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
return 0; return 0;
} }
void ena_adjust_intr_moderation(struct ena_ring *rx_ring, static void ena_dim_work(struct work_struct *w)
struct ena_ring *tx_ring)
{ {
/* We apply adaptive moderation on Rx path only. struct dim *dim = container_of(w, struct dim, work);
* Tx uses static interrupt moderation. struct dim_cq_moder cur_moder =
*/ net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
ena_com_calculate_interrupt_delay(rx_ring->ena_dev, struct ena_napi *ena_napi = container_of(dim, struct ena_napi, dim);
rx_ring->per_napi_packets,
rx_ring->per_napi_bytes, ena_napi->rx_ring->smoothed_interval = cur_moder.usec;
&rx_ring->smoothed_interval, dim->state = DIM_START_MEASURE;
&rx_ring->moder_tbl_idx); }
/* Reset per napi packets/bytes */ static void ena_adjust_adaptive_rx_intr_moderation(struct ena_napi *ena_napi)
tx_ring->per_napi_packets = 0; {
tx_ring->per_napi_bytes = 0; struct dim_sample dim_sample;
struct ena_ring *rx_ring = ena_napi->rx_ring;
if (!rx_ring->per_napi_packets)
return;
rx_ring->non_empty_napi_events++;
dim_update_sample(rx_ring->non_empty_napi_events,
rx_ring->rx_stats.cnt,
rx_ring->rx_stats.bytes,
&dim_sample);
net_dim(&ena_napi->dim, dim_sample);
rx_ring->per_napi_packets = 0; rx_ring->per_napi_packets = 0;
rx_ring->per_napi_bytes = 0;
} }
static void ena_unmask_interrupt(struct ena_ring *tx_ring, static void ena_unmask_interrupt(struct ena_ring *tx_ring,
...@@ -1260,9 +1274,11 @@ static int ena_io_poll(struct napi_struct *napi, int budget) ...@@ -1260,9 +1274,11 @@ static int ena_io_poll(struct napi_struct *napi, int budget)
* from the interrupt context (vs from sk_busy_loop) * from the interrupt context (vs from sk_busy_loop)
*/ */
if (napi_complete_done(napi, rx_work_done)) { if (napi_complete_done(napi, rx_work_done)) {
/* Tx and Rx share the same interrupt vector */ /* We apply adaptive moderation on Rx path only.
* Tx uses static interrupt moderation.
*/
if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev)) if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
ena_adjust_intr_moderation(rx_ring, tx_ring); ena_adjust_adaptive_rx_intr_moderation(ena_napi);
ena_unmask_interrupt(tx_ring, rx_ring); ena_unmask_interrupt(tx_ring, rx_ring);
} }
...@@ -1740,13 +1756,16 @@ static int ena_create_all_io_rx_queues(struct ena_adapter *adapter) ...@@ -1740,13 +1756,16 @@ static int ena_create_all_io_rx_queues(struct ena_adapter *adapter)
rc = ena_create_io_rx_queue(adapter, i); rc = ena_create_io_rx_queue(adapter, i);
if (rc) if (rc)
goto create_err; goto create_err;
INIT_WORK(&adapter->ena_napi[i].dim.work, ena_dim_work);
} }
return 0; return 0;
create_err: create_err:
while (i--) while (i--) {
cancel_work_sync(&adapter->ena_napi[i].dim.work);
ena_com_destroy_io_queue(ena_dev, ENA_IO_RXQ_IDX(i)); ena_com_destroy_io_queue(ena_dev, ENA_IO_RXQ_IDX(i));
}
return rc; return rc;
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define ENA_H #define ENA_H
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/dim.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -153,6 +154,7 @@ struct ena_napi { ...@@ -153,6 +154,7 @@ struct ena_napi {
struct ena_ring *tx_ring; struct ena_ring *tx_ring;
struct ena_ring *rx_ring; struct ena_ring *rx_ring;
u32 qid; u32 qid;
struct dim dim;
}; };
struct ena_calc_queue_size_ctx { struct ena_calc_queue_size_ctx {
...@@ -280,6 +282,7 @@ struct ena_ring { ...@@ -280,6 +282,7 @@ struct ena_ring {
u32 per_napi_packets; u32 per_napi_packets;
u32 per_napi_bytes; u32 per_napi_bytes;
enum ena_intr_moder_level moder_tbl_idx; enum ena_intr_moder_level moder_tbl_idx;
u16 non_empty_napi_events;
struct u64_stats_sync syncp; struct u64_stats_sync syncp;
union { union {
struct ena_stats_tx tx_stats; struct ena_stats_tx tx_stats;
......
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