Skip to content

os/drivers/cpu, apps/system: Add CPU driver interface and test app#7033

Open
mukku-suneel wants to merge 3 commits intoSamsung:masterfrom
mukku-suneel:cpu_on_off_driver
Open

os/drivers/cpu, apps/system: Add CPU driver interface and test app#7033
mukku-suneel wants to merge 3 commits intoSamsung:masterfrom
mukku-suneel:cpu_on_off_driver

Conversation

@mukku-suneel
Copy link
Copy Markdown
Contributor

@mukku-suneel mukku-suneel commented Nov 6, 2025

Add Secondary CPUs management interface with character driver interface,
test application and board configuration support.

CPU Driver:

  • Add character driver for CPU management through /dev/cpuX device nodes
  • Provide ioctl interface for CPU enable/disable and state operations

Test Application:

  • Add cputest application with shell commands for testing CPU driver functionality.
  • Provides commands to enable/disable secondary CPUs and check CPU status through device interface.
  • Register commands during system initialization

Configuration:

  • Enable CPU driver in rtl8730e board configurations
  • Add Kconfig options for CPU driver and test application

Shell commands added:

  • cpuctrl on <cpu_id>: Power on specified CPU
  • cpuctrl off <cpu_id>: Power off specified CPU
  • cpuctrl status: Show status of all Secondary CPUs
  • cpuctrl help : Show the help message
**Test Results: **

TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 0 (running)

TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU1
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU1
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU1
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU1
  Main[0]: Thread 8 created
Thread[2]: Calling pthread_barrier_wait()
Thread[1]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
Thread[6]: Done
Thread[1]: Done
Thread[3]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[7]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>
TASH>>cpuctrl off 1
TASH>>powering down cpu1!
cpu1 successfully disabled
state: 1 (offline)

TASH>>
TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 1 (offline)

TASH>>
TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU0
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU0
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU0
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU0
  Main[0]: Thread 8 created
Thread[1]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[2]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[1]: Done
Thread[3]: Done
Thread[7]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[6]: Done
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>cpuctrl on 1
TASH>>powering up cpu1!
cpu1 successfully enabled
state: 0 (running)

TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 0 (running)

TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU1
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU1
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU1
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU1
  Main[0]: Thread 8 created
Thread[2]: Calling pthread_barrier_wait()
Thread[1]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
Thread[6]: Done
Thread[1]: Done
Thread[3]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[7]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>

@mukku-suneel
Copy link
Copy Markdown
Contributor Author

mukku-suneel commented Nov 6, 2025

This PR depends on PR #7028

Comment thread apps/system/cputest/cputest.c Outdated
@mukku-suneel mukku-suneel marked this pull request as ready for review November 11, 2025 09:24
@mukku-suneel mukku-suneel force-pushed the cpu_on_off_driver branch 4 times, most recently from 3a55ddb to 220a207 Compare November 11, 2025 11:44
@amandeep-samsung
Copy link
Copy Markdown
Contributor

  • Integrate with existing cpu_arch_ops_s architecture operations

-need to remove it

Comment thread apps/system/cputest/cputest.c Outdated
Comment thread os/drivers/cpu/cpu_driver.c Outdated
@mukku-suneel mukku-suneel force-pushed the cpu_on_off_driver branch 2 times, most recently from 38deec1 to 771c4b9 Compare November 11, 2025 13:53
Comment thread os/drivers/cpu/Kconfig Outdated
Comment thread apps/system/cputest/cputest.c Outdated
@mukku-suneel mukku-suneel changed the title os/drivers/cpu, apps/system: Add CPU driver interface and test application for CPU management os/drivers/cpu, apps/system: Add CPU driver interface and test app Nov 11, 2025
@amandeep-samsung
Copy link
Copy Markdown
Contributor

LGTM

Comment thread apps/system/cputest/Kconfig Outdated
Comment thread apps/system/cputest/cputest.c Outdated
Comment thread apps/system/cputest/cputest.c Outdated
Comment thread apps/system/cputest/cputest.c Outdated
Comment thread build/configs/rtl8730e/flat_dev_ddr/defconfig Outdated
Comment thread os/drivers/cpu/cpu_driver.c Outdated
Comment thread apps/system/cputest/cputest.c Outdated
Comment thread os/kernel/init/os_bringup.c
@mukku-suneel mukku-suneel force-pushed the cpu_on_off_driver branch 2 times, most recently from 66f8606 to 3785ca7 Compare November 17, 2025 09:24
Comment thread apps/system/cpucontrol/cpucontrol.c Outdated
Comment thread apps/system/cpucontrol/cpucontrol.c
Comment thread os/drivers/cpu/cpu_driver.c
@seokhun-eom24
Copy link
Copy Markdown
Contributor

Hello @mukku-suneel
#7059
This PR is mered. Can you rebase to master, test again and update result into commit body and PR body.

@mukku-suneel
Copy link
Copy Markdown
Contributor Author

mukku-suneel commented Dec 29, 2025

Hello @mukku-suneel #7059 This PR is mered. Can you rebase to master, test again and update result into commit body and PR body.

Hello @seokhun-eom24
I have updated the test results into the commit body and PR body.

Comment thread os/drivers/cpu/cpu_driver.c Outdated
Comment thread os/drivers/cpu/cpu_driver.c Outdated
Comment thread apps/system/cpucontrol/cpucontrol.c Outdated
@mukku-suneel mukku-suneel force-pushed the cpu_on_off_driver branch 2 times, most recently from d01ca81 to 990f28f Compare February 2, 2026 14:17
Comment thread os/drivers/Makefile Outdated
Comment thread os/drivers/cpu/cpu_driver.c Outdated
Comment thread os/drivers/cpu/cpu_driver.c Outdated
Comment thread apps/system/init/init.c Outdated
Comment thread apps/system/cpucontrol/cpucontrol.c Outdated
Comment thread apps/system/cpucontrol/cpucontrol.c Outdated
@mukku-suneel mukku-suneel force-pushed the cpu_on_off_driver branch 3 times, most recently from 92836c0 to da56183 Compare February 11, 2026 14:25
@seokhun-eom24
Copy link
Copy Markdown
Contributor

Is there any reason for turn config on only flat_dev_ddr and loadable_ext_ddr?
How about turn on for every SMP enabled defconfig?

@mukku-suneel
Copy link
Copy Markdown
Contributor Author

Is there any reason for turn config on only flat_dev_ddr and loadable_ext_ddr? How about turn on for every SMP enabled defconfig?

Enabled the configs in every SMP enabled defconfig.

Comment on lines 82 to 83
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add sched_migrate_tasks(cpu); before sched_cpuoff?

Hello @vivek1-j @rish-sg
firstly, to verificate cpu on/off, I suggest to add sched_migrate_tasks here.
Could you please share your opinion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sched_migrate_task API has preconditions.

  1. Call must be made from context which blocks preemption.
  2. Before making this call, corresponding bit in g_active_cpus_mask must be cleared.

For testing purposes only, we can do it here.

@rish-sg Do you have anything to add?

Copy link
Copy Markdown
Contributor Author

@mukku-suneel mukku-suneel Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add sched_migrate_tasks(cpu); before sched_cpuoff?

Added.
But after adding sched_migrate_tasks(cpu); before sched_cpuoff,
we can't disable cpu1 since corresponding bit in g_active_cpus_mask not cleared.

Log:

TASH>>
TASH>>cpuctrl off 1
TASH>>powering down cpu1!
cpu_ioctl: ERROR: Failed to migrate tasks from CPU1: -22
Failed to disable CPU1: error 22

TASH>>

Add character driver for Secondary CPUs management operations through /dev/cpuX device nodes.
Provides ioctl interface for CPU enable/disable and state query operations.

This driver enables userspace applications and test utilities to control CPU
states and perform cpu on/off operations through standard interface.
…esting

Add cputest application with shell commands for testing CPU driver functionality.
Provides commands to enable/disable secondary CPUs and check CPU status through device interface.

Shell commands added:
- cpuctrl on <cpu_id>: Power on specified CPU
- cpuctrl off <cpu_id>: Power off specified CPU
- cpuctrl status: Show status of all Secondary CPUs
- cpuctrl help  : Show the help message

Test Results:

TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 0 (running)

TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU1
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU1
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU1
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU1
  Main[0]: Thread 8 created
Thread[2]: Calling pthread_barrier_wait()
Thread[1]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
Thread[6]: Done
Thread[1]: Done
Thread[3]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[7]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>
TASH>>cpuctrl off 1
TASH>>powering down cpu1!
cpu1 successfully disabled
state: 1 (offline)

TASH>>
TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 1 (offline)

TASH>>
TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU0
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU0
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU0
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU0
  Main[0]: Thread 8 created
Thread[1]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[2]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[1]: Done
Thread[3]: Done
Thread[7]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[6]: Done
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>cpuctrl on 1
TASH>>powering up cpu1!
cpu1 successfully enabled
state: 0 (running)

TASH>>
TASH>>
TASH>>cpuctrl status
TASH>>cpu state for cpu1: 0 (running)

TASH>>
TASH>>
TASH>>
TASH>>smp
TASH>>  Main[0]: Running on CPU0
  Main[0]: Initializing barrier
Running SMP test with AMP configuration
Thread[1]: Started
Thread[1]: Running on CPU0
  Main[0]: Thread 1 created
Thread[2]: Started
Thread[2]: Running on CPU1
  Main[0]: Thread 2 created
Thread[3]: Started
Thread[3]: Running on CPU0
  Main[0]: Thread 3 created
Thread[4]: Started
Thread[4]: Running on CPU1
  Main[0]: Thread 4 created
Thread[5]: Started
Thread[5]: Running on CPU0
  Main[0]: Thread 5 created
Thread[6]: Started
Thread[6]: Running on CPU1
  Main[0]: Thread 6 created
Thread[7]: Started
Thread[7]: Running on CPU0
  Main[0]: Thread 7 created
Thread[8]: Started
Thread[8]: Running on CPU1
  Main[0]: Thread 8 created
Thread[2]: Calling pthread_barrier_wait()
Thread[1]: Calling pthread_barrier_wait()
Thread[4]: Calling pthread_barrier_wait()
Thread[3]: Calling pthread_barrier_wait()
Thread[5]: Calling pthread_barrier_wait()
Thread[6]: Calling pthread_barrier_wait()
Thread[7]: Calling pthread_barrier_wait()
Thread[8]: Calling pthread_barrier_wait()
Thread[8]: Back with ret=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
Thread[1]: Back with ret=0 (I am not special)
Thread[3]: Back with ret=0 (I am not special)
Thread[5]: Back with ret=0 (I am not special)
Thread[7]: Back with ret=0 (I am not special)
Thread[2]: Back with ret=0 (I am not special)
Thread[4]: Back with ret=0 (I am not special)
Thread[6]: Back with ret=0 (I am not special)
Thread[8]: Done
Thread[2]: Done
Thread[4]: Done
Thread[6]: Done
Thread[1]: Done
Thread[3]: Done
Thread[5]: Done
  Main[0]: Thread 1 completed with result=0
Thread[7]: Done
  Main[0]: Thread 2 completed with result=0
  Main[0]: Thread 3 completed with result=0
  Main[0]: Thread 4 completed with result=0
  Main[0]: Thread 5 completed with result=0
  Main[0]: Thread 6 completed with result=0
  Main[0]: Thread 7 completed with result=0
  Main[0]: Thread 8 completed with result=0

TASH>>
TASH>>
TASH>>
TASH>>
…ration for rtl8730e

Add CONFIG_CPU_DRIVER=y and CONFIG_SYSTEM_CPUCONTROL=y to rtl8730e board configurations to enable
CPU driver support and CPU control app for CPU management operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants