-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor arm interrupt stack related code #2061
Conversation
Signed-off-by: Masayuki Ishikawa <[email protected]>
g_intstackalloc: | ||
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) | ||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we align up here? ((CONFIG_ARCH_INTERRUPTSTACK + 7) & ~7)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ouss4
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the alignment need sync with the code in stack setup and dump. for example here is line 70:
# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 8
if we select the align up, the above logic is wrong and should change to CONFIG_ARCH_INTERRUPTSTACK < 1.
So, I would like to keep the logic as simple as possible instead bringing up more inconsistentence like this. The round down logic is more suitable choice because I don't think there is much difference betwen 2000 and 2008 if user set CONFIG_ARCH_INTERRUPTSTACK to 2006. The consistent round strategy across all related code is more important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiaoxiang781216 why would that line be wrong? We use CONFIG_ARCH_INTERRUPTSTACK < ALIGN_REQUIREMENT
to mean that there is no interrupt stack. We are not changing CONFIG_ARCH_INTERRUPTSTACK
.
But yes, when dumping and checking the stack we always use the align down. Not sure why, if we have a consistent INTSTACK_SIZE (whether aligned up or down) wouldn't that suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the intension is aligned up, CONFIG_ARCH_INTERRUPTSTACK> 0 && CONFIG_ARCH_INTERRUPTSTACK < 7 is a correct stack value(even it's crazy that the stack has 8 bytes, but it correct from logic). Yes, as I mention before the key point is to use the alignup or aligndown consistently in all place, but since algindown is use in many place and there isn't real difference between alignup and aligndown, I would prefer to use the aligndown across the related code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ouss4
Thanks, I keep the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the thing. Nuttx does not support nested interrupt. If a design is super low on memory (it happens) the interrupt stack allocation has to not round down. If know the CONFIG (FPU etc) the size of the int stack is a fixed number . If I ask for That number and get a stack that is less it will over write memory. This will be a debugging nightmare! Please round it UP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR doesn't change the round behaviour, please don't do the different thing in one PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need keep the old code after disscussion
91b8f9d
to
3a0b9ec
Compare
@masayuki2009 Thank you for the PR and all the information on what was done. Would you please add some back ground as to why these changes are needed? |
@davids5 Anyway, thanks for pointing out. |
Signed-off-by: Masayuki Ishikawa <[email protected]>
3a0b9ec
to
920390f
Compare
@Ouss4 @xiaoxiang781216 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@masayuki2009 do you have plan to fix -4/-8 issue for idle thread stack and normal task/thread stack? |
@Ouss4 do you have more comment? otherwise, I will merge this patch. |
@xiaoxiang781216, @MasayukiIshikawa, @Ouss4 I would like to test this on HW. I also think we need to define Top, bottom, base in terms of addresses. Thing like this read wrong
high address <-sp I need to review this more carefully, but it look to me that were are adding instructions for alignment when the compiler can do it. Update: |
Sure, let's wait your test.
Yes, the term usage is strange, but it is an unrelated issue. It's better to create new PR to fix the term issue.
|
LGTM, but let's wait for David's input.
In terms of address, "base" is "top" for a push-down stack, this is what's making things a bit confusing. However, I believe it's used consistently: |
@masayuki2009 - I have tested this. My only 2 concerns are 1) Not rounding UP (see #2061 (comment)), and 2 this change: Would you help me understand if is it correct? Are we using Descending Empty or Descending Full? |
@xiaoxiang781216 Agreed it can be changes in another PR.
Yes Memory allocations are base that is understood. The other is a visual thing for me. (I was indoctrinated by my first debugger http://www.pestingers.net/pdfs/s100-computers/vector-graphics/vector-raid-man.pdf - I wish there were pics) I find it incorrect and confusing on descending stack arch. Please read this with a smile....it it written with one...... Where do we put the lamp shade on a lamp? On the top or the base. |
The rounddown exist for a long time and nobody complain this behvaiour. if you think the roundup is better, please create a new PR to fix it. (#2061 (comment))), and 2 this change:
We can't select here, ARM require the descending full stack: |
Thanks @xiaoxiang781216 So.. Descending-full then implies: Correct? Then isn't the changes with SP-X wrong? The value at [SP-X] get overwritten by any push's in the call chain of arm_decodeirq. Or am I seeing this incorrectly? |
Yes, it is correct.
The ! at the end will write back the sp - 4 to sp, so the next push will allocate the new location in the next slot.
|
@masayuki2009 @xiaoxiang781216 On the alignment please see the 86400a2 and the blame. I think in this PR we are reverting a change that fixed a real problem. |
I did not even notice it! Thank you! |
from the change, the stack space allocation round to the near(may roundup or rounddown), but the sp always point to the rounddown location. So I can't understand what problem he want to fix without the detail commit message. At least, the change isn't consistent with other related code(init sp and stack check). |
|
@davids5 , from the description +4 is good fix to support 4 bytes and 8 bytes alignment for different arm arch. |
g_intstackalloc: | ||
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) | ||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need keep the old code after disscussion
Summary: - This commit fixes CPUx IDLE stack top for SMP - Also removes SMP_STACK_TOP from smp.h Impact: - Affects armv7-a SMP only Testing: - Tested with sabre-6quad:smp (QEMU) Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Add CONFIG_DEBUG_FULLOPT=y - Add CONFIG_DEBUG_SYMBOLS=y - Remove CONFIG_HOST_WINDOWS=y - Add CONFIG_READLINE_CMD_HISTORY=y - Add CONFIG_STACK_COLORATION=y Impact: - Affects sabre-6quad:nsh only Testing: - Tested with QEMU Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Remove -4/-8 offset coding in imx_irq.c and arm_vectors.S - Instead, add SP adjustment after calling setirqstack/setfiqstack - Fix off-by-one irq/fiq stack allocation in 8-byte aligned arch - Fix comments on the user stack pointer in arm_vectors.S - Also, fix up_dumpstate() to extract the user stack pointer - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-a with interrupt stack enabled Testing: - Tested with sabre-6quad:smp with QEMU - Tested with sabre-6quad:nsh with QEMU Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Apply the same logic for armv7-a - NOTE: stack pointer alignment is 4-byte Impact: - Affects arm (arm7/9) and c5471 with interrupt stack enabled Testing: - Built with c5471evm.nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Built with ea3131:nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Not tested but should work Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Apply the same logic for armv7-a - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-r with interrupt stack enabled Testing: - Not tested but should work Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Add CONFIG_ARCH_INTERRUPTSTACK=2048 - Add CONFIG_ARMV7M_LAZYFPU=y - Add CONFIG_TESTING_OSTEST_FPUSIZE=132 Impact: - Affects stm32f4discovery:wifi only Testing: - Tested with ostest, uSD card, Wi-Fi Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Remove +4/-8 offset coding - Also, fix alignments for g_intstackalloc - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-m with interrupt stack enabled Testing: - Tested with spresense:wifi_smp - Tested with lc823450:smp - Tested with stm32f4discovery:wifi Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Apply the same logic for armv7-m - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv8-m with interrupt stack enabled Testing: - Not tested but should work Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - Apply the same logic for armv7-m - NOTE: stack pointer alignment is 4-byte Impact: - Affects armv6-m with interrupt stack enabled Testing: - Built with freedom-kl25z:nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Not tested but should work Signed-off-by: Masayuki Ishikawa <[email protected]>
Summary: - This commit fixes kernel stack dump information Impact: - Affects armv7-a with kernel build Testing: - Built with sama5d4-ek:knsh - Not tested Signed-off-by: Masayuki Ishikawa <[email protected]>
920390f
to
df8c323
Compare
@Ouss4, @davids5, @xiaoxiang781216 @davids5 |
LGTM, @davids5 please help verify and merge the change. |
@xiaoxiang781216 I will, but it will Monday. |
hmmm, That pic was from my email, maybe we can ask @patacongo if it can be restored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masayuki2009 - I have tested this on an M7 and M3 core. AOK!
@davids5 |
Summary
Impact
Testing