Skip to content

Conversation

@Lfan-ke
Copy link

@Lfan-ke Lfan-ke commented Jan 11, 2026

eg. rv32im

This allows buddy_system_allocator to run on targets without native atomic support, such as RV32IM platforms without the A extension, while keeping the default behavior unchanged.
default = ["alloc", "use_spin"]
alloc = []
use_spin = ["spin"]
soft_atomic_spin_single_core = ["spin/portable-atomic", "portable-atomic/unsafe-assume-single-core"]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we really need this: By https://doc.rust-lang.org/cargo/reference/features.html#feature-unification, you can enable spin/portable-atomic in a downstream project if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

The real feature wanted here is to use spin without spin_mutex?

@Lfan-ke
Copy link
Author

Lfan-ke commented Jan 12, 2026 via email

@jiegec
Copy link
Member

jiegec commented Jan 12, 2026

spin_mutex used core::atomic by default. If you want to use 'LockedHeap', and there is no hardware support for atomic instructions, such as when the target is 'rv32im", it will become unavailable.At this point, you need to enable the portable-atomic software shim for support.The features are separated for convenience of combination, so that configuration can be easily done in the dependency section instead of leaving the configuration task to downstream tasks. However, it's not a big problem.Currently, one of my template projects is being developed based on the modified fork.

When you need to specify the additional feature for buddy_system_allocator, you can specify the portable-atomic feature for spin in the same way. I think it is more elegant: we don't want to copy all those features from spin to buddy_system_allocator.

@Lfan-ke
Copy link
Author

Lfan-ke commented Jan 12, 2026 via email

@jiegec
Copy link
Member

jiegec commented Jan 12, 2026

okay,thanks. However, if there are projects that depend on this project for development, and then new projects depend on those projects that in turn depend on this project, it can easily lead to configuration hell if we do not expose the underlying features of spin to allow complete configuration at a certain layer, but instead push all configuration tasks to the top-level project. If users then discover that dependency package A relies on feature1 of the underlying package BASE1, while dependency B relies on another version or a different feature of the underlying package BASE1, the only available strategy would be to fork the original project and write an additional wrapper layer. By exposing these features, such situations can be better avoided at a certain abstraction layer. If all configuration is pushed to the top level, then the initial Cargo.toml of a large project will be anything but elegant.

Please give a concrete example where your approach is cleaner that the existing one.

@Lfan-ke
Copy link
Author

Lfan-ke commented Jan 12, 2026 via email

@jiegec
Copy link
Member

jiegec commented Jan 12, 2026

Since my goal is a simple RV32IM board, I need to use an allocator to initialize the heap. However, I don’t want to develop it myself (QwQ—never mind for now). Subsequent projects based on this board will have a simple template (see: github cargo-ecos/template/c1), and later there will also be UI adaptation layers, etc. If every template contains a patch during initialization, it will be... inelegant, and the project will no longer be transparent to users.

You can specify the portable-atomic feature in the board support crate.

@Lfan-ke
Copy link
Author

Lfan-ke commented Jan 12, 2026 via email

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.

2 participants