Support for handling interrupt storm
Subsystems (2)
v2 cover Support for handling interrupt storm
This patcheset contain:
Patch #1 Add fields for interrupt storm handling Patch #2 Add support for handling interrupt storm
v0->v2
Comments pointed out by Ilpo:
- Renamed the macro MLXREG_HOTPLUG_WM_WINDOW to MLXREG_HOTPLUG_WM_WINDOW_MS to indicate milli seconds
- Removed the timestamp stored in wmark_high_ts and used jiffies directly
- Calculating the time window and storing it in the new variable wmark_window.
- Removed the variables wmark_low_ts and wmark_high_ts
- Used continue statement inside the time window check
Changes added by Ciju:
- Renamed variable wmark_low_cntr to wmark_cntr
- Fixed the time window to check for interrupt storm
Ciju Rajan K (2):
platform_data/mlxreg: Add fields for interrupt storm handling platform/mellanox: mlxreg-hotplug: Add support for handling interrupt
storm
drivers/platform/mellanox/mlxreg-hotplug.c | 32 ++++++++++++++++++++-- include/linux/platform_data/mlxreg.h | 6 ++++ 2 files changed, 36 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.2
PATCH v2 1/2 platform_data/mlxreg: Add fields for interrupt storm handling
Add fields for interrupt storm handling.
Extend structure mlxreg_core_data with the following fields:
'wmark_cntr' - interrupt storm counter.
'wmark_window' - time window to count interrupts to check for storm.
Extend structure mlxreg_core_item with the following field:
'storming_bits' - interrupt storming bits mask.
--- include/linux/platform_data/mlxreg.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/platform_data/mlxreg.h +6 -0
@@ -131,6 +131,8 @@ struct mlxreg_hotplug_device {* @regnum: number of registers occupied by multi-register attribute; * @slot: slot number, at which device is located; * @secured: if set indicates that entry access is secured; +* @wmark_cntr: interrupt storm counter; +* @wmark_window: time window to count interrupts to check for storm; */ struct mlxreg_core_data {char label[MLXREG_CORE_LABEL_MAX_SIZE ];
@@ -151,6 +153,8 @@ struct mlxreg_core_data {u8 regnum;u8 slot;u8 secured; +unsigned int wmark_cntr; +unsigned long wmark_window; };/**
@@ -167,6 +171,7 @@ struct mlxreg_core_data {* @ind: element's index inside the group; * @inversed: if 0: 0 for signal status is OK, if 1 - 1 is OK; * @health: true if device has health indication, false in other case; +* @storming_bits: interrupt storming bits mask; */ struct mlxreg_core_item {struct mlxreg_core_data *data;
@@ -180,6 +185,7 @@ struct mlxreg_core_item {u8 ind;u8 inversed;u8 health; +u32 storming_bits; };/**
Signature · 1 line
2.47.2
Ilpo Järvinen
maintainerRe: [PATCH platform-next v2 1/2] [PATCH platform-next 1/2] platform_data/mlxreg: Add fields for interrupt storm handling
Quoted 46 lines · Ciju Rajan K
Add fields for interrupt storm handling.
Extend structuremlxreg_core_datawith the following fields:
'wmark_cntr' - interrupt storm counter.
'wmark_window' - time window to count interrupts to check for storm.Extend structure
mlxreg_core_itemwith the following field:
'storming_bits' - interrupt storming bits mask.Reviewed-by Vadim Pasternak <[email protected]>Signed-off-by Ciju Rajan K <[email protected]>--- include/linux/platform_data/mlxreg.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/platform_data/mlxreg.h +5
-0@@ -131,6 +131,8 @@ struct mlxreg_hotplug_device {* @regnum: number of registers occupied by multi-register attribute; * @slot: slot number, at which device is located; * @secured: if set indicates that entry access is secured; +* @wmark_cntr: interrupt storm counter; +* @wmark_window: time window to count interrupts to check for storm; */ struct mlxreg_core_data {char label[MLXREG_CORE_LABEL_MAX_SIZE ];@@ -151,6 +153,8 @@ struct mlxreg_core_data {u8 regnum;u8 slot;u8 secured; +unsigned int wmark_cntr; +unsigned long wmark_window; };/** @@ -167,6 +171,7 @@ struct mlxreg_core_data {* @ind: element's index inside the group; * @inversed: if 0: 0 for signal status is OK, if 1 - 1 is OK; * @health: true if device has health indication, false in other case; +* @storming_bits: interrupt storming bits mask; */ struct mlxreg_core_item {struct mlxreg_core_data *data;
include/linux/platform_data/mlxreg.h struct mlxreg_core_item { · line 191
Quoted 7 lines
include/linux/platform_data/mlxreg.h +1
-0@@ -180,6 +185,7 @@ struct mlxreg_core_item {u8 ind;u8 inversed;u8 health; +u32 storming_bits; };/**
I don't know what's the benefit of having this as a separate patch, the fields are getting used in patch 2 so it would feel natural to introduce them there so the entire change would end up into the same commit.
Signature · 1 line
i.
RE: [PATCH platform-next v2 1/2] [PATCH platform-next 1/2] platform_data/mlxreg: Add fields for interrupt storm handling
Hi Ilpo,
Thanks for the review.
Quoted 9 lines
Quoted 9 lines
struct mlxreg_core_item { struct mlxreg_core_data *data;include/linux/platform_data/mlxreg.h +1
-0@@ -180,6 +185,7 @@ struct mlxreg_core_item {u8 ind;u8 inversed;u8 health; +u32 storming_bits; };
Quoted 6 lines
Review struct mlxreg_core_item { · line 191
Quoted 2 lines
(quoted diff) +0
-0/**I don't know what's the benefit of having this as a separate patch, the fields are getting used in patch 2 so it would feel natural to introduce them there so the entire change would end up into the same commit.
Combined into a single patch.
Thanks
Ciju
PATCH v2 2/2 platform/mellanox: mlxreg-hotplug: Add support for handling interrupt storm
In reply to Ciju Rajan KIn case of broken hardware, it is possible that broken device will flood interrupt handler with false events. For example, if fan or power supply has damaged presence pin, it will cause permanent generation of plugged in / plugged out events. As a result, interrupt handler will consume a lot of CPU resources and will keep raising "UDEV" events to the user space.
This patch provides a mechanism to detect device causing interrupt flooding and mask interrupt for this specific device, to isolate from interrupt handling flow. Use the following criteria: if the specific interrupt was generated 'N' times during 'T' seconds, such device is to be considered as broken and will be closed for getting interrupts. User will be notified through the log error and will be instructed to replace broken device.
--- drivers/platform/mellanox/mlxreg-hotplug.c | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/platform/mellanox/mlxreg-hotplug.c +30 -2
@@ -11,6 +11,7 @@#include <linux/hwmon-sysfs.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/jiffies.h> #include <linux/module.h> #include <linux/platform_data/mlxreg.h> #include <linux/platform_device.h>
@@ -30,6 +31,11 @@#define MLXREG_HOTPLUG_ATTRS_MAX 128#define MLXREG_HOTPLUG_NOT_ASSERT 3 +/* Interrupt storm definitions */ +#define MLXREG_HOTPLUG_WM_COUNTER 100 +/* Time window in milliseconds */ +#define MLXREG_HOTPLUG_WM_WINDOW_MS 3000 +/** * struct mlxreg_hotplug_priv_data - platform private data: * @irq: platform device interrupt number;
@@ -366,11 +372,33 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,for_each_set_bit (bit, &asserted,8 ) {int pos; +/* Skip already marked storming bit. */ +if (item->storming_bits &BIT (bit)) +continue ; + pos =mlxreg_hotplug_item_label_index_get (item->mask, bit);if (pos <0 ) goto out; data = item->data + pos; + +/* Interrupt storm handling logic. */ +if (data->wmark_cntr ==0 ) + data->wmark_window = jiffies + +msecs_to_jiffies (MLXREG_HOTPLUG_WM_WINDOW_MS ); + +if (data->wmark_cntr >=MLXREG_HOTPLUG_WM_COUNTER -1 ) { +if (time_after (data->wmark_window, jiffies)) { +dev_err (priv->dev, +"Storming bit %d (label: %s) - interrupt masked permanently. Replace broken HW." , + bit, data->label); +/* Mark bit as storming. */ + item->storming_bits |=BIT (bit); +continue ; + } + data->wmark_cntr =0 ; + } + data->wmark_cntr++;if (regval &BIT (bit)) {if (item->inversed)mlxreg_hotplug_device_destroy (priv, data, item->kind);
@@ -390,9 +418,9 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,if (ret) goto out; -/* Unmask event. */ +/* Unmask event, exclude storming bits. */ ret =regmap_write (priv->regmap, item->reg +MLXREG_HOTPLUG_MASK_OFF , - item->mask); + item->mask & ~item->storming_bits); out:if (ret)
Signature · 1 line
2.47.2
Ilpo Järvinen
maintainerRe: [PATCH platform-next v2 2/2] [PATCH platform-next 2/2] platform/mellanox: mlxreg-hotplug: Add support for handling interrupt storm
Quoted 53 lines · Ciju Rajan K
In case of broken hardware, it is possible that broken device will flood interrupt handler with false events. For example, if fan or power supply has damaged presence pin, it will cause permanent generation of plugged in / plugged out events. As a result, interrupt handler will consume a lot of CPU resources and will keep raising "UDEV" events to the user space.
This patch provides a mechanism to detect device causing interrupt flooding and mask interrupt for this specific device, to isolate from interrupt handling flow. Use the following criteria: if the specific interrupt was generated 'N' times during 'T' seconds, such device is to be considered as broken and will be closed for getting interrupts. User will be notified through the log error and will be instructed to replace broken device.
Reviewed-by Vadim Pasternak <[email protected]>Signed-off-by Ciju Rajan K <[email protected]>--- drivers/platform/mellanox/mlxreg-hotplug.c | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-hotplug.c +10
-0@@ -11,6 +11,7 @@#include <linux/hwmon-sysfs.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/jiffies.h> #include <linux/module.h> #include <linux/platform_data/mlxreg.h> #include <linux/platform_device.h> @@ -30,6 +31,11 @@#define MLXREG_HOTPLUG_ATTRS_MAX 128#define MLXREG_HOTPLUG_NOT_ASSERT 3 +/* Interrupt storm definitions */ +#define MLXREG_HOTPLUG_WM_COUNTER 100 +/* Time window in milliseconds */ +#define MLXREG_HOTPLUG_WM_WINDOW_MS 3000 +/** * struct mlxreg_hotplug_priv_data - platform private data: * @irq: platform device interrupt number; @@ -366,11 +372,33 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,for_each_set_bit (bit, &asserted,8 ) {int pos; +/* Skip already marked storming bit. */ +if (item->storming_bits &BIT (bit)) +continue ; +
drivers/platform/mellanox/mlxreg-hotplug.c mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv, · line 388
Quoted 10 lines
drivers/platform/mellanox/mlxreg-hotplug.c +5
-0pos =mlxreg_hotplug_item_label_index_get (item->mask, bit);if (pos <0 ) goto out; data = item->data + pos; + +/* Interrupt storm handling logic. */ +if (data->wmark_cntr ==0 ) + data->wmark_window = jiffies + +msecs_to_jiffies (MLXREG_HOTPLUG_WM_WINDOW_MS );
Please use braces for multi-line if blocks.
drivers/platform/mellanox/mlxreg-hotplug.c mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv, · line 401
Quoted 13 lines
drivers/platform/mellanox/mlxreg-hotplug.c +13
-0+ +if (data->wmark_cntr >=MLXREG_HOTPLUG_WM_COUNTER -1 ) { +if (time_after (data->wmark_window, jiffies)) { +dev_err (priv->dev, +"Storming bit %d (label: %s) - interrupt masked permanently. Replace broken HW." , + bit, data->label); +/* Mark bit as storming. */ + item->storming_bits |=BIT (bit); +continue ; + } + data->wmark_cntr =0 ; + } + data->wmark_cntr++;
I think this should be in else block to allow recalculation of the time window when the counter wraps.
Quoted 16 lines
drivers/platform/mellanox/mlxreg-hotplug.c +2
-2if (regval &BIT (bit)) {if (item->inversed)mlxreg_hotplug_device_destroy (priv, data, item->kind);@@ -390,9 +418,9 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,if (ret) goto out; -/* Unmask event. */ +/* Unmask event, exclude storming bits. */ ret =regmap_write (priv->regmap, item->reg +MLXREG_HOTPLUG_MASK_OFF , - item->mask); + item->mask & ~item->storming_bits); out:if (ret)
Signature · 1 line
i.
RE: [PATCH platform-next v2 2/2] [PATCH platform-next 2/2] platform/mellanox: mlxreg-hotplug: Add support for handling interrupt storm
Hi Ilpo,
Thanks for the review.
Quoted 8 lines
drivers/platform/mellanox/mlxreg-hotplug.c mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv, · line 389
Quoted 5 lines
drivers/platform/mellanox/mlxreg-hotplug.c +5
-0+ +/* Interrupt storm handling logic. */ +if (data->wmark_cntr ==0 ) + data->wmark_window = jiffies + +
msecs_to_jiffies(MLXREG_HOTPLUG_WM_WINDOW_MS);Please use braces for multi-line if blocks.
Done.
Quoted 15 lines
drivers/platform/mellanox/mlxreg-hotplug.c mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,
Quoted 5 lines
drivers/platform/mellanox/mlxreg-hotplug.c +5
-0+ +if (data->wmark_cntr >=MLXREG_HOTPLUG_WM_COUNTER -1 ) { +if (time_after (data->wmark_window, jiffies)) { + dev_err(priv->dev, + "Storming bit %d (label: %s) - interrupt maskedpermanently. Replace broken HW.",
drivers/platform/mellanox/mlxreg-hotplug.c mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv, · line 401
Quoted 8 lines
drivers/platform/mellanox/mlxreg-hotplug.c +8
-0+ bit, data->label); +/* Mark bit as storming. */ + item->storming_bits |=BIT (bit); +continue ; + } + data->wmark_cntr =0 ; + } + data->wmark_cntr++;
Quoted 2 lines
I think this should be in else block to allow recalculation of the time window when the counter wraps.
Good catch. Otherwise, time window will never get reset. Fixed in the next version (on the way).
Thanks
Ciju