Marking select(2) as restrict
Konstantin Belousov
kib at freebsd.org
Sun Feb 25 13:51:30 UTC 2018
On Sun, Feb 25, 2018 at 06:52:55AM +0100, Stefan Blachmann wrote:
> The Linux manual pages do not mention restrict for select().
> glibc select() itself returns just ENOSYS(), if there is no alias for select().
>
> So I guess what actually gets called is this:
> https://github.com/udp/freebsd-libc/blob/master/sys/select.c#L48
> Which in turn appears to call __sys_select:
> https://github.com/udp/freebsd-libc/blob/master/include/libc_private.h#L346
> See also:
> https://lists.freebsd.org/pipermail/freebsd-questions/2007-August/154906.html
>
> If I understand correctly, the *only* place that defines the
> optimizations actually being done is the static functions itself:
> https://github.com/freebsd/freebsd/blob/master/lib/libthr/thread/thr_syscalls.c#L487
No, you do not understand this correctly. Select(2) implementation is
in kernel and cannot be affected by the userspace prototype change. It
is the caller of select(2) which might be optimized unexpectedly when
select claims that its arguments cannot be aliased.
The use of restrict in the glibc prototype would be a good argument if
clang on glibc were not a rare combination.
>
> So maybe the actual prototypes being used for the
> functions for which the interpose array is used are irrelevant:
> https://github.com/freebsd/freebsd/blob/master/lib/libthr/thread/thr_syscalls.c#L642
>
> I not yet found out which functions are actually weakly aliased in,
> but I could imagine that adding the restrict keyword to the prototypes
> of the functions listed there, is possibly only
> of cosmetical importance, without any actual effect.
> If this is correct, one could be "Posix compliant" without causing any
> disruptive "optimization" :)
>
> Have a nice Sunday!
> Stefan
>
>
> P.S.: Maybe it would be better to avoid adding the restrict keyword in the
> __thr_select() function itself mentioned above, as Linux' select
> function seems to have no restrict:
> https://github.com/torvalds/linux/blob/master/fs/select.c#L1262
> https://github.com/torvalds/linux/blob/master/fs/select.c#L599
>
>
> On 2/25/18, Eitan Adler <lists at eitanadler.com> wrote:
> > On 24 February 2018 at 10:55, Conrad Meyer <cem at freebsd.org> wrote:
> >> On Sat, Feb 24, 2018 at 10:35 AM, Eitan Adler <lists at eitanadler.com>
> >> wrote:
> >>> After this entire thread here is the summary. If I've misrepresented
> >>> you here please let me know.
> >>> ...
> >>>
> >>> kib@ - no benefit; concerned fallout could be hard to observe
> >>> cem@ - concerned about warnings
> >>
> >> Consider me a +1 to kib at . I did not voice those concerns explicitly
> >> in earlier email because kib did already and I didn't anticipate you
> >> would ignore him.
> >
> > I am not ignoring him. As I stated above I do not believe fallout is
> > likely since most other major libc implementations have already done
> > this:
> >
> > glibc: already done -
> > https://github.com/bminor/glibc/blob/master/misc/sys/select.h#L101
> > openbsd: already done
> > https://github.com/openbsd/src/blob/master/sys/sys/select.h#L128
> > dragonflyBSD: alredy done:
> > https://github.com/dragonflybsd/dragonflybsd/blob/master/sys/sys/select.h#L50
> > netbsd: already done:
> > https://github.com/NetBSD/src/blob/trunk/sys/sys/select.h#L69
> >
> > As a further check I went through the search results on github for
> > select() and did not see any failures in the top few pages.
> >
> > --
> > Eitan Adler
> > _______________________________________________
> > freebsd-hackers at freebsd.org mailing list
> > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
> >
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
More information about the freebsd-hackers
mailing list