-
Notifications
You must be signed in to change notification settings - Fork 8
/
builder.go
113 lines (94 loc) · 2.53 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package tlb
import "github.com/sarchlab/akita/v3/sim"
// A Builder can build TLBs
type Builder struct {
engine sim.Engine
freq sim.Freq
numReqPerCycle int
numSets int
numWays int
pageSize uint64
lowModule sim.Port
numMSHREntry int
}
// MakeBuilder returns a Builder
func MakeBuilder() Builder {
return Builder{
freq: 1 * sim.GHz,
numReqPerCycle: 4,
numSets: 1,
numWays: 32,
pageSize: 4096,
numMSHREntry: 4,
}
}
// WithEngine sets the engine that the TLBs to use
func (b Builder) WithEngine(engine sim.Engine) Builder {
b.engine = engine
return b
}
// WithFreq sets the freq the TLBs use
func (b Builder) WithFreq(freq sim.Freq) Builder {
b.freq = freq
return b
}
// WithNumSets sets the number of sets in a TLB. Use 1 for fully associated
// TLBs.
func (b Builder) WithNumSets(n int) Builder {
b.numSets = n
return b
}
// WithNumWays sets the number of ways in a TLB. Set this field to the number
// of TLB entries for all the functions.
func (b Builder) WithNumWays(n int) Builder {
b.numWays = n
return b
}
// WithPageSize sets the page size that the TLB works with.
func (b Builder) WithPageSize(n uint64) Builder {
b.pageSize = n
return b
}
// WithNumReqPerCycle sets the number of requests per cycle can be processed by
// a TLB
func (b Builder) WithNumReqPerCycle(n int) Builder {
b.numReqPerCycle = n
return b
}
// WithLowModule sets the port that can provide the address translation in case
// of tlb miss.
func (b Builder) WithLowModule(lowModule sim.Port) Builder {
b.lowModule = lowModule
return b
}
// WithNumMSHREntry sets the number of mshr entry
func (b Builder) WithNumMSHREntry(num int) Builder {
b.numMSHREntry = num
return b
}
// Build creates a new TLB
func (b Builder) Build(name string) *TLB {
tlb := &TLB{}
tlb.TickingComponent =
sim.NewTickingComponent(name, b.engine, b.freq, tlb)
tlb.numSets = b.numSets
tlb.numWays = b.numWays
tlb.numReqPerCycle = b.numReqPerCycle
tlb.pageSize = b.pageSize
tlb.LowModule = b.lowModule
tlb.mshr = newMSHR(b.numMSHREntry)
b.createPorts(name, tlb)
tlb.reset()
return tlb
}
func (b Builder) createPorts(name string, tlb *TLB) {
tlb.topPort = sim.NewLimitNumMsgPort(tlb, b.numReqPerCycle,
name+".TopPort")
tlb.AddPort("Top", tlb.topPort)
tlb.bottomPort = sim.NewLimitNumMsgPort(tlb, b.numReqPerCycle,
name+".BottomPort")
tlb.AddPort("Bottom", tlb.bottomPort)
tlb.controlPort = sim.NewLimitNumMsgPort(tlb, 1,
name+".ControlPort")
tlb.AddPort("Control", tlb.controlPort)
}