diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2013-03-21 12:28:47 -0400 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2013-03-21 13:39:31 -0400 |
commit | 62479586532715b6da4777374a6f53b32453385e (patch) | |
tree | 232004eb56bf36b966ea11ec8295a1b2893ac9e9 /arch/arm64/lib | |
parent | 2b8cac814cd5a0a305d62dcd1d589faccb705a4d (diff) |
arm64: klib: Optimised atomic bitops
This patch implements the AArch64-specific atomic bitops functions using
exclusive memory accesses to avoid locking.
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64/lib')
-rw-r--r-- | arch/arm64/lib/bitops.S | 70 | ||||
-rw-r--r-- | arch/arm64/lib/bitops.c | 25 |
2 files changed, 70 insertions, 25 deletions
diff --git a/arch/arm64/lib/bitops.S b/arch/arm64/lib/bitops.S new file mode 100644 index 000000000000..fd1e801b53e7 --- /dev/null +++ b/arch/arm64/lib/bitops.S | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Based on arch/arm/lib/bitops.h | ||
3 | * | ||
4 | * Copyright (C) 2013 ARM Ltd. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/linkage.h> | ||
20 | #include <asm/assembler.h> | ||
21 | |||
22 | /* | ||
23 | * x0: bits 5:0 bit offset | ||
24 | * bits 63:6 word offset | ||
25 | * x1: address | ||
26 | */ | ||
27 | .macro bitop, name, instr | ||
28 | ENTRY( \name ) | ||
29 | and x3, x0, #63 // Get bit offset | ||
30 | eor x0, x0, x3 // Clear low bits | ||
31 | mov x2, #1 | ||
32 | add x1, x1, x0, lsr #3 // Get word offset | ||
33 | lsl x3, x2, x3 // Create mask | ||
34 | 1: ldxr x2, [x1] | ||
35 | \instr x2, x2, x3 | ||
36 | stxr w0, x2, [x1] | ||
37 | cbnz w0, 1b | ||
38 | ret | ||
39 | ENDPROC(\name ) | ||
40 | .endm | ||
41 | |||
42 | .macro testop, name, instr | ||
43 | ENTRY( \name ) | ||
44 | and x3, x0, #63 // Get bit offset | ||
45 | eor x0, x0, x3 // Clear low bits | ||
46 | mov x2, #1 | ||
47 | add x1, x1, x0, lsr #3 // Get word offset | ||
48 | lsl x4, x2, x3 // Create mask | ||
49 | smp_dmb ish | ||
50 | 1: ldxr x2, [x1] | ||
51 | lsr x0, x2, x3 // Save old value of bit | ||
52 | \instr x2, x2, x4 // toggle bit | ||
53 | stxr w2, x2, [x1] | ||
54 | cbnz w2, 1b | ||
55 | smp_dmb ish | ||
56 | and x0, x0, #1 | ||
57 | 3: ret | ||
58 | ENDPROC(\name ) | ||
59 | .endm | ||
60 | |||
61 | /* | ||
62 | * Atomic bit operations. | ||
63 | */ | ||
64 | bitop change_bit, eor | ||
65 | bitop clear_bit, bic | ||
66 | bitop set_bit, orr | ||
67 | |||
68 | testop test_and_change_bit, eor | ||
69 | testop test_and_clear_bit, bic | ||
70 | testop test_and_set_bit, orr | ||
diff --git a/arch/arm64/lib/bitops.c b/arch/arm64/lib/bitops.c deleted file mode 100644 index aa4965e60acc..000000000000 --- a/arch/arm64/lib/bitops.c +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2012 ARM Limited | ||
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 version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/spinlock.h> | ||
19 | #include <linux/atomic.h> | ||
20 | |||
21 | #ifdef CONFIG_SMP | ||
22 | arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = { | ||
23 | [0 ... (ATOMIC_HASH_SIZE-1)] = __ARCH_SPIN_LOCK_UNLOCKED | ||
24 | }; | ||
25 | #endif | ||