From owner-svn-src-head@freebsd.org Thu Jan 21 17:52:57 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 41DA8A8C09B; Thu, 21 Jan 2016 17:52:57 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1E1F911CD; Thu, 21 Jan 2016 17:52:57 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0LHqurJ022231; Thu, 21 Jan 2016 17:52:56 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0LHquRG022228; Thu, 21 Jan 2016 17:52:56 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201601211752.u0LHquRG022228@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 21 Jan 2016 17:52:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294520 - head/sys/compat/linuxkpi/common/include/asm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2016 17:52:57 -0000 Author: hselasky Date: Thu Jan 21 17:52:55 2016 New Revision: 294520 URL: https://svnweb.freebsd.org/changeset/base/294520 Log: 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 @ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h head/sys/compat/linuxkpi/common/include/asm/atomic.h Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic-long.h Thu Jan 21 17:49:10 2016 (r294519) +++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h Thu Jan 21 17:52:55 2016 (r294520) @@ -36,7 +36,7 @@ #include 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: head/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic.h Thu Jan 21 17:49:10 2016 (r294519) +++ head/sys/compat/linuxkpi/common/include/asm/atomic.h Thu Jan 21 17:52:55 2016 (r294520) @@ -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 @@ -36,9 +36,13 @@ #include 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)) @@ -46,7 +50,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) @@ -84,24 +89,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_ */