[I] [BUG] hartid and cpuid mismatch for RISCV when CONFIG_ARCH_RV_CPUID_MAP is configured [nuttx]</span></a></span> </h1> <p class="darkgray font13"> <span class="sender pipe"><a href="/search?l=commits@nuttx.apache.org&q=from:%22via+GitHub%22" rel="nofollow"><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">via GitHub</span></span></a></span> <span class="date"><a href="/search?l=commits@nuttx.apache.org&q=date:20260806" rel="nofollow">Thu, 06 Aug 2026 02:18:58 -0700</a></span> </p> </div> <div itemprop="articleBody" class="msgBody"> <!--X-Body-of-Message--> <pre> evolution124 opened a new issue, #19713: URL: <a rel="nofollow" href="https://github.com/apache/nuttx/issues/19713">https://github.com/apache/nuttx/issues/19713</a></pre><pre> ### Description / Steps to reproduce the issue CONFIG_ARCH_RV_CPUID_MAP is configured 1. bellow code using g_cpux_idlestack to get stack but without translate cpuid to hartid ``` arch/risc-v/src/common/riscv_cpuidlestack.c //will read stack by cpuid stack_alloc = (uintptr_t)g_cpux_idlestack(cpu); ``` ``` arch/risc-v/src/common/riscv_initialstate.c // will read stack by cpuid tcb->stack_alloc_ptr = (void *)g_cpux_idlestack(this_cpu()); ``` ``` arch/risc-v/src/common/riscv_common_memorymap.h //using cpuid to read stack #define g_cpux_idlestack(cpuid) \ (g_idle_topstack - SMP_STACK_SIZE * (CONFIG_SMP_NCPUS - (cpuid))) ``` 2. if using customized cpuid to hartid mapping like bellow, stack is wrong. ``` int riscv_hartid_to_cpuid(int hart) { #ifdef CONFIG_SMP int cpu_id = -1; switch(hart) { case 0: cpu_id = 0; break; case 1: cpu_id = 2; break; case 2: cpu_id = 1; break; default : DEBUGASSERT(0); break; } return cpu_id; #else return 0; #endif } int riscv_cpuid_to_hartid(int cpu) { #ifdef CONFIG_SMP int hart_id = -1; switch(cpu) { case 0: hart_id = 0; break; case 1: hart_id = 2; break; case 2: hart_id = 1; break; default : DEBUGASSERT(0); break; } return hart_id; #else return up_cpu_index(); #endif } ``` ### On which OS does this issue occur? [OS: Linux] ### What is the version of your OS? Ubuntu 22.04.4 LTS ### NuttX Version 96f440f0c068f278cc11a956c2c6cf52ff79cf01 ### Issue Architecture [Arch: risc-v] ### Issue Area [Area: Kernel] ### Host information 1. g_cpux_idlestack dose not translate cpuid to hartid ` arch/risc-v/src/common/riscv_cpuidlestack.c // using cpuid to get stack stack_alloc = (uintptr_t)g_cpux_idlestack(cpu); ` ` arch/risc-v/src/common/riscv_initialstate.c // using cpuid to get stack `tcb->stack_alloc_ptr = (void *)g_cpux_idlestack(this_cpu());` ` ` arch/risc-v/src/common/riscv_common_memorymap.h #define g_cpux_idlestack(cpuid) \ (g_idle_topstack - SMP_STACK_SIZE * (CONFIG_SMP_NCPUS - (cpuid))) ` 2. if using hartid to cpudid mapping like bellow, will get wrong stack, because, we using hartid to setup stack ` int riscv_hartid_to_cpuid(int hart) { #ifdef CONFIG_SMP int cpu_id = -1; switch(hart) { case 0: cpu_id = 0; break; case 1: cpu_id = 2; break; case 2: cpu_id = 1; break; default : DEBUGASSERT(0); break; } return cpu_id; #else return 0; #endif } int riscv_cpuid_to_hartid(int cpu) { #ifdef CONFIG_SMP int hart_id = -1; switch(cpu) { case 0: hart_id = 0; break; case 1: hart_id = 2; break; case 2: hart_id = 1; break; default : DEBUGASSERT(0); break; } return hart_id; #else return up_cpu_index(); #endif } ` ### Verification - [x] I have verified before submitting the report. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org </pre> </div> <div class="msgButtons margintopdouble"> <ul class="overflow"> <li class="msgButtonItems"><a class="button buttonleft " accesskey="p" href="msg167909.html">Previous message</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="c" href="index.html#167911">View by thread</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="i" href="maillist.html#167911">View by date</a></li> <li class="msgButtonItems textalignright"><a class="button buttonright " accesskey="n" href="msg167926.html">Next message</a></li> </ul> </div> <a name="tslice"></a> <div class="tSliceList margintopdouble"> <ul class="icons monospace"> <li class="icons-email tSliceCur"><span class="subject">[I] [BUG] <title>hartid and cpuid mismatch for RISCV when...</span> <span class="sender italic">via GitHub</span></li> <li><ul> <li class="icons-email"><span class="subject"><a href="msg167926.html">Re: [I] [BUG] <title>hartid and cpuid mismatch for R...</a></span> <span class="sender italic">via GitHub</span></li> </ul> </ul> </div> <div class="overflow msgActions margintopdouble"> <div class="msgReply" > <h2> Reply via email to </h2> <form method="POST" action="/mailto.php"> <input type="hidden" name="subject" value="[I] [BUG] <title>hartid and cpuid mismatch for RISCV when CONFIG_ARCH_RV_CPUID_MAP is configured [nuttx]"> <input type="hidden" name="msgid" value="I_kwDODZiUac8AAAABLsUWBA@gitbox.apache.org"> <input type="hidden" name="relpath" value="commits@nuttx.apache.org/msg167911.html"> <input type="submit" value=" via GitHub "> </form> </div> </div> </div> <div class="aside" role="complementary"> <div class="logo"> <a href="/"><img src="/logo.png" width=247 height=88 alt="The Mail Archive"></a> </div> <form class="overflow" action="/search" method="get"> <input type="hidden" name="l" value="commits@nuttx.apache.org"> <label class="hidden" for="q">Search the site</label> <input class="submittext" type="text" id="q" name="q" placeholder="Search commits"> <input class="submitbutton" name="submit" type="image" src="/submit.png" alt="Submit"> </form> <div class="nav margintop" id="nav" role="navigation"> <ul class="icons font16"> <li class="icons-home"><a href="/">The Mail Archive home</a></li> <li class="icons-list"><a href="/commits@nuttx.apache.org/">commits - all messages</a></li> <li class="icons-about"><a href="/commits@nuttx.apache.org/info.html">commits - about the list</a></li> <li class="icons-expand"><a href="/search?l=commits@nuttx.apache.org&q=subject:%22%5C%5BI%5C%5D+%5C%5BBUG%5C%5D+%3Ctitle%3Ehartid+and+cpuid+mismatch+for+RISCV+when+CONFIG_ARCH_RV_CPUID_MAP+is+configured+%5C%5Bnuttx%5C%5D%22&o=newest&f=1" title="e" id="e">Expand</a></li> <li class="icons-prev"><a href="msg167909.html" title="p">Previous message</a></li> <li class="icons-next"><a href="msg167926.html" title="n">Next message</a></li> </ul> </div> <div class="listlogo margintopdouble"> </div> <div class="margintopdouble"> </div> </div> </div> <div class="footer" role="contentinfo"> <ul> <li><a href="/">The Mail Archive home</a></li> <li><a href="/faq.html#newlist">Add your mailing list</a></li> <li><a href="/faq.html">FAQ</a></li> <li><a href="/faq.html#support">Support</a></li> <li><a href="/faq.html#privacy">Privacy</a></li> <li class="darkgray">I_kwDODZiUac8AAAABLsUWBA@gitbox.apache.org</li> </ul> </div> </body> </html>