Skip to contentSkip to conversation

trace-cmd: Unlock tsync mutex on thread exit

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 1 message Apr 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Unlock tsync mutex on thread exit

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

---
 lib/trace-cmd/trace-timesync.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-timesync.c +3 -1
index f8ec15a3..90ffa6d0 100644
@@ -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);
Signature · 1 line
2.35.1