* Drain any pending ktrace records from the per-thread queue to disk. This * is used both internally before committing other records, and also on * system call return. We drain all the ones we can find at the time when * drain is requested, but don't keep draining after that as those events * may be approximately "after" the current event. */
| 360 | * may be approximately "after" the current event. |
| 361 | */ |
| 362 | static void |
| 363 | ktr_drain(struct thread *td) |
| 364 | { |
| 365 | struct ktr_request *queued_req; |
| 366 | STAILQ_HEAD(, ktr_request) local_queue; |
| 367 | |
| 368 | ktrace_assert(td); |
| 369 | sx_assert(&ktrace_sx, SX_XLOCKED); |
| 370 | |
| 371 | STAILQ_INIT(&local_queue); |
| 372 | |
| 373 | if (!STAILQ_EMPTY(&td->td_proc->p_ktr)) { |
| 374 | mtx_lock(&ktrace_mtx); |
| 375 | STAILQ_CONCAT(&local_queue, &td->td_proc->p_ktr); |
| 376 | mtx_unlock(&ktrace_mtx); |
| 377 | |
| 378 | while ((queued_req = STAILQ_FIRST(&local_queue))) { |
| 379 | STAILQ_REMOVE_HEAD(&local_queue, ktr_list); |
| 380 | ktr_writerequest(td, queued_req); |
| 381 | ktr_freerequest(queued_req); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * Submit a trace record for immediate commit to disk -- to be used only |
no test coverage detected