blob: f250feab670256f28fa494639dca342594a6199c [file] [log] [blame]
Willy Tarreau55542642021-10-08 09:33:24 +02001/*
2 * General time-keeping code and variables
3 *
4 * Copyright 2000-2021 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <sys/time.h>
Willy Tarreau6cb0c392021-10-08 14:48:30 +020014#include <signal.h>
Willy Tarreau55542642021-10-08 09:33:24 +020015#include <time.h>
16
Willy Tarreau44c58da2021-10-08 12:27:54 +020017#ifdef USE_THREAD
18#include <pthread.h>
19#endif
20
Willy Tarreau55542642021-10-08 09:33:24 +020021#include <haproxy/api.h>
Willy Tarreauf9d5e102021-10-08 10:43:59 +020022#include <haproxy/activity.h>
Willy Tarreau55542642021-10-08 09:33:24 +020023#include <haproxy/clock.h>
Willy Tarreau6cb0c392021-10-08 14:48:30 +020024#include <haproxy/signal-t.h>
Willy Tarreau55542642021-10-08 09:33:24 +020025#include <haproxy/time.h>
26#include <haproxy/tinfo-t.h>
27#include <haproxy/tools.h>
28
29struct timeval start_date; /* the process's start date in wall-clock time */
Willy Tarreau6093ba42023-02-07 15:52:14 +010030struct timeval start_time; /* the process's start date in internal monotonic time */
Willy Tarreau55542642021-10-08 09:33:24 +020031volatile ullong global_now; /* common monotonic date between all threads (32:32) */
32volatile uint global_now_ms; /* common monotonic date in milliseconds (may wrap) */
33
34THREAD_ALIGNED(64) static ullong now_offset; /* global offset between system time and global time */
35
36THREAD_LOCAL uint now_ms; /* internal monotonic date in milliseconds (may wrap) */
37THREAD_LOCAL struct timeval now; /* internal monotonic date derived from real clock */
38THREAD_LOCAL struct timeval date; /* the real current date (wall-clock time) */
Willy Tarreau55542642021-10-08 09:33:24 +020039
Willy Tarreau2c6a9982021-10-08 11:38:30 +020040static THREAD_LOCAL struct timeval before_poll; /* system date before calling poll() */
41static THREAD_LOCAL struct timeval after_poll; /* system date after leaving poll() */
Willy Tarreauf9d5e102021-10-08 10:43:59 +020042static THREAD_LOCAL unsigned int samp_time; /* total elapsed time over current sample */
43static THREAD_LOCAL unsigned int idle_time; /* total idle time over current sample */
Willy Tarreau55542642021-10-08 09:33:24 +020044static THREAD_LOCAL unsigned int iso_time_sec; /* last iso time value for this thread */
45static THREAD_LOCAL char iso_time_str[34]; /* ISO time representation of gettimeofday() */
46
Willy Tarreau21694982021-10-08 15:09:17 +020047#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
48static clockid_t per_thread_clock_id[MAX_THREADS];
49#endif
50
Willy Tarreau55542642021-10-08 09:33:24 +020051/* returns the system's monotonic time in nanoseconds if supported, otherwise zero */
52uint64_t now_mono_time(void)
53{
54 uint64_t ret = 0;
Willy Tarreau6cb0c392021-10-08 14:48:30 +020055#if defined(_POSIX_TIMERS) && defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK)
Willy Tarreau55542642021-10-08 09:33:24 +020056 struct timespec ts;
57 clock_gettime(CLOCK_MONOTONIC, &ts);
58 ret = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
59#endif
60 return ret;
61}
62
Aurelien DARRAGON07cbd8e2022-11-25 08:56:46 +010063/* Returns the system's monotonic time in nanoseconds.
64 * Uses the coarse clock source if supported (for fast but
65 * less precise queries with limited resource usage).
66 * Fallback to now_mono_time() if coarse source is not supported,
67 * which may itself return 0 if not supported either.
68 */
69uint64_t now_mono_time_fast(void)
70{
71#if defined(CLOCK_MONOTONIC_COARSE)
72 struct timespec ts;
73
74 clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
75 return (ts.tv_sec * 1000000000ULL + ts.tv_nsec);
76#else
77 /* fallback to regular mono time,
78 * returns 0 if not supported
79 */
80 return now_mono_time();
81#endif
82}
83
Willy Tarreau55542642021-10-08 09:33:24 +020084/* returns the current thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
85uint64_t now_cpu_time(void)
86{
87 uint64_t ret = 0;
88#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
89 struct timespec ts;
90 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
91 ret = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
92#endif
93 return ret;
94}
95
Aurelien DARRAGONdf188f12023-04-04 17:21:40 +020096/* Returns the current thread's cumulated CPU time in nanoseconds.
97 *
98 * thread_local timer is cached so that call is less precise but also less
99 * expensive if heavily used.
100 * We use the mono time as a cache expiration hint since now_cpu_time() is
101 * known to be much more expensive than now_mono_time_fast() on systems
102 * supporting the COARSE clock source.
103 *
104 * Returns 0 if either now_mono_time_fast() or now_cpu_time() are not
105 * supported.
106 */
107uint64_t now_cpu_time_fast(void)
108{
109 static THREAD_LOCAL uint64_t mono_cache = 0;
110 static THREAD_LOCAL uint64_t cpu_cache = 0;
111 uint64_t mono_cur;
112
113 mono_cur = now_mono_time_fast();
114 if (unlikely(mono_cur != mono_cache)) {
115 /* global mono clock was updated: local cache is outdated */
116 cpu_cache = now_cpu_time();
117 mono_cache = mono_cur;
118 }
119 return cpu_cache;
120}
121
Willy Tarreau55542642021-10-08 09:33:24 +0200122/* returns another thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
Willy Tarreau21694982021-10-08 15:09:17 +0200123uint64_t now_cpu_time_thread(int thr)
Willy Tarreau55542642021-10-08 09:33:24 +0200124{
125 uint64_t ret = 0;
126#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
127 struct timespec ts;
Willy Tarreau21694982021-10-08 15:09:17 +0200128 clock_gettime(per_thread_clock_id[thr], &ts);
Willy Tarreau55542642021-10-08 09:33:24 +0200129 ret = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
130#endif
131 return ret;
132}
133
Willy Tarreau44c58da2021-10-08 12:27:54 +0200134/* set the clock source for the local thread */
135void clock_set_local_source(void)
136{
137#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
138#ifdef USE_THREAD
Willy Tarreau21694982021-10-08 15:09:17 +0200139 pthread_getcpuclockid(pthread_self(), &per_thread_clock_id[tid]);
Willy Tarreau44c58da2021-10-08 12:27:54 +0200140#else
Willy Tarreau21694982021-10-08 15:09:17 +0200141 per_thread_clock_id[tid] = CLOCK_THREAD_CPUTIME_ID;
Willy Tarreau44c58da2021-10-08 12:27:54 +0200142#endif
143#endif
144}
145
Willy Tarreau6cb0c392021-10-08 14:48:30 +0200146/* registers a timer <tmr> of type timer_t delivering signal <sig> with value
147 * <val>. It tries on the current thread's clock ID first and falls back to
148 * CLOCK_REALTIME. Returns non-zero on success, 1 on failure.
149 */
150int clock_setup_signal_timer(void *tmr, int sig, int val)
151{
152 int ret = 0;
153
154#if defined(USE_RT) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
155 struct sigevent sev = { };
156 timer_t *timer = tmr;
157 sigset_t set;
158
159 /* unblock the WDTSIG signal we intend to use */
160 sigemptyset(&set);
161 sigaddset(&set, WDTSIG);
162 ha_sigmask(SIG_UNBLOCK, &set, NULL);
163
164 /* this timer will signal WDTSIG when it fires, with tid in the si_int
165 * field (important since any thread will receive the signal).
166 */
167 sev.sigev_notify = SIGEV_SIGNAL;
168 sev.sigev_signo = sig;
169 sev.sigev_value.sival_int = val;
Willy Tarreau21694982021-10-08 15:09:17 +0200170 if (timer_create(per_thread_clock_id[tid], &sev, timer) != -1 ||
Willy Tarreau6cb0c392021-10-08 14:48:30 +0200171 timer_create(CLOCK_REALTIME, &sev, timer) != -1)
172 ret = 1;
173#endif
174 return ret;
175}
176
Willy Tarreau55542642021-10-08 09:33:24 +0200177/* clock_update_date: sets <date> to system time, and sets <now> to something as
178 * close as possible to real time, following a monotonic function. The main
179 * principle consists in detecting backwards and forwards time jumps and adjust
180 * an offset to correct them. This function should be called once after each
181 * poll, and never farther apart than MAX_DELAY_MS*2. The poll's timeout should
182 * be passed in <max_wait>, and the return value in <interrupted> (a non-zero
183 * value means that we have not expired the timeout).
184 *
185 * clock_init_process_date() must have been called once first, and
186 * clock_init_thread_date() must also have been called once for each thread.
187 *
188 * An offset is used to adjust the current time (date), to figure a monotonic
189 * local time (now). The offset is not critical, as it is only updated after a
190 * clock jump is detected. From this point all threads will apply it to their
191 * locally measured time, and will then agree around a common monotonic
192 * global_now value that serves to further refine their local time. As it is
193 * not possible to atomically update a timeval, both global_now and the
194 * now_offset values are instead stored as 64-bit integers made of two 32 bit
195 * values for the tv_sec and tv_usec parts. The offset is made of two signed
196 * ints so that the clock can be adjusted in the two directions.
197 */
Willy Tarreaua7004202022-09-21 07:37:27 +0200198void clock_update_local_date(int max_wait, int interrupted)
Willy Tarreau55542642021-10-08 09:33:24 +0200199{
Willy Tarreaua7004202022-09-21 07:37:27 +0200200 struct timeval min_deadline, max_deadline;
201 ullong ofs;
Willy Tarreau55542642021-10-08 09:33:24 +0200202
203 gettimeofday(&date, NULL);
204
205 /* compute the minimum and maximum local date we may have reached based
206 * on our past date and the associated timeout. There are three possible
207 * extremities:
208 * - the new date cannot be older than before_poll
209 * - if not interrupted, the new date cannot be older than
210 * before_poll+max_wait
211 * - in any case the new date cannot be newer than
212 * before_poll+max_wait+some margin (100ms used here).
213 * In case of violation, we'll ignore the current date and instead
214 * restart from the last date we knew.
215 */
216 _tv_ms_add(&min_deadline, &before_poll, max_wait);
217 _tv_ms_add(&max_deadline, &before_poll, max_wait + 100);
218
219 ofs = HA_ATOMIC_LOAD(&now_offset);
220
221 if (unlikely(__tv_islt(&date, &before_poll) || // big jump backwards
222 (!interrupted && __tv_islt(&date, &min_deadline)) || // small jump backwards
223 __tv_islt(&max_deadline, &date))) { // big jump forwards
224 if (!interrupted)
225 _tv_ms_add(&now, &now, max_wait);
226 } else {
227 /* The date is still within expectations. Let's apply the
228 * now_offset to the system date. Note: ofs if made of two
229 * independent signed ints.
230 */
231 now.tv_sec = date.tv_sec + (int)(ofs >> 32); // note: may be positive or negative
232 now.tv_usec = date.tv_usec + (int)ofs; // note: may be positive or negative
233 if ((int)now.tv_usec < 0) {
234 now.tv_usec += 1000000;
235 now.tv_sec -= 1;
236 } else if (now.tv_usec >= 1000000) {
237 now.tv_usec -= 1000000;
238 now.tv_sec += 1;
239 }
240 }
Willy Tarreaua7004202022-09-21 07:37:27 +0200241 now_ms = __tv_to_ms(&now);
242}
243
244void clock_update_global_date()
245{
246 struct timeval tmp_now;
247 uint old_now_ms;
248 ullong old_now;
249 ullong new_now;
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200250 ullong ofs_new;
Willy Tarreaua7004202022-09-21 07:37:27 +0200251 uint sec_ofs, usec_ofs;
252
Willy Tarreau55542642021-10-08 09:33:24 +0200253 /* now that we have bounded the local time, let's check if it's
254 * realistic regarding the global date, which only moves forward,
255 * otherwise catch up.
256 */
257 old_now = global_now;
258 old_now_ms = global_now_ms;
259
260 do {
261 tmp_now.tv_sec = (unsigned int)(old_now >> 32);
262 tmp_now.tv_usec = old_now & 0xFFFFFFFFU;
263
264 if (__tv_islt(&now, &tmp_now))
265 now = tmp_now;
266
267 /* now <now> is expected to be the most accurate date,
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200268 * equal to <global_now> or newer. Updating the global
269 * date too often causes extreme contention and is not
270 * needed: it's only used to help threads run at the
271 * same date in case of local drift, and the global date,
272 * which changes, is only used by freq counters (a choice
273 * which is debatable by the way since it changes under us).
274 * Tests have seen that the contention can be reduced from
275 * 37% in this function to almost 0% when keeping clocks
276 * synchronized no better than 32 microseconds, so that's
277 * what we're doing here.
Willy Tarreau55542642021-10-08 09:33:24 +0200278 */
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200279
Willy Tarreau55542642021-10-08 09:33:24 +0200280 new_now = ((ullong)now.tv_sec << 32) + (uint)now.tv_usec;
281 now_ms = __tv_to_ms(&now);
282
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200283 if (!((new_now ^ old_now) & ~0x1FULL))
284 return;
285
Willy Tarreau55542642021-10-08 09:33:24 +0200286 /* let's try to update the global <now> (both in timeval
287 * and ms forms) or loop again.
288 */
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200289 } while ((!_HA_ATOMIC_CAS(&global_now, &old_now, new_now) ||
Willy Tarreau55542642021-10-08 09:33:24 +0200290 (now_ms != old_now_ms && !_HA_ATOMIC_CAS(&global_now_ms, &old_now_ms, now_ms))) &&
291 __ha_cpu_relax());
292
293 /* <now> and <now_ms> are now updated to the last value of global_now
294 * and global_now_ms, which were also monotonically updated. We can
295 * compute the latest offset, we don't care who writes it last, the
296 * variations will not break the monotonic property.
297 */
298
299 sec_ofs = now.tv_sec - date.tv_sec;
300 usec_ofs = now.tv_usec - date.tv_usec;
301 if ((int)usec_ofs < 0) {
302 usec_ofs += 1000000;
303 sec_ofs -= 1;
304 }
305 ofs_new = ((ullong)sec_ofs << 32) + usec_ofs;
Willy Tarreau4eaf85f2022-09-21 08:21:45 +0200306 HA_ATOMIC_STORE(&now_offset, ofs_new);
Willy Tarreau55542642021-10-08 09:33:24 +0200307}
308
309/* must be called once at boot to initialize some global variables */
310void clock_init_process_date(void)
311{
312 now_offset = 0;
313 gettimeofday(&date, NULL);
314 now = after_poll = before_poll = date;
315 global_now = ((ullong)date.tv_sec << 32) + (uint)date.tv_usec;
316 global_now_ms = now.tv_sec * 1000 + now.tv_usec / 1000;
Willy Tarreau28360dc2023-02-07 14:44:44 +0100317
318 /* force time to wrap 20s after boot: we first compute the time offset
319 * that once applied to the wall-clock date will make the local time
320 * wrap in 5 seconds. This offset is applied to the process-wide time,
321 * and will be used to recompute the local time, both of which will
322 * match and continue from this shifted date.
323 */
324 now_offset = (uint64_t)(-(global_now_ms / 1000U) - BOOT_TIME_WRAP_SEC) << 32;
325 global_now += now_offset;
326
Willy Tarreau45c38e22021-09-30 18:28:49 +0200327 th_ctx->idle_pct = 100;
Willy Tarreau55542642021-10-08 09:33:24 +0200328 clock_update_date(0, 1);
329}
330
331/* must be called once per thread to initialize their thread-local variables.
332 * Note that other threads might also be initializing and running in parallel.
333 */
334void clock_init_thread_date(void)
335{
336 ullong old_now;
337
338 gettimeofday(&date, NULL);
339 after_poll = before_poll = date;
340
341 old_now = _HA_ATOMIC_LOAD(&global_now);
342 now.tv_sec = old_now >> 32;
343 now.tv_usec = (uint)old_now;
Willy Tarreau45c38e22021-09-30 18:28:49 +0200344 th_ctx->idle_pct = 100;
Aurelien DARRAGON16d6c0c2022-11-10 11:47:47 +0100345 th_ctx->prev_cpu_time = now_cpu_time();
Willy Tarreau55542642021-10-08 09:33:24 +0200346 clock_update_date(0, 1);
347}
348
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200349/* report the average CPU idle percentage over all running threads, between 0 and 100 */
350uint clock_report_idle(void)
351{
352 uint total = 0;
353 uint rthr = 0;
354 uint thr;
355
356 for (thr = 0; thr < MAX_THREADS; thr++) {
Willy Tarreau1e7f0d62022-06-27 16:22:22 +0200357 if (!ha_thread_info[thr].tg ||
358 !(ha_thread_info[thr].tg->threads_enabled & ha_thread_info[thr].ltid_bit))
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200359 continue;
Willy Tarreau45c38e22021-09-30 18:28:49 +0200360 total += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].idle_pct);
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200361 rthr++;
362 }
363 return rthr ? total / rthr : 0;
364}
365
366/* Update the idle time value twice a second, to be called after
367 * clock_update_date() when called after poll(), and currently called only by
368 * clock_leaving_poll() below. It relies on <before_poll> to be updated to
369 * the system time before calling poll().
370 */
371static inline void clock_measure_idle(void)
372{
373 /* Let's compute the idle to work ratio. We worked between after_poll
374 * and before_poll, and slept between before_poll and date. The idle_pct
375 * is updated at most twice every second. Note that the current second
376 * rarely changes so we avoid a multiply when not needed.
377 */
378 int delta;
379
380 if ((delta = date.tv_sec - before_poll.tv_sec))
381 delta *= 1000000;
382 idle_time += delta + (date.tv_usec - before_poll.tv_usec);
383
384 if ((delta = date.tv_sec - after_poll.tv_sec))
385 delta *= 1000000;
386 samp_time += delta + (date.tv_usec - after_poll.tv_usec);
387
388 after_poll.tv_sec = date.tv_sec; after_poll.tv_usec = date.tv_usec;
389 if (samp_time < 500000)
390 return;
391
Willy Tarreau45c38e22021-09-30 18:28:49 +0200392 HA_ATOMIC_STORE(&th_ctx->idle_pct, (100ULL * idle_time + samp_time / 2) / samp_time);
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200393 idle_time = samp_time = 0;
394}
395
396/* Collect date and time information after leaving poll(). <timeout> must be
397 * set to the maximum sleep time passed to poll (in milliseconds), and
398 * <interrupted> must be zero if the poller reached the timeout or non-zero
399 * otherwise, which generally is provided by the poller's return value.
400 */
401void clock_leaving_poll(int timeout, int interrupted)
402{
403 clock_measure_idle();
Willy Tarreau45c38e22021-09-30 18:28:49 +0200404 th_ctx->prev_cpu_time = now_cpu_time();
405 th_ctx->prev_mono_time = now_mono_time();
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200406}
407
408/* Collect date and time information before calling poll(). This will be used
409 * to count the run time of the past loop and the sleep time of the next poll.
Ilya Shipitsin4a689da2022-10-29 09:34:32 +0500410 * It also compares the elapsed and cpu times during the activity period to
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200411 * estimate the amount of stolen time, which is reported if higher than half
412 * a millisecond.
413 */
414void clock_entering_poll(void)
415{
416 uint64_t new_mono_time;
417 uint64_t new_cpu_time;
Willy Tarreau20adfde2021-10-08 11:34:46 +0200418 uint32_t run_time;
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200419 int64_t stolen;
420
421 gettimeofday(&before_poll, NULL);
422
Willy Tarreau20adfde2021-10-08 11:34:46 +0200423 run_time = (before_poll.tv_sec - after_poll.tv_sec) * 1000000U + (before_poll.tv_usec - after_poll.tv_usec);
424
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200425 new_cpu_time = now_cpu_time();
426 new_mono_time = now_mono_time();
427
Willy Tarreau45c38e22021-09-30 18:28:49 +0200428 if (th_ctx->prev_cpu_time && th_ctx->prev_mono_time) {
429 new_cpu_time -= th_ctx->prev_cpu_time;
430 new_mono_time -= th_ctx->prev_mono_time;
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200431 stolen = new_mono_time - new_cpu_time;
432 if (unlikely(stolen >= 500000)) {
433 stolen /= 500000;
434 /* more than half a millisecond difference might
435 * indicate an undesired preemption.
436 */
437 report_stolen_time(stolen);
438 }
439 }
Willy Tarreau20adfde2021-10-08 11:34:46 +0200440
441 /* update the average runtime */
442 activity_count_runtime(run_time);
Willy Tarreauf9d5e102021-10-08 10:43:59 +0200443}
444
Willy Tarreau55542642021-10-08 09:33:24 +0200445/* returns the current date as returned by gettimeofday() in ISO+microsecond
446 * format. It uses a thread-local static variable that the reader can consume
447 * for as long as it wants until next call. Thus, do not call it from a signal
448 * handler. If <pad> is non-0, a trailing space will be added. It will always
449 * return exactly 32 or 33 characters (depending on padding) and will always be
450 * zero-terminated, thus it will always fit into a 34 bytes buffer.
451 * This also always include the local timezone (in +/-HH:mm format) .
452 */
453char *timeofday_as_iso_us(int pad)
454{
455 struct timeval new_date;
456 struct tm tm;
457 const char *offset;
458 char c;
459
460 gettimeofday(&new_date, NULL);
461 if (new_date.tv_sec != iso_time_sec || !new_date.tv_sec) {
462 get_localtime(new_date.tv_sec, &tm);
463 offset = get_gmt_offset(new_date.tv_sec, &tm);
464 if (unlikely(strftime(iso_time_str, sizeof(iso_time_str), "%Y-%m-%dT%H:%M:%S.000000+00:00", &tm) != 32))
Willy Tarreaufc458ec2023-04-07 18:11:39 +0200465 strlcpy2(iso_time_str, "YYYY-mm-ddTHH:MM:SS.000000-00:00", sizeof(iso_time_str)); // make the failure visible but respect format.
Willy Tarreau55542642021-10-08 09:33:24 +0200466 iso_time_str[26] = offset[0];
467 iso_time_str[27] = offset[1];
468 iso_time_str[28] = offset[2];
469 iso_time_str[30] = offset[3];
470 iso_time_str[31] = offset[4];
471 iso_time_sec = new_date.tv_sec;
472 }
473
474 /* utoa_pad adds a trailing 0 so we save the char for restore */
475 c = iso_time_str[26];
476 utoa_pad(new_date.tv_usec, iso_time_str + 20, 7);
477 iso_time_str[26] = c;
478 if (pad) {
479 iso_time_str[32] = ' ';
480 iso_time_str[33] = 0;
481 }
482 return iso_time_str;
483}