3 * Copyright (C) 2013 Battelle Memorial Institute
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Evan Felix <evan.felix at pnnl.gov>
25 #include "utils_ignorelist.h"
27 #include <MicAccessTypes.h>
28 #include <MicAccessErrorTypes.h>
29 #include <MicAccessApi.h>
30 #include <MicThermalAPI.h>
35 static MicDeviceOnSystem mics[MAX_MICS];
36 static U32 num_mics = 0;
37 static HANDLE mic_handle = NULL;
39 static int const therm_ids[] = {
40 eMicThermalDie, eMicThermalDevMem, eMicThermalFin, eMicThermalFout,
41 eMicThermalVccp, eMicThermalVddg, eMicThermalVddq };
42 static char const * const therm_names[] = {
43 "die", "devmem", "fin", "fout",
44 "vccp", "vddg", "vddq" };
46 static const char *config_keys[] =
53 "IgnoreSelectedTemperature",
55 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
57 static _Bool show_cpu = 1;
58 static _Bool show_cpu_cores = 1;
59 static _Bool show_memory = 1;
60 static _Bool show_temps = 1;
61 static ignorelist_t *temp_ignore = NULL;
63 static int mic_init (void)
71 mic_count = (U32) STATIC_ARRAY_SIZE(mics);
72 ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &mic_count);
73 if (ret != MIC_ACCESS_API_SUCCESS) {
74 ERROR("mic plugin: Problem initializing MicAccessAPI: %s",
75 MicGetErrorString(ret));
77 DEBUG("mic plugin: found: %"PRIu32" MIC(s)",mic_count);
79 if (mic_count<0 || mic_count>=MAX_MICS) {
80 ERROR("mic plugin: No Intel MICs in system");
89 static int mic_config (const char *key, const char *value) {
90 if (temp_ignore == NULL)
91 temp_ignore = ignorelist_create(1);
92 if (temp_ignore == NULL)
95 if (strcasecmp("ShowCPU",key) == 0)
97 show_cpu = IS_TRUE(value);
99 else if (strcasecmp("ShowCPUCores",key) == 0)
101 show_cpu_cores = IS_TRUE(value);
103 else if (strcasecmp("ShowTemperatures",key) == 0)
105 show_temps = IS_TRUE(value);
107 else if (strcasecmp("ShowMemory",key) == 0)
109 show_memory = IS_TRUE(value);
111 else if (strcasecmp("Temperature",key) == 0)
113 ignorelist_add(temp_ignore,value);
115 else if (strcasecmp("IgnoreSelectedTemperature",key) == 0)
120 ignorelist_set_invert(temp_ignore,invert);
129 static void mic_submit_memory_use(int micnumber, const char *type_instance, U32 val)
132 value_list_t vl = VALUE_LIST_INIT;
134 /* MicAccessAPI reports KB's of memory, adjust for this */
135 DEBUG("mic plugin: Memory Value Report; %u %lf",val,((gauge_t)val)*1024.0);
136 values[0].gauge = ((gauge_t)val)*1024.0;
141 strncpy (vl.host, hostname_g, sizeof (vl.host));
142 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
143 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
144 strncpy (vl.type, "memory", sizeof (vl.type));
145 strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
147 plugin_dispatch_values (&vl);
150 /* Gather memory Utilization */
151 static int mic_read_memory(int mic)
154 U32 mem_total,mem_free,mem_bufs;
156 ret = MicGetMemoryUtilization(mic_handle,&mem_total,&mem_free,&mem_bufs);
157 if (ret != MIC_ACCESS_API_SUCCESS) {
158 ERROR("mic plugin: Problem getting Memory Utilization: %s",
159 MicGetErrorString(ret));
162 mic_submit_memory_use(mic,"free",mem_free);
163 mic_submit_memory_use(mic,"used",mem_total-mem_free-mem_bufs);
164 mic_submit_memory_use(mic,"buffered",mem_bufs);
165 DEBUG("mic plugin: Memory Read: %u %u %u",mem_total,mem_free,mem_bufs);
169 static void mic_submit_temp(int micnumber, const char *type, gauge_t val)
172 value_list_t vl = VALUE_LIST_INIT;
174 values[0].gauge = val;
179 strncpy (vl.host, hostname_g, sizeof (vl.host));
180 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
181 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
183 strncpy (vl.type, "temperature", sizeof (vl.type));
184 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
186 plugin_dispatch_values (&vl);
189 /* Gather Temperature Information */
190 static int mic_read_temps(int mic)
192 size_t num_therms = STATIC_ARRAY_SIZE(therm_ids);
195 for (j = 0; j < num_therms; j++) {
198 U32 buffer_size = (U32)sizeof(temp_buffer);
199 char const *name = therm_names[j];
201 if (ignorelist_match(temp_ignore, name) != 0)
204 status = MicGetTemperature(mic_handle, therm_ids[j],
205 &temp_buffer, &buffer_size);
206 if (status != MIC_ACCESS_API_SUCCESS) {
207 ERROR("mic plugin: Error reading temperature \"%s\": "
208 "%s", name, MicGetErrorString(status));
211 mic_submit_temp(mic, name, temp_buffer);
216 static void mic_submit_cpu(int micnumber, const char *type_instance,
217 int core, derive_t val)
220 value_list_t vl = VALUE_LIST_INIT;
222 values[0].derive = val;
227 strncpy (vl.host, hostname_g, sizeof (vl.host));
228 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
229 if (core < 0) /* global aggregation */
230 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
232 else /* per-core statistics */
233 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
234 "%i-cpu-%i", micnumber, core);
235 strncpy (vl.type, "cpu", sizeof (vl.type));
236 strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
238 plugin_dispatch_values (&vl);
241 /*Gather CPU Utilization Information */
242 static int mic_read_cpu(int mic)
244 MicCoreUtil core_util;
245 MicCoreJiff core_jiffs[MAX_CORES];
249 core_jiffs_size = MAX_CORES * sizeof(MicCoreJiff);
250 status = MicGetCoreUtilization(mic_handle, &core_util,
251 core_jiffs, &core_jiffs_size);
252 if (status != MIC_ACCESS_API_SUCCESS) {
253 ERROR("mic plugin: Problem getting CPU utilization: %s",
254 MicGetErrorString(status));
259 mic_submit_cpu(mic, "user", -1, core_util.sum.user);
260 mic_submit_cpu(mic, "sys", -1, core_util.sum.sys);
261 mic_submit_cpu(mic, "nice", -1, core_util.sum.nice);
262 mic_submit_cpu(mic, "idle", -1, core_util.sum.idle);
265 if (show_cpu_cores) {
267 for (j = 0; j < core_util.core; j++) {
268 mic_submit_cpu(mic, "user", j, core_jiffs[j].user);
269 mic_submit_cpu(mic, "sys", j, core_jiffs[j].sys);
270 mic_submit_cpu(mic, "nice", j, core_jiffs[j].nice);
271 mic_submit_cpu(mic, "idle", j, core_jiffs[j].idle);
277 static int mic_read (void)
284 for (i=0;i<num_mics;i++) {
285 ret = MicInitAdapter(&mic_handle,&mics[i]);
286 if (ret != MIC_ACCESS_API_SUCCESS) {
287 ERROR("mic plugin: Problem initializing MicAdapter: %s",
288 MicGetErrorString(ret));
292 if (error == 0 && show_memory)
293 error = mic_read_memory(i);
295 if (error == 0 && show_temps)
296 error = mic_read_temps(i);
298 if (error == 0 && (show_cpu || show_cpu_cores))
299 error = mic_read_cpu(i);
301 ret = MicCloseAdapter(mic_handle);
302 if (ret != MIC_ACCESS_API_SUCCESS) {
303 ERROR("mic plugin: Problem closing MicAdapter: %s",
304 MicGetErrorString(ret));
315 static int mic_shutdown (void)
318 MicCloseAPI(&mic_handle);
322 void module_register (void)
324 plugin_register_init ("mic", mic_init);
325 plugin_register_shutdown ("mic", mic_shutdown);
326 plugin_register_read ("mic", mic_read);
327 plugin_register_config ("mic",mic_config, config_keys, config_keys_num);
328 } /* void module_register */
331 * vim: set shiftwidth=8 softtabstop=8 noet textwidth=78 :