我正在运行一个简单的测试来确定两个碎片整理操作对我们系统的性能影响,并注意到在一定数量的执行周期后,任何一个碎片整理功能的执行都开始在执行时间上出现大的(并且不断增长的)峰值。此外,即使在峰值出现之前,执行时间也呈上升趋势。
我已经尝试过写入内存的测试文件的大小,在执行碎片整理之前允许建立的过时扇区的数量,以及部分碎片整理的最大块数不同,但趋势是每次都类似。
我们将 S25FL256SAIF00(密度 256 Mb,统一 256 个 64 KB 扇区)与 MPLAB Harmony v3 PLIB 库一起使用。
知道是否存在已知问题吗?还是在设置测试时我可能会遗漏一些东西?
我的代码:
//Number of obsolete sectors
ULONG obsoleteSectors = nor_flash.lx_nor_flash_obsolete_physical_sectors;
recordBuffer[recordNumber][sequenceNumber] = (uint32_t)obsoleteSectors;
recordNumber++;
//Initialize timer value
executionStartTicks = (uint32_t) tx_time_get();
//01 - Create a file called TEST.TXT in the root directory.
startTicks = (uint32_t) tx_time_get();
status = fx_file_create(m_NV_DATA_p_mediaPtr, "TEST.TXT");
endTicks = (uint32_t) tx_time_get();
fileCreateTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileCreateTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
//Check for an already created status. This is expected on the second pass of this loop!
if (status != FX_ALREADY_CREATED)
{
break;
}
}
//02 - Open the test file.
startTicks = (uint32_t) tx_time_get();
status = fx_file_open(m_NV_DATA_p_mediaPtr, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
endTicks = (uint32_t) tx_time_get();
fileOpenTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileOpenTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//03 - Seek to the beginning of the test file.
startTicks = (uint32_t) tx_time_get();
status = fx_file_seek(&my_file, 0);
endTicks = (uint32_t) tx_time_get();
fileWriteSeekTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileWriteSeekTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//04 - Write a string to the test file.
startTicks = (uint32_t) tx_time_get();
for( uint32_t data = 0; data < FILE_WRITE_SIZE_LONG_WORDS; data++ )
{
status = fx_file_write(&my_file, &data, sizeof( data ) );
if (status != FX_SUCCESS)
{
break;
}
}
endTicks = (uint32_t) tx_time_get();
fileWriteTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileWriteTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//05 - Seek to the beginning of the test file.
startTicks = (uint32_t) tx_time_get();
status = fx_file_seek(&my_file, 0);
endTicks = (uint32_t) tx_time_get();
fileReadSeekTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileReadSeekTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//06 - Read the test file.
startTicks = (uint32_t) tx_time_get();
status = fx_file_read(&my_file, local_buffer, FILE_WRITE_SIZE_BYTES, &actual);
endTicks = (uint32_t) tx_time_get();
fileReadTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileReadTimeTicks;
recordNumber++;
if ((status != FX_SUCCESS) || (actual != FILE_WRITE_SIZE_BYTES ))
{
break;
}
//07 - Check the contents
for( uint32_t data = 0; data < FILE_WRITE_SIZE_LONG_WORDS; data++ )
{
if ( local_buffer[data] != data )
{
//Error reading back file file, break the loop.
status = 1;
break;
}
}
//08 - Close the test file.
startTicks = (uint32_t) tx_time_get();
status = fx_file_close(&my_file);
endTicks = (uint32_t) tx_time_get();
fileCloseTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileCloseTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//09 - Delete the file
startTicks = (uint32_t) tx_time_get();
status = fx_file_delete(m_NV_DATA_p_mediaPtr, "TEST.TXT");
endTicks = (uint32_t) tx_time_get();
fileDeleteTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = fileDeleteTimeTicks;
recordNumber++;
if (status != FX_SUCCESS)
{
break;
}
//10 - Defragment
bool defragOn = true;
startTicks = (uint32_t) tx_time_get();
endTicks = (uint32_t) tx_time_get();
//if( obsoleteSectors > 4500 && defragOn)
//if( (runCount%defragTrigger) == 0 && defragOn)
//if(defragCount%defragTrigger == 0)
if( obsoleteSectors >= 128 && defragOn)
{
//status = lx_nor_flash_defragment( &nor_flash );
status = lx_nor_flash_partial_defragment(&nor_flash, 128);
endTicks = (uint32_t) tx_time_get();
//defragCount++;
defragCount = 0;
if(defragCount%1 == 0)
{
defragTrigger=defragTrigger+1;
}
}
defragCount++;
levelxDefragmentTimeTicks = endTicks - startTicks;
recordBuffer[recordNumber][sequenceNumber] = levelxDefragmentTimeTicks;
recordNumber++;
if (status != LX_SUCCESS)
{
break;
}
//11 - Total execution time
executionEndTicks = (uint32_t) tx_time_get();
executionTimeTicks = executionEndTicks - executionStartTicks;
recordBuffer[recordNumber][sequenceNumber] = executionTimeTicks;
recordNumber++;