linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Korty <joe.korty@ccur.com>
To: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>
Subject: [PATCH] Display active jiffie timers in /proc/timer_list
Date: Tue, 25 Nov 2008 13:57:40 -0500	[thread overview]
Message-ID: <20081125185740.GA21806@tsunami.ccur.com> (raw)
In-Reply-To: <517f3f820811250806n33850ea8ua8e203347c0f7ba6@mail.gmail.com>

Add to /proc/timer_list a display of the active jiffie timers.

Tested on i386 and x86_64, with 'less /proc/timer_list' and
through SysRq-Q.

Signed-off-by: Joe Korty <joe.korty@ccur.com>

Index: 2.6.28-rc6/kernel/timer.c
===================================================================
--- 2.6.28-rc6.orig/kernel/timer.c	2008-11-25 11:59:07.000000000 -0500
+++ 2.6.28-rc6/kernel/timer.c	2008-11-25 13:49:05.000000000 -0500
@@ -36,6 +36,8 @@
 #include <linux/syscalls.h>
 #include <linux/delay.h>
 #include <linux/tick.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/kallsyms.h>
 
 #include <asm/uaccess.h>
@@ -1568,6 +1570,87 @@
 	open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
 }
 
+#if defined(CONFIG_PROC_FS) || defined(CONFIG_MAGIC_SYSRQ)
+
+/*
+ * This allows printing both to /proc/timer_list and
+ * to the console (on SysRq-Q):
+ */
+#define SEQ_printf(m, x...)			\
+ do {						\
+	if (m)					\
+		seq_printf(m, x);		\
+	else					\
+		printk(x);			\
+ } while (0)
+
+static void print_nearest_symbol(struct seq_file *m, void *symaddr)
+{
+	char symname[KSYM_NAME_LEN];
+
+	if (lookup_symbol_name((unsigned long)symaddr, symname) < 0)
+		SEQ_printf(m, "<%p>", symaddr);
+	else
+		SEQ_printf(m, "%s", symname);
+}
+
+static void print_single_jtimer(struct seq_file *m, struct timer_list *timer)
+{
+	unsigned long base_jiffies = tbase_get_base(timer->base)->timer_jiffies;
+#ifdef CONFIG_TIMER_STATS
+	char tmp[TASK_COMM_LEN + 1];
+#endif
+
+	SEQ_printf(m, " %p: ", (void *)(timer->expires - base_jiffies));
+	print_nearest_symbol(m, timer->function);
+	SEQ_printf(m, " (");
+	print_nearest_symbol(m, (void *)(timer->data));
+	SEQ_printf(m, ")");
+#ifdef CONFIG_TIMER_STATS
+	SEQ_printf(m, " from ");
+	print_nearest_symbol(m, timer->start_site);
+	memcpy(tmp, timer->start_comm, TASK_COMM_LEN);
+	tmp[TASK_COMM_LEN] = 0;
+	SEQ_printf(m, ", %s/%d", tmp, timer->start_pid);
+#endif
+	SEQ_printf(m, "\n");
+}
+
+static void print_list_jtimers(struct seq_file *m, struct list_head *head)
+{
+	struct timer_list *timer;
+	struct list_head *item;
+
+	for (item = head->next; item != head; item = item->next) {
+		timer = list_entry(item, struct timer_list, entry);
+		print_single_jtimer(m, timer);
+	}
+}
+
+void print_cpu_jtimers(struct seq_file *m, int cpu)
+{
+	int i;
+	struct tvec_base *base = per_cpu(tvec_bases, cpu);
+
+	SEQ_printf(m, "active jiffie timers:\n");
+	spin_lock_irq(&base->lock);
+	SEQ_printf(m, " base: %p\n", base);
+	SEQ_printf(m, " timer_jiffies: %p\n", (void *)(base->timer_jiffies));
+	SEQ_printf(m, " running_timer: %p\n", base->running_timer);
+
+	for (i = 0; i < TVR_SIZE; i++)
+		print_list_jtimers(m, base->tv1.vec + i);
+	for (i = 0; i < TVN_SIZE; i++) {
+		print_list_jtimers(m, base->tv2.vec + i);
+		print_list_jtimers(m, base->tv3.vec + i);
+		print_list_jtimers(m, base->tv4.vec + i);
+		print_list_jtimers(m, base->tv5.vec + i);
+	}
+	spin_unlock_irq(&base->lock);
+}
+
+#endif /* CONFIG_PROC_FS || CONFIG_MAGIC_SYSRQ */
+
 /**
  * msleep - sleep safely even with waitqueue interruptions
  * @msecs: Time in milliseconds to sleep for
Index: 2.6.28-rc6/include/linux/jiffies.h
===================================================================
--- 2.6.28-rc6.orig/include/linux/jiffies.h	2008-11-25 11:59:07.000000000 -0500
+++ 2.6.28-rc6/include/linux/jiffies.h	2008-11-25 13:22:41.000000000 -0500
@@ -298,6 +298,13 @@
 extern u64 jiffies_64_to_clock_t(u64 x);
 extern u64 nsec_to_clock_t(u64 x);
 
+struct seq_file;
+#if defined(CONFIG_PROC_FS) || defined(CONFIG_MAGIC_SYSRQ)
+extern void print_cpu_jtimers(struct seq_file *, int);
+#else
+static inline void print_cpu_jtimers(struct seq_file *, int) {}
+#endif
+
 #define TIMESTAMP_SIZE	30
 
 #endif
Index: 2.6.28-rc6/kernel/time/timer_list.c
===================================================================
--- 2.6.28-rc6.orig/kernel/time/timer_list.c	2008-11-25 11:59:07.000000000 -0500
+++ 2.6.28-rc6/kernel/time/timer_list.c	2008-11-25 13:47:30.000000000 -0500
@@ -17,6 +17,7 @@
 #include <linux/seq_file.h>
 #include <linux/kallsyms.h>
 #include <linux/tick.h>
+#include <linux/jiffies.h>
 
 #include <asm/uaccess.h>
 
@@ -139,6 +140,7 @@
 		SEQ_printf(m, " clock %d:\n", i);
 		print_base(m, cpu_base->clock_base + i, now);
 	}
+
 #define P(x) \
 	SEQ_printf(m, "  .%-15s: %Lu\n", #x, \
 		   (unsigned long long)(cpu_base->x))
@@ -176,9 +178,11 @@
 		P(last_jiffies);
 		P(next_jiffies);
 		P_ns(idle_expires);
-		SEQ_printf(m, "jiffies: %Lu\n",
+		SEQ_printf(m, "jiffies: %llu (0x%llx)\n",
+			   (unsigned long long)jiffies,
 			   (unsigned long long)jiffies);
 	}
+	print_cpu_jtimers(m, cpu);
 #endif
 
 #undef P
@@ -252,7 +256,7 @@
 	u64 now = ktime_to_ns(ktime_get());
 	int cpu;
 
-	SEQ_printf(m, "Timer List Version: v0.4\n");
+	SEQ_printf(m, "Timer List Version: v0.5\n");
 	SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
 	SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
 
@@ -286,7 +290,7 @@
 {
 	struct proc_dir_entry *pe;
 
-	pe = proc_create("timer_list", 0644, NULL, &timer_list_fops);
+	pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
 	if (!pe)
 		return -ENOMEM;
 	return 0;

  reply	other threads:[~2008-11-25 18:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081121221113.GA13566@tsunami.ccur.com>
     [not found] ` <20081121221113.GA13566-jPwT5PJblzyhckIl5yWhCw@public.gmane.org>
2008-11-25 16:06   ` [PATCH] create /proc/timer-wheel-list Michael Kerrisk
2008-11-25 18:57     ` Joe Korty [this message]
     [not found]       ` <20081125185740.GA21806-jPwT5PJblzyhckIl5yWhCw@public.gmane.org>
2008-11-25 21:36         ` [PATCH] Display active jiffie timers in /proc/timer_list Thomas Gleixner
     [not found]           ` <alpine.LFD.2.00.0811252224430.3235-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-11-25 22:23             ` Joe Korty
2008-11-25 22:53               ` Thomas Gleixner
2008-11-26 16:48       ` [PATCH] Display active jiffie timers in /proc/timer_list, v2 Joe Korty
     [not found]         ` <20081126164845.GA17394-jPwT5PJblzyhckIl5yWhCw@public.gmane.org>
2008-11-26 17:07           ` Greg KH
     [not found]             ` <20081126170715.GA28422-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2008-11-26 17:34               ` Joe Korty
     [not found]                 ` <20081126173410.GA17879-jPwT5PJblzyhckIl5yWhCw@public.gmane.org>
2008-11-26 17:39                   ` Greg KH
     [not found]                     ` <20081126173931.GA1636-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2008-11-26 21:06                       ` [PATCH] ABI Documentation for /proc/timer_list Joe Korty
     [not found]                         ` <20081126210613.GA20529-jPwT5PJblzyhckIl5yWhCw@public.gmane.org>
2008-11-28 21:37                           ` Michael Kerrisk
     [not found]                             ` <cfd18e0f0811281337j57166b4cv54e05296a779252e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-12-01 18:11                               ` [PATCH] ABI Documentation for /proc/timer_list, v2 Joe Korty
2008-12-05 17:12                                 ` Randy Dunlap
     [not found]                                   ` <493960F2.6070102-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-12-05 19:01                                     ` Joe Korty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081125185740.GA21806@tsunami.ccur.com \
    --to=joe.korty@ccur.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mtk.manpages@gmail.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).