aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-04 19:47:29 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-04 19:47:29 -0500
commit6c655551fb7f5994f58ac1ef5a01f654059f19f9 (patch)
tree77c8ef4c9d5282d23b68695dc51d4379a168921a
parentd57c3460bebbf73af5168328baef93090435dfb7 (diff)
Used miscdevice API for sched_trace
This patch changes sched_trace.c to use the miscdevice API instead of doing all the cdev management ourselves. This remove a chunk of code and we get sysfs / udev integration for free. On systems with default udev rules, this will result in a /dev/litmus/log device being created automatically.
-rw-r--r--litmus/ctrldev.c2
-rw-r--r--litmus/sched_trace.c72
2 files changed, 18 insertions, 56 deletions
diff --git a/litmus/ctrldev.c b/litmus/ctrldev.c
index 238da453228d..6677a67cc945 100644
--- a/litmus/ctrldev.c
+++ b/litmus/ctrldev.c
@@ -7,7 +7,7 @@
7#include <litmus/litmus.h> 7#include <litmus/litmus.h>
8 8
9/* only one page for now, but we might want to add a RO version at some point */ 9/* only one page for now, but we might want to add a RO version at some point */
10#define CTRL_MINOR_COUNT 1 10
11#define CTRL_NAME "litmus/ctrl" 11#define CTRL_NAME "litmus/ctrl"
12 12
13/* allocate t->rt_param.ctrl_page*/ 13/* allocate t->rt_param.ctrl_page*/
diff --git a/litmus/sched_trace.c b/litmus/sched_trace.c
index 55c3dc23b3ef..cea227b13785 100644
--- a/litmus/sched_trace.c
+++ b/litmus/sched_trace.c
@@ -5,7 +5,7 @@
5#include <linux/semaphore.h> 5#include <linux/semaphore.h>
6 6
7#include <linux/fs.h> 7#include <linux/fs.h>
8#include <linux/cdev.h> 8#include <linux/miscdevice.h>
9#include <asm/uaccess.h> 9#include <asm/uaccess.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/sysrq.h> 11#include <linux/sysrq.h>
@@ -15,6 +15,8 @@
15#include <litmus/sched_trace.h> 15#include <litmus/sched_trace.h>
16#include <litmus/litmus.h> 16#include <litmus/litmus.h>
17 17
18#define SCHED_TRACE_NAME "litmus/log"
19
18/* Allocate a buffer of about 1 MB per CPU */ 20/* Allocate a buffer of about 1 MB per CPU */
19#define LITMUS_TRACE_BUF_ORDER 8 21#define LITMUS_TRACE_BUF_ORDER 8
20#define LITMUS_TRACE_BUF_SIZE (PAGE_SIZE * LITMUS_TRACE_BUF_ORDER) 22#define LITMUS_TRACE_BUF_SIZE (PAGE_SIZE * LITMUS_TRACE_BUF_ORDER)
@@ -25,14 +27,6 @@
25/* Max length for one write --- from kernel --- to the buffer */ 27/* Max length for one write --- from kernel --- to the buffer */
26#define MSG_SIZE 255 28#define MSG_SIZE 255
27 29
28/*
29 * Major number for the tracing char device.
30 * the major numbes are from the unassigned/local use block
31 *
32 * set MAJOR to 0 to have it dynamically assigned
33 */
34#define LOG_MAJOR 251
35
36/* Inner ring buffer structure */ 30/* Inner ring buffer structure */
37typedef struct { 31typedef struct {
38 rwlock_t del_lock; 32 rwlock_t del_lock;
@@ -316,54 +310,18 @@ static int log_release(struct inode *in, struct file *filp)
316 * 310 *
317 * Except for opening the device file it uses the same operations as trace_fops. 311 * Except for opening the device file it uses the same operations as trace_fops.
318 */ 312 */
319struct file_operations log_fops = { 313static struct file_operations log_fops = {
320 .owner = THIS_MODULE, 314 .owner = THIS_MODULE,
321 .open = log_open, 315 .open = log_open,
322 .release = log_release, 316 .release = log_release,
323 .read = log_read, 317 .read = log_read,
324}; 318};
325 319
326/* 320static struct miscdevice litmus_log_dev = {
327 * Device registration 321 .name = SCHED_TRACE_NAME,
328 */ 322 .minor = MISC_DYNAMIC_MINOR,
329static int __init register_buffer_dev(const char* name, 323 .fops = &log_fops,
330 struct file_operations* fops, 324};
331 int major, int count)
332{
333 dev_t trace_dev;
334 struct cdev *cdev;
335 int error = 0;
336
337 if(major) {
338 trace_dev = MKDEV(major, 0);
339 error = register_chrdev_region(trace_dev, count, name);
340 } else {
341 /* dynamically allocate major number */
342 error = alloc_chrdev_region(&trace_dev, 0, count, name);
343 major = MAJOR(trace_dev);
344 }
345 if (error) {
346 printk(KERN_WARNING "sched trace: "
347 "Could not register major/minor number %d\n", major);
348 return error;
349 }
350 cdev = cdev_alloc();
351 if (!cdev) {
352 printk(KERN_WARNING "sched trace: "
353 "Could not get a cdev for %s.\n", name);
354 return -ENOMEM;
355 }
356 cdev->owner = THIS_MODULE;
357 cdev->ops = fops;
358 error = cdev_add(cdev, trace_dev, count);
359 if (error) {
360 printk(KERN_WARNING "sched trace: "
361 "add_cdev failed for %s.\n", name);
362 return -ENOMEM;
363 }
364 return error;
365
366}
367 325
368#ifdef CONFIG_MAGIC_SYSRQ 326#ifdef CONFIG_MAGIC_SYSRQ
369void dump_trace_buffer(int max) 327void dump_trace_buffer(int max)
@@ -372,7 +330,7 @@ void dump_trace_buffer(int max)
372 int len; 330 int len;
373 int count = 0; 331 int count = 0;
374 332
375 /* potentially, but very unlikely race... */ 333 /* potential, but very unlikely, race... */
376 trace_recurse = 1; 334 trace_recurse = 1;
377 while ((max == 0 || count++ < max) && 335 while ((max == 0 || count++ < max) &&
378 (len = rb_get(&log_buffer.buf, line, sizeof(line) - 1)) > 0) { 336 (len = rb_get(&log_buffer.buf, line, sizeof(line) - 1)) > 0) {
@@ -408,9 +366,13 @@ static int __init init_sched_trace(void)
408#endif 366#endif
409 367
410 368
411 return register_buffer_dev("litmus_log", &log_fops, 369 return misc_register(&litmus_log_dev);
412 LOG_MAJOR, 1);
413} 370}
414 371
415module_init(init_sched_trace); 372static void __exit exit_sched_trace(void)
373{
374 misc_deregister(&litmus_log_dev);
375}
416 376
377module_init(init_sched_trace);
378module_exit(exit_sched_trace);