synchronization in ltt-usertrace
Naoya Maruyama <[email protected]>
| Newsgroups | gmane.linux.kernel.tracing |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'm currently walking through the usertrace code, and am confused by a couple of code sections of the "fast" tracer. My question is the use of a semaphore in ltt_reserve_slot function in ltt-usertrae/ltt/ltt-usertrace-fast.h. I don't fully understand the entire code yet, but I'm thinking that it's not signal-safe in the following condition. I would appreciate if anyone could tell me whether my understanding is correct or not. 1. Let's say the writer has just called reserve_slot and the reservation starts at a new subbuffer. 2. Assuming the subbuffer is not corrupted, the writer will call sem_wait. 3. The write successfully returns from sem_wait, but is preempted by a signal after the signals being re-enabled, but before the cmpxchg. 4. The handler for the signal could call reserve_slot, find the new slot starts at the beginning of the next subbuffer, because the writer does not yet update the value of offset field. So, if the above steps happened, sem_wait would be called twice, even though the writer and its signal handler would eventually use the same subbuffer. If my understanding is correct, the semaphore is initialized to the number of the subbuffers. If it's true, it wouldn't make sense to call sem_wait multiple times for a single subbuffer, right? BTW, in the same function (reserve_slot in ltt-usertrace-fast.h), I don't yet understand why sem_post is called when the next subbuffer is corrupted, which might explain why I don't understand the call to sem_wait. Thanks very much in advance, Naoya Maruyama