]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/cpu.cpp
6ac7780c04cbedec68ed6b1c9bc84bd1357fd557
[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   struct By_phys_id
12   {
13     Cpu_phys_id _p;
14     By_phys_id(Cpu_phys_id p) : _p(p) {}
15     template<typename CPU>
16     bool operator () (CPU const &c) const { return _p == c.phys_id(); }
17   };
18   // we actually use a mask that has one CPU more that we can physically,
19   // have, to avoid lots of special cases for an invalid CPU number
20   typedef Cpu_mask_t<Config::Max_num_cpus + 1> Online_cpu_mask;
21
22   enum { Invalid = Config::Max_num_cpus };
23   static Cpu_number invalid() { return Cpu_number(Invalid); }
24
25   /** Get the logical ID of this CPU */
26   Cpu_number id() const;
27
28
29   /**
30    * Set this CPU to online state.
31    * NOTE: This does not activate an inactive CPU, Just set the given state.
32    */
33   void set_online(bool o);
34
35   /** Convienience for Cpu::cpus.cpu(cpu).online() */
36   static bool online(Cpu_number cpu);
37
38   static Online_cpu_mask const &online_mask();
39
40 private:
41   /** Is this CPU online ? */
42   bool online() const;
43
44   static Online_cpu_mask _online_mask;
45 };
46
47
48 //--------------------------------------------------------------------------
49 INTERFACE[mp]:
50
51 EXTENSION class Cpu
52 {
53
54 private:
55   void set_id(Cpu_number id) { _id = id; }
56   Cpu_number _id;
57 };
58
59 //--------------------------------------------------------------------------
60 INTERFACE[!mp]:
61
62 EXTENSION class Cpu
63 {
64 private:
65   void set_id(Cpu_number) {}
66 };
67
68
69 // --------------------------------------------------------------------------
70 IMPLEMENTATION:
71
72 Cpu::Online_cpu_mask Cpu::_online_mask(Online_cpu_mask::Init::Bss);
73
74 IMPLEMENT inline
75 Cpu::Online_cpu_mask const &
76 Cpu::online_mask()
77 { return _online_mask; }
78
79 // --------------------------------------------------------------------------
80 IMPLEMENTATION [mp]:
81
82 #include "kdb_ke.h"
83
84 IMPLEMENT inline
85 Cpu_number
86 Cpu::id() const
87 { return _id; }
88
89 IMPLEMENT inline
90 bool
91 Cpu::online() const
92 { return _online_mask.get(_id); }
93
94 IMPLEMENT inline
95 void
96 Cpu::set_online(bool o)
97 {
98   if (o)
99     _online_mask.set(_id);
100   else
101     _online_mask.clear(_id);
102 }
103
104
105 IMPLEMENT static inline NEEDS["kdb_ke.h"]
106 bool
107 Cpu::online(Cpu_number _cpu)
108 { return _online_mask.get(_cpu); }
109
110
111 // --------------------------------------------------------------------------
112 IMPLEMENTATION [!mp]:
113
114 IMPLEMENT inline
115 Cpu_number
116 Cpu::id() const
117 { return Cpu_number::boot_cpu(); }
118
119 IMPLEMENT inline
120 bool
121 Cpu::online() const
122 { return true; }
123
124 IMPLEMENT inline
125 void
126 Cpu::set_online(bool)
127 {}
128
129 IMPLEMENT static inline
130 bool
131 Cpu::online(Cpu_number _cpu)
132 { return _cpu == Cpu_number::boot_cpu(); }
133