xen/arm64: Assembly optimized bitops from Linux
PATCH v2 1/1 xen/arm64: Assembly optimized bitops from Linux
This patch replaces the previous hashed lock implementaiton of bitops with assembly optimized ones taken from Linux v3.10-rc4.
The Linux derived ASM only supports 8 byte aligned bitmaps (which under Linux are unsigned long * rather than our void *). We do have actually uses of 4 byte alignment (i.e. the bitmaps in struct xmem_pool) which trigger alignment faults.
Therefore adjust the assembly to work in 4 byte increments, which involved:
- bit offset now bits 4:0 => mask #31 not #63
- use wN register not xN for load/modify/store loop.
There is no need to adjust the shift used to calculate the word offset, the difference is already acounted for in the #63->#31 change.
NB: Xen's build system cannot cope with the change from .c to .S file, remove xen/arch/arm/arm64/lib/.bitops.o.d or clean your build tree.
---
v2: No need to adjust the word offset shift size.
--- xen/arch/arm/arm64/lib/bitops.S | 68 ++++++++++++ xen/arch/arm/arm64/lib/bitops.c | 22 ---- xen/include/asm-arm/arm64/bitops.h | 203 ++---------------------------------- 3 files changed, 76 insertions(+), 217 deletions(-) create mode 100644 xen/arch/arm/arm64/lib/bitops.S delete mode 100644 xen/arch/arm/arm64/lib/bitops.c
xen/arch/arm/arm64/lib/bitops.S new file +68 -0
@@ -0,0 +1,68 @@ +/* + * Based on linux/arch/arm64/lib/bitops.h which in turn is + * Based on arch/arm/lib/bitops.h + * + * Copyright (C) 2013 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <xen/config.h> + +/* + * x0: bits 4:0 bit offset + * bits 31:5 word offset + * x1: address + */ + .macro bitop, name, instr +ENTRY( \name ) + and w3, w0, #31 // Get bit offset + eor w0, w0, w3 // Clear low bits + mov x2, #1 + add x1, x1, x0, lsr #3 // Get word offset + lsl x3, x2, x3 // Create mask +1: ldxr w2, [x1] + \instr w2, w2, w3 + stxr w0, w2, [x1] + cbnz w0, 1b + ret +ENDPROC(\name ) + .endm + + .macro testop, name, instr +ENTRY( \name ) + and w3, w0, #31 // Get bit offset + eor w0, w0, w3 // Clear low bits + mov x2, #1 + add x1, x1, x0, lsr #3 // Get word offset + lsl x4, x2, x3 // Create mask +1: ldaxr w2, [x1] + lsr w0, w2, w3 // Save old value of bit + \instr w2, w2, w4 // toggle bit + stlxr w5, w2, [x1] + cbnz w5, 1b + and w0, w0, #1 +3: ret +ENDPROC(\name ) + .endm + +/* + * Atomic bit operations. + */ + bitop change_bit, eor + bitop clear_bit, bic + bitop set_bit, orr + + testop test_and_change_bit, eor + testop test_and_clear_bit, bic + testop test_and_set_bit, orr
xen/arch/arm/arm64/lib/bitops.c deleted +0 -22
@@ -1,22 +0,0 @@ -/* -* Copyright (C) 2012 ARM Limited -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <xen/spinlock.h> -#include <xen/bitops.h> - -spinlock_t __atomic_hash[ATOMIC_HASH_SIZE ]/*__lock_aligned*/ = { - [0 ... (ATOMIC_HASH_SIZE -1 )] =SPIN_LOCK_UNLOCKED -};
xen/include/asm-arm/arm64/bitops.h +8 -195
216 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Quoted 12 lines · Ian Campbell
This patch replaces the previous hashed lock implementaiton of bitops with assembly optimized ones taken from Linux v3.10-rc4.
The Linux derived ASM only supports 8 byte aligned bitmaps (which under Linux are unsigned long * rather than our void *). We do have actually uses of 4 byte alignment (i.e. the bitmaps in struct
xmem_pool) which trigger alignment faults.Therefore adjust the assembly to work in 4 byte increments, which involved:
- bit offset now bits 4:0 => mask #31 not #63
- use wN register not xN for load/modify/store loop.
Quoted 7 lines
There is no need to adjust the shift used to calculate the word offset, the difference is already acounted for in the #63->#31 change.
NB: Xen's build system cannot cope with the change from .c to .S file, remove xen/arch/arm/arm64/lib/.bitops.o.d or clean your build tree.
Signed-off-by Ian Campbell <[email protected]>
Quoted 16 lines · Tim Deegan
Quoted 15 lines · Ian Campbell
This patch replaces the previous hashed lock implementaiton of bitops with assembly optimized ones taken from Linux v3.10-rc4.
The Linux derived ASM only supports 8 byte aligned bitmaps (which under Linux are unsigned long * rather than our void *). We do have actually uses of 4 byte alignment (i.e. the bitmaps in struct
xmem_pool) which trigger alignment faults.Therefore adjust the assembly to work in 4 byte increments, which involved:
- bit offset now bits 4:0 => mask #31 not #63
- use wN register not xN for load/modify/store loop.There is no need to adjust the shift used to calculate the word offset, the difference is already acounted for in the #63->#31 change.
Quoted 6 lines
Quoted 4 lines
NB: Xen's build system cannot cope with the change from .c to .S file, remove xen/arch/arm/arm64/lib/.bitops.o.d or clean your build tree.
Signed-off-by Ian Campbell <[email protected]>Acked-by Tim Deegan <[email protected]>
Thanks. After discussing with Stefano I think we can live without this for 4.3 since we are quite late in the rc and this isn't an unmodified copy of the Linux code. So I'll keep this under my hat until 4.4.
Ian