Skip to content

Conversation

@kiwichris
Copy link

@kiwichris kiwichris commented Aug 7, 2024

This pull request adds support for RTEMS 6 for the legacy network and libbsd.

It needs a current build of RTEMS 6 and tools.

@kiwichris
Copy link
Author

I have reviewed the CI failures and I do not think they are related to the changes I have made.

@anjohnson
Copy link
Member

I just pushed a change to the master branch here which cleaned up some compiler warnings, and the subsequent CI build jobs for RTEMS 4.9 and 4.10 both succeeded. I also re-triggered those CI builds for this PR which unfortunately both failed again, so some code change inside this PR must have caused the failures.

I don't care about the pre-commit check failure, just the ability to build this module against RTEMS 4.9 and 4.10. Note that the EPICS Base 7.0 version that this CI is using at the moment doesn't include your RTEMS-6 PRs, and we expect future releases of this module to continue to build against older EPICS versions anyway — the CI jobs that build it for Linux against both 3.14 and 3.15 should hint at that.

@kiwichris kiwichris force-pushed the rtems-6-legacy-libbsd branch from 29a2d9e to 1a65c02 Compare August 25, 2024 03:34
@kiwichris
Copy link
Author

kiwichris commented Aug 25, 2024

@anjohnson I have resolved the issue with 4.10 and I assume 4.9. It seems the define _RTEMS_VIOLATE_KERNEL_VISIBILITY__ effects what is included by rtems.h and in this case wkspace.h was not being included. I have moved the include order to clean this up.

@hjunkes
Copy link

hjunkes commented Aug 26, 2024

Unfortunately, when I try to compile (MVME6100 legacy RTEMS6) I get this:
...
/include -I/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-support/StreamDevice/include -c ../devIocStatsWaveform.c
In file included from ../os/RTEMS/devIocStatsOSD.h:84,
from ../devIocStats.h:52,
from ../devIocStatsWaveform.c:76:
/home/rtems/MVME6100_6_legacy_INST/rtems/6/powerpc-rtems6/include/stdlib.h:260:21: error: macro "random" passed 1 arguments, but takes just 0
260 | long random (void);
| ^
In file included from /home/rtems/MVME6100_6_legacy_INST/rtems/6/powerpc-rtems6/beatnik/lib/include/sys/malloc.h:39,
from /home/rtems/MVME6100_6_legacy_INST/rtems/6/powerpc-rtems6/beatnik/lib/include/sys/mbuf.h:38,
from ../os/RTEMS/devIocStatsOSD.h:65:
/home/rtems/MVME6100_6_legacy_INST/rtems/6/powerpc-rtems6/beatnik/lib/include/rtems/rtems_bsdnet_internal.h:63: note: macro "random" defined here
63 | #define random() rtems_bsdnet_random()
|
make[2]: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_BUILD:259: devIocStatsWaveform.o] Error 1
make[2]: Leaving directory '/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-support/iocStats/devIocStats/O.RTEMS-beatnik'
make[1]: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_ARCHS:58: install.RTEMS-beatnik] Error 2
make[1]: Leaving directory '/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-support/iocStats/devIocStats'
make: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_DIRS:85: devIocStats.install] Error 2

@hjunkes
Copy link

hjunkes commented Aug 26, 2024

e.g. in devIocStats/os/RTEMS/devIocStatsOSD.h
RTEMS_MAJOR, RTEMS_MINOR, RTEMS_REVISION
are not defined. Is that why the version status queries do not work?
defined in 6/powerpc-rtems6/beatnik/lib/include/rtems/score/cpuopts.h
So rtems.h must be included before the __RTEMS_XXX macros can be used?

But then I get this error:
support/StreamDevice/include -c ../os/RTEMS/osdFdUsage.c
../os/RTEMS/osdFdUsage.c: In function 'devIocStatsGetFDUsage':
../os/RTEMS/osdFdUsage.c:49:16: error: implicit declaration of function 'rtems_libio_count_open_iops' [-Werror=implicit-function-declaration]
49 | pval->used = rtems_libio_count_open_iops();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_BUILD:259: osdFdUsage.o] Error 1
make[2]: Leaving directory '/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-support/iocStats/devIocStats/O.RTEMS-beatnik'
make[1]: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_ARCHS:58: install.RTEMS-beatnik] Error 2
make[1]: Leaving directory '/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-support/iocStats/devIocStats'
make: *** [/home/rtems/MVME6100_6_legacy_INST/EPICS/epics-base/configure/RULES_DIRS:85: devIocStats.install] Error 2

@hjunkes
Copy link

hjunkes commented Aug 26, 2024

ok, found this:
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/117#note_109499
Will update my RTEMS ...

@kiwichris
Copy link
Author

The rtems.h needs to be after #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ for the build to complete for the pre RTEMS 6 versions. I could have broken it for 6 making the change?

@hjunkes
Copy link

hjunkes commented Aug 27, 2024

Works with the current RTEMS6 master(main). rtems_libio_count_open_iops is defined there.

@kiwichris
Copy link
Author

Works with the current RTEMS6 master(main). rtems_libio_count_open_iops is defined there.

Thanks for confirming this. I do not know what the approval for workflows means.

@anjohnson
Copy link
Member

@simon-ess will have to speak up if he cares about the clang-format failure (those checks seem rather obnoxious to me), but this looks good for the RTEMS builds, thanks!

@simon-ess
Copy link
Contributor

I would prefer that the formatting check pass; otherwise it should be disabled, since we would then be just ignoring a failing test.

We could discuss exactly what the best formatting is, but I don't like the idea of letting it fail.

@kiwichris
Copy link
Author

I would prefer that the formatting check pass; otherwise it should be disabled, since we would then be just ignoring a failing test.

I had no idea there was a coding standard. I am happy to take a look.

We could discuss exactly what the best formatting is, but I don't like the idea of letting it fail.

This makes sense. I can fix it.

@kiwichris kiwichris force-pushed the rtems-6-legacy-libbsd branch from 1a65c02 to a5ccfbe Compare September 5, 2024 05:37
@kiwichris
Copy link
Author

I have pushed changes to fix the formatting. I did the changes manually from the diff in the CI log.

Is this OK?

@hjunkes
Copy link

hjunkes commented Oct 5, 2024

I found a problem when I wanted to use iocStats for beaglebone black (arm).
I had to change the following:
diff --git a/devIocStats/os/RTEMS/osdClustInfo.c b/devIocStats/os/RTEMS/osdClustInfo.c
index 1e07474..e1c74b7 100644
--- a/devIocStats/os/RTEMS/osdClustInfo.c
+++ b/devIocStats/os/RTEMS/osdClustInfo.c
@@ -110,6 +110,8 @@ int devIocStatsGetClusterInfo(int pool, clustInfo *pval) {
return 0;
}

+int devIocStatsGetClusterUsage(int pool, int pval) { return -1; }
+
#else /
RTEMS_LIBBSD_STACK */

/* This would otherwise need _KERNEL to be defined... */

@kiwichris kiwichris force-pushed the rtems-6-legacy-libbsd branch from a5ccfbe to 46633e2 Compare March 2, 2025 01:38
@kiwichris
Copy link
Author

@hjunkes thanks for the LibBSD fix. I have added it to the PR with a minor change. The pval argument is int*.

I have build iocStats against RTEMS 6.1 and the MVME2700 BSP and LibBSD.

@kiwichris
Copy link
Author

Ping

@hjunkes
Copy link

hjunkes commented Jan 25, 2026

Sorry for the long delay. I am currently trying RTEMS 7 with rtems-libbsd and EPICS R7.0.9.1-DEV with RTEMS-xilinx_zynq_a9_qemu. Unfortunately, I get a core dump on iocInit if devIocStats.dbd is included.
I need to investigate this.

Starting iocInit
############################################################################
## EPICS R7.0.9.1-DEV
## Rev. R7.0.9-228-gc556e21df5decc3def9f-dirty
## Rev. Date Git: 2025-12-08 09:35:25 +0100
############################################################################

*** FATAL ***
fatal source: 9 (RTEMS_FATAL_SOURCE_EXCEPTION)

R0   = 0x00000000 R8  = 0x00000000
R1   = 0x00000000 R9  = 0x0083a578
R2   = 0x00000000 R10 = 0x0083a50c
R3   = 0x00000000 R11 = 0x00000065
R4   = 0x0faaec00 R12 = 0x00000000
R5   = 0x00892000 SP  = 0x00891fa0
R6   = 0x013da420 LR  = 0x002e02a7
R7   = 0x00000000 PC  = 0x0028a408
CPSR = 0x40010173 VEC = 0x00000004
FPEXC = 0x40000000
FPSCR = 0x80000010
D00 = 0x0000000000000047
D01 = 0x0000000000000000
D02 = 0x0000003f00000040
D03 = 0x0000003d0000003e
D04 = 0x0000006500000066
D05 = 0x0000006300000064
D06 = 0x8040201008040201
D07 = 0x000dca8500100000
D08 = 0x0000000000000000
D09 = 0x0000000000000000
D10 = 0x0000000000000000
D11 = 0x0000000000000000
D12 = 0x0000000000000000
D13 = 0x0000000000000000
D14 = 0x0000000000000000
D15 = 0x0000000000000000
D16 = 0x0000000000000000
D17 = 0x0000000000000000
D18 = 0x412b950a00000000
D19 = 0x3fecec093d966384
D20 = 0x0000000000000000
D21 = 0x0000000000000000
D22 = 0x0000005a0000002d
D23 = 0x0000001e0000003c
D24 = 0x000000140000003c
D25 = 0x0000003c0000000a
D26 = 0x0000000400000004
D27 = 0x0000000400000004
D28 = 0x0070156000701210
D29 = 0x007014780070122c
D30 = 0x007003d800701658
D31 = 0x0070157c00701248
RTEMS version: 7.0.0.8f0f451c7aef41953799a3d35948f4f1cbe47742
RTEMS tools: 15.2.0 20250808 (RTEMS 7, RSB 08d2e69f30b61de6bf0f5dbf06946d12d074d60e, Newlib 038afec1)
executing thread ID: 0x0b010001
executing thread name: _main_

@hjunkes
Copy link

hjunkes commented Jan 25, 2026

It crashes when registering device support for 'devAiStats'.

Breakpoint 2, initDevSup () at ../misc/iocInit.c:452
452	            dset *pdset = registryDeviceSupportFind(pdevSup->name);
(gdb) print pdevSup->name
$8 = 0x12cde68 "devAiStats"
(gdb) c
Continuing.
[Inferior 1 (process 1) exited normally]

@hjunkes
Copy link

hjunkes commented Jan 25, 2026

I have been able to trace this so far to 'memstat_sysctl_uma()':

#0  memstat_sysctl_uma (list=list@entry=0x139de80, flags=flags@entry=0) at ../../freebsd/lib/libmemstat/memstat_uma.c:89
#1  0x00318d5e in memstat_sysctl_all (mtlp=mtlp@entry=0x139de80, flags=flags@entry=0) at ../../freebsd/lib/libmemstat/memstat_all.c:48
#2  0x00107b4c in devIocStatsGetClusterInfo (pool=pool@entry=1, pval=pval@entry=0x83a548 <clustinfo+32>) at ../os/RTEMS/osdClustInfo.c:81
#3  0x0010667a in ai_init (pass=0) at ../devIocStatsAnalog.c:460
#4  ai_init (pass=0) at ../devIocStatsAnalog.c:433
#5  0x00206c7e in dbInitDevSup (pdevSup=<optimized out>, pdset=<optimized out>) at ../dbStatic/dbStaticRun.c:56
#6  0x00208c74 in initDevSup () at ../misc/iocInit.c:458
#7  iocBuild_2 () at ../misc/iocInit.c:173
#8  0x00208f14 in iocBuild () at ../misc/iocInit.c:218
#9  0x0020900a in iocInit () at ../misc/iocInit.c:113
#10 0x002128be in iocInitCallFunc (args=<optimized out>) at ../misc/miscIocRegister.c:26
#11 0x0022f86a in iocshBody (pathname=<optimized out>, commandLine=0x0, macros=<optimized out>) at ../iocsh/iocsh.cpp:1270
#12 0x001052fc in main (argc=<optimized out>, argv=<optimized out>) at ../myExampleMain.cpp:21
(gdb) list
77	 */
78	int
79	memstat_sysctl_uma(struct memory_type_list *list, int flags)
80	{
81		struct uma_stream_header *ushp;
82		struct uma_type_header *uthp;
83		struct uma_percpu_stat *upsp;
84		struct memory_type *mtp;
85		int count, hint_dontsearch, i, j, maxcpus, maxid;
86		char *buffer, *p;
87		size_t size;
88
89		hint_dontsearch = LIST_EMPTY(&list->mtl_list);
(gdb) next
memstat_sysctl_uma (list=list@entry=0x139de80, flags=flags@entry=0) at ../../freebsd/lib/libmemstat/memstat_uma.c:113
113		if (sysctlbyname("vm.zone_count", &count, &size, NULL, 0) < 0) {
(gdb) next
125		size = sizeof(*uthp) + count * (sizeof(*uthp) + sizeof(*upsp) *
(gdb) next
128		buffer = malloc(size);
(gdb) next
134		if (sysctlbyname("vm.zone_stats", buffer, &size, NULL, 0) < 0) {
(gdb) next
129		if (buffer == NULL) {
(gdb) next
[Inferior 1 (process 1) exited normally]

@hjunkes
Copy link

hjunkes commented Jan 26, 2026

Error in freebsd/sys/vm/uma_core.c,

uma_vm_zone_stats(struct uma_type_header *uth, uma_zone_t z, struct sbuf *sbuf,
struct uma_percpu_stat *ups, bool internal)

uma_zone_t z == 0 ??

(gdb) print z->uz_sleeps
Cannot access memory at address 0x0
(gdb) list 5715
5703		uma_zone_domain_t zdom;
5704		uma_cache_t cache;
5705		int i;
5706
5707		for (i = 0; i < vm_ndomains; i++) {
5708			zdom = ZDOM_GET(z, i);
5709			uth->uth_zone_free += zdom->uzd_nitems;
5710		}
5711		uth->uth_allocs = counter_u64_fetch(z->uz_allocs);
5712		uth->uth_frees = counter_u64_fetch(z->uz_frees);
5713		uth->uth_fails = counter_u64_fetch(z->uz_fails);
5714		uth->uth_xdomain = counter_u64_fetch(z->uz_xdomain);
5715		uth->uth_sleeps = z->uz_sleeps;
5716
5717		for (i = 0; i < mp_maxid + 1; i++) {
5718			bzero(&ups[i], sizeof(*ups));
5719			if (internal || CPU_ABSENT(i))
5720				continue;
5721			cache = &z->uz_cpu[i];
5722			ups[i].ups_cache_free += cache->uc_allocbucket.ucb_cnt;
5723			ups[i].ups_cache_free += cache->uc_freebucket.ucb_cnt;
5724			ups[i].ups_cache_free += cache->uc_crossbucket.ucb_cnt;
5725			ups[i].ups_allocs = cache->uc_allocs;
5726			ups[i].ups_frees = cache->uc_frees;
5727		}
(gdb) bt
#0  sysctl_vm_zone_stats (oidp=0x711d80 <_bsd_sysctl___vm_zone_stats>, arg1=0x0, arg2=0, req=0x8920b0)
    at ../../freebsd/sys/vm/uma_core.c:5743
#1  0x00287442 in sysctl_root_handler_locked (oid=0x711d80 <_bsd_sysctl___vm_zone_stats>, arg1=0x0, arg2=0, req=0x8920b0,
    tracker=<synthetic pointer>) at ../../freebsd/sys/kern/kern_sysctl.c:203
#2  sysctl_root (oidp=0x0, arg1=0x0, arg2=0, req=0x8920b0) at ../../freebsd/sys/kern/kern_sysctl.c:2327
#3  _bsd_kernel_sysctl (td=td@entry=0x0, name=name@entry=0x892118, namelen=<optimized out>, old=old@entry=0x193eb20,
    oldlenp=oldlenp@entry=0x892224, new=new@entry=0x0, newlen=newlen@entry=0, retval=retval@entry=0x892224,
    flags=flags@entry=0) at ../../freebsd/sys/kern/kern_sysctl.c:2050
#4  0x002e4928 in sysctl (name=0x892178, namelen=<optimized out>, oldp=0x193eb20, oldlenp=0x892224, newp=0x0, newlen=0)
    at ../../rtemsbsd/rtems/rtems-bsd-syscall-api.c:858
#5  sysctlbyname (name=name@entry=0x55b5b8 "vm.zone_stats", oldp=oldp@entry=0x193eb20, oldlenp=oldlenp@entry=0x892224,
    newp=newp@entry=0x0, newlen=newlen@entry=0) at ../../rtemsbsd/rtems/rtems-bsd-syscall-api.c:886
#6  0x00318dca in memstat_sysctl_uma (list=list@entry=0x139dc18, flags=flags@entry=0)
    at ../../freebsd/lib/libmemstat/memstat_uma.c:134
#7  0x00318d5e in memstat_sysctl_all (mtlp=mtlp@entry=0x139dc18, flags=flags@entry=0)
    at ../../freebsd/lib/libmemstat/memstat_all.c:48
#8  0x00107b4c in devIocStatsGetClusterInfo (pool=pool@entry=1, pval=pval@entry=0x83a548 <clustinfo+32>)
    at ../os/RTEMS/osdClustInfo.c:81
#9  0x0010667a in ai_init (pass=0) at ../devIocStatsAnalog.c:460
#10 ai_init (pass=0) at ../devIocStatsAnalog.c:433
#11 0x00206c7e in dbInitDevSup (pdevSup=<optimized out>, pdset=<optimized out>) at ../dbStatic/dbStaticRun.c:56
#12 0x00208c74 in initDevSup () at ../misc/iocInit.c:458
#13 iocBuild_2 () at ../misc/iocInit.c:173
#14 0x00208f14 in iocBuild () at ../misc/iocInit.c:218
#15 0x0020900a in iocInit () at ../misc/iocInit.c:113
#16 0x002128be in iocInitCallFunc (args=<optimized out>) at ../misc/miscIocRegister.c:26
#17 0x0022f86a in iocshBody (pathname=<optimized out>, commandLine=0x0, macros=<optimized out>) at ../iocsh/iocsh.cpp:1270
#18 0x001052fc in main (argc=<optimized out>, argv=<optimized out>) at ../myExampleMain.cpp:21

@kiwichris
Copy link
Author

kiwichris commented Jan 26, 2026

Thanks @hjunkes for the detailed report and debugging. It looks like a bug in the zone allocation port to RTEMS.

I have opened an issue in RTEMS https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/issues/74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants