diff --git a/.ci b/.ci deleted file mode 160000 index fd925d8..0000000 --- a/.ci +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fd925d83b60291d14c21442d7f6f4938e483b1f4 diff --git a/README_devIocStats b/README_devIocStats index dac17cc..f576448 100644 --- a/README_devIocStats +++ b/README_devIocStats @@ -74,6 +74,7 @@ Analog In (ai) Records (DTYP = "IOC stats"), INP = @one of the following: sys_cpuload - estimated percent CPU load on the system no_of_cpus - number of CPU cores on the system ioc_cpuload - estimated percent CPU utilization by this IOC + cpu_temperature - measured temperature of the CPU (only implemented for Linux IOC) fd - number of file descriptors currently in use maxfd - max number of file descriptors Note - free_bytes, total_bytes, sys_cpuload, no_of_cpus can be instantiated once per system instead diff --git a/devIocStats/Makefile b/devIocStats/Makefile index 5acd089..10fd9e1 100644 --- a/devIocStats/Makefile +++ b/devIocStats/Makefile @@ -44,6 +44,7 @@ SRCS += osdBootInfo.c SRCS += osdSystemInfo.c SRCS += osdHostInfo.c SRCS += osdPIDInfo.c +SRCS += osdCpuTemp.c OBJS_vxWorks += osdCpuUsageTest.o diff --git a/devIocStats/devIocStats.h b/devIocStats/devIocStats.h index 1a76ef8..1e2dd32 100644 --- a/devIocStats/devIocStats.h +++ b/devIocStats/devIocStats.h @@ -131,4 +131,7 @@ extern int devIocStatsGetHostname (char **pval); extern int devIocStatsGetPID (double *proc_id); extern int devIocStatsGetPPID (double *proc_id); +/* CPU Temperature */ +extern int devIocStatsGetCpuTemp (int *pval); + #endif /* devIocStats_H */ diff --git a/devIocStats/devIocStatsAnalog.c b/devIocStats/devIocStatsAnalog.c index a43804d..a078c0d 100644 --- a/devIocStats/devIocStatsAnalog.c +++ b/devIocStats/devIocStatsAnalog.c @@ -202,6 +202,7 @@ static void statsWSAllocBytes(double*); static void statsWSTotalBytes(double*); static void statsCpuUsage(double*); static void statsCpuUtilization(double*); +static void statsCpuTemperature(double*); static void statsNoOfCpus(double*); static void statsSuspendedTasks(double*); static void statsFdUsage(double*); @@ -231,7 +232,6 @@ static void statsCbMediumQOverruns(double*); static void statsCbHighQHiWtrMrk(double*); static void statsCbHighQUsed(double*); static void statsCbHighQOverruns(double*); - struct { char *name; double scan_rate; @@ -286,6 +286,7 @@ static validGetParms statsGetParms[]={ { "cbHighQueueHiWtrMrk", statsCbHighQHiWtrMrk, QUEUE_TYPE }, { "cbHighQueueUsed", statsCbHighQUsed, QUEUE_TYPE }, { "cbHighQueueOverruns", statsCbHighQOverruns, QUEUE_TYPE }, + { "cpu_temperature", statsCpuTemperature, LOAD_TYPE }, { NULL,NULL,0 } }; @@ -307,6 +308,7 @@ static scanInfo scan[TOTAL_TYPES] = {{0}}; static fdInfo fdusage = {0,0}; static loadInfo loadinfo = {1,0.,0.}; static int susptasknumber = 0; +static int cputemperature = 0; static int recordnumber = 0; static clustInfo clustinfo[2] = {{{0}},{{0}}}; static int mbufnumber[2] = {0,0}; @@ -385,12 +387,15 @@ static void scan_time(int type) { loadInfo loadinfo_local = {1,0.,0.}; int susptasknumber_local = 0; + int cputemperature_local = 0; devIocStatsGetCpuUsage(&loadinfo_local); devIocStatsGetCpuUtilization(&loadinfo_local); devIocStatsGetSuspTasks(&susptasknumber_local); + devIocStatsGetCpuTemp(&cputemperature_local); epicsMutexLock(scan_mutex); loadinfo = loadinfo_local; susptasknumber = susptasknumber_local; + cputemperature = cputemperature_local; epicsMutexUnlock(scan_mutex); break; } @@ -747,6 +752,10 @@ static void statsCpuUtilization(double* val) { *val = loadinfo.iocLoad; } +static void statsCpuTemperature(double* val) +{ + *val = (double)cputemperature/1000.; +} static void statsNoOfCpus(double* val) { *val = (double)loadinfo.noOfCpus; diff --git a/devIocStats/os/Linux/osdCpuTemp.c b/devIocStats/os/Linux/osdCpuTemp.c new file mode 100644 index 0000000..639a66d --- /dev/null +++ b/devIocStats/os/Linux/osdCpuTemp.c @@ -0,0 +1,40 @@ +/*************************************************************************\ +* Copyright (c) 2009 Helmholtz-Zentrum Berlin fuer Materialien und Energie. +* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* osdCpuTemp.c - Temperature of the CPU: default implementation = do nothing */ + +/* + * Author: Florian Feldbauer (RUB) + * + */ + +#include +#include +#include +#include + +#include + +int devIocStatsGetCpuTemp (int *pval) { + FILE *pFile = fopen ( "/sys/class/thermal/thermal_zone0/temp", "r" ); + if( !pFile ) { + fprintf( stderr, "\033[31;1m: Could not open file '/sys/class/thermal/thermal_zone0/temp': %s\033[0m\n", + strerror( errno ) ); + return -1; + } + + unsigned num = fscanf( pFile, "%d", pval ); + if ( 1 != num ) { + fprintf( stderr, "\033[31;1mCould not parse value\033[0m\n" ); + } + fclose( pFile ); + return 0; +} diff --git a/devIocStats/os/default/osdCpuTemp.c b/devIocStats/os/default/osdCpuTemp.c new file mode 100644 index 0000000..341565a --- /dev/null +++ b/devIocStats/os/default/osdCpuTemp.c @@ -0,0 +1,21 @@ +/*************************************************************************\ +* Copyright (c) 2009 Helmholtz-Zentrum Berlin fuer Materialien und Energie. +* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* osdCpuTemp.c - Temperature of the CPU: default implementation = do nothing */ + +/* + * Author: Florian Feldbauer (RUB) + * + */ + +#include + +int devIocStatsGetCpuTemp (int *pval) { return -1; }