-
Notifications
You must be signed in to change notification settings - Fork 4
/
ssd_event.cpp
270 lines (227 loc) · 5.88 KB
/
ssd_event.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* Copyright 2009, 2010 Brendan Tauras */
/* ssd_event.cpp is part of FlashSim. */
/* FlashSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version. */
/* FlashSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. */
/* You should have received a copy of the GNU General Public License
* along with FlashSim. If not, see <http://www.gnu.org/licenses/>. */
/****************************************************************************/
/* Event class
* Brendan Tauras 2010-07-16
*
* Class to manage I/O requests as events for the SSD. It was designed to keep
* track of an I/O request by storing its type, addressing, and timing. The
* SSD class creates an instance for each I/O request it receives.
*/
#include <assert.h>
#include <stdio.h>
#include "ssd.h"
using namespace ssd;
/* see "enum event_type" in ssd.h for details on event types */
Event::Event(enum event_type type, ulong logical_address, uint size, double start_time):
start_time(start_time),
time_taken(0.0),
bus_wait_time(0.0),
type(type),
logical_address(logical_address),
size(size),
payload(NULL),
next(NULL),
noop(false)
{
assert(start_time >= 0.0);
return;
}
Event::~Event(void)
{
return;
}
/* find the last event in the list to finish and use that event's finish time
* to calculate time_taken
* add bus_wait_time for all events in the list to bus_wait_time
* all events in the list do not need to start at the same time
* bus_wait_time can potentially exceed time_taken with long event lists
* because bus_wait_time is a sum while time_taken is a max
* be careful to only call this method once when the metaevent is finished */
void Event::consolidate_metaevent(Event &list)
{
Event *cur;
double max;
double tmp;
assert(start_time >= 0);
/* find max time taken with respect to this event's start_time */
max = start_time - list.start_time + list.time_taken;
for(cur = list.next; cur != NULL; cur = cur -> next)
{
tmp = start_time - cur -> start_time + cur -> time_taken;
if(tmp > max)
max = tmp;
bus_wait_time += cur -> get_bus_wait_time();
}
time_taken = max;
assert(time_taken >= 0);
assert(bus_wait_time >= 0);
return;
}
ssd::ulong Event::get_logical_address(void) const
{
return logical_address;
}
const Address &Event::get_address(void) const
{
return address;
}
const Address &Event::get_merge_address(void) const
{
return merge_address;
}
const Address &Event::get_log_address(void) const
{
return log_address;
}
const Address &Event::get_replace_address(void) const
{
return replace_address;
}
void Event::set_log_address(const Address &address)
{
log_address = address;
}
ssd::uint Event::get_size(void) const
{
return size;
}
enum event_type Event::get_event_type(void) const
{
return type;
}
void Event::set_event_type(const enum event_type &type)
{
this->type = type;
}
double Event::get_start_time(void) const
{
assert(start_time >= 0.0);
return start_time;
}
double Event::get_time_taken(void) const
{
assert(time_taken >= 0.0);
return time_taken;
}
double Event::get_bus_wait_time(void) const
{
assert(bus_wait_time >= 0.0);
return bus_wait_time;
}
bool Event::get_noop(void) const
{
return noop;
}
Event *Event::get_next(void) const
{
return next;
}
void Event::set_payload(void *payload)
{
this->payload = payload;
}
void *Event::get_payload(void) const
{
return payload;
}
void Event::set_address(const Address &address)
{
this -> address = address;
return;
}
void Event::set_merge_address(const Address &address)
{
merge_address = address;
return;
}
void Event::set_replace_address(const Address &address)
{
replace_address = address;
}
void Event::set_noop(bool value)
{
noop = value;
}
void Event::set_next(Event &next)
{
this -> next = &next;
return;
}
double Event::incr_bus_wait_time(double time_incr)
{
if(time_incr > 0.0)
bus_wait_time += time_incr;
return bus_wait_time;
}
double Event::incr_time_taken(double time_incr)
{
//printf("\nEvent::incr_time_taken +++++++++++++++\n");
if(time_incr > 0.0)
time_taken += time_incr;
return time_taken;
}
void Event::print(FILE *stream)
{
if(type == READ)
fprintf(stream, "Read ");
else if(type == WRITE)
fprintf(stream, "Write");
else if(type == ERASE)
fprintf(stream, "Erase");
else if(type == MERGE)
fprintf(stream, "Merge");
else
fprintf(stream, "Unknown event type: ");
address.print(stream);
if(type == MERGE)
merge_address.print(stream);
fprintf(stream, " Time[%f, %f) Bus_wait: %f\n", start_time, start_time + time_taken, bus_wait_time);
return;
}
#if 0
/* may be useful for further integration with DiskSim */
/* caution: copies pointers from rhs */
ioreq_event &Event::operator= (const ioreq_event &rhs)
{
assert(&rhs != NULL);
if((const ioreq_event *) &rhs == (const ioreq_event *) &(this -> ioreq))
return *(this -> ioreq);
ioreq -> time = rhs.time;
ioreq -> type = rhs.type;
ioreq -> next = rhs.next;
ioreq -> prev = rhs.prev;
ioreq -> bcount = rhs.bcount;
ioreq -> blkno = rhs.blkno;
ioreq -> flags = rhs.flags;
ioreq -> busno = rhs.busno;
ioreq -> slotno = rhs.slotno;
ioreq -> devno = rhs.devno;
ioreq -> opid = rhs.opid;
ioreq -> buf = rhs.buf;
ioreq -> cause = rhs.cause;
ioreq -> tempint1 = rhs.tempint1;
ioreq -> tempint2 = rhs.tempint2;
ioreq -> tempptr1 = rhs.tempptr1;
ioreq -> tempptr2 = rhs.tempptr2;
ioreq -> mems_sled = rhs.mems_sled;
ioreq -> mems_reqinfo = rhs.mems_reqinfo;
ioreq -> start_time = rhs.start_time;
ioreq -> batchno = rhs.batchno;
ioreq -> batch_complete = rhs.batch_complete;
ioreq -> batch_size = rhs.batch_size;
ioreq -> batch_next = rhs.batch_next;
ioreq -> batch_prev = rhs.batch_prev;
return *ioreq;
}
#endif