Last active
December 14, 2015 09:38
-
-
Save laijs/5066159 to your computer and use it in GitHub Desktop.
test lglock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/lglock.h> | |
#include <linux/percpu-rwlock.h> | |
#include <linux/sched.h> | |
DEFINE_STATIC_LGRWLOCK(test_lgrw); | |
DEFINE_STATIC_PERCPU_RWLOCK(test_percpu_rwlock); | |
static DEFINE_RWLOCK(test_rwlock); | |
#define TEST_COUNT 10000 | |
#define NEST1(a, b) do { a; b; } while (0) | |
#define NEST2(a, b) do { a;a; b;b;} while (0) | |
#define NEST4(a, b) do { a;a;a;a; b;b;b;b; } while (0) | |
#define lgrw_r1() lg_rwlock_local_read_lock(&test_lgrw) | |
#define lgrw_r0() lg_rwlock_local_read_unlock(&test_lgrw) | |
#define lgrw_1() NEST1(lgrw_r1(), lgrw_r0()) | |
#define lgrw_2() NEST2(lgrw_r1(), lgrw_r0()) | |
#define lgrw_4() NEST4(lgrw_r1(), lgrw_r0()) | |
#define pcrw_r1() percpu_read_lock_irqsafe(&test_percpu_rwlock) | |
#define pcrw_r0() percpu_read_unlock_irqsafe(&test_percpu_rwlock) | |
#define pcrw_1() NEST1(pcrw_r1(), pcrw_r0()) | |
#define pcrw_2() NEST2(pcrw_r1(), pcrw_r0()) | |
#define pcrw_4() NEST4(pcrw_r1(), pcrw_r0()) | |
#define rw_r1() read_lock(&test_rwlock) | |
#define rw_r0() read_unlock(&test_rwlock) | |
#define rw_1() NEST1(rw_r1(), rw_r0()) | |
#define rw_2() NEST2(rw_r1(), rw_r0()) | |
#define rw_4() NEST4(rw_r1(), rw_r0()) | |
#define DOTEST(s) do { \ | |
int i; \ | |
u64 t1, t2; \ | |
local_irq_disable(); \ | |
t1 = sched_clock(); \ | |
for (i = 0; i < TEST_COUNT; i++) \ | |
s; \ | |
t2 = sched_clock(); \ | |
local_irq_enable(); \ | |
printk(KERN_INFO "test:%s, before=%llu,after=%llu,time=%llu\n", \ | |
#s, t1, t2, t2 - t1); \ | |
cond_resched(); \ | |
} while (0) | |
static int test_init(void) | |
{ | |
DOTEST(rw_1()); | |
DOTEST(rw_2()); | |
DOTEST(rw_4()); | |
DOTEST(lgrw_1()); | |
DOTEST(lgrw_2()); | |
DOTEST(lgrw_4()); | |
DOTEST(pcrw_1()); | |
DOTEST(pcrw_2()); | |
DOTEST(pcrw_4()); | |
return -1; | |
} | |
MODULE_LICENSE("GPL"); | |
module_init(test_init); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment