hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/include/asm-generic/qspinlock.h
....@@ -1,15 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Queued spinlock
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
134 *
145 * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
156 * (C) Copyright 2015 Hewlett-Packard Enterprise Development LP
....@@ -20,7 +11,9 @@
2011 #define __ASM_GENERIC_QSPINLOCK_H
2112
2213 #include <asm-generic/qspinlock_types.h>
14
+#include <linux/atomic.h>
2315
16
+#ifndef queued_spin_is_locked
2417 /**
2518 * queued_spin_is_locked - is the spinlock locked?
2619 * @lock: Pointer to queued spinlock structure
....@@ -34,6 +27,7 @@
3427 */
3528 return atomic_read(&lock->val);
3629 }
30
+#endif
3731
3832 /**
3933 * queued_spin_value_unlocked - is the spinlock structure unlocked?
....@@ -66,27 +60,31 @@
6660 */
6761 static __always_inline int queued_spin_trylock(struct qspinlock *lock)
6862 {
69
- if (!atomic_read(&lock->val) &&
70
- (atomic_cmpxchg_acquire(&lock->val, 0, _Q_LOCKED_VAL) == 0))
71
- return 1;
72
- return 0;
63
+ u32 val = atomic_read(&lock->val);
64
+
65
+ if (unlikely(val))
66
+ return 0;
67
+
68
+ return likely(atomic_try_cmpxchg_acquire(&lock->val, &val, _Q_LOCKED_VAL));
7369 }
7470
7571 extern void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
7672
73
+#ifndef queued_spin_lock
7774 /**
7875 * queued_spin_lock - acquire a queued spinlock
7976 * @lock: Pointer to queued spinlock structure
8077 */
8178 static __always_inline void queued_spin_lock(struct qspinlock *lock)
8279 {
83
- u32 val;
80
+ u32 val = 0;
8481
85
- val = atomic_cmpxchg_acquire(&lock->val, 0, _Q_LOCKED_VAL);
86
- if (likely(val == 0))
82
+ if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val, _Q_LOCKED_VAL)))
8783 return;
84
+
8885 queued_spin_lock_slowpath(lock, val);
8986 }
87
+#endif
9088
9189 #ifndef queued_spin_unlock
9290 /**