linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Alessio Balsini <alessio.balsini@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Joel Fernandes <joel@joelfernandes.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Tommaso Cucinotta <tommaso.cucinotta@santannapisa.it>,
	Luca Abeni <luca.abeni@santannapisa.it>,
	Claudio Scordino <claudio@evidence.eu.com>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Patrick Bellasi <patrick.bellasi@arm.com>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [RFC PATCH] sched/deadline: sched_getattr() returns absolute dl-task information
Date: Mon, 23 Jul 2018 11:49:04 +0200	[thread overview]
Message-ID: <20180723094904.GB2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180629120947.14579-1-alessio.balsini@gmail.com>

On Fri, Jun 29, 2018 at 02:09:47PM +0200, Alessio Balsini wrote:

Joel nailed it wrt the Changelog, that needs improvement.


> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index fbfc3f1d368a..f75a4169cd47 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -2568,13 +2568,41 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
>  	dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime);
>  }
>  
> -void __getparam_dl(struct task_struct *p, struct sched_attr *attr)
> +void __getparam_dl(struct task_struct *p, struct sched_attr *attr,
> +		   unsigned int flags)
>  {
>  	struct sched_dl_entity *dl_se = &p->dl;
>  
>  	attr->sched_priority = p->rt_priority;
> -	attr->sched_runtime = dl_se->dl_runtime;
> -	attr->sched_deadline = dl_se->dl_deadline;
> +
> +	if (flags & SCHED_GETATTR_FLAGS_DL_ABSOLUTE) {
> +		/*
> +		 * If the task is not running, its runtime is already
> +		 * properly accounted. Otherwise, update clocks and the
> +		 * statistics for the task.
> +		 */
> +		if (task_running(task_rq(p), p)) {
> +			struct rq_flags rf;
> +			struct rq *rq;
> +
> +			rq = task_rq_lock(p, &rf);
> +			sched_clock_tick();

This isn't required here. The reason it is used elsewhere is because
those are interrupts, but this is a system call, the clock state should
be good.

> +			update_rq_clock(rq);
> +			task_tick_dl(rq, p, 0);

Do we really want task_tick_dl() here, or update_curr_dl()? Also, who
says the task still is dl ? :-)

> +			task_rq_unlock(rq, p, &rf);
> +		}
> +
> +		/*
> +		 * If the task is throttled, this value could be negative,
> +		 * but sched_runtime is unsigned.
> +		 */
> +		attr->sched_runtime = dl_se->runtime <= 0 ? 0 : dl_se->runtime;
> +		attr->sched_deadline = dl_se->deadline;

This is all very racy..

Even if the task wasn't running when you did the task_running() test, it
could be running now. And if it was running, it might not be running
anymore by the time you've acquired the rq->lock.

On 32bit reading these numbers without locks is broken to boot. And even
on 64bit, I suppose you can a consistent snapshot of runtime and
deadline together, which isn't possible without the locks.

And of course, by the time we get back to userspace, the returned values
will be out-of-date anyway. But that isn't to be helped I suppose.


> +	} else {
> +		attr->sched_runtime = dl_se->dl_runtime;
> +		attr->sched_deadline = dl_se->dl_deadline;
> +	}
> +
>  	attr->sched_period = dl_se->dl_period;
>  	attr->sched_flags = dl_se->flags;
>  }

  parent reply	other threads:[~2018-07-23  9:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 12:09 [RFC PATCH] sched/deadline: sched_getattr() returns absolute dl-task information Alessio Balsini
2018-06-29 18:45 ` Joel Fernandes
2018-07-23  9:49 ` Peter Zijlstra [this message]
2018-07-23 12:49   ` Patrick Bellasi
2018-07-23 14:13     ` Peter Zijlstra
2018-07-23 14:31       ` Patrick Bellasi
2019-04-29 16:11 ` Alessio Balsini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180723094904.GB2494@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=alessio.balsini@gmail.com \
    --cc=bristot@redhat.com \
    --cc=claudio@evidence.eu.com \
    --cc=joel@joelfernandes.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca.abeni@santannapisa.it \
    --cc=mingo@redhat.com \
    --cc=patrick.bellasi@arm.com \
    --cc=tommaso.cucinotta@santannapisa.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).