/* Author : Rick van der Zwet * S-number : 0433373 * Version : $Id: memory.h 363 2007-12-03 06:07:31Z rick $ * Copyright : FreeBSD Licence * Description : BANKS-bank word-interleaved memory with random access time * of RAS clock cycles */ #include #include #include #include "common.h" void memory_bank(const int BANKS, const int RAS) { struct bus2_t line; struct result_t output = {0, 0, 0, 0}; int bankneeded; int i,j; /* Temp counter */ int t; /* Temp variable to hold condition */ /* BANKS bank memory, so BANKS places which could be busy * by convention 0 means not busy else busy */ int * bankbusy = (int *)malloc(sizeof(int) * BANKS); /* Init all banks to be available in the beginning */ for (i = 0; i < BANKS; i++) bankbusy[i] = FALSE; while (fscanfbus2(&line) != EOF) { /* Process the counts */ setstats(&line, &output); /* New request means new cycle as well */ output.cycles++; /* Find proper bank */ bankneeded = line.address % BANKS; /* Determine whether the bank is busy, if so this will result * in waiting for completion of this bank . It is not allowed * for next calls to memory to complete before this one */ if (bankbusy[bankneeded] != FALSE) { output.conflicts++; /* Lower memory count till memory bank is free */ t = bankbusy[bankneeded]; for (i = 0; i < t; i++) { for (j = 0; j < BANKS; j++) { if (bankbusy[j] != FALSE) bankbusy[j]--; } output.cycles++; } } /* Set bank to be busy */ bankbusy[bankneeded] = RAS + TRANSFER; /* Process all banks to lower cycle count by one */ for (i = 0; i < BANKS; i++) { if (bankbusy[i] != FALSE) bankbusy[i]--; } } /* Make sure remaining data leaves memory safely */ /* 'Abuse' t to be identifier wether some bank was lowered */ for (i = 0; i < RAS; i++) { t = FALSE; for (j = 0; j < BANKS; j++) { if (bankbusy[j] != FALSE) { bankbusy[j]--; t = TRUE; } } /* Check if something was changed */ if (t == FALSE) break; output.cycles++; } /* delete allocated memory */ free(bankbusy); printfresult(stdout, &output); }