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

* Re: What is MMU_TRACE for?
  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
  2 siblings, 0 replies; 4+ messages in thread
From: David Mosberger @ 2004-08-18  8:13 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Wed, 18 Aug 2004 14:25:58 +1000, Ian Wienand <ianw@gelato.unsw.edu.au> said:

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

It's just left-over debugging code.  We should remove it.  What I used
to do is store the traces in kernel-memory and then I'd use Ski to
look at the traces.

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

Looks like a fine patch.  Such debug code is normally maintained as
separate patches, though, and not part of the main-line source tree.

	--david

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

* Re: What is MMU_TRACE for?
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Wienand @ 2004-08-19  4:55 UTC (permalink / raw)
  To: linux-ia64


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

On Wed, Aug 18, 2004 at 01:13:32AM -0700, David Mosberger wrote:
> It's just left-over debugging code.  We should remove it. 

Here is a little patch to do that

-i

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

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/08/19 14:25:49+10:00 ianw@baci.gelato 
#   Remove extraneous MMU_TRACE debugging macros
# 
# include/asm-ia64/tlbflush.h
#   2004/08/19 14:24:42+10:00 ianw@baci.gelato +2 -5
#   Remove extraneous debugging macros
# 
# include/asm-ia64/mmu_context.h
#   2004/08/19 14:24:41+10:00 ianw@baci.gelato +1 -38
#   Remove extraneous debugging macros
# 
diff -Nru a/include/asm-ia64/mmu_context.h b/include/asm-ia64/mmu_context.h
--- a/include/asm-ia64/mmu_context.h	2004-08-19 14:27:07 +10:00
+++ b/include/asm-ia64/mmu_context.h	2004-08-19 14:27:07 +10:00
@@ -28,36 +28,6 @@
 
 #include <asm/processor.h>
 
-#define MMU_CONTEXT_DEBUG	0
-
-#if MMU_CONTEXT_DEBUG
-
-#include <ia64intrin.h>
-
-extern struct mmu_trace_entry {
-	char op;
-	u8 cpu;
-	u32 context;
-	void *mm;
-} mmu_tbuf[1024];
-
-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);	\
-	struct mmu_trace_entry e;							\
-	e.op = (_op);									\
-	e.cpu = (_cpu);									\
-	e.mm = (_mm);									\
-	e.context = (_ctx);								\
-	mmu_tbuf[i] = e;								\
-} while (0)
-
-#else
-# define MMU_TRACE(op,cpu,mm,ctx)	do { ; } while (0)
-#endif
-
 struct ia64_ctx {
 	spinlock_t lock;
 	unsigned int next;	/* next context number to use */
@@ -123,7 +93,6 @@
 static inline int
 init_new_context (struct task_struct *p, struct mm_struct *mm)
 {
-	MMU_TRACE('N', smp_processor_id(), mm, 0);
 	mm->context = 0;
 	return 0;
 }
@@ -132,7 +101,6 @@
 destroy_context (struct mm_struct *mm)
 {
 	/* Nothing to do.  */
-	MMU_TRACE('D', smp_processor_id(), mm, mm->context);
 }
 
 static inline void
@@ -171,19 +139,14 @@
 
 	do {
 		context = get_mmu_context(mm);
-		MMU_TRACE('A', smp_processor_id(), mm, context);
 		if (!cpu_isset(smp_processor_id(), mm->cpu_vm_mask))
 			cpu_set(smp_processor_id(), mm->cpu_vm_mask);
 		reload_context(context);
-		MMU_TRACE('a', smp_processor_id(), mm, context);
 		/* in the unlikely event of a TLB-flush by another thread, redo the load: */
 	} while (unlikely(context != mm->context));
 }
 
-#define deactivate_mm(tsk,mm)					\
-do {								\
-	MMU_TRACE('d', smp_processor_id(), mm, mm->context);	\
-} while (0)
+#define deactivate_mm(tsk,mm)	do { } while (0)
 
 /*
  * Switch from address space PREV to address space NEXT.
diff -Nru a/include/asm-ia64/tlbflush.h b/include/asm-ia64/tlbflush.h
--- a/include/asm-ia64/tlbflush.h	2004-08-19 14:27:07 +10:00
+++ b/include/asm-ia64/tlbflush.h	2004-08-19 14:27:07 +10:00
@@ -48,22 +48,19 @@
 static inline void
 flush_tlb_mm (struct mm_struct *mm)
 {
-	MMU_TRACE('F', smp_processor_id(), mm, mm->context);
 	if (!mm)
-		goto out;
+		return;
 
 	mm->context = 0;
 
 	if (atomic_read(&mm->mm_users) == 0)
-		goto out;		/* happens as a result of exit_mmap() */
+		return;		/* happens as a result of exit_mmap() */
 
 #ifdef CONFIG_SMP
 	smp_flush_tlb_mm(mm);
 #else
 	local_finish_flush_tlb_mm(mm);
 #endif
-  out:
-	MMU_TRACE('f', smp_processor_id(), mm, mm->context);
 }
 
 extern void flush_tlb_range (struct vm_area_struct *vma, unsigned long start, unsigned long end);

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

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

* Re: What is MMU_TRACE for?
  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
  2 siblings, 0 replies; 4+ messages in thread
From: David Mosberger @ 2004-08-19  7:41 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Thu, 19 Aug 2004 14:55:34 +1000, Ian Wienand <ianw@gelato.unsw.edu.au> said:

  Ian> On Wed, Aug 18, 2004 at 01:13:32AM -0700, David Mosberger
  Ian> wrote:
  >> It's just left-over debugging code.  We should remove it.

  Ian> Here is a little patch to do that

Looks good to me.

Thanks,

	--david

^ 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