Changeset 35671 in vbox
- Timestamp:
- Jan 21, 2011 8:20:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/tstVDIo.cpp
r35664 r35671 1 /* $Id 1 /* $Id$ */ 2 2 /** @file 3 3 * … … 110 110 /** Flag whether the request is outstanding or not. */ 111 111 volatile bool fOutstanding; 112 /** Buffer to use for reads. */ 113 void *pvBufRead; 112 114 } VDIOREQ, *PVDIOREQ; 113 115 … … 126 128 size_t cbBlkIo; 127 129 /** Number of bytes to transfer. */ 128 size_tcbIo;130 uint64_t cbIo; 129 131 /** Chance in percent to get a write. */ 130 132 unsigned uWriteChance; … … 143 145 /** Pointer to the bitmap marking accessed blocks. */ 144 146 uint8_t *pbMapAccessed; 147 /** Number of unaccessed blocks. */ 148 uint32_t cBlocksLeft; 145 149 } Rnd; 146 150 } u; … … 357 361 } 358 362 359 static int tstVDIoTestInit(PVDIOTEST pIoTest, PVDTESTGLOB pGlob, bool fRandomAcc, size_t cbIo,363 static int tstVDIoTestInit(PVDIOTEST pIoTest, PVDTESTGLOB pGlob, bool fRandomAcc, uint64_t cbIo, 360 364 size_t cbBlkSize, uint64_t offStart, uint64_t offEnd, 361 365 unsigned uWriteChance, unsigned uReadChance); … … 562 566 uint64_t NanoTS = RTTimeNanoTS(); 563 567 568 /* Init requests. */ 564 569 for (unsigned i = 0; i < cMaxTasksOutstanding; i++) 570 { 565 571 paIoReq[i].idx = i; 566 567 while (tstVDIoTestRunning(&IoTest)) 572 paIoReq[i].pvBufRead = RTMemAlloc(cbBlkSize); 573 if (!paIoReq[i].pvBufRead) 574 { 575 rc = VERR_NO_MEMORY; 576 break; 577 } 578 } 579 580 while ( tstVDIoTestRunning(&IoTest) 581 && RT_SUCCESS(rc)) 568 582 { 569 583 bool fTasksOutstanding = false; … … 588 602 { 589 603 rc = VDRead(pGlob->pVD, paIoReq[idx].off, paIoReq[idx].DataSeg.pvSeg, paIoReq[idx].cbReq); 590 RTMemFree(paIoReq[idx].DataSeg.pvSeg);591 604 break; 592 605 } … … 613 626 rc = VDAsyncRead(pGlob->pVD, paIoReq[idx].off, paIoReq[idx].cbReq, &paIoReq[idx].SgBuf, 614 627 tstVDIoTestReqComplete, &paIoReq[idx], EventSem); 615 if (rc == VINF_VD_ASYNC_IO_FINISHED)616 RTMemFree(paIoReq[idx].DataSeg.pvSeg);617 628 break; 618 629 } … … 1170 1181 } 1171 1182 1172 static int tstVDIoTestInit(PVDIOTEST pIoTest, PVDTESTGLOB pGlob, bool fRandomAcc, size_t cbIo,1183 static int tstVDIoTestInit(PVDIOTEST pIoTest, PVDTESTGLOB pGlob, bool fRandomAcc, uint64_t cbIo, 1173 1184 size_t cbBlkSize, uint64_t offStart, uint64_t offEnd, 1174 1185 unsigned uWriteChance, unsigned uReadChance) … … 1183 1194 pIoTest->uWriteChance = uWriteChance; 1184 1195 pIoTest->pIoRnd = pGlob->pIoRnd; 1196 1185 1197 if (fRandomAcc) 1186 1198 { 1187 pIoTest->u.Rnd.cBlocks = cbIo / cbBlkSize + ((cbIo % cbBlkSize) ? 1 : 0); 1199 uint64_t cbRange = pIoTest->offEnd < pIoTest->offStart 1200 ? pIoTest->offStart - pIoTest->offEnd 1201 : pIoTest->offEnd - pIoTest->offStart; 1202 1203 pIoTest->u.Rnd.cBlocks = cbRange / cbBlkSize + ((cbRange % cbBlkSize) ? 1 : 0); 1204 pIoTest->u.Rnd.cBlocksLeft = pIoTest->u.Rnd.cBlocks; 1188 1205 pIoTest->u.Rnd.pbMapAccessed = (uint8_t *)RTMemAllocZ(pIoTest->u.Rnd.cBlocks / 8 1189 1206 + ((pIoTest->u.Rnd.cBlocks % 8) … … 1248 1265 { 1249 1266 /* Read */ 1250 pIoReq->DataSeg.pvSeg = RTMemAlloc(pIoReq->cbReq); 1251 if (!pIoReq->DataSeg.pvSeg) 1252 rc = VERR_NO_MEMORY; 1267 pIoReq->DataSeg.pvSeg = pIoReq->pvBufRead; 1253 1268 } 1254 1269 … … 1264 1279 1265 1280 /* In case this is the last request we don't need to search further. */ 1266 if (pIoTest-> cbIo > 0)1281 if (pIoTest->u.Rnd.cBlocksLeft > 1) 1267 1282 { 1268 1283 int idxIo; … … 1285 1300 Assert(idx != -1); 1286 1301 pIoReq->off = idx * pIoTest->cbBlkIo; 1287 ASMBitSet(pIoTest->u.Rnd.pbMapAccessed, idx); 1302 pIoTest->u.Rnd.cBlocksLeft--; 1303 if (!pIoTest->u.Rnd.cBlocksLeft) 1304 { 1305 /* New round, clear everthing. */ 1306 ASMBitClearRange(pIoTest->u.Rnd.pbMapAccessed, 0, pIoTest->u.Rnd.cBlocks); 1307 pIoTest->u.Rnd.cBlocksLeft = pIoTest->u.Rnd.cBlocks; 1308 } 1309 else 1310 ASMBitSet(pIoTest->u.Rnd.pbMapAccessed, idx); 1288 1311 } 1289 1312 else 1290 1313 { 1291 pIoReq->off = pIoTest->u.offNext; 1292 pIoTest->u.offNext = pIoTest->offEnd < pIoTest->offStart 1293 ? RT_MAX(pIoTest->offEnd, pIoTest->u.offNext - pIoTest->cbBlkIo) 1294 : RT_MIN(pIoTest->offEnd, pIoTest->u.offNext + pIoTest->cbBlkIo); 1314 pIoReq->off = pIoTest->u.offNext; 1315 if (pIoTest->offEnd < pIoTest->offStart) 1316 { 1317 pIoTest->u.offNext = pIoTest->u.offNext == 0 1318 ? pIoTest->offEnd - pIoTest->cbBlkIo 1319 : RT_MAX(pIoTest->offEnd, pIoTest->u.offNext - pIoTest->cbBlkIo); 1320 } 1321 else 1322 { 1323 pIoTest->u.offNext = pIoTest->u.offNext + pIoTest->cbBlkIo >= pIoTest->offEnd 1324 ? 0 1325 : RT_MIN(pIoTest->offEnd, pIoTest->u.offNext + pIoTest->cbBlkIo); 1326 } 1295 1327 } 1296 1328 pIoReq->fOutstanding = true;
Note:
See TracChangeset
for help on using the changeset viewer.