All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ratelimit: add initialization macro
@ 2014-08-20 12:54 Dmitry Monakhov
  2014-08-20 12:54 ` [PATCH 2/2] fault-inject: add ratelimit option Dmitry Monakhov
  2014-10-19  9:06 ` [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Monakhov @ 2014-08-20 12:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: akinobu.mita, Dmitry Monakhov


Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 include/linux/ratelimit.h |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
index 0a260d8..1810252 100644
--- a/include/linux/ratelimit.h
+++ b/include/linux/ratelimit.h
@@ -17,14 +17,20 @@ struct ratelimit_state {
 	unsigned long	begin;
 };
 
-#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
-									\
-	struct ratelimit_state name = {					\
+#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) {		\
 		.lock		= __RAW_SPIN_LOCK_UNLOCKED(name.lock),	\
 		.interval	= interval_init,			\
 		.burst		= burst_init,				\
 	}
 
+#define RATELIMIT_STATE_INIT_DISABLED					\
+	RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
+
+#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
+									\
+	struct ratelimit_state name =					\
+		RATELIMIT_STATE_INIT(name, interval_init, burst_init)	\
+
 static inline void ratelimit_state_init(struct ratelimit_state *rs,
 					int interval, int burst)
 {
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] fault-inject: add ratelimit option
  2014-08-20 12:54 [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
@ 2014-08-20 12:54 ` Dmitry Monakhov
  2014-08-20 14:20   ` Akinobu Mita
  2014-10-19  9:06 ` [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry Monakhov @ 2014-08-20 12:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: akinobu.mita, Dmitry Monakhov

Current debug levels are not optimal. Especially if one want to
provoke big numbers of faults(broken device simulator) then any verbose
level will produce giant numbers of identical logging messages.
Let's add ratelimit parameter for that purpose.

Change-log:
- Dump fault_attr configuration on minimal verbose level.
- Add name to fault_attr
- Add ratelimit parameter


Example:
  # Limit verbosity to one at 5 seconds
  echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
  echo 5000 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms

  # dump only once in a day
  echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
  echo $((24 * 60 * 60* 1000)) > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 include/linux/fault-inject.h |   17 +++++++++++------
 lib/fault-inject.c           |   30 ++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
index c6f996f..798fad9 100644
--- a/include/linux/fault-inject.h
+++ b/include/linux/fault-inject.h
@@ -5,6 +5,7 @@
 
 #include <linux/types.h>
 #include <linux/debugfs.h>
+#include <linux/ratelimit.h>
 #include <linux/atomic.h>
 
 /*
@@ -25,14 +26,18 @@ struct fault_attr {
 	unsigned long reject_end;
 
 	unsigned long count;
+	struct ratelimit_state ratelimit_state;
+	struct dentry *dname;
 };
 
-#define FAULT_ATTR_INITIALIZER {				\
-		.interval = 1,					\
-		.times = ATOMIC_INIT(1),			\
-		.require_end = ULONG_MAX,			\
-		.stacktrace_depth = 32,				\
-		.verbose = 2,					\
+#define FAULT_ATTR_INITIALIZER {					\
+		.interval = 1,						\
+		.times = ATOMIC_INIT(1),				\
+		.require_end = ULONG_MAX,				\
+		.stacktrace_depth = 32,					\
+		.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,	\
+		.verbose = 2,						\
+		.dname = NULL,						\
 	}
 
 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index d7d501e..ebb3485 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -40,10 +40,25 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
 
 static void fail_dump(struct fault_attr *attr)
 {
-	if (attr->verbose > 0)
-		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
-	if (attr->verbose > 1)
-		dump_stack();
+	if (attr->verbose > 0 &&
+	    ___ratelimit(&attr->ratelimit_state, __func__)) {
+		if (attr->dname)
+			printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure."
+			       "name %pd, interval %lu, probability %lu, "
+			       "space %d, times %d\n", attr->dname,
+			       attr->probability, attr->interval,
+			       atomic_read(&attr->space),
+			       atomic_read(&attr->times));
+		else
+			printk(KERN_NOTICE "FAULT_INJECTION: forcing a "
+			       "failure, interval %lu, probability %lu, "
+			       "space %d, times %d\n", attr->probability,
+			       attr->interval, atomic_read(&attr->space),
+			       atomic_read(&attr->times));
+
+		if (attr->verbose > 1)
+			dump_stack();
+	}
 }
 
 #define atomic_dec_not_zero(v)		atomic_add_unless((v), -1, 0)
@@ -202,6 +217,12 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 		goto fail;
 	if (!debugfs_create_ul("verbose", mode, dir, &attr->verbose))
 		goto fail;
+	if (!debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
+				&attr->ratelimit_state.interval))
+		goto fail;
+	if (!debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
+				&attr->ratelimit_state.burst))
+		goto fail;
 	if (!debugfs_create_bool("task-filter", mode, dir, &attr->task_filter))
 		goto fail;
 
@@ -222,6 +243,7 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
+	attr->dname = dget(dir);
 	return dir;
 fail:
 	debugfs_remove_recursive(dir);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] fault-inject: add ratelimit option
  2014-08-20 12:54 ` [PATCH 2/2] fault-inject: add ratelimit option Dmitry Monakhov
@ 2014-08-20 14:20   ` Akinobu Mita
  2014-08-20 14:36     ` Dmitry Monakhov
  0 siblings, 1 reply; 8+ messages in thread
From: Akinobu Mita @ 2014-08-20 14:20 UTC (permalink / raw)
  To: Dmitry Monakhov; +Cc: LKML

2014-08-20 21:54 GMT+09:00 Dmitry Monakhov <dmonakhov@openvz.org>:
> @@ -40,10 +40,25 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
>
>  static void fail_dump(struct fault_attr *attr)
>  {
> -       if (attr->verbose > 0)
> -               printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
> -       if (attr->verbose > 1)
> -               dump_stack();
> +       if (attr->verbose > 0 &&
> +           ___ratelimit(&attr->ratelimit_state, __func__)) {

You can use __ratelimit(state) instead of ___ratelimit(state, __func__).

> +               if (attr->dname)
> +                       printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure."
> +                              "name %pd, interval %lu, probability %lu, "
> +                              "space %d, times %d\n", attr->dname,
> +                              attr->probability, attr->interval,
> +                              atomic_read(&attr->space),
> +                              atomic_read(&attr->times));
> +               else
> +                       printk(KERN_NOTICE "FAULT_INJECTION: forcing a "
> +                              "failure, interval %lu, probability %lu, "
> +                              "space %d, times %d\n", attr->probability,
> +                              attr->interval, atomic_read(&attr->space),
> +                              atomic_read(&attr->times));

This looks a bit redundant.  NULL pointer to "%pd" format produces
"(null)" string, so this printk and if-else can be removed.

Also, this message line is a bit longer than usual kernel message.
Should we put '\n' after "forcing a failure."?

This patch looks good to me.  Please feel free to add my ACK.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] fault-inject: add ratelimit option
  2014-08-20 14:20   ` Akinobu Mita
@ 2014-08-20 14:36     ` Dmitry Monakhov
  2014-10-19  9:07       ` Dmitry Monakhov
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Monakhov @ 2014-08-20 14:36 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: LKML

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Wed, 20 Aug 2014 23:20:18 +0900, Akinobu Mita <akinobu.mita@gmail.com> wrote:
> This looks a bit redundant.  NULL pointer to "%pd" format produces
> "(null)" string, so this printk and if-else can be removed.
> 
> Also, this message line is a bit longer than usual kernel message.
> Should we put '\n' after "forcing a failure."?
> 
> This patch looks good to me.  Please feel free to add my ACK.
Ok. Here is updated version.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fault-inject-add-ratelimit-option-v2.patch --]
[-- Type: text/x-patch, Size: 3836 bytes --]

>From d06acefdd4da0d590e6dc0b1351e7adefad98fc7 Mon Sep 17 00:00:00 2001
From: Dmitry Monakhov <dmonakhov@openvz.org>
Date: Wed, 20 Aug 2014 18:31:06 +0400
Subject: [PATCH] fault-inject: add ratelimit option  v2

Current debug levels are not optimal. Especially if one want to
provoke big numbers of faults(broken device simulator) then any verbose
level will produce giant numbers of identical logging messages.
Let's add ratelimit parameter for that purpose.

Change-log:
- Dump fault_attr configuration on minimal verbose level.
- Add name to fault_attr
- Add ratelimit parameter

Example:
  # Limit verbosity to one at 5 seconds
  echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
  echo 5000 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms

  # dump only once in a day
  echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
  echo $((24 * 60 * 60* 1000)) > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms

Acked-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 include/linux/fault-inject.h |   17 +++++++++++------
 lib/fault-inject.c           |   21 +++++++++++++++++----
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
index c6f996f..798fad9 100644
--- a/include/linux/fault-inject.h
+++ b/include/linux/fault-inject.h
@@ -5,6 +5,7 @@
 
 #include <linux/types.h>
 #include <linux/debugfs.h>
+#include <linux/ratelimit.h>
 #include <linux/atomic.h>
 
 /*
@@ -25,14 +26,18 @@ struct fault_attr {
 	unsigned long reject_end;
 
 	unsigned long count;
+	struct ratelimit_state ratelimit_state;
+	struct dentry *dname;
 };
 
-#define FAULT_ATTR_INITIALIZER {				\
-		.interval = 1,					\
-		.times = ATOMIC_INIT(1),			\
-		.require_end = ULONG_MAX,			\
-		.stacktrace_depth = 32,				\
-		.verbose = 2,					\
+#define FAULT_ATTR_INITIALIZER {					\
+		.interval = 1,						\
+		.times = ATOMIC_INIT(1),				\
+		.require_end = ULONG_MAX,				\
+		.stacktrace_depth = 32,					\
+		.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,	\
+		.verbose = 2,						\
+		.dname = NULL,						\
 	}
 
 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index d7d501e..f1cdeb0 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -40,10 +40,16 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
 
 static void fail_dump(struct fault_attr *attr)
 {
-	if (attr->verbose > 0)
-		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
-	if (attr->verbose > 1)
-		dump_stack();
+	if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
+		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
+		       "name %pd, interval %lu, probability %lu, "
+		       "space %d, times %d\n", attr->dname,
+		       attr->probability, attr->interval,
+		       atomic_read(&attr->space),
+		       atomic_read(&attr->times));
+		if (attr->verbose > 1)
+			dump_stack();
+	}
 }
 
 #define atomic_dec_not_zero(v)		atomic_add_unless((v), -1, 0)
@@ -202,6 +208,12 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 		goto fail;
 	if (!debugfs_create_ul("verbose", mode, dir, &attr->verbose))
 		goto fail;
+	if (!debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
+				&attr->ratelimit_state.interval))
+		goto fail;
+	if (!debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
+				&attr->ratelimit_state.burst))
+		goto fail;
 	if (!debugfs_create_bool("task-filter", mode, dir, &attr->task_filter))
 		goto fail;
 
@@ -222,6 +234,7 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
+	attr->dname = dget(dir);
 	return dir;
 fail:
 	debugfs_remove_recursive(dir);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] ratelimit: add initialization macro
  2014-08-20 12:54 [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
  2014-08-20 12:54 ` [PATCH 2/2] fault-inject: add ratelimit option Dmitry Monakhov
@ 2014-10-19  9:06 ` Dmitry Monakhov
  1 sibling, 0 replies; 8+ messages in thread
From: Dmitry Monakhov @ 2014-10-19  9:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: akinobu.mita

[-- Attachment #1: Type: text/plain, Size: 1268 bytes --]

Dmitry Monakhov <dmonakhov@openvz.org> writes:

Ping.
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> ---
>  include/linux/ratelimit.h |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
> index 0a260d8..1810252 100644
> --- a/include/linux/ratelimit.h
> +++ b/include/linux/ratelimit.h
> @@ -17,14 +17,20 @@ struct ratelimit_state {
>  	unsigned long	begin;
>  };
>  
> -#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
> -									\
> -	struct ratelimit_state name = {					\
> +#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) {		\
>  		.lock		= __RAW_SPIN_LOCK_UNLOCKED(name.lock),	\
>  		.interval	= interval_init,			\
>  		.burst		= burst_init,				\
>  	}
>  
> +#define RATELIMIT_STATE_INIT_DISABLED					\
> +	RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
> +
> +#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
> +									\
> +	struct ratelimit_state name =					\
> +		RATELIMIT_STATE_INIT(name, interval_init, burst_init)	\
> +
>  static inline void ratelimit_state_init(struct ratelimit_state *rs,
>  					int interval, int burst)
>  {
> -- 
> 1.7.1

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] fault-inject: add ratelimit option
  2014-08-20 14:36     ` Dmitry Monakhov
@ 2014-10-19  9:07       ` Dmitry Monakhov
  2014-10-19 12:17         ` Akinobu Mita
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Monakhov @ 2014-10-19  9:07 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: LKML

[-- Attachment #1: Type: text/plain, Size: 4680 bytes --]

Dmitry Monakhov <dmonakhov@openvz.org> writes:
Ping.
> On Wed, 20 Aug 2014 23:20:18 +0900, Akinobu Mita <akinobu.mita@gmail.com> wrote:
>> This looks a bit redundant.  NULL pointer to "%pd" format produces
>> "(null)" string, so this printk and if-else can be removed.
>> 
>> Also, this message line is a bit longer than usual kernel message.
>> Should we put '\n' after "forcing a failure."?
>> 
>> This patch looks good to me.  Please feel free to add my ACK.
> Ok. Here is updated version.
> From d06acefdd4da0d590e6dc0b1351e7adefad98fc7 Mon Sep 17 00:00:00 2001
> From: Dmitry Monakhov <dmonakhov@openvz.org>
> Date: Wed, 20 Aug 2014 18:31:06 +0400
> Subject: [PATCH] fault-inject: add ratelimit option  v2
>
> Current debug levels are not optimal. Especially if one want to
> provoke big numbers of faults(broken device simulator) then any verbose
> level will produce giant numbers of identical logging messages.
> Let's add ratelimit parameter for that purpose.
>
> Change-log:
> - Dump fault_attr configuration on minimal verbose level.
> - Add name to fault_attr
> - Add ratelimit parameter
>
> Example:
>   # Limit verbosity to one at 5 seconds
>   echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
>   echo 5000 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms
>
>   # dump only once in a day
>   echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
>   echo $((24 * 60 * 60* 1000)) > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms
>
> Acked-by: Akinobu Mita <akinobu.mita@gmail.com>
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> ---
>  include/linux/fault-inject.h |   17 +++++++++++------
>  lib/fault-inject.c           |   21 +++++++++++++++++----
>  2 files changed, 28 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
> index c6f996f..798fad9 100644
> --- a/include/linux/fault-inject.h
> +++ b/include/linux/fault-inject.h
> @@ -5,6 +5,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/debugfs.h>
> +#include <linux/ratelimit.h>
>  #include <linux/atomic.h>
>  
>  /*
> @@ -25,14 +26,18 @@ struct fault_attr {
>  	unsigned long reject_end;
>  
>  	unsigned long count;
> +	struct ratelimit_state ratelimit_state;
> +	struct dentry *dname;
>  };
>  
> -#define FAULT_ATTR_INITIALIZER {				\
> -		.interval = 1,					\
> -		.times = ATOMIC_INIT(1),			\
> -		.require_end = ULONG_MAX,			\
> -		.stacktrace_depth = 32,				\
> -		.verbose = 2,					\
> +#define FAULT_ATTR_INITIALIZER {					\
> +		.interval = 1,						\
> +		.times = ATOMIC_INIT(1),				\
> +		.require_end = ULONG_MAX,				\
> +		.stacktrace_depth = 32,					\
> +		.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,	\
> +		.verbose = 2,						\
> +		.dname = NULL,						\
>  	}
>  
>  #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
> diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> index d7d501e..f1cdeb0 100644
> --- a/lib/fault-inject.c
> +++ b/lib/fault-inject.c
> @@ -40,10 +40,16 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
>  
>  static void fail_dump(struct fault_attr *attr)
>  {
> -	if (attr->verbose > 0)
> -		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
> -	if (attr->verbose > 1)
> -		dump_stack();
> +	if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
> +		printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
> +		       "name %pd, interval %lu, probability %lu, "
> +		       "space %d, times %d\n", attr->dname,
> +		       attr->probability, attr->interval,
> +		       atomic_read(&attr->space),
> +		       atomic_read(&attr->times));
> +		if (attr->verbose > 1)
> +			dump_stack();
> +	}
>  }
>  
>  #define atomic_dec_not_zero(v)		atomic_add_unless((v), -1, 0)
> @@ -202,6 +208,12 @@ struct dentry *fault_create_debugfs_attr(const char *name,
>  		goto fail;
>  	if (!debugfs_create_ul("verbose", mode, dir, &attr->verbose))
>  		goto fail;
> +	if (!debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
> +				&attr->ratelimit_state.interval))
> +		goto fail;
> +	if (!debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
> +				&attr->ratelimit_state.burst))
> +		goto fail;
>  	if (!debugfs_create_bool("task-filter", mode, dir, &attr->task_filter))
>  		goto fail;
>  
> @@ -222,6 +234,7 @@ struct dentry *fault_create_debugfs_attr(const char *name,
>  
>  #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
>  
> +	attr->dname = dget(dir);
>  	return dir;
>  fail:
>  	debugfs_remove_recursive(dir);
> -- 
> 1.7.1

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] fault-inject: add ratelimit option
  2014-10-19  9:07       ` Dmitry Monakhov
@ 2014-10-19 12:17         ` Akinobu Mita
  0 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2014-10-19 12:17 UTC (permalink / raw)
  To: Dmitry Monakhov; +Cc: LKML, Andrew Morton

Hi Dmitry,

2014-10-19 18:07 GMT+09:00 Dmitry Monakhov <dmonakhov@openvz.org>:
> Dmitry Monakhov <dmonakhov@openvz.org> writes:
> Ping.

Could you resend this series with CCing Andrew for asking -mm tree
inclusion?

>> On Wed, 20 Aug 2014 23:20:18 +0900, Akinobu Mita <akinobu.mita@gmail.com> wrote:
>>> This looks a bit redundant.  NULL pointer to "%pd" format produces
>>> "(null)" string, so this printk and if-else can be removed.
>>>
>>> Also, this message line is a bit longer than usual kernel message.
>>> Should we put '\n' after "forcing a failure."?
>>>
>>> This patch looks good to me.  Please feel free to add my ACK.
>> Ok. Here is updated version.
>> From d06acefdd4da0d590e6dc0b1351e7adefad98fc7 Mon Sep 17 00:00:00 2001
>> From: Dmitry Monakhov <dmonakhov@openvz.org>
>> Date: Wed, 20 Aug 2014 18:31:06 +0400
>> Subject: [PATCH] fault-inject: add ratelimit option  v2
>>
>> Current debug levels are not optimal. Especially if one want to
>> provoke big numbers of faults(broken device simulator) then any verbose
>> level will produce giant numbers of identical logging messages.
>> Let's add ratelimit parameter for that purpose.
>>
>> Change-log:
>> - Dump fault_attr configuration on minimal verbose level.
>> - Add name to fault_attr
>> - Add ratelimit parameter
>>
>> Example:
>>   # Limit verbosity to one at 5 seconds
>>   echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
>>   echo 5000 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms
>>
>>   # dump only once in a day
>>   echo 1 > /sys/kernel/debug/fail_make_request/verbose_ratelimit_burst
>>   echo $((24 * 60 * 60* 1000)) > /sys/kernel/debug/fail_make_request/verbose_ratelimit_interval_ms
>>
>> Acked-by: Akinobu Mita <akinobu.mita@gmail.com>
>> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
>> ---
>>  include/linux/fault-inject.h |   17 +++++++++++------
>>  lib/fault-inject.c           |   21 +++++++++++++++++----
>>  2 files changed, 28 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
>> index c6f996f..798fad9 100644
>> --- a/include/linux/fault-inject.h
>> +++ b/include/linux/fault-inject.h
>> @@ -5,6 +5,7 @@
>>
>>  #include <linux/types.h>
>>  #include <linux/debugfs.h>
>> +#include <linux/ratelimit.h>
>>  #include <linux/atomic.h>
>>
>>  /*
>> @@ -25,14 +26,18 @@ struct fault_attr {
>>       unsigned long reject_end;
>>
>>       unsigned long count;
>> +     struct ratelimit_state ratelimit_state;
>> +     struct dentry *dname;
>>  };
>>
>> -#define FAULT_ATTR_INITIALIZER {                             \
>> -             .interval = 1,                                  \
>> -             .times = ATOMIC_INIT(1),                        \
>> -             .require_end = ULONG_MAX,                       \
>> -             .stacktrace_depth = 32,                         \
>> -             .verbose = 2,                                   \
>> +#define FAULT_ATTR_INITIALIZER {                                     \
>> +             .interval = 1,                                          \
>> +             .times = ATOMIC_INIT(1),                                \
>> +             .require_end = ULONG_MAX,                               \
>> +             .stacktrace_depth = 32,                                 \
>> +             .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,       \
>> +             .verbose = 2,                                           \
>> +             .dname = NULL,                                          \
>>       }
>>
>>  #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
>> diff --git a/lib/fault-inject.c b/lib/fault-inject.c
>> index d7d501e..f1cdeb0 100644
>> --- a/lib/fault-inject.c
>> +++ b/lib/fault-inject.c
>> @@ -40,10 +40,16 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
>>
>>  static void fail_dump(struct fault_attr *attr)
>>  {
>> -     if (attr->verbose > 0)
>> -             printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
>> -     if (attr->verbose > 1)
>> -             dump_stack();
>> +     if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
>> +             printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
>> +                    "name %pd, interval %lu, probability %lu, "
>> +                    "space %d, times %d\n", attr->dname,
>> +                    attr->probability, attr->interval,
>> +                    atomic_read(&attr->space),
>> +                    atomic_read(&attr->times));
>> +             if (attr->verbose > 1)
>> +                     dump_stack();
>> +     }
>>  }
>>
>>  #define atomic_dec_not_zero(v)               atomic_add_unless((v), -1, 0)
>> @@ -202,6 +208,12 @@ struct dentry *fault_create_debugfs_attr(const char *name,
>>               goto fail;
>>       if (!debugfs_create_ul("verbose", mode, dir, &attr->verbose))
>>               goto fail;
>> +     if (!debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
>> +                             &attr->ratelimit_state.interval))
>> +             goto fail;
>> +     if (!debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
>> +                             &attr->ratelimit_state.burst))
>> +             goto fail;
>>       if (!debugfs_create_bool("task-filter", mode, dir, &attr->task_filter))
>>               goto fail;
>>
>> @@ -222,6 +234,7 @@ struct dentry *fault_create_debugfs_attr(const char *name,
>>
>>  #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
>>
>> +     attr->dname = dget(dir);
>>       return dir;
>>  fail:
>>       debugfs_remove_recursive(dir);
>> --
>> 1.7.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] ratelimit: add initialization macro
@ 2014-10-19 12:50 Dmitry Monakhov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Monakhov @ 2014-10-19 12:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, Dmitry Monakhov

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 include/linux/ratelimit.h |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
index 0a260d8..1810252 100644
--- a/include/linux/ratelimit.h
+++ b/include/linux/ratelimit.h
@@ -17,14 +17,20 @@ struct ratelimit_state {
 	unsigned long	begin;
 };
 
-#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
-									\
-	struct ratelimit_state name = {					\
+#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) {		\
 		.lock		= __RAW_SPIN_LOCK_UNLOCKED(name.lock),	\
 		.interval	= interval_init,			\
 		.burst		= burst_init,				\
 	}
 
+#define RATELIMIT_STATE_INIT_DISABLED					\
+	RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
+
+#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)		\
+									\
+	struct ratelimit_state name =					\
+		RATELIMIT_STATE_INIT(name, interval_init, burst_init)	\
+
 static inline void ratelimit_state_init(struct ratelimit_state *rs,
 					int interval, int burst)
 {
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-10-19 12:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 12:54 [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
2014-08-20 12:54 ` [PATCH 2/2] fault-inject: add ratelimit option Dmitry Monakhov
2014-08-20 14:20   ` Akinobu Mita
2014-08-20 14:36     ` Dmitry Monakhov
2014-10-19  9:07       ` Dmitry Monakhov
2014-10-19 12:17         ` Akinobu Mita
2014-10-19  9:06 ` [PATCH 1/2] ratelimit: add initialization macro Dmitry Monakhov
2014-10-19 12:50 Dmitry Monakhov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.