rt-fixes (0) experimental :: add stp_rwlock_t which can be raw_spinlock on RT
There is no raw_rwlock_t type on most kernels, so use a regular spinlock instead.
(Using rwlock_t in the wrong context can prevent probes from locking data entirely,
and causes kernel freeze in the conversions_profile.stp stress test.)
changes made throughout translator and runtime
- add stp_rwlock_t either rwlock_t or raw_spinlock_t
- ensure DEFINE_RWLOCK -> DEFINE_STP_RWLOCK
- ensure {read,write}_{,un,try}lock -> stp_{read,write}_{,un,try}lock
diff --git a/runtime/linux/probe_lock.h b/runtime/linux/probe_lock.h
index 847f0d4..de53e65 100644
--- a/runtime/linux/probe_lock.h
+++ b/runtime/linux/probe_lock.h
@@ -22,7 +22,7 @@
atomic_t *skipped;
atomic_t *contention;
#endif
- rwlock_t *lock;
+ stp_rwlock_t *lock;
unsigned write_p;
};
@@ -34,9 +34,9 @@
if (num_locks == 0) return; /* defeat a gcc9 warning */
for (i = num_locks; i-- > 0;) {
if (locks[i].write_p)
- write_unlock(locks[i].lock);
+ stp_write_unlock(locks[i].lock);
else
- read_unlock(locks[i].lock);
+ stp_read_unlock(locks[i].lock);
}
}
@@ -47,7 +47,7 @@
unsigned i, retries = 0;
for (i = 0; i < num_locks; ++i) {
if (locks[i].write_p)
- while (!write_trylock(locks[i].lock)) {
+ while (!stp_write_trylock(locks[i].lock)) {
#if !defined(STAP_SUPPRESS_TIME_LIMITS_ENABLE)
if (++retries > MAXTRYLOCK)
goto skip;
@@ -58,7 +58,7 @@
udelay (TRYLOCKDELAY);
}
else
- while (!read_trylock(locks[i].lock)) {
+ while (!stp_read_trylock(locks[i].lock)) {
#if !defined(STAP_SUPPRESS_TIME_LIMITS_ENABLE)
if (++retries > MAXTRYLOCK)
goto skip;
diff --git a/runtime/linux/uprobes-inode.c b/runtime/linux/uprobes-inode.c
index b9604e6..065e408 100644
--- a/runtime/linux/uprobes-inode.c
+++ b/runtime/linux/uprobes-inode.c
@@ -76,7 +76,7 @@
* This may not be system-wide, e.g. only the -c process.
* We use task_finder to manage this list. */
struct list_head processes; /* stapiu_process */
- rwlock_t process_lock;
+ stp_rwlock_t process_lock;
struct stap_task_finder_target finder;
diff --git a/runtime/stp_helper_lock.h b/runtime/stp_helper_lock.h
index 7fe79f7..debdd1a 100644
--- a/runtime/stp_helper_lock.h
+++ b/runtime/stp_helper_lock.h
@@ -4,7 +4,7 @@
*
* Author: Santosh Shukla <sshukla@mvista.com>
*
- * Copyright (C) 2014 Red Hat Inc.
+ * Copyright (C) 2014-2019 Red Hat Inc.
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
@@ -20,6 +20,7 @@
#ifdef CONFIG_PREEMPT_RT_FULL
#define stp_spinlock_t raw_spinlock_t
+#define stp_rwlock_t raw_spinlock_t
#define STP_DEFINE_SPINLOCK(lock) DEFINE_RAW_SPINLOCK(lock)
@@ -39,6 +40,9 @@
static inline void stp_write_lock(raw_spinlock_t *lock) { raw_spin_lock(lock); }
static inline void stp_write_unlock(raw_spinlock_t *lock) { raw_spin_unlock(lock); }
+static inline void stp_read_trylock(rwlock_t *lock) { read_trylock(lock); }
+static inline void stp_write_trylock(rwlock_t *lock) { write_trylock(lock); }
+
#define stp_read_lock_irqsave(lock, flags) raw_spin_lock_irqsave(lock, flags)
#define stp_read_unlock_irqrestore(lock, flags) raw_spin_unlock_irqrestore(lock, flags)
#define stp_write_lock_irqsave(lock, flags) raw_spin_lock_irqsave(lock, flags)
@@ -47,6 +51,7 @@
#else
#define stp_spinlock_t spinlock_t
+#define stp_rwlock_t rwlock_t
#define STP_DEFINE_SPINLOCK(lock) DEFINE_SPINLOCK(lock)
@@ -65,6 +70,9 @@
static inline void stp_write_lock(rwlock_t *lock) { write_lock(lock); }
static inline void stp_write_unlock(rwlock_t *lock) { write_unlock(lock); }
+static inline void stp_read_trylock(rwlock_t *lock) { read_trylock(lock); }
+static inline void stp_write_trylock(rwlock_t *lock) { write_trylock(lock); }
+
#define stp_read_lock_irqsave(lock, flags) read_lock_irqsave(lock, flags)
#define stp_read_unlock_irqrestore(lock, flags) read_unlock_irqrestore(lock, flags)
#define stp_write_lock_irqsave(lock, flags) write_lock_irqsave(lock, flags)
diff --git a/translate.cxx b/translate.cxx
index f5a73ec..992b020 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -1660,7 +1660,7 @@
else
o->newline() << type << " " << vn << ";";
- o->newline() << "rwlock_t " << vn << "_lock;";
+ o->newline() << "stp_rwlock_t " << vn << "_lock;";
o->newline() << "#ifdef STP_TIMING";
o->newline() << "atomic_t " << vn << "_lock_skip_count;";
o->newline() << "atomic_t " << vn << "_lock_contention_count;";