Skip to content

capdl-loader-app: spec for domain schedule in us#95

Open
midnightveil wants to merge 1 commit into
masterfrom
julia/microsecond-domsched
Open

capdl-loader-app: spec for domain schedule in us#95
midnightveil wants to merge 1 commit into
masterfrom
julia/microsecond-domsched

Conversation

@midnightveil

@midnightveil midnightveil commented Jul 7, 2026

Copy link
Copy Markdown

This is partially an experiment, but to make this useful for userspace programs, it makes sense for the capDL specification to treat the domain schedule values as microseconds, instead of timer ticks.

In the work on RFC-20 it was proposed that it would make sense to remove this (micro)seconds-to-ticks conversions from seL4 and migrate all of userspace APIs to be in ticks, to make dealing with these calculations and their trickiness to instead be done at user-level.

This PR demonstrates that it should be possible to do this for at least the capDL initialiser. For other cases supported by the capDL specification, such as (MCS) budgets and periods currently specified in microseconds, the capDL initialiser should be able to paper over the change in kernel APIs without the users needing to deal with this distinction.

These changes are motivated by the Domain schedules PR to the seL4 Microkit, which creates a capDL specification for the (Rust version) of the capDL initialiser to use. At the moment, this PR is unable to be consistent about the values exposed to the user for the units of the domain schedule: whilst we can statically determine the us->ticks conversion for ARM/RISC-V platforms, on x86 this is a runtime-known value only. Since the spec is packed at system-build-time, we cannot therefore specify x86 domain schedules in a consistent set of units.

(Note, I haven't actually tested that this works, but I have tested a similar change to rust-seL4 capDL initialiser. This PR is mostly for discussion; this could likely also move to a formal RFC).

This is partially an experiment, but to make this useful for
userspace programs, it makes sense for the capDL specification
to treat the domain schedule values as *microseconds*, instead
of timer ticks.

In the work on [RFC-20] it was proposed that it would make sense
to remove this (micro)seconds-to-ticks conversions from seL4
and migrate all of userspace APIs to be in ticks, to make dealing
with these calculations and their trickiness to instead be done
at user-level.

This PR demonstrates that it should be possible to do this for
at least the capDL initialiser. For other cases supported by
the capDL specification, such as (MCS) budgets and periods currently
specified in microseconds, the capDL initialiser should be able to
paper over the change in kernel APIs without the users needing to
deal with this distinction.

These changes are motivated by the [Domain schedules] PR to the
seL4 Microkit, which creates a capDL specification for the
(Rust version) of the capDL initialiser to use. At the moment,
this PR is unable to be consistent about the values exposed
to the user for the units of the domain schedule: whilst we can
statically determine the us->ticks conversion for ARM/RISC-V
platforms, on x86 this is a runtime-known value only. Since
the spec is packed at system-build-time, we cannot therefore
specify x86 domain schedules in a consistent set of units.

[RFC-20]: seL4/rfcs#33
[Domain schedules]: seL4/microkit#445

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
@midnightveil midnightveil requested review from Indanz and lsf37 July 7, 2026 08:03
@lsf37

lsf37 commented Jul 7, 2026

Copy link
Copy Markdown
Member

Generally, this would be good addition, but we do need to retain the ability to specify the duration in ticks, so we can't just change the unit. We'll need a mechanism to specify the unit.

The whole point of making the interface be ticks is that the FIXME for AArch32 that is still in there is not nicely solvable in general (the method the kernel currently has is flawed in multiple ways). It does not necessarily need to be fully solved in general, because on the platforms where it is problematic you likely to want to compute in ticks anyway.

I.e. if we use the current (flawed) kernel method for conversion on AArch32 but also have a capDL ticks interface available, the flaws are avoidable for the systems where that matters.

@Indanz Indanz left a comment

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.

I think it makes sense to make things easier to configure for user space, which means doing it in real time instead of ticks. User space doesn't run into the problems that the kernel has as much, so the trade-off is different there.

* timer frequency to us at build time, in Hertz */
uin64_t timer_frequency = CONFIG_TIMER_FREQUENCY;

/* FIXME: On ARM32 we need to pull in a 64-bit division helper;

@Indanz Indanz Jul 7, 2026

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.

Those should be part of the compiler built-in already: There is an __aeabi_uldivmod which will be used automatically for 64-bit divisions on 32-bit Arm.

This is one of the reasons why doing this in user space is easier than in the kernel.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well, that's part of libgcc (GCC) or compiler-rt (LLVM), which may or may not be linked in the builds here; however, broadly yes.

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.

I suppose it depends on how verified you want your user space to be, that's the only reason I can think of for not linking to the compiler library in user space. But I don't see anyone putting that amount of effort into this for 32-bit platforms. (And if they do, they can always use the ticks interface if this is a problem for verification.)

Comment on lines +2116 to +2117
Note: there are some values of us which would cause unrepresentable
values in ticks; we should add a static check to error out.

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.

Yes, that's the main question: How do you deal with non-whole MHz clock frequencies. If there is no exact conversion you at least want to warn the user about this. Ideally the user should be able to specify whether a time needs to be exact or not.

seL4_BootInfoHeader *tsc_freq_hdr = extended_bootinfo_table[SEL4_BOOTINFO_HEADER_X86_TSC_FREQ];
ZF_LOGF_IF(tsc_freq == NULL,
"Unable to determine timer frequency as no TSC frequency provided in bootinfo");
/* For x86 platforms, the timer frequency is provided in MHz by the bootinfo */

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.

I wonder if anyone ever double checked that the reported frequency is correct.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well, us at TS will find out soon when our drivers start using bootinfo, but I sure hope so given the kernel itself uses this value internally.

/* For x86 platforms, the timer frequency is provided in MHz by the bootinfo */
uint32_t tsc_freq_mhz;
assert(tsc_freq_hdr->len == sizeof(seL4_BootInfoHeader) + sizeof(tsc_freq_mhz);
memcpy((void *)&tsc_freq_mhz, ((void *)tsc_freq_hdr) + sizeof(seL4_BootInfoHeader), sizeof(tsc_freq_mhz));

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.

cache_extended_bootinfo_headers assumes that the headers are aligned. If that's the case, then the value will be too, so no need for a memcpy here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No it doesn't? It stores the pointers directly; it does access hdr->len directly but that assumes that is is aligned for seL4_BootInfoHeader, not for the appropriate bootinfo. Although in this case that is probably the same.

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.

it does access hdr->len directly but that assumes that is is aligned for seL4_BootInfoHeader

Exactly. The only alignment here that matters is tsc_freq_mhz, which is uint32_t.

@midnightveil

midnightveil commented Jul 8, 2026

Copy link
Copy Markdown
Author

Generally, this would be good addition, but we do need to retain the ability to specify the duration in ticks, so we can't just change the unit. We'll need a mechanism to specify the unit.

Hrm. I don't think I know if there's any cases like this, I suppose... Might need to hand-roll something specific for units here. ACK, this is just an implementation thing mostly then.

@lsf37

lsf37 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Hrm. I don't think I know if there's any cases like this, I suppose... Might need to hand-roll something specific for units here. ACK, this is just an implementation thing mostly then.

Yes, no problem with us from the conceptual side, as long as we can also do ticks.

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.

3 participants