<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Norman,<div>Thanks for the response. I have replied inline below whilst quoting the relevant parts. Let me know if this list has some other preferred way of organizing longer email exchanges.</div><div><br></div><div><div>Thanks,<br></div><div>Sid</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 10, 2022 at 6:14 AM Norman Feske <<a href="mailto:norman.feske@genode-labs.com" target="_blank">norman.feske@genode-labs.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Both constraints can be satisfied by managing the region allocation<br>
within a dedicated stack-region map manually.</blockquote><div>Thanks. This makes sense. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> 2. A PD is defined as Address Space and CSpace. I wondered if it is<br>
> possible to have multiple address spaces inside a PD. The RM for each of<br>
> these different Address spaces would still be separate capabilities in the<br>
> singular CSpace for that PD. This way, a thread can potentially jump across<br>
> different address spaces like [1, 2]. Or multiple threads can have slightly<br>
> different address spaces.<br>
<br>
Early versions of Genode indeed decoupled address spaces from PDs.<br>
However, as we never found reasonable use cases of this presumed<br>
flexibility, we abandoned this artificial separation of mechanisms. As a<br>
result, the implementation became less complex and thereby more robust.<br>
<br>
[1]<br>
<a href="https://genode.org/documentation/release-notes/16.05#Consolidation_of_core_s_SIGNAL__CAP__RM__and_PD_services" rel="noreferrer" target="_blank">https://genode.org/documentation/release-notes/16.05#Consolidation_of_core_s_SIGNAL__CAP__RM__and_PD_services</a><br>
<br>
BTW, it is still possible to share a portion of the virtual address<br>
space between multiple PDs by using core's RM service. E.g., the<br>
cached_fs_rom component uses this mechanism to make files available as<br>
read-only dataspaces shared by multiple clients.<br>
<br></blockquote><div>Thanks, I will look at fs_rom. </div><div>I want to share a portion of the virtual address space between multiple threads in the same PD (and not different PD),</div><div>this was both the threads have access to the same Cspace.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Regarding the idea of a thread "jumping across address spaces", that is<br>
really what's happening when issuing an RPC. Genode's RPC mechanism<br>
mimics plain synchronous function calls.<br></blockquote><div>In the case of issuing an RPC, the Cspace is also changing, right? Since we making the RPC call </div><div>from 1 PD to another.  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> 3. Where am I going with this? I am trying to implement a new type of<br>
> thread. In this thread(let's call it thread-stack), each thread's stack<br>
> will be completely isolated from the other threads. That is, threads will<br>
> not have access to each other's stacks. They will still share the<br>
> code-section, library, and heap sections. This is a toy idea, so I can get<br>
> my hand dirty with the Genode basics. I think everything I need to<br>
> implement is already there in Genode but wanted to get your opinion.<br>
<br>
Genode's mechanisms allow you to build that scenario. Just a rough sketch:<br>
<br>
A custom parent component (runtime) would create a new PD for each<br>
"thread". But instead of loading the real program into the PD, it would<br>
load a simple bootstrapping program. Once executed, this bootstrapping<br>
program would request ROM and RAM dataspaces containing the text and<br>
data segments of the designated program from the parent. The parent is<br>
free to hand out the same dataspaces for each child.<br>
<br>
What I just described is actually very similar to the regular function<br>
of our dynamic linker.<br></blockquote><div>Thanks. I will take a look at that. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> 4. Are they any helper functions to clone an entire address space?<br>
> Replicate the page table hierarchy with the same underlying page frames.<br>
<br>
Not an entire address space. But a region map can be used as a<br>
dataspace. On kernels other than Linux, this - so called managed<br>
dataspace" - can be shared between PDs. It can also be used to implement<br>
on-demand page-fault handling. Think of automatically growing threads or<br>
page swapping. You can find an example at [2] However, in practice the<br>
mechanism is not used much.<br>
<br>
[2]<br>
<a href="https://github.com/genodelabs/genode/blob/master/repos/base/src/test/rm_nested/main.cc" rel="noreferrer" target="_blank">https://github.com/genodelabs/genode/blob/master/repos/base/src/test/rm_nested/main.cc</a></blockquote><div>thanks.  I will take a look at that. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> 1. Using the notion of Affinity, I can restrict a thread to run on a<br>
> particular CPU, but is there a way to restrict other threads from running<br>
> on a given CPU. I am exploring isolating two threads by ensuring that they<br>
> run on separate cores.<br>
<br>
It's best to think in terms of PDs when partitioning resources. At the<br>
granularity of PDs, you can express the assignment of two PDs to a<br>
mutually exclusive set of CPU cores using init's configuration: defining<br>
an affinity space of 2x1, assigning the "left" part to one PD, and the<br>
"right" part to the other. Note however, that the boot CPU is<br>
effectively shared with other components and the execution of core's<br>
services. So to minimize the chance for cross talk, one would need to<br>
use a CPU with more than two cores (one for the boot CPU and one for<br>
each resource partition).<br>
<br>
BTW, you can readily experiment with the mechanism using the<br>
Genode-based Sculpt OS as described at [3].<br>
<br>
[3] <a href="http://genodians.org/nfeske/2021-03-24-sculpt-os" rel="noreferrer" target="_blank">http://genodians.org/nfeske/2021-03-24-sculpt-os</a><br>
<br>
> 2. Is there a way to restrict the time slices given to a particular thread.<br>
> I am thinking of something like cgroups. I see that seL4 has the MCS<br>
> kernel, which shares some of the motivations. But I think Genode does not<br>
> support the MCS sel4 kernel.<br>
<br>
We haven't used seL4's MCS kernel, yet.<br>
<br>
That said, our custom base-hw microkernel supports a similar scheduling<br>
feature since version 14.11 [4].<br></blockquote><div>If a component has the capability for every thread in the system it can implement any arbitrary scheduling policy using suspend/resume on the seL4 TCB.</div><div>I think, my initial statement about not being able to do scheduling in userspace in seL4 might have been premature.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
[4]<br>
<a href="https://genode.org/documentation/release-notes/14.11#Trading_CPU_time_between_components_using_the_HW_kernel" rel="noreferrer" target="_blank">https://genode.org/documentation/release-notes/14.11#Trading_CPU_time_between_components_using_the_HW_kernel</a><br>
<br>
> 1. Is the CSpace for a PD the same as CSpace in seL4, or is there a<br>
> different notion of Cspace in Genode?<br>
<br>
It is the same notion. It is only used in the seL4-specific part of<br>
Genode (in base-sel4/).<br>
<br>
> 2. Is there an easy way to print the entire CSpace for debugging purposes?<br>
<br>
Unfortunately not. However, while working with the code, you may chose<br>
to make any class you like printable (a valid argument to 'log',<br>
'warning', 'error') by implementing a const 'print' method in the class.<br>
You can find simple examples at [5].<br>
<br>
[5]<br>
<a href="https://github.com/genodelabs/genode/blob/master/repos/os/include/util/geometry.h" rel="noreferrer" target="_blank">https://github.com/genodelabs/genode/blob/master/repos/os/include/util/geometry.h</a><br>
<br>
Have fun with the further exploration!<br>
<br>
Norman<br>
<br>
<br>
-- <br>
Dr.-Ing. Norman Feske<br>
Genode Labs<br>
<br>
<a href="https://www.genode-labs.com" rel="noreferrer" target="_blank">https://www.genode-labs.com</a> · <a href="https://genode.org" rel="noreferrer" target="_blank">https://genode.org</a><br>
<br>
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden<br>
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth<br>
<br>
_______________________________________________<br>
Genode users mailing list<br>
<a href="mailto:users@lists.genode.org" target="_blank">users@lists.genode.org</a><br>
<a href="https://lists.genode.org/listinfo/users" rel="noreferrer" target="_blank">https://lists.genode.org/listinfo/users</a><br>
</blockquote></div>
</div></div></div>