gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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

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 resetStats ()
 Reset statistics associated with this object. 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 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
 EventManager (EventManager &em)
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
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)
 
void setCurTick (Tick newVal)
 
- 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...
 

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, Callback *event) override
 Access functions Access function to simulate a read/write access to the memory. More...
 
void writeMemory (uint64_t address, uint32_t amount, Callback *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, Callback *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...
 
EventWrapper< FlashDevice,&FlashDevice::actionCompleteplaneEvent
 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 ()
 Get the fully-qualified name of the active section. More...
 
static void serializeAll (const std::string &cpt_dir)
 
static void unserializeGlobals (CheckpointIn &cp)
 
- Static Public Attributes inherited from Serializable
static int ckptCount = 0
 
static int ckptMaxCount = 0
 
static int ckptPrevCount = -1
 
- 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 56 of file flash_device.hh.

Member Enumeration Documentation

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

Constructor & Destructor Documentation

FlashDevice::FlashDevice ( const FlashDeviceParams *  p)

Initialize functions.

Flash Device constructor and destructor.

Definition at line 75 of file flash_device.cc.

References fatal, numPlanes, and planeMask.

FlashDevice::~FlashDevice ( )

Definition at line 154 of file flash_device.cc.

References DPRINTF.

Member Function Documentation

void FlashDevice::accessDevice ( uint64_t  address,
uint32_t  amount,
Callback 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 165 of file flash_device.cc.

References accessTimes(), ActionRead, ActionWrite, blockEmptyEntries, blockValidEntries, clearUnknownPages(), X86ISA::count, curTick(), DPRINTF, MipsISA::event, FlashDevice::FlashDeviceStats::fileSystemAccess, FlashDevice::CallBackEntry::function, 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(), X86ISA::size(), stats, FlashDevice::CallBackEntry::time, Event::when(), FlashDevice::FlashDeviceStats::writeAccess, and FlashDevice::FlashDeviceStats::writeLatency.

Referenced by readMemory(), and writeMemory().

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

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

Referenced by accessDevice(), and remap().

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

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

void FlashDevice::checkDrain ( )

Checkdrain; needed to enable checkpoints.

Definition at line 586 of file flash_device.cc.

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

Referenced by actionComplete().

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

References unknownPages.

Referenced by accessDevice().

DrainState FlashDevice::drain ( )
overridevirtual

Checkpoint functions.

Drain; needed to enable checkpoints.

Implements Drainable.

Definition at line 570 of file flash_device.cc.

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

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

References unknownPages.

Referenced by accessDevice().

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

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

Referenced by initializeMemory().

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

Device access functions Inherrited from AbstractNVM.

Implements AbstractNVM.

Definition at line 110 of file flash_device.hh.

References initializeFlash().

void FlashDevice::readMemory ( uint64_t  address,
uint32_t  amount,
Callback 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(), and ActionRead.

void FlashDevice::regStats ( )
overrideprivatevirtual
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 353 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().

void FlashDevice::serialize ( CheckpointOut cp) const
overridevirtual

Serialize; needed to create checkpoints.

Implements Serializable.

Definition at line 523 of file flash_device.cc.

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

void FlashDevice::unserialize ( CheckpointIn cp)
overridevirtual

Unserialize; needed to restore from checkpoints.

Implements Serializable.

Definition at line 546 of file flash_device.cc.

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

void FlashDevice::writeMemory ( uint64_t  address,
uint32_t  amount,
Callback event 
)
inlineoverrideprivatevirtual

Implements AbstractNVM.

Definition at line 121 of file flash_device.hh.

References accessDevice(), and ActionWrite.

Member Data Documentation

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

number of empty entries

Definition at line 189 of file flash_device.hh.

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

const uint32_t FlashDevice::blockSize
private

Definition at line 154 of file flash_device.hh.

Referenced by initializeFlash().

uint32_t FlashDevice::blocksPerDisk
private

Definition at line 175 of file flash_device.hh.

Referenced by initializeFlash().

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

number of valid entries per block

Definition at line 187 of file flash_device.hh.

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

const Enums::DataDistribution FlashDevice::dataDistribution
private

Flash organization.

Definition at line 166 of file flash_device.hh.

Referenced by initializeFlash().

uint64_t FlashDevice::diskSize
private

Disk sizes in bytes.

Definition at line 153 of file flash_device.hh.

Referenced by initializeFlash().

const Tick FlashDevice::eraseLatency
private

Definition at line 163 of file flash_device.hh.

Referenced by accessTimes().

const uint32_t FlashDevice::GCActivePercentage
private

Garbage collection algorithm emulator.

Definition at line 158 of file flash_device.hh.

Referenced by remap().

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

address to logic place has a block and a page field

Definition at line 185 of file flash_device.hh.

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

const uint32_t FlashDevice::numPlanes
private

Definition at line 167 of file flash_device.hh.

Referenced by accessDevice(), actionComplete(), and FlashDevice().

const uint32_t FlashDevice::pageSize
private

Definition at line 155 of file flash_device.hh.

Referenced by accessDevice(), and initializeFlash().

uint32_t FlashDevice::pagesPerBlock
private

Disk dimensions in pages and blocks.

Definition at line 173 of file flash_device.hh.

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

uint32_t FlashDevice::pagesPerDisk
private

Definition at line 174 of file flash_device.hh.

Referenced by initializeFlash(), and remap().

EventWrapper<FlashDevice, &FlashDevice::actionComplete> FlashDevice::planeEvent
private

Completion event.

Definition at line 195 of file flash_device.hh.

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

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

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

Definition at line 192 of file flash_device.hh.

Referenced by accessDevice(), and actionComplete().

uint32_t FlashDevice::planeMask
private

Definition at line 177 of file flash_device.hh.

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

const Tick FlashDevice::readLatency
private

Access latencies.

Definition at line 161 of file flash_device.hh.

Referenced by accessTimes().

struct FlashDeviceStats FlashDevice::stats
private

RequestHandler stats.

Definition at line 170 of file flash_device.hh.

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

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

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

const Tick FlashDevice::writeLatency
private

Definition at line 162 of file flash_device.hh.

Referenced by accessTimes().


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

Generated on Fri Jun 9 2017 13:04:10 for gem5 by doxygen 1.8.6