gem5  v21.1.0.2
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gem5::FlashDevice Class Reference

Flash Device model The Flash Device model is a timing model for a NAND flash device. More...

#include <flash_device.hh>

Inheritance diagram for gem5::FlashDevice:
gem5::AbstractNVM gem5::SimObject gem5::EventManager gem5::Serializable gem5::Drainable gem5::statistics::Group gem5::Named

Classes

struct  CallBackEntry
 
struct  FlashDeviceStats
 
struct  PageMapEntry
 Every logical address maps to a physical block and a physical page. More...
 

Public Member Functions

 FlashDevice (const FlashDeviceParams &)
 Initialize functions. More...
 
 ~FlashDevice ()
 
DrainState drain () override
 Checkpoint functions. More...
 
void checkDrain ()
 Checkdrain; needed to enable checkpoints. More...
 
void serialize (CheckpointOut &cp) const override
 Serialize; needed to create checkpoints. More...
 
void unserialize (CheckpointIn &cp) override
 Unserialize; needed to restore from checkpoints. More...
 
- Public Member Functions inherited from gem5::AbstractNVM
 AbstractNVM (const AbstractNVMParams &p)
 
virtual ~AbstractNVM ()
 
- Public Member Functions inherited from gem5::SimObject
const Paramsparams () const
 
 SimObject (const Params &p)
 
virtual ~SimObject ()
 
virtual void init ()
 init() is called after all C++ SimObjects have been created and all ports are connected. More...
 
virtual void loadState (CheckpointIn &cp)
 loadState() is called on each SimObject when restoring from a checkpoint. More...
 
virtual void initState ()
 initState() is called on each SimObject when not restoring from a checkpoint. More...
 
virtual void regProbePoints ()
 Register probe points for this object. More...
 
virtual void regProbeListeners ()
 Register probe listeners for this object. More...
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object. More...
 
virtual PortgetPort (const std::string &if_name, PortID idx=InvalidPortID)
 Get a port with a given name and index. More...
 
virtual void startup ()
 startup() is the final initialization call before simulation. More...
 
DrainState drain () override
 Provide a default implementation of the drain interface for objects that don't need draining. More...
 
virtual void memWriteback ()
 Write back dirty buffers to memory using functional writes. More...
 
virtual void memInvalidate ()
 Invalidate the contents of memory buffers. More...
 
void serialize (CheckpointOut &cp) const override
 Serialize an object. More...
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object. More...
 
- Public Member Functions inherited from gem5::EventManager
EventQueueeventQueue () const
 
void schedule (Event &event, Tick when)
 
void deschedule (Event &event)
 
void reschedule (Event &event, Tick when, bool always=false)
 
void schedule (Event *event, Tick when)
 
void deschedule (Event *event)
 
void reschedule (Event *event, Tick when, bool always=false)
 
void wakeupEventQueue (Tick when=(Tick) -1)
 This function is not needed by the usual gem5 event loop but may be necessary in derived EventQueues which host gem5 on other schedulers. More...
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue. More...
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
- Public Member Functions inherited from gem5::Serializable
 Serializable ()
 
virtual ~Serializable ()
 
void serializeSection (CheckpointOut &cp, const char *name) const
 Serialize an object into a new section. More...
 
void serializeSection (CheckpointOut &cp, const std::string &name) const
 
void unserializeSection (CheckpointIn &cp, const char *name)
 Unserialize an a child object. More...
 
void unserializeSection (CheckpointIn &cp, const std::string &name)
 
- Public Member Functions inherited from gem5::Drainable
DrainState drainState () const
 Return the current drain state of an object. More...
 
virtual void notifyFork ()
 Notify a child process of a fork. More...
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group. More...
 
virtual ~Group ()
 
virtual void regStats ()
 Callback to set stat parameters. More...
 
virtual void resetStats ()
 Callback to reset stats. More...
 
virtual void preDumpStats ()
 Callback before stats are dumped. More...
 
void addStat (statistics::Info *info)
 Register a stat with this group. More...
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object. More...
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object. More...
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block. More...
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group. More...
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block. More...
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 
- Public Member Functions inherited from gem5::Named
 Named (const std::string &name_)
 
virtual ~Named ()=default
 
virtual std::string name () const
 

Private Types

enum  Actions { ActionRead, ActionWrite, ActionErase, ActionCopy }
 Defines the possible actions to the flash. More...
 

Private Member Functions

void initializeMemory (uint64_t disk_size, uint32_t sector_size) override
 Device access functions Inherrited from AbstractNVM. More...
 
void readMemory (uint64_t address, uint32_t amount, const std::function< void()> &event) override
 Access functions Access function to simulate a read/write access to the memory. More...
 
void writeMemory (uint64_t address, uint32_t amount, const std::function< void()> &event) override
 
void initializeFlash (uint64_t disk_size, uint32_t sector_size)
 Initialization function; called when all disk specifics are known. More...
 
void accessDevice (uint64_t address, uint32_t amount, const std::function< void()> &event, Actions action)
 Flash action function. More...
 
void actionComplete ()
 Event rescheduler. More...
 
Tick remap (uint64_t logic_page_addr)
 FTL functionality. More...
 
Tick accessTimes (uint64_t address, Actions accesstype)
 Access time calculator. More...
 
void clearUnknownPages (uint32_t index)
 Function to indicate that a page is known. More...
 
bool getUnknownPages (uint32_t index)
 Function to test if a page is known. More...
 

Private Attributes

uint64_t diskSize
 Disk sizes in bytes. More...
 
const uint32_t blockSize
 
const uint32_t pageSize
 
const uint32_t GCActivePercentage
 Garbage collection algorithm emulator. More...
 
const Tick readLatency
 Access latencies. More...
 
const Tick writeLatency
 
const Tick eraseLatency
 
const enums::DataDistribution dataDistribution
 Flash organization. More...
 
const uint32_t numPlanes
 
struct FlashDeviceStats stats
 RequestHandler stats. More...
 
uint32_t pagesPerBlock
 Disk dimensions in pages and blocks. More...
 
uint32_t pagesPerDisk
 
uint32_t blocksPerDisk
 
uint32_t planeMask
 
std::vector< uint32_t > unknownPages
 when the disk is first started we are unsure of the number of used pages, this variable will help determining what we do know. More...
 
std::vector< struct PageMapEntrylocationTable
 address to logic place has a block and a page field More...
 
std::vector< uint32_t > blockValidEntries
 number of valid entries per block More...
 
std::vector< uint32_t > blockEmptyEntries
 number of empty entries More...
 
std::vector< std::deque< struct CallBackEntry > > planeEventQueue
 This vector of queues keeps track of all the callbacks per plane. More...
 
EventFunctionWrapper planeEvent
 Completion event. More...
 

Additional Inherited Members

- Public Types inherited from gem5::SimObject
typedef SimObjectParams Params
 
- Static Public Member Functions inherited from gem5::SimObject
static void serializeAll (const std::string &cpt_dir)
 Create a checkpoint by serializing all SimObjects in the system. More...
 
static SimObjectfind (const char *name)
 Find the SimObject with the given name and return a pointer to it. More...
 
static void setSimObjectResolver (SimObjectResolver *resolver)
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
static SimObjectResolvergetSimObjectResolver ()
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
- Static Public Member Functions inherited from gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section. More...
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it. More...
 
- Protected Member Functions inherited from gem5::Drainable
 Drainable ()
 
virtual ~Drainable ()
 
virtual void drainResume ()
 Resume execution after a successful drain. More...
 
void signalDrainDone () const
 Signal that an object is drained. More...
 
- Protected Attributes inherited from gem5::SimObject
const SimObjectParams & _params
 Cached copy of the object parameters. More...
 
- Protected Attributes inherited from gem5::EventManager
EventQueueeventq
 A pointer to this object's event queue. More...
 

Detailed Description

Flash Device model The Flash Device model is a timing model for a NAND flash device.

It doesn't tranfer any data

Definition at line 57 of file flash_device.hh.

Member Enumeration Documentation

◆ Actions

Defines the possible actions to the flash.

Enumerator
ActionRead 
ActionWrite 
ActionErase 
ActionCopy 

A copy involves taking all the used pages from a block and store it in another.

Definition at line 74 of file flash_device.hh.

Constructor & Destructor Documentation

◆ FlashDevice()

gem5::FlashDevice::FlashDevice ( const FlashDeviceParams &  p)

Initialize functions.

Flash Device constructor and destructor.

Definition at line 65 of file flash_device.cc.

References actionComplete().

◆ ~FlashDevice()

gem5::FlashDevice::~FlashDevice ( )

Definition at line 145 of file flash_device.cc.

References DPRINTF.

Member Function Documentation

◆ accessDevice()

void gem5::FlashDevice::accessDevice ( uint64_t  address,
uint32_t  amount,
const std::function< void()> &  event,
Actions  action 
)
private

Flash action function.

Handles the accesses to the device.

The function determines when certain actions are scheduled and schedules an event that uses the callback function on completion of the action.

The access will be broken up in a number of page accesses. The number of page accesses depends on the amount that needs to be transfered. The assumption here is that the interface is completely ignorant of the page size and that this model has to figure out all of the transaction characteristics.

Check if the page is known and used. unknownPages is a bitmap of all the pages. It tracks wether we can be sure that the information of this page is taken into acount in the model (is it considered in blockValidEntries and blockEmptyEntries?). If it has been used in the past, then it is known.

previous part of the function found the times spend in different planes, now lets find the maximum to know when to callback the disk

If there are no events for this plane, then add the current time to the occupation time; otherwise, plan it after the last event. If by chance that event is handled in this tick, then we would still end up with the same result.

Definition at line 156 of file flash_device.cc.

References accessTimes(), ActionRead, ActionWrite, gem5::QARMA::amount, blockEmptyEntries, blockValidEntries, clearUnknownPages(), gem5::X86ISA::count, gem5::curTick(), DPRINTF, gem5::MipsISA::event, gem5::FlashDevice::FlashDeviceStats::fileSystemAccess, getUnknownPages(), gem5::MipsISA::index, locationTable, numPlanes, pageSize, pagesPerBlock, planeEvent, planeEventQueue, planeMask, gem5::FlashDevice::FlashDeviceStats::readAccess, gem5::FlashDevice::FlashDeviceStats::readLatency, remap(), gem5::EventManager::reschedule(), gem5::statistics::DistBase< Derived, Stor >::sample(), gem5::EventManager::schedule(), gem5::Event::scheduled(), stats, gem5::FlashDevice::CallBackEntry::time, gem5::Event::when(), gem5::FlashDevice::FlashDeviceStats::writeAccess, and gem5::FlashDevice::FlashDeviceStats::writeLatency.

Referenced by readMemory(), and writeMemory().

◆ accessTimes()

Tick gem5::FlashDevice::accessTimes ( uint64_t  address,
Actions  accesstype 
)
private

Access time calculator.

Calculates the accesstime per operation needed.

Just read the page

Write the page, and read the result

Erase and check wether it was successfull

Copy every valid page

Definition at line 395 of file flash_device.cc.

References ActionCopy, ActionErase, ActionRead, ActionWrite, blockValidEntries, DPRINTF, eraseLatency, readLatency, and writeLatency.

Referenced by accessDevice(), and remap().

◆ actionComplete()

void gem5::FlashDevice::actionComplete ( )
private

Event rescheduler.

When a plane completes its action, this event is triggered.

When a callback function was associated with that event, it will be called.

Search for a callback that is supposed to happen in this Tick

Invariant: All queued events are scheduled in the present or future.

To ensure that the follow-up action is executed correctly, the callback entry first need to be cleared before it can be called.

Found a callback, lets make it happen

Find when to schedule the planeEvent next

Schedule the next plane that will be ready (if any)

Definition at line 281 of file flash_device.cc.

References checkDrain(), gem5::curTick(), DPRINTF, numPlanes, planeEvent, planeEventQueue, gem5::EventManager::reschedule(), and gem5::Event::when().

Referenced by FlashDevice().

◆ checkDrain()

void gem5::FlashDevice::checkDrain ( )

Checkdrain; needed to enable checkpoints.

Definition at line 570 of file flash_device.cc.

References gem5::curTick(), DPRINTF, gem5::Draining, gem5::Drainable::drainState(), planeEvent, gem5::Drainable::signalDrainDone(), and gem5::Event::when().

Referenced by actionComplete().

◆ clearUnknownPages()

void gem5::FlashDevice::clearUnknownPages ( uint32_t  index)
inlineprivate

Function to indicate that a page is known.

clearUnknownPages.

defines that a page is known and used unknownPages is a bitmap of all the pages. It tracks wether we can be sure that the information of this page is taken into acount in the model (is it considered in blockValidEntries and blockEmptyEntries?). If it has been used in the past, then it is known. But it needs to be tracked to make decisions about write accesses, and indirectly about copy actions. one unknownPage entry is a 32 bit integer. So if we have a page index, then that means that we need entry floor(index/32) (index >> 5) and we need to select the bit which number is equal to the remainder of index/32 (index%32). The bit is cleared to make sure that we see it as considered in the future.

Definition at line 445 of file flash_device.cc.

References gem5::MipsISA::index, and unknownPages.

Referenced by accessDevice().

◆ drain()

DrainState gem5::FlashDevice::drain ( )
overridevirtual

Checkpoint functions.

Drain; needed to enable checkpoints.

Implements gem5::Drainable.

Definition at line 554 of file flash_device.cc.

References DPRINTF, gem5::Drained, gem5::Draining, planeEvent, and gem5::Event::scheduled().

◆ getUnknownPages()

bool gem5::FlashDevice::getUnknownPages ( uint32_t  index)
inlineprivate

Function to test if a page is known.

getUnknownPages.

Verify wether a page is known

Definition at line 456 of file flash_device.cc.

References gem5::MipsISA::index, and unknownPages.

Referenced by accessDevice().

◆ initializeFlash()

void gem5::FlashDevice::initializeFlash ( uint64_t  disk_size,
uint32_t  sector_size 
)
private

Initialization function; called when all disk specifics are known.

Initiates all the flash functions: initializes the lookup tables, age of the device, etc.

This can only be done once the disk image is known. Thats why it can't be done in the constructor.

Sanity information: check flash configuration

Garbage collection related

This is a bitmap. Every bit is a page unknownPages is a vector of 32 bit integers. If every page was an integer, the total size would be pagesPerDisk; since we can map one page per bit we need ceil(pagesPerDisk/32) entries. 32 = 1 << 5 hence it will do to just shift pagesPerDisk five positions and add one. This will allocate one integer to many for this data structure in the worst case.

Definition at line 103 of file flash_device.cc.

References blockEmptyEntries, blockSize, blocksPerDisk, blockValidEntries, gem5::X86ISA::count, dataDistribution, diskSize, DPRINTF, locationTable, pageSize, pagesPerBlock, pagesPerDisk, and unknownPages.

Referenced by initializeMemory().

◆ initializeMemory()

void gem5::FlashDevice::initializeMemory ( uint64_t  disk_size,
uint32_t  sector_size 
)
inlineoverrideprivatevirtual

Device access functions Inherrited from AbstractNVM.

Implements gem5::AbstractNVM.

Definition at line 118 of file flash_device.hh.

References initializeFlash().

◆ readMemory()

void gem5::FlashDevice::readMemory ( uint64_t  address,
uint32_t  amount,
const std::function< void()> &  event 
)
inlineoverrideprivatevirtual

Access functions Access function to simulate a read/write access to the memory.

Once the action has completed, the Callback event should be called. Putting a NULL pointer as callback is valid syntax, and should result in the simulation of the access, but with no callback to the higher layer. This may be used to occupy the device, such that next actions will be delayed. The read/write function will schedule the incoming requests on a first come first serve basis.

Parameters
addressThe logical address to a location in the Non-volatile memory.
amountThe amount of data transfered from the NVM in bytes
eventA pointer to a callback function that will perform the actions taken by the disk controller on successfull completion of the data transfer between the disk and the disk controller.

Implements gem5::AbstractNVM.

Definition at line 124 of file flash_device.hh.

References accessDevice(), ActionRead, gem5::QARMA::amount, and gem5::MipsISA::event.

◆ remap()

Tick gem5::FlashDevice::remap ( uint64_t  logic_page_addr)
private

FTL functionality.

Handles the remapping of the pages.

It is a (I hope) sensible statistic approach. asumption: garbage collection happens when a clean is needed (may become stochastic function).

Are there any empty left in this Block, or do we need to do an erase

Definition at line 342 of file flash_device.cc.

References accessTimes(), ActionCopy, ActionErase, ActionWrite, blockEmptyEntries, gem5::X86ISA::count, DPRINTF, GCActivePercentage, locationTable, pagesPerBlock, pagesPerDisk, stats, and gem5::FlashDevice::FlashDeviceStats::totalGCActivations.

Referenced by accessDevice().

◆ serialize()

void gem5::FlashDevice::serialize ( CheckpointOut cp) const
overridevirtual

◆ unserialize()

void gem5::FlashDevice::unserialize ( CheckpointIn cp)
overridevirtual

◆ writeMemory()

void gem5::FlashDevice::writeMemory ( uint64_t  address,
uint32_t  amount,
const std::function< void()> &  event 
)
inlineoverrideprivatevirtual

Implements gem5::AbstractNVM.

Definition at line 131 of file flash_device.hh.

References accessDevice(), ActionWrite, gem5::QARMA::amount, and gem5::MipsISA::event.

Member Data Documentation

◆ blockEmptyEntries

std::vector<uint32_t> gem5::FlashDevice::blockEmptyEntries
private

number of empty entries

Definition at line 196 of file flash_device.hh.

Referenced by accessDevice(), initializeFlash(), remap(), serialize(), and unserialize().

◆ blockSize

const uint32_t gem5::FlashDevice::blockSize
private

Definition at line 161 of file flash_device.hh.

Referenced by initializeFlash().

◆ blocksPerDisk

uint32_t gem5::FlashDevice::blocksPerDisk
private

Definition at line 182 of file flash_device.hh.

Referenced by initializeFlash().

◆ blockValidEntries

std::vector<uint32_t> gem5::FlashDevice::blockValidEntries
private

number of valid entries per block

Definition at line 194 of file flash_device.hh.

Referenced by accessDevice(), accessTimes(), initializeFlash(), serialize(), and unserialize().

◆ dataDistribution

const enums::DataDistribution gem5::FlashDevice::dataDistribution
private

Flash organization.

Definition at line 173 of file flash_device.hh.

Referenced by initializeFlash().

◆ diskSize

uint64_t gem5::FlashDevice::diskSize
private

Disk sizes in bytes.

Definition at line 160 of file flash_device.hh.

Referenced by initializeFlash().

◆ eraseLatency

const Tick gem5::FlashDevice::eraseLatency
private

Definition at line 170 of file flash_device.hh.

Referenced by accessTimes().

◆ GCActivePercentage

const uint32_t gem5::FlashDevice::GCActivePercentage
private

Garbage collection algorithm emulator.

Definition at line 165 of file flash_device.hh.

Referenced by remap().

◆ locationTable

std::vector<struct PageMapEntry> gem5::FlashDevice::locationTable
private

address to logic place has a block and a page field

Definition at line 192 of file flash_device.hh.

Referenced by accessDevice(), initializeFlash(), remap(), serialize(), and unserialize().

◆ numPlanes

const uint32_t gem5::FlashDevice::numPlanes
private

Definition at line 174 of file flash_device.hh.

Referenced by accessDevice(), and actionComplete().

◆ pageSize

const uint32_t gem5::FlashDevice::pageSize
private

Definition at line 162 of file flash_device.hh.

Referenced by accessDevice(), and initializeFlash().

◆ pagesPerBlock

uint32_t gem5::FlashDevice::pagesPerBlock
private

Disk dimensions in pages and blocks.

Definition at line 180 of file flash_device.hh.

Referenced by accessDevice(), initializeFlash(), and remap().

◆ pagesPerDisk

uint32_t gem5::FlashDevice::pagesPerDisk
private

Definition at line 181 of file flash_device.hh.

Referenced by initializeFlash(), and remap().

◆ planeEvent

EventFunctionWrapper gem5::FlashDevice::planeEvent
private

Completion event.

Definition at line 202 of file flash_device.hh.

Referenced by accessDevice(), actionComplete(), checkDrain(), and drain().

◆ planeEventQueue

std::vector<std::deque<struct CallBackEntry> > gem5::FlashDevice::planeEventQueue
private

This vector of queues keeps track of all the callbacks per plane.

Definition at line 199 of file flash_device.hh.

Referenced by accessDevice(), and actionComplete().

◆ planeMask

uint32_t gem5::FlashDevice::planeMask
private

Definition at line 184 of file flash_device.hh.

Referenced by accessDevice(), serialize(), and unserialize().

◆ readLatency

const Tick gem5::FlashDevice::readLatency
private

Access latencies.

Definition at line 168 of file flash_device.hh.

Referenced by accessTimes().

◆ stats

struct FlashDeviceStats gem5::FlashDevice::stats
private

RequestHandler stats.

Definition at line 177 of file flash_device.hh.

Referenced by accessDevice(), and remap().

◆ unknownPages

std::vector<uint32_t> gem5::FlashDevice::unknownPages
private

when the disk is first started we are unsure of the number of used pages, this variable will help determining what we do know.

Definition at line 190 of file flash_device.hh.

Referenced by clearUnknownPages(), getUnknownPages(), initializeFlash(), serialize(), and unserialize().

◆ writeLatency

const Tick gem5::FlashDevice::writeLatency
private

Definition at line 169 of file flash_device.hh.

Referenced by accessTimes().


The documentation for this class was generated from the following files:

Generated on Tue Sep 21 2021 12:27:35 for gem5 by doxygen 1.8.17