int main() { pool = xmem_create_pool(sizeof(test_struct)); int total_start, alloc_start, free_start; total_start = alloc_start = rdtsc(); for(int i = 0; i < TEST_COUNT; i++) { test_array[i] = xmem_alloc(pool); } alloc_total = rdtsc() - alloc_start; free_start = rdtsc(); for(int i = 0; i < TEST_COUNT; i++) { xmem_free(pool, test_array[i]); } free_total = rdtsc() - free_start; xmem_destroy_pool(pool); total = rdtsc() - total_start; printf("=== perf of xmem\n"); printf("alloc & free times: %d\n", TEST_COUNT); printf("alloc time: %d CPU cycles\n", alloc_total); printf("free time: %d CPU cycles\n", free_total); printf("total time: %d CPU cycles\n", total); return 0; }
int main(int argc, char** argv) { deal_with_test_count(argc, argv); pool = xmem_create_pool(sizeof(test_struct)); uint64_t total_start, alloc_start, free_start; total_start = alloc_start = rdtsc(); for(int i = 0; i < test_count; i++) { test_array[i] = (test_struct*)xmem_alloc(pool); } alloc_total = rdtsc() - alloc_start; free_start = rdtsc(); for(int i = 0; i < test_count; i++) { xmem_free(pool, (char*)test_array[i]); } free_total = rdtsc() - free_start; xmem_destroy_pool(pool); total = rdtsc() - total_start; printf("=== perf of xmem\n"); printf("alloc & free times: %d\n", test_count); printf("alloc time: %llu CPU cycles\n", alloc_total); printf("free time: %llu CPU cycles\n", free_total); printf("total time: %llu CPU cycles\n", total); return 0; }
/*---------------------------------------------------------------------------*/ uint8_t lwb_stats_load(void) { #if LWB_CONF_USE_XMEM if(!xmem_init()) { /* make sure external memory is accessible */ return 0; } stats_addr = xmem_alloc(sizeof(lwb_statistics_t)); if(XMEM_ALLOC_ERROR == stats_addr || !xmem_read(stats_addr, sizeof(lwb_statistics_t), (uint8_t*)&stats)) { DEBUG_PRINT_MSG_NOW("WARNING: failed to load stats"); } if(crc16((uint8_t*)&stats, sizeof(lwb_statistics_t) - 2, 0) != stats.crc) { DEBUG_PRINT_MSG_NOW("WARNING: stats corrupted, values reset"); memset(&stats, 0, sizeof(lwb_statistics_t)); } stats.reset_cnt++; DEBUG_PRINT_MSG_NOW("stats loaded, reset count: %d", stats.reset_cnt); return 1; #else return 0; #endif /* LWB_CONF_USE_XMEM */ }