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
/*
 * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
 
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <copperplate/heapobj.h>
#include <copperplate/threadobj.h>
#include "sysregfs.h"
#include "../internal.h"
 
#ifdef CONFIG_XENO_PSHARED
 
static int retrieve_task_state(pid_t pid)
{
   char trash[BUFSIZ], state = '?', path[32];
   FILE *fp;
   int ret;
 
   /*
    * Try to figure out the state in kernel context of a Mercury
    * task which does not wait on a copperplate service. If this
    * task is not runnable, then display 'X', which is
    * reminiscent of a Cobalt task running out of real-time mode.
    * Otherwise, show this task as runnable.
    */
   snprintf(path, sizeof(path), "/proc/%d/stat", pid);
   fp = fopen(path, "r");
   if (fp) {
       ret = fscanf(fp, "%[0-9] (%[^) ]) %c", trash, trash, &state);
       fclose(fp);
       if (ret == 3 && state != 'R')
           state = 'X';
   }
 
   return state;
}
 
char *format_thread_status(const struct thread_data *p, char *buf, size_t len)
{
   char *wp = buf;
 
   if (len < 4)
       return NULL;
 
   if (p->status & __THREAD_S_TIMEDWAIT)
       *wp++ = 'w';
   else if (p->status & __THREAD_S_WAIT)
       *wp++ = 'W';
   else if (p->status & __THREAD_S_DELAYED)
       *wp++ = 'D';
   else if (p->status & __THREAD_S_STARTED)
       *wp++ = retrieve_task_state(p->pid);
   else
       *wp++ = 'U';
 
   if (p->schedlock > 0)
       *wp++ = 'l';
 
   if (p->policy == SCHED_RR)
       *wp++ = 'r';
 
   *wp = '\0';
 
   return buf;
}
 
#endif /* CONFIG_XENO_PSHARED */
 
struct sysreg_fsdir sysreg_dirs[] = {
   {
       .path = NULL,
   },
};
 
struct sysreg_fsfile sysreg_files[] = {
#ifdef CONFIG_XENO_PSHARED
   {
       .path = "/threads",
       .mode = O_RDONLY,
       .ops = {
           .open = open_threads,
           .release = fsobj_obstack_release,
           .read = fsobj_obstack_read
       },
   },
   {
       .path = "/heaps",
       .mode = O_RDONLY,
       .ops = {
           .open = open_heaps,
           .release = fsobj_obstack_release,
           .read = fsobj_obstack_read
       },
   },
#endif /* CONFIG_XENO_PSHARED */
   {
       .path = "/version",
       .mode = O_RDONLY,
       .ops = {
           .open = open_version,
           .release = fsobj_obstack_release,
           .read = fsobj_obstack_read
       },
   },
   {
       .path = NULL,
   }
};