FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
virt_aio_ctx.h
1 #ifndef __VIRT_AIO_CTX_H__
2 #define __VIRT_AIO_CTX_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of SAFSlib.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "container.h"
24 #include "wpaio.h"
25 
26 namespace safs
27 {
28 
29 struct req_entry {
30  struct iocb *req;
31  struct timeval issue_time;
32 };
33 
34 /*
35  * This class defines the data inside the virtual SSDs.
36  */
37 class virt_data
38 {
39 public:
40  virtual void create_data(int fd, void *data, int size, off_t off) = 0;
41  virtual bool verify_data(int fd, void *data, int size, off_t off) = 0;
42 };
43 
44 class ssd_perf_model
45 {
46 public:
47  virtual long get_read_delay(off_t off, size_t size) = 0;
48  virtual long get_write_delay(off_t off, size_t size) = 0;
49 };
50 
51 /*
52  * This emulates an SSD and provides the interface of an AIO context.
53  * It is used for performance evaluation and debugging.
54  * It accepts requests and returns them after a certain period of time.
55  * The delay from the virtual AIO instance should be similar to the delay
56  * from an SSD.
57  */
58 class virt_aio_ctx: public aio_ctx
59 {
60  int max_aio;
61  fifo_queue<struct req_entry> pending_reqs;
62  virt_data *data;
63  ssd_perf_model *model;
64 
65  long read_bytes;
66  long write_bytes;
67  long read_bytes_ps; // the bytes to read within a second.
68  long write_bytes_ps; // the bytes to write within a second.
69  struct timeval prev_print_time;
70 public:
71  virt_aio_ctx(virt_data *data, int node_id, int max_aio);
72 
73  virtual void submit_io_request(struct iocb* ioq[], int num);
74  virtual int io_wait(struct timespec* to, int num);
75 
76  virtual int max_io_slot();
77 
78  virtual void print_stat() {
79  printf("the virtual AIO context reads %ld bytes and writes %ld bytes\n",
80  read_bytes, write_bytes);
81  }
82 };
83 
84 }
85 
86 #endif