staging: erofs: atomic_cond_read_relaxed on ref-locked workgroup
authorGao Xiang <gaoxiang25@huawei.com>
Thu, 22 Nov 2018 17:16:01 +0000 (01:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Nov 2018 09:53:07 +0000 (10:53 +0100)
It's better to use atomic_cond_read_relaxed, which is implemented
in hardware instructions to monitor a variable changes currently
for ARM64, instead of open-coded busy waiting.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/erofs/internal.h

index 3ac4599bbe011fe88fa09ec9f6311418f94365a6..f933ab602c3704ef3514a96bc3a4d1f7e1eb30a7 100644 (file)
@@ -221,23 +221,29 @@ static inline void erofs_workgroup_unfreeze(
        preempt_enable();
 }
 
+#if defined(CONFIG_SMP)
+static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
+{
+       return atomic_cond_read_relaxed(&grp->refcount,
+                                       VAL != EROFS_LOCKED_MAGIC);
+}
+#else
+static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
+{
+       int v = atomic_read(&grp->refcount);
+
+       /* workgroup is never freezed on uniprocessor systems */
+       DBG_BUGON(v == EROFS_LOCKED_MAGIC);
+       return v;
+}
+#endif
+
 static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt)
 {
-       const int locked = (int)EROFS_LOCKED_MAGIC;
        int o;
 
 repeat:
-       o = atomic_read(&grp->refcount);
-
-       /* spin if it is temporarily locked at the reclaim path */
-       if (unlikely(o == locked)) {
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
-               do
-                       cpu_relax();
-               while (atomic_read(&grp->refcount) == locked);
-#endif
-               goto repeat;
-       }
+       o = erofs_wait_on_workgroup_freezed(grp);
 
        if (unlikely(o <= 0))
                return -1;