diff mbox series

trace-cmd: Unlock tsync mutex on thread exit

Message ID 20220411041002.132379-1-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit 36f6934bb83a592aeb038bb1fc4e5347708ce25d
Headers show
Series trace-cmd: Unlock tsync mutex on thread exit | expand

Commit Message

Tzvetomir Stoyanov (VMware) April 11, 2022, 4:10 a.m. UTC
The logic for synchronising host and guest time stamps uses pthreads and
mutexes. The guest pthread locks a mutex on the beginning of each
synchronization iteration and uses it to wait on a conditional variable.
When the synchronization is done and the thread exists, this mutex
should be unlocked.

fixes: 08b9d507 ("trace-cmd: Basic infrastructure for host - guest timestamp synchronization")
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215808
Reported-by: Ryan <ycaibb@gmail.com>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-timesync.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index f8ec15a3..90ffa6d0 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -807,8 +807,10 @@  static int tsync_with_guest(struct tracecmd_time_sync *tsync)
 			first = false;
 			pthread_barrier_wait(&tsync->first_sync);
 		}
-		if (end || i < tsync->vcpu_count)
+		if (end || i < tsync->vcpu_count) {
+			pthread_mutex_unlock(&tsync->lock);
 			break;
+		}
 		if (tsync->loop_interval > 0) {
 			get_ts_loop_delay(&timeout, tsync->loop_interval);
 			ret = pthread_cond_timedwait(&tsync->cond, &tsync->lock, &timeout);