jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / helper / time_support.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /***************************************************************************
4 * Copyright (C) 2006 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
6 * *
7 * Copyright (C) 2007,2008 Øyvind Harboe *
8 * oyvind.harboe@zylin.com *
9 * *
10 * Copyright (C) 2008 by Spencer Oliver *
11 * spen@spen-soft.co.uk *
12 ***************************************************************************/
13
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17
18 #include "time_support.h"
19
20 /* calculate difference between two struct timeval values */
21 int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
22 {
23 if (x->tv_usec < y->tv_usec) {
24 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
25 y->tv_usec -= 1000000 * nsec;
26 y->tv_sec += nsec;
27 }
28 if (x->tv_usec - y->tv_usec > 1000000) {
29 int nsec = (x->tv_usec - y->tv_usec) / 1000000;
30 y->tv_usec += 1000000 * nsec;
31 y->tv_sec -= nsec;
32 }
33
34 result->tv_sec = x->tv_sec - y->tv_sec;
35 result->tv_usec = x->tv_usec - y->tv_usec;
36
37 /* Return 1 if result is negative. */
38 return x->tv_sec < y->tv_sec;
39 }
40
41 int timeval_add_time(struct timeval *result, long sec, long usec)
42 {
43 result->tv_sec += sec;
44 result->tv_usec += usec;
45
46 while (result->tv_usec > 1000000) {
47 result->tv_usec -= 1000000;
48 result->tv_sec++;
49 }
50
51 return 0;
52 }
53
54 /* compare two timevals and return -1/0/+1 accordingly */
55 int timeval_compare(const struct timeval *x, const struct timeval *y)
56 {
57 if (x->tv_sec < y->tv_sec)
58 return -1;
59 else if (x->tv_sec > y->tv_sec)
60 return 1;
61 else if (x->tv_usec < y->tv_usec)
62 return -1;
63 else if (x->tv_usec > y->tv_usec)
64 return 1;
65 else
66 return 0;
67 }
68
69 int duration_start(struct duration *duration)
70 {
71 return gettimeofday(&duration->start, NULL);
72 }
73
74 int duration_measure(struct duration *duration)
75 {
76 struct timeval end;
77 int retval = gettimeofday(&end, NULL);
78 if (retval == 0)
79 timeval_subtract(&duration->elapsed, &end, &duration->start);
80 return retval;
81 }
82
83 float duration_elapsed(const struct duration *duration)
84 {
85 float t = duration->elapsed.tv_sec;
86 t += (float)duration->elapsed.tv_usec / 1000000.0;
87 return t;
88 }
89
90 float duration_kbps(const struct duration *duration, size_t count)
91 {
92 return count / (1024.0 * duration_elapsed(duration));
93 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)