public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Felix Moessbauer <felix.moessbauer@siemens.com>,
	linux-kernel@vger.kernel.org
Cc: Frederic Weisbecker <frederic@kernel.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	jan.kiszka@siemens.com,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	qyousef@layalina.io,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: Re: [PATCH v3 1/1] hrtimer: use and report correct timerslack values for realtime tasks
Date: Tue, 13 Aug 2024 11:45:19 +0200	[thread overview]
Message-ID: <87ed6src28.ffs@tglx> (raw)
In-Reply-To: <20240813072953.209119-2-felix.moessbauer@siemens.com>

On Tue, Aug 13 2024 at 09:29, Felix Moessbauer wrote:
> @@ -2569,10 +2569,11 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
>  	}
>  
>  	task_lock(p);
> -	if (slack_ns == 0)
> -		p->timer_slack_ns = p->default_timer_slack_ns;
> -	else
> -		p->timer_slack_ns = slack_ns;
> +	if (task_is_realtime(p))
> +		slack_ns = 0;

This should respect the user supplied value, i.e.

    if (!task_is_realtime(p) && !slack_ns)
	    slack_ns = p->default_timer_slack_ns;

> +	else if (slack_ns == 0)
> +		slack_ns = p->default_timer_slack_ns;
> +	p->timer_slack_ns = slack_ns;
>  	task_unlock(p);
>  
>  out:
> diff --git a/fs/select.c b/fs/select.c
> index 9515c3fa1a03..153124ed50fd 100644
> --- a/fs/select.c
> +++ b/fs/select.c
> @@ -77,19 +77,13 @@ u64 select_estimate_accuracy(struct timespec64 *tv)
>  {
>  	u64 ret;
>  	struct timespec64 now;
> -
> -	/*
> -	 * Realtime tasks get a slack of 0 for obvious reasons.
> -	 */
> -
> -	if (rt_task(current))
> -		return 0;
> +	u64 slack = current->timer_slack_ns;
>  
>  	ktime_get_ts64(&now);
>  	now = timespec64_sub(*tv, now);
>  	ret = __estimate_accuracy(&now);
> -	if (ret < current->timer_slack_ns)
> -		return current->timer_slack_ns;
> +	if (ret < slack || slack == 0)
> +		return slack;

Seriously? Do all the calculations first and then discard them when
slack is 0?

> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index ae1b42775ef9..195d2f2834a9 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
> @@ -406,6 +406,14 @@ static void __setscheduler_params(struct task_struct *p,
>  	else if (fair_policy(policy))
>  		p->static_prio = NICE_TO_PRIO(attr->sched_nice);
>  
> +	/* rt-policy tasks do not have a timerslack */
> +	if (task_is_realtime(p)) {
> +		p->timer_slack_ns = 0;
> +	} else if (p->timer_slack_ns == 0) {
> +		/* when switching back to non-rt policy, restore timerslack */
> +		p->timer_slack_ns = p->default_timer_slack_ns;
> +	}
> +
>  	/*
>  	 * __sched_setscheduler() ensures attr->sched_priority == 0 when
>  	 * !rt_policy. Always setting this ensures that things like
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 3a2df1bd9f64..e3c4cffb520c 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2557,6 +2557,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
>  			error = current->timer_slack_ns;
>  		break;
>  	case PR_SET_TIMERSLACK:
> +		if (task_is_realtime(current))
> +			break;

Why are you declaring that a RT task has to have 0 slack if we are
lifting the hard coded slack zeroing in the hrtimer functions?

Thanks,

        tglx

  reply	other threads:[~2024-08-13  9:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13  7:29 [PATCH v3 0/1] hrtimer: More fixes for handling of timer slack of rt tasks Felix Moessbauer
2024-08-13  7:29 ` [PATCH v3 1/1] hrtimer: use and report correct timerslack values for realtime tasks Felix Moessbauer
2024-08-13  9:45   ` Thomas Gleixner [this message]
2024-08-13 10:23     ` MOESSBAUER, Felix
2024-08-14 10:42       ` Thomas Gleixner

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=87ed6src28.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=felix.moessbauer@siemens.com \
    --cc=frederic@kernel.org \
    --cc=jan.kiszka@siemens.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qyousef@layalina.io \
    /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