From 01a02e604b9a5f666609d6a894ff66305d1e9f6d Mon Sep 17 00:00:00 2001 From: Amir Vadai Date: Tue, 14 Dec 2010 09:55:54 +0200 Subject: [PATCH] sdp: make sdp_prf index atomic Will make sdpprf more reliable - records won't override other records. Signed-off-by: Amir Vadai --- drivers/infiniband/ulp/sdp/sdp_dbg.h | 7 ++++--- drivers/infiniband/ulp/sdp/sdp_proc.c | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/infiniband/ulp/sdp/sdp_dbg.h b/drivers/infiniband/ulp/sdp/sdp_dbg.h index a0a4d85eb4ff..cb00b85be42f 100644 --- a/drivers/infiniband/ulp/sdp/sdp_dbg.h +++ b/drivers/infiniband/ulp/sdp/sdp_dbg.h @@ -61,13 +61,14 @@ struct sdpprf_log { #define SDPPRF_LOG_SIZE 0x20000 /* must be a power of 2 */ extern struct sdpprf_log sdpprf_log[SDPPRF_LOG_SIZE]; -extern int sdpprf_log_count; +extern atomic_t sdpprf_log_count; #define _sdp_prf(sk, s, _func, _line, format, arg...) ({ \ + int idx = atomic_add_return(1, &sdpprf_log_count); \ struct sdpprf_log *l = \ - &sdpprf_log[sdpprf_log_count++ & (SDPPRF_LOG_SIZE - 1)]; \ + &sdpprf_log[idx & (SDPPRF_LOG_SIZE - 1)]; \ preempt_disable(); \ - l->idx = sdpprf_log_count - 1; \ + l->idx = idx; \ l->pid = current->pid; \ l->sk_num = (sk) ? inet_sk(sk)->num : -1; \ l->sk_dport = (sk) ? ntohs(inet_sk(sk)->dport) : -1; \ diff --git a/drivers/infiniband/ulp/sdp/sdp_proc.c b/drivers/infiniband/ulp/sdp/sdp_proc.c index aa825dcf3823..33f66b6a2393 100644 --- a/drivers/infiniband/ulp/sdp/sdp_proc.c +++ b/drivers/infiniband/ulp/sdp/sdp_proc.c @@ -417,7 +417,7 @@ static struct file_operations sdpstats_fops = { #ifdef SDP_PROFILING struct sdpprf_log sdpprf_log[SDPPRF_LOG_SIZE]; -int sdpprf_log_count; +atomic_t sdpprf_log_count; static cycles_t start_t; @@ -435,7 +435,7 @@ static int sdpprf_show(struct seq_file *m, void *v) struct sdpprf_log *l = v; unsigned long usec_rem, t; - if (!sdpprf_log_count) { + if (!atomic_read(&sdpprf_log_count)) { seq_printf(m, "No performance logs\n"); goto out; } @@ -457,15 +457,15 @@ static void *sdpprf_start(struct seq_file *p, loff_t *pos) int idx = *pos; if (!*pos) { - if (!sdpprf_log_count) + if (!atomic_read(&sdpprf_log_count)) return SEQ_START_TOKEN; } - if (*pos >= MIN(sdpprf_log_count, SDPPRF_LOG_SIZE - 1)) + if (*pos >= MIN(atomic_read(&sdpprf_log_count), SDPPRF_LOG_SIZE - 1)) return NULL; - if (sdpprf_log_count >= SDPPRF_LOG_SIZE - 1) { - int off = sdpprf_log_count & (SDPPRF_LOG_SIZE - 1); + if (atomic_read(&sdpprf_log_count) >= SDPPRF_LOG_SIZE - 1) { + int off = atomic_read(&sdpprf_log_count) & (SDPPRF_LOG_SIZE - 1); idx = (idx + off) & (SDPPRF_LOG_SIZE - 1); } @@ -479,7 +479,7 @@ static void *sdpprf_next(struct seq_file *p, void *v, loff_t *pos) { struct sdpprf_log *l = v; - if (++*pos >= MIN(sdpprf_log_count, SDPPRF_LOG_SIZE - 1)) + if (++*pos >= MIN(atomic_read(&sdpprf_log_count), SDPPRF_LOG_SIZE - 1)) return NULL; ++l; @@ -512,7 +512,7 @@ static int sdpprf_open(struct inode *inode, struct file *file) static ssize_t sdpprf_write(struct file *file, const char __user *buf, size_t count, loff_t *offs) { - sdpprf_log_count = 0; + atomic_set(&sdpprf_log_count, 0); printk(KERN_INFO "Cleared sdpprf statistics\n"); return count; -- 2.50.1