<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">

<p class="details" style="font-style: italic; color: #626168;">
Issue created by <a href="https://gitlab.rtems.org/mirek23">Miroslaw Dach</a>: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5810">#5810</a>
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<div class="gl-relative markdown-code-block js-markdown-code" style="margin-top: 0px;">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0px 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" data-lang="plaintext" style="margin-top: 0px;">Board: Raspberry Pi 3 Model B+, BSP arm/raspberrypi2, RTEMS 6.2 (be446b02d0)</span>
<span id="LC2" class="line" data-lang="plaintext">and main (4bca987369, same code), rtems-libbsd 6-freebsd-14, EPICS 7.0.10 IOC.</span>
<span id="LC3" class="line" data-lang="plaintext"></span>
<span id="LC4" class="line" data-lang="plaintext">Symptom: with USB (LAN7800 Ethernet) interrupt load the system freezes</span>
<span id="LC5" class="line" data-lang="plaintext">completely after seconds to minutes: console dead, no task runs. It looked</span>
<span id="LC6" class="line" data-lang="plaintext">like a bus or CPU lockup.</span>
<span id="LC7" class="line" data-lang="plaintext"></span>
<span id="LC8" class="line" data-lang="plaintext">Cause: bsp_interrupt_dispatch() in bsps/arm/raspberrypi/irq/irq.c reads</span>
<span id="LC9" class="line" data-lang="plaintext">BCM2835_IRQ_BASIC and, when any speed-up bit is set, calls ffs() on the</span>
<span id="LC10" class="line" data-lang="plaintext">UNMASKED value:</span>
<span id="LC11" class="line" data-lang="plaintext"></span>
<span id="LC12" class="line" data-lang="plaintext">    pend = BCM2835_REG(BCM2835_IRQ_BASIC);</span>
<span id="LC13" class="line" data-lang="plaintext">    if ( pend & BCM2835_IRQ_BASIC_SPEEDUP_USED_BITS ) {</span>
<span id="LC14" class="line" data-lang="plaintext">      pend_bit = ffs(pend) - 1;</span>
<span id="LC15" class="line" data-lang="plaintext">      vector = bcm2835_irq_speedup_table[pend_bit];</span>
<span id="LC16" class="line" data-lang="plaintext"></span>
<span id="LC17" class="line" data-lang="plaintext">Bit 8 of IRQ_BASIC ("one or more bits set in pending register 1") is set</span>
<span id="LC18" class="line" data-lang="plaintext">whenever a bank-1 interrupt without a speed-up bit is pending, e.g. the</span>
<span id="LC19" class="line" data-lang="plaintext">system timer compare 3 used for the clock tick (GPU IRQ 3). If that happens</span>
<span id="LC20" class="line" data-lang="plaintext">while a speed-up interrupt (USB, GPU IRQ 9, speed-up bit 11) is pending too,</span>
<span id="LC21" class="line" data-lang="plaintext">the register reads 0x900. ffs(0x900) - 1 = 8, bcm2835_irq_speedup_table[8]</span>
<span id="LC22" class="line" data-lang="plaintext">is -1, vector becomes 0xffffffff, the "vector < 255" check fails, no handler</span>
<span id="LC23" class="line" data-lang="plaintext">runs, the interrupt stays asserted and the CPU re-enters the dispatcher</span>
<span id="LC24" class="line" data-lang="plaintext">forever.</span>
<span id="LC25" class="line" data-lang="plaintext"></span>
<span id="LC26" class="line" data-lang="plaintext">Evidence: a RAM trace surviving the watchdog reset shows, in every frozen</span>
<span id="LC27" class="line" data-lang="plaintext">run, the last 600 entries as IRQ_BASIC reads returning 0x900 at about</span>
<span id="LC28" class="line" data-lang="plaintext">1.3 million per second with no handler call in between. The probability per</span>
<span id="LC29" class="line" data-lang="plaintext">interrupt is small, so the time to failure scales with the interrupt rate</span>
<span id="LC30" class="line" data-lang="plaintext">(about 30 s at 40000 USB interrupts/s plus a 2 kHz tick).</span>
<span id="LC31" class="line" data-lang="plaintext"></span>
<span id="LC32" class="line" data-lang="plaintext">Fix: mask before the bit scan,</span>
<span id="LC33" class="line" data-lang="plaintext">    pend_bit = ffs(pend & BCM2835_IRQ_BASIC_SPEEDUP_USED_BITS) - 1;</span>
<span id="LC34" class="line" data-lang="plaintext">With 0x900 the USB interrupt is dispatched first; the immediate re-entry</span>
<span id="LC35" class="line" data-lang="plaintext">sees 0x100, takes the IRQ_PENDING1 path and dispatches the tick.</span>
<span id="LC36" class="line" data-lang="plaintext"></span>
<span id="LC37" class="line" data-lang="plaintext">Tested: 15.5 h continuous operation with 450 million USB transfers and</span>
<span id="LC38" class="line" data-lang="plaintext">1.8 billion interrupts, then a second run of more than 17 h with a 1 kHz</span>
<span id="LC39" class="line" data-lang="plaintext">EPICS scan, versus a freeze within a minute before the change.</span>
<span id="LC40" class="line" data-lang="plaintext"></span>
<span id="LC41" class="line" data-lang="plaintext">Mailing list thread: "EPICS ioc with RTEMS on Raspberry Pi", users@/devel@,</span>
<span id="LC42" class="line" data-lang="plaintext">2026-10-14.</span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<h2 id="user-content-mr-description" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">MR description<a href="#mr-description" aria-label="Link to heading 'MR description'" data-heading-content="MR description" class="anchor" style="margin-top: 0px;"></a>
</h2>
<div class="gl-relative markdown-code-block js-markdown-code" style="margin-bottom: 0px;">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0px 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" data-lang="plaintext" style="margin-top: 0px;">bsp_interrupt_dispatch() of the raspberrypi BSP feeds the unmasked</span>
<span id="LC2" class="line" data-lang="plaintext">BCM2835_IRQ_BASIC value to ffs(). When a bank-1 interrupt (clock tick) and a</span>
<span id="LC3" class="line" data-lang="plaintext">speed-up interrupt (USB) are pending together the register reads 0x900,</span>
<span id="LC4" class="line" data-lang="plaintext">ffs() selects bit 8 whose speedup-table entry is -1, no handler is called</span>
<span id="LC5" class="line" data-lang="plaintext">and the CPU loops in the dispatcher forever. Mask the value with</span>
<span id="LC6" class="line" data-lang="plaintext">BCM2835_IRQ_BASIC_SPEEDUP_USED_BITS before the bit scan.</span>
<span id="LC7" class="line" data-lang="plaintext"></span>
<span id="LC8" class="line" data-lang="plaintext">Tested on Raspberry Pi 3B+ with rtems-libbsd USB Ethernet and an EPICS 7</span>
<span id="LC9" class="line" data-lang="plaintext">IOC: >15 h and >17 h soak runs without a freeze, versus a freeze within a</span>
<span id="LC10" class="line" data-lang="plaintext">minute before. The same code is in the 6 branch; a backport is requested.</span>
<span id="LC11" class="line" data-lang="plaintext"></span>
<span id="LC12" class="line" data-lang="plaintext">Close #N.</span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
</div>

</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5810">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/namespace/49/sent_notifications/6-159594alh521pcwwlu0jzevpv-1d/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5810 at 1792299199
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Work item","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5810"}}</script>


</p>
</div>
</body>
</html>