Re: [PATCH] user-defined profiling

From: Akinobu Mita
Date: Mon Nov 01 2004 - 11:53:02 EST


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");



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/