Skip to content

Instantly share code, notes, and snippets.

@agentzh
Last active June 18, 2020 18:32
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/f83bb342cb7c6de45b4a913b3e29493c to your computer and use it in GitHub Desktop.
Save agentzh/f83bb342cb7c6de45b4a913b3e29493c to your computer and use it in GitHub Desktop.
diff --git a/runtime/print_flush.c b/runtime/print_flush.c
index 18b3e8f62..93535ba2c 100644
--- a/runtime/print_flush.c
+++ b/runtime/print_flush.c
@@ -111,6 +111,30 @@ 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;
+
+ buf = _stp_get_rchan_subbuf(_stp_relay_data.rchan->buf,
+ smp_processor_id());
+
+ inode = buf->dentry->d_inode;
+
+ if (in_interrupt() || in_atomic()) {
+ locked = down_write_trylock(&inode->i_rwsem);
+ if (unlikely(!locked)) {
+ dbug_trans(0, "failed to obtain the relay file "
+ "inode lock");
+ atomic_inc (&_stp_transport_failures);
+ }
+ } else {
+ inode_lock(inode);
+ locked = 1;
+ }
+#endif /* defined(__KERNEL__) */
+
/* Prevent probe reentrancy on _stp_print_lock.
*
* Since stp_print_flush may be called from probe context, we
@@ -149,6 +173,11 @@ void stp_print_flush(_stp_pbuf *pb)
}
stp_spin_unlock_irqrestore(&_stp_print_lock, flags);
_stp_runtime_entryfn_put_context(c);
+
+#if defined(__KERNEL__)
+ if (locked)
+ up_write(&inode->i_rwsem);
+#endif
}
#endif /* STP_TRANSPORT_VERSION != 1 */
#endif /* !STP_BULKMODE */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment