diff options
author | Christopher Kenna <cjk@cs.unc.edu> | 2012-05-04 15:58:00 -0400 |
---|---|---|
committer | Christopher Kenna <cjk@cs.unc.edu> | 2012-05-04 15:58:00 -0400 |
commit | bc53437f599fa2595385a2088a7bb74e47c4c8bb (patch) | |
tree | 84be715fab0e4d3ebef5e399448828701781051e /litmus/color_proc.c | |
parent | 27549ac2327435e299b1a08de626c794a9005be2 (diff) |
Fix up color proc CPU servers.
Diffstat (limited to 'litmus/color_proc.c')
-rw-r--r-- | litmus/color_proc.c | 141 |
1 files changed, 51 insertions, 90 deletions
diff --git a/litmus/color_proc.c b/litmus/color_proc.c index 3ad010f21b02..a8bcd145ccf0 100644 --- a/litmus/color_proc.c +++ b/litmus/color_proc.c | |||
@@ -5,27 +5,33 @@ | |||
5 | #include <litmus/sched_trace.h> | 5 | #include <litmus/sched_trace.h> |
6 | #include <litmus/color.h> | 6 | #include <litmus/color.h> |
7 | 7 | ||
8 | #define SPERIOD_LEN 7 | ||
9 | #define SPERIOD_FILE "period" | ||
10 | #define SWCET_LEN 5 | ||
11 | #define SWCET_FILE "wcet" | ||
12 | |||
13 | extern int color_sysctl_add_pages_data; /* litmus/color.c */ | 8 | extern int color_sysctl_add_pages_data; /* litmus/color.c */ |
14 | 9 | ||
15 | static int zero = 0; | 10 | static int zero = 0; |
16 | static int one = 1; | 11 | static int one = 1; |
12 | /* used as names for server proc entries */ | ||
13 | char *period_str = "period"; | ||
14 | char *wcet_str = "wcet"; | ||
15 | |||
16 | /* servers have a WCET and period */ | ||
17 | #define NR_SERVER_PARAMS 2 | ||
18 | #define CPU_NAME_LEN 3 | ||
19 | struct color_cpu_server { | ||
20 | char name[CPU_NAME_LEN]; | ||
21 | unsigned long wcet; | ||
22 | unsigned long period; | ||
23 | /* the + 1 is for the sentinel element */ | ||
24 | struct ctl_table table[NR_SERVER_PARAMS + 1]; | ||
25 | }; | ||
26 | static struct color_cpu_server color_cpu_servers[NR_CPUS]; | ||
17 | 27 | ||
18 | static unsigned long *server_wcet; | 28 | /* the + 1 is for the sentinel element */ |
19 | static unsigned long *server_period; | 29 | static struct ctl_table color_cpu_tables[NR_CPUS + 1]; |
20 | 30 | ||
21 | #define NR_PAGES_INDEX 0 /* location of nr_pages in the table below */ | 31 | #define NR_PAGES_INDEX 0 /* location of nr_pages in the table below */ |
22 | static struct ctl_table color_table[] = | 32 | static struct ctl_table color_table[] = |
23 | { | 33 | { |
24 | { | 34 | { |
25 | .procname = "servers", | ||
26 | .mode = 0555, | ||
27 | }, | ||
28 | { | ||
29 | /* you MUST update NR_PAGES_INDEX if you move this entry */ | 35 | /* you MUST update NR_PAGES_INDEX if you move this entry */ |
30 | .procname = "nr_pages", | 36 | .procname = "nr_pages", |
31 | .mode = 0444, | 37 | .mode = 0444, |
@@ -34,6 +40,11 @@ static struct ctl_table color_table[] = | |||
34 | .maxlen = 0, /* also set later */ | 40 | .maxlen = 0, /* also set later */ |
35 | }, | 41 | }, |
36 | { | 42 | { |
43 | .procname = "servers", | ||
44 | .mode = 0555, | ||
45 | .child = color_cpu_tables, | ||
46 | }, | ||
47 | { | ||
37 | .procname = "add_pages", | 48 | .procname = "add_pages", |
38 | .data = &color_sysctl_add_pages_data, | 49 | .data = &color_sysctl_add_pages_data, |
39 | .maxlen = sizeof(int), | 50 | .maxlen = sizeof(int), |
@@ -66,20 +77,23 @@ static struct ctl_table litmus_dir_table[] = { | |||
66 | 77 | ||
67 | int color_server_params(int cpu, unsigned long *wcet, unsigned long *period) | 78 | int color_server_params(int cpu, unsigned long *wcet, unsigned long *period) |
68 | { | 79 | { |
80 | struct color_cpu_server *svr; | ||
81 | |||
69 | if (cpu >= num_online_cpus()) { | 82 | if (cpu >= num_online_cpus()) { |
70 | printk(KERN_WARNING "Cannot access illegal CPU: %d\n", cpu); | 83 | printk(KERN_WARNING "Cannot access illegal CPU: %d\n", cpu); |
71 | return -EFAULT; | 84 | return -EFAULT; |
72 | } | 85 | } |
73 | 86 | ||
74 | if (server_wcet[cpu] == 0 || server_period[cpu] == 0) { | 87 | svr = &color_cpu_servers[cpu]; |
88 | if (svr->wcet == 0 || svr->period == 0) { | ||
75 | printk(KERN_WARNING "Server %d is uninitialized!\n", cpu); | 89 | printk(KERN_WARNING "Server %d is uninitialized!\n", cpu); |
76 | return -EPERM; | 90 | return -EPERM; |
77 | } | 91 | } |
78 | 92 | ||
79 | *wcet = server_wcet[cpu]; | 93 | *wcet = svr->wcet; |
80 | *period = server_period[cpu]; | 94 | *period = svr->period; |
81 | 95 | ||
82 | TRACE("For %d: %lu, %lu\n", cpu, server_wcet[cpu], server_period[cpu]); | 96 | TRACE("For %d: %lu, %lu\n", cpu, svr->wcet, svr->period); |
83 | 97 | ||
84 | return 0; | 98 | return 0; |
85 | } | 99 | } |
@@ -107,82 +121,44 @@ static void __init init_server_entry(struct ctl_table *entry, | |||
107 | entry->mode = 0666; | 121 | entry->mode = 0666; |
108 | entry->proc_handler = proc_doulongvec_minmax; | 122 | entry->proc_handler = proc_doulongvec_minmax; |
109 | entry->data = parameter; | 123 | entry->data = parameter; |
110 | entry->maxlen = sizeof(unsigned long); | 124 | entry->maxlen = sizeof(*parameter); |
111 | } | 125 | } |
112 | 126 | ||
113 | static int __init init_cpu_entry(struct ctl_table *cpu_table, int cpu) | 127 | static int __init init_cpu_entry(struct ctl_table *cpu_table, |
128 | struct color_cpu_server *svr, int cpu) | ||
114 | { | 129 | { |
115 | char *name; | 130 | struct ctl_table *entry = svr->table; |
116 | size_t size; | ||
117 | struct ctl_table *server_table, *entry; | ||
118 | |||
119 | server_wcet[cpu] = 0; | ||
120 | server_period[cpu] = 0; | ||
121 | 131 | ||
122 | printk(KERN_INFO "Creating cpu %d\n", cpu); | 132 | printk(KERN_INFO "Creating cpu %d\n", cpu); |
123 | 133 | ||
124 | size = sizeof(ctl_table) * 3; | 134 | init_server_entry(entry, &svr->wcet, wcet_str); |
125 | server_table = kmalloc(size, GFP_ATOMIC); | 135 | entry++; |
126 | if (!server_table) { | 136 | init_server_entry(entry, &svr->period, period_str); |
127 | printk(KERN_WARNING "Could not allocate " | ||
128 | "color server proc for CPU %d.\n", cpu); | ||
129 | return -ENOMEM; | ||
130 | } | ||
131 | memset(server_table, 0, size); | ||
132 | |||
133 | /* Server WCET */ | ||
134 | name = kmalloc(SWCET_LEN, GFP_ATOMIC); | ||
135 | if (!name) { | ||
136 | return -ENOMEM; | ||
137 | } | ||
138 | strcpy(name, SWCET_FILE); | ||
139 | entry = &server_table[0]; | ||
140 | init_server_entry(entry, &server_wcet[cpu], name); | ||
141 | |||
142 | |||
143 | /* Server period */ | ||
144 | name = kmalloc(SPERIOD_LEN, GFP_ATOMIC); | ||
145 | if (!name) { | ||
146 | return -ENOMEM; | ||
147 | } | ||
148 | strcpy(name, SPERIOD_FILE); | ||
149 | entry = &server_table[1]; | ||
150 | init_server_entry(entry, &server_period[cpu], name); | ||
151 | 137 | ||
152 | name = kmalloc(3, GFP_ATOMIC); | 138 | /* minus one for the null byte */ |
153 | if (!name) { | 139 | snprintf(svr->name, CPU_NAME_LEN - 1, "%d", cpu); |
154 | return -ENOMEM; | 140 | cpu_table->procname = svr->name; |
155 | } | ||
156 | snprintf(name, 2, "%d", cpu); | ||
157 | cpu_table->procname = name; | ||
158 | cpu_table->mode = 0555; | 141 | cpu_table->mode = 0555; |
159 | cpu_table->child = server_table; | 142 | cpu_table->child = svr->table; |
160 | 143 | ||
161 | return 0; | 144 | return 0; |
162 | } | 145 | } |
163 | 146 | ||
164 | static int __init init_server_entries(struct ctl_table *cpu_tables) | 147 | static int __init init_server_entries(void) |
165 | { | 148 | { |
166 | size_t size; | 149 | int cpu, err = 0; |
167 | int ret, cpu; | ||
168 | struct ctl_table *cpu_table; | 150 | struct ctl_table *cpu_table; |
169 | 151 | struct color_cpu_server *svr; | |
170 | size = sizeof(unsigned long) * num_online_cpus(); | ||
171 | server_wcet = kmalloc(size, GFP_ATOMIC); | ||
172 | server_period = kmalloc(size, GFP_ATOMIC); | ||
173 | if (!server_wcet || !server_period) { | ||
174 | printk(KERN_WARNING "Could not allocate server parameters.\n"); | ||
175 | return -ENOMEM; | ||
176 | } | ||
177 | 152 | ||
178 | for_each_online_cpu(cpu) { | 153 | for_each_online_cpu(cpu) { |
179 | cpu_table = &cpu_tables[cpu]; | 154 | cpu_table = &color_cpu_tables[cpu]; |
180 | ret = init_cpu_entry(cpu_table, cpu); | 155 | svr = &color_cpu_servers[cpu]; |
181 | if (ret) { | 156 | err = init_cpu_entry(cpu_table, svr, cpu); |
182 | return ret; | 157 | if (err) |
183 | } | 158 | goto out; |
184 | } | 159 | } |
185 | return 0; | 160 | out: |
161 | return err; | ||
186 | } | 162 | } |
187 | 163 | ||
188 | 164 | ||
@@ -191,8 +167,6 @@ static struct ctl_table_header *litmus_sysctls; | |||
191 | static int __init litmus_sysctl_init(void) | 167 | static int __init litmus_sysctl_init(void) |
192 | { | 168 | { |
193 | int ret = 0; | 169 | int ret = 0; |
194 | size_t size; | ||
195 | struct ctl_table *cpu_tables; | ||
196 | 170 | ||
197 | printk(KERN_INFO "Registering LITMUS^RT proc sysctl.\n"); | 171 | printk(KERN_INFO "Registering LITMUS^RT proc sysctl.\n"); |
198 | litmus_sysctls = register_sysctl_table(litmus_dir_table); | 172 | litmus_sysctls = register_sysctl_table(litmus_dir_table); |
@@ -205,22 +179,9 @@ static int __init litmus_sysctl_init(void) | |||
205 | if (ret) | 179 | if (ret) |
206 | goto out; | 180 | goto out; |
207 | 181 | ||
208 | 182 | ret = init_server_entries(); | |
209 | size = sizeof(ctl_table) * (num_online_cpus() + 2); | ||
210 | cpu_tables = kmalloc(size, GFP_ATOMIC); | ||
211 | if (!cpu_tables) { | ||
212 | printk(KERN_WARNING "Could not allocate color CPU proc.\n"); | ||
213 | ret = -ENOMEM; | ||
214 | goto out; | ||
215 | } | ||
216 | memset(cpu_tables, 0, size); | ||
217 | |||
218 | ret = init_server_entries(cpu_tables); | ||
219 | if (ret) | 183 | if (ret) |
220 | goto out; | 184 | goto out; |
221 | |||
222 | color_table[0].child = cpu_tables; | ||
223 | |||
224 | out: | 185 | out: |
225 | return ret; | 186 | return ret; |
226 | } | 187 | } |