X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmic.c;h=ab5ffd1b687beb26b910c0838f710dcc7165fa2a;hb=936c450a86c841eea89888c8550c9118fae90c25;hp=eec55f1be2dd9b6c775d2937458c51734f219a32;hpb=ad02e903bac893fa907a1131295be2b3d310991e;p=collectd.git diff --git a/src/mic.c b/src/mic.c index eec55f1b..ab5ffd1b 100644 --- a/src/mic.c +++ b/src/mic.c @@ -16,17 +16,19 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Evan Felix + * Evan Felix **/ #include "collectd.h" -#include "plugin.h" + #include "common.h" +#include "plugin.h" #include "utils_ignorelist.h" -#include -#include #include +#include +#include +#include #include #define MAX_MICS 32 @@ -34,273 +36,337 @@ static MicDeviceOnSystem mics[MAX_MICS]; static U32 num_mics = 0; -static HANDLE mic_handle=NULL; -#define NUM_THERMS 7 -static const int therms[NUM_THERMS] = {eMicThermalDie,eMicThermalDevMem,eMicThermalFin,eMicThermalFout,eMicThermalVccp,eMicThermalVddg,eMicThermalVddq}; -static const char *therm_names[NUM_THERMS] = {"die","devmem","fin","fout","vccp","vddg","vddq"}; - -static const char *config_keys[] = -{ - "ShowTotalCPU", - "ShowPerCPU", - "ShowTemps", - "ShowMemory", - "TempSensor", - "IgnoreTempSelected", -}; -static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); - -static _Bool show_total_cpu = 1; -static _Bool show_per_cpu = 1; -static _Bool show_temps = 1; +static HANDLE mic_handle = NULL; + +static int const therm_ids[] = { + eMicThermalDie, eMicThermalDevMem, eMicThermalFin, eMicThermalFout, + eMicThermalVccp, eMicThermalVddg, eMicThermalVddq}; +static char const *const therm_names[] = {"die", "devmem", "fin", "fout", + "vccp", "vddg", "vddq"}; + +static const char *config_keys[] = { + "ShowCPU", "ShowCPUCores", "ShowMemory", + "ShowTemperatures", "Temperature", "IgnoreSelectedTemperature", + "ShowPower", "Power", "IgnoreSelectedPower"}; +static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); + +static _Bool show_cpu = 1; +static _Bool show_cpu_cores = 1; static _Bool show_memory = 1; +static _Bool show_temps = 1; static ignorelist_t *temp_ignore = NULL; - - -static int mic_init (void) -{ - U32 ret; - - if (mic_handle) - return (0); - - ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &num_mics); - if (ret != MIC_ACCESS_API_SUCCESS) { - ERROR("Problem initializing MicAccessAPI: %s",MicGetErrorString(ret)); - } - DEBUG("MICs found: %d",num_mics); - - if (num_mics<0 || num_mics>=MAX_MICS) { - ERROR("No Intel MICs in system"); - return (1); - } - else - return (0); +static _Bool show_power = 1; +static ignorelist_t *power_ignore = NULL; + +static int mic_init(void) { + U32 ret; + U32 mic_count; + + if (mic_handle) + return (0); + + mic_count = (U32)STATIC_ARRAY_SIZE(mics); + ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &mic_count); + if (ret != MIC_ACCESS_API_SUCCESS) { + ERROR("mic plugin: Problem initializing MicAccessAPI: %s", + MicGetErrorString(ret)); + } + DEBUG("mic plugin: found: %" PRIu32 " MIC(s)", mic_count); + + if (mic_count < 0 || mic_count >= MAX_MICS) { + ERROR("mic plugin: No Intel MICs in system"); + return (1); + } else { + num_mics = mic_count; + return (0); + } } -static int mic_config (const char *key, const char *value) { - if (temp_ignore == NULL) - temp_ignore = ignorelist_create(1); - if (temp_ignore == NULL) - return (1); - - if (strcasecmp("ShowTotalCPU",key) == 0) - { - show_total_cpu = IS_TRUE(value); - } - else if (strcasecmp("ShowPerCPU",key) == 0) - { - show_per_cpu = IS_TRUE(value); - } - else if (strcasecmp("ShowTemps",key) == 0) - { - show_temps = IS_TRUE(value); - } - else if (strcasecmp("ShowMemory",key) == 0) - { - show_memory = IS_TRUE(value); - } - else if (strcasecmp("TempSensor",key) == 0) - { - ignorelist_add(temp_ignore,value); - } - else if (strcasecmp("IgnoreTempSelected",key) == 0) - { - int invert = 1; - if (IS_TRUE(value)) - invert = 0; - ignorelist_set_invert(temp_ignore,invert); - } - else - { - return (-1); - } - return (0); +static int mic_config(const char *key, const char *value) { + if (temp_ignore == NULL) + temp_ignore = ignorelist_create(1); + if (power_ignore == NULL) + power_ignore = ignorelist_create(1); + if (temp_ignore == NULL || power_ignore == NULL) + return (1); + + if (strcasecmp("ShowCPU", key) == 0) { + show_cpu = IS_TRUE(value); + } else if (strcasecmp("ShowCPUCores", key) == 0) { + show_cpu_cores = IS_TRUE(value); + } else if (strcasecmp("ShowTemperatures", key) == 0) { + show_temps = IS_TRUE(value); + } else if (strcasecmp("ShowMemory", key) == 0) { + show_memory = IS_TRUE(value); + } else if (strcasecmp("ShowPower", key) == 0) { + show_power = IS_TRUE(value); + } else if (strcasecmp("Temperature", key) == 0) { + ignorelist_add(temp_ignore, value); + } else if (strcasecmp("IgnoreSelectedTemperature", key) == 0) { + int invert = 1; + if (IS_TRUE(value)) + invert = 0; + ignorelist_set_invert(temp_ignore, invert); + } else if (strcasecmp("Power", key) == 0) { + ignorelist_add(power_ignore, value); + } else if (strcasecmp("IgnoreSelectedPower", key) == 0) { + int invert = 1; + if (IS_TRUE(value)) + invert = 0; + ignorelist_set_invert(power_ignore, invert); + } else { + return (-1); + } + return (0); } -static void mic_submit_memory_use(int micnumber, const char *type_instance, gauge_t val) -{ - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; +static void mic_submit_memory_use(int micnumber, const char *type_instance, + U32 value) { + value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; + /* MicAccessAPI reports KB's of memory, adjust for this */ + DEBUG("mic plugin: Memory Value Report; %u %lf", value, + ((gauge_t)value) * 1024.0); - vl.values=values; - vl.values_len=1; + vl.values = &(value_t){.gauge = ((gauge_t)value) * 1024.0}; + vl.values_len = 1; - strncpy (vl.host, hostname_g, sizeof (vl.host)); - strncpy (vl.plugin, "mic", sizeof (vl.plugin)); - ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber); - strncpy (vl.type, "memory", sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + strncpy(vl.plugin, "mic", sizeof(vl.plugin)); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + strncpy(vl.type, "memory", sizeof(vl.type)); + strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); - plugin_dispatch_values (&vl); -} + plugin_dispatch_values(&vl); +} /* Gather memory Utilization */ -static int mic_read_memory(int mic) -{ - U32 ret; - U32 mem_total,mem_used,mem_bufs; - - ret = MicGetMemoryUtilization(mic_handle,&mem_total,&mem_used,&mem_bufs); - if (ret != MIC_ACCESS_API_SUCCESS) { - ERROR("Problem getting Memory Utilization: %s",MicGetErrorString(ret)); - return (1); - } - /* API reprots KB's of memory, adjust for this */ - mic_submit_memory_use(mic,"free",(mem_total-mem_used-mem_bufs)*1024); - mic_submit_memory_use(mic,"used",mem_used*1024); - mic_submit_memory_use(mic,"buffered",mem_bufs*1024); - /*INFO("Memory Read: %u %u %u",mem_total,mem_used,mem_bufs);*/ - return (0); +static int mic_read_memory(int mic) { + U32 ret; + U32 mem_total, mem_free, mem_bufs; + + ret = MicGetMemoryUtilization(mic_handle, &mem_total, &mem_free, &mem_bufs); + if (ret != MIC_ACCESS_API_SUCCESS) { + ERROR("mic plugin: Problem getting Memory Utilization: %s", + MicGetErrorString(ret)); + return (1); + } + mic_submit_memory_use(mic, "free", mem_free); + mic_submit_memory_use(mic, "used", mem_total - mem_free - mem_bufs); + mic_submit_memory_use(mic, "buffered", mem_bufs); + DEBUG("mic plugin: Memory Read: %u %u %u", mem_total, mem_free, mem_bufs); + return (0); } -static void mic_submit_temp(int micnumber, const char *type, gauge_t val) -{ - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; +static void mic_submit_temp(int micnumber, const char *type, gauge_t value) { + value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; + vl.values = &(value_t){.gauge = value}; + vl.values_len = 1; - vl.values=values; - vl.values_len=1; + strncpy(vl.host, hostname_g, sizeof(vl.host)); + strncpy(vl.plugin, "mic", sizeof(vl.plugin)); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + strncpy(vl.type, "temperature", sizeof(vl.type)); + strncpy(vl.type_instance, type, sizeof(vl.type_instance)); - strncpy (vl.host, hostname_g, sizeof (vl.host)); - strncpy (vl.plugin, "mic", sizeof (vl.plugin)); - ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber); - strncpy (vl.type, "temperature", sizeof (vl.type)); - strncpy (vl.type_instance, type, sizeof (vl.type_instance)); - - plugin_dispatch_values (&vl); -} + plugin_dispatch_values(&vl); +} /* Gather Temperature Information */ -static int mic_read_temps(int mic) -{ - int j; - U32 ret; - U32 temp_buffer; - U32 buffer_size = (U32)sizeof(temp_buffer); - - for (j=0;j