Project

General

Profile

MMU description » History » Version 63

Alexander Kamkin, 03/07/2013 08:17 AM

1 24 Alexander Kamkin
h1. MMU Description
2 1 Taya Sergeeva
3 62 Alexander Kamkin
_~By Taya Sergeeva~_
4
5 63 Alexander Kamkin
{{toc}}
6
7 35 Alexander Kamkin
A _memory management unit_ (_MMU_) is known to be one of the most complex and error-prone components of a modern microprocessor. MicroTESK has a special subsystem, called _MMU subsystem_, intended for (1) specifying memory devices and (2) deriving testing knowledge from such specifications. The subsystem provides unified facilities for describing memory buffers (like _L1_ and _L2 caches_, _translation look-aside buffers_ (_TLBs_), etc.) as well as a means for connecting several buffers into a memory hierarchy.
8 34 Alexander Kamkin
9 38 Alexander Kamkin
h2. Address Description
10
11 40 Alexander Kamkin
A buffer is accessed by an _address_, which is typically a _bit vector_ of a fixed length (width). Different buffers are allowed to have a common address space (e.g., L1 and L2 are usually both addressed by physical addresses). However, in general case, each buffer has its own domain.
12
13 60 Alexander Kamkin
An address space is described using a construct *address*. A few examples are given below.
14 38 Alexander Kamkin
15 1 Taya Sergeeva
<pre>
16 61 Alexander Kamkin
// The singleton.
17 56 Taya Sergeeva
address Void { width = 0;  }
18 45 Alexander Kamkin
</pre>
19 46 Alexander Kamkin
20 1 Taya Sergeeva
<pre>
21 61 Alexander Kamkin
// 40-bit physical addresses.
22
address PA { width = 40; }
23 38 Alexander Kamkin
</pre>
24 1 Taya Sergeeva
25
<pre>
26 61 Alexander Kamkin
// 64-bit virtual addresses.
27
address VA { width = 64; }
28 58 Alexander Kamkin
</pre>
29
30 59 Alexander Kamkin
The code above defines three address spaces: (1) a singleton @Void@; (2) a space @PA@ consisting of 40-bit addresses (_physical addresses_) and (3) a space @VA@ consisting of 64-bit addresses (_virtual addresses_).
31 10 Alexander Kamkin
32 2 Taya Sergeeva
h2. Buffer Description
33 1 Taya Sergeeva
34 57 Taya Sergeeva
Buffer is described by the construct *buffer*. Buffer can have different parameters, such as an associativity, a number of lines, the tag computing function, the index computing function, and the structure of data unit displacement, the controlling bits, the strategies of data changing when ''miss'' occurs, and so on. 
35 1 Taya Sergeeva
36 57 Taya Sergeeva
Let as consider a simple buffer which has only 2 attributes, such as the associativity, *sets*, i.e. the set''s size, and the number of sets in the buffer, *lines*. 
37
38 56 Taya Sergeeva
<pre>
39
buffer TLB 
40
{ 
41
  sets=8;
42
  lines=64;
43
} 
44 1 Taya Sergeeva
</pre>
45
46 57 Taya Sergeeva
The example above describes translation lookaside buffer (_TLB_), which has an associativity being equal to 8, (i.e. the number of lines in one set in this TLB buffer is equal to 8), and has the number of lines being equal to 64.   
47 56 Taya Sergeeva
48 57 Taya Sergeeva
Each *line* of the buffer can be described optionally by _tag_ and _data_ parameters. 
49 56 Taya Sergeeva
For example, 
50
51 1 Taya Sergeeva
<pre>
52 56 Taya Sergeeva
line = (tag:22, data:1024);
53 1 Taya Sergeeva
</pre>
54 56 Taya Sergeeva
55 1 Taya Sergeeva
describes lines of the cache, each of them containing a 22-bit tag and 1024-bit data.
56 56 Taya Sergeeva
57 57 Taya Sergeeva
In a MMU buffer also can have the *index* computing function. When accessing data, the cache determines a set by calculating a x-bit index. For example,
58 56 Taya Sergeeva
59 1 Taya Sergeeva
<pre>
60 57 Taya Sergeeva
index(addr:PA) = addr<14..13>;
61 1 Taya Sergeeva
</pre>
62
63 57 Taya Sergeeva
The cache calculates a 2-bit index. _index_ returns the initial and the final points of the field kept in bytes.
64 1 Taya Sergeeva
65 57 Taya Sergeeva
Each device stores some data which can be accessed (read from or written into) by their address. If a device contains a line with a given address, this situation is called a ''hit''; the opposite situation referes to as a ''miss''. If a ''miss'' occurs, the device usually displaces one of the set''s line with the line associated with the address given. The predicate which determines if there is a ''miss'' or ''hit'' situation is called *match*. There is the example below:
66
67 56 Taya Sergeeva
<pre>
68 57 Taya Sergeeva
line = (tag:22, data:1024);
69
match(addr:VA) = line.tag == addr<14..1>;
70 56 Taya Sergeeva
</pre>
71
72 57 Taya Sergeeva
If the set contains a line with the tag equal to the 22 upper bits of the physical address, this is a ''hit''. _match_ returns ''true'' if there is a ''hit'' in the line, and returns ''false'' otherwise.
73 56 Taya Sergeeva
74 57 Taya Sergeeva
The strategy which will be used for the lines displacement is specified by *policy*. 
75 56 Taya Sergeeva
76 57 Taya Sergeeva
<pre>
77
policy = LRU;
78
</pre>
79 56 Taya Sergeeva
80 57 Taya Sergeeva
Example above sets the strategy of data replacement to be _Last_ _Recently_ _Used_ policy, i.e. if the ''miss'' occured, the cache displaces the least-recently-used line of the set.
81 56 Taya Sergeeva
82 57 Taya Sergeeva
There is the example below, describing a real ''lower-level'' cache L1: 
83 2 Taya Sergeeva
84 53 Taya Sergeeva
<pre>
85
buffer L1 
86
{
87
	sets = 4;
88
	lines = 128;
89
	line = (tag:30, data:256);
90 10 Alexander Kamkin
	index(addr:PA) = addr<9..8>;
91 1 Taya Sergeeva
	match(addr:PA) = line.tag == addr<39..10>;
92
	policy = lru;
93
}
94
</pre>
95 19 Taya Sergeeva
96
_Description of each constructor_ in the buffer example is below:
97 49 Taya Sergeeva
98 21 Taya Sergeeva
h3. buffer
99 55 Taya Sergeeva
100 21 Taya Sergeeva
<pre>
101 1 Taya Sergeeva
  has a name, ''L1'' in our example; it can have names ''L2'' and ''TLB'' also;
102 51 Taya Sergeeva
  _buffer_ can be described by different parameters, such _sets_, _lines_, _index_, _match_, _policy_, and so on, which number is infixed;
103 16 Taya Sergeeva
</pre>
104 15 Taya Sergeeva
105 54 Taya Sergeeva
h3.  sets 
106 15 Taya Sergeeva
107 1 Taya Sergeeva
<pre>
108 49 Taya Sergeeva
  _sets_ is an associativity of a buffer; it returns the number of lines in a one set;
109 17 Taya Sergeeva
</pre>
110 15 Taya Sergeeva
111 54 Taya Sergeeva
h3.  lines
112 15 Taya Sergeeva
113 13 Taya Sergeeva
<pre>
114 49 Taya Sergeeva
  _lines_ is the number of sets in a given buffer;
115 1 Taya Sergeeva
</pre>
116 17 Taya Sergeeva
117 54 Taya Sergeeva
h3.  line
118
119 1 Taya Sergeeva
<pre>
120 52 Taya Sergeeva
  _line_ is an optional description of line''s fields;
121 54 Taya Sergeeva
  it designates each line of the cache; 
122 14 Taya Sergeeva
  _line_ includes its own parameters in the braces: _tag_ and _data_, each of them has an appropriate width of the fields kept in bytes;
123 1 Taya Sergeeva
  in our example _line_ has only two parameters, but in general case it can include more;
124
  it contains a 30-bit tag and a 256-bit data;
125 49 Taya Sergeeva
</pre>
126 17 Taya Sergeeva
127 54 Taya Sergeeva
h3.  index
128
129 1 Taya Sergeeva
<pre>
130
   _index_ is the function for index calculation;
131
   returns the initial and the final points of the field kept in bytes; they are marked in a three-cornered brackets, after _addr_; in our case index has 2 bits;
132
  _index_ depends on an _address_, which is ''physical'' (PA) in our case; the type of an address is set in the braces after _index_; 
133 49 Taya Sergeeva
</pre>
134 17 Taya Sergeeva
135 54 Taya Sergeeva
h3.  match 
136
137
<pre>
138 1 Taya Sergeeva
  _match_ is a predicate checking whether the line and the address match each other or not;
139
  it returns ''true'' or ''false'' depending on if the data required is in the given line or not; 
140 52 Taya Sergeeva
  it returns ''true'' if there is a ''hit'' in the line, and returns ''false'' otherwise; if the set contains a line with the tag equal to the 30 upper bits of the physical address, this is a ''hit''; if the set does not contain the line, this is a ''miss'' situation;
141 1 Taya Sergeeva
  _match_ description contains the the initial and the final points of the address field in the triangle brackets after _addr_; 
142
  as _index_ in the round braces _match_ also has the type of the address used; ''PA'' in our case;
143
</pre>
144 49 Taya Sergeeva
145 1 Taya Sergeeva
h3.  policy
146 54 Taya Sergeeva
147 56 Taya Sergeeva
<pre>
148 52 Taya Sergeeva
  _policy_ is the strategy of data displacement; 
149 1 Taya Sergeeva
  sets a policy which will be applied to our buffer, ''lru'' (Least Recently Used) in our example; 
150 25 Alexander Kamkin
  policy also can be ''plru'' (Pseudo LRU) and ''fifo'' (First Input First Out).
151
</pre>
152
153
h2. Code Structure
154
155
The MMU grammar is in ru.ispras.microtesk.translator.mmu.grammar folder. It contains Lexer, Parser and TreeWalker files. These files can be compiled by build.xml file (microtesk++/build.xml). The files generated (MMULexer.java, MMUParser.java, MMUTreeWalker.java) are in microtesk++.gen.ru.ispras.microtesk.translator.mmu.grammar folder. 
156
157
The folders ru.ispras.microtesk.translator.mmu.ir.* contain the inner representation of the MMU hierarchy of one buffer.  
158 1 Taya Sergeeva
159
MMU translator is in the ru.ispras.microtesk.translator.mmu.translator folder. 
160 26 Alexander Kamkin
161
Files in ru.ispras.microtesk.model.api.mmu folder contain different policies of cache. Folder ru.ispras.microtesk.model.api.mmu.buffer contains the model of MMU - the files which describe Buffer, Set, Line, Address expressions.  
162 1 Taya Sergeeva
163
After grammar files being generated the file ''BufferExample'' can be loaded to the translator.