Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1573331
| From | Waiman Long <longman@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH-tip v5 21/21] futex: Dump internal futex state via debugfs |
| Date | 2017-02-03 19:10 +0100 |
| Message-ID | <t6Qt4-57B-33@gated-at.bofh.it> (permalink) |
| References | <t6Qt3-57B-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
For debugging purpose, it is sometimes useful to dump the internal
states in the futex hash bucket table. This patch adds a file
"futex_hash_table" in debugfs root filesystem to dump the internal
futex states.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/futex.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/kernel/futex.c b/kernel/futex.c
index 6bf5304..8b7a591 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -4428,3 +4428,85 @@ static int __init futex_init(void)
return 0;
}
__initcall(futex_init);
+
+#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_SMP)
+/*
+ * Debug code to dump selected content of in-kernel futex hash bucket table.
+ */
+#include <linux/debugfs.h>
+
+static int futex_dump_show(struct seq_file *m, void *arg)
+{
+ struct futex_hash_bucket *hb = arg;
+ struct futex_state *state;
+ int i;
+
+ if (list_empty(&hb->fs_head))
+ return 0;
+
+ seq_printf(m, "\nHash bucket %d:\n", (int)(hb - futex_queues));
+ spin_lock(&hb->fs_lock);
+ i = 0;
+ list_for_each_entry(state, &hb->fs_head, fs_list) {
+ seq_printf(m, " Futex state %d\n", i++);
+ if (state->owner)
+ seq_printf(m, " owner PID = %d\n",
+ task_pid_vnr(state->owner));
+ if (state->mutex_owner)
+ seq_printf(m, " mutex owner PID = %d\n",
+ task_pid_vnr(state->mutex_owner));
+ seq_printf(m, " reference count = %d\n",
+ atomic_read(&state->refcount));
+ seq_printf(m, " handoff PID = %d\n", state->handoff_pid);
+ }
+ spin_unlock(&hb->fs_lock);
+ return 0;
+}
+
+static void *futex_dump_start(struct seq_file *m, loff_t *pos)
+{
+ return (*pos < futex_hashsize) ? &futex_queues[*pos] : NULL;
+}
+
+static void *futex_dump_next(struct seq_file *m, void *arg, loff_t *pos)
+{
+ (*pos)++;
+ return (*pos < futex_hashsize) ? &futex_queues[*pos] : NULL;
+}
+
+static void futex_dump_stop(struct seq_file *m, void *arg)
+{
+}
+
+static const struct seq_operations futex_dump_op = {
+ .start = futex_dump_start,
+ .next = futex_dump_next,
+ .stop = futex_dump_stop,
+ .show = futex_dump_show,
+};
+
+static int futex_dump_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &futex_dump_op);
+}
+
+static const struct file_operations fops_futex_dump = {
+ .open = futex_dump_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
+/*
+ * Initialize debugfs for the futex hash bucket table dump.
+ */
+static int __init init_futex_dump(void)
+{
+ if (!debugfs_create_file("futex_hash_table", 0400, NULL, NULL,
+ &fops_futex_dump))
+ return -ENOMEM;
+ return 0;
+}
+fs_initcall(init_futex_dump);
+
+#endif /* CONFIG_DEBUG_FS && CONFIG_SMP */
--
1.8.3.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH-tip v5 00/21] futex: Introducing throughput-optimized (TP) futexes Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 20/21] sched, TP-futex: Make wake_up_q() return wakeup count Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 21/21] futex: Dump internal futex state via debugfs Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 17/21] TP-futex: Group readers together in wait queue Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
Re: [PATCH-tip v5 17/21] TP-futex: Group readers together in wait queue valdis.kletnieks@vt.edu - 2017-02-03 19:30 +0100
Re: [PATCH-tip v5 17/21] TP-futex: Group readers together in wait queue Waiman Long <longman@redhat.com> - 2017-02-03 19:50 +0100
Re: [PATCH-tip v5 17/21] TP-futex: Group readers together in wait queue valdis.kletnieks@vt.edu - 2017-02-03 20:30 +0100
[PATCH-tip v5 05/21] futex: Add helpers to get & cmpxchg futex value without lock Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 04/21] futex: Rename futex_pi_state to futex_state Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 10/21] TP-futex: Enable robust handling Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 08/21] futex: Allow direct attachment of futex_state objects to hash bucket Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 03/21] futex: Consolidate duplicated timer setup code Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 19/21] perf bench: Extend mutex/rwlock futex suite to test TP futexes Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
[PATCH-tip v5 11/21] TP-futex: Implement lock handoff to prevent lock starvation Waiman Long <longman@redhat.com> - 2017-02-03 19:10 +0100
csiph-web