MuxingKvmGic::copyBankedDistRange(BaseGicRegisters* from, BaseGicRegisters* to,
Addr daddr, size_t size)
{
- for (int ctx = 0; ctx < system._numContexts; ++ctx)
+ for (int ctx = 0; ctx < system.numContexts(); ++ctx)
for (auto a = daddr; a < daddr + size; a += 4)
copyDistRegister(from, to, ctx, a);
}
MuxingKvmGic::clearBankedDistRange(BaseGicRegisters* to,
Addr daddr, size_t size)
{
- for (int ctx = 0; ctx < system._numContexts; ++ctx)
+ for (int ctx = 0; ctx < system.numContexts(); ++ctx)
for (auto a = daddr; a < daddr + size; a += 4)
to->writeDistributor(ctx, a, 0xFFFFFFFF);
}
// Copy CPU Interface Control Register (CTLR),
// Interrupt Priority Mask Register (PMR), and
// Binary Point Register (BPR)
- for (int ctx = 0; ctx < system._numContexts; ++ctx) {
+ for (int ctx = 0; ctx < system.numContexts(); ++ctx) {
copyCpuRegister(from, to, ctx, GICC_CTLR);
copyCpuRegister(from, to, ctx, GICC_PMR);
copyCpuRegister(from, to, ctx, GICC_BPR);
// have been shifted by three bits due to its having been emulated by
// a VGIC with only 5 PMR bits in its VMCR register. Presently the
// Linux kernel does not repair this inaccuracy, so we correct it here.
- for (int cpu = 0; cpu < system._numContexts; ++cpu) {
+ for (int cpu = 0; cpu < system.numContexts(); ++cpu) {
cpuPriority[cpu] <<= 3;
assert((cpuPriority[cpu] & ~0xff) == 0);
}
std::string task_filename = "tasks.txt";
taskFile = simout.create(name() + "." + task_filename);
- for (int i = 0; i < _numContexts; i++) {
- ThreadContext *tc = threadContexts[i];
+ for (const auto tc : threadContexts) {
uint32_t pid = tc->getCpuPtr()->getPid();
if (pid != BaseCPU::invldPid) {
mapPid(tc, pid);
#include "sim/system.hh"
+#include <algorithm>
+
#include "arch/remote_gdb.hh"
#include "arch/utility.hh"
#include "base/loader/object_file.hh"
System::System(Params *p)
: MemObject(p), _systemPort("system_port", this),
- _numContexts(0),
multiThread(p->multi_thread),
pagePtr(0),
init_param(p->init_param),
"Cannot have two CPUs with the same id (%d)\n", id);
threadContexts[id] = tc;
- _numContexts++;
#if THE_ISA != NULL_ISA
int port = getRemoteGDBPort();
int
System::numRunningContexts()
{
- int running = 0;
- for (int i = 0; i < _numContexts; ++i) {
- if (threadContexts[i]->status() != ThreadContext::Halted)
- ++running;
- }
- return running;
+ return std::count_if(
+ threadContexts.cbegin(),
+ threadContexts.cend(),
+ [] (ThreadContext* tc) {
+ return tc->status() != ThreadContext::Halted;
+ }
+ );
}
void
#endif
std::vector<ThreadContext *> threadContexts;
- int _numContexts;
const bool multiThread;
ThreadContext *getThreadContext(ContextID tid)
return threadContexts[tid];
}
- int numContexts()
- {
- assert(_numContexts == (int)threadContexts.size());
- return _numContexts;
- }
+ unsigned numContexts() const { return threadContexts.size(); }
/** Return number of running (non-halted) thread contexts in
* system. These threads could be Active or Suspended. */