forked from MatiasBjorling/flashsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssd_raidssd.cpp
122 lines (103 loc) · 3.42 KB
/
ssd_raidssd.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
/* Copyright 2012 Matias Bjørling */
/* 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/>. */
/****************************************************************************/
/* Ssd class
* Matias Bjørling 2012-01-09
*
* The Raid SSD is responsible for raiding multiple SSDs together using different mapping techniques.
*/
#include <cmath>
#include <new>
#include <assert.h>
#include <stdio.h>
#include "ssd.h"
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
using namespace ssd;
/* use caution when editing the initialization list - initialization actually
* occurs in the order of declaration in the class definition and not in the
* order listed here */
RaidSsd::RaidSsd(uint ssd_size):
size(ssd_size)
{
/*
* Idea
*
* Create the instances of the SSDs.
*
* Techniques
*
* 1. Striping
* 2. Address splitting.
* 3. Complete control
*/
Ssds = new Ssd[RAID_NUMBER_OF_PHYSICAL_SSDS];
return;
}
RaidSsd::~RaidSsd(void)
{
return;
}
double RaidSsd::event_arrive(enum event_type type, ulong logical_address, uint size, double start_time)
{
return event_arrive(type, logical_address, size, start_time, NULL);
}
/* This is the function that will be called by DiskSim
* Provide the event (request) type (see enum in ssd.h),
* logical_address (page number), size of request in pages, and the start
* time (arrive time) of the request
* The SSD will process the request and return the time taken to process the
* request. Remember to use the same time units as in the config file. */
double RaidSsd::event_arrive(enum event_type type, ulong logical_address, uint size, double start_time, void *buffer)
{
if (type == WRITE)
printf("Writing to logical address: %lu\n", logical_address);
else if (type == READ)
printf("Read from logical address: %lu\n", logical_address);
if (PARALLELISM_MODE == 1) // Striping
{
double timings[RAID_NUMBER_OF_PHYSICAL_SSDS];
for (int i=0;i<RAID_NUMBER_OF_PHYSICAL_SSDS;i++)
{
if (buffer == NULL)
{
printf("Executing stage: %i\n", i);
timings[i] = Ssds[i].event_arrive(type, logical_address, size, start_time, NULL);
}
else
timings[i] = Ssds[i].event_arrive(type, logical_address, size, start_time, (char*)buffer +(i*PAGE_SIZE));
}
for (int i=0;i<RAID_NUMBER_OF_PHYSICAL_SSDS-1;i++)
{
if (timings[i] != timings[i+1])
fprintf(stderr, "ERROR: Timings are not the same. %d %d\n", timings[i], timings[i+1]);
}
return timings[0];
}
else if (PARALLELISM_MODE == 2) // Splitted address space
{
return Ssds[logical_address%RAID_NUMBER_OF_PHYSICAL_SSDS].event_arrive(type, logical_address, size, start_time, (char*)buffer);
}
return 0;
}
/*
* Returns a pointer to the global buffer of the Ssd.
* It is up to the user to not read out of bound and only
* read the intended size. i.e. the page size.
*/
void *RaidSsd::get_result_buffer()
{
return global_buffer;
}