hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * Copyright (C) 2001-2013 Philippe Gerum <rpm@xenomai.org>.
 *
 * Xenomai is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * Xenomai is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Xenomai; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
#include <cobalt/kernel/lock.h>
#include <cobalt/kernel/clock.h>
#include <cobalt/kernel/vfile.h>
#include <cobalt/kernel/intr.h>
#include <cobalt/kernel/heap.h>
#include <cobalt/kernel/timer.h>
#include <cobalt/kernel/sched.h>
#include <xenomai/version.h>
#include "debug.h"
 
#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
 
static int lock_vfile_show(struct xnvfile_regular_iterator *it, void *data)
{
   struct xnlockinfo lockinfo;
   spl_t s;
   int cpu;
 
   for_each_realtime_cpu(cpu) {
       xnlock_get_irqsave(&nklock, s);
       lockinfo = per_cpu(xnlock_stats, cpu);
       xnlock_put_irqrestore(&nklock, s);
 
       if (cpu > 0)
           xnvfile_printf(it, "\n");
 
       xnvfile_printf(it, "CPU%d:\n", cpu);
 
       xnvfile_printf(it,
                "  longest locked section: %llu ns\n"
                "  spinning time: %llu ns\n"
                "  section entry: %s:%d (%s)\n",
                  xnclock_ticks_to_ns(&nkclock, lockinfo.lock_time),
                  xnclock_ticks_to_ns(&nkclock, lockinfo.spin_time),
                  lockinfo.file, lockinfo.line, lockinfo.function);
   }
 
   return 0;
}
 
static ssize_t lock_vfile_store(struct xnvfile_input *input)
{
   ssize_t ret;
   spl_t s;
   int cpu;
 
   long val;
 
   ret = xnvfile_get_integer(input, &val);
   if (ret < 0)
       return ret;
 
   if (val != 0)
       return -EINVAL;
 
   for_each_realtime_cpu(cpu) {
       xnlock_get_irqsave(&nklock, s);
       memset(&per_cpu(xnlock_stats, cpu), '\0', sizeof(struct xnlockinfo));
       xnlock_put_irqrestore(&nklock, s);
   }
 
   return ret;
}
 
static struct xnvfile_regular_ops lock_vfile_ops = {
   .show = lock_vfile_show,
   .store = lock_vfile_store,
};
 
static struct xnvfile_regular lock_vfile = {
   .ops = &lock_vfile_ops,
};
 
#endif /* CONFIG_XENO_OPT_DEBUG_LOCKING */
 
static int latency_vfile_show(struct xnvfile_regular_iterator *it, void *data)
{
   xnvfile_printf(it, "%Lu\n",
              xnclock_ticks_to_ns(&nkclock, nkclock.gravity.user));
 
   return 0;
}
 
static ssize_t latency_vfile_store(struct xnvfile_input *input)
{
   ssize_t ret;
   long val;
 
   ret = xnvfile_get_integer(input, &val);
   if (ret < 0)
       return ret;
 
   nkclock.gravity.user = xnclock_ns_to_ticks(&nkclock, val);
 
   return ret;
}
 
static struct xnvfile_regular_ops latency_vfile_ops = {
   .show = latency_vfile_show,
   .store = latency_vfile_store,
};
 
static struct xnvfile_regular latency_vfile = {
   .ops = &latency_vfile_ops,
};
 
static int version_vfile_show(struct xnvfile_regular_iterator *it, void *data)
{
   xnvfile_printf(it, "%s\n", XENO_VERSION_STRING);
 
   return 0;
}
 
static struct xnvfile_regular_ops version_vfile_ops = {
   .show = version_vfile_show,
};
 
static struct xnvfile_regular version_vfile = {
   .ops = &version_vfile_ops,
};
 
static int faults_vfile_show(struct xnvfile_regular_iterator *it, void *data)
{
   int cpu, trap;
 
   xnvfile_puts(it, "TRAP ");
 
   for_each_realtime_cpu(cpu)
       xnvfile_printf(it, "        CPU%d", cpu);
 
   for (trap = 0; cobalt_machine.fault_labels[trap]; trap++) {
       if (*cobalt_machine.fault_labels[trap] == '\0')
           continue;
 
       xnvfile_printf(it, "\n%3d: ", trap);
 
       for_each_realtime_cpu(cpu)
           xnvfile_printf(it, "%12u",
                      per_cpu(cobalt_machine_cpudata, cpu).faults[trap]);
 
       xnvfile_printf(it, "    (%s)",
                  cobalt_machine.fault_labels[trap]);
   }
 
   xnvfile_putc(it, '\n');
 
   return 0;
}
 
static struct xnvfile_regular_ops faults_vfile_ops = {
   .show = faults_vfile_show,
};
 
static struct xnvfile_regular faults_vfile = {
   .ops = &faults_vfile_ops,
};
 
void xnprocfs_cleanup_tree(void)
{
#ifdef CONFIG_XENO_OPT_DEBUG
#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
   xnvfile_destroy_regular(&lock_vfile);
#endif
   xnvfile_destroy_dir(&cobalt_debug_vfroot);
#endif /* XENO_OPT_DEBUG */
   xnvfile_destroy_regular(&faults_vfile);
   xnvfile_destroy_regular(&version_vfile);
   xnvfile_destroy_regular(&latency_vfile);
   xnintr_cleanup_proc();
   xnheap_cleanup_proc();
   xnclock_cleanup_proc();
   xnsched_cleanup_proc();
   xnvfile_destroy_root();
}
 
int __init xnprocfs_init_tree(void)
{
   int ret;
 
   ret = xnvfile_init_root();
   if (ret)
       return ret;
 
   ret = xnsched_init_proc();
   if (ret)
       return ret;
 
   xnclock_init_proc();
   xnheap_init_proc();
   xnintr_init_proc();
   xnvfile_init_regular("latency", &latency_vfile, &cobalt_vfroot);
   xnvfile_init_regular("version", &version_vfile, &cobalt_vfroot);
   xnvfile_init_regular("faults", &faults_vfile, &cobalt_vfroot);
#ifdef CONFIG_XENO_OPT_DEBUG
   xnvfile_init_dir("debug", &cobalt_debug_vfroot, &cobalt_vfroot);
#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
   xnvfile_init_regular("lock", &lock_vfile, &cobalt_debug_vfroot);
#endif
#endif
 
   return 0;
}