Skip to content

Conversation

@hujun260
Copy link
Contributor

Summary

Currently, if we need to schedule a task to another CPU, we have to completely halt the other CPU,
manipulate the scheduling linked list, and then resume the operation of that CPU. This process is both time-consuming and unnecessary.

During this process, both the current CPU and the target CPU are inevitably subjected to busyloop.

The improved strategy is to simply send a cross-core interrupt to the target CPU.
The current CPU continues to run while the target CPU responds to the interrupt, eliminating the certainty of a busyloop occurring.

Impact

all smp arch

Testing

We performed performance testing on the Cortex-R82 ARM64 SMP chip. Sending messages through a message queue which causes context switching. We recorded the time from sending a message to receiving it, with the time unit being cycles.
image

we also use monkey test in armv7-a

@github-actions github-actions bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: sparc Issues related to the SPARC architecture Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Area: OS Components OS Components issues Size: L The size of the change in this PR is large labels Sep 26, 2024
@nuttxpr
Copy link

nuttxpr commented Sep 26, 2024

[Experimental Bot, please feedback here]

NuttX PR Requirements Review

This PR appears to meet most NuttX requirements, but some clarifications are needed:

Strengths:

  • Clear Summary: The summary explains the problem (inefficient cross-core task scheduling), the solution (cross-core interrupts), and the benefits (reduced overhead, no busyloops).
  • Impact Well-Defined: The impact on SMP architectures is noted, but more details are needed for each "Impact" sub-point (User, Build, Hardware, Documentation, Security, Compatibility). For example:
    • User: Will applications need to change how they schedule tasks across cores?
    • Build: Are any new configuration options introduced?
    • Hardware: Are specific interrupt mechanisms required on target platforms?
  • Testing Provided: Performance testing results are included, demonstrating improvements on a specific platform.

Areas for Improvement:

  • Complete Impact Assessment: Provide specific answers for each impact sub-point. Even if the answer is "NO," briefly explain why.
  • Testing Details:
    • Environment: Specify the OS, CPU, compiler used for the build host in the "Testing" section.
    • Target Details: Provide the full board:config used for the Cortex-R82 tests.
    • Monkey Test: Briefly describe the "monkey test" and its significance.
    • Before/After Logs: The "Testing logs" sections are empty. Include relevant log snippets showing the improvement.

Conciseness: The provided information is concise and well-written.

Overall:

This PR demonstrates a promising improvement, but requires a more thorough impact assessment and additional testing details before it can be considered complete.

@masayuki2009
Copy link
Contributor

all smp arch

@hujun260
Which configurations did you test with this PR?

@hujun260
Copy link
Contributor Author

all smp arch

@hujun260 Which configurations did you test with this PR?

qemu-armv7a:smp
qemu-armv8a:nsh_smp

@masayuki2009
Copy link
Contributor

all smp arch

@hujun260 Which configurations did you test with this PR?

qemu-armv7a:smp qemu-armv8a:nsh_smp

Please test esp32-devkitc:smp, rv-virt:smp, rv-virt:smp64, rv-virt:ksmp64 and sim:smp, since the PR affects these architectures.
Aslo, if you have spresense and raspberrypi-pico, please test the boards as well.

@hujun260
Copy link
Contributor Author

all smp arch

@hujun260 Which configurations did you test with this PR?

qemu-armv7a:smp qemu-armv8a:nsh_smp

Please test esp32-devkitc:smp, rv-virt:smp, rv-virt:smp64, rv-virt:ksmp64 and sim:smp, since the PR affects these architectures. Aslo, if you have spresense and raspberrypi-pico, please test the boards as well.

esp32-devkitc:smp ostest test ok
sim:smp can't boot, not caused by this pr
rv-virt:smp ostest test ok
rv-virt:smp64 ostest test ok
rv-virt:ksmp64 ostest test ok (except vfork break introdced by #12812)
raspberrypi-pico:smp ostest test ok

reason:
Currently, if we need to schedule a task to another CPU, we have to completely halt the other CPU,
manipulate the scheduling linked list, and then resume the operation of that CPU. This process is both time-consuming and unnecessary.

During this process, both the current CPU and the target CPU are inevitably subjected to busyloop.

The improved strategy is to simply send a cross-core interrupt to the target CPU.
The current CPU continues to run while the target CPU responds to the interrupt, eliminating the certainty of a busyloop occurring.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
       which can save processing time.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 merged commit d470764 into apache:master Sep 29, 2024
@hujun260 hujun260 deleted the apache_13 branch September 29, 2024 03:27
@masayuki2009
Copy link
Contributor

@hujun260
After merging this PR, I noticed that the hello app hangs with qemu-intel64:smp.

NuttShell (NSH) NuttX-12.0.0
nsh>  
nsh> uname -a
NuttX 12.0.0 d4707646d5 Sep 30 2024 09:52:36 x86_64 qemu-intel64
nsh> mount
  /proc type procfs
nsh> ps
  PID GROUP CPU PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK COMMAND
    0     0   0   0 FIFO     Kthread   - Assigned           0000000000000000 4194280 CPU0 IDLE
    1     0   1   0 FIFO     Kthread   - Running            0000000000000000 4194272 CPU1 IDLE
    2     2   0 100 FIFO     Task      - Running            0000000000000000 4194240 nsh_main
nsh> free
                 total       used       free    maxused    maxfree  nused  nfree
      Umem:  241659896    4201320  237458576    4202112  237458576     34      1
nsh> kill -4 0
nsh> kill -4 1
nsh> hello
Hello, World!!

Also,

sim:smp can't boot, not caused by this pr

Hmm, but you modified the sim-related code as well.
This means that you've never tested this code with the sim:smp but pushed the code.

@hujun260
Copy link
Contributor Author

hujun260 commented Sep 30, 2024

@hujun260 After merging this PR, I noticed that the hello app hangs with qemu-intel64:smp.

NuttShell (NSH) NuttX-12.0.0
nsh>  
nsh> uname -a
NuttX 12.0.0 d4707646d5 Sep 30 2024 09:52:36 x86_64 qemu-intel64
nsh> mount
  /proc type procfs
nsh> ps
  PID GROUP CPU PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK COMMAND
    0     0   0   0 FIFO     Kthread   - Assigned           0000000000000000 4194280 CPU0 IDLE
    1     0   1   0 FIFO     Kthread   - Running            0000000000000000 4194272 CPU1 IDLE
    2     2   0 100 FIFO     Task      - Running            0000000000000000 4194240 nsh_main
nsh> free
                 total       used       free    maxused    maxfree  nused  nfree
      Umem:  241659896    4201320  237458576    4202112  237458576     34      1
nsh> kill -4 0
nsh> kill -4 1
nsh> hello
Hello, World!!

Also,

sim:smp can't boot, not caused by this pr

Hmm, but you modified the sim-related code as well. This means that you've never tested this code with the sim:smp but pushed the code.

qemu-intel64:smp, i'll fix it as soon as possible #13749
sim fix #13753

hujun260 added a commit to hujun260/nuttx that referenced this pull request Sep 30, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from apache#13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
hujun260 added a commit to hujun260/nuttx that referenced this pull request Sep 30, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from apache#13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
hujun260 added a commit to hujun260/nuttx that referenced this pull request Sep 30, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from apache#13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
masayuki2009 pushed a commit that referenced this pull request Oct 1, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from #13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
raiden00pl pushed a commit to raiden00pl/nuttx that referenced this pull request Oct 5, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from apache#13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
jerpelea pushed a commit to jerpelea/nuttx that referenced this pull request Oct 10, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from apache#13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
xiaoxiang781216 pushed a commit that referenced this pull request Oct 10, 2024
reason:
In x86_64, g_current_regs is still used for context switching.

This commit fixes the regression from #13616

Signed-off-by: hujun5 <hujun5@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: sparc Issues related to the SPARC architecture Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Area: OS Components OS Components issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants