Commit 1538f888f1e793de04e0f90372352ac1b05833cf

Authored by Masami Hiramatsu
Committed by Steven Rostedt
1 parent 7143f168e2

tracing/kprobes: Merge trace probe enable/disable functions

Merge redundant enable/disable functions into enable_trace_probe()
and disable_trace_probe().

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: yrl.pp-manager.tt@hitachi.com
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Link: http://lkml.kernel.org/r/20110627072644.6528.26910.stgit@fedora15

[ converted kprobe selftest to use  enable_trace_probe ]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Showing 1 changed file with 36 additions and 56 deletions Side-by-side Diff

kernel/trace/trace_kprobe.c
... ... @@ -683,6 +683,34 @@
683 683 return NULL;
684 684 }
685 685  
  686 +/* Enable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
  687 +static int enable_trace_probe(struct trace_probe *tp, int flag)
  688 +{
  689 + int ret = 0;
  690 +
  691 + tp->flags |= flag;
  692 + if (tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE)) {
  693 + if (trace_probe_is_return(tp))
  694 + ret = enable_kretprobe(&tp->rp);
  695 + else
  696 + ret = enable_kprobe(&tp->rp.kp);
  697 + }
  698 +
  699 + return ret;
  700 +}
  701 +
  702 +/* Disable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
  703 +static void disable_trace_probe(struct trace_probe *tp, int flag)
  704 +{
  705 + tp->flags &= ~flag;
  706 + if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
  707 + if (trace_probe_is_return(tp))
  708 + disable_kretprobe(&tp->rp);
  709 + else
  710 + disable_kprobe(&tp->rp.kp);
  711 + }
  712 +}
  713 +
686 714 /* Unregister a trace_probe and probe_event: call with locking probe_lock */
687 715 static void unregister_trace_probe(struct trace_probe *tp)
688 716 {
... ... @@ -1514,30 +1542,6 @@
1514 1542 return TRACE_TYPE_PARTIAL_LINE;
1515 1543 }
1516 1544  
1517   -static int probe_event_enable(struct ftrace_event_call *call)
1518   -{
1519   - struct trace_probe *tp = (struct trace_probe *)call->data;
1520   -
1521   - tp->flags |= TP_FLAG_TRACE;
1522   - if (trace_probe_is_return(tp))
1523   - return enable_kretprobe(&tp->rp);
1524   - else
1525   - return enable_kprobe(&tp->rp.kp);
1526   -}
1527   -
1528   -static void probe_event_disable(struct ftrace_event_call *call)
1529   -{
1530   - struct trace_probe *tp = (struct trace_probe *)call->data;
1531   -
1532   - tp->flags &= ~TP_FLAG_TRACE;
1533   - if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
1534   - if (trace_probe_is_return(tp))
1535   - disable_kretprobe(&tp->rp);
1536   - else
1537   - disable_kprobe(&tp->rp.kp);
1538   - }
1539   -}
1540   -
1541 1545 #undef DEFINE_FIELD
1542 1546 #define DEFINE_FIELD(type, item, name, is_signed) \
1543 1547 do { \
1544 1548  
1545 1549  
1546 1550  
1547 1551  
1548 1552  
... ... @@ -1716,49 +1720,25 @@
1716 1720 head = this_cpu_ptr(call->perf_events);
1717 1721 perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head);
1718 1722 }
1719   -
1720   -static int probe_perf_enable(struct ftrace_event_call *call)
1721   -{
1722   - struct trace_probe *tp = (struct trace_probe *)call->data;
1723   -
1724   - tp->flags |= TP_FLAG_PROFILE;
1725   -
1726   - if (trace_probe_is_return(tp))
1727   - return enable_kretprobe(&tp->rp);
1728   - else
1729   - return enable_kprobe(&tp->rp.kp);
1730   -}
1731   -
1732   -static void probe_perf_disable(struct ftrace_event_call *call)
1733   -{
1734   - struct trace_probe *tp = (struct trace_probe *)call->data;
1735   -
1736   - tp->flags &= ~TP_FLAG_PROFILE;
1737   -
1738   - if (!(tp->flags & TP_FLAG_TRACE)) {
1739   - if (trace_probe_is_return(tp))
1740   - disable_kretprobe(&tp->rp);
1741   - else
1742   - disable_kprobe(&tp->rp.kp);
1743   - }
1744   -}
1745 1723 #endif /* CONFIG_PERF_EVENTS */
1746 1724  
1747 1725 static __kprobes
1748 1726 int kprobe_register(struct ftrace_event_call *event, enum trace_reg type)
1749 1727 {
  1728 + struct trace_probe *tp = (struct trace_probe *)event->data;
  1729 +
1750 1730 switch (type) {
1751 1731 case TRACE_REG_REGISTER:
1752   - return probe_event_enable(event);
  1732 + return enable_trace_probe(tp, TP_FLAG_TRACE);
1753 1733 case TRACE_REG_UNREGISTER:
1754   - probe_event_disable(event);
  1734 + disable_trace_probe(tp, TP_FLAG_TRACE);
1755 1735 return 0;
1756 1736  
1757 1737 #ifdef CONFIG_PERF_EVENTS
1758 1738 case TRACE_REG_PERF_REGISTER:
1759   - return probe_perf_enable(event);
  1739 + return enable_trace_probe(tp, TP_FLAG_PROFILE);
1760 1740 case TRACE_REG_PERF_UNREGISTER:
1761   - probe_perf_disable(event);
  1741 + disable_trace_probe(tp, TP_FLAG_PROFILE);
1762 1742 return 0;
1763 1743 #endif
1764 1744 }
... ... @@ -1905,7 +1885,7 @@
1905 1885 pr_warning("error on getting new probe.\n");
1906 1886 warn++;
1907 1887 } else
1908   - probe_event_enable(&tp->call);
  1888 + enable_trace_probe(tp, TP_FLAG_TRACE);
1909 1889 }
1910 1890  
1911 1891 ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target "
... ... @@ -1920,7 +1900,7 @@
1920 1900 pr_warning("error on getting new probe.\n");
1921 1901 warn++;
1922 1902 } else
1923   - probe_event_enable(&tp->call);
  1903 + enable_trace_probe(tp, TP_FLAG_TRACE);
1924 1904 }
1925 1905  
1926 1906 if (warn)