]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_mp_request_sl.cpp
2e4dcd6fb61ad1f66e09b4ce6f2b6c60f9e1a937
[l4.git] / kernel / fiasco / src / jdb / jdb_mp_request_sl.cpp
1 IMPLEMENTATION [mp]:
2
3 #include <cstdio>
4 #include "simpleio.h"
5
6 #include "jdb.h"
7 #include "jdb_module.h"
8 #include "static_init.h"
9 #include "types.h"
10 #include "mp_request.h"
11
12
13 class Jdb_mp_request_module : public Jdb_module
14 {
15   typedef Mp_request_queue::Fifo Fifo;
16   typedef Fifo::Item Item;
17 public:
18   Jdb_mp_request_module() FIASCO_INIT;
19   struct Find_cpu
20   {
21     Item const *r;
22     mutable unsigned cpu;
23     Find_cpu(Item const *i) : r(i), cpu(~0U) {}
24     void operator()(unsigned _cpu) const
25     {
26       if (&Mp_request_queue::rq.cpu(_cpu) == r)
27         {
28           cpu = _cpu;
29           return;
30         }
31     }
32   };
33 };
34
35 static Jdb_mp_request_module jdb_mp_request_module INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
36
37 PRIVATE static
38 unsigned
39 Jdb_mp_request_module::find_cpu(Item const *r)
40 {
41   if (!r)
42     return 0;
43
44   Find_cpu _find_cpu(r);
45   Jdb::foreach_cpu(_find_cpu);
46   return _find_cpu.cpu;
47 }
48
49 PRIVATE static
50 void
51 Jdb_mp_request_module::print_request(Item const *item)
52 {
53   printf("  Request item of cpu %u [%p]:\n"
54          "    value  = { func = %p, arg = %p, _lock=%lu }\n"
55          "    next   = %p (cpu %u)\n",
56          find_cpu(item), item, item->value.func, item->value.arg, item->value._lock,
57          item->next, find_cpu(item->next));
58 }
59
60 PRIVATE static
61 void
62 Jdb_mp_request_module::print_queue(unsigned cpu)
63 {
64
65   if (!Jdb::cpu_in_jdb(cpu))
66     {
67       bool online = Cpu::online(cpu);
68       if (!online)
69         {
70           printf("CPU %u is not online...\n", cpu);
71           return;
72         }
73       printf("CPU %u has not entered JDB (try to display queue...\n", cpu);
74     }
75
76   Item const *item = &Mp_request_queue::rq.cpu(cpu);
77   Fifo const *fifo = &Mp_request_queue::fifo.cpu(cpu);
78
79
80   printf("CPU[%2u]: Mp request item @%p, Mp request FIFO @%p\n"
81          " Local queue Item:\n",
82          cpu, item, fifo);
83
84   print_request(item);
85
86   printf(" Request FIFO: head = %p(%u), tail = { %p(%u) }\n",
87          fifo->_head, find_cpu(fifo->_head),
88          fifo->_tail, find_cpu(fifo->_tail));
89
90   item = fifo->_head;
91   while (item)
92     {
93       print_request(item);
94       item = item->next;
95     }
96
97   puts("");
98 }
99
100 PUBLIC
101 Jdb_module::Action_code
102 Jdb_mp_request_module::action (int cmd, void *&argbuf, char const *&fmt, int &next)
103 {
104   char const *c = (char const *)argbuf;
105   unsigned cpu;
106   if (cmd!=0)
107     return NOTHING;
108
109   if (argbuf != &cpu)
110     {
111       if (*c == 'a')
112         Jdb::foreach_cpu(&print_queue);
113       else if (*c >= '0' && *c <= '9')
114         {
115           next = *c; argbuf = &cpu; fmt = "%i";
116           return EXTRA_INPUT_WITH_NEXTCHAR;
117         }
118     }
119   else
120     print_queue(cpu);
121
122   return NOTHING;
123 }
124
125 PUBLIC
126 int
127 Jdb_mp_request_module::num_cmds() const
128
129   return 1;
130 }
131
132 PUBLIC
133 Jdb_module::Cmd const *
134 Jdb_mp_request_module::cmds() const
135 {
136   static char c;
137   static Cmd cs[] =
138     { { 0, "", "mpqueue", "%C", "mpqueue all|<cpunum>\tdump X-CPU "
139                                 "request queues", &c } };
140
141   return cs;
142 }
143
144 IMPLEMENT
145 Jdb_mp_request_module::Jdb_mp_request_module()
146   : Jdb_module("INFO")
147 {}