Skip to content
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

Add support for starting cores with PSCI #169

Merged
merged 8 commits into from
Feb 9, 2024
Merged

Conversation

PandaZ3D
Copy link
Contributor

@PandaZ3D PandaZ3D commented Feb 5, 2024

In this PR we add basic support for SMP to the ARM version of the kernel. It uses PSCI to boot up cores. PSCI is the power management interface commonly supported by ARM devices. The kernel gets to the same place as before (running the startup terminal from init). There are still other stuff missing and issues related to synchronization (e.g. locks) which we plan to address in future PR's.

Two bugs surfaced while implementing this which required changes to the generic kernel code. One is that when creating the idle thread, before setting the current thread, the kernel tries to acquire a lock to allocate some memory. The issues is that all cores race to acquire the mutex which calls scheduler to run other work if they need to wait which then crashes since no current thread is defined. So we have the mutex avoid calling the scheduler if no current thread is defined. The second problem was that init_secondary was called in main (from the boot core) which caused issues with ARM initialization code. I tried to remove it, but it seemed to cause the x86_64 code to not boot. The workaround for now was to conditionally compile that in for x86_64 code.

Summary

  • Add PSCI support to turn on cores
  • Make cores spin and wait
  • Make the Mutex only call the scheduler if there is a current thread
  • Only call init_secondary for x86_64 in main

@PandaZ3D PandaZ3D added bug Something isn't working enhancement New feature or request kernel Internal kernel issues labels Feb 5, 2024
@PandaZ3D PandaZ3D self-assigned this Feb 5, 2024
@PandaZ3D PandaZ3D changed the title Add support for staring cores with PSCI Add support for starting cores with PSCI Feb 5, 2024
@PandaZ3D PandaZ3D marked this pull request as draft February 5, 2024 20:01
@PandaZ3D PandaZ3D marked this pull request as ready for review February 7, 2024 18:26
Copy link
Contributor

@gvnn3 gvnn3 left a comment

Choose a reason for hiding this comment

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

Happy to approve but please look at the one thing I asked about.

}

pub fn halt_and_wait() {
/* TODO: spin a bit */
/* TODO: actually put the cpu into deeper and deeper sleep */
todo!()
/* TODO: actually put the cpu into deeper and deeper sleep, see PSCI */
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the todo!() was removed is this still a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. wfe puts the core in some low power state (standby), but PSCI gives more control to put the core in different power level states (e.g., retention).

@PandaZ3D PandaZ3D merged commit 4ec5a30 into main Feb 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request kernel Internal kernel issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants