Skip to content

Commit df134b8

Browse files
Gao Xianggregkh
authored andcommitted
staging: erofs: atomic_cond_read_relaxed on ref-locked workgroup
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 <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 51232df commit df134b8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/staging/erofs/internal.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,29 @@ static inline void erofs_workgroup_unfreeze(
221221
preempt_enable();
222222
}
223223

224+
#if defined(CONFIG_SMP)
225+
static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
226+
{
227+
return atomic_cond_read_relaxed(&grp->refcount,
228+
VAL != EROFS_LOCKED_MAGIC);
229+
}
230+
#else
231+
static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
232+
{
233+
int v = atomic_read(&grp->refcount);
234+
235+
/* workgroup is never freezed on uniprocessor systems */
236+
DBG_BUGON(v == EROFS_LOCKED_MAGIC);
237+
return v;
238+
}
239+
#endif
240+
224241
static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt)
225242
{
226-
const int locked = (int)EROFS_LOCKED_MAGIC;
227243
int o;
228244

229245
repeat:
230-
o = atomic_read(&grp->refcount);
231-
232-
/* spin if it is temporarily locked at the reclaim path */
233-
if (unlikely(o == locked)) {
234-
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
235-
do
236-
cpu_relax();
237-
while (atomic_read(&grp->refcount) == locked);
238-
#endif
239-
goto repeat;
240-
}
246+
o = erofs_wait_on_workgroup_freezed(grp);
241247

242248
if (unlikely(o <= 0))
243249
return -1;

0 commit comments

Comments
 (0)