buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
From: Peter Seiderer <ps.report@gmx.net>
To: Arnout Vandecappelle <arnout@mind.be>
Cc: David Laight <David.Laight@ACULAB.COM>,
	"buildroot@buildroot.org" <buildroot@buildroot.org>
Subject: Re: [Buildroot] [git commit] package/ntp: Fix building with glibc 2.34+
Date: Thu, 23 Sep 2021 23:34:09 +0200	[thread overview]
Message-ID: <20210923233409.50cba2f7@gmx.net> (raw)
In-Reply-To: <970f860f-a99b-71cb-6b4c-9920f5a5653c@mind.be>

Hello Arnout, David, all,

On Thu, 23 Sep 2021 11:26:18 +0200, Arnout Vandecappelle <arnout@mind.be> wrote:

> On 23/09/2021 10:23, David Laight wrote:
> > From: Arnout Vandecappelle
> >> Sent: 22 September 2021 21:13
> > ...
> >> On attempt to build ntp with glibc 2.34 the following error happens:
> >> -------------------------------->8------------------------------
> >> In file included from .../output/host/lib/gcc/i586-buildroot-linux-gnu/10.3.0/include-
> >> fixed/pthread.h:42,
> >>                   from work_thread.c:13:
> >> work_thread.c:45:57: error: missing binary operator before token "("
> >>     45 | #if defined(PTHREAD_STACK_MIN) && THREAD_MINSTACKSIZE < PTHREAD_STACK_MIN
> >>        |                                                         ^~~~~~~~~~~~~~~~~
> >> -------------------------------->8------------------------------
> >>
> >> That's because starting from glibc 2.34 PTHREAD_STACK_MIN gets determined
> >> dynamically in runtime via sysconf(), see [1].
> > ...
> >> +In glibc 2.34+ PTHREAD_STACK_MIN is not a compile-time constant which
> >> +could mean different stack sizes at runtime on different architectures
> >> +and it also causes compile failure. Default glibc thread stack size
> >> +or 64Kb set by ntp should be good in glibc these days.
> > ...
> >> + #ifndef THREAD_MINSTACKSIZE
> >> + # define THREAD_MINSTACKSIZE	(64U * 1024)
> >> + #endif
> >> +-#ifndef __sun
> >> ++#if !defined(__sun) && !defined(__GLIBC__)
> >> + #if defined(PTHREAD_STACK_MIN) && THREAD_MINSTACKSIZE < PTHREAD_STACK_MIN
> >> + # undef THREAD_MINSTACKSIZE
> >> + # define THREAD_MINSTACKSIZE PTHREAD_STACK_MIN
> >
> > I'm not convinced that is the correct fix.
> > The same issues apply to the thread stack as they do to the signal stack.
> > Albeit the sizes are larger.
> >
> > The very reason that PTHREAD_STACK_MIN isn't a compile-time constant
> > is that the value cannot be determined at compile time.
> > While 64k may seem ok for now, there is no reason for it to be enough.
> >
> > Possibly something like:
> > #ifndef PTHREAD_STACK_MIN
> > #define THREAD_MINSTACKSIZE	(64U * 1024)
> > #else
> > #define THREAD_MINSTACKSIZE	(PTHREAD_STACK_MIN > 64U * 1024 ? PTHREAD_STACK_MIN : 64U * 1024)
> > #endif
> > would be better.
> > Although a form that only evaluates PTHREAD_STACK_MIN once may be better.
>
>   It really doesn't matter that much. The only place where THREAD_MINSTACKSIZE
> is used is in the code leading up to this:
>
>                  if (nstacksize != ostacksize)
>                          rc = pthread_attr_setstacksize(&thr_attr, nstacksize);
>                  if (0 != rc)
>                          msyslog(LOG_ERR,
>                                  "start_blocking_thread:
> pthread_attr_setstacksize(0x%lx -> 0x%lx) -> %s",
>                                  (u_long)ostacksize, (u_long)nstacksize,
>                                  strerror(rc));
>
>   Note that there's no error handling other than printing an error message. So,
> if PTHREAD_STACK_MIN turns out to be less than 64K (which is very, very unlikely
> to be the case), then the only thing that will happen is that
> pthread_attr_setstacksize will fail to set the stack size to a lower value and
> we keep the default stack size (and print an error message).
>
>   I do agree however that your alternative fix is better (though Id keep the
> existing __sun ifdeffery, just to make the change minimal). So feel free to send
> a patch that changes the existing patch.
>
>
> > Quite why ntp is setting the thread stack size is any bodies guess though.
>
>   I guess because there are some threads that need more than 4K stack (which is
> minstacksize on some platforms), and on the other hand they don't want to waste
> stack space on threads that really don't need that much.
>
> > It can only get it wrong in a different way!
>
>   For relatively small code, it's not that hard to measure or calculate the
> amount of stack you need.
>
> > Although ISTR one version of ntp thinking itself so important
> > that it locked all its memory.
> > So maybe it is just trying to reduce that locked memory footprint.
>
>   I do indeed see an mlockall() in ntpd.c, but I don't see any code doing any
> prefaulting of the stack, so it doesn't seem to be very effective :-)
>
>
> > Given that it's pretty much impossible for ntp to accurately set
> > the time to less than the RTT to the server (it can't tell whether
> > the RTT delays are on the tx or rx side) I can't see that it matters.
>
>   Yeah, it looks like ntp is a pretty dead-end project...

Maybe time to provide NTPsec [1] as alternative...

Regards,
Peter

[1] https://www.ntpsec.org/

>
>   Regards,
>   Arnout
>
> >
> > Anyone who needs sub-ms time sync has bigger problems.
> >
> > 	David
> >
> > -
> > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> > Registration No: 1397386 (Wales)
> >
> _______________________________________________
> buildroot mailing list
> buildroot@lists.buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2021-09-23 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 20:13 [Buildroot] [git commit] package/ntp: Fix building with glibc 2.34+ Arnout Vandecappelle
2021-09-23  8:23 ` David Laight
2021-09-23  9:26   ` Arnout Vandecappelle
2021-09-23 21:34     ` Peter Seiderer [this message]
2021-10-05  6:27       ` Peter Korsgaard

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=20210923233409.50cba2f7@gmx.net \
    --to=ps.report@gmx.net \
    --cc=David.Laight@ACULAB.COM \
    --cc=arnout@mind.be \
    --cc=buildroot@buildroot.org \
    /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).