summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys
diff options
context:
space:
mode:
authorvangyzen <vangyzen@FreeBSD.org>2017-05-01 01:36:54 +0000
committervangyzen <vangyzen@FreeBSD.org>2017-05-01 01:36:54 +0000
commit1f3f7c15d6db5da93247e3a10bb3f1ff40f61915 (patch)
tree2c49170567af964db6609d58aff8eb6a7649f4ce /lib/libc/sys
parent57723a7d7f1db867d4acce11b84c8389cefc9acd (diff)
downloadFreeBSD-src-1f3f7c15d6db5da93247e3a10bb3f1ff40f61915.zip
FreeBSD-src-1f3f7c15d6db5da93247e3a10bb3f1ff40f61915.tar.gz
MFC r315526
Add clock_nanosleep() Add a clock_nanosleep() syscall, as specified by POSIX. Make nanosleep() a wrapper around it. Attach the clock_nanosleep test from NetBSD. Adjust it for the FreeBSD behavior of updating rmtp only when interrupted by a signal. I believe this to be POSIX-compliant, since POSIX mentions the rmtp parameter only in the paragraph about EINTR. This is also what Linux does. (NetBSD updates rmtp unconditionally.) Copy the whole nanosleep.2 man page from NetBSD because it is complete and closely resembles the POSIX description. Edit, polish, and reword it a bit, being sure to keep any relevant text from the FreeBSD page. Regenerate syscall files. Relnotes: yes Sponsored by: Dell EMC
Diffstat (limited to 'lib/libc/sys')
-rw-r--r--lib/libc/sys/Makefile.inc2
-rw-r--r--lib/libc/sys/Symbol.map2
-rw-r--r--lib/libc/sys/clock_nanosleep.c53
-rw-r--r--lib/libc/sys/interposing_table.c1
-rw-r--r--lib/libc/sys/nanosleep.2169
5 files changed, 187 insertions, 40 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index ac1bb11..8ecfbbc 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -34,6 +34,7 @@ INTERPOSED = \
accept \
accept4 \
aio_suspend \
+ clock_nanosleep \
close \
connect \
fcntl \
@@ -349,6 +350,7 @@ MLINKS+=chown.2 fchown.2 \
chown.2 lchown.2
MLINKS+=clock_gettime.2 clock_getres.2 \
clock_gettime.2 clock_settime.2
+MLINKS+=nanosleep.2 clock_nanosleep.2
MLINKS+=cpuset.2 cpuset_getid.2 \
cpuset.2 cpuset_setid.2
MLINKS+=cpuset_getaffinity.2 cpuset_setaffinity.2
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index 489635e..83d1af9 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -399,6 +399,7 @@ FBSD_1.4 {
};
FBSD_1.5 {
+ clock_nanosleep;
fdatasync;
};
@@ -511,6 +512,7 @@ FBSDprivate_1.0 {
__sys_clock_getres;
_clock_gettime;
__sys_clock_gettime;
+ __sys_clock_nanosleep;
_clock_settime;
__sys_clock_settime;
_close;
diff --git a/lib/libc/sys/clock_nanosleep.c b/lib/libc/sys/clock_nanosleep.c
new file mode 100644
index 0000000..65e1548
--- /dev/null
+++ b/lib/libc/sys/clock_nanosleep.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2017 Eric van Gyzen
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <time.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_clock_nanosleep, __clock_nanosleep);
+
+#pragma weak clock_nanosleep
+int
+clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp,
+ struct timespec *rmtp)
+{
+
+ return (((int (*)(clockid_t, int, const struct timespec *,
+ struct timespec *))
+ __libc_interposing[INTERPOS_clock_nanosleep])(clock_id, flags,
+ rqtp, rmtp));
+}
diff --git a/lib/libc/sys/interposing_table.c b/lib/libc/sys/interposing_table.c
index 1447e42..faf1e6c 100644
--- a/lib/libc/sys/interposing_table.c
+++ b/lib/libc/sys/interposing_table.c
@@ -80,6 +80,7 @@ interpos_func_t __libc_interposing[INTERPOS_MAX] = {
SLOT(ppoll, __sys_ppoll),
SLOT(map_stacks_exec, __libc_map_stacks_exec),
SLOT(fdatasync, __sys_fdatasync),
+ SLOT(clock_nanosleep, __sys_clock_nanosleep),
};
#undef SLOT
diff --git a/lib/libc/sys/nanosleep.2 b/lib/libc/sys/nanosleep.2
index f50544b..29277f3 100644
--- a/lib/libc/sys/nanosleep.2
+++ b/lib/libc/sys/nanosleep.2
@@ -1,5 +1,4 @@
-.\" $OpenBSD: nanosleep.2,v 1.1 1997/04/20 20:56:20 tholo Exp $
-.\" $NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $
+.\" $NetBSD: nanosleep.2,v 1.23 2016/11/14 10:40:59 wiz Exp $
.\"
.\" Copyright (c) 1986, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -31,51 +30,136 @@
.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd April 17, 1997
+.Dd March 17, 2017
.Dt NANOSLEEP 2
.Os
.Sh NAME
.Nm nanosleep
-.Nd suspend process execution for an interval measured in nanoseconds
+.Nd high resolution sleep
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In time.h
.Ft int
-.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp"
+.Fo clock_nanosleep
+.Fa "clockid_t clock_id"
+.Fa "int flags"
+.Fa "const struct timespec *rqtp"
+.Fa "struct timespec *rmtp"
+.Fc
+.Ft int
+.Fo nanosleep
+.Fa "const struct timespec *rqtp"
+.Fa "struct timespec *rmtp"
+.Fc
.Sh DESCRIPTION
-The
-.Fn nanosleep
-system call
-causes the calling thread to sleep until the time interval specified by
+If the
+.Dv TIMER_ABSTIME
+flag is not set in the
+.Fa flags
+argument, then
+.Fn clock_nanosleep
+suspends execution of the calling thread until either the
+time interval specified by the
+.Fa rqtp
+argument has elapsed,
+or a signal is delivered to the calling process and its
+action is to invoke a signal-catching function or to terminate the
+process.
+The clock used to measure the time is specified by the
+.Fa clock_id
+argument.
+.Pp
+If the
+.Dv TIMER_ABSTIME
+flag is set in the
+.Fa flags
+argument, then
+.Fn clock_nanosleep
+suspends execution of the calling thread until either the value
+of the clock specified by the
+.Fa clock_id
+argument reaches the absolute time specified by the
+.Fa rqtp
+argument,
+or a signal is delivered to the calling process and its
+action is to invoke a signal-catching function or to terminate the
+process.
+If, at the time of the call, the time value specified by
.Fa rqtp
-has elapsed.
-An unmasked signal will
-cause it to terminate the sleep early, regardless of the
+is less than or equal to the time value of the specified clock, then
+.Fn clock_nanosleep
+returns immediately and the calling thread is not suspended.
+.Pp
+The suspension time may be longer than requested due to the
+scheduling of other activity by the system.
+An unmasked signal will terminate the sleep early, regardless of the
.Dv SA_RESTART
value on the interrupting signal.
-.Sh RETURN VALUES
-If the
+The
+.Fa rqtp
+and
+.Fa rmtp
+arguments can point to the same object.
+.Pp
+The following
+.Fa clock_id
+values are supported:
+.Pp
+.Bl -item -compact -offset indent
+.It
+CLOCK_MONOTONIC
+.It
+CLOCK_MONOTONIC_FAST
+.It
+CLOCK_MONOTONIC_PRECISE
+.It
+CLOCK_REALTIME
+.It
+CLOCK_REALTIME_FAST
+.It
+CLOCK_REALTIME_PRECISE
+.It
+CLOCK_SECOND
+.It
+CLOCK_UPTIME
+.It
+CLOCK_UPTIME_FAST
+.It
+CLOCK_UPTIME_PRECISE
+.El
+.Pp
+The
.Fn nanosleep
-system call returns because the requested time has elapsed, the value
-returned will be zero.
+function behaves like
+.Fn clock_nanosleep
+with a
+.Fa clock_id
+argument of
+.Dv CLOCK_REALTIME
+and without the
+.Dv TIMER_ABSTIME
+flag in the
+.Fa flags
+argument.
+.Sh RETURN VALUES
+These functions return zero when the requested time has elapsed.
.Pp
-If the
+If these functions return for any other reason, then
+.Fn clock_nanosleep
+will directly return the error number, and
.Fn nanosleep
-system call returns due to the delivery of a signal, the value returned
-will be -1, and the global variable
+will return \-1 with the global variable
.Va errno
-will be set to indicate the interruption.
-If
+set to indicate the error.
+If a relative sleep is interrupted by a signal and
.Fa rmtp
is
-.No non- Ns Dv NULL ,
+.Pf non- Dv NULL ,
the timespec structure it references is updated to contain the
unslept amount (the request time minus the time actually slept).
.Sh ERRORS
-The
-.Fn nanosleep
-system call fails if:
+These functions can fail with the following errors.
.Bl -tag -width Er
.It Bq Er EFAULT
Either
@@ -85,27 +169,32 @@ or
points to memory that is not a valid part of the process
address space.
.It Bq Er EINTR
-The
-.Fn nanosleep
-system call
-was interrupted by the delivery of a signal.
+The function was interrupted by the delivery of a signal.
.It Bq Er EINVAL
The
.Fa rqtp
-argument
-specified a nanosecond value less than zero
+argument specified a nanosecond value less than zero
or greater than or equal to 1000 million.
-.It Bq Er ENOSYS
+.It Bq Er EINVAL
The
-.Fn nanosleep
-system call
-is not supported by this implementation.
+.Fa flags
+argument contained an invalid flag.
+.It Bq Er EINVAL
+The
+.Fa clock_id
+argument was
+.Dv CLOCK_THREAD_CPUTIME_ID
+or an unrecognized value.
+.It Bq Er ENOTSUP
+The
+.Fa clock_id
+argument was valid but not supported by this implementation of
+.Fn clock_nanosleep .
.El
.Sh SEE ALSO
-.Xr sigsuspend 2 ,
+.Xr clock_gettime 2 ,
+.Xr sigaction 2 ,
.Xr sleep 3
.Sh STANDARDS
-The
-.Fn nanosleep
-system call conforms to
-.St -p1003.1b-93 .
+These functions conform to
+.St -p1003.1-2008 .
OpenPOWER on IntegriCloud