public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* What is MMU_TRACE for?
@ 2004-08-18  4:25 Ian Wienand
  2004-08-18  8:13 ` David Mosberger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ian Wienand @ 2004-08-18  4:25 UTC (permalink / raw)
  To: linux-ia64


[-- Attachment #1.1: Type: text/plain, Size: 404 bytes --]

Hi,

The change @ http://tinyurl.com/4g5dz introduced MMU_TRACE, but left
the structure to keep the traces in as extern with no corresponding
definition.  Is maybe some of the patch missing?  What was its
original intention?

I actaully wanted to use something like this, so just exported it out
to a proc entry (attached just for the archives).

-i
ianw@gelato.unsw.edu.au
http://www.gelato.unsw.edu.au

[-- Attachment #1.2: mmu_debug.patch --]
[-- Type: text/plain, Size: 5307 bytes --]

Index: linux-dev-tree/include/asm-ia64/mmu_context.h
===================================================================
--- linux-dev-tree.orig/include/asm-ia64/mmu_context.h	2004-08-17 16:31:48.000000000 +1000
+++ linux-dev-tree/include/asm-ia64/mmu_context.h	2004-08-18 13:56:16.340327806 +1000
@@ -28,24 +28,25 @@
 
 #include <asm/processor.h>
 
-#define MMU_CONTEXT_DEBUG	0
-
-#if MMU_CONTEXT_DEBUG
+#ifdef CONFIG_IA64_DEBUG_MMU_CONTEXT
 
 #include <ia64intrin.h>
 
-extern struct mmu_trace_entry {
+#define MMU_DEBUG_CONTEXT_ENTRIES 512
+
+struct mmu_trace_entry {
 	char op;
 	u8 cpu;
 	u32 context;
 	void *mm;
-} mmu_tbuf[1024];
+};
 
+extern struct mmu_trace_entry mmu_tbuf[MMU_DEBUG_CONTEXT_ENTRIES];
 extern volatile int mmu_tbuf_index;
 
 # define MMU_TRACE(_op,_cpu,_mm,_ctx)							\
 do {											\
-	int i = __sync_fetch_and_add(&mmu_tbuf_index, 1) % ARRAY_SIZE(mmu_tbuf);	\
+	int i = __sync_fetch_and_add(&mmu_tbuf_index, 1) % MMU_DEBUG_CONTEXT_ENTRIES;	\
 	struct mmu_trace_entry e;							\
 	e.op = (_op);									\
 	e.cpu = (_cpu);									\
@@ -180,10 +181,16 @@
 	} while (unlikely(context != mm->context));
 }
 
-#define deactivate_mm(tsk,mm)					\
-do {								\
-	MMU_TRACE('d', smp_processor_id(), mm, mm->context);	\
+#ifdef CONFIG_IA64_DEBUG_MMU_CONTEXT
+#define deactivate_mm(tsk,mm)							\
+do {										\
+	/* Kernel threads may not have an mm */					\
+	if (mm)									\
+		MMU_TRACE('d', smp_processor_id(), mm, mm->context);		\
 } while (0)
+#else
+#define deactivate_mm(tsk,mm) do {} while (0)
+#endif
 
 /*
  * Switch from address space PREV to address space NEXT.
Index: linux-dev-tree/arch/ia64/mm/debug_mmu_context.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-dev-tree/arch/ia64/mm/debug_mmu_context.c	2004-08-18 14:12:40.398909502 +1000
@@ -0,0 +1,75 @@
+/*
+ * MMU context switching debugging 
+ *
+ * Copyright (C) 2004 Gelato@UNSW
+ *	Ian Wienand <ianw@gelato.unsw.edu.au>
+ */
+ 
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/types.h>
+#include <linux/module.h>
+ 
+#include <asm/mmu_context.h>
+
+#ifdef CONFIG_IA64_DEBUG_MMU_CONTEXT
+
+MODULE_AUTHOR("Ian Wienand <ianw@gelato.unsw.edu.au>");
+MODULE_DESCRIPTION("/proc interface to MMU context switch debugging");
+MODULE_LICENSE("GPL");
+
+/* The main structure holding all the trace entries */
+struct mmu_trace_entry mmu_tbuf[MMU_DEBUG_CONTEXT_ENTRIES];
+volatile int mmu_tbuf_index;
+
+static struct proc_dir_entry *mmu_context_debug_file;
+
+static int proc_read_mmu_context_debug(char *buf, char **start,
+                             off_t fpos, int length,
+                             int *eof, void *data)
+{
+	int i = 0;
+	int len = 0, printed = 0;
+
+	while (i < MMU_DEBUG_CONTEXT_ENTRIES)
+	{
+		struct mmu_trace_entry *p = &mmu_tbuf[i];
+		if (p->op)
+			len += sprintf(buf+len, "%4d|%c|%2d|%5d%s", 
+				       i, p->op, p->cpu, 
+				       p->context, 
+				       (++printed % 5) ? " * ":"\n"); 
+		i++;
+	}
+	len += sprintf(buf+len, "\n");
+
+        if (fpos >=len){
+                *start = buf;
+                *eof = 1;
+                return 0;
+        }
+        *start = buf + fpos;
+        if ((len -= fpos) > length)
+                return length;
+        *eof = 1;
+        return len;
+}
+
+static int __init init_mmu_context_debug_init(void)
+{
+	int rv = 0;
+
+	mmu_context_debug_file = create_proc_read_entry("mmu_context_debug",
+                                              0444, &proc_root,
+                                              proc_read_mmu_context_debug,
+                                              NULL);
+        if(mmu_context_debug_file == NULL) {
+                rv  = -ENOMEM;
+        }
+
+	return rv;
+}
+
+module_init(init_mmu_context_debug_init);
+
+#endif /* CONFIG_IA64_DEBUG_MMU_CONTEXT */
Index: linux-dev-tree/arch/ia64/mm/Makefile
===================================================================
--- linux-dev-tree.orig/arch/ia64/mm/Makefile	2004-08-17 16:31:35.000000000 +1000
+++ linux-dev-tree/arch/ia64/mm/Makefile	2004-08-18 13:56:16.340327806 +1000
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 obj-$(CONFIG_NUMA)	   += numa.o
 obj-$(CONFIG_DISCONTIGMEM) += discontig.o
+obj-$(CONFIG_IA64_DEBUG_MMU_CONTEXT) += debug_mmu_context.o
 ifndef CONFIG_DISCONTIGMEM
 obj-y += contig.o
 endif
Index: linux-dev-tree/arch/ia64/Kconfig
===================================================================
--- linux-dev-tree.orig/arch/ia64/Kconfig	2004-08-16 15:00:10.000000000 +1000
+++ linux-dev-tree/arch/ia64/Kconfig	2004-08-18 13:56:16.341304369 +1000
@@ -471,6 +471,13 @@
 	  and restore instructions.  It's useful for tracking down spinlock
 	  problems, but slow!  If you're unsure, select N.
 
+config IA64_DEBUG_MMU_CONTEXT
+	bool "Trace MMU on context switches"
+	depends on DEBUG_KERNEL
+	help
+	  Selecting this option turns on /proc/debug_mmu where you can see what
+	  the kernel has been up to when it is doing context switches.
+	  
 config DEBUG_INFO
 	bool "Compile the kernel with debug info"
 	depends on DEBUG_KERNEL

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-19  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-18  4:25 What is MMU_TRACE for? Ian Wienand
2004-08-18  8:13 ` David Mosberger
2004-08-19  4:55 ` Ian Wienand
2004-08-19  7:41 ` David Mosberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox