kref: prefer atomic_inc_not_zero to atomic_add_unless
PATCH 1/1 kref: prefer atomic_inc_not_zero to atomic_add_unless
On most platforms, there exists this ifdef:
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of atomic_inc_not_zero with its own assembly that is slightly more optimized than atomic_add_unless. So, this patch changes kref to use atomic_inc_not_zero instead, for PPC and any future platforms that might provide an explicit implementation.
This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses atomic_inc_not_zero.
[1] http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2167.pdf
--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kref.h +1 -1
@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
Signature · 1 line
2.6.0
Quoted 34 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.Signed-off-by Jason A. Donenfeld <[email protected]>--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kref.h +1
-1@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
This was positively reviewed but never picked up. Can someone queue this for rc3?
Thanks,
Jason
Quoted 39 lines · Thomas Hellstrom
Reviewed-by Thomas Hellstrom <[email protected]>Quoted 34 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.Signed-off-by Jason A. Donenfeld <[email protected]>--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kref.h +1
-1@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
This was positively reviewed by maintainers but never picked up. Can someone queue this for 4.7 or 4.8?
Thanks,
Jason
Quoted 46 lines · Jason A. Donenfeld
This was positively reviewed but never picked up. Can someone queue this for rc3?
Thanks,
JasonQuoted 39 lines · Thomas Hellstrom
Reviewed-by Thomas Hellstrom <[email protected]>Quoted 34 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.Signed-off-by Jason A. Donenfeld <[email protected]>--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kref.h +1
-1@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
Patch for drm-next WAS Re: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless
Dave,
Since kref_get_unless_zero() was brought in by drm, could we add this to drm-next?
Thanks,
Thomas
Quoted 40 lines · Jason A. Donenfeld
This was positively reviewed by maintainers but never picked up. Can someone queue this for 4.7 or 4.8?
Thanks,
JasonQuoted 33 lines · Jason A. Donenfeld
This was positively reviewed but never picked up. Can someone queue this for rc3?
Thanks,
JasonQuoted 26 lines · Thomas Hellstrom
Reviewed-by Thomas Hellstrom <[email protected]>Quoted 22 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.Signed-off-by Jason A. Donenfeld <[email protected]>--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
include/linux/kref.h +0
-0Quoted 8 lines
Quoted 8 lines
include/linux/kref.h static inline int kref_put_mutex(struct kref *kref, · line 171
Quoted 8 lines
include/linux/kref.h +1
-1@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: Patch for drm-next WAS Re: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless
Quoted 4 lines · Thomas Hellstrom
Dave,
Since
kref_get_unless_zero()was brought in by drm, could we add this to drm-next?
Sure can do, but I can't find the raw patch anywhere (I suck, I know). Care to resend?
Thanks, Daniel
Quoted 64 lines
Thanks,
ThomasQuoted 40 lines · Jason A. Donenfeld
This was positively reviewed by maintainers but never picked up. Can someone queue this for 4.7 or 4.8?
Thanks,
JasonQuoted 33 lines · Jason A. Donenfeld
This was positively reviewed but never picked up. Can someone queue this for rc3?
Thanks,
JasonQuoted 26 lines · Thomas Hellstrom
Reviewed-by Thomas Hellstrom <[email protected]>Quoted 22 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.Signed-off-by Jason A. Donenfeld <[email protected]>--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
include/linux/kref.h +0
-0Quoted 8 lines
Quoted 8 lines
include/linux/kref.h static inline int kref_put_mutex(struct kref *kref, · line 171
Quoted 8 lines
include/linux/kref.h +1
-1@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */ _______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: Patch for drm-next WAS Re: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless
Quoted 2 lines · Daniel Vetter
Sure can do, but I can't find the raw patch anywhere (I suck, I know). Care to resend?
Hey sorry I missed this email requesting the actual patch. I reposted it here:
PATCH 1/1 kref: prefer atomic_inc_not_zero to atomic_add_unless
In reply to Daniel VetterOn most platforms, there exists this ifdef:
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of atomic_inc_not_zero with its own assembly that is slightly more optimized than atomic_add_unless. So, this patch changes kref to use atomic_inc_not_zero instead, for PPC and any future platforms that might provide an explicit implementation.
This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses atomic_inc_not_zero.
[1] http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2167.pdf
---
This was reviewed favorably 14 months ago but never picked up. I'm resubmitting it now in hopes that you can finally queue it up for 4.10.
include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kref.h +1 -1
@@ -133,6 +133,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter
AppliedQuoted 15 lines · Jason A. Donenfeld
On most platforms, there exists this ifdef:
#define
atomic_inc_not_zero(v)atomic_add_unless((v), 1, 0)This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of
atomic_inc_not_zerowith its own assembly that is slightly more optimized thanatomic_add_unless. So, this patch changes kref to useatomic_inc_not_zeroinstead, for PPC and any future platforms that might provide an explicit implementation.This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses
atomic_inc_not_zero.
Quoted 4 lines
[1] http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2167.pdf
Signed-off-by Jason A. Donenfeld <[email protected]>Reviewed-by Thomas Hellstrom <[email protected]>
Applied to drm-misc, but for 4.11 since 4.10 is bugfixes only already.
Thanks, Daniel
Quoted 27 lines
---
This was reviewed favorably 14 months ago but never picked up. I'm resubmitting it now in hopes that you can finally queue it up for 4.10.include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kref.h +1
-1@@ -133,6 +133,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */ Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 kref: prefer atomic_inc_not_zero to atomic_add_unless
In reply to Thomas HellstromOn most platforms, there exists this ifdef:
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of atomic_inc_not_zero with its own assembly that is slightly more optimized than atomic_add_unless. So, this patch changes kref to use atomic_inc_not_zero instead, for PPC and any future platforms that might provide an explicit implementation.
This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses atomic_inc_not_zero.
[1] http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2167.pdf
---
This was reviewed favorably 14 months ago but never picked up. I'm resubmitting it now in hopes that you can finally queue it up for 4.10.
include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kref.h +1 -1
@@ -133,6 +133,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
Signature · 1 line
2.11.0
It's also way easier to read using atomic_inc_not_zero..
Not sure you're sending this to the right maintainers, though. You probably want to include Greg.
PATCH 1/1 kref: prefer atomic_inc_not_zero to atomic_add_unless
In reply to Jason A. DonenfeldBy request forwarded patch
This is also
/Thomas
-------- Forwarded Message --------
Subject: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless
Date: Sat, 10 Oct 2015 12:56:34 +0200
From: Jason A. Donenfeld <[email protected]>
To: Dave Airlie <[email protected]>, Thomas Hellstrom
<[email protected]>, [email protected]
CC: Jason A. Donenfeld <[email protected]>
On most platforms, there exists this ifdef:
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of atomic_inc_not_zero with its own assembly that is slightly more optimized than atomic_add_unless. So, this patch changes kref to use atomic_inc_not_zero instead, for PPC and any future platforms that might provide an explicit implementation.
This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses atomic_inc_not_zero.
--- include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kref.h +1 -1
@@ -166,6 +166,6 @@ static inline int kref_put_mutex(struct kref *kref,*/ static inline int __must_check kref_get_unless_zero (struct kref *kref) { -return atomic_add_unless (&kref->refcount,1 ,0 ); +return atomic_inc_not_zero (&kref->refcount); }#endif /* _KREF_H_ */
Signature · 6 lines
2.6.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel