From a9b9157e4d9f60030f7a8e4e1945f7f39ea15c7e Mon Sep 17 00:00:00 2001 From: ajesh Date: Mon, 23 Sep 2019 11:36:59 +0530 Subject: [PATCH] gpu: nvgpu: add Doxygen documentation for atomic Add Doxygen documentation details for atomic unit. Jira NVGPU-2596 Change-Id: I6b6d63569bd3452b3e9a9e49d45b1524dd1a10f3 Signed-off-by: ajesh Reviewed-on: https://git-master.nvidia.com/r/2203511 Reviewed-by: Philip Elcan Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/atomic.h | 341 +++++++++++++++- .../gpu/nvgpu/include/nvgpu/posix/atomic.h | 377 +++++++++++++++++- 2 files changed, 711 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/atomic.h b/drivers/gpu/nvgpu/include/nvgpu/atomic.h index 4e46ec0cb..8b0f0a2be 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/atomic.h +++ b/drivers/gpu/nvgpu/include/nvgpu/atomic.h @@ -28,135 +28,474 @@ #include #endif +/** Initialize nvgpu atomic structure. */ #define NVGPU_ATOMIC_INIT(i) nvgpu_atomic_init_impl(i) +/** Initialize 64 bit nvgpu atomic structure. */ #define NVGPU_ATOMIC64_INIT(i) nvgpu_atomic64_init_impl(i) +/** + * @brief Set atomic variable. + * + * @param v [in] Structure holding atomic variable. + * @param i [in] Value to set. + * + * Sets the value \a i atomically in structure \a v. + */ static inline void nvgpu_atomic_set(nvgpu_atomic_t *v, int i) { nvgpu_atomic_set_impl(v, i); } + +/** + * @brief Read atomic variable. + * + * @param v [in] Structure holding atomic variable to read. + * + * Atomically reads the value from structure \a v. + * + * @return Value read from the atomic variable. + */ static inline int nvgpu_atomic_read(nvgpu_atomic_t *v) { return nvgpu_atomic_read_impl(v); } + +/** + * @brief Increment the atomic variable. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v. + */ static inline void nvgpu_atomic_inc(nvgpu_atomic_t *v) { nvgpu_atomic_inc_impl(v); } + +/** + * @brief Increment the atomic variable and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increases the value in structure \a v and returns. + * + * @return Value in atomic variable incremented by 1. + */ static inline int nvgpu_atomic_inc_return(nvgpu_atomic_t *v) { return nvgpu_atomic_inc_return_impl(v); } + +/** + * @brief Decrement the atomic variable. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure \a v. + */ static inline void nvgpu_atomic_dec(nvgpu_atomic_t *v) { - nvgpu_atomic_dec_impl(v); + nvgpu_atomic_dec_impl(v); } + +/** + * @brief Decrement the atomic variable and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure v and returns. + * + * @return Value in atomic variable decremented by 1. + */ static inline int nvgpu_atomic_dec_return(nvgpu_atomic_t *v) { return nvgpu_atomic_dec_return_impl(v); } + +/** + * @brief Compare and exchange the value in atomic variable. + * + * @param v [in] Structure holding atomic variable. + * @param old [in] Value to compare. + * @param new [in] Value to store. + * + * Reads the value stored in \a v, replace the value with \a new if the read + * value is equal to \a old. In cases where the current value in \a v is not + * equal to \a old, this function acts as a read operation of atomic variable. + * + * @return Reads the value in \a v before the exchange operation and returns. + * Read value is returned irrespective of whether the exchange operation is + * carried out or not. + */ static inline int nvgpu_atomic_cmpxchg(nvgpu_atomic_t *v, int old, int new) { return nvgpu_atomic_cmpxchg_impl(v, old, new); } + +/** + * @brief Exchange the value in atomic variable. + * + * @param v [in] Structure holding atomic variable. + * @param new [in] Value to set. + * + * Atomically exchanges the value stored in \a v with \a new. + * + * @return Value in atomic variable before the operation. + */ static inline int nvgpu_atomic_xchg(nvgpu_atomic_t *v, int new) { return nvgpu_atomic_xchg_impl(v, new); } + +/** + * @brief Increment the atomic variable and test for zero. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value stored in \a v and returns true if + * the result is zero. Returns false in other cases. + * + * @return TRUE if the operation results in zero, otherwise returns FALSE. + */ static inline bool nvgpu_atomic_inc_and_test(nvgpu_atomic_t *v) { return nvgpu_atomic_inc_and_test_impl(v); } + +/** + * @brief Decrement the atomic variable and test for zero. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value stored in \a v and returns true if + * the result is zero. Returns false in other cases. + * + * @return TRUE if the operation results in zero, otherwise returns FALSE. + */ static inline bool nvgpu_atomic_dec_and_test(nvgpu_atomic_t *v) { return nvgpu_atomic_dec_and_test_impl(v); } + +/** + * @brief Subtract integer from atomic variable and test. + * + * @param i [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a i from the value stored in \a v and returns true if + * the result is zero. Returns false in other cases. + * + * @return TRUE if the subtraction results in zero, otherwise returns FALSE. + */ static inline bool nvgpu_atomic_sub_and_test(int i, nvgpu_atomic_t *v) { return nvgpu_atomic_sub_and_test_impl(i, v); } + +/** + * @brief Add integer to atomic variable. + * + * @param i [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds \a i to the value stored in structure \a v. + */ static inline void nvgpu_atomic_add(int i, nvgpu_atomic_t *v) { nvgpu_atomic_add_impl(i, v); } + +/** + * @brief Subtract integer form atomic variable and return. + * + * @param i [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a i from the value stored in structure \a v and + * returns. + * + * @return \a i subtracted from \a v is returned. + */ static inline int nvgpu_atomic_sub_return(int i, nvgpu_atomic_t *v) { return nvgpu_atomic_sub_return_impl(i, v); } + +/** + * @brief Subtract integer from atomic variable. + * + * @param i [in] Value to set. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a i from the value stored in structure \a v. + */ static inline void nvgpu_atomic_sub(int i, nvgpu_atomic_t *v) { nvgpu_atomic_sub_impl(i, v); } + +/** + * @brief Add integer to atomic variable and return. + * + * @param i [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds \a i to the value in structure \a v and returns. + * + * @return Current value in \a v added with \a i is returned. + */ static inline int nvgpu_atomic_add_return(int i, nvgpu_atomic_t *v) { return nvgpu_atomic_add_return_impl(i, v); } + +/** + * @brief Add integer to atomic variable on unless condition. + * + * @param v [in] Structure holding atomic variable. + * @param a [in] Value to add. + * @param u [in] Value to check. + * + * Atomically adds \a a to \a v if \a v is not \a u. + * + * @return Value in the atomic variable before the operation. + */ static inline int nvgpu_atomic_add_unless(nvgpu_atomic_t *v, int a, int u) { return nvgpu_atomic_add_unless_impl(v, a, u); } + +/** + * @brief Set the 64 bit atomic variable. + * + * @param v [in] Structure holding atomic variable. + * @param i [in] Value to set. + * + * Atomically sets the 64 bit value \a i in structure \a v. + */ static inline void nvgpu_atomic64_set(nvgpu_atomic64_t *v, long x) { return nvgpu_atomic64_set_impl(v, x); } + +/** + * @brief Read the 64 bit atomic variable. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically reads the 64 bit value in structure \a v. + * + * @return Value read from the atomic variable. + */ static inline long nvgpu_atomic64_read(nvgpu_atomic64_t *v) { return nvgpu_atomic64_read_impl(v); } + +/** + * @brief Addition of 64 bit integer to atomic variable. + * + * @param x [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds the 64 bit value \a x to \a v. + */ static inline void nvgpu_atomic64_add(long x, nvgpu_atomic64_t *v) { nvgpu_atomic64_add_impl(x, v); } + +/** + * @brief Increment the 64 bit atomic variable. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v. + */ static inline void nvgpu_atomic64_inc(nvgpu_atomic64_t *v) { nvgpu_atomic64_inc_impl(v); } + +/** + * @brief Increment the 64 bit atomic variable and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v and returns. + * + * @return Value in atomic variable incremented by 1. + */ static inline long nvgpu_atomic64_inc_return(nvgpu_atomic64_t *v) { return nvgpu_atomic64_inc_return_impl(v); } + +/** + * @brief Decrement the 64 bit atomic variable. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure \a v. + */ static inline void nvgpu_atomic64_dec(nvgpu_atomic64_t *v) { nvgpu_atomic64_dec_impl(v); } + +/** + * @brief Decrement the 64 bit atomic variable and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure \a v and returns. + * + * @return Value in atomic variable decremented by 1. + */ static inline long nvgpu_atomic64_dec_return(nvgpu_atomic64_t *v) { return nvgpu_atomic64_dec_return_impl(v); } + +/** + * @brief Exchange the 64 bit atomic variable value. + * + * @param v [in] Structure holding atomic variable. + * @param new [in] Value to set. + * + * Atomically exchanges the value \a new with the value in \a v. + * + * @return Value in the atomic variable before the exchange operation. + */ static inline long nvgpu_atomic64_xchg(nvgpu_atomic64_t *v, long new) { return nvgpu_atomic64_xchg_impl(v, new); } + +/** + * @brief Compare and exchange the 64 bit atomic variable value. + * + * @param v [in] Structure holding atomic variable. + * @param old [in] Value to compare. + * @param new [in] Value to exchange. + + * Reads the value stored in \a v, replace the value with \a new if the read + * value is equal to \a old. In cases where the current value in \a v is not + * equal to \a old, this function acts as a read operation of atomic variable. + * + * @return Returns the original value in atomic variable. + */ static inline long nvgpu_atomic64_cmpxchg(nvgpu_atomic64_t *v, long old, long new) { return nvgpu_atomic64_cmpxchg_impl(v, old, new); } + +/** + * @brief Addition of 64 bit integer to atomic variable and return. + * + * @param x [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically add the value x with v and returns. + * + * @return Current value in atomic variable added with \a x. + */ static inline long nvgpu_atomic64_add_return(long x, nvgpu_atomic64_t *v) { return nvgpu_atomic64_add_return_impl(x, v); } + +/** + * @brief Addition of 64 bit atomic variable on unless condition. + * + * @param v [in] Structure holding atomic variable. + * @param a [in] Value to add. + * @param u [in] Value to check. + * + * Atomically adds 64 bit value \a a to \a v if \a v is not \a u. + * + * @return Value in atomic variable before the operation. + */ static inline long nvgpu_atomic64_add_unless(nvgpu_atomic64_t *v, long a, long u) { return nvgpu_atomic64_add_unless_impl(v, a, u); } + +/** + * @brief Subtraction of 64 bit integer from atomic variable. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts the 64 bit value \a x from structure \a v. + */ static inline void nvgpu_atomic64_sub(long x, nvgpu_atomic64_t *v) { nvgpu_atomic64_sub_impl(x, v); } + +/** + * @brief Increment the 64 bit atomic variable and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value stored in \a v and test. Returns true if + * the incremented value is 0 else returns false. + * + * @return TRUE if the result of the operation is equal to zero, otherwise + * returns FALSE. + */ static inline bool nvgpu_atomic64_inc_and_test(nvgpu_atomic64_t *v) { return nvgpu_atomic64_inc_and_test_impl(v); } + +/** + * @brief Decrement the 64 bit atomic variable and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value stored in \a v and test. Returns true if + * the decremented value is 0 else returns false. + * + * @return TRUE if the result of the operation is equal to zero, otherwise + * returns FALSE. + */ static inline bool nvgpu_atomic64_dec_and_test(nvgpu_atomic64_t *v) { return nvgpu_atomic64_dec_and_test_impl(v); } + +/** + * @brief Subtract 64 bit integer from atomic variable and test. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a x from \a v and returns true if the result is 0. + * Else returns false. + * + * @return TRUE if the result of the operation is equal to zero, otherwise + * returns FALSE. + */ static inline bool nvgpu_atomic64_sub_and_test(long x, nvgpu_atomic64_t *v) { return nvgpu_atomic64_sub_and_test_impl(x, v); } + +/** + * @brief Subtract 64 bit integer from atomic variable and return. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a x from \a v and returns. + * + * @return \a x subtracted from the current value in atomic variable. + */ static inline long nvgpu_atomic64_sub_return(long x, nvgpu_atomic64_t *v) { return nvgpu_atomic64_sub_return_impl(x, v); diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h b/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h index bbede440a..7935a5dde 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h @@ -33,26 +33,56 @@ */ typedef struct __nvgpu_posix_atomic { + /** 32 bit atomic variable. */ atomic_int v; } nvgpu_atomic_t; typedef struct __nvgpu_posix_atomic64 { + /** 64 bit atomic variable. */ atomic_long v; } nvgpu_atomic64_t; +/** + * POSIX implementation for 32 bit atomic initialization. Defined to be + * congruent with kernel define names. + */ #define nvgpu_atomic_init_impl(i) { i } +/** + * POSIX implementation for 64 bit atomic initialization. Defined to be + * congruent with kernel define names. + */ #define nvgpu_atomic64_init_impl(i) { i } /* * These macros define the common cases to maximize code reuse, especially - * between the 32bit and 64bit cases. - * The static inline functions are maintained to provide type checking. + * between the 32bit and 64bit cases. The static inline functions are + * maintained to provide type checking. + */ + +/** + * @brief Define for atomic set. + * + * @param v Atomic variable to be set. + * @param i Value to set in atomic variable. */ #define NVGPU_POSIX_ATOMIC_SET(v, i) atomic_store(&((v)->v), (i)) +/** + * @brief Define for atomic read. + * + * @param v Atomic variable to be read. + */ #define NVGPU_POSIX_ATOMIC_READ(v) atomic_load(&((v)->v)) +/** + * @brief Define for atomic add and return. + * + * @param v Atomic variable. + * @param i Value to add. + * + * @return Returns \a i added with the current value in atomic variable. + */ #define NVGPU_POSIX_ATOMIC_ADD_RETURN(v, i) \ ({ \ typeof((v)->v) tmp; \ @@ -65,6 +95,14 @@ typedef struct __nvgpu_posix_atomic64 { tmp; \ }) +/** + * @brief Define for atomic subtract and return. + * + * @param v Atomic variable. + * @param i Value to subtract. + * + * @return Subtracts \a i from the current value in atomic variable and returns. + */ #define NVGPU_POSIX_ATOMIC_SUB_RETURN(v, i) \ ({ \ typeof((v)->v) tmp; \ @@ -77,6 +115,17 @@ typedef struct __nvgpu_posix_atomic64 { tmp; \ }) +/** + * @brief Define for atomic compare exchange. + * + * @param v Atomic variable. + * @param old Value to compare. + * @param new Value to exchange. + * + * @return If \a old matches with the current value in \a v, \a new is written + * into \a v and value of \a old is returned. If \a old does not match with + * the current value in \a v then the current value in \a v is returned. + */ #define NVGPU_POSIX_ATOMIC_CMPXCHG(v, old, new) \ ({ \ typeof((v)->v) tmp = (old); \ @@ -85,83 +134,242 @@ typedef struct __nvgpu_posix_atomic64 { tmp; \ }) +/** + * @brief Define for atomic exchange. + * + * @param v Atomic variable. + * @param new Value to exchange. + * + * @return Original value in the atomic variable. + */ #define NVGPU_POSIX_ATOMIC_XCHG(v, new) atomic_exchange(&((v)->v), (new)) +/** + * @brief POSIX implementation of atomic set. + * + * @param v [in] Structure holding atomic variable. + * @param i [in] Value to set. + * + * Sets the value mentioned by \a i atomically in structure \a v. + */ static inline void nvgpu_atomic_set_impl(nvgpu_atomic_t *v, int i) { NVGPU_POSIX_ATOMIC_SET(v, i); } +/** + * @brief POSIX implementation of atomic read. + * + * @param v [in] Structure holding atomic variable to read. + * + * Atomically reads the value from structure \a v. + * + * @return Value read from the atomic variable. + */ static inline int nvgpu_atomic_read_impl(nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_READ(v); } +/** + * @brief POSIX implementation of atomic increment. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v. + */ + static inline void nvgpu_atomic_inc_impl(nvgpu_atomic_t *v) { (void)NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1); } +/** + * @brief POSIX implementation of atomic increment and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increases the value in structure \a v and returns. + * + * @return Increments the value in \a v by 1 and returns. + */ static inline int nvgpu_atomic_inc_return_impl(nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1); } - +/** + * @brief POSIX implementation of atomic decrement. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrement the value in structure \a v. + */ static inline void nvgpu_atomic_dec_impl(nvgpu_atomic_t *v) { (void)NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1); } +/** + * @brief POSIX implementation of atomic decrement and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure v and returns. + * + * @return Value in \a v is decremented by 1 and returned. + */ static inline int nvgpu_atomic_dec_return_impl(nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1); } - +/** + * @brief POSIX implementation of atomic compare and exchange. + * + * @param v [in] Structure holding atomic variable. + * @param old [in] Value to compare. + * @param new [in] Value to store. + * + * Reads the value stored in structure \a v, replaces the value with \a new if + * the read value is equal to \a old. + * + * @return If \a old matches the current value in \a v, then the value of \a + * old is returned else the current value in \a v is returned. + */ static inline int nvgpu_atomic_cmpxchg_impl(nvgpu_atomic_t *v, int old, int new) { return NVGPU_POSIX_ATOMIC_CMPXCHG(v, old, new); } - +/** + * @brief POSIX implementation of atomic exchange. + * + * @param v [in] Structure holding atomic variable. + * @param new [in] Value to set. + * + * Atomically exchanges the value stored in \a v with \a new. + * + * @return The original value in atomic variable \a v. + */ static inline int nvgpu_atomic_xchg_impl(nvgpu_atomic_t *v, int new) { return NVGPU_POSIX_ATOMIC_XCHG(v, new); } +/** + * @brief POSIX implementation of atomic increment and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value stored in \a v and returns true if + * the result is zero. Returns false in other cases. + * + * @return Returns TRUE if the value in atomic variable is equal to zero after + * incrementing, else returns FALSE. + */ static inline bool nvgpu_atomic_inc_and_test_impl(nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1) == 0; } +/** + * @brief POSIX implementation of atomic decrement and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value stored in \a v and returns true if + * the result is zero. Returns false in other cases. + * + * @return Returns TRUE if the value in atomic variable is equal to zero after + * decrementing, else returns FALSE. + */ static inline bool nvgpu_atomic_dec_and_test_impl(nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1) == 0; } +/** + * @brief POSIX implementation of atomic subtract. + * + * @param i [in] Value to set. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a i from the value stored in structure \a v. + */ static inline void nvgpu_atomic_sub_impl(int i, nvgpu_atomic_t *v) { (void)NVGPU_POSIX_ATOMIC_SUB_RETURN(v, i); } +/** + * @brief POSIX implementation of atomic subtract and return. + * + * @param i [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a i from the value stored in structure \a v and + * returns. + * + * @return Returns \a v minus \a i. + */ static inline int nvgpu_atomic_sub_return_impl(int i, nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, i); } +/** + * @brief POSIX implementation of atomic subtract and test. + * + * @param i [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts i from the value stored in v and returns true if + * the result is zero. Returns false in other cases. + * + * @return Returns TRUE if the subtraction result is equal to zero, otherwise + * returns FALSE. + */ static inline bool nvgpu_atomic_sub_and_test_impl(int i, nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, i) == 0; } +/** + * @brief POSIX implementation of atomic add. + * + * @param i [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds \a i to the value stored in structure \a v. + */ static inline void nvgpu_atomic_add_impl(int i, nvgpu_atomic_t *v) { (void)NVGPU_POSIX_ATOMIC_ADD_RETURN(v, i); } - +/** + * @brief POSIX implementation of atomic add and return. + * + * @param i [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds \a i to the value in structure \a v and returns. + * + * @return \a i added with the current value in \a v. + */ static inline int nvgpu_atomic_add_return_impl(int i, nvgpu_atomic_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, i); } +/** + * @brief POSIX implementation of atomic add unless. + * + * @param v [in] Structure holding atomic variable. + * @param a [in] Value to add. + * @param u [in] Value to check. + * + * Atomically adds \a a to \a v if \a v is not \a u. + * + * @return Value in \a v before the operation. + */ static inline int nvgpu_atomic_add_unless_impl(nvgpu_atomic_t *v, int a, int u) { int old; @@ -176,26 +384,72 @@ static inline int nvgpu_atomic_add_unless_impl(nvgpu_atomic_t *v, int a, int u) return old; } +/** + * @brief POSIX implementation of 64 bit atomic set. + * + * @param v [in] Structure holding atomic variable. + * @param i [in] Value to set. + * + * Atomically sets the 64 bit value \a i in structure \a v. + */ static inline void nvgpu_atomic64_set_impl(nvgpu_atomic64_t *v, long i) { NVGPU_POSIX_ATOMIC_SET(v, i); } +/** + * @brief POSIX implementation of 64 bit atomic read. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically reads the 64 bit value in structure \a v. + * + * @return Current value in atomic variable. + */ static inline long nvgpu_atomic64_read_impl(nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_READ(v); } +/** + * @brief POSIX implementation of 64 bit atomic add. + * + * @param x [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds the 64 bit value \a x to \a v. + */ static inline void nvgpu_atomic64_add_impl(long x, nvgpu_atomic64_t *v) { (void)NVGPU_POSIX_ATOMIC_ADD_RETURN(v, x); } +/** + * @brief POSIX implementation of 64 bit atomic add and return. + * + * @param x [in] Value to add. + * @param v [in] Structure holding atomic variable. + * + * Atomically adds the value \a x with \a v and returns. + * + * @return \a x added with \a v is returned. + */ static inline long nvgpu_atomic64_add_return_impl(long x, nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, x); } +/** + * @brief POSIX implementation of 64 bit atomic add unless. + * + * @param v [in] Structure holding atomic variable. + * @param a [in] Value to add. + * @param u [in] Value to check. + * + * Atomically adds 64 bit value \a a to \a v if \a v is not \a u. + * + * @return Value in atomic variable before the operation. + */ static inline long nvgpu_atomic64_add_unless_impl(nvgpu_atomic64_t *v, long a, long u) { @@ -211,57 +465,160 @@ static inline long nvgpu_atomic64_add_unless_impl(nvgpu_atomic64_t *v, long a, return old; } +/** + * @brief POSIX implementation of 64 bit atomic increment. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v. + */ static inline void nvgpu_atomic64_inc_impl(nvgpu_atomic64_t *v) { (void)NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1L); } +/** + * @brief POSIX implementation of 64 bit atomic increment and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value in structure \a v and returns. + * + * @return Value in the atomic variable incremented by 1. + */ static inline long nvgpu_atomic64_inc_return_impl(nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1L); } +/** + * @brief POSIX implementation of 64 bit atomic increment and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically increments the value stored in \a v and test. Returns true if the + * incremented value is 0 else returns false. + * + * @return TRUE if the addition results in zero, otherwise FALSE. + */ static inline bool nvgpu_atomic64_inc_and_test_impl(nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_ADD_RETURN(v, 1L) == 0L; } +/** + * @brief POSIX implementation of 64 bit atomic decrement. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure \a v. + */ static inline void nvgpu_atomic64_dec_impl(nvgpu_atomic64_t *v) { (void)NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1L); } +/** + * @brief POSIX implementation of 64 bit atomic decrement and return. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value in structure \a v and returns. + * + * @return Value in atomic variable decremented by 1. + */ static inline long nvgpu_atomic64_dec_return_impl(nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1L); } +/** + * @brief POSIX implementation of 64 bit atomic decrement and test. + * + * @param v [in] Structure holding atomic variable. + * + * Atomically decrements the value stored in \a v and test. Returns true if + * the decremented value is 0 else returns false. + * + * @return TRUE if the decremented value is equal to zero, otherwise FALSE. + */ static inline bool nvgpu_atomic64_dec_and_test_impl(nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, 1L) == 0; } +/** + * @brief POSIX implementation of 64 bit atomic exchange. + * + * @param v [in] Structure holding atomic variable. + * @param new [in] Value to set. + * + * Atomically exchanges the value \a new with the value in \a v. + * + * @return Value in the atomic variable before the exchange operation. + */ static inline long nvgpu_atomic64_xchg_impl(nvgpu_atomic64_t *v, long new) { return NVGPU_POSIX_ATOMIC_XCHG(v, new); } +/** + * @brief POSIX implementation of 64 bit atomic compare and exchange. + * + * @param v [in] Structure holding atomic variable. + * @param old [in] Value to compare. + * @param new [in] Value to exchange. + + * Reads the value stored in structure \a v, replaces the value with \a new if + * the read value is equal to \a old. + * + * @return Returns the original value in atomic variable. + */ static inline long nvgpu_atomic64_cmpxchg_impl(nvgpu_atomic64_t *v, long old, long new) { return NVGPU_POSIX_ATOMIC_CMPXCHG(v, old, new); } +/** + * @brief POSIX implementation of 64 bit atomic subtract. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts the 64 bit \a x from structure \a v. + */ static inline void nvgpu_atomic64_sub_impl(long x, nvgpu_atomic64_t *v) { (void)NVGPU_POSIX_ATOMIC_SUB_RETURN(v, x); } +/** + * @brief POSIX implementation of 64 bit atomic sub and return. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a x from \a v and returns. + * + * @return \a x subtracted from the current value in \a v. + */ static inline long nvgpu_atomic64_sub_return_impl(long x, nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, x); } +/** + * @brief POSIX implementation of 64 bit atomic subtract and test. + * + * @param x [in] Value to subtract. + * @param v [in] Structure holding atomic variable. + * + * Atomically subtracts \a x from \a v and returns true if the result is 0. + * Else returns false. + * + * @return TRUE if the operation results in zero, otherwise FALSE. + */ static inline bool nvgpu_atomic64_sub_and_test_impl(long x, nvgpu_atomic64_t *v) { return NVGPU_POSIX_ATOMIC_SUB_RETURN(v, x) == 0; @@ -272,6 +629,14 @@ static inline bool nvgpu_atomic64_sub_and_test_impl(long x, nvgpu_atomic64_t *v) * of the cmpxchg function. For POSIX, this is translated to a call to * nvgpu_atomic_cmpxchg. */ + +/** + * @brief Define for compare and exchange POSIX implementation. + * + * @param p Pointer to data. + * @param old Value to compare. + * @param new Value to exchange. + */ #define cmpxchg(p, old, new) \ ({ \ typeof(*(p)) tmp = (old); \