Skip to content

Commit

Permalink
sunrpc: Add static trace point to report RPC latency stats
Browse files Browse the repository at this point in the history
Introduce a low-overhead mechanism to report information about
latencies of individual RPCs. The goal is to enable user space to
filter the trace record for latency outliers, or build histograms,
etc.

Signed-off-by: Chuck Lever <[email protected]>
Signed-off-by: Anna Schumaker <[email protected]>
  • Loading branch information
chucklever authored and amschuma-ntap committed Apr 10, 2018
1 parent e671edb commit 40bf7eb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
45 changes: 45 additions & 0 deletions include/trace/events/sunrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,51 @@ DEFINE_EVENT(rpc_task_queued, rpc_task_wakeup,

);

TRACE_EVENT(rpc_stats_latency,

TP_PROTO(
const struct rpc_task *task,
ktime_t backlog,
ktime_t rtt,
ktime_t execute
),

TP_ARGS(task, backlog, rtt, execute),

TP_STRUCT__entry(
__field(u32, xid)
__field(int, version)
__string(progname, task->tk_client->cl_program->name)
__string(procname, rpc_proc_name(task))
__field(unsigned long, backlog)
__field(unsigned long, rtt)
__field(unsigned long, execute)
__string(addr,
task->tk_xprt->address_strings[RPC_DISPLAY_ADDR])
__string(port,
task->tk_xprt->address_strings[RPC_DISPLAY_PORT])
),

TP_fast_assign(
__entry->xid = be32_to_cpu(task->tk_rqstp->rq_xid);
__entry->version = task->tk_client->cl_vers;
__assign_str(progname, task->tk_client->cl_program->name)
__assign_str(procname, rpc_proc_name(task))
__entry->backlog = ktime_to_us(backlog);
__entry->rtt = ktime_to_us(rtt);
__entry->execute = ktime_to_us(execute);
__assign_str(addr,
task->tk_xprt->address_strings[RPC_DISPLAY_ADDR]);
__assign_str(port,
task->tk_xprt->address_strings[RPC_DISPLAY_PORT]);
),

TP_printk("peer=[%s]:%s xid=0x%08x %sv%d %s backlog=%lu rtt=%lu execute=%lu",
__get_str(addr), __get_str(port), __entry->xid,
__get_str(progname), __entry->version, __get_str(procname),
__entry->backlog, __entry->rtt, __entry->execute)
);

/*
* First define the enums in the below macros to be exported to userspace
* via TRACE_DEFINE_ENUM().
Expand Down
16 changes: 11 additions & 5 deletions net/sunrpc/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <linux/sunrpc/metrics.h>
#include <linux/rcupdate.h>

#include <trace/events/sunrpc.h>

#include "netns.h"

#define RPCDBG_FACILITY RPCDBG_MISC
Expand Down Expand Up @@ -148,7 +150,7 @@ void rpc_count_iostats_metrics(const struct rpc_task *task,
struct rpc_iostats *op_metrics)
{
struct rpc_rqst *req = task->tk_rqstp;
ktime_t delta, now;
ktime_t backlog, execute, now;

if (!op_metrics || !req)
return;
Expand All @@ -164,16 +166,20 @@ void rpc_count_iostats_metrics(const struct rpc_task *task,
op_metrics->om_bytes_sent += req->rq_xmit_bytes_sent;
op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd;

backlog = 0;
if (ktime_to_ns(req->rq_xtime)) {
delta = ktime_sub(req->rq_xtime, task->tk_start);
op_metrics->om_queue = ktime_add(op_metrics->om_queue, delta);
backlog = ktime_sub(req->rq_xtime, task->tk_start);
op_metrics->om_queue = ktime_add(op_metrics->om_queue, backlog);
}

op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt);

delta = ktime_sub(now, task->tk_start);
op_metrics->om_execute = ktime_add(op_metrics->om_execute, delta);
execute = ktime_sub(now, task->tk_start);
op_metrics->om_execute = ktime_add(op_metrics->om_execute, execute);

spin_unlock(&op_metrics->om_lock);

trace_rpc_stats_latency(req->rq_task, backlog, req->rq_rtt, execute);
}
EXPORT_SYMBOL_GPL(rpc_count_iostats_metrics);

Expand Down

0 comments on commit 40bf7eb

Please sign in to comment.