Skip to contentSkip to conversation

lockmeter port for ppc64

PATCH tdgarcia 1 participant 1 message Nov 1, 2005

lore
Share & tools
lore

tdgarcia

author
#0 lore raw

My team and I adapted your lockmeter code to the ppc64 architecture. I am attaching the ppc64 specific code to this email. This code should patch cleanly to the 2.6.13 kernel.

arch/ppc64/Kconfig.debug 2005-10-11 07:40:28.000000000 -0700 renamed from arch/ppc64/Kconfig.debug 2005-08-28 16:41:01.000000000 -0700 +7 -0
diff -Narup linux-2.6.13/arch/ppc64/Kconfig.debug linux-2.6.13-lockmeter/arch/ppc64/Kconfig.debug
@@ -19,6 +19,13 @@ config KPROBES
      for kernel debugging, non-intrusive instrumentation and testing.
      If in doubt, say "N".
 
+config LOCKMETER
+ bool "Kernel lock metering"
+ depends on SMP && !PREEMPT
+ help
+   Say Y to enable kernel lock metering, which adds overhead to SMP locks,
+   but allows you to see various statistics using the lockstat command.
+

config DEBUG_STACK_USAGE
bool "Stack utilization instrumentation"
depends on DEBUG_KERNEL

arch/ppc64/lib/dec_and_lock.c 2005-10-10 13:02:47.000000000 -0700 renamed from arch/ppc64/lib/dec_and_lock.c 2005-08-28 16:41:01.000000000 -0700 +0 -0
diff -Narup linux-2.6.13/arch/ppc64/lib/dec_and_lock.c linux-2.6.13-lockmeter/arch/ppc64/lib/dec_and_lock.c
@@ -28,7 +28,13 @@
 */
 

#ifndef ATOMIC_DEC_AND_LOCK
+
+#ifndef CONFIG_LOCKMETER
+int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) +#else
int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) +#endif /* CONFIG_LOCKMETER */
+

{
    int counter;
    int newcount;
@@ -51,5 +57,10 @@ int _atomic_dec_and_lock(atomic_t *atomi
    return 0;
}

+#ifndef CONFIG_LOCKMETER
+EXPORT_SYMBOL(atomic_dec_and_lock);
+#else
EXPORT_SYMBOL(_atomic_dec_and_lock);
+#endif /* CONFIG_LOCKMETER */
+
#endif /* ATOMIC_DEC_AND_LOCK */

include/asm-ppc64/lockmeter.h 2005-10-11 08:48:48.000000000 -0700 renamed from include/asm-ppc64/lockmeter.h 1969-12-31 16:00:00.000000000 -0800 +108 -0

108 lines not on this page · raw message

include/asm-ppc64/spinlock.h 2005-10-10 14:04:25.000000000 -0700 renamed from include/asm-ppc64/spinlock.h 2005-08-28 16:41:01.000000000 -0700 +0 -0
diff -Narup linux-2.6.13/include/asm-ppc64/spinlock.h linux-2.6.13-lockmeter/include/asm-ppc64/spinlock.h
@@ -23,6 +23,9 @@
 
typedef struct {
    volatile unsigned int lock;
+#ifdef CONFIG_LOCKMETER
+  unsigned int lockmeter_magic;
+#endif /* CONFIG_LOCKMETER */
#ifdef CONFIG_PREEMPT
    unsigned int break_lock;

#endif
@@ -30,13 +33,20 @@ typedef struct {

typedef struct {
    volatile signed int lock;

+#ifdef CONFIG_LOCKMETER
+ unsigned int index;
+ unsigned int cpu;
+#endif /* CONFIG_LOCKMETER */

#ifdef CONFIG_PREEMPT
    unsigned int break_lock;

#endif
} rwlock_t;

-#ifdef __KERNEL__
-#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
+#ifdef CONFIG_LOCKMETER
+ #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } +#else
+ #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 , 0} +#endif /* CONFIG_LOCKMETER */

#define spin_is_locked(x) ((x)->lock != 0)
#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
@@ -144,7 +154,7 @@ static void __inline__ _raw_spin_lock_fl
* irq-safe write-lock, but readers can get non-irqsafe
* read-locks.
*/
-#define RW_LOCK_UNLOCKED (rwlock_t) { 0 } +#define RW_LOCK_UNLOCKED (rwlock_t) { 0 , 0 , 0 }

#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)

@@ -157,6 +167,44 @@ static __inline__ void _raw_write_unlock

    rw->lock = 0;
}

+#if defined(CONFIG_LOCKMETER) && defined(CONFIG_HAVE_DEC_LOCK) +extern void _metered_spin_lock (spinlock_t *lock, void *caller_pc); +extern void _metered_spin_unlock(spinlock_t *lock);
+
+/*

+ *  Matches what is in arch/ppc64/lib/dec_and_lock.c, except this one is
+ *  "static inline" so that the spin_lock(), if actually invoked, is charged
+ *  against the real caller, not against the catch-all atomic_dec_and_lock

+ */
+static inline int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) +{
+ int counter;
+ int newcount;
+
+ for (;;) {

+                counter = atomic_read(atomic);
+                newcount = counter - 1;
+                if (!newcount)

+ break; /* do it the slow way */
+
+ newcount = cmpxchg(&atomic->counter, counter, newcount);
+ if (newcount == counter)
+ return 0;
+ }
+

+        preempt_disable();
+        _metered_spin_lock(lock, __builtin_return_address(0));
+        if (atomic_dec_and_test(atomic))

+ return 1;
+ _metered_spin_unlock(lock);
+ preempt_enable();
+
+ return 0;
+}
+
+#define ATOMIC_DEC_AND_LOCK
+#endif /* CONFIG_LOCKMETER and CONFIG_HAVE_DEC_LOCK */ +
/*
* This returns the old value in the lock + 1,
* so we got a read lock if the return value is > 0.
@@ -256,5 +304,4 @@ static void __inline__ _raw_write_lock(r

    }
}

-#endif /* __KERNEL__ */
#endif /* __ASM_SPINLOCK_H */