Skip to content

Commit

Permalink
Add source line to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
larytet committed Jul 10, 2017
1 parent 6edcb1a commit 61a2847
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -37,3 +37,4 @@ stamp-elfutils
dtrace
stappaths.7
.zanata-cache
/Debug/
2 changes: 2 additions & 0 deletions runtime/common_probe_context.h
Expand Up @@ -175,3 +175,5 @@ struct unwind_context uwcontext_kernel;
#ifdef _HAVE_PERF_
long *perf_read_values;
#endif

unsigned line;
6 changes: 4 additions & 2 deletions runtime/linux/runtime_context.h
Expand Up @@ -76,13 +76,14 @@ static inline struct context * _stp_runtime_get_context(void)
return rcu_dereference_sched(contexts[smp_processor_id()]);
}

static struct context * _stp_runtime_entryfn_get_context(void)
static struct context * _stp_runtime_entryfn_get_context(int line)
{
struct context* __restrict__ c = NULL;
preempt_disable ();
c = _stp_runtime_get_context();
if (c != NULL) {
if (atomic_inc_return(&c->busy) == 1) {
c->line = line;
// NB: Notice we're not re-enabling preemption
// here. We exepect the calling code to call
// _stp_runtime_entryfn_get_context() and
Expand Down Expand Up @@ -131,7 +132,8 @@ static void _stp_runtime_context_wait(void)
if (time_after(jiffies, hold_start + HZ) // > 1 second
&& (i > hold_index)) { // not already printed
hold_index = i;
printk(KERN_ERR "%s context[%d] stuck: %s\n", THIS_MODULE->name, i, c->probe_point);
printk(KERN_ERR "%s context[%d] stuck: %s, line=%d, last_err=%s last_stmt=%s\n", THIS_MODULE->name, i,
c->probe_point, c->line, c->last_error, c->last_stmt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/print_flush.c
Expand Up @@ -127,7 +127,7 @@ void stp_print_flush(_stp_pbuf *pb)
* concurrency-control-laden effort with a lockless
* algorithm.
*/
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);

dbug_trans(1, "calling _stp_data_write...\n");
stp_spin_lock_irqsave(&_stp_print_lock, flags);
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime.h
Expand Up @@ -15,7 +15,7 @@
static int _stp_runtime_contexts_alloc(void);
static void _stp_runtime_contexts_free(void);
static int _stp_runtime_get_data_index(void);
static struct context *_stp_runtime_entryfn_get_context(void);
static struct context *_stp_runtime_entryfn_get_context(int);
static void _stp_runtime_entryfn_put_context(struct context *);
static struct context *_stp_runtime_get_context(void);

Expand Down
8 changes: 4 additions & 4 deletions runtime/transport/control.c
Expand Up @@ -564,7 +564,7 @@ static int _stp_ctl_send(int type, void *data, unsigned len)
We ensure this by grabbing the context here and everywhere else that
uses those locks, so such a probe will appear reentrant and be
skipped rather than deadlock. */
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);

/* get a buffer from the free pool */
bptr = _stp_ctl_get_buffer(type, data, len);
Expand Down Expand Up @@ -621,7 +621,7 @@ static ssize_t _stp_ctl_read_cmd(struct file *file, char __user *buf,
unsigned long flags;

/* Prevent probe reentrancy while grabbing probe-used locks. */
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);

/* wait for nonempty ready queue */
spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
Expand All @@ -632,7 +632,7 @@ static ssize_t _stp_ctl_read_cmd(struct file *file, char __user *buf,
return -EAGAIN;
if (wait_event_interruptible(_stp_ctl_wq, !list_empty(&_stp_ctl_ready_q)))
return -ERESTARTSYS;
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);
spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
}

Expand All @@ -658,7 +658,7 @@ static ssize_t _stp_ctl_read_cmd(struct file *file, char __user *buf,
}

/* put it on the pool of free buffers */
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);
_stp_ctl_free_buffer(bptr);
_stp_runtime_entryfn_put_context(c);

Expand Down
2 changes: 1 addition & 1 deletion runtime/transport/transport.c
Expand Up @@ -348,7 +348,7 @@ static void _stp_ctl_work_callback(unsigned long val)
struct context* __restrict__ c = NULL;

/* Prevent probe reentrancy while grabbing probe-used locks. */
c = _stp_runtime_entryfn_get_context();
c = _stp_runtime_entryfn_get_context(__LINE__);

spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
if (!list_empty(&_stp_ctl_ready_q))
Expand Down
2 changes: 1 addition & 1 deletion tapsets.cxx
Expand Up @@ -168,7 +168,7 @@ common_probe_entryfn_prologue (systemtap_session& s,
pre_context_callback(s, callback_data);
s.op->newline() << "#endif";
}
s.op->newline() << "c = _stp_runtime_entryfn_get_context();";
s.op->newline() << "c = _stp_runtime_entryfn_get_context(__LINE__);";
s.op->newline() << "if (!c) {";
s.op->newline(1) << "#if !INTERRUPTIBLE";
s.op->newline() << "atomic_inc (skipped_count());";
Expand Down
2 changes: 1 addition & 1 deletion translate.cxx
Expand Up @@ -2251,7 +2251,7 @@ c_unparser::emit_module_exit ()
else
{
o->newline() << "struct context* __restrict__ c;";
o->newline() << "c = _stp_runtime_entryfn_get_context();";
o->newline() << "c = _stp_runtime_entryfn_get_context(__LINE__);";
}

// teardown tracepoints (if needed)
Expand Down

0 comments on commit 61a2847

Please sign in to comment.