Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions devIocStats/os/RTEMS/devIocStatsOSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@
* info of 100% free (but 100% of 0 is still 0).
*
*/
/*
* Updated to RTEMS 6
* Contemporary Software
* Chris Johns <[email protected]>
*/
#include "epicsVersion.h"

#define RTEMS_VERSION_INT \
VERSION_INT(__RTEMS_MAJOR__, __RTEMS_MINOR__, __RTEMS_REVISION__, 0)

#if RTEMS_VERSION_INT <= VERSION_INT(5, 0, 0, 0)
/*
* This define effects rtems.h includes on 4.10 and earlier
*/
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
#include <rtems.h>
#include <bsp.h>
#include <rtems/libcsupport.h>
#include <rtems/libio_.h>
Expand All @@ -53,6 +66,9 @@
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_var.h>
#endif /* RTEMS 5 and earlier */

#include <rtems.h>

#undef malloc
#undef free
Expand All @@ -67,17 +83,36 @@
#include <string.h>
#include <stdlib.h>

#include "epicsVersion.h"
#if RTEMS_VERSION_INT < VERSION_INT(6, 0, 0, 0)
#define rtems_bsd_reset() bsp_reset()
#else /* RTEMS_VERSION_INT < VERSION_INT(6, 0, 0, 0) */
#define rtems_bsd_reset() bsp_reset()
#endif /* RTEMS_VERSION_INT < VERSION_INT(6, 0, 0, 0) */

#define RTEMS_VERSION_INT \
VERSION_INT(__RTEMS_MAJOR__, __RTEMS_MINOR__, __RTEMS_REVISION__, 0)
#if RTEMS_LEGACY_STACK

#include <rtems/rtems_bsdnet.h>

#define sysBootLine rtems_bsdnet_bootp_cmdline
#else
#define sysBootLine "BOOTP cmdline not supported"
#endif
/* Override default STARTUP environment variable to use INIT */
#undef STARTUP
#define STARTUP "INIT"

#define CLUSTSIZES 2 /* only regular mbufs and clusters */

#if RTEMS_VERSION_INT >= VERSION_INT(6, 0, 0, 0)

#define NO_OF_CPUS rtems_configuration_get_maximum_processors()

#include <bsp/bootcard.h>
static inline void reboot(int val) {
(void)val;
bsp_reset(RTEMS_FATAL_SOURCE_APPLICATION, 112233);
}
#else /* RTEMS 6 or later */
#ifdef RTEMS_BSP_PGM_EXEC_AFTER /* only defined on uC5282 */
#define reboot(x) bsp_reset(0)
#elif (defined(__PPC__) && RTEMS_VERSION_INT > VERSION_INT(4, 9, 0, 0))
Expand All @@ -91,3 +126,4 @@
#else
#define reboot(x) rtemsReboot()
#endif
#endif /* RTEMS 6 or later */
66 changes: 64 additions & 2 deletions devIocStats/os/RTEMS/osdClustInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,71 @@

#include <devIocStats.h>

/* This would otherwise need _KERNEL to be defined... */
extern struct mbstat mbstat;
#include <sys/param.h>
#include <sys/mbuf.h>

int devIocStatsInitClusterInfo(void) { return 0; }

#if RTEMS_LIBBSD_STACK

#include <memstat.h>

int devIocStatsGetClusterInfo(int pool, clustInfo *pval) {
struct memory_type_list *mtlp;
struct memory_type *mtp;

if (pool == DATA_POOL) {
return -1;
}

mtlp = memstat_mtl_alloc();
if (mtlp == NULL) {
return -1;
}

if (memstat_sysctl_all(mtlp, 0) < 0) {
memstat_mtl_free(mtlp);
return -1;
}

mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_MEM_NAME);
if (mtp == NULL) {
memstat_mtl_free(mtlp);
return -1;
}

(*pval)[0][0] = memstat_get_size(mtp);
(*pval)[0][1] = memstat_get_count(mtp);
(*pval)[0][2] = memstat_get_free(mtp);
(*pval)[0][3] = (*pval)[0][1] - (*pval)[0][2];

mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME);
if (mtp == NULL) {
memstat_mtl_free(mtlp);
return -1;
}

(*pval)[0][0] = memstat_get_size(mtp);
(*pval)[0][1] = memstat_get_count(mtp);
(*pval)[0][2] = memstat_get_free(mtp);
(*pval)[0][3] = (*pval)[0][1] - (*pval)[0][2];

memstat_mtl_free(mtlp);

return 0;
}

int devIocStatsGetClusterUsage(int pool, int* pval) {
(void) pool;
(void) pval;
return -1;
}

#else /* RTEMS_LIBBSD_STACK */

/* This would otherwise need _KERNEL to be defined... */
extern struct mbstat mbstat;

int devIocStatsGetClusterInfo(int pool, clustInfo *pval) {
if (pool == DATA_POOL)
return -1;
Expand All @@ -86,3 +146,5 @@ int devIocStatsGetClusterUsage(int pool, int *pval) {

return 0;
}

#endif /* RTEMS_LIBBSD_STACK */
37 changes: 34 additions & 3 deletions devIocStats/os/RTEMS/osdCpuUsage.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@

#include <devIocStats.h>

static double prev_total = 0;
static double prev_idle = 0;

#if __RTEMS_MAJOR__ >= 6

#include <sys/resource.h>

static double oldActiveUsage;
static double oldIdleUsage;

/*
* See IEEE Std 1003.1-1988 (“POSIX.1”) for getrusage()
*/
static void cpu_ticks(double *total, double *idle) {
struct rusage stats;
double curActive;
double curIdle;
getrusage(RUSAGE_SELF, &stats);
curActive = (double)stats.ru_utime.tv_sec + stats.ru_utime.tv_usec / 1e6;
curIdle = (double)stats.ru_stime.tv_sec + stats.ru_stime.tv_usec / 1e6;
*idle = curIdle - oldIdleUsage;
*total = *idle + (curActive - oldActiveUsage);
oldActiveUsage = curActive;
oldIdleUsage = curIdle;
}

#else /* RTEMS 6 or later */

/*
* Direct access to the Object information table
*/

#if (__RTEMS_MAJOR__ > 4) || (__RTEMS_MAJOR__ == 4 && __RTEMS_MINOR__ > 7)
typedef char objName[13];
#define RTEMS_OBJ_GET_NAME(tc, name) \
Expand Down Expand Up @@ -79,9 +111,6 @@ typedef char *objName;
* from the RTEMS source.
*/

static double prev_total = 0;
static double prev_idle = 0;

static void cpu_ticks(double *total, double *idle) {
Objects_Information *obj;
Thread_Control *tc;
Expand Down Expand Up @@ -116,6 +145,8 @@ static void cpu_ticks(double *total, double *idle) {
}
}

#endif /* RTEMS 6 or later */

int devIocStatsInitCpuUsage(void) {
cpu_ticks(&prev_total, &prev_idle);
#ifdef SSRLAPPSMISCUTILS
Expand Down
1 change: 0 additions & 1 deletion devIocStats/os/RTEMS/osdCpuUtilization.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ int devIocStatsInitCpuUtilization(loadInfo *pval) {
return 0;
}

/* FIXME: This relies on the device support calling it after CpuUsage */
int devIocStatsGetCpuUtilization(loadInfo *pval) {
pval->iocLoad = pval->cpuLoad;
return 0;
Expand Down
8 changes: 8 additions & 0 deletions devIocStats/os/RTEMS/osdFdUsage.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@

#include <devIocStats.h>

#if __RTEMS_MAJOR__ >= 6
#include <rtems/libio_.h>
#endif /* _RTEMS_MAJOR__ >= 6 */

int devIocStatsInitFDUsage(void) { return 0; }

int devIocStatsGetFDUsage(fdInfo *pval) {
#if __RTEMS_MAJOR__ >= 6
pval->used = rtems_libio_count_open_iops();
#else
int i, tot;

for (tot = 0, i = 0; i < rtems_libio_number_iops; i++) {
if (rtems_libio_iops[i].flags & LIBIO_FLAGS_OPEN)
tot++;
}
pval->used = tot;
#endif /* _RTEMS_MAJOR__ >= 6 */
pval->max = rtems_libio_number_iops;
return 0;
}
41 changes: 39 additions & 2 deletions devIocStats/os/RTEMS/osdIFErrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,47 @@

#include <devIocStats.h>

int devIocStatsInitIFErrors(void) { return 0; }

#if RTEMS_LIBBSD_STACK

#include <ifaddrs.h>
#include <net/if.h>

int devIocStatsGetIFErrors(ifErrInfo *pval) {
struct ifaddrs *ifap, *ifa;

/* add all interfaces' errors */
pval->ierrors = 0;
pval->oerrors = 0;

if (getifaddrs(&ifap) != 0) {
return -1;
}

for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family != AF_LINK) {
continue;
}
#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_##s)
pval->ierrors += IFA_STAT(ierrors);
pval->oerrors += IFA_STAT(oerrors);
}

freeifaddrs(ifap);

return 0;
}

#else /* RTEMS_LIBBSD_STACK */

#include <net/if_var.h>

/* This would otherwise need _KERNEL to be defined... */
extern struct ifnet *ifnet;

int devIocStatsInitIFErrors(void) { return 0; }

int devIocStatsGetIFErrors(ifErrInfo *pval) {

struct ifnet *ifp;

/* add all interfaces' errors */
Expand All @@ -57,3 +92,5 @@ int devIocStatsGetIFErrors(ifErrInfo *pval) {
}
return 0;
}

#endif /* RTEMS_LIBBSD_STACK */
4 changes: 4 additions & 0 deletions devIocStats/os/RTEMS/osdSuspTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
int devIocStatsInitSuspTasks(void) { return 0; }

int devIocStatsGetSuspTasks(int *pval) {
#if __RTEMS_MAJOR__ < 6
Objects_Control *o;
Objects_Id id = OBJECTS_ID_INITIAL_INDEX;
Objects_Id nid;
Expand All @@ -59,4 +60,7 @@ int devIocStatsGetSuspTasks(int *pval) {
}
*pval = n;
return 0;
#else /* __RTEMS_MAJOR__ < 6 */
return -1;
#endif /* __RTEMS_MAJOR__ < 6 */
}
5 changes: 5 additions & 0 deletions devIocStats/os/RTEMS/osdWorkspaceUsage.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ int devIocStatsInitWorkspaceUsage(void) { return 0; }

int devIocStatsGetWorkspaceUsage(memInfo *pval) {
Heap_Information_block info;
#if __RTEMS_MAJOR__ >= 6
malloc_info(&info);
pval->numBytesTotal = info.Stats.size;
#else /* __RTEMS_MAJOR__ >= 6 */
#ifdef RTEMS_PROTECTED_HEAP
_Protected_heap_Get_information(&_Workspace_Area, &info);
#else /* RTEMS_PROTECTED_HEAP */
Expand All @@ -45,6 +49,7 @@ int devIocStatsGetWorkspaceUsage(memInfo *pval) {
#else
pval->numBytesTotal = _Configuration_Table->work_space_size;
#endif
#endif /* _RTEMS_MAJOR__ >= 6 */
pval->numBytesFree = info.Free.total;
pval->numBytesAlloc = info.Used.total;
return 0;
Expand Down