linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* subj: [PATHC] user-defined profiling
@ 2004-11-01 16:33 Akinobu Mita
  2004-11-01 16:49 ` [PATCH] " Akinobu Mita
  2004-11-01 17:39 ` subj: [PATHC] " William Lee Irwin III
  0 siblings, 2 replies; 3+ messages in thread
From: Akinobu Mita @ 2004-11-01 16:33 UTC (permalink / raw)
  To: Andrew Morton, William Lee Irwin III; +Cc: linux-kernel

Hello,

This patch provides support for user-defined profiling. It is
inspired by scheduler profiling.

If you put the following code into interesting function

	profile_hit(USR_PROFILNG, __buildin_return_address(0));

and boot with profile=user then the readprofile shows which functions
called it, and how many times.

Furthermore I much prefer to insert the user-defined profile point
with Kprobe. This is why the profile_hits() was exported.

Please apply.

Signed-off-by Akinobu Mita <amgta@yacht.ocn.ne.jp>


--- 2.6-mm/Documentation/kernel-parameters.txt.orig	2004-11-02 01:17:50.491934664 +0900
+++ 2.6-mm/Documentation/kernel-parameters.txt	2004-11-02 01:18:47.552260176 +0900
@@ -1002,8 +1002,9 @@ running once the system is up.
 			Ranges are in pairs (memory base and size).
 
 	profile=	[KNL] Enable kernel profiling via /proc/profile
-			{ schedule | <number> }
+			{ schedule | user| <number> }
 			(param: schedule - profile schedule points}
+			(param: user - profile user-defined points}
 			(param: profile step/bucket size as a power of 2 for
 				statistical time based profiling)
 
--- 2.6-mm/include/linux/profile.h.orig	2004-11-02 01:18:40.740295752 +0900
+++ 2.6-mm/include/linux/profile.h	2004-11-02 01:18:47.538262304 +0900
@@ -11,6 +11,7 @@
 
 #define CPU_PROFILING	1
 #define SCHED_PROFILING	2
+#define USR_PROFILING	3
 
 struct proc_dir_entry;
 struct pt_regs;
--- 2.6-mm/kernel/profile.c.orig	2004-11-02 01:18:27.490310056 +0900
+++ 2.6-mm/kernel/profile.c	2004-11-02 01:18:47.550260480 +0900
@@ -47,18 +47,26 @@ static DECLARE_MUTEX(profile_flip_mutex)
 static int __init profile_setup(char * str)
 {
 	int par;
+	char *desc;
 
 	if (!strncmp(str, "schedule", 8)) {
 		prof_on = SCHED_PROFILING;
-		printk(KERN_INFO "kernel schedule profiling enabled\n");
-		if (str[7] == ',')
-			str += 8;
+		desc = "schedule";
+		str += 8;
+	} else if (!strncmp(str, "user", 4)) {
+		prof_on = USR_PROFILING;
+		desc = "user-defined";
+		str += 4;
+
+	} else {
+		prof_on = CPU_PROFILING;
+		desc = "";
 	}
+
 	if (get_option(&str,&par)) {
 		prof_shift = par;
-		prof_on = CPU_PROFILING;
-		printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
-			prof_shift);
+		printk(KERN_INFO "kernel %s profiling enabled (shift: %ld)\n",
+			desc, prof_shift);
 	}
 	return 1;
 }
@@ -392,6 +400,8 @@ void profile_hit(int type, void *__pc)
 }
 #endif /* !CONFIG_SMP */
 
+EXPORT_SYMBOL_GPL(profile_hit);
+
 void profile_tick(int type, struct pt_regs *regs)
 {
 	if (type == CPU_PROFILING)





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

* Re: [PATCH] user-defined profiling
  2004-11-01 16:33 subj: [PATHC] user-defined profiling Akinobu Mita
@ 2004-11-01 16:49 ` Akinobu Mita
  2004-11-01 17:39 ` subj: [PATHC] " William Lee Irwin III
  1 sibling, 0 replies; 3+ messages in thread
From: Akinobu Mita @ 2004-11-01 16:49 UTC (permalink / raw)
  To: Andrew Morton, William Lee Irwin III; +Cc: linux-kernel

On Tuesday 02 November 2004 01:33, Akinobu Mita wrote:

> Furthermore I much prefer to insert the user-defined profile point
> with Kprobe. This is why the profile_hits() was exported.

I am using this kernel module to insert user-defined profiling.

$ insmod usrprof.ko probe=<address>


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/profile.h>
#include <linux/kprobes.h>

#if !defined(__i386__) || !defined(CONFIG_FRAME_POINTER)
#error not supported
#endif

/* copied from arch/i386/traps.c */

static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
{
	return  p > (void *)tinfo &&
		p < (void *)tinfo + THREAD_SIZE - 3;
}

int pre_handler(struct kprobe *p, struct pt_regs *regs) {
	unsigned long ebp = regs->ebp;
	unsigned long addr = ~0UL;
	struct thread_info *context = (struct thread_info *)
		(regs->esp & (~(THREAD_SIZE - 1)));

	if (valid_stack_ptr(context, (void *)ebp))
		addr = *(unsigned long *)(ebp + 4);
		
	profile_hit(USR_PROFILING, (void *)addr);

	return 0;
}

static struct kprobe kp = {
	.pre_handler	= pre_handler,
};

static long probe;
module_param(probe, long, 0);

static int __init init_usrprof(void)
{
	if (!probe) {
		printk(KERN_ERR "%lx: invalid address\n", probe);
		return 1;
	}
	kp.addr = (void *)probe;
	register_kprobe(&kp);
	return 0;
}

static void __exit cleanup_usrprof(void)
{
	unregister_kprobe(&kp);
}

module_init(init_usrprof);
module_exit(cleanup_usrprof);

MODULE_LICENSE("GPL");




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

* Re: subj: [PATHC] user-defined profiling
  2004-11-01 16:33 subj: [PATHC] user-defined profiling Akinobu Mita
  2004-11-01 16:49 ` [PATCH] " Akinobu Mita
@ 2004-11-01 17:39 ` William Lee Irwin III
  1 sibling, 0 replies; 3+ messages in thread
From: William Lee Irwin III @ 2004-11-01 17:39 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: Andrew Morton, linux-kernel

On Tue, Nov 02, 2004 at 01:33:53AM +0900, Akinobu Mita wrote:
> This patch provides support for user-defined profiling. It is
> inspired by scheduler profiling.
> If you put the following code into interesting function
> 	profile_hit(USR_PROFILNG, __buildin_return_address(0));
> and boot with profile=user then the readprofile shows which functions
> called it, and how many times.
> Furthermore I much prefer to insert the user-defined profile point
> with Kprobe. This is why the profile_hits() was exported.
> Please apply.
> Signed-off-by Akinobu Mita <amgta@yacht.ocn.ne.jp>

It makes sense, though I wouldn't mind getting a look at who calls this.
Looking at the callee in isolation leaves me vaguely puzzled.


-- wli

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

end of thread, other threads:[~2004-11-01 17:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-01 16:33 subj: [PATHC] user-defined profiling Akinobu Mita
2004-11-01 16:49 ` [PATCH] " Akinobu Mita
2004-11-01 17:39 ` subj: [PATHC] " William Lee Irwin III

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).