-
Notifications
You must be signed in to change notification settings - Fork 4
/
Option.h
170 lines (135 loc) · 3.72 KB
/
Option.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
/*
* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2018 Intel Corporation
*
* Authors: Fengguang Wu <[email protected]>
* Yao Yuan <[email protected]>
*/
#ifndef _OPTION_H
#define _OPTION_H
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
typedef enum {
MIGRATE_NONE,
MIGRATE_HOT,
MIGRATE_COLD,
MIGRATE_BOTH = MIGRATE_HOT | MIGRATE_COLD,
MIGRATE_END,
} MigrateWhat;
typedef enum {
PLACEMENT_NONE,
PLACEMENT_DRAM, // skip scan, assuming mlock'ed in DRAM
PLACEMENT_PMEM, // no effect for now
PLACEMENT_END,
} Placement;
struct Policy
{
Policy() {
pid = -1;
migrate_what = MIGRATE_NONE;
placement = PLACEMENT_NONE;
dump_distribution = false;
}
pid_t pid;
std::string name;
MigrateWhat migrate_what;
Placement placement;
bool dump_distribution;
};
typedef std::vector<Policy> PolicySet;
struct NumaHWConfig{
bool is_valid() {
return numa_dram_list.size()
|| numa_pmem_list.size()
|| pmem_dram_map.size();
}
std::string numa_dram_list;
std::string numa_pmem_list;
std::string pmem_dram_map;
};
typedef std::unordered_map<std::string, std::string> NumaHWConfigEntry;
typedef std::vector<NumaHWConfigEntry> NumaHWConfigV2;
struct Option
{
int set_dram_percent(int dp);
int add_policy(Policy& new_policy);
PolicySet& get_policies() {
return policies;
}
void dump();
static MigrateWhat parse_migrate_name(std::string name);
template<typename Tmap, typename Tval>
static int parse_str_from_map(Tmap& map, std::string &name, Tval& val)
{
auto search = map.find(name);
if (search != map.end()) {
val = search->second;
return 0;
}
return -1;
}
template<typename Tmap, typename Tval>
static int parse_name_map(Tmap& map, std::string name, Tval& val, int max_val)
{
if (isdigit(name[0])) {
int m = atoi(name.c_str());
if (m >= max_val) {
std::cerr << "invalid value: " << name << std::endl;
return -1;
}
val = (Tval) m;
return 0;
}
if (parse_str_from_map(map, name, val) < 0) {
std::cerr << "invalid value: " << name << std::endl;
return -2;
}
return 0;
}
public:
int debug_level = 0;
static const int DRAM_NUMA_NODE = 0;
static const int PMEM_NUMA_NODE = 1;
static std::unordered_map<std::string, bool> bool_name_map;
static std::unordered_map<std::string, MigrateWhat> migrate_name_map;
static std::unordered_map<std::string, Placement> placement_name_map;
pid_t pid = -1;
float initial_interval = 0.1;
float interval = 0; // auto adjust
float sleep_secs = 1;
int max_walks = 10;
int nr_walks = 0; // auto stop when nr_top_pages can fit in half DRAM size
int nr_loops = 0;
// set either dram_percent or hot_min_refs/cold_max_refs, but not both
int dram_percent = 0;
int hot_min_refs = -1;
int cold_max_refs = -1;
int exit_on_stabilized = 0; // percent moved
bool exit_on_exceeded = false; // when exceed dram_percent
bool dump_options = false;
bool dump_processes = false;
int hugetlb = 0;
int thp = 0;
int max_threads = 0;
std::string split_rss_size; // no split task address space
float bandwidth_mbps = 0;
MigrateWhat migrate_what = MIGRATE_HOT;
std::string output_file;
std::string config_file;
NumaHWConfig numa_hw_config;
NumaHWConfigV2 numa_hw_config_v2;
int debug_move_pages = 0;
bool daemon = false;
bool show_numa_stats = false;
// Not used for now, so current sys-refs behavior is to ignore all processes
// w/o a policy defined. In future, may consider applying this to all
// processes in ProcessCollection::collect().
// Policy default_policy;
private:
PolicySet policies;
};
#endif
// vim:set ts=2 sw=2 et: