Commit Graph

35104 Commits

Author SHA1 Message Date
Florian Weimer
060d8b9ced WIP mul64 dlsym optimization
Change-Id: I4caf4f14deb7a106c17e3ca89bdff5cd89f9541b
2019-11-11 16:09:32 +01:00
Florian Weimer
0fa7402cbb elf: Optimize symbol binding by pre-computing divisions
The division for the hash table lookup shows up in profiles.  We can
use a standard compiler optimization technique to speed up the hash
table lookup.  The speedup is most pronounced when a symbol lookup
succeeds early in the scope array, otherwise the bitmap check
dominates the profiles.

Change-Id: I898b7c711979447d4756b3f7b567c49a8d33187b
2019-11-11 14:18:36 +01:00
Florian Weimer
0e5a24f5a9 Introduce divopt.h
Change-Id: I440e41fd50de1cfc036c8557846c0bfc75654e49
2019-11-11 14:18:36 +01:00
Florian Weimer
6e18a8ddf1 dlsym: Do not determine caller link map if not needed
Obtaining the link map is potentially very slow because it requires
iterating over all loaded objects in the current implementation.  If
the caller supplied an explicit handle (i.e., not one of the RTLD_*
constants), the dlsym implementation does not need the identity of the
caller (except in the special cause of auditing), so this change
avoids computing it in that case.

Even in the minimal case (dlsym called from a main program linked with
-dl), this shows a small speedup, perhaps around five percent.  The
performance improvement can be arbitrarily large in principle (if
_dl_find_dso_for_object has to iterate over many link maps).

Change-Id: Ide5d9e2cc7ac25a0ffae8fb4c26def0c898efa29
2019-11-11 14:18:36 +01:00
Florian Weimer
10cf7f52c6 linux: Reduce stack size for nptl/tst-thread-affinity-pthread
And related tests.  These tests create a thread for each core, so
they may fail due to address space limitations with the default
stack size.

Change-Id: Ieef44a7731f58d3b7d6638cce4ccd31126647551
2019-11-11 13:40:55 +01:00
Florian Weimer
36ada9ee2c support: Add support_set_small_thread_stack_size
And support_small_stack_thread_attribute

Change-Id: I1cf79a469984f8f30a4a947ee9ec2a5e74de8926
2019-11-11 13:40:55 +01:00
Andreas Schwab
fc141ea78e Fix array bounds violation in regex matcher (bug 25149)
If the regex has more subexpressions than the number of elements allocated
in the regmatch_t array passed to regexec then proceed_next_node may
access the regmatch_t array outside its bounds.

No testcase added because even without this bug it would then crash in
pop_fail_stack which is bug 11053.
2019-11-11 12:24:59 +01:00
Alistair Francis
2e44b10b42 sysdeps/clock_nanosleep: Use clock_nanosleep_time64 if avaliable
The clock_nanosleep syscall is not supported on newer 32-bit platforms (such
as RV32). To fix this issue let's use clock_nanosleep_time64 if it is
avaliable.
2019-11-08 12:06:17 -08:00
Adhemerval Zanella
31f000a8a6 Remove hppa pthreadP.h
It just contains duplicated defitions provided by other generic
nptl headers.

Checked with run-built-tests=no against hppa-linux-gnu.

Change-Id: I95f55d5b7b7ae528c81cd2394d57ce92398189bf
2019-11-08 15:46:26 -03:00
Florian Weimer
be6b16d975 login: Acquire write lock early in pututline [BZ #24882]
It has been reported that due to lack of fairness in POSIX file
locking, the current reader-to-writer lock upgrade can result in
lack of forward progress.  Acquiring the write lock directly
hopefully avoids this issue if there are only writers.

This also fixes bug 24882 due to the cache revalidation in
__libc_pututline.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Change-Id: I57e31ae30719e609a53505a0924dda101d46372e
2019-11-07 23:09:39 +01:00
Adhemerval Zanella
4f4bb489e0 nptl: Add missing placeholder abi symbol from nanosleep move
Adds the __libpthread_version_placeholder symbol with the same version
of nanosleep/__nanosleep that was removed by 79a547b162 and that
is not provided by other symbols.
2019-11-07 16:46:06 +00:00
Florian Weimer
b0a83ae71b login: Remove double-assignment of fl.l_whence in try_file_lock
Since l_whence is the second member of struct flock, it is written
twice.  The double-assignment is technically undefined behavior due to
the lack of a sequence point.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Change-Id: I2baf9e70690e723c61051b25ccbd510aec15976c
2019-11-07 09:54:33 +01:00
Florian Weimer
a673c07af3 hurd: Use __clock_gettime in _hurd_select
The __gettimeofday references caused check-localplt failures after
commit 5e46749c64.

Fixes: 5e46749c64
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Change-Id: Ia6da4045157a5bbccc67d79e881d7592e6f8a890
2019-11-07 09:54:33 +01:00
Florian Weimer
50471a8613 hurd: Remove lingering references to the time function
They cause a check-localplt failure after commit f9a7554009.

Fixes: f9a7554009
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Change-Id: I37bc20f3449b9e358f32879ed231720c969965b4
2019-11-07 09:54:33 +01:00
liqingqing
dae7bf3897 math: enhance the endloop condition of function handle_input_flag
In the function handle_input_flag, the end-loop condition is not
correct, because when the loop variable i equals 16
(num_input_flag_types), then input_flags[16] will be out of bounds.
(This issue is only relevant with invalid input files to
gen-auto-libm-tests.)
2019-11-07 00:26:54 +00:00
Adhemerval Zanella
807edded25 nptl: Refactor thrd_sleep in terms of clock_nanosleep
Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-11-06 14:47:05 -03:00
Adhemerval Zanella
3537ecb49c Refactor nanosleep in terms of clock_nanosleep
The generic version is straightforward.  For Hurd, its nanosleep
implementation is moved to clock_nanosleep with adjustments from
generic unix implementation.

The generic clock_nanosleep unix version is also removed since
it calls nanosleep.

Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-11-06 14:47:02 -03:00
Adhemerval Zanella
79a547b162 nptl: Move nanosleep implementation to libc
Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.  I also checked
the libpthread.so .gnu.version_d entries for every ABI affected and
all of them contains the required versions (including for architectures
which exports __nanosleep with a different version).

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-11-06 14:36:07 -03:00
Adhemerval Zanella
2a0356e119 posix: Sync regex with gnulib
It sync with gnulib commit 6cfb4302b3e1da14d706198b693558290e9b00f4
and contains the fixes:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=32915b2a8a43825720755113bdffe9f67a591748
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=48f07576b8cd935b48e1050551f45ab1a79b9f01
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=5e407aba1f775d51b25481cb55f324c9868f62d7
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=4e02b30c761c76d04057fa5f6bba71401f9310cd
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=79f8ee4e389f8cb1339f8abed9a7d29816e2a2d4

Checked on x86_64-linux-gnu and i686-linux-gnu.
2019-11-06 09:20:52 -03:00
Mike FABIAN
4ecd584908 Add mnw language code [BZ #25139] 2019-11-06 08:15:16 +01:00
Talachan Mon
c5fbd7c3ea Add new locale: mnw_MM (Mon language spoken in Myanmar) [BZ #25139] 2019-11-06 08:15:16 +01:00
Stefan Liebler
64bca76f42 S390: Fp comparison are now raising FE_INVALID with gcc 10.
The s390 gcc bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77918
"S390: Floating point comparisons don't raise invalid for unordered operands."
is fixed with gcc 10. Thus we conditionally set FIX_COMPARE_INVALID
to 0 or 1.
2019-11-06 08:07:40 +01:00
Lukasz Majewski
f2e30cc0f8 linux: pselect: Remove CALL_PSELECT6 macro
Nothing defines CALL_PSELECT6 in the current tree, so remove it.

Tested with:
- make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8" (x86_64)
- scripts/build-many-glibcs.py
2019-11-05 17:58:05 +01:00
Arjun Shankar
81a1fa6cbf Fix run-one-test so that it runs elf tests
The `test' make target passes a trailing slash in the subdir argument.  This
does not play well with elf/rtld-Rules which looks for `elf' without any
trailing slash, and therefore doesn't find a match when running an elf test
individually.  This commit removes the trailing slash from the invocation.

Reviewed-by: DJ Delorie <dj@redhat.com>
2019-11-05 17:45:07 +01:00
Mike Crowe
3ef5e118f2 nptl: Fix niggles with pthread_clockjoin_np
Joseph Myers spotted[1] that 69ca4b54c1 added
pthread_clockjoin_np to sysdeps/nptl/pthread.h but not to its hppa-specific
equivalent sysdeps/unix/sysv/linux/hppa/pthread.h.

Rafal Luzynski spotted[2] typos in the NEWS entry and manual updates too.

Florian Weimer spotted[3] that the clockid parameter was not using a
reserved identifier in pthread.h.

[1] https://sourceware.org/ml/libc-alpha/2019-11/msg00016.html
[2] https://sourceware.org/ml/libc-alpha/2019-11/msg00019.html
[3] https://sourceware.org/ml/libc-alpha/2019-11/msg00022.html

Reviewed-by: Joseph Myers <joseph@codesourcery.com>
Reviewed-by: Rafal Luzynski <digitalfreak@lingonborough.com>
Reviewed-by: Florian Weimer <fw@deneb.enyo.de>
2019-11-04 16:44:49 -03:00
John David Anglin
e4c23a029a hppa: Align __clone stack argument to 8 bytes (Bug 25066)
The hppa architecture requires strict alignment for loads and stores.
As a result, the minimum stack alignment that will work is 8 bytes.
This patch adjusts __clone() to align the stack argument passed to it.
It also adjusts slightly some formatting.

This fixes the nptl/tst-tls1 test.
2019-11-03 16:28:01 -05:00
Lukasz Majewski
42893aa38f y2038: linux: Provide __futimens64 implementation
This patch provides new __futimens64 explicit 64 bit function for
setting access and modification time of file (by using its file descriptor).
Moreover, a 32 bit version - __futimens has been refactored to internally use
__futimens64.

The __futimens is now supposed to be used on systems still supporting
32 bit time (__TIMESIZE != 64) - hence the necessary conversions to 64 bit
struct __timespec64.
When pointer to struct __timespec64 is NULL - the file access and modification
time is set to the current one (by the kernel) and no conversions from struct
timespec to __timespec64 are performed.

The __futimens64 reuses __utimensat64_helper defined for __utimensat64.

The test procedure for __futimens64 is the same as for __utimensat64 conversion
patch.
2019-11-02 08:41:35 +01:00
Lukasz Majewski
f5b6fd258b y2038: linux: Provide __utimensat64 implementation
This patch provides new __utimensat64 explicit 64 bit function for
setting access and modification time of a file. Moreover, a 32 bit version
- __utimensat has been refactored to internally use __utimensat64.

The __utimensat is now supposed to be used on systems still supporting
32 bit time (__TIMESIZE != 64) - hence the necessary conversions to 64 bit
struct __timespec64.
When pointer to struct __timespec64 is NULL - the file access and modification
time is set to the current one and no conversions from struct timespec to
__timespec64 are performed.

The new utimensat_time64 syscall available from Linux 5.1+ has been used,
when applicable.
The new helper function - __utimensat64_helper - has been introduced to
facilitate code re-usage on function providing futimens syscall handling.
The Linux kernel checks if passed tv_nsec value overflows, so there is no
need to repeat it in glibc.
When utimensat syscall on systems supporting 32 bit time ABI is used,
the check is performed if passed data (which may have 64 bit tv_sec) fits
into 32 bit range.

Build tests:
- The code has been tested on x86_64/x86 (native compilation):
make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8"

- The glibc has been build tested (make PARALLELMFLAGS="-j8") for
x86 (i386), x86_64-x32, and armv7

Run-time tests:
- Run specific tests on ARM/x86 32bit systems (qemu):
https://github.com/lmajewski/meta-y2038 and run tests:
https://github.com/lmajewski/y2038-tests/commits/master

- Use of cross-test-ssh.sh for ARM (armv7):
make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck

Linux kernel, headers and minimal kernel version for glibc build test
matrix:
- Linux v5.1 (with utimensat_time64) and glibc build with v5.1 as
minimal kernel version (--enable-kernel="5.1.0")
The __ASSUME_TIME64_SYSCALLS flag defined.

- Linux v5.1 and default minimal kernel version
The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports utimensat_time64
syscall.

- Linux v4.19 (no utimensat_time64 support) with default minimal kernel
version for contemporary glibc
This kernel doesn't support utimensat_time64 syscall, so the fallback
to utimensat is tested.

The above tests were performed with Y2038 redirection applied as well as
without (so the __TIMESIZE != 64 execution path is checked as well).

No regressions were observed.
2019-11-02 08:41:25 +01:00
Mike Crowe
7aeab82edb nptl: Add pthread_timedjoin_np, pthread_clockjoin_np NULL timeout test
Passing NULL as the timeout parameter to pthread_timedjoin_np has resulted
in it behaving like pthread_join for a long time. Since that is now the
documented behaviour, we ought to test that both it and the new
pthread_clockjoin_np support it.

Checked on x86_64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-11-01 11:23:43 -03:00
Mike Crowe
69ca4b54c1 nptl: Add pthread_clockjoin_np
Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
accepts a clockid_t parameter to indicate which clock the timeout should be
measured against. This mirrors the recently-added POSIX-proposed "clock"
wait functions.

Checked on x86_64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-11-01 11:23:43 -03:00
Mike Crowe
893bbdd007 manual: Add documentation for pthread_tryjoin_np and pthread_timedjoin_np
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-11-01 11:23:43 -03:00
Mike Crowe
22434b2f03 nptl: Convert tst-join3 to use libsupport
Checked on x86_64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-11-01 11:23:43 -03:00
Paul Eggert
f8042536dc Sync time/mktime.c with gnulib
This syncs with gnulib commit 9e78024bad107fe786cc3e5e328a475921ea0873.
* time/mktime.c: Update URL in comment.
2019-10-31 13:17:00 -07:00
Adhemerval Zanella
c1dac8f83e Sync timespec-{add,sub} with gnulib
It sync with gnulib commit 06011ed74e978613422aca43c0bd92dc44213933.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2019-10-31 17:03:04 -03:00
Adhemerval Zanella
356ced8dcb Sync intprops.h with gnulib
It sync with gnulib commit f5756b919addb9e8ce03f4e61a10e4fcff14874a.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2019-10-31 17:02:49 -03:00
Adhemerval Zanella
c81aa64e81 Refactor adjtimex based on clock_adjtime
Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-10-31 11:09:25 -03:00
Adhemerval Zanella
6b1472eb2e Refactor PI mutexes internal definitions
This patch adds the generic futex_lock_pi and futex_unlock_pi to wrap
around the syscall machinery required to issue the syscall calls. It
simplifies a bit the futex code required to implement PI mutexes.

No function changes, checked on x86_64-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-31 11:09:10 -03:00
Adhemerval Zanella
fbb4a31437 Remove pause and nanosleep not cancel wrappers
Since they are not used any longer.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-31 11:09:06 -03:00
Adhemerval Zanella
215078017f nptl: Replace non cancellable pause/nanosleep with futex
To help y2038 work avoid duplicate all the logic of nanosleep on
non cancellable version, the patch replace it with a new futex
operation, lll_timedwait.  The changes are:

  - Add a expected value for __lll_clocklock_wait, so it can be used
    to wait for generic values.

  - Remove its internal atomic operation and move the logic to
    __lll_clocklock.  It makes __lll_clocklock_wait even more generic
    and __lll_clocklock slight faster on fast-path (since it won't
    require a function call anymore).

  - Add lll_timedwait, which uses __lll_clocklock_wait, to replace both
    __pause_nocancel and __nanosleep_nocancel.

It also allows remove the sparc32 __lll_clocklock_wait implementation
(since it is similar to the generic one).

Checked on x86_64-linux-gnu, sparcv9-linux-gnu, and i686-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-31 11:09:01 -03:00
Adhemerval Zanella
b580327434 Consolidate lowlevellock-futex.h
NPTL is already Linux specific, there is no need to parametrize low
level lock futex operations and add a sysdep Linux specific
implementation.  This patch moves the relevant Linux code to nptl one.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-31 11:08:57 -03:00
Adhemerval Zanella
b865eed0ac Consolidate futex-internal.h
NPTL is already Linux specific, there is no need to parametrize futex
operations and add a sysdep Linux specific implementation.  This patch
moves the relevant Linux code to nptl one.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-31 11:08:54 -03:00
DJ Delorie
ff12e0fb91 Base max_fast on alignment, not width, of bins (Bug 24903)
set_max_fast sets the "impossibly small" value based on,
eventually, MALLOC_ALIGNMENT.  The comparisons for the smallest
chunk used is, eventually, MIN_CHUNK_SIZE.  Note that i386
is the only platform where these are the same, so a smallest
chunk *would* be put in a no-fastbins fastbin.

This change calculates the "impossibly small" value
based on MIN_CHUNK_SIZE instead, so that we can know it will
always be impossibly small.
2019-10-30 22:59:11 -04:00
Zack Weinberg
62193c4a3a Revise the documentation of simple calendar time.
This is a thorough revision of all the material relating to the
functions time, stime, gettimeofday, settimeofday, clock_gettime,
clock_getres, clock_settime, and difftime, spilling over into the
discussion of time-related data types (which now get their own
section) and touching the adjtime family as well (which deserves its
own thorough revision, but I'd have to do a bunch of research first).

Substantive changes are:

 * Document clock_gettime, clock_getres, and clock_settime.  (Only
   CLOCK_REALTIME and CLOCK_MONOTONIC are documented; the others are
   either a bit too Linux-specific, or have more to do with measuring
   CPU/processor time.  That section _also_ deserves its own thorough
   revision but again I'd have to do a bunch of research first.)

 * Present gettimeofday, settimeofday, and struct timeval as obsolete
   relative to clock_*.

 * Remove the documentation of struct timezone.  Matching POSIX,
   say that the type of the second argument to gettimeofday and
   settimeofday is [const] void *.

 * Clarify ISO C and POSIX's requirements on time_t.  Clarify the
   circumstances under which difftime is equivalent to simple
   subtraction.

 * Consolidate documentation of most of the time-related data types
   into a new section "Time Types," right after "Time Basics."  (The
   exceptions are struct tm, which stays in "Broken-down Time," and
   struct times, which stays in "Processor And CPU Time."

 * The "Elapsed Time" section is now called "Calculating Elapsed Time"
   and includes only difftime and the discussion of how to compute
   timeval differences by hand.

 * Fold the "Simple Calendar Time," "High Resolution Calendar," and
   "High Accuracy Clock" sections together into two new sections titled
   "Getting the Time" and "Setting and Adjusting the Time."
2019-10-30 17:11:10 -03:00
Zack Weinberg
2f2c76e1c8 Make second argument of gettimeofday as 'void *'
Also make the public prototype of gettimeofday declare its second
argument with type "void *" unconditionally, consistent with POSIX.

It is also consistent with POSIX.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Adhemerval Zanella
5e46749c64 Use clock_gettime to implement gettimeofday.
Consolidate generic gettimeofday implementation to use clock_gettime.
Linux ports that still provide gettimeofday through vDSO are not
changed.

Remove sysdeps/unix/clock_gettime.c, which implemented clock_gettime
using gettimeofday; new OS ports must provide a real implementation of
clock_gettime.

Rename sysdeps/mach/gettimeofday.c to sysdeps/mach/clock_gettime.c and
convert into an implementation of clock_gettime.  It only supports
CLOCK_REALTIME; Mach does not appear to have any support for monotonic
clocks.  It uses __host_get_time, which provides at best microsecond
resolution.  Hurd is currently using sysdeps/posix/clock_getres.c for
clock_getres; its output for CLOCK_REALTIME is based on
sysconf (_SC_CLK_TCK), and I do not know whether that gives the
correct result.

Unlike settimeofday, there are no known uses of gettimeofday's
vestigial "get time zone" feature that are not bugs.  (The per-process
timezone support in localtime and friends is unrelated, and the
programs that set the kernel's offset between the hardware clock and
UTC do not need to read it back.)  Therefore, this feature is dummied
out.  Henceforth, if gettimeofday's "struct timezone" argument is not
NULL, it will write zeroes to both fields.  Any program that is
actually looking at this data will thus think it is running in UTC,
which is probably more correct than whatever it was doing before.

[__]gettimeofday no longer has any internal callers, so we can now
remove its internal prototype and PLT bypass aliases.  The
__gettimeofday@GLIBC_2.0 export remains, in case it is used by any
third-party code.

It also allows to simplify the arch-specific implementation on x86 and
powerpc to remove the hack to disable the internal route to non iFUNC
variant for internal symbol.

This patch also fixes a missing optimization on aarch64, powerpc, and
x86 where the code used on static build do not use the vDSO.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Co-authored-by: Zack Weinberg <zackw@panix.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Zack Weinberg
40a36935ff Use clock_gettime to implement timespec_get.
timespec_get is the same function as clock_gettime, with an obnoxious
coating of NIH painted on it by the ISO C committee.  In addition to
the rename, it takes its arguments in a different order, it returns 0
on *failure* or a positive number on *success*, and it requires that
all of its TIME_* constants be positive.  This last means we cannot
directly reuse the existing CLOCK_* constants for it, because
those have been allocated starting with CLOCK_REALTIME = 0 on all
existing platforms.

This patch simply promotes the sysdeps/posix implementation to
universal, and removes the Linux-specific implementation, whose
apparent reason for existing was to cut out one function call's worth
of overhead.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Zack Weinberg
2b5fea833b Consolidate and deprecate ftime
ftime is an obsolete variation on gettimeofday, offering only
millisecond time resolution; it was probably a system call in ooold
versions of BSD Unix.  For historic reasons, we had three
implementations of it.  These are all consolidated into time/ftime.c,
and then the function is deprecated.

For some reason, the implementation of ftime in terms of gettimeofday
was rounding rather than truncating microseconds to milliseconds.  In
all the other places where we use a higher-resolution time function to
implement a lower-resolution one, we truncate.  ftime is changed to
match, just for tidiness' sake.

Like gettimeofday, ftime tries to report the time zone, and using that
information is always a bug.  This patch dummies out the reported
timezone information; the timezone and dstflag fields of the
returned "struct timeb" will always be zero.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, and powerpc-linux-gnu.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Adhemerval Zanella
f9a7554009 Change most internal uses of time to __clock_gettime.
As for gettimeofday, time will be implemented based on clock_gettime
on all platforms and internal code should use clock_gettime
directly.  In addition to removing a layer of indirection, this will
allow us to remove the PLT-bypass gunk for gettimeofday.

The changed code always assumes __clock_gettime (CLOCK_REALTIME)
or __clock_gettime (CLOCK_REALTIME_COARSE) (for Linux case) cannot
fail, using the same rationale for gettimeofday change.  And internal
helper was added (time_now).

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, and powerpc-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Adhemerval Zanella
0d56378349 Use clock_gettime to implement time.
Change the default implementation of time to call clock_gettime,
to align with new Linux ports that are expected to only implement
__NR_clock_gettime.  Arch-specific implementation that either call
the time vDSO or route to gettimeofday vDSO are not removed.

Also for Linux, CLOCK_REALTIME_COARSE is used instead of generic
CLOCK_REALTIME clockid.  This takes less CPU time and its behavior
better matches what the current glibc does.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Co-authored-by: Zack Weinberg <zackw@panix.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:05:14 -03:00
Zack Weinberg
c3f9aef063 Use clock_settime to implement settimeofday.
Unconditionally, on all ports, use clock_settime to implement
settimeofday.  Remove sysdeps/unix/clock_settime.c, which implemented
clock_settime by calling settimeofday; new OS ports must henceforth
provide a real implementation of clock_settime.

Hurd had a real implementation of settimeofday but not of
clock_settime; this patch converts it into an implementation of
clock_settime.  It only supports CLOCK_REALTIME and microsecond
resolution; Hurd/Mach does not appear to have any support for
finer-resolution clocks.

The vestigial "set time zone" feature of settimeofday complicates the
generic settimeofday implementation a little.  The only remaining uses
of this feature that aren't just bugs, are using it to inform the
Linux kernel of the offset between the hardware clock and UTC, on
systems where the hardware clock doesn't run in UTC (usually because
of dual-booting with Windows).  There currently isn't any other way to
do this.  However, the callers that do this call settimeofday with
_only_ the timezone argument non-NULL.  Therefore, glibc's new
behavior is: callers of settimeofday must supply one and only one of
the two arguments.  If both arguments are non-NULL, or both arguments
are NULL, the call fails and sets errno to EINVAL.

When only the timeval argument is supplied, settimeofday calls
__clock_settime(CLOCK_REALTIME), same as stime.

When only the timezone argument is supplied, settimeofday calls a new
internal function called __settimezone.  On Linux, only, this function
will pass the timezone structure to the settimeofday system call.  On
all other operating systems, and on Linux architectures that don't
define __NR_settimeofday, __settimezone is a stub that always sets
errno to ENOSYS and returns -1.

The settimeoday syscall is enabled on Linux by the flag
COMPAT_32BIT_TIME, which is an option to either 32-bits ABIs or COMPAT
builds (defined usually by 64-bit kernels that want to support 32-bit
 ABIs, such as x86).  The idea to future 64-bit time_t only ABIs
is to not provide settimeofday syscall.

The same semantics are implemented for Linux/Alpha's GLIBC_2.0 compat
symbol for settimeofday.

There are no longer any internal callers of __settimeofday, so the
internal prototype is removed.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:05:14 -03:00