Skip to content

Instantly share code, notes, and snippets.

@scamp
Last active October 13, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scamp/4247737 to your computer and use it in GitHub Desktop.
Save scamp/4247737 to your computer and use it in GitHub Desktop.
Sysctl hw.em.max_interrupt_rate control added.
--- sys/dev/e1000/if_em.h.orig 2012-12-08 11:55:00.000000000 +0200
+++ sys/dev/e1000/if_em.h 2012-12-08 11:58:18.000000000 +0200
@@ -461,6 +461,9 @@
int prev_ticks;
#define NUM_STAT_MAX 5
struct net_stats stat_max[NUM_STAT_MAX];
+
+ /* Maximum interrupt rate */
+ int max_interrupt_rate;
};
/* ******************************************************************************
--- sys/dev/e1000/if_em.c.orig 2012-12-08 11:59:06.000000000 +0200
+++ sys/dev/e1000/if_em.c 2012-12-08 12:01:17.000000000 +0200
@@ -414,6 +414,10 @@
const char *, int *, int);
#endif
+#define MAX_INTS_PER_SEC 8000
+static unsigned em_max_interrupt_rate = MAX_INTS_PER_SEC;
+TUNABLE_INT("hw.em.max_interrupt_rate", &em_max_interrupt_rate);
+
/* Global used in WOL setup with multiport cards */
static int global_quad_port_a = 0;
@@ -524,6 +528,14 @@
AS(gprc); AS(gptc); AS(gorc); AS(gotc);
#undef AS
}
+
+ adapter->max_interrupt_rate = em_max_interrupt_rate;
+ SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
+ SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
+ OID_AUTO, "max_interrupt_rate", CTLTYPE_UINT|CTLFLAG_RW,
+ &adapter->max_interrupt_rate, adapter->max_interrupt_rate,
+ "Maximum interrupt rate");
+
callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
callout_init_mtx(&adapter->tx_fifo_timer, &adapter->tx_mtx, 0);
@@ -4288,8 +4300,6 @@
* Enable receive unit.
*
**********************************************************************/
-#define MAX_INTS_PER_SEC 8000
-#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
static void
em_initialize_receive_unit(struct adapter *adapter)
@@ -4312,9 +4322,12 @@
adapter->rx_abs_int_delay.value);
/*
* Set the interrupt throttling rate. Value is calculated
- * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns)
+ * as 1/(max_interrupt_rate * 256ns)
*/
-// E1000_WRITE_REG(&adapter->hw, E1000_ITR, DEFAULT_ITR);
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_ITR,
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
}
/*
@@ -4322,9 +4335,12 @@
** using the EITR register (82574 only)
*/
if (adapter->msix)
- for (int i = 0; i < 4; i++)
- E1000_WRITE_REG(&adapter->hw,
- E1000_EITR_82574(i), DEFAULT_ITR);
+ for (int i = 0; i < 4; i++) {
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_EITR_82574(i),
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
+ }
/* Disable accelerated ackknowledge */
if (adapter->hw.mac.type == e1000_82574)
--- sys/dev/e1000/if_em.h.orig 2012-12-08 11:55:00.000000000 +0200
+++ sys/dev/e1000/if_em.h 2012-12-08 11:58:18.000000000 +0200
@@ -461,6 +461,9 @@
int prev_ticks;
#define NUM_STAT_MAX 5
struct net_stats stat_max[NUM_STAT_MAX];
+
+ /* Maximum interrupt rate */
+ int max_interrupt_rate;
};
/* ******************************************************************************
--- sys/dev/e1000/if_em.c.orig 2012-12-08 11:59:06.000000000 +0200
+++ sys/dev/e1000/if_em.c 2012-12-08 12:01:17.000000000 +0200
@@ -414,6 +414,10 @@
const char *, int *, int);
#endif
+#define MAX_INTS_PER_SEC 8000
+static unsigned em_max_interrupt_rate = MAX_INTS_PER_SEC;
+TUNABLE_INT("hw.em.max_interrupt_rate", &em_max_interrupt_rate);
+
/* Global used in WOL setup with multiport cards */
static int global_quad_port_a = 0;
@@ -524,6 +528,14 @@
AS(gprc); AS(gptc); AS(gorc); AS(gotc);
#undef AS
}
+
+ adapter->max_interrupt_rate = em_max_interrupt_rate;
+ SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
+ SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
+ OID_AUTO, "max_interrupt_rate", CTLTYPE_UINT|CTLFLAG_RW,
+ &adapter->max_interrupt_rate, adapter->max_interrupt_rate,
+ "Maximum interrupt rate");
+
callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
callout_init_mtx(&adapter->tx_fifo_timer, &adapter->tx_mtx, 0);
@@ -4040,8 +4052,6 @@
* Enable receive unit.
*
**********************************************************************/
-#define MAX_INTS_PER_SEC 8000
-#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
static void
em_initialize_receive_unit(struct adapter *adapter)
@@ -4067,16 +4077,22 @@
* Set the interrupt throttling rate. Value is calculated
* as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns)
*/
-// E1000_WRITE_REG(hw, E1000_ITR, DEFAULT_ITR);
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_ITR,
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
/*
** When using MSIX interrupts we need to throttle
** using the EITR register (82574 only)
*/
if (hw->mac.type == e1000_82574)
- for (int i = 0; i < 4; i++)
- E1000_WRITE_REG(hw, E1000_EITR_82574(i),
- DEFAULT_ITR);
+ for (int i = 0; i < 4; i++) {
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_EITR_82574(i),
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
+ }
/* Disable accelerated ackknowledge */
if (adapter->hw.mac.type == e1000_82574)
--- sys/dev/e1000/if_em.h.orig 2013-04-08 14:01:40.000000000 +0300
+++ sys/dev/e1000/if_em.h 2013-04-08 22:06:19.000000000 +0300
@@ -475,6 +475,9 @@
int prev_ticks;
#define NUM_STAT_MAX 5
struct net_stats stat_max[NUM_STAT_MAX];
+
+ /* Maximum interrupt rate */
+ int max_interrupt_rate;
};
/********************************************************************************
--- sys/dev/e1000/if_em.c.orig 2013-04-08 14:01:40.000000000 +0300
+++ sys/dev/e1000/if_em.c 2013-04-08 22:11:55.000000000 +0300
@@ -380,6 +380,10 @@
static int em_fc_setting = e1000_fc_full;
TUNABLE_INT("hw.em.fc_setting", &em_fc_setting);
+#define MAX_INTS_PER_SEC 8000
+static unsigned em_max_interrupt_rate = MAX_INTS_PER_SEC;
+TUNABLE_INT("hw.em.max_interrupt_rate", &em_max_interrupt_rate);
+
/* Global used in WOL setup with multiport cards */
static int global_quad_port_a = 0;
@@ -484,6 +488,13 @@
#undef AS
}
+ adapter->max_interrupt_rate = em_max_interrupt_rate;
+ SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
+ SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
+ OID_AUTO, "max_interrupt_rate", CTLTYPE_UINT|CTLFLAG_RW,
+ &adapter->max_interrupt_rate, adapter->max_interrupt_rate,
+ "Maximum interrupt rate");
+
callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
/* Determine hardware and mac info */
@@ -4173,9 +4184,6 @@
* Enable receive unit.
*
**********************************************************************/
-#define MAX_INTS_PER_SEC 8000
-#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
-
static void
em_initialize_receive_unit(struct adapter *adapter)
{
@@ -4201,15 +4209,22 @@
* as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns)
*/
// E1000_WRITE_REG(hw, E1000_ITR, DEFAULT_ITR);
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_ITR,
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
/*
** When using MSIX interrupts we need to throttle
** using the EITR register (82574 only)
*/
if (hw->mac.type == e1000_82574)
- for (int i = 0; i < 4; i++)
- E1000_WRITE_REG(hw, E1000_EITR_82574(i),
- DEFAULT_ITR);
+ for (int i = 0; i < 4; i++) {
+ if (adapter->max_interrupt_rate > 0) {
+ E1000_WRITE_REG(&adapter->hw, E1000_EITR_82574(i),
+ 1000000000/256/adapter->max_interrupt_rate);
+ }
+ }
/* Disable accelerated ackknowledge */
if (adapter->hw.mac.type == e1000_82574)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment