]> 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   struct By_phys_id
12   {
13     Unsigned32 _p;
14     By_phys_id(Unsigned32 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
24   /** Get the logical ID of this CPU */
25   unsigned id() const;
26
27
28   /**
29    * Set this CPU to online state.
30    * NOTE: This does not activate an inactive CPU, Just set the given state.
31    */
32   void set_online(bool o);
33
34   /** Convienience for Cpu::cpus.cpu(cpu).online() */
35   static bool online(unsigned cpu);
36
37   static Online_cpu_mask const &online_mask();
38
39 private:
40   /** Is this CPU online ? */
41   bool online() const;
42
43   static Online_cpu_mask _online_mask;
44 };
45
46
47 //--------------------------------------------------------------------------
48 INTERFACE[mp]:
49
50 EXTENSION class Cpu
51 {
52
53 private:
54   void set_id(unsigned id) { _id = id; }
55   unsigned _id;
56 };
57
58 //--------------------------------------------------------------------------
59 INTERFACE[!mp]:
60
61 EXTENSION class Cpu
62 {
63 private:
64   void set_id(unsigned) {}
65 };
66
67
68 // --------------------------------------------------------------------------
69 IMPLEMENTATION:
70
71 Cpu::Online_cpu_mask Cpu::_online_mask(Online_cpu_mask::Init::Bss);
72
73 IMPLEMENT inline
74 Cpu::Online_cpu_mask const &
75 Cpu::online_mask()
76 { return _online_mask; }
77
78 // --------------------------------------------------------------------------
79 IMPLEMENTATION [mp]:
80
81 #include "kdb_ke.h"
82
83 IMPLEMENT inline
84 unsigned
85 Cpu::id() const
86 { return _id; }
87
88 IMPLEMENT inline
89 bool
90 Cpu::online() const
91 { return _online_mask.get(_id); }
92
93 IMPLEMENT inline
94 void
95 Cpu::set_online(bool o)
96 {
97   if (o)
98     _online_mask.set(_id);
99   else
100     _online_mask.clear(_id);
101 }
102
103
104 IMPLEMENT static inline NEEDS["kdb_ke.h"]
105 bool
106 Cpu::online(unsigned _cpu)
107 { return _online_mask.get(_cpu); }
108
109
110 // --------------------------------------------------------------------------
111 IMPLEMENTATION [!mp]:
112
113 IMPLEMENT inline
114 unsigned
115 Cpu::id() const
116 { return 0; }
117
118 IMPLEMENT inline
119 bool
120 Cpu::online() const
121 { return true; }
122
123 IMPLEMENT inline
124 void
125 Cpu::set_online(bool)
126 {}
127
128 IMPLEMENT static inline
129 bool
130 Cpu::online(unsigned _cpu)
131 { return _cpu == 0; }
132