Skip to content

Instantly share code, notes, and snippets.

@agentzh
Last active June 18, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentzh/84e937cd50238c5b96ba75d46a3f85a2 to your computer and use it in GitHub Desktop.
Save agentzh/84e937cd50238c5b96ba75d46a3f85a2 to your computer and use it in GitHub Desktop.
diff --git a/runtime/print_flush.c b/runtime/print_flush.c
index 18b3e8f62..a0fa71b48 100644
--- a/runtime/print_flush.c
+++ b/runtime/print_flush.c
@@ -111,6 +111,13 @@ void stp_print_flush(_stp_pbuf *pb)
struct context* __restrict__ c = NULL;
char *bufp = pb->buf;
+#if defined(__KERNEL__)
+ int locked;
+ struct rchan_buf *buf;
+ struct inode *inode;
+ int i;
+#endif
+
/* Prevent probe reentrancy on _stp_print_lock.
*
* Since stp_print_flush may be called from probe context, we
@@ -131,6 +138,25 @@ void stp_print_flush(_stp_pbuf *pb)
dbug_trans(1, "calling _stp_data_write...\n");
stp_spin_lock_irqsave(&_stp_print_lock, flags);
+
+#if defined(__KERNEL__)
+ buf = _stp_get_rchan_subbuf(_stp_relay_data.rchan->buf,
+ smp_processor_id());
+
+ inode = buf->dentry->d_inode;
+
+ /* emulate a spin lock here */
+ for (i = 0; i < 200; i++) {
+ locked = down_write_trylock(&inode->i_rwsem);
+ if (locked)
+ break;
+ }
+
+#ifdef DEBUG_TRANS
+ if (!locked)
+ dbug_trans(0, "failed to lock the relay file inode");
+#endif
+#endif /* defined(__KERNEL__) */
+
while (len > 0) {
size_t bytes_reserved;
@@ -147,6 +173,12 @@ void stp_print_flush(_stp_pbuf *pb)
break;
}
}
+
+#if defined(__KERNEL__)
+ if (locked)
+ up_write(&inode->i_rwsem);
+#endif
+
stp_spin_unlock_irqrestore(&_stp_print_lock, flags);
_stp_runtime_entryfn_put_context(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment