]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
sdp: make sdp_prf index atomic
authorAmir Vadai <amirv@mellanox.co.il>
Tue, 14 Dec 2010 07:55:54 +0000 (09:55 +0200)
committerMukesh Kacker <mukesh.kacker@oracle.com>
Tue, 6 Oct 2015 12:05:36 +0000 (05:05 -0700)
Will make sdpprf more reliable - records won't override other records.

Signed-off-by: Amir Vadai <amirv@mellanox.co.il>
drivers/infiniband/ulp/sdp/sdp_dbg.h
drivers/infiniband/ulp/sdp/sdp_proc.c

index a0a4d85eb4ff0539bfe6996e5b1f5d2bb179025d..cb00b85be42fb815fa82b6731c33a2b1d135831b 100644 (file)
@@ -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; \
index aa825dcf3823281c84e564d2f4c6054834a93c74..33f66b6a2393f358903df839b230e011db7181f9 100644 (file)
@@ -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;