Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Apr 2021 17:23:05 +0200
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Neel Chauhan <nc@freebsd.org>
Cc:        src-committers@freebsd.org, dev-commits-src-all@freebsd.org,  dev-commits-src-main@freebsd.org
Subject:   Re: git: ce65353ac1a1 - main - linuxkpi: Implement atomic_dec_and_lock_irqsave()
Message-ID:  <CAGudoHE1_jrWYAfapX%2B7NyfLvZ=MFW6MJUu1R%2BUnYS3wwSYafA@mail.gmail.com>
In-Reply-To: <202104261515.13QFFuFQ072779@gitrepo.freebsd.org>
References:  <202104261515.13QFFuFQ072779@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 4/26/21, Neel Chauhan <nc@freebsd.org> wrote:
> The branch main has been updated by nc (ports committer):
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=ce65353ac1a17677bef03e96df8da967c9086743
>
> commit ce65353ac1a17677bef03e96df8da967c9086743
> Author:     Neel Chauhan <nc@FreeBSD.org>
> AuthorDate: 2021-04-26 15:15:49 +0000
> Commit:     Neel Chauhan <nc@FreeBSD.org>
> CommitDate: 2021-04-26 15:15:49 +0000
>
>     linuxkpi: Implement atomic_dec_and_lock_irqsave()
>
>     This is needed by the drm-kmod 5.5 update.
>
>     Reviewed by:            hselasky, manu
>     MFC after:              3 days
>     Differential Revision:  https://reviews.freebsd.org/D29988
> ---
>  sys/compat/linuxkpi/common/include/linux/spinlock.h | 13 +++++++++++++
>  sys/sys/param.h                                     |  2 +-
>  2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h
> b/sys/compat/linuxkpi/common/include/linux/spinlock.h
> index 2309794b26ec..7ef474b671dc 100644
> --- a/sys/compat/linuxkpi/common/include/linux/spinlock.h
> +++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h
> @@ -31,6 +31,7 @@
>  #ifndef	_LINUX_SPINLOCK_H_
>  #define	_LINUX_SPINLOCK_H_
>
> +#include <asm/atomic.h>
>  #include <sys/param.h>
>  #include <sys/kernel.h>
>  #include <sys/lock.h>
> @@ -160,4 +161,16 @@ spin_lock_destroy(spinlock_t *lock)
>  	mtx_assert(&(_l)->m, MA_OWNED);		\
>  } while (0)
>
> +static inline int
> +atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
> +    unsigned long flags)
> +{
> +	spin_lock_irqsave(lock, flags);
> +	if (atomic_dec_and_test(cnt)) {
> +		return (1);
> +	}
> +	spin_unlock_irqrestore(lock, flags);
> +	return (0);
> +}

This is likely going to significantly reduce performance. The routine
is only expected to grab the lock when transitioning the count to 0.
iow, this wants a fcmpset loop akin to what can be found in
refcount_release_if_gt
> +
>  #endif					/* _LINUX_SPINLOCK_H_ */
> diff --git a/sys/sys/param.h b/sys/sys/param.h
> index e4fdb272b7fe..4f80ad5972a4 100644
> --- a/sys/sys/param.h
> +++ b/sys/sys/param.h
> @@ -60,7 +60,7 @@
>   *		in the range 5 to 9.
>   */
>  #undef __FreeBSD_version
> -#define __FreeBSD_version 1400010	/* Master, propagated to newvers */
> +#define __FreeBSD_version 1400011	/* Master, propagated to newvers */
>
>  /*
>   * __FreeBSD_kernel__ indicates that this system uses the kernel of
> FreeBSD,
>


-- 
Mateusz Guzik <mjguzik gmail.com>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHE1_jrWYAfapX%2B7NyfLvZ=MFW6MJUu1R%2BUnYS3wwSYafA>