diff options
author | Kristian Høgsberg <krh@redhat.com> | 2005-12-20 17:55:03 +0000 |
---|---|---|
committer | Kristian Høgsberg <krh@src.gnome.org> | 2005-12-20 17:55:03 +0000 |
commit | ad5ffd749bafd462724df74f4ebe945d9ceee805 (patch) | |
tree | c065dec862cf5420ca61d2f433022a79d678fcb6 /module | |
parent | c1f411c356273d4464e21c407516ed6131c006dd (diff) |
Dist and install udev rule.
2005-12-20 Kristian Høgsberg <krh@redhat.com>
* Makefile.am: Dist and install udev rule.
* collector.c: (open_fd):
* sysprof-text.c: (no_module):
* sysprof.c: (on_start_toggled): Update device filename.
* 60-sysprof.rules: New udev rule file to set permissions for
sysprof char device.
* module/sysprof-module.c: Switch kernel module to use a misc char
device instead. Start and stop the timer on device open and
close instead of module load and unload.
Diffstat (limited to 'module')
-rw-r--r-- | module/sysprof-module.c | 77 | ||||
-rw-r--r-- | module/sysprof-module.h | 2 |
2 files changed, 54 insertions, 25 deletions
diff --git a/module/sysprof-module.c b/module/sysprof-module.c index 0eb2310..abcc77e 100644 --- a/module/sysprof-module.c +++ b/module/sysprof-module.c @@ -27,6 +27,7 @@ #include <linux/kernel.h> /* Needed for KERN_ALERT */ #include <linux/module.h> /* Needed by all modules */ #include <linux/sched.h> +#include <linux/miscdevice.h> #include <linux/proc_fs.h> #include <asm/uaccess.h> @@ -166,26 +167,30 @@ timer_notify (struct pt_regs *regs) } static int -procfile_read(char *buffer, - char **buffer_location, - off_t offset, - int buffer_len, - int *eof, - void *data) +sysprof_read(struct file *file, char *buffer, size_t count, loff_t *offset) { + SysprofStackTrace *trace; + + if (count < sizeof *tail) + return -EMSGSIZE; + if (head == tail) return -EWOULDBLOCK; - *buffer_location = (char *)tail; - + printk(KERN_NOTICE "sysprof: read one trace\n"); + + trace = tail; if (tail++ == &stack_traces[N_TRACES - 1]) tail = &stack_traces[0]; - return sizeof (SysprofStackTrace); + if (copy_to_user(buffer, tail, sizeof *tail)) + return -EFAULT; + + return sizeof *tail; } static unsigned int -procfile_poll(struct file *filp, poll_table *poll_table) +sysprof_poll(struct file *filp, poll_table *poll_table) { if (head != tail) return POLLIN | POLLRDNORM; @@ -198,23 +203,47 @@ procfile_poll(struct file *filp, poll_table *poll_table) return 0; } -struct proc_dir_entry *trace_proc_file; +static int +sysprof_open(struct inode *inode, struct file *file) +{ + register_timer_hook (timer_notify); + + return 0; +} + +static int +sysprof_release(struct inode *inode, struct file *file) +{ + unregister_timer_hook (timer_notify); + + return 0; +} + +static struct file_operations sysprof_fops = { + .owner = THIS_MODULE, + .read = sysprof_read, + .poll = sysprof_poll, + .open = sysprof_open, + .release = sysprof_release, +}; + +static struct miscdevice sysprof_miscdev = { + MISC_DYNAMIC_MINOR, + "sysprof-trace", + &sysprof_fops +}; int init_module(void) { - trace_proc_file = - create_proc_entry ("sysprof-trace", S_IFREG | S_IRUGO, &proc_root); - - if (!trace_proc_file) - return 1; - - trace_proc_file->read_proc = procfile_read; - trace_proc_file->proc_fops->poll = procfile_poll; - trace_proc_file->size = sizeof (SysprofStackTrace); + int ret; + + ret = misc_register(&sysprof_miscdev); + if (ret) { + printk(KERN_ERR "sysprof: failed to register misc device\n"); + return ret; + } - register_timer_hook (timer_notify); - printk(KERN_ALERT "sysprof: loaded\n"); return 0; @@ -223,9 +252,7 @@ init_module(void) void cleanup_module(void) { - unregister_timer_hook (timer_notify); - - remove_proc_entry("sysprof-trace", &proc_root); + misc_deregister(&sysprof_miscdev); printk(KERN_ALERT "sysprof: unloaded\n"); } diff --git a/module/sysprof-module.h b/module/sysprof-module.h index 66a11ae..ac2f4c6 100644 --- a/module/sysprof-module.h +++ b/module/sysprof-module.h @@ -20,6 +20,8 @@ #ifndef SYSPROF_MODULE_H #define SYSPROF_MODULE_H +#define SYSPROF_FILE "/dev/sysprof-trace" + typedef struct SysprofStackTrace SysprofStackTrace; #define SYSPROF_MAX_ADDRESSES 512 |