Changes for 4.5.0 snapshot
[newlib-cygwin.git] / libgloss / arc / hl / hl_clock.c
blobb71267296ad573b991a9662121e0b1afada1f7ce
1 /*
2 * hl_clock.c -- provide _clock() and _times().
4 * Copyright (c) 2024 Synopsys Inc.
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
18 #include <errno.h>
19 #include <stdint.h>
20 #include <time.h>
21 #include <sys/times.h>
23 #include "../arc-timer.h"
25 #include "hl_toolchain.h"
26 #include "hl_api.h"
28 /* Implements HL_SYSCALL_CLOCK. */
29 static __always_inline clock_t
30 _hl_clock (void)
32 uint32_t ret;
33 volatile __uncached char *p;
35 p = _hl_message (HL_SYSCALL_CLOCK, ":i", (uint32_t *) &ret);
37 _hl_delete ();
39 if (p == NULL)
41 errno = ETIMEDOUT;
42 return -1;
45 return ret;
49 * This implementation returns timer 0 value if it exists or
50 * host clock() value converted to target clocks.
52 * Please note that this value cannot be converted to seconds
53 * using CLOCKS_PER_SEC.
55 clock_t
56 _clock (void)
58 if (_arc_timer_default_present ())
59 return _arc_timer_default_read ();
60 else
61 return _hl_clock ();
64 /* All time is counted as user time. */
65 clock_t
66 _times (struct tms *tp)
68 clock_t ret;
70 if (tp == NULL)
72 errno = EFAULT;
73 return -1;
76 ret = _clock ();
78 if (ret == (clock_t) -1)
79 return ret;
81 tp->tms_utime = ret;
82 tp->tms_stime = 0;
83 tp->tms_cutime = 0;
84 tp->tms_cstime = 0;
86 return ret;