gem5  v20.1.0.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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 FlashDevice:
AbstractNVM SimObject EventManager Serializable Drainable Stats::Group

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 AbstractNVM
 AbstractNVM (const AbstractNVMParams *p)
 
virtual ~AbstractNVM ()
 
- Public Member Functions inherited from SimObject
const Paramsparams () const
 
 SimObject (const Params *_params)
 
virtual ~SimObject ()
 
virtual const std::string name () const
 
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 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 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 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 Stats::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group. More...
 
virtual ~Group ()
 
virtual void resetStats ()
 Callback to reset stats. More...
 
virtual void preDumpStats ()
 Callback before stats are dumped. More...
 
void addStat (Stats::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...
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 

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...
 
void regStats () override
 Stats register function. 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 SimObject
typedef SimObjectParams Params
 
- Static Public Member Functions inherited from SimObject
static void serializeAll (CheckpointOut &cp)
 Serialize 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 Public Member Functions inherited from Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section. More...
 
static void serializeAll (const std::string &cpt_dir)
 Serializes all the SimObjects. More...
 
static void unserializeGlobals (CheckpointIn &cp)
 
- Protected Member Functions inherited from 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 SimObject
const SimObjectParams * _params
 Cached copy of the object parameters. More...
 
- Protected Attributes inherited from 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 54 of file flash_device.hh.

Member Enumeration Documentation

◆ Actions

enum FlashDevice::Actions
private

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 71 of file flash_device.hh.

Constructor & Destructor Documentation

◆ FlashDevice()

FlashDevice::FlashDevice ( const FlashDeviceParams *  p)

Initialize functions.

Flash Device constructor and destructor.

Definition at line 73 of file flash_device.cc.

References actionComplete().

◆ ~FlashDevice()

FlashDevice::~FlashDevice ( )

Definition at line 152 of file flash_device.cc.

References DPRINTF.

Member Function Documentation

◆ accessDevice()

void 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 163 of file flash_device.cc.

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

Referenced by readMemory(), and writeMemory().

◆ accessTimes()

Tick 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 402 of file flash_device.cc.

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

Referenced by accessDevice(), and remap().

◆ actionComplete()

void 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 288 of file flash_device.cc.

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

Referenced by FlashDevice().

◆ checkDrain()

void FlashDevice::checkDrain ( )

Checkdrain; needed to enable checkpoints.

Definition at line 582 of file flash_device.cc.

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

Referenced by actionComplete().

◆ clearUnknownPages()

void 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 452 of file flash_device.cc.

References MipsISA::index, and unknownPages.

Referenced by accessDevice().

◆ drain()

DrainState FlashDevice::drain ( )
overridevirtual

Checkpoint functions.

Drain; needed to enable checkpoints.

Implements Drainable.

Definition at line 566 of file flash_device.cc.

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

◆ getUnknownPages()

bool FlashDevice::getUnknownPages ( uint32_t  index)
inlineprivate

Function to test if a page is known.

getUnknownPages.

Verify wether a page is known

Definition at line 463 of file flash_device.cc.

References MipsISA::index, and unknownPages.

Referenced by accessDevice().

◆ initializeFlash()

void 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 110 of file flash_device.cc.

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

Referenced by initializeMemory().

◆ initializeMemory()

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

Device access functions Inherrited from AbstractNVM.

Implements AbstractNVM.

Definition at line 109 of file flash_device.hh.

References initializeFlash().

◆ readMemory()

void 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 AbstractNVM.

Definition at line 115 of file flash_device.hh.

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

◆ regStats()

void FlashDevice::regStats ( )
overrideprivatevirtual

◆ remap()

Tick 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 349 of file flash_device.cc.

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

Referenced by accessDevice().

◆ serialize()

void FlashDevice::serialize ( CheckpointOut cp) const
overridevirtual

Serialize; needed to create checkpoints.

Implements Serializable.

Definition at line 519 of file flash_device.cc.

References blockEmptyEntries, blockValidEntries, X86ISA::count, csprintf(), locationTable, paramOut(), planeMask, SERIALIZE_CONTAINER, SERIALIZE_SCALAR, and unknownPages.

◆ unserialize()

void FlashDevice::unserialize ( CheckpointIn cp)
overridevirtual

Unserialize; needed to restore from checkpoints.

Implements Serializable.

Definition at line 542 of file flash_device.cc.

References blockEmptyEntries, blockValidEntries, X86ISA::count, csprintf(), locationTable, paramIn(), planeMask, unknownPages, UNSERIALIZE_CONTAINER, and UNSERIALIZE_SCALAR.

◆ writeMemory()

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

Implements AbstractNVM.

Definition at line 122 of file flash_device.hh.

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

Member Data Documentation

◆ blockEmptyEntries

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

number of empty entries

Definition at line 190 of file flash_device.hh.

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

◆ blockSize

const uint32_t FlashDevice::blockSize
private

Definition at line 155 of file flash_device.hh.

Referenced by initializeFlash().

◆ blocksPerDisk

uint32_t FlashDevice::blocksPerDisk
private

Definition at line 176 of file flash_device.hh.

Referenced by initializeFlash().

◆ blockValidEntries

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

number of valid entries per block

Definition at line 188 of file flash_device.hh.

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

◆ dataDistribution

const Enums::DataDistribution FlashDevice::dataDistribution
private

Flash organization.

Definition at line 167 of file flash_device.hh.

Referenced by initializeFlash().

◆ diskSize

uint64_t FlashDevice::diskSize
private

Disk sizes in bytes.

Definition at line 154 of file flash_device.hh.

Referenced by initializeFlash().

◆ eraseLatency

const Tick FlashDevice::eraseLatency
private

Definition at line 164 of file flash_device.hh.

Referenced by accessTimes().

◆ GCActivePercentage

const uint32_t FlashDevice::GCActivePercentage
private

Garbage collection algorithm emulator.

Definition at line 159 of file flash_device.hh.

Referenced by remap().

◆ locationTable

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

address to logic place has a block and a page field

Definition at line 186 of file flash_device.hh.

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

◆ numPlanes

const uint32_t FlashDevice::numPlanes
private

Definition at line 168 of file flash_device.hh.

Referenced by accessDevice(), and actionComplete().

◆ pageSize

const uint32_t FlashDevice::pageSize
private

Definition at line 156 of file flash_device.hh.

Referenced by accessDevice(), and initializeFlash().

◆ pagesPerBlock

uint32_t FlashDevice::pagesPerBlock
private

Disk dimensions in pages and blocks.

Definition at line 174 of file flash_device.hh.

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

◆ pagesPerDisk

uint32_t FlashDevice::pagesPerDisk
private

Definition at line 175 of file flash_device.hh.

Referenced by initializeFlash(), and remap().

◆ planeEvent

EventFunctionWrapper FlashDevice::planeEvent
private

Completion event.

Definition at line 196 of file flash_device.hh.

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

◆ planeEventQueue

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

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

Definition at line 193 of file flash_device.hh.

Referenced by accessDevice(), and actionComplete().

◆ planeMask

uint32_t FlashDevice::planeMask
private

Definition at line 178 of file flash_device.hh.

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

◆ readLatency

const Tick FlashDevice::readLatency
private

Access latencies.

Definition at line 162 of file flash_device.hh.

Referenced by accessTimes().

◆ stats

struct FlashDeviceStats FlashDevice::stats
private

RequestHandler stats.

Definition at line 171 of file flash_device.hh.

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

◆ unknownPages

std::vector<uint32_t> 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 184 of file flash_device.hh.

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

◆ writeLatency

const Tick FlashDevice::writeLatency
private

Definition at line 163 of file flash_device.hh.

Referenced by accessTimes().


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

Generated on Wed Sep 30 2020 14:02:24 for gem5 by doxygen 1.8.17