Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Apr 2016 07:52:09 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r297658 - stable/10/sys/ofed/include/asm
Message-ID:  <201604070752.u377q9vg082724@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Apr  7 07:52:09 2016
New Revision: 297658
URL: https://svnweb.freebsd.org/changeset/base/297658

Log:
  MFC r294520:
  LinuxKPI atomic fixes:
  - Fix implementation of atomic_add_unless(). The atomic_cmpset_int()
    function returns a boolean and not the previous value of the atomic
    variable.
  - The atomic counters should be signed according to Linux.
  - Some minor cosmetics and styling while at it.
  
  Reviewed by:	alfred @
  Sponsored by:	Mellanox Technologies

Modified:
  stable/10/sys/ofed/include/asm/atomic-long.h
  stable/10/sys/ofed/include/asm/atomic.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ofed/include/asm/atomic-long.h
==============================================================================
--- stable/10/sys/ofed/include/asm/atomic-long.h	Thu Apr  7 07:45:31 2016	(r297657)
+++ stable/10/sys/ofed/include/asm/atomic-long.h	Thu Apr  7 07:52:09 2016	(r297658)
@@ -35,7 +35,7 @@
 #include <machine/atomic.h>
 
 typedef struct {
-	volatile u_long counter;
+	volatile long counter;
 } atomic_long_t;
 
 #define	atomic_long_add(i, v)		atomic_long_add_return((i), (v))

Modified: stable/10/sys/ofed/include/asm/atomic.h
==============================================================================
--- stable/10/sys/ofed/include/asm/atomic.h	Thu Apr  7 07:45:31 2016	(r297657)
+++ stable/10/sys/ofed/include/asm/atomic.h	Thu Apr  7 07:52:09 2016	(r297658)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -35,9 +35,13 @@
 #include <machine/atomic.h>
 
 typedef struct {
-	volatile u_int counter;
+	volatile int counter;
 } atomic_t;
 
+/*------------------------------------------------------------------------*
+ *	32-bit atomic operations
+ *------------------------------------------------------------------------*/
+
 #define	atomic_add(i, v)		atomic_add_return((i), (v))
 #define	atomic_sub(i, v)		atomic_sub_return((i), (v))
 #define	atomic_inc_return(v)		atomic_add_return(1, (v))
@@ -45,7 +49,8 @@ typedef struct {
 #define	atomic_sub_and_test(i, v)	(atomic_sub_return((i), (v)) == 0)
 #define	atomic_dec_and_test(v)		(atomic_sub_return(1, (v)) == 0)
 #define	atomic_inc_and_test(v)		(atomic_add_return(1, (v)) == 0)
-#define atomic_dec_return(v)             atomic_sub_return(1, (v))
+#define	atomic_dec_return(v)		atomic_sub_return(1, (v))
+#define	atomic_inc_not_zero(v)		atomic_add_unless((v), 1, 0)
 
 static inline int
 atomic_add_return(int i, atomic_t *v)
@@ -83,24 +88,19 @@ atomic_dec(atomic_t *v)
 	return atomic_fetchadd_int(&v->counter, -1) - 1;
 }
 
-static inline int atomic_add_unless(atomic_t *v, int a, int u)
+static inline int
+atomic_add_unless(atomic_t *v, int a, int u)
 {
-        int c, old;
-        c = atomic_read(v);
-        for (;;) {
-                if (unlikely(c == (u)))
-                        break;
-                old = atomic_cmpset_int(&v->counter, c, c + (a));
-                if (likely(old == c))
-                        break;
-                c = old;
-        }
-        return c != (u);
-}
-
-#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
-
-
+	int c;
 
+	for (;;) {
+		c = atomic_read(v);
+		if (unlikely(c == u))
+			break;
+		if (likely(atomic_cmpset_int(&v->counter, c, c + a)))
+			break;
+	}
+	return (c != u);
+}
 
-#endif	/* _ASM_ATOMIC_H_ */
+#endif					/* _ASM_ATOMIC_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604070752.u377q9vg082724>