📄 perform.c
字号:
OpStartTime = time_now (); /* for next iteration */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, StartTime); /* display results */ DeltaTime /= TicksPerMS; STTBX_Print (("%6u ms\n", DeltaTime)); LongestTime /= TicksPerMS; STTBX_Print (("\t longest single write %4u ms" " (equivalent %4u ms/1000 bytes)\n", LongestTime, ((LongestTime * 1000) / BlockSize) ));}/******************************************************************************Function Name : Pause Description : Performance tests for alternate read and write (for a cyclic file, thus mimicing 'pause mode' operation) Parameters :******************************************************************************/static TestResult_t Pause(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandle; STAVFS_FileHandle_t FileHandle; /* Use partition 2 throughout (2 sectors per cluster) */ const int Partition = 2; U64 FileSize; U32 FileBytes = 10 * M_BYTES; if (TEST_PASSED != OpenPartition (0, Partition, DEV_NAME, &DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } else { /* Create the file */ I64_SetValue (FileBytes, 0, FileSize); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, STAVFS_CYCLIC_MODE | STAVFS_WRITE_MODE | STAVFS_READ_MODE, FileSize, &FileHandle)) { EXTRA_Print (("Couldn't create %u MB cyclic file on partition %i\n", FileBytes / M_BYTES, Partition)); Result = TEST_FAILED; } else { STTBX_Print (("\n\tAlternately reading and writing %u MB" "\n\tcyclic file on %i sector(s) per cluster:\n", FileBytes / M_BYTES, TestPartitionDefs[Partition].SizeOfCluster)); PauseInner (FileHandle, FileBytes, &Result); /* Close and delete the file */ if (ST_NO_ERROR != STAVFS_CloseFile(FileHandle)) { EXTRA_Print (("Couldn't close file on partition %i\n", Partition)); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { EXTRA_Print (("Couldn't delete file on partition %i\n", Partition)); Result = TEST_FAILED; } } if (TEST_PASSED != ClosePartition (DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } return (Result);}/******************************************************************************Function Name : PauseInner Description : Inner part of Pause test comprising all the write/read subtests run on a particular file Parameters : file handle, size of file we're working in, place to record test failure******************************************************************************/static void PauseInner(STAVFS_FileHandle_t FileHandle, U32 FileBytes, TestResult_t * Result_p){ static U32 const FillChunkSize = 4 * K_BYTES; static U32 const BlockSizes[] = { 500, 1000, 4000, 64000 }; U32 SizeIdx, TotalChunks, ChunkIdx; U32 DataCnt; /* for STAVFS_WriteFile */ /* absolute time values */ clock_t StartTime, EndTime; /* accumulated total execution times (initialised for each new BlockSize) */ clock_t ReadTime, WriteTime; /* Fill half the file with data, to separate the read and write positions */ assert (FillChunkSize <= sizeof(Buffer)); TotalChunks = FileBytes / (2 * FillChunkSize); for (ChunkIdx = 0; ChunkIdx < TotalChunks; ++ChunkIdx) { if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, Buffer, FillChunkSize, &DataCnt)) { EXTRA_Print (("Couldn't write file (1)\n")); *Result_p = TEST_FAILED; return; /* As usual, caller handles all clean-up */ } } for (SizeIdx = 0; (SizeIdx < TABLE_LEN(BlockSizes)); ++SizeIdx) { /* reset total time spent reading/writing */ ReadTime = WriteTime = 0; assert (BlockSizes[SizeIdx] <= sizeof(Buffer)); TotalChunks = FileBytes / BlockSizes[SizeIdx]; /* cover about a file length */ STTBX_Print (("\t %6u %5u byte chunks:\n", TotalChunks, BlockSizes[SizeIdx])); StartTime = time_now (); for (ChunkIdx = 0; ChunkIdx < TotalChunks; ++ChunkIdx) { if (ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer, BlockSizes[SizeIdx], &DataCnt)) { EXTRA_Print (("Couldn't read file\n")); *Result_p = TEST_FAILED; return; /* As usual, caller handles all clean-up */ } EndTime = time_now (); ReadTime += time_minus (EndTime, StartTime); StartTime = EndTime; /* use old EndTime as new StartTime to ensure ReadTime+WriteTime gives the total time taken */ if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, Buffer, BlockSizes[SizeIdx], &DataCnt)) { EXTRA_Print (("Couldn't write file (2)\n")); *Result_p = TEST_FAILED; return; /* As usual, caller handles all clean-up */ } EndTime = time_now (); WriteTime += time_minus (EndTime, StartTime); StartTime = EndTime; /* for next iteration */ } /* display results */ STTBX_Print (("\t\t\ttotal time reading %6u ms\n", ReadTime / TicksPerMS)); STTBX_Print (("\t\t\ttotal time writing %6u ms\n", WriteTime / TicksPerMS)); }}/******************************************************************************Function Name : RawHAL Description : Benchmark the raw HAL in a way similar to test 3 Parameters :******************************************************************************/static TestResult_t RawHAL(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; /* In sectors, 512 bytes, 1024 bytes, 4096 bytes, 65536 bytes: */ static U32 const BlockSizes[] = { 1, 2, 8, 128 }; static U32 const TotalSize = 20 * 8 * 128; /* large and a common multiple of all the BlockSizes */ stavfs_HAL_t HAL; /* Start the sector after the end of the last partition */ const U32 InitialPos = TestPartitionDefs[3].Position + TestPartitionDefs[3].Size; U64 DiskSize; U32 SizeSoFar; U64 Pos; /* current position wrapped in a U64 for HalRead/Write */ U32 SizeIdx; /* absolute time values */ clock_t StartTime, EndTime; /* time value differences */ clock_t ReadTime, WriteTime; /* Set up HAL layer */ HAL.Initialised = FALSE; HAL.UnitNumber = 0; HAL.Protocol = 1; strcpy (HAL.EVTName, EVT_DEVICE_NAME); strcpy (HAL.ATAPIName, ATAPI_DEVICE_NAME); if (ST_NO_ERROR != stavfs_HalInit (&HAL)) { EXTRA_Print (("Error initialising HAL layer\n")); Result = TEST_FAILED; } else { /* sanity check that the disk is big enough for what we want to do. This is the index for the sector after the last we will use: */ I64_SetValue (InitialPos + TotalSize, 0, Pos); if (ST_NO_ERROR != stavfs_HalDiskSize (&HAL, &DiskSize)) { EXTRA_Print (("Error initialising HAL layer\n")); Result = TEST_FAILED; } else if (I64_IsLessThan( DiskSize, Pos)) { EXTRA_Print (("Disk is too small for test\n")); Result = TEST_FAILED; } for (SizeIdx = 0; (SizeIdx < TABLE_LEN(BlockSizes)) && (Result == TEST_PASSED); ++SizeIdx) { assert (BlockSizes[SizeIdx] * DISK_SECTOR_SIZE <= sizeof(Buffer)); STTBX_Print (("\n\tUsing the raw HAL for %2u MB" " in %5u byte chunks:\n", (TotalSize * DISK_SECTOR_SIZE) / M_BYTES, BlockSizes[SizeIdx] * DISK_SECTOR_SIZE)); /* Write at this chunk size */ StartTime = time_now (); for (SizeSoFar = 0; (SizeSoFar < TotalSize) && (Result == TEST_PASSED); SizeSoFar += BlockSizes[SizeIdx]) { I64_SetValue (InitialPos + SizeSoFar, 0, Pos); if (ST_NO_ERROR != stavfs_HalWrite (&HAL, &Pos, BlockSizes[SizeIdx], (char *) Buffer, FALSE)) { EXTRA_Print (("Error calling stavfs_HalWrite\n")); Result = TEST_FAILED; } } EndTime = time_now (); WriteTime = time_minus (EndTime, StartTime); /* Read at this chunk size */ StartTime = time_now (); for (SizeSoFar = 0; (SizeSoFar < TotalSize) && (Result == TEST_PASSED); SizeSoFar += BlockSizes[SizeIdx]) { I64_SetValue (InitialPos + SizeSoFar, 0, Pos); if (ST_NO_ERROR != stavfs_HalRead (&HAL, &Pos, BlockSizes[SizeIdx], (char *) Buffer, FALSE)) { EXTRA_Print (("Error calling stavfs_HalRead\n")); Result = TEST_FAILED; } } EndTime = time_now (); ReadTime = time_minus (EndTime, StartTime); /* display results if test ran as intended */ if (Result == TEST_PASSED) { STTBX_Print (("\t\treading %6u ms, writing %6u ms\n", ReadTime / TicksPerMS, WriteTime / TicksPerMS)); } } if (ST_NO_ERROR != stavfs_HalTerm (&HAL)) { EXTRA_Print (("Error terminating HAL layer\n")); Result = TEST_FAILED; } } return (Result);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -