From: Chuck Lever <chuck.lever@oracle.com>
To: linux-rdma@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: [PATCH v2 08/10] SUNRPC: serialize iostats updates
Date: Sat, 08 Nov 2014 20:15:09 -0500 [thread overview]
Message-ID: <20141109011509.8806.40278.stgit@manet.1015granger.net> (raw)
In-Reply-To: <20141109010328.8806.5861.stgit@manet.1015granger.net>
Occasionally mountstats reports a negative retransmission rate.
Ensure that two RPCs completing concurrently don't confuse the sums
in the transport's op_metrics array.
Since pNFS filelayout can invoke rpc_count_iostats() on another
transport from xprt_release(), we can't rely on simply holding the
transport_lock in xprt_release(). There's nothing for it but hard
serialization. One spin lock per RPC operation should make this as
painless as it can be.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
include/linux/sunrpc/metrics.h | 3 +++
net/sunrpc/stats.c | 21 ++++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/include/linux/sunrpc/metrics.h b/include/linux/sunrpc/metrics.h
index 1565bbe..eecb5a7 100644
--- a/include/linux/sunrpc/metrics.h
+++ b/include/linux/sunrpc/metrics.h
@@ -27,10 +27,13 @@
#include <linux/seq_file.h>
#include <linux/ktime.h>
+#include <linux/spinlock.h>
#define RPC_IOSTATS_VERS "1.0"
struct rpc_iostats {
+ spinlock_t om_lock;
+
/*
* These counters give an idea about how many request
* transmissions are required, on average, to complete that
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
index 5453049..9711a15 100644
--- a/net/sunrpc/stats.c
+++ b/net/sunrpc/stats.c
@@ -116,7 +116,15 @@ EXPORT_SYMBOL_GPL(svc_seq_show);
*/
struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt)
{
- return kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL);
+ struct rpc_iostats *stats;
+ int i;
+
+ stats = kcalloc(clnt->cl_maxproc, sizeof(*stats), GFP_KERNEL);
+ if (stats) {
+ for (i = 0; i < clnt->cl_maxproc; i++)
+ spin_lock_init(&stats[i].om_lock);
+ }
+ return stats;
}
EXPORT_SYMBOL_GPL(rpc_alloc_iostats);
@@ -135,20 +143,21 @@ EXPORT_SYMBOL_GPL(rpc_free_iostats);
* rpc_count_iostats - tally up per-task stats
* @task: completed rpc_task
* @stats: array of stat structures
- *
- * Relies on the caller for serialization.
*/
void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats)
{
struct rpc_rqst *req = task->tk_rqstp;
struct rpc_iostats *op_metrics;
- ktime_t delta;
+ ktime_t delta, now;
if (!stats || !req)
return;
+ now = ktime_get();
op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx];
+ spin_lock(&op_metrics->om_lock);
+
op_metrics->om_ops++;
op_metrics->om_ntrans += req->rq_ntrans;
op_metrics->om_timeouts += task->tk_timeouts;
@@ -161,8 +170,10 @@ void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats)
op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt);
- delta = ktime_sub(ktime_get(), task->tk_start);
+ delta = ktime_sub(now, task->tk_start);
op_metrics->om_execute = ktime_add(op_metrics->om_execute, delta);
+
+ spin_unlock(&op_metrics->om_lock);
}
EXPORT_SYMBOL_GPL(rpc_count_iostats);
next prev parent reply other threads:[~2014-11-09 1:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-09 1:14 [PATCH v2 00/10] NFS/RDMA patches for 3.19 Chuck Lever
2014-11-09 1:14 ` [PATCH v2 01/10] xprtrdma: Return an errno from rpcrdma_register_external() Chuck Lever
2014-11-09 1:14 ` [PATCH v2 02/10] xprtrdma: Cap req_cqinit Chuck Lever
2014-11-09 10:13 ` Sagi Grimberg
2014-11-09 21:43 ` Chuck Lever
2014-11-09 1:14 ` [PATCH v2 03/10] xprtrdma: unmap all FMRs during transport disconnect Chuck Lever
2014-11-09 1:14 ` [PATCH v2 04/10] xprtrdma: Refactor tasklet scheduling Chuck Lever
2014-11-09 1:14 ` [PATCH v2 05/10] xprtrdma: Re-write rpcrdma_flush_cqs() Chuck Lever
2014-11-09 1:14 ` [PATCH v2 06/10] xprtrdma: Enable pad optimization Chuck Lever
2014-11-10 14:36 ` Anna Schumaker
2014-11-10 14:54 ` Chuck Lever
2014-11-10 15:05 ` J. Bruce Fields
2014-11-09 1:15 ` [PATCH v2 07/10] xprtrdma: Display async errors Chuck Lever
2014-11-11 14:30 ` Sagi Grimberg
2014-11-11 16:52 ` Chuck Lever
2014-11-11 18:49 ` Sagi Grimberg
2014-11-11 20:30 ` Or Gerlitz
2014-11-09 1:15 ` Chuck Lever [this message]
2014-11-09 1:15 ` [PATCH v2 09/10] NFS: SETCLIENTID XDR buffer sizes are incorrect Chuck Lever
2014-11-10 15:22 ` Anna Schumaker
2014-11-10 16:21 ` Trond Myklebust
2014-11-09 1:15 ` [PATCH v2 10/10] NFS: Clean up nfs4_init_callback() Chuck Lever
2014-11-26 16:25 ` [PATCH v2 00/10] NFS/RDMA patches for 3.19 Anna Schumaker
2014-11-26 16:36 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141109011509.8806.40278.stgit@manet.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox