Streamline interface to Request object.

src/SConscript:
    mem/request.cc no longer needed (all functions inline).
src/cpu/simple/atomic.cc:
src/cpu/simple/base.cc:
src/cpu/simple/timing.cc:
src/dev/io_device.cc:
src/mem/port.cc:
    Modified Request object interface.
src/mem/packet.hh:
    Modified Request object interface.
    Address & size are always set together now, so track
    with single flag.
src/mem/request.hh:
    Streamline interface to support a handful of calls that set
    multiple fields reflecting common usage patterns.
    Reduce number of validFoo booleans by combining flags for fields
    which must be set together.

--HG--
extra : convert_revision : 3b499de90d6d5f12f0cc7a9a788663265677fe10
This commit is contained in:
Steve Reinhardt 2006-05-31 00:12:29 -04:00
parent 91e3aa6295
commit d77d39daee
8 changed files with 149 additions and 167 deletions

View file

@ -95,7 +95,6 @@ base_sources = Split('''
mem/packet.cc
mem/physical.cc
mem/port.cc
mem/request.cc
sim/builder.cc
sim/configfile.cc

View file

@ -120,26 +120,17 @@ AtomicSimpleCPU::AtomicSimpleCPU(Params *p)
{
_status = Idle;
ifetch_req = new Request(true);
ifetch_req->setAsid(0);
// @todo fix me and get the real cpu iD!!!
ifetch_req->setCpuNum(0);
ifetch_req->setSize(sizeof(MachInst));
// @todo fix me and get the real cpu id & thread number!!!
ifetch_req = new Request();
ifetch_pkt = new Packet(ifetch_req, Packet::ReadReq, Packet::Broadcast);
ifetch_pkt->dataStatic(&inst);
data_read_req = new Request(true);
// @todo fix me and get the real cpu iD!!!
data_read_req->setCpuNum(0);
data_read_req->setAsid(0);
data_read_req = new Request();
data_read_pkt = new Packet(data_read_req, Packet::ReadReq,
Packet::Broadcast);
data_read_pkt->dataStatic(&dataReg);
data_write_req = new Request(true);
// @todo fix me and get the real cpu iD!!!
data_write_req->setCpuNum(0);
data_write_req->setAsid(0);
data_write_req = new Request();
data_write_pkt = new Packet(data_write_req, Packet::WriteReq,
Packet::Broadcast);
}
@ -236,10 +227,7 @@ template <class T>
Fault
AtomicSimpleCPU::read(Addr addr, T &data, unsigned flags)
{
data_read_req->setVaddr(addr);
data_read_req->setSize(sizeof(T));
data_read_req->setFlags(flags);
data_read_req->setTime(curTick);
data_read_req->setVirt(0, addr, sizeof(T), flags, cpuXC->readPC());
if (traceData) {
traceData->setAddr(addr);
@ -314,10 +302,7 @@ template <class T>
Fault
AtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
{
data_write_req->setVaddr(addr);
data_write_req->setTime(curTick);
data_write_req->setSize(sizeof(T));
data_write_req->setFlags(flags);
data_write_req->setVirt(0, addr, sizeof(T), flags, cpuXC->readPC());
if (traceData) {
traceData->setAddr(addr);
@ -408,7 +393,6 @@ AtomicSimpleCPU::tick()
checkForInterrupts();
ifetch_req->resetMin();
Fault fault = setupFetchRequest(ifetch_req);
if (fault == NoFault) {

View file

@ -357,13 +357,9 @@ BaseSimpleCPU::setupFetchRequest(Request *req)
DPRINTF(Fetch,"Fetch: PC:%08p NPC:%08p NNPC:%08p\n",cpuXC->readPC(),
cpuXC->readNextPC(),cpuXC->readNextNPC());
req->setVaddr(cpuXC->readPC() & ~3);
req->setTime(curTick);
#if FULL_SYSTEM
req->setFlags((cpuXC->readPC() & 1) ? PHYSICAL : 0);
#else
req->setFlags(0);
#endif
req->setVirt(0, cpuXC->readPC() & ~3, sizeof(MachInst),
(FULL_SYSTEM && (cpuXC->readPC() & 1)) ? PHYSICAL : 0,
cpuXC->readPC());
Fault fault = cpuXC->translateInstReq(req);

View file

@ -172,12 +172,10 @@ template <class T>
Fault
TimingSimpleCPU::read(Addr addr, T &data, unsigned flags)
{
Request *data_read_req = new Request(true);
// need to fill in CPU & thread IDs here
Request *data_read_req = new Request();
data_read_req->setVaddr(addr);
data_read_req->setSize(sizeof(T));
data_read_req->setFlags(flags);
data_read_req->setTime(curTick);
data_read_req->setVirt(0, addr, sizeof(T), flags, cpuXC->readPC());
if (traceData) {
traceData->setAddr(data_read_req->getVaddr());
@ -255,11 +253,9 @@ template <class T>
Fault
TimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
{
Request *data_write_req = new Request(true);
data_write_req->setVaddr(addr);
data_write_req->setTime(curTick);
data_write_req->setSize(sizeof(T));
data_write_req->setFlags(flags);
// need to fill in CPU & thread IDs here
Request *data_write_req = new Request();
data_write_req->setVirt(0, addr, sizeof(T), flags, cpuXC->readPC());
// translate to physical address
Fault fault = cpuXC->translateDataWriteReq(data_write_req);
@ -340,8 +336,8 @@ TimingSimpleCPU::fetch()
{
checkForInterrupts();
Request *ifetch_req = new Request(true);
ifetch_req->setSize(sizeof(MachInst));
// need to fill in CPU & thread IDs here
Request *ifetch_req = new Request();
Fault fault = setupFetchRequest(ifetch_req);
ifetch_pkt = new Packet(ifetch_req, Packet::ReadReq, Packet::Broadcast);

View file

@ -166,15 +166,12 @@ DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
for (ChunkGenerator gen(addr, size, peerBlockSize());
!gen.done(); gen.next()) {
Request *req = new Request(false);
req->setPaddr(gen.addr());
req->setSize(gen.size());
req->setTime(curTick);
Request *req = new Request(gen.addr(), gen.size(), 0);
Packet *pkt = new Packet(req, cmd, Packet::Broadcast);
// Increment the data pointer on a write
if (data)
pkt->dataStatic(data + prevSize) ;
pkt->dataStatic(data + prevSize);
prevSize += gen.size();

View file

@ -91,10 +91,8 @@ class Packet
* (unlike * addr, size, and src). */
short dest;
/** Is the 'addr' field valid? */
bool addrValid;
/** Is the 'size' field valid? */
bool sizeValid;
/** Are the 'addr' and 'size' fields valid? */
bool addrSizeValid;
/** Is the 'src' field valid? */
bool srcValid;
@ -192,11 +190,8 @@ class Packet
short getDest() const { return dest; }
void setDest(short _dest) { dest = _dest; }
Addr getAddr() const { assert(addrValid); return addr; }
void setAddr(Addr _addr) { addr = _addr; addrValid = true; }
int getSize() const { assert(sizeValid); return size; }
void setSize(int _size) { size = _size; sizeValid = true; }
Addr getAddr() const { assert(addrSizeValid); return addr; }
int getSize() const { assert(addrSizeValid); return size; }
/** Constructor. Note that a Request object must be constructed
* first, but the Requests's physical address and size fields
@ -205,7 +200,7 @@ class Packet
Packet(Request *_req, Command _cmd, short _dest)
: data(NULL), staticData(false), dynamicData(false), arrayData(false),
addr(_req->paddr), size(_req->size), dest(_dest),
addrValid(_req->validPaddr), sizeValid(_req->validSize),
addrSizeValid(_req->validPaddr),
srcValid(false),
req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
result(Unknown)
@ -223,9 +218,9 @@ class Packet
* multiple transactions. */
void reinitFromRequest() {
assert(req->validPaddr);
setAddr(req->paddr);
assert(req->validSize);
setSize(req->size);
addr = req->paddr;
size = req->size;
addrSizeValid = true;
result = Unknown;
if (dynamicData) {
deleteData();

View file

@ -45,13 +45,12 @@ Port::setPeer(Port *port)
void
Port::blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd)
{
Request req(false);
Request req;
Packet pkt(&req, cmd, Packet::Broadcast);
for (ChunkGenerator gen(addr, size, peerBlockSize());
!gen.done(); gen.next()) {
req.setPaddr(gen.addr());
req.setSize(gen.size());
req.setPhys(gen.addr(), gen.size(), 0);
pkt.reinitFromRequest();
pkt.dataStatic(p);
sendFunctional(&pkt);

View file

@ -61,139 +61,155 @@ const unsigned NO_ALIGN_FAULT = 0x400;
class Request
{
//@todo Make Accesor functions, make these private.
public:
/** Constructor, needs a bool to signify if it is/isn't Cpu Request. */
Request(bool isCpu);
/** reset the request to it's initial state so it can be reused.*/
void resetAll(bool isCpu);
/** reset the request's addrs times, etc, so but not everything to same
* time. */
void resetMin();
//First non-cpu request fields
private:
/** The physical address of the request. */
/**
* The physical address of the request. Valid only if validPaddr
* is set. */
Addr paddr;
/** Wether or not paddr is valid (has been written yet). */
bool validPaddr;
/** The size of the request. */
/**
* The size of the request. This field must be set when vaddr or
* paddr is written via setVirt() or setPhys(), so it is always
* valid as long as one of the address fields is valid. */
int size;
/** Wether or not size is valid (has been written yet). */
bool validSize;
/** The time this request was started. Used to calculate latencies. */
Tick time;
/** Wether or not time is valid (has been written yet). */
bool validTime;
/** Destination address if this is a block copy. */
Addr copyDest;
/** Wether or not copyDest is valid (has been written yet). */
bool validCopyDest;
/** Flag structure for the request. */
uint32_t flags;
//Accsesors for non-cpu request fields
public:
/** Accesor for paddr. */
Addr getPaddr();
/** Accesor for paddr. */
void setPaddr(Addr _paddr);
/** Accesor for size. */
int getSize();
/** Accesor for size. */
void setSize(int _size);
/** Accesor for time. */
Tick getTime();
/** Accesor for time. */
void setTime(Tick _time);
/** Accesor for copy dest. */
Addr getCopyDest();
/** Accesor for copy dest. */
void setCopyDest(Addr _copyDest);
/** Accesor for flags. */
uint32_t getFlags();
/** Accesor for paddr. */
void setFlags(uint32_t _flags);
//Now cpu-request fields
private:
/** Bool to signify if this is a cpuRequest. */
bool cpuReq;
/** The virtual address of the request. */
Addr vaddr;
/** Wether or not the vaddr is valid. */
bool validVaddr;
/**
* The time this request was started. Used to calculate
* latencies. This field is set to curTick any time paddr or vaddr
* is written. */
Tick time;
/** The address space ID. */
int asid;
/** Wether or not the asid is valid. */
bool validAsid;
/** The virtual address of the request. */
Addr vaddr;
/** The return value of store conditional. */
uint64_t scResult;
/** Wether or not the sc result is valid. */
bool validScResult;
/** The cpu number for statistics. */
/** The cpu number (for statistics, typically). */
int cpuNum;
/** Wether or not the cpu number is valid. */
bool validCpuNum;
/** The requesting thread id. */
/** The requesting thread id (for statistics, typically). */
int threadNum;
/** Wether or not the thread id is valid. */
bool validThreadNum;
/** program counter of initiating access; for tracing/debugging */
Addr pc;
/** Wether or not the pc is valid. */
/** Whether or not paddr is valid (has been written yet). */
bool validPaddr;
/** Whether or not the asid & vaddr are valid. */
bool validAsidVaddr;
/** Whether or not the sc result is valid. */
bool validScResult;
/** Whether or not the cpu number & thread ID are valid. */
bool validCpuAndThreadNums;
/** Whether or not the pc is valid. */
bool validPC;
//Accessor Functions for cpu request fields
public:
/** Accesor function to determine if this is a cpu request or not.*/
bool isCpuRequest();
/** Minimal constructor. No fields are initialized. */
Request()
: validPaddr(false), validAsidVaddr(false),
validScResult(false), validCpuAndThreadNums(false), validPC(false)
{}
/** Accesor function for vaddr.*/
Addr getVaddr();
/** Accesor function for vaddr.*/
void setVaddr(Addr _vaddr);
/**
* Constructor for physical (e.g. device) requests. Initializes
* just physical address, size, flags, and timestamp (to curTick).
* These fields are adequate to perform a request. */
Request(Addr _paddr, int _size, int _flags)
: validCpuAndThreadNums(false)
{ setPhys(_paddr, _size, _flags); }
/** Accesor function for asid.*/
int getAsid();
/** Accesor function for asid.*/
void setAsid(int _asid);
/**
* Set up CPU and thread numbers. */
void setThreadContext(int _cpuNum, int _threadNum)
{
cpuNum = _cpuNum;
threadNum = _threadNum;
validCpuAndThreadNums = true;
}
/** Accesor function for store conditional return value.*/
uint64_t getScResult();
/** Accesor function for store conditional return value.*/
void setScResult(uint64_t _scResult);
/**
* Set up a physical (e.g. device) request in a previously
* allocated Request object. */
void setPhys(Addr _paddr, int _size, int _flags)
{
paddr = _paddr;
size = _size;
flags = _flags;
time = curTick;
validPaddr = true;
validAsidVaddr = false;
validPC = false;
validScResult = false;
}
/** Accesor function for cpu number.*/
int getCpuNum();
/** Accesor function for cpu number.*/
void setCpuNum(int _cpuNum);
/**
* Set up a virtual (e.g., CPU) request in a previously
* allocated Request object. */
void setVirt(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc)
{
asid = _asid;
vaddr = _vaddr;
size = _size;
flags = _flags;
pc = _pc;
time = curTick;
validPaddr = false;
validAsidVaddr = true;
validPC = true;
validScResult = false;
}
/** Accesor function for thread number.*/
int getThreadNum();
/** Accesor function for thread number.*/
void setThreadNum(int _threadNum);
/** Set just the physical address. This should only be used to
* record the result of a translation, and thus the vaddr must be
* valid before this method is called. Otherwise, use setPhys()
* to guarantee that the size and flags are also set.
*/
void setPaddr(Addr _paddr)
{
assert(validAsidVaddr);
paddr = _paddr;
validPaddr = true;
}
/** Accesor function for pc.*/
Addr getPC();
/** Accesor function for pc.*/
void setPC(Addr _pc);
/** Accessor for paddr. */
Addr getPaddr() { assert(validPaddr); return paddr; }
/** Accessor for size. */
int getSize() { assert(validPaddr || validAsidVaddr); return size; }
/** Accessor for time. */
Tick getTime() { assert(validPaddr || validAsidVaddr); return time; }
/** Accessor for flags. */
uint32_t getFlags() { assert(validPaddr || validAsidVaddr); return flags; }
/** Accessor for paddr. */
void setFlags(uint32_t _flags)
{ assert(validPaddr || validAsidVaddr); flags = _flags; }
/** Accessor function for vaddr.*/
Addr getVaddr() { assert(validAsidVaddr); return vaddr; }
/** Accessor function for asid.*/
int getAsid() { assert(validAsidVaddr); return asid; }
/** Accessor function for store conditional return value.*/
uint64_t getScResult() { assert(validScResult); return scResult; }
/** Accessor function for store conditional return value.*/
void setScResult(uint64_t _scResult)
{ scResult = _scResult; validScResult = true; }
/** Accessor function for cpu number.*/
int getCpuNum() { assert(validCpuAndThreadNums); return cpuNum; }
/** Accessor function for thread number.*/
int getThreadNum() { assert(validCpuAndThreadNums); return threadNum; }
/** Accessor function for pc.*/
Addr getPC() { assert(validPC); return pc; }
friend class Packet;
};