mbcache: LLVMLinux: Remove double calculation from mbcache
PATCH 1/1 mbcache: LLVMLinux: Remove double calculation from mbcache
From: Mark Charlebois <[email protected]>
The call to __builtin_log2 presumes there is a double log2(double x) function defined in the kernel.
The call to hash_log is a call to hash_64 which is defined in include/linux/hash.h
static __always_inline u64 hash_64(u64 val, unsigned int bits)
That means that __builtin_log2(NR_BG_LOCKS) is converting NR_BG_LOCKS to a double and returning a double and then that is converted to an unsigned int.
Using ilog2 is much more appropriate and efficient.
Another side effect of using __builtin_log2 is that is uses __aeabi_* functions for ARM that require linking with libgcc.a.
Author: Mark Charlebois <[email protected]>
--- fs/mbcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/mbcache.c +1 -1
@@ -93,7 +93,7 @@#define MB_CACHE_WRITER ((unsigned short)~0U >> 1) -#define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS) +#define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS)#define MB_CACHE_ENTRY_LOCK_INDEX (ce) \ (hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS))
Signature · 1 line
1.8.3.2
I suspect this will generate FP instructions on x86 which will corrupt user space state. This is thus a critical bug!!
Quoted 39 lines · On April 29, 2014 6:10:39 PM PDT, [email protected] wrote:
From: Mark Charlebois <[email protected]>
The call to
__builtin_log2presumes there is a double log2(double x) function defined in the kernel.The call to
hash_logis a call tohash_64which is defined ininclude/linux/hash.hstatic
__always_inlineu64hash_64(u64 val, unsigned int bits)That means that
__builtin_log2(NR_BG_LOCKS)is convertingNR_BG_LOCKSto a double and returning a double and then that is converted to an unsigned int.Using ilog2 is much more appropriate and efficient.
Another side effect of using
__builtin_log2is that is uses __aeabi_* functions for ARM that require linking with libgcc.a.Author: Mark Charlebois <[email protected]>
Signed-off-by Mark Charlebois <[email protected]>Signed-off-by Behan Webster <[email protected]>---
fs/mbcache.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/mbcache.c +1
-1@@ -93,7 +93,7 @@#define MB_CACHE_WRITER ((unsigned short)~0U >> 1) -#define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS) +#define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS)#define MB_CACHE_ENTRY_LOCK_INDEX (ce) \ (hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS))
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 1 line · H. Peter Anvin
I suspect this will generate FP instructions on x86 which will corrupt user space state. This is thus a critical bug!!
It looks like at least x86-64 gcc does the evaluation at compile time and there aren't any fp instructions left in the code. However, it should still be fixed.
-hpa