LibBSD | ZONE(9): Fix per-CPU counters on SMP (!165)

Sebastian Huber (@sebhub) gitlab at rtems.org
Sat Oct 3 06:59:01 UTC 2026



Sebastian Huber created a merge request: https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/merge_requests/165

Project:Branches: sebhub/rtems-libbsd:counter-smp to rtems/pkg/rtems-libbsd:7-freebsd-14
Author: Sebastian Huber

## Summary

Issue #112: counter_u64 is broken on SMP archs

The update to FreeBSD 14 dropped the processor offset from `zpcpu_get()`. All processors added to the slot of processor 0 without an atomic operation.

The new `keg_layout()` places the items of a per-CPU slab in its first page and the copy of each processor in a page of its own. The RTEMS value of `UMA_PCPU_ALLOC_SIZE` was `PAGE_SIZE / 32`. `counter_u64_fetch()` therefore added the values of unrelated counters, and an `M_ZERO` allocation cleared them. This gave the `netstat -i` output of the issue.

Use `PAGE_SIZE` for `UMA_PCPU_ALLOC_SIZE` and restore the processor offset in `zpcpu_get()`, as FreeBSD does. Give the size of the early counter in `uint64_t` elements. On a target with 32 processors, the early counter takes 128 KiB.

The new test `counter01` checks the sum of each counter and the slot of each processor. It fails without the fix. With the fix, `counter01`, `epoch01`, `smp01`, `loopback01` and `init01` pass. `origin/6-freebsd-14` has the same defect.

**BSP** sparc/gr740 with RTEMS_SMP · **Simulator** sis -gr740 -m 4

## AI Details
<!-- Make sure you have read our statement at https://www.rtems.org/generative-ai/ -->

### Prompt used

None as a single prompt. The work was done in an interactive Claude Code session on the rtems-libbsd tree. The task was to fix issue #112. Each change was directed and reviewed.

### AI model used

Claude Opus 5.5 (claude-opus-5-5), through Claude Code.

### How AI was used for the contribution

- ( ) Formatting
- (x) Test creation.
- (x) Code comments.
- ( ) The entire contribution was generated using AI
- ( ) AI code completion such as Copilot in VSCode.

The diagnosis, the implementation and the test were produced in that session under my direction, and the commit message was drafted there.

### Access

I have not used a product which claims copyright in its output, and I have legitimate access to the one I used.

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/merge_requests/165
You're receiving this email because of your account on gitlab.rtems.org. Unsubscribe from this thread: https://gitlab.rtems.org/-/namespace/20/sent_notifications/5-d4xl71byswr865szp3rz0clsm-k/unsubscribe | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | Help: https://gitlab.rtems.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20261003/3a4b20c8/attachment-0001.htm>


More information about the bugs mailing list