SDF_boolean_t object_exists(SDF_internal_ctxt_t *pai, SDF_CONTAINER c, SDF_key_t key) { SDF_boolean_t exists = SDF_FALSE; objMetaData_t *metaData = plat_alloc(sizeof(objMetaData_t)); char *fkey = plat_alloc(256); char *name = NULL; name = (char *)ObjectKey_getName(key->object_id); metaData->objFlags = 0; metaData->expTime = 0; metaData->createTime = 0; metaData->keyLen = strlen(name); metaData->dataLen = 0; memcpy(fkey, name, strlen(name)); if (!isContainerNull(c) && key != NULL) { local_SDF_CONTAINER lc = getLocalContainer(&lc, c); local_SDF_CONTAINER_PARENT lparent = getLocalContainerParent(&lparent, lc->parent); // We only need to do the check for object containers if (lparent->container_type == SDF_OBJECT_CONTAINER) { // char buf[size]; struct shard *shard = NULL; if ((shard = get_shard(pai, lc)) == NULL) { exists = SDF_FALSE; plat_log_msg(21597, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "FAILURE: object_exists - failed to get shard"); } else { if (flashGet(shard, metaData, (char *) fkey, NULL)) { exists = SDF_TRUE; } if (fkey != NULL) { plat_free(fkey); } } } releaseLocalContainer(&lc); releaseLocalContainerParent(&lparent); } return (exists); }
SDF_status_t put_object(struct shard *shard, SDF_key_t key, void *pbuf, SDF_size_t size, SDF_operation_t *opid) { SDF_status_t status = SDF_FAILURE; char *data = NULL; objMetaData_t *metaData = plat_alloc(sizeof(objMetaData_t)); char *fkey = plat_alloc(256); char *name = NULL; name = (char *)ObjectKey_getName(key->object_id); metaData->objFlags = 0; metaData->expTime = 0; metaData->createTime = 0; metaData->keyLen = strlen(name); metaData->dataLen = size; memcpy(fkey, name, strlen(name)); if (pbuf != NULL && (data = plat_alloc(4+size)) == NULL) { status = SDF_FAILURE_MEMORY_ALLOC; plat_log_msg(21590, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "FAILURE: put_object - memory allocation"); } else { if (pbuf != NULL) { memcpy(data, pbuf, size); } if (!flashPut(shard, metaData, (char *)fkey, data)) { status = SDF_FAILURE_STORAGE_WRITE; plat_log_msg(21591, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "FAILURE: put_object - flashPut"); } else { status = SDF_SUCCESS; plat_log_msg(21592, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "SUCCESS: put_object - flashPut"); } if (fkey != NULL) { plat_free(fkey); } } return (status); }
void lock_init(struct lock *lock) { pthread_spinlock_t *sl = plat_alloc(sizeof(*sl)); pthread_spin_init(sl, 0); lock->priv = sl; }
int main(void) { pthread_t pthread[10]; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); shmem_config->size = SHM_SIZE; plat_shmem_prototype_init(shmem_config); int tmp = plat_shmem_attach(shmem_config->mmap); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", shmem_config->mmap, plat_strerror(-tmp)); plat_abort(); } #ifdef MULTIQ_SCHED fthInitMultiQ(1,NUM_PTHREADS); // Tell the scheduler code NUM_PTHREADS schedulers starting up #else fthInit(); #endif for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_create(&pthread[i], NULL, &pthreadRoutine, (void *) i); } for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_join(pthread[i], NULL); } printf("Done\n"); plat_exit(exitRV); }
SDF_status_t get_object(struct shard *shard, SDF_key_t key, SDF_CACHE_OBJ *dest, SDF_size_t *size, SDF_operation_t *opid) { int code = 0; SDF_status_t status = SDF_FAILURE; char *data = NULL; local_SDF_CACHE_OBJ lo = NULL; char *fkey = plat_alloc(256); char *name = NULL; objMetaData_t *metaData = plat_alloc(sizeof(objMetaData_t)); name = (char *)ObjectKey_getName(key->object_id); metaData->objFlags = 0; metaData->expTime = 0; metaData->createTime = 0; metaData->keyLen = strlen(name); metaData->dataLen = 0; memcpy(fkey, name, strlen(name)); if ((code = flashGet(shard, metaData, (char *)fkey, &data)) == 0) { plat_log_msg(21588, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "FAILURE: get_object - flashget"); } else { uint32_t dataLen = *((uint32_t *) data); *dest = createCacheObject(dataLen); plat_assert(!isCacheObjectNull(*dest)); getLocalCacheObject(&lo, *dest, dataLen); memcpy(lo, data, dataLen); releaseLocalCacheObject(&lo, dataLen); *size = dataLen; status = SDF_SUCCESS; plat_log_msg(21589, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "SUCCESS: get_object - flashget"); } if (fkey != NULL) { plat_free(fkey); } return (status); }
/** * Synchronously receive a message. * * On success, *msg contains the message which was received and * *msg_free_closure code which will free it. * * Returns positive on success, 0 on EOF, -errno on failure */ int plat_recv_msg(int fd, struct plat_msg_header **msg_ptr, plat_msg_free_t *msg_free_closure) { struct plat_msg_header header, *msg = NULL; int got; size_t remain; int ret; ret = recv_bytes(fd, &header, sizeof (header)); if (!ret) { } else if (0 <= ret && ret < sizeof (header)) { plat_log_msg(20959, PLAT_LOG_CAT_PLATFORM_MSG, PLAT_LOG_LEVEL_DIAGNOSTIC, "plat_recv_msg short header %d of %u bytes", ret, (unsigned)sizeof (header)); ret = -PLAT_EEOF; } else if (ret == sizeof (header) && header.magic != PLAT_MSG_MAGIC) { plat_log_msg(20960, PLAT_LOG_CAT_PLATFORM_MSG, PLAT_LOG_LEVEL_DIAGNOSTIC, "plat_recv_msg bad magix %x", header.magic); ret = -EILSEQ; } else { msg = plat_alloc(header.len); if (!msg) { ret = -ENOMEM; }; }; if (ret > 0) { memcpy(msg, &header, sizeof (header)); remain = header.len - sizeof (header); got = recv_bytes(fd, ((char *)msg) + sizeof (header), remain); if (got < 0) { ret = got; } else if (!got) { ret = -PLAT_EEOF; } else if (got < remain) { plat_log_msg(20961, PLAT_LOG_CAT_PLATFORM_MSG, PLAT_LOG_LEVEL_DIAGNOSTIC, "plat_recv_msg short payload %d of %u bytes", got, (unsigned)remain); ret = -PLAT_EEOF; } else { ret += got; } } if (ret > 0) { *msg_ptr = msg; *msg_free_closure = plat_msg_free_create(PLAT_CLOSURE_SCHEDULER_SYNCHRONOUS, &free_msg, NULL); } else { plat_free(msg); } return (ret); }
int main () { int ret; int tmp; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); plat_shmem_prototype_init(shmem_config); const char *path = plat_shmem_config_get_path(shmem_config); tmp = plat_shmem_attach(path); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", path, plat_strerror(-tmp)); plat_abort(); } sem_init(&general_sem, 0, 0); fthInit(); mboxShmem = ptofMbox_sp_alloc(); plat_assert_always(!ptofMbox_sp_is_null(mboxShmem)); mbox = ptofMbox_sp_rwref(&mbox, mboxShmem); ptofMboxInit(mbox); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); printf("starting fth scheduler pthread ....\n"); if ((ret = pthread_create(&sched_thread, &attr, fthSchedPthread, NULL))) { plat_assert_always(0 == 1); } /* wait for all the threads to get created */ plat_assert_always(0==sem_wait(&general_sem)); // runThreadPool(pool); /* kick off the mail blast */ printf("Starting the mail blast 0\n"); for(int ii=0; ii < NUM_THREADS ; ii++) { mail_sp_t mailShm = mail_sp_alloc(); mail_t *mail = mail_sp_rwref(&mail, mailShm); mail->counter = ii; printf(" Posting mail with counter %d\n", mail->counter); ptofMboxPost(mboxShmem, shmem_cast(shmem_void, mailShm)); } /* We wait for all the messages to be delievered before exiting */ plat_assert_always(0==sem_wait(&general_sem)); // pthread_join(sched_thread, NULL); return 0; }
string_t * build_string_type_from_key_type(SDF_key_t key) { string_t *fkey; const char *name; // The string_t key should NOT include the NULL termination char! fkey = (string_t *) plat_alloc(4+ObjectKey_getLen(key->object_id)); fkey->len = (int) ObjectKey_getLen(key->object_id) - 1; // Note the reduction in LEN by 1 name = ObjectKey_getName(key->object_id); memcpy(&fkey->chars, name, fkey->len); return (fkey); }
int init_containers(struct sdf_agent_state *state) { SDF_status_t status = SDF_SUCCESS; struct sdf_replicator *replicator = NULL; if (state->config.always_replicate) { replicator = sdf_replicator_adapter_get_replicator(state->ReplicationInitState.adapter); if (replicator == NULL) { status = SDF_FAILURE; plat_assert(replicator != NULL); } } SDF_action_init_t *pai = (SDF_action_init_t *)&state->ActionInitState; SDF_action_thrd_state_t *pts = (SDF_action_thrd_state_t *) plat_alloc( sizeof(SDF_action_thrd_state_t) ); plat_assert( NULL != pts ); pai->pts = (void *) pts; pts->phs = state->ActionInitState.pcs; InitActionAgentPerThreadState(pai->pcs, pts, pai); pai->ctxt = ActionGetContext(pts); if (status == SDF_SUCCESS) { init_sdf_initialize_config(&state->ContainerInitState, (SDF_internal_ctxt_t *)pai, state->config.numObjs, state->config.system_recovery, state->rank, state->flash_dev, state->flash_dev_count, state->config.defaultShardCount, replicator); state->ContainerInitState.flash_msg = state->config.flash_msg; state->ContainerInitState.always_replicate = state->config.always_replicate; state->ContainerInitState.replication_type = state->config.replication_type; state->ContainerInitState.nnodes = state->config.nnodes; state->ContainerInitState.flash_dev = state->flash_dev; state->ContainerInitState.flash_dev_count = state->config.numFlashDevs; status = init_sdf_initialize(&state->ContainerInitState, state->config.system_restart); } // initZS_operational_states_t(); state->op_access.is_shutdown_in_progress = SDF_FALSE; return (status == SDF_SUCCESS); }
int main() { pthread_t pth; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); shmem_config->size = SHM_SIZE; plat_shmem_prototype_init(shmem_config); int tmp = plat_shmem_attach(shmem_config->mmap); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", shmem_config->mmap, plat_strerror(-tmp)); plat_abort(); } fthInit(); xmboxShmem = ptofMbox_sp_alloc(); xmbox = ptofMbox_sp_rwref(&xmbox, xmboxShmem); ptofMboxInit(xmbox); pthread_create(&pth, NULL, &pthreadSchedRoutine, (void *) 0); sleep(1); // Give the scheduler a chance to init int rc = ptofMboxDestroy(xmbox); if (rc) { printf("Non zero RC from ptofMboxDestroy - %i\n", rc); plat_exit(1); } fthKill(100); pthread_join(pth, NULL); printf("test finished. \n"); printf("In this file,the failed count is %d. \n", failed_count); return (failed_count); //plat_exit(0); }
/* * Caller want to know the ntop hot clients. It should provide string buffer. */ int hot_client_report(Reporter_t *preporter, int ntop, char *rpbuf, int rpsize) { int i = 0; char *pos = rpbuf + strlen(rpbuf); ReportSortEntry_t *sort_client = NULL; int nlists = CLIENT_BUCKETS * NCLINETS_PER_BUCKET; int dump_num = __sync_add_and_fetch(&preporter->dump_num, 1); if (dump_num > MAX_DUMP_NUM) { (void)__sync_sub_and_fetch(&preporter->dump_num, 1); return -1; } sort_client = plat_alloc(sizeof(ReportSortEntry_t) * preporter->instances[0].nwinner_head); if (sort_client == NULL) { plat_log_msg(100016, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Allocate memory for sorted client failed."); (void)__sync_sub_and_fetch(&preporter->dump_num, 1); return -1; } pos += snprintf(pos, rpsize, "HOTCLIENT\r\n"); if (nlists > preporter->instances[0].nwinner_head) { nlists = preporter->instances[0].nwinner_head; } for (i = 0; i < nlists; i++) { sort_client[i].index = preporter->client_ref[i].client_ip; sort_client[i].refcount = preporter->client_ref[i].refcount; } dump_hot_client(sort_client, nlists, ntop, rpsize, pos); plat_free(sort_client); (void)__sync_sub_and_fetch(&preporter->dump_num, 1); return (0); }
int main(void) { pthread_t pthread[NUM_PTHREADS]; int tmp; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); shmem_config->size = SHM_SIZE; plat_shmem_prototype_init(shmem_config); int tmp = plat_shmem_attach(shmem_config->mmap); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", shmem_config->mmap, plat_strerror(-tmp)); plat_abort(); } fthInit(); head = foo_sp_null; tail = foo_sp_null; for (int i = 0; i < NUM_TRIES * NUM_PTHREADS; i++) { rands[i] = rand(); foo_sp_t foo_shmem = foo_sp_alloc(); foo_t *foo = foo_sp_rwref(&foo, foo_shmem); foo->myData = i; check[i] = foo_shmem; foo_sp_rwrelease(&foo); } for (uint64_t i = 0; i < NUM_PTHREADS-1; i++) { pthread_create(&pthread[i], NULL, &pthreadSchedRoutine, (void *) i); } pthreadSchedRoutine((void *) NUM_PTHREADS-1); // for (uint64_t i = 0; i < NUM_PTHREADS; i++) { // pthread_join(pthread[i], NULL); // } }
int main(int argc, char **argv) { iterations = atoi(argv[1]); struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); shmem_config->size = SHM_SIZE; plat_shmem_prototype_init(shmem_config); int tmp = plat_shmem_attach(shmem_config->mmap); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", shmem_config->mmap, plat_strerror(-tmp)); plat_abort(); } fthInit(); fthLockInit(&lock1); fthLockInit(&lock2); fthLockInit(&lockStart); fthThread_t *thread1 = XSpawn(&threadRoutine1, 4096); fthThread_t *thread2 = XSpawn(&threadRoutine2, 4096); fthThread_t *thread3 = XSpawn(&threadRoutine3, 4096); fthWaitEl_t *wait = fthLock(&lockStart, 1, NULL); XResume(thread1, 1); XResume(thread2, 2); XResume(thread3, (uint64_t) wait); fthSchedulerPthread(0); return (0); }
SDF_status_t put_block(SDF_CONTAINER c, struct shard *shard, SDF_key_t key, void *pbuf, SDF_size_t size, SDF_operation_t *opid) { SDF_status_t status = SDF_FAILURE; local_SDF_CONTAINER lc = getLocalContainer(&lc, c); local_SDF_CONTAINER_PARENT lparent = getLocalContainerParent(&lparent, lc->parent); struct flashDev *dev = shard->dev; SDF_blocknum_t blockNum = key->block_id; SDF_size_t blockSize = lparent->blockSize; char *buf = NULL; releaseLocalContainer(&lc); releaseLocalContainerParent(&lparent); if (pbuf == NULL) { buf = (char *) plat_alloc(blockSize); memset(buf, ' ', blockSize); pbuf = buf; } if (flashBlockWrite(dev, pbuf, blockNum, blockSize) != blockSize) { status = SDF_FAILURE_STORAGE_WRITE; plat_log_msg(21595, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "FAILURE: put_block - flashBlockWrite"); } else { status = SDF_SUCCESS; plat_log_msg(21596, PLAT_LOG_CAT_SDF_SHARED, PLAT_LOG_LEVEL_TRACE, "SUCCESS: put_block - flashBlockWrite"); } return (status); }
/** * copy winner list for sort */ static int copy_winner_list(ReporterInstance_t *rpt, ReportCopyWinner_t *copy_winner) { int i = 0; int winner_head_size = rpt->nwinner_head * sizeof(ReportWinnerList_t); int winner_size = rpt->nwinners * sizeof(ReportEntry_t); int key_table_size = rpt->nkeys_per_winner_list * MAX_KEY_LEN * rpt->nwinner_head; ReportWinnerList_t *winner_head = rpt->winner_head; int sorted_winner_size = rpt->nsort_winners * sizeof(uint16_t); int sorted_ref_size = sizeof(ReportSortEntry_t) * rpt->nwinner_head; copy_winner->winner_head = plat_alloc(winner_head_size); if (copy_winner->winner_head == NULL) { plat_log_msg(100019, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Fail to allocate memory for copy of winner head."); return -1; } memset(copy_winner->winner_head, 0, winner_head_size); copy_winner->winners = plat_alloc(winner_size); if (copy_winner->winners == NULL) { plat_log_msg(100020, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Fail to allocate memory for copy of winners."); return -1; } memset(copy_winner->winners, 0, winner_size); copy_winner->key_table = plat_alloc(key_table_size); if (copy_winner->key_table == NULL) { plat_log_msg(100021, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Fail to allocate memory for copy of key table."); return -1; } memset(copy_winner->key_table, 0, key_table_size); for (i = 0; i < rpt->nwinner_head; i++) { HotkeyLock(winner_head[i].lock, winner_head[i].lock_wait); memcpy(©_winner->winner_head[i], &winner_head[i], sizeof(ReportWinnerList_t)); memcpy(©_winner->winners[WLI_TO_WI(rpt, i)], &rpt->winners[WLI_TO_WI(rpt, i)], sizeof(ReportEntry_t) * rpt->nwinners_per_list); memcpy(©_winner->key_table[WLI_TO_WKI(rpt, i) * MAX_KEY_LEN], &rpt->key_table[WLI_TO_WKI(rpt, i) * MAX_KEY_LEN], MAX_KEY_LEN * rpt->nkeys_per_winner_list); HotkeyUnlock(winner_head[i].lock, winner_head[i].lock_wait); } copy_winner->snapshot.winner_sorted = plat_alloc(sorted_winner_size); if (copy_winner->snapshot.winner_sorted == NULL) { plat_log_msg(100022, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Fail to allocate memory for snapshot sorted winners."); return -1; } memset(copy_winner->snapshot.winner_sorted, 0, sorted_winner_size); copy_winner->snapshot.total = rpt->nsort_winners; copy_winner->snapshot.cur = 0; copy_winner->snapshot.used = 0; copy_winner->ref_sort = plat_alloc(sorted_ref_size); if (copy_winner->ref_sort == NULL) { plat_log_msg(100023, LOG_CAT_HOTKEY, PLAT_LOG_LEVEL_ERROR, "Fail to allocate memory for ref sorted winners."); return -1; } memset(copy_winner->ref_sort, 0, sorted_ref_size); return 0; }
struct flashDev * fifo_flashOpen( char * devName, flash_settings_t *flash_settings_in, int flags ) { int i; int rc; struct flashDev * pdev; plat_log_msg(21691, PLAT_LOG_CAT_SDF_APP_MEMCACHED, PLAT_LOG_LEVEL_DEBUG, "ENTERING, devName=%s", devName ); /* Global settings for aio and flash subsystems */ flash_settings = *flash_settings_in; pdev = plat_alloc( sizeof(struct flashDev) ); if ( NULL == pdev ) { plat_log_msg(21692, PLAT_LOG_CAT_FLASH, PLAT_LOG_LEVEL_ERROR, "failed to alloc dev"); return NULL; } for ( i = 0; i < FTH_MAX_SCHEDS; i++ ) { pdev->stats[i].flashOpCount = 0; pdev->stats[i].flashReadOpCount = 0; pdev->stats[i].flashBytesTransferred = 0; } pdev->shardList = NULL; InitLock( pdev->lock ); /* * initialize the aio subsystem */ pdev->paio_state = plat_alloc( sizeof(struct ssdaio_state) ); if ( NULL == pdev->paio_state ) { plat_log_msg(21693, PLAT_LOG_CAT_FLASH, PLAT_LOG_LEVEL_ERROR, "failed to alloc aio state"); plat_free(pdev); return NULL; } rc = ssdaio_init( pdev->paio_state, devName ); if ( 0 != rc ) { plat_log_msg(21694, PLAT_LOG_CAT_FLASH, PLAT_LOG_LEVEL_ERROR, "failed to init aio"); plat_free(pdev->paio_state); plat_free(pdev); return NULL; } pdev->size = pdev->paio_state->size; pdev->used = 0; plat_log_msg(21695, PLAT_LOG_CAT_SDF_APP_MEMCACHED, PLAT_LOG_LEVEL_DEBUG, "dev size is %lu", pdev->size ); if ( NULL == Ssd_fifo_ops.flashOpen ) { plat_log_msg(21696, PLAT_LOG_CAT_SDF_APP_MEMCACHED, PLAT_LOG_LEVEL_FATAL, "fifo_flashOpen not implemented!" ); plat_abort(); } Ssd_fifo_ops.flashOpen( devName, flash_settings_in, flags ); return pdev; }
int main() { pthread_t pthread[10]; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); plat_shmem_prototype_init(shmem_config); const char *path = plat_shmem_config_get_path(shmem_config); int tmp = plat_shmem_attach(path); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", path, plat_strerror(-tmp)); plat_abort(); } fthInit(); xmboxShmem = ptofMbox_sp_alloc(); xmbox = ptofMbox_sp_rwref(&xmbox, xmboxShmem); ptofMboxInit(xmbox); pthread_create(&pthread[0], NULL, &pthreadSchedRoutine, (void *) 0); sleep(1); // Give the scheduler a chance to init printf("Posting first 10\n"); for (uint64_t i = 0; i < 10; i++) { mail_sp_t mailShmem = mail_sp_alloc(); mail_t *mail = mail_sp_rwref(&mail, mailShmem); mail->mail = i + 100; mail_sp_rwrelease(&mail); ptofMboxPost(xmboxShmem, shmem_cast(shmem_void, mailShmem)); calcsum += (17 * (i+100)); } printf("First 10 complete\n"); sleep(1); mail_sp_t mailShmem = mail_sp_alloc(); mail_t *mail = mail_sp_rwref(&mail, mailShmem); mail->mail = 300; mail_sp_rwrelease(&mail); ptofMboxPost(xmboxShmem, shmem_cast(shmem_void, mailShmem)); printf("Singleton posted\n"); calcsum += (23 * 300); sleep(1); for (uint64_t i = 0; i < 10; i++) { mail_sp_t mailShmem = mail_sp_alloc(); mail_t *mail = mail_sp_rwref(&mail, mailShmem); mail->mail = i + 200; mail_sp_rwrelease(&mail); ptofMboxPost(xmboxShmem, shmem_cast(shmem_void, mailShmem)); calcsum += (19 * (i+200)); } printf("Second 10 posted\n"); pthread_create(&pthread[1], NULL, &pthreadSchedRoutine, (void *) 1); while (kill == 0) { sleep(1); } fthKill(2); for (int i = 0; i < 2; ++i) { pthread_join(pthread[i], NULL); } int rc = ptofMboxDestroy(xmbox); if (rc) { printf("Non zero RC from ptofMboxDestroy - %i\n", rc); plat_exit(1); } if (calcsum != checksum) { printf("Expected checksum of %i but got %i\n", calcsum, checksum); plat_exit(1); } printf("Checksum OK - was %i\n", checksum); plat_exit(0); }
int main() { pthread_t pthread[10]; pthread_t pthread2[100]; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); plat_shmem_prototype_init(shmem_config); const char *path = plat_shmem_config_get_path(shmem_config); int tmp = plat_shmem_attach(path); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", path, plat_strerror(-tmp)); plat_abort(); } fthInit(); xmboxShmem = ftopMbox_sp_alloc(); xmbox = ftopMbox_sp_rwref(&xmbox, xmboxShmem); ftopMboxInit(xmbox); for (uint64_t i = 0; i < 10; i++) { pthread_create(&pthread2[i], NULL, &pthreadRoutine2, (void *) i); } for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_create(&pthread[i], NULL, &pthreadSchedRoutine, (void *) i); } sleep(1); pthread_create(&pthread2[10], NULL, &pthreadRoutine3, (void *) 10); for (int i = 0; i < 11; i++) { pthread_join(pthread2[i], NULL); } fthKill(NUM_PTHREADS); for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_join(pthread[i], NULL); } int rc = ftopMboxDestroy(xmbox); if (rc) { printf("Non zero RC from ftopMboxDestroy - %i\n", rc); plat_exit(1); } if (calcsum != checksum) { printf("Expected checksum of %i but got %i\n", calcsum, checksum); plat_exit(1); } printf("Checksum OK - was %i\n", checksum); plat_exit(0); }
void threadTest(uint64_t arg) { int maxtop = 16; int top = 16; int nbuckets = hashsize(16); // uint64_t updates = 160 * nbuckets; uint64_t updates = 16; int i, t, cmd_type; int mm_size[4]; void* buf[4]; Reporter_t *rpt[4]; char *recv = plat_alloc(300*top); char *cmp_recv = plat_alloc(300*top); for (int i = 0; i < 4; i++) { mm_size[i] = calc_hotkey_memory(maxtop, nbuckets, i); buf[i] = plat_alloc(mm_size[i]); rpt[i] = hot_key_init(buf[i], mm_size[i], nbuckets, maxtop, i); } init_key(4); // case 0: 0x00 handler // keys are get/update, randomized ip, result should be // merged keys and 0 for ip // 16 keys with different ip for (i = 0; i < updates*2; i++) { t = i % KEY_NUM; int ip = rnd_ip(i); cmd_type = rnd_cmd(i % 2); printf("key_t=%s\n", keys[t].key_str); hot_key_update(rpt[0], keys[t].key_str, KEY_LEN+1, keys[t].syndrome, keys[t].bucket, cmd_type, ip); cmd_type <= 2 ? (keys[t].get_count++): (keys[t].update_count++); keys[t].count++; } recv[0] = '\0'; hot_key_report(rpt[0], top, recv, 300*top, 1, 0); printf("handle 0x00:get\n%s", recv); strcpy(cmp_recv, recv); recv[0] = '\0'; hot_key_report(rpt[0], top, recv, 300*top, 2, 0); printf("handle 0x00:update\n%s", recv); if (strcmp(cmp_recv, recv)) { printf("error: get/update should be both access for 0x00 reporter\n"); nfailed++; } recv[0] = '\0'; hot_client_report(rpt[0], top, recv, 300*top); printf("handle 0x00: client\n%s", recv); hot_key_reset(rpt[0]); // case 1: 0x01 handler // keys are get/update, randomized ip, result should be // seperate keys and 0 for ip // each instance has 16 keys with different ip for (i = 0; i < updates*2; i++) { t = i % KEY_NUM; for (int j = 0; j < 2; j++) { int ip = rnd_ip(i); cmd_type = rnd_cmd(j); hot_key_update(rpt[1], keys[t].key_str, KEY_LEN+1, keys[t].syndrome, keys[t].bucket, cmd_type, ip); cmd_type <= 2 ? (keys[t].get_count++): (keys[t].update_count++); keys[t].count++; } } recv[0] = '\0'; hot_key_report(rpt[1], top, recv, 300*top, 1, 0); printf("handle 0x01:get\n%s", recv); strcpy(cmp_recv, recv); recv[0] = '\0'; hot_key_report(rpt[1], top, recv, 300*top, 3, 0); printf("handle 0x01:update\n%s", recv); if (strcmp(cmp_recv, recv) != 0) { printf("error: get/update should be the same for 0x01 reporter\n"); nfailed++; } recv[0] = '\0'; hot_client_report(rpt[1], top, recv, 300*top); printf("handle 0x01: client\n%s", recv); hot_key_reset(rpt[1]); // case 2: 0x02 handler // keys are get/update, randomized ip, result should be // merged keys keys for get/set while different ip // 8 sets, and 8 gets, the winner is filled with 16 entries // with the same key but different ip for (i = 0; i < updates*4; i++) { int ip = rnd_ip(i); for (int j = 0; j < 2; j++) { t = j; int cmd_type = rnd_cmd(j); hot_key_update(rpt[2], keys[t].key_str, KEY_LEN+1, keys[t].syndrome, keys[t].bucket, cmd_type, ip); } } recv[0] = '\0'; hot_key_report(rpt[2], top, recv, 300*top, 1, 0); printf("handle 0x02:get\n%s", recv); strcpy(cmp_recv, recv); recv[0] = '\0'; hot_key_report(rpt[2], top, recv, 300*top, 3, 0); printf("handle 0x02:update\n%s", recv); if (strcmp(cmp_recv, recv)) { printf("error: get/update should be same for 0x02 reporter\n"); nfailed++; } recv[0] = '\0'; hot_client_report(rpt[2], top, recv, 300*top); printf("handle 0x02: client\n%s", recv); hot_key_reset(rpt[2]); // case 3: 0x03 handler // keys are get/update, randomized ip, result should be // separated keys keys for get/set while different ip // 16 sets, and 16 gets, the winner is filled with 16 entries // with the same key but different ip for (i = 0; i < updates*4; i++) { t = 0; int ip = rnd_ip(i); for (int j = 0; j < 2; j++) { int cmd_type = rnd_cmd(j); hot_key_update(rpt[3], keys[t].key_str, KEY_LEN+1, keys[t].syndrome, keys[t].bucket, cmd_type, ip); } } recv[0] = '\0'; hot_key_report(rpt[3], top, recv, 300*top, 1, 0); printf("handle 0x03: get\n%s", recv); strcpy(cmp_recv, recv); recv[0] = '\0'; hot_key_report(rpt[3], top, recv, 300*top, 3, 0); printf("handle 0x03: update\n%s", recv); if (strcmp(cmp_recv, recv) != 0) { printf("error: get/update should be the same for 0x03 reporter\n"); nfailed++; } recv[0] = '\0'; hot_client_report(rpt[3], top, recv, 300*top); printf("handle 0x03: client\n%s", recv); hot_key_reset(rpt[3]); plat_free(recv); plat_free(cmp_recv); printf("nfailed = %d\n", nfailed); done = 1; }
int getPropertyFromFile(const char *prop_file, char *inKey, char *outVal) { int ret = 0; if (!prop_file || !prop_file[0]) return 0; FILE *fp = fopen(prop_file, "r"); if (!fp) { plat_log_msg(21756, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_ERROR, "Reading properties file '%s' has an error!\n", propertiesDefaultFile); return -1; } char *line = (char *) plat_alloc(2048), *beg, *str, *key, *val; while(fgets(line, 2048, fp)) { beg = line; while(' ' == *beg) { // trim beginning beg++; } if('#' == *beg || '\0' == *beg || '\n' == *beg) { // search for comment continue; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get key str++; } if (str-beg) { key = strndup(beg, str-beg); } else { continue; } beg = str++; while(' ' == *beg || '=' == *beg) { // trim beginning beg++; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get value str++; } if (str - beg) { val = strndup(beg, str-beg); } else { free(key); continue; } if ( strcmp(inKey,key) == 0 ) { strcpy(outVal,val); free(key); free(val); break; } else { free(key); free(val); } } fclose(fp); plat_free(line); return (ret); }
int loadProperties(const char *path_arg) { #ifndef SDFAPIONLY /* In SDF library the hash can be initialized already by SDFSetPropery API*/ if (NULL != _sdf_globalPropertiesMap) { return 0; } #endif int ret = 0; const char *path = NULL; path = path_arg; if (!path) return 0; FILE *fp = fopen(path, "r"); if (!fp) { plat_log_msg(21756, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_ERROR, "Reading properties file '%s' has an error!\n", path); return -1; } if (!_sdf_globalPropertiesMap) { initializeProperties(); } char *line = (char *) plat_alloc(2048), *beg, *str, *key, *val; while(fgets(line, 2048, fp)) { // aah... really needed Boost here beg = line; while(' ' == *beg) { // trim beginning beg++; } if('#' == *beg || '\0' == *beg || '\n' == *beg) { // search for comment continue; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get key str++; } if (str-beg) { key = strndup(beg, str-beg); } else { continue; } beg = str++; while(' ' == *beg || '=' == *beg) { // trim beginning beg++; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get value str++; } if (str-beg) { val = strndup(beg, str-beg); } else { free(key); continue; } #ifdef SDFAPIONLY /* in SDF library properties from file override properties set in runtime using SDFSetProperty */ setProperty(key, val); #else if (0 != insertProperty(key, val)) { ret--; plat_log_msg(21757, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_ERROR, "Parsed property error (ret:%d)('%s', '%s')", ret, key, val); } #endif /** * XXX: drew 2008-12-17 It would be better to log at the point of use * so we can output whether the default value was being used; but * this will get us the current settings in Patrick's memcached * runs. */ if (ZS_log_level <= PLAT_LOG_LEVEL_TRACE_LOW) { plat_log_msg(21758, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_TRACE_LOW, "Parsed property ('%s', '%s')", key, val); } } if (ZS_log_level <= PLAT_LOG_LEVEL_TRACE_LOW) { plat_log_msg(70124, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_TRACE_LOW, "Read from properties file '%s'", path); } fclose(fp); plat_free(line); return (ret); }
/** * the main entrance of the colloctor process */ int main(int argc, char **argv) { struct sigaction act_full_A, act_full_B; /*change the user if we need*/ if(argc>=3&&0==strcmp(argv[1],"-u")) { become_user(argv[2]); } /*get the two buffers */ shmem_info_A = get_shmem_info(0); shmem_info_B = get_shmem_info(1); /*get the config parameter */ INIT_CONFIG_PARAMETER(TRACE_CONFIG_FILE, "LOG_DIR=", LOG_DIR, 1); INIT_CONFIG_PARAMETER(TRACE_CONFIG_FILE, "END_FILE=", END_FILE, 1); INIT_CONFIG_PARAMETER(TRACE_CONFIG_FILE, "CIRCLE_TRACE=", CIRCLE_TRACE, 0); INIT_CONFIG_PARAMETER(TRACE_CONFIG_FILE, "MAX_FILE_NUMBER=", MAX_FILE_NUMBER, 0); /*init the buffer size from config file */ INIT_CONFIG_PARAMETER(TRACE_CONFIG_FILE, "CONTENT_SIZE=", SHME_CONTENT_SIZE, 0); SHME_CONTENT_SIZE = SHME_CONTENT_SIZE << 20; /*prepare the log file */ if (shmem_info_A->shm != (char *)(-1)) { /*mk the dir if not exsits,493==0755 */ mkdir(LOG_DIR, 493); /*ini the size, real_size and pid */ //*(shmem_info_A->size) = 0; //*(shmem_info_A->real_size) = 0; *(shmem_info_A->pid) = plat_getpid(); //*(shmem_info_B->size) = 0; //*(shmem_info_B->real_size) = 0; *(shmem_info_B->pid) = plat_getpid(); //buffer=malloc(SHME_MAX_SIZE*sizeof(char)); /*open all files here */ int i = 0; files = plat_alloc(sizeof(struct file_dump) * MAX_FILE_NUMBER); for (i = 0; i < MAX_FILE_NUMBER; i++) { sprintf(files[i].file_name, "%s/%d", LOG_DIR, i); files[i].fp = fopen(files[i].file_name, "wb+"); } /*catch the int and term */ signal(SIGINT, interrupt); signal(SIGTERM, interrupt); /*set the handler of two singnal */ act_full_A.sa_sigaction = collector_A; act_full_A.sa_flags = SA_SIGINFO; act_full_B.sa_sigaction = collector_B; act_full_B.sa_flags = SA_SIGINFO; sigaction(SHME_FULL_A, &act_full_A, NULL); sigaction(SHME_FULL_B, &act_full_B, NULL); /*only the SHME_FULL_A and SHME_FULL_B would be catched */ sigemptyset(&mask); sigaddset(&mask, SHME_FULL_A); sigaddset(&mask, SHME_FULL_B); sigprocmask(SIG_BLOCK, &mask, &oldmask); /*block to wait the two singals */ while (1) { sigsuspend(&oldmask); } interrupt(); } return 0; }
void threadTest(uint64_t arg) { int maxtop = 16; int top = 16; int nbuckets = hashsize(4); int loops = NCANDIDATES; int mm_size; void *buf; struct _key keys[NCANDIDATES]; struct _key big_key, small_key; char *recv = (char *) plat_alloc(300*top); if (recv == NULL) { perror("failed to alloc"); } mm_size = calc_hotkey_memory(maxtop, nbuckets, 0); buf = plat_alloc(mm_size); Reporter_t *rpt; for (int i = 0; i < NCANDIDATES; i++) { gen_str(keys[i].key_str); keys[i].syndrome = 10000 + i; keys[i].bucket = i % 4; } gen_str(big_key.key_str); big_key.syndrome = 10000 + NCANDIDATES - 1; big_key.bucket = (NCANDIDATES - 1) % 4; gen_str(small_key.key_str); small_key.syndrome = 10000 + 65536; small_key.bucket = (NCANDIDATES - 1) % 4; rpt = hot_key_init(buf, mm_size, nbuckets, maxtop, 0); int ip = 127001; for (int i = 0; i < 2; i++) { loops = NCANDIDATES; while (loops--) { hot_key_update(rpt, keys[loops].key_str, KEY_LEN + 1, keys[loops].syndrome, keys[loops].bucket, 1 + random()%11, ip); } } hot_key_report(rpt, top, recv, 300*top, 1, 0); printf("keys:\n%s", recv); loops = NCANDIDATES; while (loops--) { if (!strstr(recv, keys[loops].key_str) && loops >= NCANDIDATES - NKEY_PER_WINNER_LIST) { printf("fail to set key %s\n", keys[loops].key_str); nfailed++; } } // at this moment, winner list's threshold is updated and it should // forbiddn lower ref-count keys to be winner loops = 2; while (loops--) { hot_key_update(rpt, small_key.key_str, KEY_LEN+1, small_key.syndrome, small_key.bucket, 1+random()%11, ip); } recv[0] = '\0'; printf("keys:\n"); hot_key_report(rpt, top, recv, 300*top, 1, 0); if (strstr(recv, small_key.key_str)) { printf("small key should not be hot keys %s\n", small_key.key_str); nfailed++; } // continue with this key, it should be winner if // ref-count is larger than threshold hot_key_update(rpt, small_key.key_str, KEY_LEN + 1, small_key.syndrome, small_key.bucket, 1 + random()%11, ip); recv[0] = '\0'; printf("keys after small key increased:\n"); hot_key_report(rpt, top, recv, 300*top, 1, 0); if (!strstr(recv, small_key.key_str)) { printf("small key should be hot keys as it's no longer small %s\n", small_key.key_str); nfailed++; } // small_key = keys[NCANDIDATES - 1]; small_key.syndrome = keys[NCANDIDATES - NKEY_PER_WINNER_LIST].syndrome; small_key.bucket = keys[NCANDIDATES - NKEY_PER_WINNER_LIST].bucket; strcpy(small_key.key_str, keys[NCANDIDATES - NKEY_PER_WINNER_LIST].key_str); if (strstr(recv, small_key.key_str)) { printf("winner should be evicted out:%s\n", small_key.key_str); nfailed++; } recv[0] = '\0'; hot_client_report(rpt, top, recv, 300*top); printf("clients:\n%s", recv); hot_key_reset(rpt); hot_key_cleanup(rpt); plat_free(recv); printf("failed = %d\n", nfailed); done = 1; }
static int init_flash(struct sdf_agent_state *state) { char *device_name; int flash_flags = 0; // Allocate space for the Mcd_containers array Mcd_containers = (mcd_container_t *) plat_alloc(sizeof(mcd_container_t) * max_num_containers); memset(Mcd_containers, 0, sizeof(*Mcd_containers) * max_num_containers); /* This initializes the code that redirects * flash API calls to one of several alternative * flash subsystems (see sdf/ssd). */ #ifdef ENABLE_MULTIPLE_FLASH_SUBSYSTEMS ssd_Init(); #endif #ifdef FLASH_RECOVERY flash_flags = FLASH_OPEN_PERSISTENCE_AVAILABLE; #endif switch(state->config.system_recovery) { case SYS_FLASH_RECOVERY: default: flash_flags |= FLASH_OPEN_NORMAL_RECOVERY; break; case SYS_FLASH_REFORMAT: flash_flags |= FLASH_OPEN_REFORMAT_DEVICE; break; } #ifdef MULTIPLE_FLASH_DEV_ENABLED int ii; for(ii=0; ii < state->config.numFlashDevs; ii++) { if (plat_asprintf(&device_name, "%s%d", state->config.flashDevName, ii) > 0) { state->flash_dev[ii] = (flashDev_t *)NULL; state->flash_dev[ii] = flashOpen(device_name, &state->flash_settings, flash_flags); plat_assert(state->flash_dev[ii]); plat_free(device_name); } } /* All the /dev/flash names have been converted to /dev/flash0 even in signle flashcard machines. So no need to handle single card case separately */ #else state->flash_dev = NULL; if (strstr(state->config.flashDevName, "%")) { if (plat_asprintf(&device_name, state->config.flashDevName, (int)state->rank) > 0) { state->flash_dev = flashOpen(device_name, &state->flash_settings, flash_flags); plat_assert(state->flash_dev); plat_free(device_name); } } else { if (plat_asprintf(&device_name, "%s%d", state->config.flashDevName, 0) > 0) { state->flash_dev = flashOpen(device_name, &state->flash_settings, flash_flags); plat_assert(state->flash_dev); plat_free(device_name); } } #endif // MULTI_FLASH_DEV_ENABLED state->flash_dev_count = state->config.numFlashDevs; return (state->flash_dev != NULL); }