From: "MOESSBAUER, Felix" <felix.moessbauer@siemens.com>
To: "tglx@linutronix.de" <tglx@linutronix.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "qyousef@layalina.io" <qyousef@layalina.io>,
"frederic@kernel.org" <frederic@kernel.org>,
"Kiszka, Jan" <jan.kiszka@siemens.com>,
"bigeasy@linutronix.de" <bigeasy@linutronix.de>,
"anna-maria@linutronix.de" <anna-maria@linutronix.de>
Subject: Re: [PATCH v3 1/1] hrtimer: use and report correct timerslack values for realtime tasks
Date: Tue, 13 Aug 2024 10:23:02 +0000 [thread overview]
Message-ID: <76cd1f3e07c6c12a7dceac31cdf7a3ca8d1e8265.camel@siemens.com> (raw)
In-Reply-To: <87ed6src28.ffs@tglx>
On Tue, 2024-08-13 at 11:45 +0200, Thomas Gleixner wrote:
> 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.
Ok, but then we need to update the man page as well (see below).
>
> 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?
Ok, I'll short circuit.
>
> > 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?
This is what the manpage states [1]:
+ Timer slack is not applied to threads that are scheduled under a
+ real-time scheduling policy (see sched_setscheduler(2)).
[1] https://man7.org/linux/man-pages/man2/PR_SET_TIMERSLACK.2const.html
Best regards,
Felix
>
> Thanks,
>
> tglx
--
Siemens AG, Technology
Linux Expert Center
next prev parent reply other threads:[~2024-08-13 10:23 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
2024-08-13 10:23 ` MOESSBAUER, Felix [this message]
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=76cd1f3e07c6c12a7dceac31cdf7a3ca8d1e8265.camel@siemens.com \
--to=felix.moessbauer@siemens.com \
--cc=anna-maria@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=frederic@kernel.org \
--cc=jan.kiszka@siemens.com \
--cc=linux-kernel@vger.kernel.org \
--cc=qyousef@layalina.io \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®