Will be used for testing the module.
Signed-off-by: Jakub Sitnicki <[email protected]>
---
lib/performance.c | 18 ++++++++++++++++++
lib/performance.h | 3 +++
2 files changed, 21 insertions(+)
diff --git a/lib/performance.c b/lib/performance.c
index 8af124d1d..0239c78ee 100644
--- a/lib/performance.c
+++ b/lib/performance.c
@@ -64,6 +64,7 @@ struct performance {
enum performance_op {
OP_START_SAMPLE,
OP_END_SAMPLE,
+ OP_SYNC,
OP_RESET,
OP_SHUTDOWN,
};
@@ -76,6 +77,7 @@ struct performance_packet {
static struct shash performances = SHASH_INITIALIZER(&performances);
static struct ovs_mutex performances_lock = OVS_MUTEX_INITIALIZER;
+static pthread_cond_t performances_sync = PTHREAD_COND_INITIALIZER;
static int performance_pipe[2];
static pthread_t performance_thread_id;
@@ -406,6 +408,9 @@ performance_thread(void *ign OVS_UNUSED)
case OP_END_SAMPLE:
performance_end_sample_protected(&pkt);
break;
+ case OP_SYNC:
+ xpthread_cond_signal(&performances_sync);
+ break;
case OP_RESET:
performance_reset_protected(&pkt);
break;
@@ -512,3 +517,16 @@ performance_end_sample(const char *name, unsigned long
long ts)
return true;
}
+
+void
+performance_sync(void)
+{
+ struct performance_packet pkt = {
+ .op = OP_SYNC,
+ };
+
+ ovs_mutex_lock(&performances_lock);
+ write(performance_pipe[1], &pkt, sizeof(pkt));
+ ovs_mutex_cond_wait(&performances_sync, &performances_lock);
+ ovs_mutex_unlock(&performances_lock);
+}
diff --git a/lib/performance.h b/lib/performance.h
index 09ca844b9..995c975ac 100644
--- a/lib/performance.h
+++ b/lib/performance.h
@@ -52,4 +52,7 @@ bool performance_end_sample(const char *name, unsigned long
long ts);
/* Retrieve statistics calculated from collected samples */
bool performance_get_stats(const char *name, struct performance_stats *stats);
+/* Block until all enqueued samples have been processed. */
+void performance_sync(void);
+
#endif /* performance.h */
--
2.14.3
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev