[2] | 1 | /* Author : Rick van der Zwet
|
---|
| 2 | * S-number : 0433373
|
---|
| 3 | * Version : $Id: memory.h 363 2007-12-03 06:07:31Z rick $
|
---|
| 4 | * Copyright : FreeBSD Licence
|
---|
| 5 | * Description : BANKS-bank word-interleaved memory with random access time
|
---|
| 6 | * of RAS clock cycles
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 | #include <stdlib.h>
|
---|
| 11 | #include <string.h>
|
---|
| 12 | #include "common.h"
|
---|
| 13 |
|
---|
| 14 | void
|
---|
| 15 | memory_bank(const int BANKS, const int RAS)
|
---|
| 16 | {
|
---|
| 17 | struct bus2_t line;
|
---|
| 18 | struct result_t output = {0, 0, 0, 0};
|
---|
| 19 |
|
---|
| 20 | int bankneeded;
|
---|
| 21 | int i,j; /* Temp counter */
|
---|
| 22 | int t; /* Temp variable to hold condition */
|
---|
| 23 |
|
---|
| 24 | /* BANKS bank memory, so BANKS places which could be busy
|
---|
| 25 | * by convention 0 means not busy else busy
|
---|
| 26 | */
|
---|
| 27 | int * bankbusy = (int *)malloc(sizeof(int) * BANKS);
|
---|
| 28 |
|
---|
| 29 | /* Init all banks to be available in the beginning */
|
---|
| 30 | for (i = 0; i < BANKS; i++)
|
---|
| 31 | bankbusy[i] = FALSE;
|
---|
| 32 |
|
---|
| 33 | while (fscanfbus2(&line) != EOF) {
|
---|
| 34 | /* Process the counts */
|
---|
| 35 | setstats(&line, &output);
|
---|
| 36 |
|
---|
| 37 | /* New request means new cycle as well */
|
---|
| 38 | output.cycles++;
|
---|
| 39 |
|
---|
| 40 | /* Find proper bank */
|
---|
| 41 | bankneeded = line.address % BANKS;
|
---|
| 42 |
|
---|
| 43 | /* Determine whether the bank is busy, if so this will result
|
---|
| 44 | * in waiting for completion of this bank . It is not allowed
|
---|
| 45 | * for next calls to memory to complete before this one
|
---|
| 46 | */
|
---|
| 47 | if (bankbusy[bankneeded] != FALSE) {
|
---|
| 48 | output.conflicts++;
|
---|
| 49 |
|
---|
| 50 | /* Lower memory count till memory bank is free */
|
---|
| 51 | t = bankbusy[bankneeded];
|
---|
| 52 | for (i = 0; i < t; i++) {
|
---|
| 53 | for (j = 0; j < BANKS; j++) {
|
---|
| 54 | if (bankbusy[j] != FALSE)
|
---|
| 55 | bankbusy[j]--;
|
---|
| 56 | }
|
---|
| 57 | output.cycles++;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /* Set bank to be busy */
|
---|
| 62 | bankbusy[bankneeded] = RAS + TRANSFER;
|
---|
| 63 |
|
---|
| 64 | /* Process all banks to lower cycle count by one */
|
---|
| 65 | for (i = 0; i < BANKS; i++) {
|
---|
| 66 | if (bankbusy[i] != FALSE)
|
---|
| 67 | bankbusy[i]--;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /* Make sure remaining data leaves memory safely */
|
---|
| 72 | /* 'Abuse' t to be identifier wether some bank was lowered */
|
---|
| 73 | for (i = 0; i < RAS; i++) {
|
---|
| 74 | t = FALSE;
|
---|
| 75 | for (j = 0; j < BANKS; j++) {
|
---|
| 76 | if (bankbusy[j] != FALSE) {
|
---|
| 77 | bankbusy[j]--;
|
---|
| 78 | t = TRUE;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | /* Check if something was changed */
|
---|
| 82 | if (t == FALSE)
|
---|
| 83 | break;
|
---|
| 84 |
|
---|
| 85 | output.cycles++;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | /* delete allocated memory */
|
---|
| 90 | free(bankbusy);
|
---|
| 91 |
|
---|
| 92 | printfresult(stdout, &output);
|
---|
| 93 | }
|
---|