Repository navigation
Expand file tree
/
Copy pathcontroller.h
More file actions
216 lines (172 loc) · 4.71 KB
/
Copy pathcontroller.h
File metadata and controls
216 lines (172 loc) · 4.71 KB
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
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <deque>
#include <list>
#include <vector>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/composite_key.hpp>
#include "iosrc.h"
#include "common_def.h"
using namespace boost::multi_index;
// 512 sector = 256kB
#define DEF_STRIPE_SECT 512
typedef struct {
uint64_t max_lba;
} DriveInfo;
typedef enum {
RAID5
} RAID_TYPE;
typedef struct {
std::vector<DriveInfo*> drive_list;
RAID_TYPE rg_type;
uint64_t max_lba;
uint32_t drive_num;
uint64_t stripe_width;
uint32_t stripe_size;
} RGInfo;
typedef struct {
} RGOption;
typedef struct {
uint32_t tgt_drive;
CommandInfo cmd_info;
} DriveCommandInfo;
typedef struct {
uint64_t hcmd_count;
uint64_t hcmd_rd_count;
uint64_t hcmd_wr_count;
uint64_t hcmd_rd_sect;
uint64_t hcmd_wr_sect;
uint64_t drvcmd_count;
uint64_t drv_rd_count;
uint64_t drv_wr_count;
uint64_t drv_rd_sect;
uint64_t drv_wr_sect;
} CTL_STATISTICS;
typedef struct {
uint64_t drv_gc_rd_count;
uint64_t drv_gc_wr_count;
uint64_t drv_gc_rd_sect;
uint64_t drv_gc_wr_sect;
} CTL_COMP_STATISTICS;
class Controller
{
public:
Controller();
virtual ~Controller(){}
// multi RG isnt supported
virtual bool build_raid(RAID_TYPE type, std::vector<DriveInfo*>& drive_list, uint32_t stripe_size = DEF_STRIPE_SECT);
// host to controller
virtual bool receive_command(const CommandInfo&);
// controller to drive
virtual bool pull_next_command(DriveCommandInfo&);
virtual void print_statistics();
virtual void clear_statistics();
virtual uint64_t get_max_lba() { return max_lba;}
protected:
std::list<RGInfo> rg_list;
std::list<DriveCommandInfo> pending_cmd;
CTL_STATISTICS stats;
uint64_t max_lba;
virtual bool raid_translation(const CommandInfo& org_command, std::list<DriveCommandInfo>& cmd_list);
virtual void record_statis(const CommandInfo& cmd);
virtual void record_statis(const DriveCommandInfo& cmd);
};
class CompEngine;
class CompController : public Controller
{
public:
CompController();
virtual ~CompController();
bool init(CompEngine* cmp_engine, double gc_buffer_ratio = 0.8, uint64_t chunk_sector_size = 16);
virtual uint64_t get_max_lba(){ return virtual_max_lba;}
// host to controller
virtual bool receive_command(const CommandInfo&);
// controller to drive
virtual bool pull_next_command(DriveCommandInfo&);
virtual void print_statistics();
virtual void clear_statistics();
uint64_t get_lp_num() { return lp_num;}
void print_map();
bool do_gc();
private:
typedef struct {
uint32_t lb_id;
uint32_t ofs;
uint32_t len;
} LPMAP;
typedef struct {
uint32_t ofs;
uint64_t lpn;
} REVMAP;
typedef enum {
LB_FREE = 0,
LB_OPEN = 1,
LB_CLOSE = 2
} LOGBLOCK_STATE;
typedef struct {
uint32_t id;
LOGBLOCK_STATE state;
uint32_t free_sector_num;
std::deque<REVMAP> rev_map;
} LOGBLOCK;
typedef struct {
LOGBLOCK* tgt_lgblock;
uint32_t cur_sector;
} BUFINFO;
typedef struct {
uint64_t lpn;
bool rmw_needed;
} LPCMD;
struct free_sector {};
typedef composite_key<
LOGBLOCK,
BOOST_MULTI_INDEX_MEMBER(LOGBLOCK, LOGBLOCK_STATE, state),
BOOST_MULTI_INDEX_MEMBER(LOGBLOCK, uint32_t, free_sector_num)
> key_t;
typedef composite_key_compare <
std::greater<uint32_t>,
std::greater<uint32_t>
> key_comp;
typedef multi_index_container<
LOGBLOCK*,
indexed_by<
random_access<>,
ordered_non_unique<tag<free_sector>, key_t, key_comp >
>
> LB_SORTED_LIST;
//typedef LB_SORTED_LIST::index<free_sector>::type::iterator LB_ITR;
CompEngine* cmp_engine;
BUFINFO buf;
LPMAP* lpt;
LOGBLOCK* lbt;
LB_SORTED_LIST lb_list;
std::deque<LOGBLOCK*> free_list;
std::deque<LOGBLOCK*> destage_tgt;
uint64_t real_data_size;
uint64_t virtual_max_lba;
uint64_t lb_num;
uint64_t lp_num;
CTL_COMP_STATISTICS cmp_stats;
// given parameter
double real_data_ratio;
double avg_comp_ratio;
uint64_t gc_threshold;
uint64_t lb_size;
uint64_t lp_size;
// function
bool extract_hcmd_to_lp(const CommandInfo& host_cmd, std::list<LPCMD>& lp_list);
bool close_buf_and_open_next();
bool is_buf_full(BUFINFO& buf, uint32_t next_data_len) { return buf.cur_sector + next_data_len > lb_size;}
bool lp_read(uint64_t lp_no);
bool lp_write(uint64_t lp_no);
uint32_t do_compression(uint32_t org_data_size);
uint64_t calc_lp_no(uint64_t host_lba);
uint64_t calc_raid_addr(uint32_t lb_id, uint32_t ofs);
void update_lb_list(LOGBLOCK* lb);
};
#endif