Re: [PATCH v0.9.1 3/6] sched/umcg: implement UMCG syscalls

From: Peter Zijlstra
Date: Fri Nov 26 2021 - 17:02:56 EST


On Fri, Nov 26, 2021 at 10:08:14PM +0100, Thomas Gleixner wrote:
> On Fri, Nov 26 2021 at 18:09, Peter Zijlstra wrote:
> > +
> > + if (timo) {
> > + hrtimer_init_sleeper_on_stack(&timeout, tsk->umcg_clock,
> > + HRTIMER_MODE_ABS);
> > + hrtimer_set_expires_range_ns(&timeout.timer, (s64)timo,
> > + tsk->timer_slack_ns);
> > + }
> > +
> > + for (;;) {
> > + set_current_state(TASK_INTERRUPTIBLE);
> > +
> > + ret = -EINTR;
> > + if (signal_pending(current))
> > + break;
> > +
> > + /*
> > + * Faults can block and scribble our wait state.
> > + */
> > + pagefault_disable();
> > + if (get_user(state, &self->state)) {
> > + pagefault_enable();
> > +
> > + ret = -EFAULT;
> > + if (page) {
> > + unpin_user_page(page);
> > + page = NULL;
> > + break;
> > + }
> > +
> > + if (pin_user_pages_fast((unsigned long)self, 1, 0, &page) != 1) {
> > + page = NULL;
> > + break;
> > + }
> > +
> > + continue;
> > + }
> > +
> > + if (page) {
> > + unpin_user_page(page);
> > + page = NULL;
> > + }
> > + pagefault_enable();
> > +
> > + state &= UMCG_TASK_MASK;
> > + if (state != UMCG_TASK_RUNNABLE) {
> > + ret = 0;
> > + if (state == UMCG_TASK_RUNNING)
> > + break;
> > +
> > + ret = -EINVAL;
> > + break;
> > + }
> > +
> > + if (timo)
> > + hrtimer_sleeper_start_expires(&timeout, HRTIMER_MODE_ABS);
> > +
> > + freezable_schedule();
>
> You can replace the whole hrtimer foo with
>
> if (!schedule_hrtimeout_range_clock(timo ? &timo : NULL,
> tsk->timer_slack_ns,
> HRTIMER_MODE_ABS,
> tsk->umcg_clock)) {
> ret = -ETIMEOUT;
> break;
> }

That seems to loose the freezable crud.. then again, since we're
interruptible, that shouldn't matter. Lemme go do that.