summaryrefslogtreecommitdiff
path: root/meta-openembedded/meta-oe/recipes-core/dbus/dbus-broker/0002-metrics-change-the-constant-used-for-invalid-timesta.patch
blob: 67a2dc46f1c5fa6fce94599dc809328dbefd4bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From 3570b3e9ba367f10718b56336ce32d5254f66575 Mon Sep 17 00:00:00 2001
From: Tom Gundersen <teg@jklm.no>
Date: Thu, 9 May 2019 13:00:37 +0200
Subject: [PATCH] metrics: change the constant used for invalid timestamps

Use (uint64_t)-1 rather than 0 to indicate an invalid timestamp. It
should not be possible for the kernel to return 0 from
clock_gettime(), but we have received some reports of our asserts
triggering, so avoid the issue entirely  by using -1 instead (which
really can never be returned).

See https://retrace.fedoraproject.org/faf/reports/2539484/

Signed-off-by: Tom Gundersen <teg@jklm.no>
Upstream-Status: dbus-broker@3570b3e9ba367f10718b56336ce32d5254f66575
---
 src/util/metrics.c | 8 ++++----
 src/util/metrics.h | 9 ++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/util/metrics.c b/src/util/metrics.c
index b5a7182..eef94eb 100644
--- a/src/util/metrics.c
+++ b/src/util/metrics.c
@@ -26,7 +26,7 @@ void metrics_init(Metrics *metrics, clockid_t id) {
 }
 
 void metrics_deinit(Metrics *metrics) {
-        c_assert(!metrics->timestamp);
+        c_assert(metrics->timestamp == METRICS_TIMESTAMP_INVALID);
         metrics_init(metrics, metrics->id);
 }
 
@@ -82,7 +82,7 @@ void metrics_sample_add(Metrics *metrics, uint64_t timestamp) {
  * a sample is not currently running.
  */
 void metrics_sample_start(Metrics *metrics) {
-        c_assert(!metrics->timestamp);
+        c_assert(metrics->timestamp == METRICS_TIMESTAMP_INVALID);
         metrics->timestamp = metrics_get_time(metrics);
 }
 
@@ -93,11 +93,11 @@ void metrics_sample_start(Metrics *metrics) {
  * End a currently running sample, and update the internal state.
  */
 void metrics_sample_end(Metrics *metrics) {
-        c_assert(metrics->timestamp);
+        c_assert(metrics->timestamp != METRICS_TIMESTAMP_INVALID);
 
         metrics_sample_add(metrics, metrics->timestamp);
 
-        metrics->timestamp = 0;
+        metrics->timestamp = METRICS_TIMESTAMP_INVALID;
 }
 
 /**
diff --git a/src/util/metrics.h b/src/util/metrics.h
index a8ee915..b00dee6 100644
--- a/src/util/metrics.h
+++ b/src/util/metrics.h
@@ -8,6 +8,8 @@
 #include <stdlib.h>
 #include <time.h>
 
+#define METRICS_TIMESTAMP_INVALID ((uint64_t) -1)
+
 typedef struct Metrics Metrics;
 
 struct Metrics {
@@ -23,9 +25,10 @@ struct Metrics {
         uint64_t sum_of_squares;
 };
 
-#define METRICS_INIT(_id) {                     \
-                .minimum = (uint64_t) -1,       \
-                .id = (_id),                    \
+#define METRICS_INIT(_id) {                                     \
+                .minimum = (uint64_t) -1,                       \
+                .id = (_id),                                    \
+                .timestamp = METRICS_TIMESTAMP_INVALID,         \
         }
 
 void metrics_init(Metrics *metrics, clockid_t id);
-- 
2.21.0