Feature request: worker threads in a Protection Domain
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Start by locating the SDF parsing and system initializer paths, then trace how the main PD thread is created and started after init. A complete implementation would define the worker-thread representation and startup semantics, shared CSpace/VSpace and scheduling setup, CPU affinity and entry points, and worker identification in fault reporting, with tests for the agreed interface.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I have a use case where a Protection Domain performs CPU-intensive data processing and needs to execute work in parallel on multiple CPU cores.
At the moment, the natural way to use multiple cores in Microkit is to split the application into multiple PDs. This works well when the components are logically separate, but is awkward when they are really execution contexts of the same application.
In my case, the processing application contains a scheduler and a fairly large object graph allocated on the heap. Processing objects have internal state and are connected through ordinary pointers. Splitting the workers into separate PDs would require moving most or all of the heap into explicitly shared memory and using a shared-memory-aware allocation scheme, even though there is no desired isolation boundary between the workers.
The seL4 model already naturally supports multiple TCBs sharing the same VSpace and CSpace, which seems like a much better fit for this use case.
I would therefore like to propose optional additional worker threads within a Microkit Protection Domain.
Possible SDF interface
For example:
<protection_domain name="audio_processor" cpu="0" priority="200" budget="1000" period="1000">
<program_image path="audio_processor.elf" />
<thread id="0" cpu="1" entry="worker_entry" stack_size="0x8000" />
<thread id="1" cpu="2" entry="worker_entry" stack_size="0x8000" />
</protection_domain>
The exact syntax is of course only a suggestion.
Proposed semantics
The existing PD thread would remain the main thread and retain the current Microkit programming model:
- it runs the normal program/runtime initialisation;
- it executes
init; - it owns the Microkit event loop;
- only this thread executes
notified,protected, andfault.
Additional threads would be worker threads rather than additional Microkit event loops.
Each worker would have:
- its own TCB;
- its own Scheduling Context;
- its own stack;
- its own CPU affinity;
- the same VSpace as the main PD thread;
- the same CSpace as the main PD thread.
This means normal pointers, heap allocations, vtables/trait objects, shared static data, and capabilities can be used directly by all threads without constructing a separate shared-memory object model.
Scheduling parameters such as priority, budget and period could initially be inherited from the parent PD, with only cpu being specified per thread. Per-thread overrides could potentially be added later if useful.
Thread initialisation and startup
Worker threads must not enter the normal program startup path independently.
In particular, global/runtime initialisation and the PD's init function must only execute once on the main thread.
Worker TCBs could therefore be created by the system initializer in a suspended state. Their initial PC would point either to their configured entry point or to a small Microkit thread trampoline.
They should only become runnable after the main PD has completed its initialisation.
There are at least two possible APIs for this:
- automatically resume all worker threads after
initreturns; or - provide the PD with a small API such as:
microkit_thread_start(thread_id);
so that the application can explicitly start workers near the end of its initialisation.
I personally prefer explicit startup, as it also permits applications to initialise shared scheduler state before workers become runnable.
A worker entry point could look conceptually like:
void worker_entry(microkit_thread_id id);
and should probably be required not to return.
IPC buffers and initial scope
I do not think full IPC support is necessary for an initial implementation.
A useful first version could support worker threads intended primarily for computation and shared-memory synchronisation.
For example, workers could use Notifications to sleep while no work is available and to signal other components after producing output.
Therefore an initial implementation could potentially create worker TCBs without IPC buffers.
Full per-thread IPC could be added later by allocating a separate IPC buffer for each thread and providing appropriate TLS/runtime support.
This would keep the first implementation considerably simpler.
Synchronisation use case
A typical worker loop in my application is conceptually:
loop:
take executable work from shared scheduler
execute available work
if no work remains:
wait for a notification
seL4 Notifications are particularly suitable for this because a notification that arrives before the worker waits remains pending, avoiding the usual lost-wakeup race between checking the work queue and going to sleep.
The notification is only a wake-up hint; the shared scheduler/work queue remains the source of truth, so notification coalescing is not a problem.
Why not model the workers as separate PDs?
Separate PDs introduce an isolation boundary that is not desired for this use case.
To make several worker PDs operate on the same state, an application has to explicitly place essentially its entire mutable object graph/heap into shared memory.
For pointer-heavy or stateful processing applications this is significantly more intrusive than simply having several execution contexts within one address space.
Another possible workaround would be to create dummy PDs and later reconfigure their TCBs to use the CSpace and VSpace of a "master" PD. Apart from being a hack, this requires exposing capabilities that allow runtime CSpace/VSpace reconfiguration and no longer accurately reflects the static system structure described by the SDF. Recently, cap_cspace was removed from capability sharing for this reason.
Representing the threads explicitly in the system description avoids that problem; the authority graph remains static and all threads are explicitly part of the same protection domain.
Fault handling
It would also be useful for worker faults to identify the worker/thread ID.
For example, debug fault reporting could distinguish:
audio_processor (main)
audio_processor.thread[0]
audio_processor.thread[1]
even though all of them belong to the same PD.
Initial feature scope
A minimal version that would already cover my use case could therefore be:
- multiple TCBs belonging to one PD;
- shared CSpace and VSpace;
- separate stacks and Scheduling Contexts;
- per-thread CPU affinity;
- configurable entry point;
- workers initially suspended;
- explicit or automatic start after PD initialisation;
- no additional Microkit event loops;
- no
notified/protecteddispatch on workers; - no worker IPC buffers initially;
- Notification-based wakeup/signalling;
- worker ID available to the entry point and fault reporting.
More complete thread runtime support, TLS, per-thread IPC buffers, and more sophisticated scheduling parameters could be added separately.
Would this fit the intended Microkit model for the "multithreaded applications" case, or is there another preferred way to represent this?
- Ngôn ngữ chính
- Rust
- Star
- 224
- Fork
- 90
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của seL4/microkit
-
Manual contradicts the tool on three x86 `irq` attributes (confirmed on Microkit 2.3.0)Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
-
Update roadmap on seL4 wbsiteCó thể làm lại được @midnightveil đã nhận 69 ngày trước và không có pull request nào đang mở. Đang mở
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Tất cả issue của seL4/microkit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aaif-goose/goose#13970 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ClickHouse/ClickHouse#136277 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Copperpour/Copperpour#1105 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug release-blocker
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày