Skip to content

Commit

Permalink
sunrpc: fix potential races in pool_stats collection
Browse files Browse the repository at this point in the history
In a later patch, we'll be removing some spinlocking around the socket
and thread queueing code in order to fix some contention problems. At
that point, the stats counters will no longer be protected by the
sp_lock.

Change the counters to atomic_long_t fields, except for the
"sockets_queued" counter which will still be manipulated under a
spinlock.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Tested-by: Chris Worley <chris.worley@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Jeff Layton authored and J. Bruce Fields committed Dec 9, 2014
1 parent 8124438 commit 403c7b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/linux/sunrpc/svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ typedef int (*svc_thread_fn)(void *);

/* statistics for svc_pool structures */
struct svc_pool_stats {
unsigned long packets;
atomic_long_t packets;
unsigned long sockets_queued;
unsigned long threads_woken;
unsigned long threads_timedout;
atomic_long_t threads_woken;
atomic_long_t threads_timedout;
};

/*
Expand Down
12 changes: 6 additions & 6 deletions net/sunrpc/svc_xprt.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void svc_xprt_do_enqueue(struct svc_xprt *xprt)
pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
spin_lock_bh(&pool->sp_lock);

pool->sp_stats.packets++;
atomic_long_inc(&pool->sp_stats.packets);

if (!list_empty(&pool->sp_threads)) {
rqstp = list_entry(pool->sp_threads.next,
Expand All @@ -383,7 +383,7 @@ static void svc_xprt_do_enqueue(struct svc_xprt *xprt)
svc_xprt_get(xprt);
wake_up_process(rqstp->rq_task);
rqstp->rq_xprt = xprt;
pool->sp_stats.threads_woken++;
atomic_long_inc(&pool->sp_stats.threads_woken);
} else {
dprintk("svc: transport %p put into queue\n", xprt);
list_add_tail(&xprt->xpt_ready, &pool->sp_sockets);
Expand Down Expand Up @@ -669,7 +669,7 @@ static struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout)

spin_lock_bh(&pool->sp_lock);
if (!time_left)
pool->sp_stats.threads_timedout++;
atomic_long_inc(&pool->sp_stats.threads_timedout);

xprt = rqstp->rq_xprt;
if (!xprt) {
Expand Down Expand Up @@ -1306,10 +1306,10 @@ static int svc_pool_stats_show(struct seq_file *m, void *p)

seq_printf(m, "%u %lu %lu %lu %lu\n",
pool->sp_id,
pool->sp_stats.packets,
(unsigned long)atomic_long_read(&pool->sp_stats.packets),
pool->sp_stats.sockets_queued,
pool->sp_stats.threads_woken,
pool->sp_stats.threads_timedout);
(unsigned long)atomic_long_read(&pool->sp_stats.threads_woken),
(unsigned long)atomic_long_read(&pool->sp_stats.threads_timedout));

return 0;
}
Expand Down

0 comments on commit 403c7b4

Please sign in to comment.