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

CP-52821: use Mtime in Xapi_periodic_scheduler #6161

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

edwintorok
Copy link
Contributor

Target: feature/perf

Note that this conflicts with 7e9310f?diff=unified&w=1, but is a pre-requisite of #6126

@robhoes
Copy link
Member

robhoes commented Dec 5, 2024

Isn't it better to rebase on master already and build on top of the scheduler changes there? Those rebase changes would have to be done later anyway, but then end up in a complicated and hard to review merge commit.

@psafont
Copy link
Member

psafont commented Dec 5, 2024

There's a further improvement here: replace all Mtime_clock.now () with Mtime_clock.elapsed() to remove the overflow treatment because the latter returns a span instead of a timestamp

@edwintorok
Copy link
Contributor Author

edwintorok commented Dec 6, 2024

Isn't it better to rebase on master already and build on top of the scheduler changes there? Those rebase changes would have to be done later anyway, but then end up in a complicated and hard to review merge commit.

I'll rebase this PR on top of master once Frediano's PR is merged.

@freddy77
Copy link
Collaborator

freddy77 commented Dec 6, 2024

There's a further improvement here: replace all Mtime_clock.now () with Mtime_clock.elapsed() to remove the overflow treatment because the latter returns a span instead of a timestamp

It's not clear what overflows you are talking about. Internally the timer is a counter since boot, that will overflow the int64 (although the numbers should be unsigned) in about 290 years. I personally find the code with Mtime_clock.elapsed() less readable having to deal with differences of differences (this span is less or more than this other span) instead of just comparing time (the deadline cross current time).

PS: @psafont are you referring to floating point? Maybe it would be sensible to consider a too big timeout (like 10 years) as an error?

@psafont
Copy link
Member

psafont commented Dec 6, 2024

It's not clear what overflows you are talking about.

One function returns an option in case of overflow, the other does not. Because, as you point out, the overflow won't happen in practise, I prefer to use the latter rather than the former.

I personally find the code with Mtime_clock.elapsed() less readable having to deal with differences of differences

I fundamentally disagree, timestamps are actually differences as well (between an epoch and a point in time), and the only practical difference is replacing is_{earlier,later} with is_{shorter,longer}. I'm fine with the improvement not being in this PR, it was only an observation

@edwintorok edwintorok marked this pull request as draft December 9, 2024 11:04
@edwintorok
Copy link
Contributor Author

Moved this to draft until the referenced PR is merged to master as this will need a rebase. #6155

@edwintorok edwintorok marked this pull request as ready for review December 10, 2024 17:30
@edwintorok
Copy link
Contributor Author

Rebased on latest feature/perf (which in turn has been updated to include latest master).
Target is still feature/perf because there are more changes coming, and this needs a bit wider testing.

E.g. previously there was a +0.5 in the periodic scheduler, but now we just use Clock.Timer.remaining, so there could be some subtle differences in behaviour.

@edwintorok
Copy link
Contributor Author

Rebased on latest feature/perf which incorporated the latest changes to the scheduler from master.

@freddy77
Copy link
Collaborator

"Minor" hidden change. Due to internal implementation moving from Mtime_clock.now to Mtime_clock.elapsed on Linux move the timer from CLOCK_MONOTONIC to CLOCK_BOOTTIME. They are both monotonic but the second takes into account when the machine is suspended. But in our case machine should not be suspended so it should be the same.

@edwintorok
Copy link
Contributor Author

move the timer from CLOCK_MONOTONIC to CLOCK_BOOTTIME

For something like 'run this task every 24h' that actually seems like the correct behaviour (even if the machine was asleep we'd want it to run the task if it wakes up sooner than that), so the periodic tasks should probably use BOOTTIME (i.e. Mtime_clock.elapsed), and oneshot tasks monotonic (i.e. Mtime_clock.now).

But as you said we don't actually suspend Dom0, so we don't need to complicate the scheduler to make that distinction.

@edwintorok edwintorok merged commit 83f4517 into xapi-project:feature/perf Dec 12, 2024
15 checks passed
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.

5 participants