/********************************************************************************** * Microbench Benchmark: mbccl * ------------------------------------------ * Filename: mbccl.c * Author : Yuanhua Yu * Date : 25/12/1999 ----------------------------------------------------------------------------------- * * Function: 1. Measuring the cache size and associativity of Level-I cache * 2. Measuring the cache size and associativity of Level-II cache * * Methods: Read a sequential array and each element of the array contains the * address of the next element. * * Condition: This benchmark works under Linux Operating System. * * History: 10/10/1999 First version * 25/10/1999 Second version * 25/12/1999 Third version * * Parameters: cache_size1 ----- the data cache size (level 1) in KB * cache_size2 ----- the cache size of level 2 in KB * * TOTAL_ACCESS----- control the number of operations : (1024*1024*128) * ARR_SIZE_0 ----- array size starts(KB) : 1024 * ARR_SIZE_1 ----- array size ends(KB) : (1024*1024*8) * SIZE_STEP ----- step of array size increment(bytes): 1024 * STEP_MODE ----- increment mode of the array size : 0/1 * STRIDE ----- distance between to accessed items : (8*4) bytes * * Variable: arr_size --- size of the array in bytes * arr_item --- number elements in the accessed array * ***********************************************************************************/ #include #include #include #include #include #include #define TOTAL_ACCESS (1024*1024*64*2) #define STRIDE 8 #define ARR_SIZE_0 1024 #define ARR_SIZE_1 (1024*48) #define SIZE_STEP 1024 #define STEP_MODE 0 #define ATYPE long /*-------------------------------------------------------------------------------*/ int main(char **av, int ac) { volatile ATYPE *va; register ATYPE s1; register long i,j,arr_item; unsigned long start_time, stop_time, arr_size; double time_cost, cost_per_op; FILE *fp; fp = fopen("Capacity.dat","a+"); fprintf(fp,"------- Cache Parameters Measurement -------\n"); fprintf(fp,"Arr_size(KB) Total_T(s)\tAccess_T(ns)\n"); printf("Arr_size(KB) Access_T(ns)\t Total_T(s)\n"); #if STEP_MODE == 0 for(arr_size=ARR_SIZE_0; arr_size<=ARR_SIZE_1; arr_size+=SIZE_STEP) #elif STEP_MODE == 1 for(arr_size=ARR_SIZE_0; arr_size<=ARR_SIZE_1; arr_size=arr_size*2) #endif { arr_item = arr_size/ (sizeof(ATYPE)); va = (ATYPE *) calloc(arr_item, sizeof(ATYPE)); for (j=0; j