Skip to content

Commit

Permalink
Separate out processing from Run to improve profiling clarity
Browse files Browse the repository at this point in the history
Increase counter threshold to 1000000 in FrameworkThread::operator()() to improve performance
  • Loading branch information
phandinhlan committed Jan 12, 2020
1 parent 80399be commit d3eb69a
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 62 deletions.
31 changes: 18 additions & 13 deletions Sim/HostComm/CustomProtocol/CustomProtocolHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,24 @@ void CustomProtocolHal::Run()
{
while (_TransferCommandQueue->empty() == false)
{
TransferCommandDesc& command = _TransferCommandQueue->front();
U8 *buffer = GetBuffer(command.Command, command.SectorIndex);
if (command.Direction == TransferCommandDesc::Direction::In)
{
_BufferHal->Memcpy(command.Buffer, buffer);
}
else
{
_BufferHal->Memcpy(buffer, command.Buffer);
}
ProcessTransferCommand();
}
}

assert(command.Listener != nullptr);
command.Listener->HandleCommandCompleted(command);
_TransferCommandQueue->pop();
void CustomProtocolHal::ProcessTransferCommand()
{
TransferCommandDesc& command = _TransferCommandQueue->front();
U8 *buffer = GetBuffer(command.Command, command.SectorIndex);
if (command.Direction == TransferCommandDesc::Direction::In)
{
_BufferHal->Memcpy(command.Buffer, buffer);
}
else
{
_BufferHal->Memcpy(buffer, command.Buffer);
}

assert(command.Listener != nullptr);
command.Listener->HandleCommandCompleted(command);
_TransferCommandQueue->pop();
}
1 change: 1 addition & 0 deletions Sim/HostComm/CustomProtocol/CustomProtocolHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CustomProtocolHal : public FrameworkThread

private:
U8* GetBuffer(CustomProtocolCommand *command, const U32 &sectorIndex);
void ProcessTransferCommand();

private:
std::unique_ptr<MessageServer<CustomProtocolCommand>> _MessageServer;
Expand Down
91 changes: 48 additions & 43 deletions Sim/Nand/Hal/NandHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,48 +80,53 @@ void NandHal::Run()
{
if (_CommandQueue->empty() == false)
{
CommandDesc& command = _CommandQueue->front();
NandAddress& address = command.Address;

// Set defaut return status is Success
command.CommandStatus = CommandDesc::Status::Success;

switch (command.Operation)
{
case CommandDesc::Op::Read:
{
if (false == ReadPage(address.Channel, address.Device, address.Block, address.Page, command.Buffer))
{
command.CommandStatus = CommandDesc::Status::Uecc;
}
}break;
case CommandDesc::Op::Write:
{
// TODO: Update command status
WritePage(address.Channel, address.Device, address.Block, address.Page, command.Buffer);
}break;
case CommandDesc::Op::Erase:
{
// TODO: Update command status
EraseBlock(address.Channel, address.Device, address.Block);
}break;
case CommandDesc::Op::ReadPartial:
{
if (false == ReadPage(address.Channel, address.Device, address.Block, address.Page, address.Sector, address.SectorCount, command.Buffer))
{
command.CommandStatus = CommandDesc::Status::Uecc;
}
}break;
case CommandDesc::Op::WritePartial:
{
// TODO: Update command status
WritePage(address.Channel, address.Device, address.Block, address.Page, address.Sector, address.SectorCount, command.Buffer);
}break;
}

assert(command.Listener != nullptr);
command.Listener->HandleCommandCompleted(command);

_CommandQueue->pop();
ProcessNandOperation();
}
}

void NandHal::ProcessNandOperation()
{
CommandDesc& command = _CommandQueue->front();
NandAddress& address = command.Address;

// Set defaut return status is Success
command.CommandStatus = CommandDesc::Status::Success;

switch (command.Operation)
{
case CommandDesc::Op::Read:
{
if (false == ReadPage(address.Channel, address.Device, address.Block, address.Page, command.Buffer))
{
command.CommandStatus = CommandDesc::Status::Uecc;
}
}break;
case CommandDesc::Op::Write:
{
// TODO: Update command status
WritePage(address.Channel, address.Device, address.Block, address.Page, command.Buffer);
}break;
case CommandDesc::Op::Erase:
{
// TODO: Update command status
EraseBlock(address.Channel, address.Device, address.Block);
}break;
case CommandDesc::Op::ReadPartial:
{
if (false == ReadPage(address.Channel, address.Device, address.Block, address.Page, address.Sector, address.SectorCount, command.Buffer))
{
command.CommandStatus = CommandDesc::Status::Uecc;
}
}break;
case CommandDesc::Op::WritePartial:
{
// TODO: Update command status
WritePage(address.Channel, address.Device, address.Block, address.Page, address.Sector, address.SectorCount, command.Buffer);
}break;
}

assert(command.Listener != nullptr);
command.Listener->HandleCommandCompleted(command);

_CommandQueue->pop();
}
3 changes: 3 additions & 0 deletions Sim/Nand/Hal/NandHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class NandHal : public FrameworkThread
protected:
virtual void Run() override;

private:
void ProcessNandOperation();

private:
std::shared_ptr<BufferHal> _BufferHal;

Expand Down
3 changes: 2 additions & 1 deletion Sim/SimFrameworkBase/FrameworkThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ void FrameworkThread::operator()()
while (false == quit)
{
++counter;
if (counter == 1000)
if (counter == 1000000)
{
quit = IsStopRequested();
counter = 0;
}

Run();
}
}
Expand Down
15 changes: 10 additions & 5 deletions Sim/SimpleFtl/SimpleFtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ void SimpleFtl::operator()()
{
while (_EventQueue->empty() == false)
{
Event event;
_EventQueue->pop(event);
switch (event.EventType)
{
ProcessEvent();
}
}

void SimpleFtl::ProcessEvent()
{
Event event;
_EventQueue->pop(event);
switch (event.EventType)
{
case Event::Type::CustomProtocolCommand:
{
OnNewCustomProtocolCommand(event.EventParams.CustomProtocolCommand);
Expand All @@ -66,7 +72,6 @@ void SimpleFtl::operator()()
{
assert(0);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Sim/SimpleFtl/SimpleFtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SimpleFtl : public CustomProtocolHal::TransferCommandListener, public Nand
};

private:
void ProcessEvent();
void ReadNextLbas();
void TransferOut(const Buffer &buffer, const NandHal::NandAddress &nandAddress, const U32 &sectorIndex);
void ReadPage(const NandHal::NandAddress &nandAddress, const Buffer &outBuffer, const U32 &descSectorIndex);
Expand Down

0 comments on commit d3eb69a

Please sign in to comment.