166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 566492cf0SYuri Pankov.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 2566492cf0SYuri Pankov.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 43c10c16deSRichard Lowe.\" Copyright 1989 AT&T 44c10c16deSRichard Lowe.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved 4566492cf0SYuri Pankov.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. 46dea9f5e6SRobert Mustacchi.\" Copyright 2021 Oxide Computer Company 4766492cf0SYuri Pankov.\" 48dea9f5e6SRobert Mustacchi.Dd October 3, 2021 49dea9f5e6SRobert Mustacchi.Dt CLOCK_SETTIME 3C 50dea9f5e6SRobert Mustacchi.Os 51dea9f5e6SRobert Mustacchi.Sh NAME 52dea9f5e6SRobert Mustacchi.Nm clock_settime , 53dea9f5e6SRobert Mustacchi.Nm clock_gettime , 54dea9f5e6SRobert Mustacchi.Nm clock_getres 55dea9f5e6SRobert Mustacchi.Nd high-resolution clock operations 56dea9f5e6SRobert Mustacchi.Sh SYNOPSIS 57dea9f5e6SRobert Mustacchi.In time.h 58dea9f5e6SRobert Mustacchi.Ft int 59dea9f5e6SRobert Mustacchi.Fo clock_settime 60dea9f5e6SRobert Mustacchi.Fa "clockid_t clock_id" 61dea9f5e6SRobert Mustacchi.Fa "const struct timespec *tp" 62dea9f5e6SRobert Mustacchi.Fc 63dea9f5e6SRobert Mustacchi.Ft int 64dea9f5e6SRobert Mustacchi.Fo clock_gettime 65dea9f5e6SRobert Mustacchi.Fa "clockid_t clock_id" 66dea9f5e6SRobert Mustacchi.Fa "struct timespec *tp" 67dea9f5e6SRobert Mustacchi.Fc 68dea9f5e6SRobert Mustacchi.Ft int 69dea9f5e6SRobert Mustacchi.Fo clock_getres 70dea9f5e6SRobert Mustacchi.Fa "clockid_t clock_id" 71dea9f5e6SRobert Mustacchi.Fa "struct timespec *res" 72dea9f5e6SRobert Mustacchi.Fc 73dea9f5e6SRobert Mustacchi.Sh DESCRIPTION 74dea9f5e6SRobert MustacchiThe 75dea9f5e6SRobert Mustacchi.Fn clock_settime 76dea9f5e6SRobert Mustacchifunction sets the specified clock, 77dea9f5e6SRobert Mustacchi.Fa clock_id , 78dea9f5e6SRobert Mustacchito the value specified by 79dea9f5e6SRobert Mustacchi.Fa tp . 80dea9f5e6SRobert MustacchiTime values that are between two consecutive non-negative integer multiples of 81dea9f5e6SRobert Mustacchithe resolution of the specified clock are truncated down to the smaller multiple 82dea9f5e6SRobert Mustacchiof the resolution. 83dea9f5e6SRobert Mustacchi.Pp 84dea9f5e6SRobert MustacchiThe 85dea9f5e6SRobert Mustacchi.Fn clock_gettime 86dea9f5e6SRobert Mustacchifunction returns the current value 87dea9f5e6SRobert Mustacchi.Fa tp 88dea9f5e6SRobert Mustacchifor the specified clock, 89dea9f5e6SRobert Mustacchi.Fa clock_id . 90dea9f5e6SRobert Mustacchi.Pp 91dea9f5e6SRobert MustacchiThe resolution of any clock can be obtained by calling 92dea9f5e6SRobert Mustacchi.Fn clock_getres 93dea9f5e6SRobert MustacchiClock resolutions are system-dependent and cannot be set by a process. 94dea9f5e6SRobert MustacchiIf the argument 95dea9f5e6SRobert Mustacchi.Fa res 96dea9f5e6SRobert Mustacchiis not 97dea9f5e6SRobert Mustacchi.Dv NULL , 98dea9f5e6SRobert Mustacchithe resolution of the specified clock is stored in the location pointed to by 99dea9f5e6SRobert Mustacchi.Fa res . 100dea9f5e6SRobert MustacchiIf 101dea9f5e6SRobert Mustacchi.Fa res 102dea9f5e6SRobert Mustacchiis 103dea9f5e6SRobert Mustacchi.Dv NULL , 104dea9f5e6SRobert Mustacchithe clock resolution is not returned. 105dea9f5e6SRobert MustacchiIf the time argument of 106dea9f5e6SRobert Mustacchi.Fn clock_settime 107dea9f5e6SRobert Mustacchiis not a multiple of 108dea9f5e6SRobert Mustacchi.Fa res , 109dea9f5e6SRobert Mustacchithen the value is truncated to a multiple of 110dea9f5e6SRobert Mustacchi.Fa res . 111dea9f5e6SRobert Mustacchi.Pp 112dea9f5e6SRobert MustacchiA clock may be system wide 113dea9f5e6SRobert Mustacchi.Pq that is, visible to all processes 114dea9f5e6SRobert Mustacchior per-process 115dea9f5e6SRobert Mustacchi.Pq measuring time that is meaningful only within a process . 116dea9f5e6SRobert Mustacchi.Pp 117dea9f5e6SRobert MustacchiThe following clocks are supported in the system and defined by 118dea9f5e6SRobert Mustacchiincluding 119dea9f5e6SRobert Mustacchi.In time.h : 120dea9f5e6SRobert Mustacchi.Bl -tag -width Ds 121dea9f5e6SRobert Mustacchi.It Dv CLOCK_REALTIME 122dea9f5e6SRobert MustacchiThis clock represents the realtime clock for the system. 123dea9f5e6SRobert MustacchiFor this clock, the values returned by 124dea9f5e6SRobert Mustacchi.Fn clock_gettime 125dea9f5e6SRobert Mustacchiand specified by 126dea9f5e6SRobert Mustacchi.Fn clock_settime 127dea9f5e6SRobert Mustacchirepresent the amount of time 128dea9f5e6SRobert Mustacchi.Pq in seconds and nanoseconds 129dea9f5e6SRobert Mustacchisince the Epoch. 130dea9f5e6SRobert Mustacchi.It Dv CLOCK_HIGHRES 131dea9f5e6SRobert MustacchiThis clock represents the non-adjustable, high-resolution clock for the system. 132dea9f5e6SRobert MustacchiFor this clock, the value returned by 133dea9f5e6SRobert Mustacchi.Fn clock_gettime 134dea9f5e6SRobert Mustacchirepresents the amount of time (in seconds and nanoseconds) since some arbitrary 135dea9f5e6SRobert Mustacchitime in the past; it is not correlated in any way to the time of day, and thus 136dea9f5e6SRobert Mustacchiis not subject to resetting or drifting by way of 137dea9f5e6SRobert Mustacchi.Xr adjtime 2 , 138*bbf21555SRichard Lowe.Xr ntp_adjtime 2 , 139dea9f5e6SRobert Mustacchi.Xr settimeofday 3C , 140dea9f5e6SRobert Mustacchior 141dea9f5e6SRobert Mustacchi.Fn clock_settime . 142dea9f5e6SRobert MustacchiThe time source for this clock is the same as that for 143dea9f5e6SRobert Mustacchi.Xr gethrtime 3C . 144dea9f5e6SRobert Mustacchi.Pp 145dea9f5e6SRobert MustacchiIt is not possible to set this clock with 146dea9f5e6SRobert Mustacchi.Fn clock_settime . 147dea9f5e6SRobert Mustacchi.Pp 148dea9f5e6SRobert Mustacchi.Dv CLOCK_MONOTONIC 149dea9f5e6SRobert Mustacchiis an alias for this clock. 150dea9f5e6SRobert MustacchiOther systems define a 151dea9f5e6SRobert Mustacchi.Dv CLOCK_MONOTONIC_RAW 152dea9f5e6SRobert Mustacchifor a high-resolution clock which is not subject to adjustments. 153dea9f5e6SRobert Mustacchi.Dv CLOCK_HIGHRES 154dea9f5e6SRobert Mustacchiis not subject to time of day adjustments and thus can always be safely 155dea9f5e6SRobert Mustacchiused here. 156dea9f5e6SRobert Mustacchi.It Dv CLOCK_VIRTUAL 157dea9f5e6SRobert MustacchiThis clock represents the amount of CPU-time 158dea9f5e6SRobert Mustacchi.Pq in seconds and nanoseconds 159dea9f5e6SRobert Mustacchithat the calling thread has spent executing user code. 160dea9f5e6SRobert MustacchiThis is the same as the 161dea9f5e6SRobert Mustacchi.Fa pr_utime 162dea9f5e6SRobert Mustacchimember of the 163dea9f5e6SRobert Mustacchi.Vt prusage_t 164dea9f5e6SRobert Mustacchiand 165dea9f5e6SRobert Mustacchi.Fa pr_utime 166dea9f5e6SRobert Mustacchimember of the 167dea9f5e6SRobert Mustacchi.Vt lwpsinfo_t 168dea9f5e6SRobert Mustacchistructure discussed in 169*bbf21555SRichard Lowe.Xr proc 5 . 170dea9f5e6SRobert Mustacchi.Pp 171dea9f5e6SRobert MustacchiThis clock cannot be set with 172dea9f5e6SRobert Mustacchi.Fn clock_settime 173dea9f5e6SRobert Mustacchiand has the same source as 174dea9f5e6SRobert Mustacchi.Xr gethrvtime 3C . 175dea9f5e6SRobert Mustacchi.It Dv CLOCK_THREAD_CPUTIME_ID 176dea9f5e6SRobert MustacchiThis clock is similar to 177dea9f5e6SRobert Mustacchi.Dv CLOCK_VIRTUAL ; 178dea9f5e6SRobert Mustacchihowever, it also includes the system time of the calling thread in 179dea9f5e6SRobert Mustacchiaddition to the user time. 180dea9f5e6SRobert Mustacchi.Pp 181dea9f5e6SRobert MustacchiThe system time is the same that is seen in the 182dea9f5e6SRobert Mustacchi.Fa pr_stime 183dea9f5e6SRobert Mustacchimember of the 184dea9f5e6SRobert Mustacchi.Vt lwpsinfo_t 185dea9f5e6SRobert Mustacchistructure discussed in 186*bbf21555SRichard Lowe.Xr proc 5 . 187dea9f5e6SRobert MustacchiSystem time includes both the system and trap microstates, 188dea9f5e6SRobert Mustacchi.Fa pr_stime 189dea9f5e6SRobert Mustacchiand 190dea9f5e6SRobert Mustacchi.Fa pr_ttime 191dea9f5e6SRobert Mustacchiof the 192dea9f5e6SRobert Mustacchi.Vt prusage_t 193dea9f5e6SRobert Mustacchistructure respectively. 194dea9f5e6SRobert Mustacchi.Pp 195dea9f5e6SRobert MustacchiThis clock cannot be set with 196dea9f5e6SRobert Mustacchi.Fn clock_settime 197dea9f5e6SRobert Mustacchiand it has an alias of 198dea9f5e6SRobert Mustacchi.Dv CLOCK_PROF . 199dea9f5e6SRobert Mustacchi.It Dv ClOCK_PROCESS_CPUTIME_ID 200dea9f5e6SRobert MustacchiThis clock represents the total CPU-time that the process 201dea9f5e6SRobert Mustacchi.Pq but not children 202dea9f5e6SRobert Mustacchihas spent in both user and system time for the calling process. 203dea9f5e6SRobert MustacchiThis is equivalent to the combination of the 204dea9f5e6SRobert Mustacchi.Fa pr_utime 205dea9f5e6SRobert Mustacchiand 206dea9f5e6SRobert Mustacchi.Fa pr_stime 207dea9f5e6SRobert Mustacchimembers of the 208dea9f5e6SRobert Mustacchi.Vt psinfo_t 209dea9f5e6SRobert Mustacchistructure documented in 210*bbf21555SRichard Lowe.Xr proc 5 . 211dea9f5e6SRobert Mustacchi.Pp 212dea9f5e6SRobert MustacchiThis clock is not settable with 213dea9f5e6SRobert Mustacchi.Fn clock_settime . 214dea9f5e6SRobert Mustacchi.El 215dea9f5e6SRobert Mustacchi.Sh RETURN VALUES 216dea9f5e6SRobert MustacchiUpon successful completion, 217dea9f5e6SRobert Mustacchi.Sy 0 218dea9f5e6SRobert Mustacchiis returned. 219dea9f5e6SRobert MustacchiOtherwise, 220dea9f5e6SRobert Mustacchi.Sy -1 221dea9f5e6SRobert Mustacchiis returned and 222dea9f5e6SRobert Mustacchi.Va errno 223dea9f5e6SRobert Mustacchiis set to indicate the error. 224dea9f5e6SRobert Mustacchi.Sh ERRORS 225dea9f5e6SRobert MustacchiThe 226dea9f5e6SRobert Mustacchi.Fn clock_settime , 227dea9f5e6SRobert Mustacchi.Fn clock_gettime , 228dea9f5e6SRobert Mustacchiand 229dea9f5e6SRobert Mustacchi.Fn clock_getres 230c10c16deSRichard Lowefunctions will fail if: 231dea9f5e6SRobert Mustacchi.Bl -tag -width Er 232dea9f5e6SRobert Mustacchi.It Er EINVAL 233dea9f5e6SRobert MustacchiThe 234dea9f5e6SRobert Mustacchi.Fa clock_id 235dea9f5e6SRobert Mustacchiargument does not specify a known clock. 236dea9f5e6SRobert Mustacchi.It Er ENOSYS 237dea9f5e6SRobert MustacchiThe functions 238dea9f5e6SRobert Mustacchi.Fn \fBclock_settime , 239dea9f5e6SRobert Mustacchi.Fn \fBclock_gettime , 240dea9f5e6SRobert Mustacchiand 241dea9f5e6SRobert Mustacchi.Fn clock_getres 242dea9f5e6SRobert Mustacchiare not supported by this implementation. 243dea9f5e6SRobert MustacchiNote, this error should not occur here. 244dea9f5e6SRobert Mustacchi.El 245dea9f5e6SRobert Mustacchi.Pp 246dea9f5e6SRobert MustacchiThe 247dea9f5e6SRobert Mustacchi.Fn clock_settime 248dea9f5e6SRobert Mustacchifunction will fail if: 249dea9f5e6SRobert Mustacchi.Bl -tag -width Er 250dea9f5e6SRobert Mustacchi.It Er EINVAL 251dea9f5e6SRobert MustacchiThe 252dea9f5e6SRobert Mustacchi.Fa tp 253dea9f5e6SRobert Mustacchiargument is outside the range for the given clock ID; or the 254dea9f5e6SRobert Mustacchi.Fa tp 255dea9f5e6SRobert Mustacchiargument specified a nanosecond value less than zero or greater than or 256dea9f5e6SRobert Mustacchiequal to 1000 million. 257dea9f5e6SRobert Mustacchi.Pp 258dea9f5e6SRobert MustacchiThe clock specified by 259dea9f5e6SRobert Mustacchi.Fa clock_id 260dea9f5e6SRobert Mustacchidoes not support being set. 261dea9f5e6SRobert Mustacchi.El 262dea9f5e6SRobert Mustacchi.Pp 263dea9f5e6SRobert MustacchiThe 264dea9f5e6SRobert Mustacchi.Fn clock_settime 265dea9f5e6SRobert Mustacchifunction may fail if: 266dea9f5e6SRobert Mustacchi.Bl -tag -width Er 267dea9f5e6SRobert Mustacchi.It Er EPERM 268c10c16deSRichard LoweThe requesting process does not have the appropriate privilege to set the 269c10c16deSRichard Lowespecified clock. 270dea9f5e6SRobert Mustacchi.El 271dea9f5e6SRobert Mustacchi.Sh INTERFACE STABILITY 272dea9f5e6SRobert Mustacchi.Sy Committed 273dea9f5e6SRobert Mustacchi.Sh MT-LEVEL 274dea9f5e6SRobert Mustacchi.Fn clock_gettime 275dea9f5e6SRobert Mustacchiis 276dea9f5e6SRobert Mustacchi.Sy Async-Signal-Safe 277dea9f5e6SRobert Mustacchi.Sh SEE ALSO 278dea9f5e6SRobert Mustacchi.Xr adjtime 2 , 279dea9f5e6SRobert Mustacchi.Xr ntp_adjtime 2 , 280dea9f5e6SRobert Mustacchi.Xr time 2 , 281dea9f5e6SRobert Mustacchi.Xr ctime 3C , 282dea9f5e6SRobert Mustacchi.Xr gethrtime 3C , 283dea9f5e6SRobert Mustacchi.Xr gethrvtime 3C , 284dea9f5e6SRobert Mustacchi.Xr settimeofday 3C , 285dea9f5e6SRobert Mustacchi.Xr timer_gettime 3C , 286dea9f5e6SRobert Mustacchi.Xr time.h 3HEAD , 287*bbf21555SRichard Lowe.Xr proc 5 288