Commit 944410e9 authored by Lars Ellenberg's avatar Lars Ellenberg Committed by Philipp Reisner

drbd: debugfs: add callback_history

Add a per-connection worker thread callback_history
with timing details, call site and callback function.
Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent f418815f
...@@ -521,6 +521,77 @@ void drbd_debugfs_resource_cleanup(struct drbd_resource *resource) ...@@ -521,6 +521,77 @@ void drbd_debugfs_resource_cleanup(struct drbd_resource *resource)
drbd_debugfs_remove(&resource->debugfs_res); drbd_debugfs_remove(&resource->debugfs_res);
} }
static void seq_print_one_timing_detail(struct seq_file *m,
const struct drbd_thread_timing_details *tdp,
unsigned long now)
{
struct drbd_thread_timing_details td;
/* No locking...
* use temporary assignment to get at consistent data. */
do {
td = *tdp;
} while (td.cb_nr != tdp->cb_nr);
if (!td.cb_addr)
return;
seq_printf(m, "%u\t%d\t%s:%u\t%ps\n",
td.cb_nr,
jiffies_to_msecs(now - td.start_jif),
td.caller_fn, td.line,
td.cb_addr);
}
static void seq_print_timing_details(struct seq_file *m,
const char *title,
unsigned int cb_nr, struct drbd_thread_timing_details *tdp, unsigned long now)
{
unsigned int start_idx;
unsigned int i;
seq_printf(m, "%s\n", title);
/* If not much is going on, this will result in natural ordering.
* If it is very busy, we will possibly skip events, or even see wrap
* arounds, which could only be avoided with locking.
*/
start_idx = cb_nr % DRBD_THREAD_DETAILS_HIST;
for (i = start_idx; i < DRBD_THREAD_DETAILS_HIST; i++)
seq_print_one_timing_detail(m, tdp+i, now);
for (i = 0; i < start_idx; i++)
seq_print_one_timing_detail(m, tdp+i, now);
}
static int callback_history_show(struct seq_file *m, void *ignored)
{
struct drbd_connection *connection = m->private;
unsigned long jif = jiffies;
seq_puts(m, "n\tage\tcallsite\tfn\n");
seq_print_timing_details(m, "worker", connection->w_cb_nr, connection->w_timing_details, jif);
seq_print_timing_details(m, "receiver", connection->r_cb_nr, connection->r_timing_details, jif);
return 0;
}
static int callback_history_open(struct inode *inode, struct file *file)
{
struct drbd_connection *connection = inode->i_private;
return drbd_single_open(file, callback_history_show, connection,
&connection->kref, drbd_destroy_connection);
}
static int callback_history_release(struct inode *inode, struct file *file)
{
struct drbd_connection *connection = inode->i_private;
kref_put(&connection->kref, drbd_destroy_connection);
return single_release(inode, file);
}
static const struct file_operations connection_callback_history_fops = {
.owner = THIS_MODULE,
.open = callback_history_open,
.read = seq_read,
.llseek = seq_lseek,
.release = callback_history_release,
};
void drbd_debugfs_connection_add(struct drbd_connection *connection) void drbd_debugfs_connection_add(struct drbd_connection *connection)
{ {
struct dentry *conns_dir = connection->resource->debugfs_res_connections; struct dentry *conns_dir = connection->resource->debugfs_res_connections;
...@@ -535,6 +606,13 @@ void drbd_debugfs_connection_add(struct drbd_connection *connection) ...@@ -535,6 +606,13 @@ void drbd_debugfs_connection_add(struct drbd_connection *connection)
if (IS_ERR_OR_NULL(dentry)) if (IS_ERR_OR_NULL(dentry))
goto fail; goto fail;
connection->debugfs_conn = dentry; connection->debugfs_conn = dentry;
dentry = debugfs_create_file("callback_history", S_IRUSR|S_IRGRP,
connection->debugfs_conn, connection,
&connection_callback_history_fops);
if (IS_ERR_OR_NULL(dentry))
goto fail;
connection->debugfs_conn_callback_history = dentry;
return; return;
fail: fail:
......
...@@ -697,6 +697,15 @@ struct drbd_resource { ...@@ -697,6 +697,15 @@ struct drbd_resource {
cpumask_var_t cpu_mask; cpumask_var_t cpu_mask;
}; };
struct drbd_thread_timing_details
{
unsigned long start_jif;
void *cb_addr;
const char *caller_fn;
unsigned int line;
unsigned int cb_nr;
};
struct drbd_connection { struct drbd_connection {
struct list_head connections; struct list_head connections;
struct drbd_resource *resource; struct drbd_resource *resource;
...@@ -759,6 +768,12 @@ struct drbd_connection { ...@@ -759,6 +768,12 @@ struct drbd_connection {
/* sender side */ /* sender side */
struct drbd_work_queue sender_work; struct drbd_work_queue sender_work;
#define DRBD_THREAD_DETAILS_HIST 16
unsigned int w_cb_nr; /* keeps counting up */
unsigned int r_cb_nr; /* keeps counting up */
struct drbd_thread_timing_details w_timing_details[DRBD_THREAD_DETAILS_HIST];
struct drbd_thread_timing_details r_timing_details[DRBD_THREAD_DETAILS_HIST];
struct { struct {
/* whether this sender thread /* whether this sender thread
* has processed a single write yet. */ * has processed a single write yet. */
...@@ -774,6 +789,17 @@ struct drbd_connection { ...@@ -774,6 +789,17 @@ struct drbd_connection {
} send; } send;
}; };
void __update_timing_details(
struct drbd_thread_timing_details *tdp,
unsigned int *cb_nr,
void *cb,
const char *fn, const unsigned int line);
#define update_worker_timing_details(c, cb) \
__update_timing_details(c->w_timing_details, &c->w_cb_nr, cb, __func__ , __LINE__ )
#define update_receiver_timing_details(c, cb) \
__update_timing_details(c->r_timing_details, &c->r_cb_nr, cb, __func__ , __LINE__ )
struct submit_worker { struct submit_worker {
struct workqueue_struct *wq; struct workqueue_struct *wq;
struct work_struct worker; struct work_struct worker;
......
...@@ -2682,9 +2682,11 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet ...@@ -2682,9 +2682,11 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
list_add_tail(&peer_req->w.list, &device->read_ee); list_add_tail(&peer_req->w.list, &device->read_ee);
spin_unlock_irq(&device->resource->req_lock); spin_unlock_irq(&device->resource->req_lock);
update_receiver_timing_details(connection, drbd_rs_should_slow_down);
if (device->state.peer != R_PRIMARY if (device->state.peer != R_PRIMARY
&& drbd_rs_should_slow_down(device, sector, false)) && drbd_rs_should_slow_down(device, sector, false))
schedule_timeout_uninterruptible(HZ/10); schedule_timeout_uninterruptible(HZ/10);
update_receiver_timing_details(connection, drbd_rs_begin_io);
if (drbd_rs_begin_io(device, sector)) if (drbd_rs_begin_io(device, sector))
goto out_free_e; goto out_free_e;
...@@ -2692,6 +2694,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet ...@@ -2692,6 +2694,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
atomic_add(size >> 9, &device->rs_sect_ev); atomic_add(size >> 9, &device->rs_sect_ev);
submit: submit:
update_receiver_timing_details(connection, drbd_submit_peer_request);
inc_unacked(device); inc_unacked(device);
if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0) if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0)
return 0; return 0;
...@@ -4601,6 +4604,7 @@ static void drbdd(struct drbd_connection *connection) ...@@ -4601,6 +4604,7 @@ static void drbdd(struct drbd_connection *connection)
struct data_cmd *cmd; struct data_cmd *cmd;
drbd_thread_current_set_cpu(&connection->receiver); drbd_thread_current_set_cpu(&connection->receiver);
update_receiver_timing_details(connection, drbd_recv_header);
if (drbd_recv_header(connection, &pi)) if (drbd_recv_header(connection, &pi))
goto err_out; goto err_out;
...@@ -4619,12 +4623,14 @@ static void drbdd(struct drbd_connection *connection) ...@@ -4619,12 +4623,14 @@ static void drbdd(struct drbd_connection *connection)
} }
if (shs) { if (shs) {
update_receiver_timing_details(connection, drbd_recv_all_warn);
err = drbd_recv_all_warn(connection, pi.data, shs); err = drbd_recv_all_warn(connection, pi.data, shs);
if (err) if (err)
goto err_out; goto err_out;
pi.size -= shs; pi.size -= shs;
} }
update_receiver_timing_details(connection, cmd->fn);
err = cmd->fn(connection, &pi); err = cmd->fn(connection, &pi);
if (err) { if (err) {
drbd_err(connection, "error receiving %s, e: %d l: %d!\n", drbd_err(connection, "error receiving %s, e: %d l: %d!\n",
......
...@@ -1905,6 +1905,29 @@ static int do_md_sync(struct drbd_device *device) ...@@ -1905,6 +1905,29 @@ static int do_md_sync(struct drbd_device *device)
return 0; return 0;
} }
/* only called from drbd_worker thread, no locking */
void __update_timing_details(
struct drbd_thread_timing_details *tdp,
unsigned int *cb_nr,
void *cb,
const char *fn, const unsigned int line)
{
unsigned int i = *cb_nr % DRBD_THREAD_DETAILS_HIST;
struct drbd_thread_timing_details *td = tdp + i;
td->start_jif = jiffies;
td->cb_addr = cb;
td->caller_fn = fn;
td->line = line;
td->cb_nr = *cb_nr;
i = (i+1) % DRBD_THREAD_DETAILS_HIST;
td = tdp + i;
memset(td, 0, sizeof(*td));
++(*cb_nr);
}
#define WORK_PENDING(work_bit, todo) (todo & (1UL << work_bit)) #define WORK_PENDING(work_bit, todo) (todo & (1UL << work_bit))
static void do_device_work(struct drbd_device *device, const unsigned long todo) static void do_device_work(struct drbd_device *device, const unsigned long todo)
{ {
...@@ -2076,11 +2099,15 @@ int drbd_worker(struct drbd_thread *thi) ...@@ -2076,11 +2099,15 @@ int drbd_worker(struct drbd_thread *thi)
while (get_t_state(thi) == RUNNING) { while (get_t_state(thi) == RUNNING) {
drbd_thread_current_set_cpu(thi); drbd_thread_current_set_cpu(thi);
if (list_empty(&work_list)) if (list_empty(&work_list)) {
update_worker_timing_details(connection, wait_for_work);
wait_for_work(connection, &work_list); wait_for_work(connection, &work_list);
}
if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) {
update_worker_timing_details(connection, do_unqueued_work);
do_unqueued_work(connection); do_unqueued_work(connection);
}
if (signal_pending(current)) { if (signal_pending(current)) {
flush_signals(current); flush_signals(current);
...@@ -2097,6 +2124,7 @@ int drbd_worker(struct drbd_thread *thi) ...@@ -2097,6 +2124,7 @@ int drbd_worker(struct drbd_thread *thi)
while (!list_empty(&work_list)) { while (!list_empty(&work_list)) {
w = list_first_entry(&work_list, struct drbd_work, list); w = list_first_entry(&work_list, struct drbd_work, list);
list_del_init(&w->list); list_del_init(&w->list);
update_worker_timing_details(connection, w->cb);
if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0) if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0)
continue; continue;
if (connection->cstate >= C_WF_REPORT_PARAMS) if (connection->cstate >= C_WF_REPORT_PARAMS)
...@@ -2105,11 +2133,14 @@ int drbd_worker(struct drbd_thread *thi) ...@@ -2105,11 +2133,14 @@ int drbd_worker(struct drbd_thread *thi)
} }
do { do {
if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) {
update_worker_timing_details(connection, do_unqueued_work);
do_unqueued_work(connection); do_unqueued_work(connection);
}
while (!list_empty(&work_list)) { while (!list_empty(&work_list)) {
w = list_first_entry(&work_list, struct drbd_work, list); w = list_first_entry(&work_list, struct drbd_work, list);
list_del_init(&w->list); list_del_init(&w->list);
update_worker_timing_details(connection, w->cb);
w->cb(w, 1); w->cb(w, 1);
} }
dequeue_work_batch(&connection->sender_work, &work_list); dequeue_work_batch(&connection->sender_work, &work_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment