diff options
author | Christopher Kenna <cjk@cs.unc.edu> | 2011-01-09 19:33:49 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-01-12 19:29:48 -0500 |
commit | d11808b5c6b032de4284281ed2ff77ae697a4ebd (patch) | |
tree | 0d135d237e96c3179b2983892b95bb9969a0166c /litmus/sched_task_trace.c | |
parent | 37eb46be881dde4b405d3d8b48e76b4a8d62ae2c (diff) |
Feather-Trace: dynamic memory allocation and clean exit2011.1
This patch changes Feather-Trace to allocate memory for the minor
devices dynamically, which addresses a long-standing FIXME. It also
provides clean module exit and error conditions for Feather-Trace.
Diffstat (limited to 'litmus/sched_task_trace.c')
-rw-r--r-- | litmus/sched_task_trace.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/litmus/sched_task_trace.c b/litmus/sched_task_trace.c index 7ef7b2889b42..a15b25d21a89 100644 --- a/litmus/sched_task_trace.c +++ b/litmus/sched_task_trace.c | |||
@@ -38,12 +38,17 @@ static int st_dev_can_open(struct ftdev *dev, unsigned int cpu) | |||
38 | static int __init init_sched_task_trace(void) | 38 | static int __init init_sched_task_trace(void) |
39 | { | 39 | { |
40 | struct local_buffer* buf; | 40 | struct local_buffer* buf; |
41 | int i, ok = 0; | 41 | int i, ok = 0, err; |
42 | printk("Allocated %u sched_trace_xxx() events per CPU " | 42 | printk("Allocated %u sched_trace_xxx() events per CPU " |
43 | "(buffer size: %d bytes)\n", | 43 | "(buffer size: %d bytes)\n", |
44 | NO_EVENTS, (int) sizeof(struct local_buffer)); | 44 | NO_EVENTS, (int) sizeof(struct local_buffer)); |
45 | ftdev_init(&st_dev, THIS_MODULE, "sched_trace"); | 45 | |
46 | for (i = 0; i < NR_CPUS; i++) { | 46 | err = ftdev_init(&st_dev, THIS_MODULE, |
47 | num_online_cpus(), "sched_trace"); | ||
48 | if (err) | ||
49 | goto err_out; | ||
50 | |||
51 | for (i = 0; i < st_dev.minor_cnt; i++) { | ||
47 | buf = &per_cpu(st_event_buffer, i); | 52 | buf = &per_cpu(st_event_buffer, i); |
48 | ok += init_ft_buffer(&buf->ftbuf, NO_EVENTS, | 53 | ok += init_ft_buffer(&buf->ftbuf, NO_EVENTS, |
49 | sizeof(struct st_event_record), | 54 | sizeof(struct st_event_record), |
@@ -51,16 +56,32 @@ static int __init init_sched_task_trace(void) | |||
51 | buf->record); | 56 | buf->record); |
52 | st_dev.minor[i].buf = &buf->ftbuf; | 57 | st_dev.minor[i].buf = &buf->ftbuf; |
53 | } | 58 | } |
54 | if (ok == NR_CPUS) { | 59 | if (ok == st_dev.minor_cnt) { |
55 | st_dev.minor_cnt = NR_CPUS; | ||
56 | st_dev.can_open = st_dev_can_open; | 60 | st_dev.can_open = st_dev_can_open; |
57 | return register_ftdev(&st_dev); | 61 | err = register_ftdev(&st_dev); |
62 | if (err) | ||
63 | goto err_dealloc; | ||
58 | } else { | 64 | } else { |
59 | return -EINVAL; | 65 | err = -EINVAL; |
66 | goto err_dealloc; | ||
60 | } | 67 | } |
68 | |||
69 | return 0; | ||
70 | |||
71 | err_dealloc: | ||
72 | ftdev_exit(&st_dev); | ||
73 | err_out: | ||
74 | printk(KERN_WARNING "Could not register sched_trace module\n"); | ||
75 | return err; | ||
76 | } | ||
77 | |||
78 | static void __exit exit_sched_task_trace(void) | ||
79 | { | ||
80 | ftdev_exit(&st_dev); | ||
61 | } | 81 | } |
62 | 82 | ||
63 | module_init(init_sched_task_trace); | 83 | module_init(init_sched_task_trace); |
84 | module_exit(exit_sched_task_trace); | ||
64 | 85 | ||
65 | 86 | ||
66 | static inline struct st_event_record* get_record(u8 type, struct task_struct* t) | 87 | static inline struct st_event_record* get_record(u8 type, struct task_struct* t) |