[parisc-linux-cvs] Added kernel profiling

Paul Bame bame@fc.hp.com
Thu, 30 May 2002 10:19:33 -0600


Index: real2.S
===================================================================
RCS file: /var/cvs/linux/arch/parisc/kernel/real2.S,v
retrieving revision 1.5
diff -u -r1.5 real2.S
--- real2.S	2001/03/22 16:24:16	1.5
+++ real2.S	2002/05/30 16:10:50
@@ -275,3 +275,11 @@
 	nop
 
 #endif
+	.export pc_in_user_space
+	.text
+	/* Doesn't belong here but I couldn't find a nicer spot. */
+	/* Should never get called, only used by profile stuff in time.c */
+pc_in_user_space:
+	bv,n	0(%rp)
+	nop
+
Index: time.c
===================================================================
RCS file: /var/cvs/linux/arch/parisc/kernel/time.c,v
retrieving revision 1.22
diff -u -r1.22 time.c
--- time.c	2002/02/26 00:44:44	1.22
+++ time.c	2002/05/30 16:10:50
@@ -42,6 +42,26 @@
 extern void smp_do_timer(struct pt_regs *regs);
 #endif
 
+static inline void
+parisc_do_profile(unsigned long pc)
+{
+	extern char _stext;
+
+	if (!prof_buffer)
+		return;
+
+	pc -= (unsigned long) &_stext;
+	pc >>= prof_shift;
+	/*
+	 * Don't ignore out-of-bounds PC values silently,
+	 * put them into the last histogram slot, so if
+	 * present, they will show up as a sharp peak.
+	 */
+	if (pc > prof_len - 1)
+		pc = prof_len - 1;
+	atomic_inc((atomic_t *)&prof_buffer[pc]);
+}
+
 void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	long now = mfctl(16);
@@ -74,7 +94,14 @@
 		smp_do_timer(regs);
 #endif
 		if (cpu == 0) {
+			extern int pc_in_user_space;
 			write_lock(&xtime_lock);
+#ifndef CONFIG_SMP
+			if (!user_mode(regs))
+				parisc_do_profile(regs->iaoq[0]);
+			else
+				parisc_do_profile(&pc_in_user_space);
+#endif
 			do_timer(regs);
 			write_unlock(&xtime_lock);
 		}