mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
Merge branch 'x86-atomic-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-atomic-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86: Fix LOCK_PREFIX_HERE for uniprocessor build x86, atomic64: In selftest, distinguish x86-64 from 586+ x86-32: Fix atomic64_inc_not_zero return value convention lib: Fix atomic64_inc_not_zero test lib: Fix atomic64_add_unless return value convention x86-32: Fix atomic64_add_unless return value convention lib: Fix atomic64_add_unless test x86: Implement atomic[64]_dec_if_positive() lib: Only test atomic64_dec_if_positive on archs having it x86-32: Rewrite 32-bit atomic64 functions in assembly lib: Add self-test for atomic64_t x86-32: Allow UP/SMP lock replacement in cmpxchg64 x86: Add support for lock prefix in alternatives
This commit is contained in:
commit
93c9d7f60c
14 changed files with 895 additions and 298 deletions
|
|
@ -1098,6 +1098,13 @@ config DMA_API_DEBUG
|
|||
This option causes a performance degredation. Use only if you want
|
||||
to debug device drivers. If unsure, say N.
|
||||
|
||||
config ATOMIC64_SELFTEST
|
||||
bool "Perform an atomic64_t self-test at boot"
|
||||
help
|
||||
Enable this option to test the atomic64_t functions at boot.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
source "samples/Kconfig"
|
||||
|
||||
source "lib/Kconfig.kgdb"
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o
|
|||
|
||||
obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
|
||||
|
||||
obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o
|
||||
|
||||
hostprogs-y := gen_crc32table
|
||||
clean-files := crc32table.h
|
||||
|
||||
|
|
|
|||
|
|
@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u)
|
|||
{
|
||||
unsigned long flags;
|
||||
spinlock_t *lock = lock_addr(v);
|
||||
int ret = 1;
|
||||
int ret = 0;
|
||||
|
||||
spin_lock_irqsave(lock, flags);
|
||||
if (v->counter != u) {
|
||||
v->counter += a;
|
||||
ret = 0;
|
||||
ret = 1;
|
||||
}
|
||||
spin_unlock_irqrestore(lock, flags);
|
||||
return ret;
|
||||
|
|
|
|||
164
lib/atomic64_test.c
Normal file
164
lib/atomic64_test.c
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* Testsuite for atomic64_t functions
|
||||
*
|
||||
* Copyright © 2010 Luca Barbieri
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <linux/init.h>
|
||||
#include <asm/atomic.h>
|
||||
|
||||
#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
|
||||
static __init int test_atomic64(void)
|
||||
{
|
||||
long long v0 = 0xaaa31337c001d00dLL;
|
||||
long long v1 = 0xdeadbeefdeafcafeLL;
|
||||
long long v2 = 0xfaceabadf00df001LL;
|
||||
long long onestwos = 0x1111111122222222LL;
|
||||
long long one = 1LL;
|
||||
|
||||
atomic64_t v = ATOMIC64_INIT(v0);
|
||||
long long r = v0;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
atomic64_set(&v, v1);
|
||||
r = v1;
|
||||
BUG_ON(v.counter != r);
|
||||
BUG_ON(atomic64_read(&v) != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_add(onestwos, &v);
|
||||
r += onestwos;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_add(-one, &v);
|
||||
r += -one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r += onestwos;
|
||||
BUG_ON(atomic64_add_return(onestwos, &v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r += -one;
|
||||
BUG_ON(atomic64_add_return(-one, &v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_sub(onestwos, &v);
|
||||
r -= onestwos;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_sub(-one, &v);
|
||||
r -= -one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r -= onestwos;
|
||||
BUG_ON(atomic64_sub_return(onestwos, &v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r -= -one;
|
||||
BUG_ON(atomic64_sub_return(-one, &v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_inc(&v);
|
||||
r += one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r += one;
|
||||
BUG_ON(atomic64_inc_return(&v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
atomic64_dec(&v);
|
||||
r -= one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
r -= one;
|
||||
BUG_ON(atomic64_dec_return(&v) != r);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
BUG_ON(atomic64_xchg(&v, v1) != v0);
|
||||
r = v1;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0);
|
||||
r = v1;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
BUG_ON(atomic64_add_unless(&v, one, v0));
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(v0);
|
||||
BUG_ON(!atomic64_add_unless(&v, one, v1));
|
||||
r += one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
#if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(_ASM_GENERIC_ATOMIC64_H)
|
||||
INIT(onestwos);
|
||||
BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
|
||||
r -= one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(0);
|
||||
BUG_ON(atomic64_dec_if_positive(&v) != -one);
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(-one);
|
||||
BUG_ON(atomic64_dec_if_positive(&v) != (-one - one));
|
||||
BUG_ON(v.counter != r);
|
||||
#else
|
||||
#warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above
|
||||
#endif
|
||||
|
||||
INIT(onestwos);
|
||||
BUG_ON(!atomic64_inc_not_zero(&v));
|
||||
r += one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(0);
|
||||
BUG_ON(atomic64_inc_not_zero(&v));
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
INIT(-one);
|
||||
BUG_ON(!atomic64_inc_not_zero(&v));
|
||||
r += one;
|
||||
BUG_ON(v.counter != r);
|
||||
|
||||
#ifdef CONFIG_X86
|
||||
printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n",
|
||||
#ifdef CONFIG_X86_64
|
||||
"x86-64",
|
||||
#elif defined(CONFIG_X86_CMPXCHG64)
|
||||
"i586+",
|
||||
#else
|
||||
"i386+",
|
||||
#endif
|
||||
boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without",
|
||||
boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without");
|
||||
#else
|
||||
printk(KERN_INFO "atomic64 test passed\n");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
core_initcall(test_atomic64);
|
||||
Loading…
Reference in a new issue