This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 2/6] linux: Assume clock_getres CLOCK_{PROCESS,THREAD}_CPUTIME_ID
- From: Andreas Schwab <schwab at suse dot de>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 20 Mar 2019 12:49:18 +0100
- Subject: Re: [PATCH v2 2/6] linux: Assume clock_getres CLOCK_{PROCESS,THREAD}_CPUTIME_ID
- References: <20190218211128.1869-1-adhemerval.zanella@linaro.org> <20190218211128.1869-2-adhemerval.zanella@linaro.org>
On Feb 18 2019, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> This patch assumes that clock_getres syscall always support
> CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID, so there is no need
> to fallback to hp-timing support for _SC_MONOTONIC_CLOCK. This allows
> simplify the sysconf support to always use the syscall.
Under which condition can clock_getres return an error for these clocks?
> diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
> index 4b297ba35f..2027444488 100644
> --- a/sysdeps/unix/sysv/linux/sysconf.c
> +++ b/sysdeps/unix/sysv/linux/sysconf.c
> @@ -35,33 +35,18 @@
> static long int posix_sysconf (int name);
>
>
> -#ifndef HAS_CPUCLOCK
> static long int
> -has_cpuclock (int name)
> +check_clock_getres (clockid_t clk_id)
> {
> -# if defined __NR_clock_getres || HP_TIMING_AVAIL
> - /* If we have HP_TIMING, we will fall back on that if the system
> - call does not work, so we support it either way. */
> -# if !HP_TIMING_AVAIL
> - /* Check using the clock_getres system call. */
> struct timespec ts;
> INTERNAL_SYSCALL_DECL (err);
> - int r = INTERNAL_SYSCALL (clock_getres, err, 2,
> - (name == _SC_CPUTIME
> - ? CLOCK_PROCESS_CPUTIME_ID
> - : CLOCK_THREAD_CPUTIME_ID),
> - &ts);
> + /* Avoid setting errno to we can check whether the kernel supports
s/to/so/
> + the CLK_ID. */
> + int r = INTERNAL_SYSCALL_CALL (clock_getres, err, clk_id, &ts);
> if (INTERNAL_SYSCALL_ERROR_P (r, err))
> return -1;
> -# endif
> return _POSIX_VERSION;
> -# else
> - return -1;
> -# endif
> }
> -# define HAS_CPUCLOCK(name) has_cpuclock (name)
> -#endif
> -
>
> /* Get the value of the system variable NAME. */
> long int
> @@ -71,29 +56,21 @@ __sysconf (int name)
>
> switch (name)
> {
> - struct rlimit rlimit;
> -#ifdef __NR_clock_getres
> case _SC_MONOTONIC_CLOCK:
> - /* Check using the clock_getres system call. */
> - {
> - struct timespec ts;
> - INTERNAL_SYSCALL_DECL (err);
> - int r;
> - r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
> - return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
> - }
> -#endif
> -
> + return check_clock_getres (CLOCK_MONOTONIC);
> case _SC_CPUTIME:
> + return check_clock_getres (CLOCK_PROCESS_CPUTIME_ID);
> case _SC_THREAD_CPUTIME:
> - return HAS_CPUCLOCK (name);
> + return check_clock_getres (CLOCK_THREAD_CPUTIME_ID);
>
> - case _SC_ARG_MAX:
> + case _SC_ARG_MAX: {
Brace on next line.
> + struct rlimit rlimit;
> /* Use getrlimit to get the stack limit. */
> if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
> return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
>
> return legacy_ARG_MAX;
> + } break;
No break needed.
>
> case _SC_NGROUPS_MAX:
> /* Try to read the information from the /proc/sys/kernel/ngroups_max
> @@ -101,13 +78,14 @@ __sysconf (int name)
> procfname = "/proc/sys/kernel/ngroups_max";
> break;
>
> - case _SC_SIGQUEUE_MAX:
> + case _SC_SIGQUEUE_MAX: {
Brace on next line.
> + struct rlimit rlimit;
> if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
> return rlimit.rlim_cur;
>
> /* The /proc/sys/kernel/rtsig-max file contains the answer. */
> procfname = "/proc/sys/kernel/rtsig-max";
> - break;
> + } break;
Line break after brace.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."