misc: Standardize the way create() constructs SimObjects.

The create() method on Params structs usually instantiate SimObjects
using a constructor which takes the Params struct as a parameter
somehow. There has been a lot of needless variation in how that was
done, making it annoying to pass Params down to base classes. Some of
the different forms were:

const Params &
Params &
Params *
const Params *
Params const*

This change goes through and fixes up every constructor and every
create() method to use the const Params & form. We use a reference
because the Params struct should never be null. We use const because
neither the create method nor the consuming object should modify the
record of the parameters as they came in from the config. That would
make consuming them not idempotent, and make it impossible to tell what
the actual simulation configuration was since it would change from any
user visible form (config script, config.ini, dot pdf output).

Change-Id: I77453cba52fdcfd5f4eec92dfb0bddb5a9945f31
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35938
Reviewed-by: Gabe Black <gabeblack@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2020-10-07 06:49:23 -07:00
parent aeb39c1441
commit 91d83cc8a1
822 changed files with 4078 additions and 4038 deletions

View File

@@ -52,12 +52,12 @@
using namespace ArmISA;
SystemCounter::SystemCounter(SystemCounterParams *const p)
SystemCounter::SystemCounter(const SystemCounterParams &p)
: SimObject(p),
_enabled(true),
_value(0),
_increment(1),
_freqTable(p->freqs),
_freqTable(p.freqs),
_activeFreqEntry(0),
_updateTick(0),
_freqUpdateEvent([this]{ freqUpdateCallback(); }, name()),
@@ -395,21 +395,21 @@ ArchTimer::drainResume()
updateCounter();
}
GenericTimer::GenericTimer(GenericTimerParams *const p)
GenericTimer::GenericTimer(const GenericTimerParams &p)
: SimObject(p),
systemCounter(*p->counter),
system(*p->system)
systemCounter(*p.counter),
system(*p.system)
{
SystemCounter::validateCounterRef(p->counter);
fatal_if(!p->system, "GenericTimer::GenericTimer: No system specified, "
SystemCounter::validateCounterRef(p.counter);
fatal_if(!p.system, "GenericTimer::GenericTimer: No system specified, "
"can't instantiate architected timers\n");
system.setGenericTimer(this);
}
const GenericTimerParams *
const GenericTimerParams &
GenericTimer::params() const
{
return dynamic_cast<const GenericTimerParams *>(_params);
return dynamic_cast<const GenericTimerParams &>(_params);
}
void
@@ -467,7 +467,7 @@ void
GenericTimer::createTimers(unsigned cpus)
{
assert(timers.size() < cpus);
auto p = static_cast<const GenericTimerParams *>(_params);
auto &p = static_cast<const GenericTimerParams &>(_params);
const unsigned old_cpu_count(timers.size());
timers.resize(cpus);
@@ -477,10 +477,10 @@ GenericTimer::createTimers(unsigned cpus)
timers[i].reset(
new CoreTimers(*this, system, i,
p->int_phys_s->get(tc),
p->int_phys_ns->get(tc),
p->int_virt->get(tc),
p->int_hyp->get(tc)));
p.int_phys_s->get(tc),
p.int_phys_ns->get(tc),
p.int_virt->get(tc),
p.int_hyp->get(tc)));
}
}
@@ -727,7 +727,7 @@ GenericTimer::CoreTimers::CoreTimers(GenericTimer &_parent,
ArmInterruptPin *_irqPhysS, ArmInterruptPin *_irqPhysNS,
ArmInterruptPin *_irqVirt, ArmInterruptPin *_irqHyp)
: parent(_parent),
cntfrq(parent.params()->cntfrq),
cntfrq(parent.params().cntfrq),
threadContext(system.threads[cpu]),
irqPhysS(_irqPhysS),
irqPhysNS(_irqPhysNS),
@@ -873,23 +873,23 @@ GenericTimerISA::readMiscReg(int reg)
return value;
}
GenericTimerFrame::GenericTimerFrame(GenericTimerFrameParams *const p)
GenericTimerFrame::GenericTimerFrame(const GenericTimerFrameParams &p)
: PioDevice(p),
timerRange(RangeSize(p->cnt_base, ArmSystem::PageBytes)),
timerRange(RangeSize(p.cnt_base, ArmSystem::PageBytes)),
addrRanges({timerRange}),
systemCounter(*p->counter),
systemCounter(*p.counter),
physTimer(csprintf("%s.phys_timer", name()),
*this, systemCounter, p->int_phys->get()),
*this, systemCounter, p.int_phys->get()),
virtTimer(csprintf("%s.virt_timer", name()),
*this, systemCounter,
p->int_virt->get()),
p.int_virt->get()),
accessBits(0x3f),
system(*dynamic_cast<ArmSystem *>(sys))
{
SystemCounter::validateCounterRef(p->counter);
SystemCounter::validateCounterRef(p.counter);
// Expose optional CNTEL0Base register frame
if (p->cnt_el0_base != MaxAddr) {
timerEl0Range = RangeSize(p->cnt_el0_base, ArmSystem::PageBytes);
if (p.cnt_el0_base != MaxAddr) {
timerEl0Range = RangeSize(p.cnt_el0_base, ArmSystem::PageBytes);
accessBitsEl0 = 0x303;
addrRanges.push_back(timerEl0Range);
}
@@ -1244,18 +1244,18 @@ GenericTimerFrame::timerWrite(Addr addr, size_t size, uint64_t data,
}
}
GenericTimerMem::GenericTimerMem(GenericTimerMemParams *const p)
GenericTimerMem::GenericTimerMem(const GenericTimerMemParams &p)
: PioDevice(p),
counterCtrlRange(RangeSize(p->cnt_control_base, ArmSystem::PageBytes)),
counterStatusRange(RangeSize(p->cnt_read_base, ArmSystem::PageBytes)),
timerCtrlRange(RangeSize(p->cnt_ctl_base, ArmSystem::PageBytes)),
counterCtrlRange(RangeSize(p.cnt_control_base, ArmSystem::PageBytes)),
counterStatusRange(RangeSize(p.cnt_read_base, ArmSystem::PageBytes)),
timerCtrlRange(RangeSize(p.cnt_ctl_base, ArmSystem::PageBytes)),
cnttidr(0x0),
addrRanges{counterCtrlRange, counterStatusRange, timerCtrlRange},
systemCounter(*p->counter),
frames(p->frames),
systemCounter(*p.counter),
frames(p.frames),
system(*dynamic_cast<ArmSystem *>(sys))
{
SystemCounter::validateCounterRef(p->counter);
SystemCounter::validateCounterRef(p.counter);
for (auto &range : addrRanges)
GenericTimerMem::validateFrameRange(range);
fatal_if(frames.size() > MAX_TIMER_FRAMES,
@@ -1586,25 +1586,25 @@ GenericTimerMem::timerCtrlWrite(Addr addr, size_t size, uint64_t data,
}
SystemCounter *
SystemCounterParams::create()
SystemCounterParams::create() const
{
return new SystemCounter(this);
return new SystemCounter(*this);
}
GenericTimer *
GenericTimerParams::create()
GenericTimerParams::create() const
{
return new GenericTimer(this);
return new GenericTimer(*this);
}
GenericTimerFrame *
GenericTimerFrameParams::create()
GenericTimerFrameParams::create() const
{
return new GenericTimerFrame(this);
return new GenericTimerFrame(*this);
}
GenericTimerMem *
GenericTimerMemParams::create()
GenericTimerMemParams::create() const
{
return new GenericTimerMem(this);
return new GenericTimerMem(*this);
}