summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2023-03-06 07:05:19 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-03-07 01:08:19 +0100
commitf34f362ad7e01a769e154cc4053b6c9b9f07998f (patch)
tree29532c1f49cdea7016f3041aa1d66a38bf2d8e7d
parent2b4486d281efc9ee70c3e23a416b6ca5c43ba6ca (diff)
kern: Fix MACH_LOCK_MON lock monitoring debug
TESTED: - by setting MACH_LOCK_MON to 1 in configfrag.ac and running "show all slocks" in kdb - does not break default configured kernel Message-Id: <20230306070512.292715-1-damien@zamaudio.com>
-rw-r--r--ddb/db_sym.h8
-rw-r--r--i386/i386/lock.h6
-rw-r--r--kern/lock.c4
-rw-r--r--kern/lock.h5
-rw-r--r--kern/lock_mon.c8
-rw-r--r--kern/thread.h4
6 files changed, 24 insertions, 11 deletions
diff --git a/ddb/db_sym.h b/ddb/db_sym.h
index 20450f64..f4fb5284 100644
--- a/ddb/db_sym.h
+++ b/ddb/db_sym.h
@@ -116,6 +116,10 @@ extern void db_symbol_values( db_symtab_t *stab,
char** namep,
db_expr_t* valuep);
+/* find symbol in current task */
+#define db_search_symbol(val,strgy,offp) \
+ db_search_task_symbol(val,strgy,offp,0)
+
/* find name&value given approx val */
#define db_find_sym_and_offset(val,namep,offp) \
@@ -157,10 +161,6 @@ extern void db_symbol_values( db_symtab_t *stab,
db_free_symbol(s); \
} while(0);
-/* find symbol in current task */
-#define db_search_symbol(val,strgy,offp) \
- db_search_task_symbol(val,strgy,offp,0)
-
/* strcmp, modulo leading char */
extern boolean_t db_eqname( const char* src, const char* dst, char c );
diff --git a/i386/i386/lock.h b/i386/i386/lock.h
index b189a559..56370440 100644
--- a/i386/i386/lock.h
+++ b/i386/i386/lock.h
@@ -59,7 +59,7 @@
#define SIMPLE_LOCK_INITIALIZER(l) \
{.lock_data = 0}
-#define simple_lock(l) \
+#define _simple_lock(l) \
({ \
while(_simple_lock_xchg_(l, 1)) \
while (*(volatile int *)&(l)->lock_data) \
@@ -67,10 +67,10 @@
0; \
})
-#define simple_unlock(l) \
+#define _simple_unlock(l) \
(_simple_lock_xchg_(l, 0))
-#define simple_lock_try(l) \
+#define _simple_lock_try(l) \
(!_simple_lock_xchg_(l, 1))
/*
diff --git a/kern/lock.c b/kern/lock.c
index 81c6a129..f076c328 100644
--- a/kern/lock.c
+++ b/kern/lock.c
@@ -673,7 +673,11 @@ void db_show_all_slocks(void)
#else /* MACH_SLOCKS && NCPUS == 1 */
void db_show_all_slocks(void)
{
+#if MACH_LOCK_MON
+ lip();
+#else
db_printf("simple lock info not available\n");
+#endif
}
#endif /* MACH_SLOCKS && NCPUS == 1 */
#endif /* MACH_KDB */
diff --git a/kern/lock.h b/kern/lock.h
index 4fcbe8ab..48976196 100644
--- a/kern/lock.h
+++ b/kern/lock.h
@@ -39,6 +39,11 @@
#if NCPUS > 1
#include <machine/lock.h>/*XXX*/
+#if MACH_LOCK_MON == 0
+#define simple_lock _simple_lock
+#define simple_lock_try _simple_lock_try
+#define simple_unlock _simple_unlock
+#endif
#endif
#define MACH_SLOCKS ((NCPUS > 1) || MACH_LDEBUG)
diff --git a/kern/lock_mon.c b/kern/lock_mon.c
index a963ec05..bb446b7a 100644
--- a/kern/lock_mon.c
+++ b/kern/lock_mon.c
@@ -45,7 +45,8 @@
#include <mach/boolean.h>
#include <kern/thread.h>
#include <kern/lock.h>
-
+#include <machine/ipl.h>
+#include <ddb/db_sym.h>
def_simple_lock_data(extern , kdb_lock)
def_simple_lock_data(extern , printf_lock)
@@ -93,7 +94,6 @@ decl_simple_lock_data(, **lock)
{
struct lock_info *li = &(lock_info[HASH_LOCK(*lock)].info[0]);
int i;
- my_cpu = cpu_number();
for (i=0; i < LOCK_INFO_PER_BUCKET; i++, li++)
if (li->lock) {
@@ -114,7 +114,7 @@ void simple_lock(lock)
decl_simple_lock_data(, *lock)
{
struct lock_info *li = locate_lock_info(&lock);
- my_cpu = cpu_number();
+ int my_cpu = cpu_number();
if (current_thread())
li->stack = current_thread()->lock_stack++;
@@ -133,7 +133,7 @@ int simple_lock_try(lock)
decl_simple_lock_data(, *lock)
{
struct lock_info *li = locate_lock_info(&lock);
- my_cpu = cpu_number();
+ int my_cpu = cpu_number();
if (curr_ipl[my_cpu])
li->masked++;
diff --git a/kern/thread.h b/kern/thread.h
index a5abefcc..f8232d1a 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -229,6 +229,10 @@ struct thread {
#if NCPUS > 1
processor_t last_processor; /* processor this last ran on */
#endif /* NCPUS > 1 */
+
+#if MACH_LOCK_MON
+ int lock_stack;
+#endif
};
/* typedef of thread_t is in kern/kern_types.h */