void testcreate() { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; SDF_boolean_t bEntryCreated; for (int blockNum = 0; blockNum < numBlocks; blockNum++) { local_key_t *lkey = get_local_block_key(blockNum); DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey, &bEntryCreated); plat_assert_always(SDF_TRUE == bEntryCreated && NULL != entry); // {{ fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ fthThread_t *top = reqq_peek(entry->q); plat_assert_always(top == fthSelf()); fthThread_t *self = reqq_dequeue(entry->q); plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); // UNLOCK REQQ // }} if (bEntryCreated) { free_local_key(lkey); // HomeDir_get_create makes a copy if created via LinkedDirList_put } } printf("Thread 1: Created %d blocks in the directory\n", numBlocks); }
void testremove() { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; for (int blockNum = 0; blockNum < numBlocks; blockNum++) { local_key_t *lkey = get_local_block_key(blockNum); DirEntry *entry = HomeDir_remove(homedir, cguid, ctype, lkey); // {{ plat_assert_always(entry); fthThread_t *top = reqq_peek(entry->q); if (top) plat_assert_always(top == fthSelf()); fthWaitEl_t *wait = reqq_lock(entry->q); fthThread_t *self = reqq_dequeue(entry->q); if (self) plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); reqq_destroy(entry->q); plat_assert_always(NULL == entry->home); plat_free(entry); // }} free_local_key(lkey); } printf("Thread 1: Removed %d blocks from the directory\n", numBlocks); }
void testget() { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; for (int blockNum = 0; blockNum < numBlocks*2; blockNum++) { local_key_t *lkey = get_local_block_key(blockNum); DirEntry *entry = HomeDir_get(homedir, cguid, ctype, lkey); // {{ if (blockNum < numBlocks) { plat_assert_always(entry); fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ fthThread_t *top = reqq_peek(entry->q); plat_assert_always(top == fthSelf()); fthThread_t *self = reqq_dequeue(entry->q); plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); // UNLOCK REQQ if (NULL != (top = reqq_peek(entry->q))) { fthResume(top, 0); printf("Thread 1: yielding after setting thread 2 to run for block=%u\n", blockNum); fthYield(1); } } // }} free_local_key(lkey); } printf("Thread 1: Got %d blocks from the directory\n", numBlocks); }
void testRoutine2(uint64_t arg) { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; int blockNum; SDF_boolean_t bEntryCreated; for (blockNum = 0; blockNum < numBlocks; blockNum++) { local_key_t *lkey = get_local_block_key(blockNum); DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey, &bEntryCreated); // {{ fthThread_t *top = reqq_peek(entry->q); if (top != fthSelf()) { fthWaitEl_t *wait = reqq_lock(entry->q); uint16_t sz = reqq_enqueue(entry->q, fthSelf()); reqq_unlock(entry->q, wait); printf("Thread 2: Size of request queue when second thread added itself = %u.\n", sz); if (sz > 1) { printf("Thread 2: going to wait\n"); fthWait(); printf("Thread 2: resumed after wait\n"); fthWaitEl_t *wait = reqq_lock(entry->q); fthThread_t *top = reqq_peek(entry->q); if (top == fthSelf()) { fthThread_t *self = reqq_dequeue(entry->q); plat_assert_always(self == top); } reqq_unlock(entry->q, wait); } } // }} } }
void testget(uint64_t seq) { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; for (int i = 0; i < niterator; i++) { local_key_t *lkey = get_local_block_key(0); DirEntry *entry = HomeDir_get(homedir, cguid, ctype, lkey); if (entry == NULL) { (void) __sync_fetch_and_add(&nmisses, 1); printf("Miss\n"); continue; } else { (void) __sync_fetch_and_add(&ngets, 1); (void) __sync_fetch_and_add(&nhits, 1); } // {{ /*if (blockNum < numBlocks) {*/ fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ fthThread_t *top = reqq_peek(entry->q); plat_assert_always(top != 0); // plat_assert_always(top == fthSelf()); fthThread_t *self = reqq_dequeue(entry->q); plat_assert_always(self != 0); // plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); // UNLOCK REQQ /* if (NULL != (top = reqq_peek(entry->q))) { fthResume(top, 0); printf( "Thread 1: yielding after setting thread 2 to run for block=%u\n", blockNum); fthYield(1); }*/ //} // }} free_local_key(lkey); } }
void testcreate(uint64_t seq) { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; SDF_boolean_t bEntryCreated; for (int i = 0; i < niterator; i++) { local_key_t *lkey = get_local_block_key(0); DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey, &bEntryCreated); if (SDF_TRUE == bEntryCreated) { printf("fth %d create block\n", seq); fflush(stdout); //record actions (void) __sync_fetch_and_add(&nputs, 1); } else { (void) __sync_fetch_and_add(&ngets, 1); (void) __sync_fetch_and_add(&nhits, 1); } plat_assert_always(entry != NULL); // {{ fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ fthThread_t *top = reqq_peek(entry->q); plat_assert_always(top != 0); // plat_assert_always(top == fthSelf()); fthThread_t *self = reqq_dequeue(entry->q); plat_assert_always(self != 0); // plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); // UNLOCK REQQ // }} if (bEntryCreated) { free_local_key(lkey); // HomeDir_get_create makes a copy if created via LinkedDirList_put } } }
void testremove(uint64_t seq) { uint64_t cguid = 1; SDF_container_type_t ctype = SDF_BLOCK_CONTAINER; for (int i = 0; i < niterator; i++) { local_key_t *lkey = get_local_block_key(0); DirEntry *entry = HomeDir_remove(homedir, cguid, ctype, lkey); if (entry) { printf("fth %d remove block\n", seq); fflush(stdout); (void)__sync_fetch_and_add(&nremoves, 1); } else { free_local_key(lkey); continue; } // {{ plat_assert_always(entry); fthThread_t *top = reqq_peek(entry->q); if (top) plat_assert_always(top == fthSelf()); fthWaitEl_t *wait = reqq_lock(entry->q); fthThread_t *self = reqq_dequeue(entry->q); if (self) plat_assert_always(self == fthSelf()); reqq_unlock(entry->q, wait); reqq_destroy(entry->q); plat_assert_always(NULL == entry->home); plat_free(entry); // }} free_local_key(lkey); } }