static int bm_act_init(int num_of_entries) { if(bm_control.init_done == True) { printk("!!!!!!! Trace is already up !!!!!!!!!\n"); return -1; } bm_entry = BM_ALLOC(0, sizeof(bm_entry_t)*num_of_entries, 0); bm_print_buf = BM_ALLOC(0, num_of_entries*128+200, 0); if (bm_entry==NULL || bm_print_buf==NULL) { printk("!!!!!!! bm_trace:: OUT of memory !!!!!!!!!\n"); bm_act_shutdown(); return -1; } bm_entry_pointer = bm_entry; bm_entry_end = bm_entry + num_of_entries; bm_control.num_of_entries = num_of_entries; bm_control.print_on = False; bm_control.enable = False; bm_control.stop_running = True; bm_control.init_done = True; create_proc_read_entry("trace",0,NULL,print_proc,NULL); trace_ctl = create_proc_entry("trace_ctl", 0644, NULL); if(trace_ctl) { trace_ctl->read_proc = trace_ctl_read; trace_ctl->write_proc = trace_ctl_write; } return 0; }
static void bm_test_cache_miss(unsigned char with_printing) { int *p_buffer; int counter = NUM_OF_LOOP_TEST; int line_counter = 0; int num = 0; int i; /* we used eight pages to generate cache miss (8 is factor of 2 * good for optimizations) the one extra page for aligment */ p_buffer = BM_ALLOC(0, CACHE_MISS_MEM_REQUIRED, 32); /* init and make sure all TLBs' are set */ for (i = 0; i < CACHE_MISS_MEM_REQUIRED / sizeof(int); ++i) p_buffer[i] = 1; { CL_TRACE_START_L0(); while (--counter) { num += p_buffer[line_counter]; /* move to the next line */ line_counter += (CACHE_LINE_SIZE / sizeof(int)); /* make sure you stay in the memory chunk */ line_counter = line_counter % (CACHE_MISS_MEM_REQUIRED / sizeof(int)); } CL_TRACE_END_L0(); } if (with_printing != False) { /* disable the optimizer to optimize this test */ printk("bm_test_cache_miss result: %d\n", num); } BM_FREE(0, p_buffer, CACHE_MISS_MEM_REQUIRED); }
static void bm_test_tlb_miss(unsigned char with_printing) { int* p_buffer; int counter = NUM_OF_LOOP_TEST; int line_counter = 0; int num = 0; unsigned int i; /* we used eight pages to generate cache miss (8 is factor of 2 good for optimizations) */ /* the */ /* one extra page for aligment */ p_buffer = BM_ALLOC(0, TLB_FAIL_MEM_REQUIRED, 32); for (i=0; i<TLB_FAIL_MEM_REQUIRED/sizeof(int); ++i) p_buffer[i] = 1; { CL_TRACE_START_L0(); while (--counter) { num += p_buffer[line_counter]; line_counter += (PAGE_SIZE/sizeof(int)); /* move to the next line */ line_counter = line_counter%(TLB_FAIL_MEM_REQUIRED/sizeof(int)); /* make sure you stay in the memory chunk */ } CL_TRACE_END_L0(); } if (with_printing!=False) { printk("bm_test_tlb_miss result: %d\n", num); /* disable the optimizer to optimize this test */ } BM_FREE(0, p_buffer, TLB_FAIL_MEM_REQUIRED); }
int main(int argc, char *argv[]) { int ii; unsigned char *map; int value; int index; int result; bool ok; map = BM_ALLOC(HUGE); if ( map == NULL ) { fprintf(stderr, "CANNOT ALLOCATE MEMORY FOR BIT MAP OF %u BITS\n", HUGE); goto Error; } else { printf("ALLOCATED AN ARRAY OF %u BITS\n", HUGE); } printf("SETTING ARRAY TO ALL '1'S\n"); BM_ALL(map, 1, HUGE); result = BM_TEST(map, 12) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 12, RESULTS('T'), 0, map[0]); printf("SETTING ARRAY TO ALL '0'S\n"); BM_ALL(map, 0, HUGE); result = BM_TEST(map, 12) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 12, RESULTS('F'), 0, map[0]); // Assign value to the bitmap map at position index: value = 11111; index = HUGE - 1; // the bitmap is indexed like a C array.. 0 to size-1 printf("ASSIGN %d AT %u\n", value, index); BM_ASSIGN(map, value, index); result = BM_TEST(map, index) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", index, RESULTS('T'), index / 8, map[index / 8]); value = 0; printf("ASSIGN %d AT %u\n", value, index); BM_ASSIGN(map, value, index); result = BM_TEST(map, index) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", index, RESULTS('F'), index / 8, map[index / 8]); printf("EVERY EVEN BIT 0, EVERY ODD BIT 1...\n"); for ( ii = 0; ii < HUGE; ii += 2 ) { BM_CLR(map, ii); BM_SET(map, ii + 1); } result = BM_TEST(map, 3456) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 3456, RESULTS('F'), 3456 / 8, map[3456 / 8]); result = BM_TEST(map, 4567) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 4567, RESULTS('T'), 4567 / 8, map[4567 / 8]); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('T')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('T')); ok = TRUE; for ( ii = 0; ii < HUGE; ii += 2 ) { if ( ii & 1 ) { if ( ! BM_TEST(map, ii) ) { printf(" FAIL: scan test: bit %u should be 1 byte:%10u is 0x%02x\n", ii, ii / 8, map[ii / 8]); ok = FALSE; break; } } else { if ( BM_TEST(map, ii) ) { printf(" FAIL: scan test: bit %u should be 0 byte:%10u is 0x%02x\n", ii, ii / 8, map[ii / 8]); ok = FALSE; break; } } } if ( ok ) printf(" scan test... OK\n"); printf("EVERY ODD BIT 0, EVERY EVEN BIT 1...\n"); for ( ii = 0; ii < HUGE; ii += 2 ) { BM_SET(map, ii); BM_CLR(map, ii + 1); } result = BM_TEST(map, 3456) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 3456, RESULTS('T'), 3456 / 8, map[3456 / 8]); result = BM_TEST(map, 4567) ; printf(" bit %12u is %c/%c %s byte:%10u is 0x%02x\n", 4567, RESULTS('F'), 4567 / 8, map[4567 / 8]); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('T')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('T')); ok = TRUE; for ( ii = 0; ii < HUGE; ii += 2 ) { if ( ii & 1 ) { if ( BM_TEST(map, ii) ) { printf(" FAIL: scan test: bit %u should be 0 byte:%10u is 0x%02x\n", ii, ii / 8, map[ii / 8]); ok = FALSE; break; } } else { if ( ! BM_TEST(map, ii) ) { printf(" FAIL: scan test: bit %u should be 1 byte:%10u is 0x%02x\n", ii, ii / 8, map[ii / 8]); ok = FALSE; break; } } } if ( ok ) printf(" scan test... OK\n"); printf("SETTING ARRAY TO ALL '1'S\n"); BM_ALL(map, 1, HUGE); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('T')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('F')); printf("SETTING ARRAY TO ALL '0'S\n"); BM_ALL(map, 0, HUGE); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('F')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('T')); printf("SETTING BIT %u TO '1'\n", HUGE - 2); BM_SET(map, HUGE - 2); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('T')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('T')); printf("SETTING ARRAY TO ALL '1'S\n"); BM_ALL(map, 1, HUGE); printf("SETTING BIT %u TO '0'\n", HUGE - 2); BM_CLR(map, HUGE - 2); result = BM_ANY(map, 1, HUGE) ; printf(" checking for any '1's: %c/%c %s\n", RESULTS('T')); result = BM_ANY(map, 0, HUGE) ; printf(" checking for any '0's: %c/%c %s\n", RESULTS('T')); // Freeing space requested: We can just use free(), or for closing the circle: BM_FREE(map); return 0; Error: return 1; }