diff --git a/devIocStats/os/RTEMS/devIocStatsOSD.h b/devIocStats/os/RTEMS/devIocStatsOSD.h index 00d5787..ed0cbf9 100644 --- a/devIocStats/os/RTEMS/devIocStatsOSD.h +++ b/devIocStats/os/RTEMS/devIocStatsOSD.h @@ -43,8 +43,21 @@ * info of 100% free (but 100% of 0 is still 0). * */ +/* + * Updated to RTEMS 6 + * Contemporary Software + * Chris Johns + */ +#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 #include #include #include @@ -53,6 +66,9 @@ #include #include #include +#endif /* RTEMS 5 and earlier */ + +#include #undef malloc #undef free @@ -67,17 +83,30 @@ #include #include -#include "epicsVersion.h" +#if RTEMS_LEGACY_STACK -#define RTEMS_VERSION_INT \ - VERSION_INT(__RTEMS_MAJOR__, __RTEMS_MINOR__, __RTEMS_REVISION__, 0) +#include #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 +static inline void reboot(int val) { + (void) val; + bsp_reset(); +} +#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)) @@ -91,3 +120,4 @@ #else #define reboot(x) rtemsReboot() #endif +#endif /* RTEMS 6 or later */ diff --git a/devIocStats/os/RTEMS/osdClustInfo.c b/devIocStats/os/RTEMS/osdClustInfo.c index 589d0f3..1e07474 100644 --- a/devIocStats/os/RTEMS/osdClustInfo.c +++ b/devIocStats/os/RTEMS/osdClustInfo.c @@ -56,11 +56,65 @@ #include -/* This would otherwise need _KERNEL to be defined... */ -extern struct mbstat mbstat; +#include +#include int devIocStatsInitClusterInfo(void) { return 0; } +#if RTEMS_LIBBSD_STACK + +#include + +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; +} + +#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; @@ -86,3 +140,5 @@ int devIocStatsGetClusterUsage(int pool, int *pval) { return 0; } + +#endif /* RTEMS_LIBBSD_STACK */ diff --git a/devIocStats/os/RTEMS/osdCpuUsage.c b/devIocStats/os/RTEMS/osdCpuUsage.c index 4963b8a..701ff5a 100644 --- a/devIocStats/os/RTEMS/osdCpuUsage.c +++ b/devIocStats/os/RTEMS/osdCpuUsage.c @@ -48,6 +48,38 @@ #include +static double prev_total = 0; +static double prev_idle = 0; + +#if __RTEMS_MAJOR__ >= 6 + +#include + +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) \ @@ -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; @@ -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 diff --git a/devIocStats/os/RTEMS/osdCpuUtilization.c b/devIocStats/os/RTEMS/osdCpuUtilization.c index c77770f..c918ade 100644 --- a/devIocStats/os/RTEMS/osdCpuUtilization.c +++ b/devIocStats/os/RTEMS/osdCpuUtilization.c @@ -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; diff --git a/devIocStats/os/RTEMS/osdFdUsage.c b/devIocStats/os/RTEMS/osdFdUsage.c index 1d52d82..93e64a0 100644 --- a/devIocStats/os/RTEMS/osdFdUsage.c +++ b/devIocStats/os/RTEMS/osdFdUsage.c @@ -38,9 +38,16 @@ #include +#if __RTEMS_MAJOR__ >= 6 +#include +#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++) { @@ -48,6 +55,7 @@ int devIocStatsGetFDUsage(fdInfo *pval) { tot++; } pval->used = tot; +#endif /* _RTEMS_MAJOR__ >= 6 */ pval->max = rtems_libio_number_iops; return 0; } diff --git a/devIocStats/os/RTEMS/osdIFErrors.c b/devIocStats/os/RTEMS/osdIFErrors.c index e01e729..d390609 100644 --- a/devIocStats/os/RTEMS/osdIFErrors.c +++ b/devIocStats/os/RTEMS/osdIFErrors.c @@ -40,12 +40,47 @@ #include +int devIocStatsInitIFErrors(void) { return 0; } + +#if RTEMS_LIBBSD_STACK + +#include +#include + +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 + /* 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 */ @@ -57,3 +92,5 @@ int devIocStatsGetIFErrors(ifErrInfo *pval) { } return 0; } + +#endif /* RTEMS_LIBBSD_STACK */ diff --git a/devIocStats/os/RTEMS/osdSuspTasks.c b/devIocStats/os/RTEMS/osdSuspTasks.c index 9679d53..aec6ead 100644 --- a/devIocStats/os/RTEMS/osdSuspTasks.c +++ b/devIocStats/os/RTEMS/osdSuspTasks.c @@ -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; @@ -59,4 +60,7 @@ int devIocStatsGetSuspTasks(int *pval) { } *pval = n; return 0; +#else /* __RTEMS_MAJOR__ < 6 */ + return -1; +#endif /* __RTEMS_MAJOR__ < 6 */ } diff --git a/devIocStats/os/RTEMS/osdWorkspaceUsage.c b/devIocStats/os/RTEMS/osdWorkspaceUsage.c index 9f7518a..1b2e4e6 100644 --- a/devIocStats/os/RTEMS/osdWorkspaceUsage.c +++ b/devIocStats/os/RTEMS/osdWorkspaceUsage.c @@ -31,20 +31,25 @@ int devIocStatsInitWorkspaceUsage(void) { return 0; } int devIocStatsGetWorkspaceUsage(memInfo *pval) { Heap_Information_block info; -#ifdef RTEMS_PROTECTED_HEAP +#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 */ + #else /* RTEMS_PROTECTED_HEAP */ _RTEMS_Lock_allocator(); /*Lock allocator to ensure accuracy */ _Heap_Get_information( &_Workspace_Area, &info); /*_Heap_Get_information is part of the RTEMS API */ _RTEMS_Unlock_allocator(); -#endif /* RTEMS_PROTECTED_HEAP */ -#if (__RTEMS_MAJOR__ > 4) || (__RTEMS_MAJOR__ == 4 && __RTEMS_MINOR__ > 9) + #endif /* RTEMS_PROTECTED_HEAP */ + #if (__RTEMS_MAJOR__ > 4) || (__RTEMS_MAJOR__ == 4 && __RTEMS_MINOR__ > 9) pval->numBytesTotal = Configuration.work_space_size; -#else + #else pval->numBytesTotal = _Configuration_Table->work_space_size; -#endif + #endif +#endif /* _RTEMS_MAJOR__ >= 6 */ pval->numBytesFree = info.Free.total; pval->numBytesAlloc = info.Used.total; return 0;