[PATCH] CRIS update: profiler
authorMikael Starvik <mikael.starvik@axis.com>
Wed, 27 Jul 2005 18:44:40 +0000 (11:44 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 27 Jul 2005 23:26:00 +0000 (16:26 -0700)
System-level profiler.

Signed-off-by: Mikael Starvik <starvik@axis.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/cris/kernel/profile.c [new file with mode: 0644]
arch/cris/kernel/time.c
include/asm-cris/ptrace.h

diff --git a/arch/cris/kernel/profile.c b/arch/cris/kernel/profile.c
new file mode 100644 (file)
index 0000000..69c5218
--- /dev/null
@@ -0,0 +1,73 @@
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/types.h>
+#include <asm/ptrace.h>
+#include <asm/uaccess.h>
+
+#define SAMPLE_BUFFER_SIZE 8192
+
+static char* sample_buffer;
+static char* sample_buffer_pos;
+static int prof_running = 0;
+
+void
+cris_profile_sample(struct pt_regs* regs)
+{
+  if (!prof_running)
+    return;
+  if (user_mode(regs))
+    *(unsigned int*)sample_buffer_pos = current->pid;
+  else
+    *(unsigned int*)sample_buffer_pos = 0;
+  *(unsigned int*)(sample_buffer_pos + 4) = instruction_pointer(regs);
+  sample_buffer_pos += 8;
+  if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE)
+    sample_buffer_pos = sample_buffer;
+}
+
+static ssize_t
+read_cris_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+{
+  unsigned long p = *ppos;
+  if (p > SAMPLE_BUFFER_SIZE)
+    return 0;
+  if (p + count > SAMPLE_BUFFER_SIZE)
+    count = SAMPLE_BUFFER_SIZE - p;
+  if (copy_to_user(buf, sample_buffer + p,count))
+               return -EFAULT;
+  memset(sample_buffer + p, 0, count);
+  *ppos += count;
+  return count;
+}
+
+static ssize_t
+write_cris_profile(struct file *file, const char __user *buf,
+              size_t count, loff_t *ppos)
+{
+  sample_buffer_pos = sample_buffer;
+  memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE);
+}
+
+static struct file_operations cris_proc_profile_operations = {
+       .read           = read_cris_profile,
+       .write          = write_cris_profile,
+};
+
+static int
+__init init_cris_profile(void)
+{
+  struct proc_dir_entry *entry;
+  sample_buffer = (char*)kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
+  sample_buffer_pos = sample_buffer;
+  entry = create_proc_entry("system_profile", S_IWUSR | S_IRUGO, NULL);
+  if (entry) {
+    entry->proc_fops = &cris_proc_profile_operations;
+    entry->size = SAMPLE_BUFFER_SIZE;
+  }
+  prof_running = 1;
+  return 0;
+}
+
+__initcall(init_cris_profile);
index 6c28b0e7f7b4b43a88d27b9e38ec76b2786cff48..fa2d4323da2592deef3bd5652110d953e7696850 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: time.c,v 1.14 2004/06/01 05:38:11 starvik Exp $
+/* $Id: time.c,v 1.18 2005/03/04 08:16:17 starvik Exp $
  *
  *  linux/arch/cris/kernel/time.c
  *
@@ -30,6 +30,7 @@
 #include <linux/bcd.h>
 #include <linux/timex.h>
 #include <linux/init.h>
+#include <linux/profile.h>
 
 u64 jiffies_64 = INITIAL_JIFFIES;
 
@@ -214,6 +215,21 @@ update_xtime_from_cmos(void)
        }
 }
 
+extern void cris_profile_sample(struct pt_regs* regs);
+
+void
+cris_do_profile(struct pt_regs* regs)
+{
+
+#if CONFIG_SYSTEM_PROFILER
+        cris_profile_sample(regs);
+#endif
+
+#if CONFIG_PROFILING
+        profile_tick(CPU_PROFILING, regs);
+#endif
+}
+
 /*
  * Scheduler clock - returns current time in nanosec units.
  */
index 7a8c2880e4879f08a7529dcb5104831086b715a4..1ec69a7ea8365282b226ff9a91dbe36df4600bf8 100644 (file)
@@ -9,4 +9,6 @@
 #define PTRACE_SETREGS            13
 #endif
 
+#define profile_pc(regs) instruction_pointer(regs)
+
 #endif /* _CRIS_PTRACE_H */