linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] lkdtm: use atomic_t to replace count_lock
@ 2012-02-01  6:58 Cong Wang
  2012-02-01  6:58 ` [PATCH 2/2] lkdtm: avoid calling sleeping functions in interrupt context Cong Wang
  2012-02-01 15:27 ` [PATCH 1/2] lkdtm: use atomic_t to replace count_lock Arnd Bergmann
  0 siblings, 2 replies; 7+ messages in thread
From: Cong Wang @ 2012-02-01  6:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Cong Wang, Prarit Bhargava, Arnd Bergmann,
	Greg Kroah-Hartman, Dave Young

Andrew, this patch replaces
lkdtm-avoid-calling-lkdtm_do_action-with-spin-lock-held.patch
in your tree.

---------->

The spin lock count_lock only protects count, it can be removed by
using atomic_t. Suggested by Arnd.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <greg@kroah.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

---
 drivers/misc/lkdtm.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 150cd70..afdef2e 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -119,8 +119,7 @@ static int recur_count = REC_NUM_DEFAULT;
 
 static enum cname cpoint = CN_INVALID;
 static enum ctype cptype = CT_NONE;
-static int count = DEFAULT_COUNT;
-static DEFINE_SPINLOCK(count_lock);
+static atomic_t count = ATOMIC_INIT(DEFAULT_COUNT);
 
 module_param(recur_count, int, 0644);
 MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
@@ -231,14 +230,11 @@ static const char *cp_name_to_str(enum cname name)
 static int lkdtm_parse_commandline(void)
 {
 	int i;
-	unsigned long flags;
 
 	if (cpoint_count < 1 || recur_count < 1)
 		return -EINVAL;
 
-	spin_lock_irqsave(&count_lock, flags);
-	count = cpoint_count;
-	spin_unlock_irqrestore(&count_lock, flags);
+	atomic_set(&count, cpoint_count);
 
 	/* No special parameters */
 	if (!cpoint_type && !cpoint_name)
@@ -353,18 +349,11 @@ static void lkdtm_do_action(enum ctype which)
 
 static void lkdtm_handler(void)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&count_lock, flags);
-	count--;
 	printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n",
-			cp_name_to_str(cpoint), cp_type_to_str(cptype), count);
+			cp_name_to_str(cpoint), cp_type_to_str(cptype), atomic_dec_return(&count));
 
-	if (count == 0) {
+	if (!atomic_cmpxchg(&count, 0, cpoint_count))
 		lkdtm_do_action(cptype);
-		count = cpoint_count;
-	}
-	spin_unlock_irqrestore(&count_lock, flags);
 }
 
 static int lkdtm_register_cpoint(enum cname which)
-- 
1.7.7.6


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

end of thread, other threads:[~2012-02-02 14:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-01  6:58 [PATCH 1/2] lkdtm: use atomic_t to replace count_lock Cong Wang
2012-02-01  6:58 ` [PATCH 2/2] lkdtm: avoid calling sleeping functions in interrupt context Cong Wang
2012-02-01 15:27 ` [PATCH 1/2] lkdtm: use atomic_t to replace count_lock Arnd Bergmann
2012-02-02 13:33   ` Cong Wang
2012-02-02 13:44     ` Arnd Bergmann
2012-02-02 14:27       ` Cong Wang
2012-02-02 14:55         ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).