]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/cpu.cpp
update
[l4.git] / kernel / fiasco / src / kern / cpu.cpp
1 INTERFACE:
2
3 #include "cpu_mask.h"
4 #include "member_offs.h"
5
6 class Cpu
7 {
8   MEMBER_OFFSET();
9
10 public:
11   /** Get the locical ID of this CPU */
12   unsigned id() const;
13
14
15   /**
16    * Set this CPU to online state.
17    * NOTE: This does not activate an inactive CPU, Just set the given state.
18    */
19   void set_online(bool o);
20
21   /** Get the physical ID of the CPU, for inter processor communication */
22   unsigned phys_id() const;
23
24   /** Convienience for Cpu::cpus.cpu(cpu).online() */
25   static bool online(unsigned cpu);
26
27   /**
28    * Get logical CPU id from physical ID
29    * NOTE: This call is SLOW, use only for debugging/bootup
30    */
31   static unsigned p2l(unsigned phys_id);
32
33   static Cpu_mask const &online_mask();
34
35
36 private:
37   /** Is this CPU online ? */
38   bool online() const;
39
40   static Cpu_mask _online_mask;
41 };
42
43
44 //--------------------------------------------------------------------------
45 INTERFACE[mp]:
46
47 EXTENSION class Cpu
48 {
49
50 private:
51   void set_id(unsigned id) { _id = id; }
52   unsigned _id;
53 };
54
55 //--------------------------------------------------------------------------
56 INTERFACE[!mp]:
57
58 EXTENSION class Cpu
59 {
60 private:
61   void set_id(unsigned) {}
62 };
63
64
65 // --------------------------------------------------------------------------
66 IMPLEMENTATION:
67
68 Cpu_mask Cpu::_online_mask(Cpu_mask::Init::Bss);
69
70 IMPLEMENT inline
71 Cpu_mask const &
72 Cpu::online_mask()
73 { return _online_mask; }
74
75 // --------------------------------------------------------------------------
76 IMPLEMENTATION [mp]:
77
78 #include "kdb_ke.h"
79
80 IMPLEMENT inline
81 unsigned
82 Cpu::id() const
83 { return _id; }
84
85 IMPLEMENT inline
86 bool
87 Cpu::online() const
88 { return _online_mask.get(_id); }
89
90 IMPLEMENT inline
91 void
92 Cpu::set_online(bool o)
93 {
94   if (o)
95     _online_mask.set(_id);
96   else
97     _online_mask.clear(_id);
98 }
99
100 IMPLEMENT
101 unsigned
102 Cpu::p2l(unsigned phys_id)
103 {
104   for (unsigned i = 0; i < Config::Max_num_cpus; ++i)
105     if (Per_cpu_data::valid(i) && Cpu::cpus.cpu(i).phys_id() == phys_id)
106       return i;
107
108   return ~0U;
109 }
110
111 IMPLEMENT static inline NEEDS["kdb_ke.h"]
112 bool
113 Cpu::online(unsigned _cpu)
114 { return _online_mask.get(_cpu); }
115
116
117 // --------------------------------------------------------------------------
118 IMPLEMENTATION [!mp]:
119
120 IMPLEMENT inline
121 unsigned
122 Cpu::id() const
123 { return 0; }
124
125 IMPLEMENT inline
126 bool
127 Cpu::online() const
128 { return true; }
129
130 IMPLEMENT inline
131 void
132 Cpu::set_online(bool)
133 {}
134
135 IMPLEMENT
136 unsigned
137 Cpu::p2l(unsigned)
138 { return 0; }
139
140 IMPLEMENT static inline
141 bool
142 Cpu::online(unsigned _cpu)
143 { return _cpu == 0; }
144