-
Notifications
You must be signed in to change notification settings - Fork 2
/
mig_mon.h
179 lines (156 loc) · 4.46 KB
/
mig_mon.h
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
#ifndef __MIG_MON_H__
#define __MIG_MON_H__
#ifdef __linux__
#define _GNU_SOURCE
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <stdbool.h>
#ifdef __linux__
#include <linux/mman.h>
#endif
#include "utils.h"
#define MAX(a, b) ((a > b) ? (a) : (b))
#define MIN(a, b) ((a < b) ? (a) : (b))
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
typedef enum {
PATTERN_SEQ = 0,
PATTERN_RAND = 1,
PATTERN_ONCE = 2,
PATTERN_NUM,
} dirty_pattern;
/* whether allow client change its IP */
#define MIG_MON_SINGLE_CLIENT (0)
#define MIG_MON_PORT (12323)
#define MIG_MON_INT_DEF (1000)
#define BUF_LEN (1024)
#define MIG_MON_SPIKE_LOG_DEF ("/tmp/spike.log")
#define DEF_MM_DIRTY_SIZE (512)
#define DEF_MM_DIRTY_PATTERN PATTERN_SEQ
/******************
* For mig_mon.c *
******************/
extern short mig_mon_port;
extern long n_cpus;
extern long page_size, huge_page_size;
extern const char *pattern_str[PATTERN_NUM];
extern const char *prog_name;
/******************
* For downtime.c *
******************/
/* Mig_mon callbacks. Return 0 for continue, non-zero for errors. */
typedef int (*mon_server_cbk)(int sock, int spike_fd);
typedef int (*mon_client_cbk)(int sock, int spike_fd, int interval_ms);
int mon_server_callback(int sock, int spike_fd);
int mon_server_rr_callback(int sock, int spike_fd);
int mon_server(const char *spike_log, mon_server_cbk server_callback);
int mon_client_callback(int sock, int spike_fd, int interval_ms);
int mon_client_rr_callback(int sock, int spike_fd, int interval_ms);
int mon_client(const char *server_ip, int interval_ms,
const char *spike_log, mon_client_cbk client_callback);
void usage_downtime_short(void);
void usage_downtime(void);
/******************
* For mm_dirty.c *
******************/
typedef struct {
/* Size of the memory to test on */
uint64_t mm_size;
/* Dirty rate (in MB/s) */
uint64_t dirty_rate;
/* mmap() flags to pass over */
unsigned int map_flags;
/* Dirty pattern */
dirty_pattern pattern;
/* Whether we're recording the memory access latencies */
bool record_latencies;
} mm_dirty_args;
int mon_mm_dirty(mm_dirty_args *args);
void usage_mm_dirty_short(void);
void usage_mm_dirty(void);
/**************
* For vm.c *
**************/
/* If set, will generate precopy live migration stream */
#define VM_TEST_PRECOPY (1UL << 0)
/* If set, will generate postcopy page requests */
#define VM_TEST_POSTCOPY (1UL << 1)
#define DEF_VM_SIZE (1UL << 40) /* 1TB */
typedef enum {
EMULATE_NONE = 0,
EMULATE_SRC = 1,
EMULATE_DST = 2,
EMULATE_NUM,
} emulate_target;
typedef struct {
int sock;
emulate_target target;
unsigned int tests;
/* Whether we should quit */
int quit;
/* Guest memory size (emulated) */
uint64_t vm_size;
/*
* Both the src/dst VMs have these threads, even if they do not mean the
* same workload will be run, we share the fields.
*/
pthread_t sender;
pthread_t receiver;
/*
* Maintaining receiving sockets
*/
/* Size = DEF_IO_BUF_SIZE */
char *recv_buffer;
/* Length of data consumed */
int recv_cur;
/* Length of data in recv_buffer */
int recv_len;
/*
* When on src: used to emulate page req queue.
* When on dst: used to notify when a page req is resolved.
*
* Data is page offset (u64), always.
*/
int page_req_pipe[2];
union {
/* Only needed on src VM */
struct {
/* Size = MAX_IOV_SIZE * DEF_IO_BUF_SIZE */
struct iovec *src_iov_buffer;
/* Dest VM ip */
const char *src_target_ip;
/* Points to the current IOV being used */
int src_cur;
/* Length of current IOV that has been consumed */
size_t src_cur_len;
};
/* Only needed on dst VM */
struct {
/* Current page to request */
uint64_t dst_current_req;
};
};
} vm_args;
int mon_vm(vm_args *args);
void usage_vm(void);
void usage_vm_short(void);
#endif