Code

Cleanup errors from upstream review, cleanup typeographical errors.
authorEvan Felix <e@pnnl.gov>
Thu, 9 May 2013 21:30:19 +0000 (14:30 -0700)
committerFlorian Forster <octo@collectd.org>
Sat, 11 May 2013 07:15:25 +0000 (09:15 +0200)
configure.in
src/mic.c

index 2c9ee3974f44a254f1bf03ce1117185df39a864e..5fccebd461783298b96667bf45f60e4f626dfea0 100644 (file)
@@ -1600,8 +1600,7 @@ then
        AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
-#
- }}}
+# }}}
 
 # --with-libdbi {{{
 with_libdbi_cppflags=""
@@ -1767,7 +1766,6 @@ AC_SUBST(GANGLIA_CPPFLAGS)
 AC_SUBST(GANGLIA_LDFLAGS)
 AC_SUBST(GANGLIA_LIBS)
 AM_CONDITIONAL(BUILD_WITH_LIBGANGLIA, test "x$with_libganglia" = "xyes")
-
 # }}}
 
 # --with-libgcrypt {{{
@@ -4170,7 +4168,7 @@ AC_ARG_WITH(mic,[AS_HELP_STRING([--with-mic@<:@=PREFIX@:>@], [Path to Intel MIC
        then
                AC_MSG_NOTICE([Not checking for Intel Mic: Manually configured])
                with_mic_cflags="-I$withval/include"
-               with_mic_ldpath="-L$withval/lib"
+               with_mic_ldpath="-L$withval/lib/Linux"
                with_mic_libs="-lMicAccessSDK -lscif -lpthread"
                with_mic="yes"
        fi; fi; fi
@@ -4192,9 +4190,9 @@ then
        LDFLAGS="$LDFLAGS $with_mic_ldpath"
 
        AC_CHECK_LIB(MicAccessSDK, MicInitAPI,
-                    [with_mic_ldpath="$with_mic_ldpath"
-                         with_mic_libs="-lMicAccessSDK -lscif -lpthread"],
-                    [with_mic="no (symbol MicInitAPI not found)"],[-lscif -lpthread])
+                       [with_mic_ldpath="$with_mic_ldpath"
+                       with_mic_libs="-lMicAccessSDK -lscif -lpthread"],
+                       [with_mic="no (symbol MicInitAPI not found)"],[-lscif -lpthread])
 
        CPPFLAGS="$SAVE_CPPFLAGS"
        LDFLAGS="$SAVE_LDFLAGS"
@@ -4655,7 +4653,6 @@ plugin_irq="no"
 plugin_libvirt="no"
 plugin_load="no"
 plugin_memory="no"
-plugin_mic="no"
 plugin_multimeter="no"
 plugin_nfs="no"
 plugin_numa="no"
@@ -5000,7 +4997,7 @@ AC_PLUGIN([md],          [$have_linux_raid_md_u_h], [md (Linux software RAID) de
 AC_PLUGIN([memcachec],   [$with_libmemcached], [memcachec statistics])
 AC_PLUGIN([memcached],   [yes],                [memcached statistics])
 AC_PLUGIN([memory],      [$plugin_memory],     [Memory usage])
-AC_PLUGIN([mic],         [$plugin_mic],          [Intel Many Integrated Core stats])
+AC_PLUGIN([mic],         [$with_mic],          [Intel Many Integrated Core stats])
 AC_PLUGIN([modbus],      [$with_libmodbus],    [Modbus plugin])
 AC_PLUGIN([multimeter],  [$plugin_multimeter], [Read multimeter values])
 AC_PLUGIN([mysql],       [$with_libmysql],     [MySQL statistics])
index 06c18d71044e2663b6890c3f9a27b6f24f3b935d..eec55f1be2dd9b6c775d2937458c51734f219a32 100644 (file)
--- a/src/mic.c
+++ b/src/mic.c
@@ -1,6 +1,6 @@
 /**
  * collectd - src/mic.c
- * Copyright (C) 2013  
+ * Copyright (C) 2013 Battelle Memorial Institute
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -16,7 +16,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
- *   Evan Felix <evan.felix@pnnl.gov
+ *   Evan Felix <evan.felix@pnnl.gov>
  **/
 
 #include "collectd.h"
 #define MAX_CORES 256
 
 static MicDeviceOnSystem mics[MAX_MICS];
-static U32 numMics = MAX_MICS;
-static HANDLE micHandle=NULL;
+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 *thermNames[NUM_THERMS] = {"die","devmem","fin","fout","vccp","vddg","vddq"};
+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",
+       "ShowTotalCPU",
+       "ShowPerCPU",
+       "ShowTemps",
+       "ShowMemory",
+       "TempSensor",
+       "IgnoreTempSelected",
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
@@ -59,242 +59,246 @@ static ignorelist_t *temp_ignore = NULL;
 
 static int mic_init (void)
 {
-  U32 ret;
-
-  ret = MicInitAPI(&micHandle,  eTARGET_SCIF_DRIVER, mics, &numMics);
-  if (ret != MIC_ACCESS_API_SUCCESS) {
-       ERROR("Problem initializing MicAccessAPI: %s",MicGetErrorString(ret));
-  }
-  DEBUG("MICs found: %d",numMics);
-  
-  if (numMics<0 || numMics>=MAX_MICS)
-       return (1);
-  else
-       return (0);
+       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 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);
+       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 void mic_submit_memory_use(int micnumber, const char *type, gauge_t val)
+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;
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].gauge = val;
+       values[0].gauge = val;
 
-  vl.values=values;
-  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, "memory", 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, "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(micHandle,&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,"total",mem_total*1024);
-  mic_submit_memory_use(mic,"used",mem_used*1024);
-  mic_submit_memory_use(mic,"bufs",mem_bufs*1024);
-  /*INFO("Memory Read: %u %u %u",mem_total,mem_used,mem_bufs);*/
-  return (0);
+       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 void mic_submit_temp(int micnumber, const char *type, gauge_t val)
 {
-  value_t values[1];
-  value_list_t vl = VALUE_LIST_INIT;
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].gauge = val;
+       values[0].gauge = val;
 
-  vl.values=values;
-  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 bufferSize;
-  U32 *tempBuffer;
-  bufferSize = sizeof(U32);
-  tempBuffer = malloc(bufferSize);
-  for (j=0;j<NUM_THERMS;j++) {
-       if (ignorelist_match(temp_ignore,thermNames[j])!=0)
-         continue;
-       ret = MicGetTemperature(micHandle,therms[j],tempBuffer,&bufferSize);
-       if (ret != MIC_ACCESS_API_SUCCESS) {
-         ERROR("Problem getting Temperature(%d) %s",j,MicGetErrorString(ret));
-         return (1);
+       int j;
+       U32 ret;
+       U32 temp_buffer;
+       U32 buffer_size = (U32)sizeof(temp_buffer);
+       
+       for (j=0;j<NUM_THERMS;j++) {
+               if (ignorelist_match(temp_ignore,therm_names[j])!=0)
+                       continue;
+               ret = MicGetTemperature(mic_handle,therms[j],&temp_buffer,&buffer_size);
+               if (ret != MIC_ACCESS_API_SUCCESS) {
+                       ERROR("Problem getting Temperature(%d) %s",j,MicGetErrorString(ret));
+                       return (1);
+               }
+               mic_submit_temp(mic,therm_names[j],temp_buffer);
        }
-       /*INFO("Temp Read: %u: %u %s",j,tempBuffer[0],thermNames[j]);*/
-       mic_submit_temp(mic,thermNames[j],tempBuffer[0]);
-  }
-  return (0);
+       return (0);
 }
 
-static void mic_submit_cpu(int micnumber, const char *type, int core, derive_t val)
+static void mic_submit_cpu(int micnumber, const char *type_instance, int core, derive_t val)
 {
-  value_t values[1];
-  value_list_t vl = VALUE_LIST_INIT;
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].derive = val;
+       values[0].derive = val;
 
-  vl.values=values;
-  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, "cpu", sizeof (vl.type));
-  if (core < 0)
-       strncpy (vl.type_instance, type, sizeof (vl.type_instance));
-  else
-       ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i-%s", core, type);
+       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, "cpu", sizeof (vl.type));
+       if (core < 0)
+               strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       else
+               ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i-%s", core, type_instance);
 
-  plugin_dispatch_values (&vl);
+       plugin_dispatch_values (&vl);
 } 
 
 /*Gather CPU Utilization Information */
 static int mic_read_cpu(int mic)
 {
-  U32 ret;
-  U32 bufferSize;
-  int j;
-  MicCoreUtil coreUtil;
-  MicCoreJiff coreJiffs[MAX_CORES];
-
-  bufferSize=MAX_CORES*sizeof(MicCoreJiff);
-  ret = MicGetCoreUtilization(micHandle,&coreUtil,coreJiffs,&bufferSize);
-  if (ret != MIC_ACCESS_API_SUCCESS) {
-       ERROR("Problem getting CPU utilization: %s",MicGetErrorString(ret));
-       return(0);
-  }
-  if (show_total_cpu) {
-       mic_submit_cpu(mic,"user",-1,coreUtil.sum.user);
-       mic_submit_cpu(mic,"sys",-1,coreUtil.sum.sys);
-       mic_submit_cpu(mic,"nice",-1,coreUtil.sum.nice);
-       mic_submit_cpu(mic,"idle",-1,coreUtil.sum.idle);
-  }
-  if (show_per_cpu) {
-       for (j=0;j<coreUtil.core;j++) {
-         mic_submit_cpu(mic,"user",j,coreJiffs[j].user);
-         mic_submit_cpu(mic,"sys",j,coreJiffs[j].sys);
-         mic_submit_cpu(mic,"nice",j,coreJiffs[j].nice);
-         mic_submit_cpu(mic,"idle",j,coreJiffs[j].idle);
+       U32 ret;
+       U32 buffer_size;
+       int j;
+       MicCoreUtil core_util;
+       MicCoreJiff core_jiffs[MAX_CORES];
+
+       buffer_size=MAX_CORES*sizeof(MicCoreJiff);
+       ret = MicGetCoreUtilization(mic_handle,&core_util,core_jiffs,&buffer_size);
+       if (ret != MIC_ACCESS_API_SUCCESS) {
+               ERROR("Problem getting CPU utilization: %s",MicGetErrorString(ret));
+               return(0);
        }
-  }
-  return (0);
+       if (show_total_cpu) {
+               mic_submit_cpu(mic,"user",-1,core_util.sum.user);
+               mic_submit_cpu(mic,"sys",-1,core_util.sum.sys);
+               mic_submit_cpu(mic,"nice",-1,core_util.sum.nice);
+               mic_submit_cpu(mic,"idle",-1,core_util.sum.idle);
+       }
+       if (show_per_cpu) {
+               for (j=0;j<core_util.core;j++) {
+                       mic_submit_cpu(mic,"user",j,core_jiffs[j].user);
+                       mic_submit_cpu(mic,"sys",j,core_jiffs[j].sys);
+                       mic_submit_cpu(mic,"nice",j,core_jiffs[j].nice);
+                       mic_submit_cpu(mic,"idle",j,core_jiffs[j].idle);
+               }
+       }
+       return (0);
 }
 
 static int mic_read (void)
 {
-  int i;
-  U32 ret;
-  int error;
-
-  error=0;
-  for (i=0;i<numMics;i++) {
-       ret = MicInitAdapter(&micHandle,&mics[i]);
-       if (ret != MIC_ACCESS_API_SUCCESS) {
-         ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
-         error=1;
-       }
-
-       if (error == 0 && show_memory)
-         error = mic_read_memory(i);
-
-       if (error == 0 && show_temps)
-         error = mic_read_temps(i);
-
-       if (error == 0 && (show_total_cpu || show_per_cpu))
-         error = mic_read_cpu(i);
-
-       ret = MicCloseAdapter(micHandle);
-       if (ret != MIC_ACCESS_API_SUCCESS) {
-         ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
-         error=2;
-         break;
+       int i;
+       U32 ret;
+       int error;
+
+       error=0;
+       for (i=0;i<num_mics;i++) {
+               ret = MicInitAdapter(&mic_handle,&mics[i]);
+               if (ret != MIC_ACCESS_API_SUCCESS) {
+                       ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
+                       error=1;
+               }
+
+               if (error == 0 && show_memory)
+                       error = mic_read_memory(i);
+
+               if (error == 0 && show_temps)
+                       error = mic_read_temps(i);
+
+               if (error == 0 && (show_total_cpu || show_per_cpu))
+                       error = mic_read_cpu(i);
+
+               ret = MicCloseAdapter(mic_handle);
+               if (ret != MIC_ACCESS_API_SUCCESS) {
+                       ERROR("Problem closing MicAdapter: %s",MicGetErrorString(ret));
+                       error=2;
+                       break;
+               }
        }
-  }
-  return error;
+       if (num_mics==0)
+               error=3;
+       return error;
 }
 
 
 static int mic_shutdown (void)
 {
-  if (micHandle)
-       MicCloseAPI(&micHandle);
-  return (0);
+       if (mic_handle)
+       MicCloseAPI(&mic_handle);
+       return (0);
 }
 
 void module_register (void)
 {
-  plugin_register_init ("mic", mic_init);
-  plugin_register_shutdown ("mic", mic_shutdown);
-  plugin_register_read ("mic", mic_read);
-  plugin_register_config ("mic",mic_config, config_keys, config_keys_num);
+       plugin_register_init ("mic", mic_init);
+       plugin_register_shutdown ("mic", mic_shutdown);
+       plugin_register_read ("mic", mic_read);
+       plugin_register_config ("mic",mic_config, config_keys, config_keys_num);
 } /* void module_register */
 
 /*