base: Declare a type for context IDs

Context IDs used to be declared as ad hoc (usually as int). This
changeset introduces a typedef for ContextIDs and a constant for
invalid context IDs.
This commit is contained in:
Andreas Sandberg 2015-08-07 09:59:13 +01:00
parent 3e26756f1d
commit 53e777d683
25 changed files with 65 additions and 61 deletions

View file

@ -181,6 +181,10 @@ const Addr MaxAddr = (Addr)-1;
typedef int16_t ThreadID;
const ThreadID InvalidThreadID = (ThreadID)-1;
/** Globally unique thread context ID */
typedef int ContextID;
const ContextID InvalidContextID = (ContextID)-1;
/**
* Port index/ID type, and a symbolic name for an invalid port id.
*/

View file

@ -460,7 +460,7 @@ class BaseDynInst : public ExecContext, public RefCounted
MasterID masterId() const { return cpu->dataMasterId(); }
/** Read this context's system-wide ID **/
int contextId() const { return thread->contextId(); }
ContextID contextId() const { return thread->contextId(); }
/** Returns the fault type. */
Fault getFault() const { return fault; }

View file

@ -96,9 +96,9 @@ class CheckerThreadContext : public ThreadContext
int cpuId() const { return actualTC->cpuId(); }
int contextId() const { return actualTC->contextId(); }
ContextID contextId() const { return actualTC->contextId(); }
void setContextId(int id)
void setContextId(ContextID id)
{
actualTC->setContextId(id);
checkerTC->setContextId(id);

View file

@ -254,7 +254,7 @@ class ExecContext : public ::ExecContext
unsigned int readStCondFailures() const { return 0; }
void setStCondFailures(unsigned int st_cond_failures) {}
int contextId() { return thread.contextId(); }
ContextID contextId() { return thread.contextId(); }
/* ISA-specific (or at least currently ISA singleton) functions */
/* X86: TLB twiddling */

View file

@ -101,7 +101,7 @@ class O3ThreadContext : public ThreadContext
/** Reads this CPU's Socket ID. */
virtual uint32_t socketId() const { return cpu->socketId(); }
virtual int contextId() const { return thread->contextId(); }
virtual ContextID contextId() const { return thread->contextId(); }
virtual void setContextId(int id) { thread->setContextId(id); }

View file

@ -95,9 +95,9 @@ ThreadContext::compare(ThreadContext *one, ThreadContext *two)
if (id1 != id2)
panic("CPU ids don't match, one: %d, two: %d", id1, id2);
id1 = one->contextId();
id2 = two->contextId();
if (id1 != id2)
const ContextID cid1 = one->contextId();
const ContextID cid2 = two->contextId();
if (cid1 != cid2)
panic("Context ids don't match, one: %d, two: %d", id1, id2);

View file

@ -71,9 +71,9 @@ struct ThreadState : public Serializable {
uint32_t socketId() const { return baseCpu->socketId(); }
int contextId() const { return _contextId; }
ContextID contextId() const { return _contextId; }
void setContextId(int id) { _contextId = id; }
void setContextId(ContextID id) { _contextId = id; }
void setThreadId(ThreadID id) { _threadId = id; }
@ -153,7 +153,7 @@ struct ThreadState : public Serializable {
BaseCPU *baseCpu;
// system wide HW context id
int _contextId;
ContextID _contextId;
// Index of hardware thread context on the CPU that this represents.
ThreadID _threadId;

View file

@ -135,7 +135,7 @@ Pl390::readDistributor(PacketPtr pkt)
{
Addr daddr = pkt->getAddr() - distAddr;
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
DPRINTF(GIC, "gic distributor read register %#x\n", daddr);
@ -269,7 +269,7 @@ Pl390::readCpu(PacketPtr pkt)
Addr daddr = pkt->getAddr() - cpuAddr;
assert(pkt->req->hasContextId());
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
assert(ctx_id < sys->numRunningContexts());
DPRINTF(GIC, "gic cpu read register %#x cpu context: %d\n", daddr,
@ -356,7 +356,7 @@ Pl390::writeDistributor(PacketPtr pkt)
Addr daddr = pkt->getAddr() - distAddr;
assert(pkt->req->hasContextId());
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
uint32_t pkt_data M5_VAR_USED;
switch (pkt->getSize())
@ -496,7 +496,7 @@ Pl390::writeCpu(PacketPtr pkt)
Addr daddr = pkt->getAddr() - cpuAddr;
assert(pkt->req->hasContextId());
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
IAR iar;
DPRINTF(GIC, "gic cpu write register cpu:%d %#x val: %#x\n",
@ -546,7 +546,7 @@ Pl390::writeCpu(PacketPtr pkt)
}
void
Pl390::softInt(int ctx_id, SWI swi)
Pl390::softInt(ContextID ctx_id, SWI swi)
{
switch (swi.list_type) {
case 1:

View file

@ -210,7 +210,7 @@ class Pl390 : public BaseGic
/** software generated interrupt
* @param data data to decode that indicates which cpus to interrupt
*/
void softInt(int ctx_id, SWI swi);
void softInt(ContextID ctx_id, SWI swi);
/** See if some processor interrupt flags need to be enabled/disabled
* @param hint which set of interrupts needs to be checked

View file

@ -75,7 +75,7 @@ CpuLocalTimer::read(PacketPtr pkt)
assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
assert(pkt->getSize() == 4);
Addr daddr = pkt->getAddr() - pioAddr;
int cpu_id = pkt->req->contextId();
ContextID cpu_id = pkt->req->contextId();
DPRINTF(Timer, "Reading from CpuLocalTimer at offset: %#x\n", daddr);
assert(cpu_id >= 0);
assert(cpu_id < CPU_MAX);
@ -153,7 +153,7 @@ CpuLocalTimer::write(PacketPtr pkt)
assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
assert(pkt->getSize() == 4);
Addr daddr = pkt->getAddr() - pioAddr;
int cpu_id = pkt->req->contextId();
ContextID cpu_id = pkt->req->contextId();
DPRINTF(Timer, "Writing to CpuLocalTimer at offset: %#x\n", daddr);
assert(cpu_id >= 0);
assert(cpu_id < CPU_MAX);

View file

@ -90,7 +90,7 @@ VGic::readVCpu(PacketPtr pkt)
{
Addr daddr = pkt->getAddr() - vcpuAddr;
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
assert(ctx_id < VGIC_CPU_MAX);
struct vcpuIntData *vid = &vcpuData[ctx_id];
@ -134,7 +134,7 @@ VGic::readCtrl(PacketPtr pkt)
{
Addr daddr = pkt->getAddr() - hvAddr;
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
DPRINTF(VGIC, "VGIC HVCtrl read register %#x\n", daddr);
@ -228,7 +228,7 @@ VGic::writeVCpu(PacketPtr pkt)
{
Addr daddr = pkt->getAddr() - vcpuAddr;
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
assert(ctx_id < VGIC_CPU_MAX);
struct vcpuIntData *vid = &vcpuData[ctx_id];
@ -275,7 +275,7 @@ VGic::writeCtrl(PacketPtr pkt)
{
Addr daddr = pkt->getAddr() - hvAddr;
int ctx_id = pkt->req->contextId();
ContextID ctx_id = pkt->req->contextId();
DPRINTF(VGIC, "VGIC HVCtrl write register %#x <= %#x\n", daddr, pkt->get<uint32_t>());
@ -380,7 +380,7 @@ VGic::unPostMaintInt(uint32_t cpu)
* This may raise a maintenance interrupt.
*/
void
VGic::updateIntState(int ctx_id)
VGic::updateIntState(ContextID ctx_id)
{
// @todo This should update APRs!

View file

@ -222,7 +222,7 @@ class VGic : public PioDevice
Tick writeVCpu(PacketPtr pkt);
Tick writeCtrl(PacketPtr pkt);
void updateIntState(int ctx_id);
void updateIntState(ContextID ctx_id);
uint32_t getMISR(struct vcpuIntData *vid);
void postVInt(uint32_t cpu, Tick when);
void unPostVInt(uint32_t cpu);

View file

@ -152,7 +152,7 @@ Device::getEthPort(const std::string &if_name, int idx)
void
Device::prepareIO(int cpu, int index)
Device::prepareIO(ContextID cpu, int index)
{
int size = virtualRegs.size();
if (index > size)
@ -165,7 +165,7 @@ Device::prepareIO(int cpu, int index)
//add stats for average number of vnics busy
void
Device::prepareRead(int cpu, int index)
Device::prepareRead(ContextID cpu, int index)
{
using namespace Regs;
prepareIO(cpu, index);
@ -206,7 +206,7 @@ Device::prepareRead(int cpu, int index)
}
void
Device::prepareWrite(int cpu, int index)
Device::prepareWrite(ContextID cpu, int index)
{
prepareIO(cpu, index);
}
@ -220,7 +220,7 @@ Device::read(PacketPtr pkt)
assert(config.command & PCI_CMD_MSE);
assert(pkt->getAddr() >= BARAddrs[0] && pkt->getSize() < BARSize[0]);
int cpu = pkt->req->contextId();
ContextID cpu = pkt->req->contextId();
Addr daddr = pkt->getAddr() - BARAddrs[0];
Addr index = daddr >> Regs::VirtualShift;
Addr raddr = daddr & Regs::VirtualMask;
@ -270,7 +270,7 @@ Device::read(PacketPtr pkt)
* IPR read of device register
Fault
Device::iprRead(Addr daddr, int cpu, uint64_t &result)
Device::iprRead(Addr daddr, ContextID cpu, uint64_t &result)
{
if (!regValid(daddr))
panic("invalid address: da=%#x", daddr);
@ -305,7 +305,7 @@ Device::write(PacketPtr pkt)
assert(config.command & PCI_CMD_MSE);
assert(pkt->getAddr() >= BARAddrs[0] && pkt->getSize() < BARSize[0]);
int cpu = pkt->req->contextId();
ContextID cpu = pkt->req->contextId();
Addr daddr = pkt->getAddr() - BARAddrs[0];
Addr index = daddr >> Regs::VirtualShift;
Addr raddr = daddr & Regs::VirtualMask;

View file

@ -273,10 +273,10 @@ class Device : public Base
virtual Tick write(PacketPtr pkt);
virtual void drainResume() M5_ATTR_OVERRIDE;
void prepareIO(int cpu, int index);
void prepareRead(int cpu, int index);
void prepareWrite(int cpu, int index);
// Fault iprRead(Addr daddr, int cpu, uint64_t &result);
void prepareIO(ContextID cpu, int index);
void prepareRead(ContextID cpu, int index);
void prepareWrite(ContextID cpu, int index);
// Fault iprRead(Addr daddr, ContextID cpu, uint64_t &result);
/**
* Statistics

View file

@ -118,7 +118,7 @@ void
Iob::readJBus(PacketPtr pkt)
{
Addr accessAddr = pkt->getAddr() - iobJBusAddr;
int cpuid = pkt->req->contextId();
ContextID cpuid = pkt->req->contextId();
int index;
uint64_t data;
@ -233,7 +233,7 @@ void
Iob::writeJBus(PacketPtr pkt)
{
Addr accessAddr = pkt->getAddr() - iobJBusAddr;
int cpuid = pkt->req->contextId();
ContextID cpuid = pkt->req->contextId();
int index;
uint64_t data;

View file

@ -74,7 +74,7 @@ class LockedAddr {
Addr addr;
// locking hw context
const int contextId;
const ContextID contextId;
static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }

View file

@ -130,7 +130,7 @@ class CacheBlk
*/
class Lock {
public:
int contextId; // locking context
ContextID contextId; // locking context
Addr lowAddr; // low address of lock range
Addr highAddr; // high address of lock range

View file

@ -332,7 +332,8 @@ Cache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat,
return false;
}
int id = pkt->req->hasContextId() ? pkt->req->contextId() : -1;
ContextID id = pkt->req->hasContextId() ?
pkt->req->contextId() : InvalidContextID;
// Here lat is the value passed as parameter to accessBlock() function
// that can modify its value.
blk = tags->accessBlock(pkt->getAddr(), pkt->isSecure(), lat, id);

View file

@ -293,7 +293,7 @@ PhysicalMemory::serialize(CheckpointOut &cp) const
{
// serialize all the locked addresses and their context ids
vector<Addr> lal_addr;
vector<int> lal_cid;
vector<ContextID> lal_cid;
for (auto& m : memories) {
const list<LockedAddr>& locked_addrs = m->getLockedAddrList();
@ -370,7 +370,7 @@ PhysicalMemory::unserialize(CheckpointIn &cp)
// unserialize the locked addresses and map them to the
// appropriate memory controller
vector<Addr> lal_addr;
vector<int> lal_cid;
vector<ContextID> lal_cid;
UNSERIALIZE_CONTAINER(lal_addr);
UNSERIALIZE_CONTAINER(lal_cid);
for(size_t i = 0; i < lal_addr.size(); ++i) {

View file

@ -296,7 +296,7 @@ class Request
uint64_t _extraData;
/** The context ID (for statistics, typically). */
int _contextId;
ContextID _contextId;
/** The thread ID (id within this CPU) */
ThreadID _threadId;
@ -353,7 +353,7 @@ class Request
}
Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
Addr pc, int cid, ThreadID tid)
Addr pc, ContextID cid, ThreadID tid)
: _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
_taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
_extraData(0), _contextId(0), _threadId(0), _pc(0),
@ -369,7 +369,7 @@ class Request
* Set up CPU and thread numbers.
*/
void
setThreadContext(int context_id, ThreadID tid)
setThreadContext(ContextID context_id, ThreadID tid)
{
_contextId = context_id;
_threadId = tid;
@ -591,7 +591,7 @@ class Request
}
/** Accessor function for context ID.*/
int
ContextID
contextId() const
{
assert(privateFlags.isSet(VALID_CONTEXT_ID));

View file

@ -49,12 +49,12 @@ class RubyRequest : public Message
PrefetchBit m_Prefetch;
uint8_t* data;
PacketPtr pkt;
unsigned m_contextId;
ContextID m_contextId;
RubyRequest(Tick curTime, uint64_t _paddr, uint8_t* _data, int _len,
uint64_t _pc, RubyRequestType _type, RubyAccessMode _access_mode,
PacketPtr _pkt, PrefetchBit _pb = PrefetchBit_No,
unsigned _proc_id = 100)
ContextID _proc_id = 100)
: Message(curTime),
m_PhysicalAddress(_paddr),
m_Type(_type),

View file

@ -667,10 +667,8 @@ void
Sequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type)
{
assert(pkt != NULL);
int proc_id = -1;
if (pkt->req->hasContextId()) {
proc_id = pkt->req->contextId();
}
ContextID proc_id = pkt->req->hasContextId() ?
pkt->req->contextId() : InvalidContextID;
// If valid, copy the pc to the ruby request
Addr pc = 0;

View file

@ -75,7 +75,7 @@ class Process : public SimObject
System *system;
// thread contexts associated with this process
std::vector<int> contextIds;
std::vector<ContextID> contextIds;
// number of CPUs (esxec contexts, really) assigned to this process.
unsigned int numCpus() { return contextIds.size(); }
@ -160,7 +160,7 @@ class Process : public SimObject
// After getting registered with system object, tell process which
// system-wide context id it is assigned.
void assignThreadContext(int context_id)
void assignThreadContext(ContextID context_id)
{
contextIds.push_back(context_id);
}

View file

@ -209,11 +209,11 @@ bool System::breakpoint()
*/
int rgdb_wait = -1;
int
System::registerThreadContext(ThreadContext *tc, int assigned)
ContextID
System::registerThreadContext(ThreadContext *tc, ContextID assigned)
{
int id;
if (assigned == -1) {
if (assigned == InvalidContextID) {
for (id = 0; id < threadContexts.size(); id++) {
if (!threadContexts[id])
break;
@ -305,7 +305,7 @@ System::initState()
}
void
System::replaceThreadContext(ThreadContext *tc, int context_id)
System::replaceThreadContext(ThreadContext *tc, ContextID context_id)
{
if (context_id >= threadContexts.size()) {
panic("replaceThreadContext: bad id, %d >= %d\n",

View file

@ -197,7 +197,7 @@ class System : public MemObject
std::vector<ThreadContext *> threadContexts;
int _numContexts;
ThreadContext *getThreadContext(ThreadID tid)
ThreadContext *getThreadContext(ContextID tid)
{
return threadContexts[tid];
}
@ -514,8 +514,9 @@ class System : public MemObject
/// @return Starting address of first page
Addr allocPhysPages(int npages);
int registerThreadContext(ThreadContext *tc, int assigned=-1);
void replaceThreadContext(ThreadContext *tc, int context_id);
ContextID registerThreadContext(ThreadContext *tc,
ContextID assigned = InvalidContextID);
void replaceThreadContext(ThreadContext *tc, ContextID context_id);
void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;