Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drbd: debugfs: add callback_history

Add a per-connection worker thread callback_history
with timing details, call site and callback function.

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>

authored by

Lars Ellenberg and committed by
Philipp Reisner
944410e9 f418815f

+144 -3
+78
drivers/block/drbd/drbd_debugfs.c
··· 521 521 drbd_debugfs_remove(&resource->debugfs_res); 522 522 } 523 523 524 + static void seq_print_one_timing_detail(struct seq_file *m, 525 + const struct drbd_thread_timing_details *tdp, 526 + unsigned long now) 527 + { 528 + struct drbd_thread_timing_details td; 529 + /* No locking... 530 + * use temporary assignment to get at consistent data. */ 531 + do { 532 + td = *tdp; 533 + } while (td.cb_nr != tdp->cb_nr); 534 + if (!td.cb_addr) 535 + return; 536 + seq_printf(m, "%u\t%d\t%s:%u\t%ps\n", 537 + td.cb_nr, 538 + jiffies_to_msecs(now - td.start_jif), 539 + td.caller_fn, td.line, 540 + td.cb_addr); 541 + } 542 + 543 + static void seq_print_timing_details(struct seq_file *m, 544 + const char *title, 545 + unsigned int cb_nr, struct drbd_thread_timing_details *tdp, unsigned long now) 546 + { 547 + unsigned int start_idx; 548 + unsigned int i; 549 + 550 + seq_printf(m, "%s\n", title); 551 + /* If not much is going on, this will result in natural ordering. 552 + * If it is very busy, we will possibly skip events, or even see wrap 553 + * arounds, which could only be avoided with locking. 554 + */ 555 + start_idx = cb_nr % DRBD_THREAD_DETAILS_HIST; 556 + for (i = start_idx; i < DRBD_THREAD_DETAILS_HIST; i++) 557 + seq_print_one_timing_detail(m, tdp+i, now); 558 + for (i = 0; i < start_idx; i++) 559 + seq_print_one_timing_detail(m, tdp+i, now); 560 + } 561 + 562 + static int callback_history_show(struct seq_file *m, void *ignored) 563 + { 564 + struct drbd_connection *connection = m->private; 565 + unsigned long jif = jiffies; 566 + 567 + seq_puts(m, "n\tage\tcallsite\tfn\n"); 568 + seq_print_timing_details(m, "worker", connection->w_cb_nr, connection->w_timing_details, jif); 569 + seq_print_timing_details(m, "receiver", connection->r_cb_nr, connection->r_timing_details, jif); 570 + return 0; 571 + } 572 + 573 + static int callback_history_open(struct inode *inode, struct file *file) 574 + { 575 + struct drbd_connection *connection = inode->i_private; 576 + return drbd_single_open(file, callback_history_show, connection, 577 + &connection->kref, drbd_destroy_connection); 578 + } 579 + 580 + static int callback_history_release(struct inode *inode, struct file *file) 581 + { 582 + struct drbd_connection *connection = inode->i_private; 583 + kref_put(&connection->kref, drbd_destroy_connection); 584 + return single_release(inode, file); 585 + } 586 + 587 + static const struct file_operations connection_callback_history_fops = { 588 + .owner = THIS_MODULE, 589 + .open = callback_history_open, 590 + .read = seq_read, 591 + .llseek = seq_lseek, 592 + .release = callback_history_release, 593 + }; 594 + 524 595 void drbd_debugfs_connection_add(struct drbd_connection *connection) 525 596 { 526 597 struct dentry *conns_dir = connection->resource->debugfs_res_connections; ··· 606 535 if (IS_ERR_OR_NULL(dentry)) 607 536 goto fail; 608 537 connection->debugfs_conn = dentry; 538 + 539 + dentry = debugfs_create_file("callback_history", S_IRUSR|S_IRGRP, 540 + connection->debugfs_conn, connection, 541 + &connection_callback_history_fops); 542 + if (IS_ERR_OR_NULL(dentry)) 543 + goto fail; 544 + connection->debugfs_conn_callback_history = dentry; 609 545 return; 610 546 611 547 fail:
+26
drivers/block/drbd/drbd_int.h
··· 697 697 cpumask_var_t cpu_mask; 698 698 }; 699 699 700 + struct drbd_thread_timing_details 701 + { 702 + unsigned long start_jif; 703 + void *cb_addr; 704 + const char *caller_fn; 705 + unsigned int line; 706 + unsigned int cb_nr; 707 + }; 708 + 700 709 struct drbd_connection { 701 710 struct list_head connections; 702 711 struct drbd_resource *resource; ··· 768 759 /* sender side */ 769 760 struct drbd_work_queue sender_work; 770 761 762 + #define DRBD_THREAD_DETAILS_HIST 16 763 + unsigned int w_cb_nr; /* keeps counting up */ 764 + unsigned int r_cb_nr; /* keeps counting up */ 765 + struct drbd_thread_timing_details w_timing_details[DRBD_THREAD_DETAILS_HIST]; 766 + struct drbd_thread_timing_details r_timing_details[DRBD_THREAD_DETAILS_HIST]; 767 + 771 768 struct { 772 769 /* whether this sender thread 773 770 * has processed a single write yet. */ ··· 788 773 unsigned current_epoch_writes; 789 774 } send; 790 775 }; 776 + 777 + void __update_timing_details( 778 + struct drbd_thread_timing_details *tdp, 779 + unsigned int *cb_nr, 780 + void *cb, 781 + const char *fn, const unsigned int line); 782 + 783 + #define update_worker_timing_details(c, cb) \ 784 + __update_timing_details(c->w_timing_details, &c->w_cb_nr, cb, __func__ , __LINE__ ) 785 + #define update_receiver_timing_details(c, cb) \ 786 + __update_timing_details(c->r_timing_details, &c->r_cb_nr, cb, __func__ , __LINE__ ) 791 787 792 788 struct submit_worker { 793 789 struct workqueue_struct *wq;
+6
drivers/block/drbd/drbd_receiver.c
··· 2682 2682 list_add_tail(&peer_req->w.list, &device->read_ee); 2683 2683 spin_unlock_irq(&device->resource->req_lock); 2684 2684 2685 + update_receiver_timing_details(connection, drbd_rs_should_slow_down); 2685 2686 if (device->state.peer != R_PRIMARY 2686 2687 && drbd_rs_should_slow_down(device, sector, false)) 2687 2688 schedule_timeout_uninterruptible(HZ/10); 2689 + update_receiver_timing_details(connection, drbd_rs_begin_io); 2688 2690 if (drbd_rs_begin_io(device, sector)) 2689 2691 goto out_free_e; 2690 2692 ··· 2694 2692 atomic_add(size >> 9, &device->rs_sect_ev); 2695 2693 2696 2694 submit: 2695 + update_receiver_timing_details(connection, drbd_submit_peer_request); 2697 2696 inc_unacked(device); 2698 2697 if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0) 2699 2698 return 0; ··· 4604 4601 struct data_cmd *cmd; 4605 4602 4606 4603 drbd_thread_current_set_cpu(&connection->receiver); 4604 + update_receiver_timing_details(connection, drbd_recv_header); 4607 4605 if (drbd_recv_header(connection, &pi)) 4608 4606 goto err_out; 4609 4607 ··· 4623 4619 } 4624 4620 4625 4621 if (shs) { 4622 + update_receiver_timing_details(connection, drbd_recv_all_warn); 4626 4623 err = drbd_recv_all_warn(connection, pi.data, shs); 4627 4624 if (err) 4628 4625 goto err_out; 4629 4626 pi.size -= shs; 4630 4627 } 4631 4628 4629 + update_receiver_timing_details(connection, cmd->fn); 4632 4630 err = cmd->fn(connection, &pi); 4633 4631 if (err) { 4634 4632 drbd_err(connection, "error receiving %s, e: %d l: %d!\n",
+34 -3
drivers/block/drbd/drbd_worker.c
··· 1905 1905 return 0; 1906 1906 } 1907 1907 1908 + /* only called from drbd_worker thread, no locking */ 1909 + void __update_timing_details( 1910 + struct drbd_thread_timing_details *tdp, 1911 + unsigned int *cb_nr, 1912 + void *cb, 1913 + const char *fn, const unsigned int line) 1914 + { 1915 + unsigned int i = *cb_nr % DRBD_THREAD_DETAILS_HIST; 1916 + struct drbd_thread_timing_details *td = tdp + i; 1917 + 1918 + td->start_jif = jiffies; 1919 + td->cb_addr = cb; 1920 + td->caller_fn = fn; 1921 + td->line = line; 1922 + td->cb_nr = *cb_nr; 1923 + 1924 + i = (i+1) % DRBD_THREAD_DETAILS_HIST; 1925 + td = tdp + i; 1926 + memset(td, 0, sizeof(*td)); 1927 + 1928 + ++(*cb_nr); 1929 + } 1930 + 1908 1931 #define WORK_PENDING(work_bit, todo) (todo & (1UL << work_bit)) 1909 1932 static void do_device_work(struct drbd_device *device, const unsigned long todo) 1910 1933 { ··· 2099 2076 while (get_t_state(thi) == RUNNING) { 2100 2077 drbd_thread_current_set_cpu(thi); 2101 2078 2102 - if (list_empty(&work_list)) 2079 + if (list_empty(&work_list)) { 2080 + update_worker_timing_details(connection, wait_for_work); 2103 2081 wait_for_work(connection, &work_list); 2082 + } 2104 2083 2105 - if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) 2084 + if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) { 2085 + update_worker_timing_details(connection, do_unqueued_work); 2106 2086 do_unqueued_work(connection); 2087 + } 2107 2088 2108 2089 if (signal_pending(current)) { 2109 2090 flush_signals(current); ··· 2124 2097 while (!list_empty(&work_list)) { 2125 2098 w = list_first_entry(&work_list, struct drbd_work, list); 2126 2099 list_del_init(&w->list); 2100 + update_worker_timing_details(connection, w->cb); 2127 2101 if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0) 2128 2102 continue; 2129 2103 if (connection->cstate >= C_WF_REPORT_PARAMS) ··· 2133 2105 } 2134 2106 2135 2107 do { 2136 - if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) 2108 + if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) { 2109 + update_worker_timing_details(connection, do_unqueued_work); 2137 2110 do_unqueued_work(connection); 2111 + } 2138 2112 while (!list_empty(&work_list)) { 2139 2113 w = list_first_entry(&work_list, struct drbd_work, list); 2140 2114 list_del_init(&w->list); 2115 + update_worker_timing_details(connection, w->cb); 2141 2116 w->cb(w, 1); 2142 2117 } 2143 2118 dequeue_work_batch(&connection->sender_work, &work_list);