source: liacs/ca/opdr3/memory_dram.c@ 92

Last change on this file since 92 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 3.0 KB
Line 
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 : page-mode DRAM with a page-size of PAGESIZE words, a
6 * random access time of RAS clock cycles and a 'next
7 * access time' of NAT clock cycles.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include "common.h"
14
15void
16memory_dram(const int PAGESIZE, const int NAT, const int RAS)
17{
18 struct bus2_t line;
19 struct result_t output = {0, 0, 0, 0};
20
21 /* Keep track of which page memory is, cause switching means a lot of
22 * extra work/cycles in terms of empty memory, moving to new bank
23 */
24 int current_page = 0;
25
26 /* Page location needed by new request */
27 int page_needed = 0;
28
29 /* Part of page needed by new request */
30 int part_needed = 0;
31
32 /* Every page has got 64 entries which all can be busy,
33 * by convention 0 means not busy else busy
34 */
35 int * partbusy = (int *)malloc(sizeof(int) * PAGESIZE);
36
37 int i; /* Temp counter */
38
39 /* Init all parts to be available in the beginning */
40 memset(partbusy, FALSE, sizeof(int) * PAGESIZE);
41
42 while (fscanfbus2(&line) != EOF) {
43 /* Process the counts */
44 setstats(&line, &output);
45
46 /* New request means new cycle as well */
47 output.cycles++;
48
49 /* Find proper page, do not take advantage of C div operator on
50 * int which is rounding directly, but use more safe/portable
51 * approch */
52 part_needed = line.address % PAGESIZE;
53 page_needed = (line.address - part_needed) / PAGESIZE;
54
55 /* Determine wether we did hit the right page or not */
56 if (page_needed == current_page) {
57 /* Check whether part is busy, which will result in waiting
58 * till part access is granted
59 */
60 if (partbusy[part_needed] != FALSE) {
61 /* Worst case senario on refresh */
62 output.cycles += RAS;
63 memset(partbusy, FALSE, sizeof(int) * PAGESIZE);
64 }
65 } else {
66 /* Wait till all pending calls in current page are completed
67 * 'Abuse' t to be identifier wether some bank was lowered
68 */
69 /* Worst case senario on refresh */
70 output.cycles += RAS;
71 memset(partbusy, FALSE, sizeof(int) * PAGESIZE);
72
73 /* Switch to new page */
74 current_page = page_needed;
75 output.cycles += NAT;
76 output.conflicts++;
77 }
78
79 /* Set new memory access */
80 partbusy[part_needed] = RAS + TRANSFER;
81
82 /* Process all parts to lower cycle count by one */
83 for (i = 0; i < PAGESIZE; i++) {
84 if (partbusy[i] != FALSE)
85 partbusy[i]--;
86 }
87 }
88
89 /* Make sure remaining data leaves memory safely */
90
91 /* Worst case senario on refresh */
92 output.cycles += RAS;
93
94 /* Delete allocated memory */
95 free(partbusy);
96
97 printfresult(stdout, &output);
98}
Note: See TracBrowser for help on using the repository browser.