儲存庫 vbox 的更動 10790
- 時間撮記:
- 2008-7-21 下午06:43:39 (16 年 以前)
- 位置:
- trunk/src/VBox/Runtime
- 檔案:
-
- 修改 3 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/common/misc/handletablectx.cpp
r10789 r10790 159 159 } 160 160 161 /* insert the table we allocated */ 162 if (pThis->cCur < pThis->cMax) 163 { 164 uint32_t iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES; 161 /* insert the table we allocated. */ 162 uint32_t iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES; 163 if ( iLevel1New < pThis->cLevel1 164 && pThis->cCur < pThis->cMax) 165 { 165 166 pThis->papvLevel1[iLevel1New] = paTable; 166 167 -
trunk/src/VBox/Runtime/common/misc/handletablesimple.cpp
r10789 r10790 158 158 } 159 159 160 /* insert the table we allocated */ 161 if (pThis->cCur < pThis->cMax) 162 { 163 uint32_t iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES; 160 /* insert the table we allocated. */ 161 uint32_t iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES; 162 if ( iLevel1New < pThis->cLevel1 163 && pThis->cCur < pThis->cMax) 164 { 164 165 pThis->papvLevel1[iLevel1New] = paTable; 165 166 -
trunk/src/VBox/Runtime/testcase/tstHandleTable.cpp
r10789 r10790 37 37 #include <iprt/err.h> 38 38 #include <iprt/getopt.h> 39 #include <iprt/mem.h> 40 #include <iprt/alloca.h> 41 #include <iprt/thread.h> 42 #include <iprt/string.h> 39 43 40 44 … … 297 301 } 298 302 303 304 typedef struct TSTHTTEST2ARGS 305 { 306 /** The handle table. */ 307 RTHANDLETABLE hHT; 308 /** The thread handle. */ 309 RTTHREAD hThread; 310 /** Thread index. */ 311 uint32_t iThread; 312 /** the max number of handles the thread should allocate. */ 313 uint32_t cMax; 314 } TSTHTTEST2ARGS, *PTSTHTTEST2ARGS; 315 316 317 static DECLCALLBACK(int) tstHandleTableTest2Thread(RTTHREAD hThread, void *pvUser) 318 { 319 RTHANDLETABLE const hHT = ((PTSTHTTEST2ARGS)pvUser)->hHT; 320 uint32_t const iThread = ((PTSTHTTEST2ARGS)pvUser)->iThread; 321 uint32_t const cMax = ((PTSTHTTEST2ARGS)pvUser)->cMax; 322 uint32_t *pah = (uint32_t *)RTMemAllocZ(sizeof(uint32_t) * cMax); 323 if (!pah) 324 { 325 RTPrintf("tstHandleTable: FAILURE (%d) - failed to allocate %zu bytes\n", __LINE__, sizeof(uint32_t) * cMax); 326 return VERR_NO_MEMORY; 327 } 328 329 /* 330 * Allocate our quota. 331 */ 332 for (uint32_t i = 0; i < cMax; i++) 333 { 334 int rc = RTHandleTableAllocWithCtx(hHT, pvUser, hThread, &pah[i]); 335 if (RT_FAILURE(rc)) 336 { 337 RTPrintf("tstHandleTable: FAILURE (%d) - t=%d i=%d: RTHandleTableAllocWithCtx failed, rc=%Rrc\n", 338 __LINE__, iThread, i, rc); 339 return rc; 340 } 341 } 342 343 /* 344 * Look them up. 345 */ 346 for (uint32_t i = 0; i < cMax; i++) 347 { 348 void *pvObj = RTHandleTableLookupWithCtx(hHT, pah[i], hThread); 349 if (pvObj != pvUser) 350 { 351 RTPrintf("tstHandleTable: FAILURE (%d) - t=%d i=%d: RTHandleTableLookupWithCtx failed, pvObj=%p\n", 352 __LINE__, iThread, i, pvObj); 353 return VERR_INTERNAL_ERROR; 354 } 355 } 356 357 /* 358 * Free them all. 359 */ 360 for (uint32_t i = 0; i < cMax; i++) 361 { 362 void *pvObj = RTHandleTableFreeWithCtx(hHT, pah[i], hThread); 363 if (pvObj != pvUser) 364 { 365 RTPrintf("tstHandleTable: FAILURE (%d) - t=%d i=%d: RTHandleTableFreeWithCtx failed, pvObj=%p\n", 366 __LINE__, iThread, i, pvObj); 367 return VERR_INTERNAL_ERROR; 368 } 369 } 370 371 RTMemFree(pah); 372 return VINF_SUCCESS; 373 } 374 375 static int tstHandleTableTest2(uint32_t uBase, uint32_t cMax, uint32_t cThreads) 376 { 377 /* 378 * Create the table. 379 */ 380 RTPrintf("tstHandleTable: TESTING %u threads: uBase=%u, cMax=%u\n", cThreads, uBase, cMax); 381 RTHANDLETABLE hHT; 382 int rc = RTHandleTableCreateEx(&hHT, RTHANDLETABLE_FLAGS_LOCKED | RTHANDLETABLE_FLAGS_CONTEXT, uBase, cMax, NULL, NULL); 383 if (RT_FAILURE(rc)) 384 { 385 RTPrintf("tstHandleTable: FAILURE - RTHandleTableCreateEx failed, %Rrc!\n", rc); 386 return 1; 387 } 388 /// @todo there must be a race somewhere in the thread code, I keep hitting a duplicate insert id here... 389 // Or perhaps it just barcelona B2 bugs? 390 RTThreadSleep(50); 391 392 /* 393 * Spawn the threads. 394 */ 395 PTSTHTTEST2ARGS paThread = (PTSTHTTEST2ARGS)alloca(sizeof(*paThread) * cThreads); 396 for (uint32_t i = 0; i < cThreads; i++) 397 { 398 paThread[i].hHT = hHT; 399 paThread[i].hThread = NIL_RTTHREAD; 400 paThread[i].iThread = i; 401 paThread[i].cMax = cMax / cThreads; 402 } 403 for (uint32_t i = 0; i < cThreads; i++) 404 { 405 char szName[32]; 406 RTStrPrintf(szName, sizeof(szName), "TEST2-%x/%x", i, cMax); 407 rc = RTThreadCreate(&paThread[i].hThread, tstHandleTableTest2Thread, &paThread[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, szName); 408 if (RT_FAILURE(rc)) 409 { 410 RTPrintf("tstHandleTable: FAILURE - RTThreadCreate failed, %Rrc!\n", rc); 411 g_cErrors++; 412 break; 413 } 414 } 415 416 /* 417 * Wait for them to complete. 418 */ 419 uint32_t cRunning; 420 do /** @todo Remove when RTSemEventWait (linux) has been fixed. */ 421 { 422 if (cRunning != cThreads) 423 RTThreadSleep(10); 424 cRunning = 0; 425 for (uint32_t i = 0; i < cThreads; i++) 426 if (paThread[i].hThread != NIL_RTTHREAD) 427 { 428 rc = RTThreadWait(paThread[i].hThread, RT_INDEFINITE_WAIT, NULL); 429 if (RT_SUCCESS(rc)) 430 paThread[i].hThread = NIL_RTTHREAD; 431 else 432 cRunning++; 433 } 434 } while (cRunning); 435 436 /* 437 * Destroy the handle table. 438 */ 439 rc = RTHandleTableDestroy(hHT, NULL, NULL); 440 if (RT_FAILURE(rc)) 441 { 442 RTPrintf("tstHandleTable: FAILURE (%d) - RTHandleTableDestroy failed, %Rrc!\n", __LINE__, rc); 443 g_cErrors++; 444 } 445 446 return 0; 447 } 448 449 299 450 int main(int argc, char **argv) 300 451 { … … 308 459 { "--base", 'b', RTGETOPT_REQ_UINT32 }, 309 460 { "--max", 'm', RTGETOPT_REQ_UINT32 }, 461 { "--threads", 't', RTGETOPT_REQ_UINT32 }, 462 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 463 { "--?", '?', RTGETOPT_REQ_NOTHING }, 310 464 }; 311 465 312 uint32_t uBase = 0; 313 uint32_t cMax = 0; 466 uint32_t uBase = 0; 467 uint32_t cMax = 0; 468 uint32_t cThreads = 0; 314 469 315 470 int ch; … … 327 482 break; 328 483 484 case 't': 485 cThreads = Value.u32; 486 if (!cThreads) 487 cThreads = 1; 488 break; 489 329 490 case '?': 330 491 case 'h': 331 RTPrintf("syntax: tst IntNet-1 [-pSt] [-d <secs>] [-f <file>] [-r <size>] [-s <size>]\n");492 RTPrintf("syntax: tstHandleTable [-b <base>] [-m <max>] [-t <threads>]\n"); 332 493 return 1; 333 494 … … 346 507 347 508 /* 348 * Do a simple warmup / smoke test first. 349 */ 350 tstHandleTableTest1(1, 65534, 128, 2048, false, 0); 351 tstHandleTableTest1(1, 65534, 128, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT); 352 tstHandleTableTest1(1, 65534, 63, 2048, false, RTHANDLETABLE_FLAGS_LOCKED); 353 tstHandleTableTest1(1, 65534, 63, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 354 /* Test that the retain and delete functions work. */ 355 tstHandleTableTest1(1, 1024, 256, 256, true, RTHANDLETABLE_FLAGS_LOCKED); 356 tstHandleTableTest1(1, 1024, 256, 256, true, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 357 /* check that the base works. */ 358 tstHandleTableTest1(0x7ffff000, 65534, 4, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 359 tstHandleTableTest1(0xeffff000, 65534, 4, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 360 tstHandleTableTest1(0, 4097, 4, 256, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 361 tstHandleTableTest1(0, 1024, 4, 128, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 362 /* For testing 1st level expansion / reallocation. */ 363 tstHandleTableTest1(1, 1024*1024*8, 3, 150000, false, 0); 364 tstHandleTableTest1(1, 1024*1024*8, 3, 150000, false, RTHANDLETABLE_FLAGS_CONTEXT); 365 366 /* 367 * Threaded tests. 368 */ 369 /** @todo threaded test for checking out the locking and expansion races. */ 509 * If any argument was specified, run the requested test setup. 510 * Otherwise run a bunch of default tests. 511 */ 512 if (cThreads || cMax || uBase) 513 { 514 if (!cMax) 515 cMax = 65535; 516 if (!cThreads) 517 tstHandleTableTest1(uBase, cMax, 128, cMax / 32, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 518 else 519 tstHandleTableTest2(uBase, cMax, 128); 520 } 521 else 522 { 523 /* 524 * Do a simple warmup / smoke test first. 525 */ 526 #if 0 527 tstHandleTableTest1(1, 65534, 128, 2048, false, 0); 528 tstHandleTableTest1(1, 65534, 128, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT); 529 tstHandleTableTest1(1, 65534, 63, 2048, false, RTHANDLETABLE_FLAGS_LOCKED); 530 tstHandleTableTest1(1, 65534, 63, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 531 /* Test that the retain and delete functions work. */ 532 tstHandleTableTest1(1, 1024, 256, 256, true, RTHANDLETABLE_FLAGS_LOCKED); 533 tstHandleTableTest1(1, 1024, 256, 256, true, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 534 /* check that the base works. */ 535 tstHandleTableTest1(0x7ffff000, 65534, 4, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 536 tstHandleTableTest1(0xeffff000, 65534, 4, 2048, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 537 tstHandleTableTest1(0, 4097, 4, 256, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 538 tstHandleTableTest1(0, 1024, 4, 128, false, RTHANDLETABLE_FLAGS_CONTEXT | RTHANDLETABLE_FLAGS_LOCKED); 539 /* For testing 1st level expansion / reallocation. */ 540 tstHandleTableTest1(1, 1024*1024*8, 3, 150000, false, 0); 541 #endif 542 tstHandleTableTest1(1, 1024*1024*8, 3, 150000, false, RTHANDLETABLE_FLAGS_CONTEXT); 543 544 /* 545 * Threaded tests. 546 */ 547 tstHandleTableTest2(0x80000000, 32768, 2); 548 tstHandleTableTest2(0x00010000, 2048, 4); 549 tstHandleTableTest2(0x00010000, 3072, 8); 550 tstHandleTableTest2(0x00000000, 1024*1024*8, 3); 551 } 370 552 371 553 /*
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器