mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Cc: yan.li.cn@windriver.com
Subject: Re: [musl] [PATCH] add check for pthread_attr_setschedparam().
Date: Tue, 24 Dec 2024 15:00:42 +0100	[thread overview]
Message-ID: <Z2q-ioXcBB-i32_X@voyager> (raw)
In-Reply-To: <20241224094104.GD10433@brightrain.aerifal.cx>

Am Tue, Dec 24, 2024 at 04:41:04AM -0500 schrieb Rich Felker:
> On Tue, Dec 24, 2024 at 10:03:01AM +0800, yan.li.cn@windriver.com wrote:
> >  int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
> >  {
> > -	a->_a_prio = param->sched_priority;
> > -	return 0;
> > +    int min = sched_get_priority_min (a->_a_policy);
> > +    int max = sched_get_priority_max (a->_a_policy);
> > +
> > +    if (min < 0 || max < 0 || param->sched_priority < min || param->sched_priority > max){
> > +        return EINVAL;
> > +    }
> > +
> > +    a->_a_prio = param->sched_priority;
> > +    return 0;
> >  }
> > --
> > 2.34.1
>
> I don't see a good motivation for this change. The error conditions
> are MAY FAIL, not SHALL FAIL, and checking for them incurs two useless
> syscalls on every call to a function that's otherwise syscall-free.
>
> Rich

It is also technically wrong. You are not supposed to relate different
attributes until the attributes actually get used.  Intermediate results
are allowed to be invalid. That's just how the entire POSIX *attr* API
works.

In this case, a scheduling priority may be wrong for the currently
selected policy, but you don't know what policy is used in the
pthread_create() call, or if the flags even contain
PTHREAD_EXPLICIT_SCHED at that point. The checking can only happen in
pthread_create(), and it doesn't even have to check these things
explicitly, it can just delegate that to the kernel when it sets the
scheduling attributes of the new thread.

Ciao,
Markus

      reply	other threads:[~2024-12-24 14:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-24  2:03 yan.li.cn
2024-12-24  9:41 ` Rich Felker
2024-12-24 14:00   ` Markus Wichmann [this message]

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=Z2q-ioXcBB-i32_X@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    --cc=yan.li.cn@windriver.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).