Do not enable unused per core interrupts by default (#4519)
Costa Tsaousis committed
Oct 30, 2018 at 23:24 UTC
1e365a68325cd6e5296cb3eafcf25cc3b03e3902
3 files changed
+52
-63
collectors/proc.plugin/proc_interrupts.c
+26
-32
@@ -56,16 +56,16 @@ static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) {
56
int do_proc_interrupts(int update_every, usec_t dt) {
57
(void)dt;
58
static procfile *ff = NULL;
59
- static int cpus = -1, do_per_core = -1;
59
+ static int cpus = -1, do_per_core = CONFIG_BOOLEAN_INVALID;
60
struct interrupt *irrs = NULL;
61
62
- if(unlikely(do_per_core == -1))
63
- do_per_core = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "interrupts per core", 1);
62
+ if(unlikely(do_per_core == CONFIG_BOOLEAN_INVALID))
63
+ do_per_core = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "interrupts per core", CONFIG_BOOLEAN_AUTO);
64
65
if(unlikely(!ff)) {
66
char filename[FILENAME_MAX + 1];
67
snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/interrupts");
68
- ff = procfile_open(config_get(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
68
+ ff = procfile_open(config_get(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
69
}
70
if(unlikely(!ff))
71
return 1;
@@ -113,6 +113,10 @@ int do_proc_interrupts(int update_every, usec_t dt) {
113
irr->id = procfile_lineword(ff, l, 0);
114
if(unlikely(!irr->id || !irr->id[0])) continue;
115
116
+ size_t idlen = strlen(irr->id);
117
+ if(irr->id[idlen - 1] == ':')
118
+ irr->id[--idlen] = '\0';
119
+
120
int c;
121
for(c = 0; c < cpus ;c++) {
122
if(likely((c + 1) < (int)words))
@@ -126,7 +130,6 @@ int do_proc_interrupts(int update_every, usec_t dt) {
130
if(unlikely(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words)) {
131
strncpyz(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME);
132
size_t nlen = strlen(irr->name);
129
- size_t idlen = strlen(irr->id);
133
if(likely(nlen + 1 + idlen <= MAX_INTERRUPT_NAME)) {
134
irr->name[nlen] = '_';
135
strncpyz(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen - 1);
@@ -166,34 +169,30 @@ int do_proc_interrupts(int update_every, usec_t dt) {
169
170
for(l = 0; l < lines ;l++) {
171
struct interrupt *irr = irrindex(irrs, l, cpus);
169
- if(unlikely(!irr->used)) continue;
170
-
171
- // some interrupt may have changed without changing the total number of lines
172
- // if the same number of interrupts have been added and removed between two
173
- // calls of this function.
174
- if(unlikely(!irr->rd || strncmp(irr->rd->name, irr->name, MAX_INTERRUPT_NAME) != 0)) {
175
- irr->rd = rrddim_find(st_system_interrupts, irr->id);
176
-
177
- if(unlikely(!irr->rd))
172
+ if(irr->used && irr->total) {
173
+ // some interrupt may have changed without changing the total number of lines
174
+ // if the same number of interrupts have been added and removed between two
175
+ // calls of this function.
176
+ if(unlikely(!irr->rd || strncmp(irr->rd->name, irr->name, MAX_INTERRUPT_NAME) != 0)) {
177
irr->rd = rrddim_add(st_system_interrupts, irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL);
179
- else
178
rrddim_set_name(st_system_interrupts, irr->rd, irr->name);
179
182
- // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop
183
- if(likely(do_per_core)) {
184
- int c;
185
- for (c = 0; c < cpus ;c++) irr->cpu[c].rd = NULL;
180
+ // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop
181
+ if(likely(do_per_core != CONFIG_BOOLEAN_NO)) {
182
+ int c;
183
+ for(c = 0; c < cpus; c++) irr->cpu[c].rd = NULL;
184
+ }
185
}
187
- }
186
189
- rrddim_set_by_pointer(st_system_interrupts, irr->rd, irr->total);
187
+ rrddim_set_by_pointer(st_system_interrupts, irr->rd, irr->total);
188
+ }
189
}
190
191
rrdset_done(st_system_interrupts);
192
193
// --------------------------------------------------------------------
194
196
- if(likely(do_per_core)) {
195
+ if(likely(do_per_core != CONFIG_BOOLEAN_NO)) {
196
static RRDSET **core_st = NULL;
197
static int old_cpus = 0;
198
@@ -231,19 +230,14 @@ int do_proc_interrupts(int update_every, usec_t dt) {
230
231
for(l = 0; l < lines ;l++) {
232
struct interrupt *irr = irrindex(irrs, l, cpus);
234
-
235
- if(unlikely(!irr->used)) continue;
236
-
237
- if(unlikely(!irr->cpu[c].rd)) {
238
- irr->cpu[c].rd = rrddim_find(core_st[c], irr->id);
239
-
240
- if(unlikely(!irr->cpu[c].rd))
233
+ if(irr->used && (do_per_core == CONFIG_BOOLEAN_YES || irr->cpu[c].value)) {
234
+ if(unlikely(!irr->cpu[c].rd)) {
235
irr->cpu[c].rd = rrddim_add(core_st[c], irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL);
242
- else
236
rrddim_set_name(core_st[c], irr->cpu[c].rd, irr->name);
244
- }
237
+ }
238
246
- rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value);
239
+ rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value);
240
+ }
241
}
242
243
rrdset_done(core_st[c]);
collectors/proc.plugin/proc_softirqs.c
+21
-28
@@ -55,10 +55,11 @@ static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) {
55
int do_proc_softirqs(int update_every, usec_t dt) {
56
(void)dt;
57
static procfile *ff = NULL;
58
- static int cpus = -1, do_per_core = -1;
58
+ static int cpus = -1, do_per_core = CONFIG_BOOLEAN_INVALID;
59
struct interrupt *irrs = NULL;
60
61
- if(unlikely(do_per_core == -1)) do_per_core = config_get_boolean("plugin:proc:/proc/softirqs", "interrupts per core", 1);
61
+ if(unlikely(do_per_core == CONFIG_BOOLEAN_INVALID))
62
+ do_per_core = config_get_boolean_ondemand("plugin:proc:/proc/softirqs", "interrupts per core", CONFIG_BOOLEAN_AUTO);
63
64
if(unlikely(!ff)) {
65
char filename[FILENAME_MAX + 1];
@@ -148,34 +149,30 @@ int do_proc_softirqs(int update_every, usec_t dt) {
149
for(l = 0; l < lines ;l++) {
150
struct interrupt *irr = irrindex(irrs, l, cpus);
151
151
- if(unlikely(!irr->used)) continue;
152
-
153
- // some interrupt may have changed without changing the total number of lines
154
- // if the same number of interrupts have been added and removed between two
155
- // calls of this function.
156
- if(unlikely(!irr->rd || strncmp(irr->name, irr->rd->name, MAX_INTERRUPT_NAME) != 0)) {
157
- irr->rd = rrddim_find(st_system_softirqs, irr->id);
158
-
159
- if(unlikely(!irr->rd))
152
+ if(irr->used && irr->total) {
153
+ // some interrupt may have changed without changing the total number of lines
154
+ // if the same number of interrupts have been added and removed between two
155
+ // calls of this function.
156
+ if(unlikely(!irr->rd || strncmp(irr->name, irr->rd->name, MAX_INTERRUPT_NAME) != 0)) {
157
irr->rd = rrddim_add(st_system_softirqs, irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL);
161
- else
158
rrddim_set_name(st_system_softirqs, irr->rd, irr->name);
159
164
- // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop
165
- if(likely(do_per_core)) {
166
- int c;
167
- for (c = 0; c < cpus ;c++) irr->cpu[c].rd = NULL;
160
+ // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop
161
+ if(likely(do_per_core != CONFIG_BOOLEAN_NO)) {
162
+ int c;
163
+ for(c = 0; c < cpus; c++) irr->cpu[c].rd = NULL;
164
+ }
165
}
169
- }
166
171
- rrddim_set_by_pointer(st_system_softirqs, irr->rd, irr->total);
167
+ rrddim_set_by_pointer(st_system_softirqs, irr->rd, irr->total);
168
+ }
169
}
170
171
rrdset_done(st_system_softirqs);
172
173
// --------------------------------------------------------------------
174
178
- if(do_per_core) {
175
+ if(do_per_core != CONFIG_BOOLEAN_NO) {
176
static RRDSET **core_st = NULL;
177
static int old_cpus = 0;
178
@@ -227,18 +224,14 @@ int do_proc_softirqs(int update_every, usec_t dt) {
224
for(l = 0; l < lines ;l++) {
225
struct interrupt *irr = irrindex(irrs, l, cpus);
226
230
- if(unlikely(!irr->used)) continue;
231
-
232
- if(unlikely(!irr->cpu[c].rd)) {
233
- irr->cpu[c].rd = rrddim_find(core_st[c], irr->id);
234
-
235
- if(unlikely(!irr->cpu[c].rd))
227
+ if(irr->used && (do_per_core == CONFIG_BOOLEAN_YES || irr->cpu[c].value)) {
228
+ if(unlikely(!irr->cpu[c].rd)) {
229
irr->cpu[c].rd = rrddim_add(core_st[c], irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL);
237
- else
230
rrddim_set_name(core_st[c], irr->cpu[c].rd, irr->name);
239
- }
231
+ }
232
241
- rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value);
233
+ rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value);
234
+ }
235
}
236
237
rrdset_done(core_st[c]);
libnetdata/config/appconfig.h
+5
-3
@@ -102,11 +102,13 @@ struct config {
102
avl_tree_lock index;
103
};
104
105
-#define CONFIG_BOOLEAN_NO 0
106
-#define CONFIG_BOOLEAN_YES 1
105
+#define CONFIG_BOOLEAN_INVALID 100 // an invalid value to check for validity (used as default initialization when needed)
106
+
107
+#define CONFIG_BOOLEAN_NO 0 // disabled
108
+#define CONFIG_BOOLEAN_YES 1 // enabled
109
110
#ifndef CONFIG_BOOLEAN_AUTO
109
-#define CONFIG_BOOLEAN_AUTO 2
111
+#define CONFIG_BOOLEAN_AUTO 2 // enabled if it has useful info when enabled
112
#endif
113
114
extern int appconfig_load(struct config *root, char *filename, int overwrite_used);