1
0
Files
kernel-49/lib/interval_tree_test.c
Greg Kroah-Hartman 955f27f668 Merge 4.9.147 into android-4.9
Changes in 4.9.147
	signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack
	lib/interval_tree_test.c: make test options module parameters
	lib/interval_tree_test.c: allow full tree search
	lib/rbtree_test.c: make input module parameters
	lib/rbtree-test: lower default params
	lib/interval_tree_test.c: allow users to limit scope of endpoint
	timer/debug: Change /proc/timer_list from 0444 to 0400
	pinctrl: sunxi: a83t: Fix IRQ offset typo for PH11
	aio: fix spectre gadget in lookup_ioctx
	MMC: OMAP: fix broken MMC on OMAP15XX/OMAP5910/OMAP310
	ARM: mmp/mmp2: fix cpu_is_mmp2() on mmp2-dt
	tracing: Fix memory leak in set_trigger_filter()
	tracing: Fix memory leak of instance function hash filters
	powerpc/msi: Fix NULL pointer access in teardown code
	Revert "drm/rockchip: Allow driver to be shutdown on reboot/kexec"
	drm/i915/execlists: Apply a full mb before execution for Braswell
	mac80211: don't WARN on bad WMM parameters from buggy APs
	mac80211: Fix condition validating WMM IE
	IB/hfi1: Remove race conditions in user_sdma send path
	locking: Remove smp_read_barrier_depends() from queued_spin_lock_slowpath()
	locking/qspinlock: Ensure node is initialised before updating prev->next
	locking/qspinlock: Bound spinning on pending->locked transition in slowpath
	locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'
	locking/qspinlock: Remove unbounded cmpxchg() loop from locking slowpath
	locking/qspinlock: Remove duplicate clear_pending() function from PV code
	locking/qspinlock: Kill cmpxchg() loop when claiming lock from head of queue
	locking/qspinlock: Re-order code
	locking/qspinlock/x86: Increase _Q_PENDING_LOOPS upper bound
	locking/qspinlock, x86: Provide liveness guarantee
	locking/qspinlock: Fix build for anonymous union in older GCC compilers
	mac80211_hwsim: fix module init error paths for netlink
	scsi: libiscsi: Fix NULL pointer dereference in iscsi_eh_session_reset
	scsi: vmw_pscsi: Rearrange code to avoid multiple calls to free_irq during unload
	x86/earlyprintk/efi: Fix infinite loop on some screen widths
	drm/msm: Grab a vblank reference when waiting for commit_done
	ARC: io.h: Implement reads{x}()/writes{x}()
	bonding: fix 802.3ad state sent to partner when unbinding slave
	nfs: don't dirty kernel pages read by direct-io
	SUNRPC: Fix a potential race in xprt_connect()
	sbus: char: add of_node_put()
	drivers/sbus/char: add of_node_put()
	drivers/tty: add missing of_node_put()
	ide: pmac: add of_node_put()
	clk: mvebu: Off by one bugs in cp110_of_clk_get()
	clk: mmp: Off by one in mmp_clk_add()
	Input: omap-keypad - fix keyboard debounce configuration
	libata: whitelist all SAMSUNG MZ7KM* solid-state disks
	mv88e6060: disable hardware level MAC learning
	net/mlx4_en: Fix build break when CONFIG_INET is off
	bpf: check pending signals while verifying programs
	ARM: 8814/1: mm: improve/fix ARM v7_dma_inv_range() unaligned address handling
	ARM: 8815/1: V7M: align v7m_dma_inv_range() with v7 counterpart
	ethernet: fman: fix wrong of_node_put() in probe function
	drm/ast: Fix connector leak during driver unload
	cifs: In Kconfig CONFIG_CIFS_POSIX needs depends on legacy (insecure cifs)
	vhost/vsock: fix reset orphans race with close timeout
	i2c: axxia: properly handle master timeout
	i2c: scmi: Fix probe error on devices with an empty SMB0001 ACPI device node
	nvmet-rdma: fix response use after free
	rtc: snvs: add a missing write sync
	rtc: snvs: Add timeouts to avoid kernel lockups
	Linux 4.9.147

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2019-02-11 23:35:45 +03:00

138 lines
3.3 KiB
C

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interval_tree.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <asm/timex.h>
#define __param(type, name, init, msg) \
static type name = init; \
module_param(name, type, 0444); \
MODULE_PARM_DESC(name, msg);
__param(int, nnodes, 100, "Number of nodes in the interval tree");
__param(int, perf_loops, 1000, "Number of iterations modifying the tree");
__param(int, nsearches, 100, "Number of searches to the interval tree");
__param(int, search_loops, 1000, "Number of iterations searching the tree");
__param(bool, search_all, false, "Searches will iterate all nodes in the tree");
__param(uint, max_endpoint, ~0, "Largest value for the interval's endpoint");
static struct rb_root root = RB_ROOT;
static struct interval_tree_node *nodes = NULL;
static u32 *queries = NULL;
static struct rnd_state rnd;
static inline unsigned long
search(struct rb_root *root, unsigned long start, unsigned long last)
{
struct interval_tree_node *node;
unsigned long results = 0;
for (node = interval_tree_iter_first(root, start, last); node;
node = interval_tree_iter_next(node, start, last))
results++;
return results;
}
static void init(void)
{
int i;
for (i = 0; i < nnodes; i++) {
u32 b = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
u32 a = (prandom_u32_state(&rnd) >> 4) % b;
nodes[i].start = a;
nodes[i].last = b;
}
/*
* Limit the search scope to what the user defined.
* Otherwise we are merely measuring empty walks,
* which is pointless.
*/
for (i = 0; i < nsearches; i++)
queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
}
static int interval_tree_test_init(void)
{
int i, j;
unsigned long results;
cycles_t time1, time2, time;
nodes = kmalloc(nnodes * sizeof(struct interval_tree_node), GFP_KERNEL);
if (!nodes)
return -ENOMEM;
queries = kmalloc(nsearches * sizeof(int), GFP_KERNEL);
if (!queries) {
kfree(nodes);
return -ENOMEM;
}
printk(KERN_ALERT "interval tree insert/remove");
prandom_seed_state(&rnd, 3141592653589793238ULL);
init();
time1 = get_cycles();
for (i = 0; i < perf_loops; i++) {
for (j = 0; j < nnodes; j++)
interval_tree_insert(nodes + j, &root);
for (j = 0; j < nnodes; j++)
interval_tree_remove(nodes + j, &root);
}
time2 = get_cycles();
time = time2 - time1;
time = div_u64(time, perf_loops);
printk(" -> %llu cycles\n", (unsigned long long)time);
printk(KERN_ALERT "interval tree search");
for (j = 0; j < nnodes; j++)
interval_tree_insert(nodes + j, &root);
time1 = get_cycles();
results = 0;
for (i = 0; i < search_loops; i++)
for (j = 0; j < nsearches; j++) {
unsigned long start = search_all ? 0 : queries[j];
unsigned long last = search_all ? max_endpoint : queries[j];
results += search(&root, start, last);
}
time2 = get_cycles();
time = time2 - time1;
time = div_u64(time, search_loops);
results = div_u64(results, search_loops);
printk(" -> %llu cycles (%lu results)\n",
(unsigned long long)time, results);
kfree(queries);
kfree(nodes);
return -EAGAIN; /* Fail will directly unload the module */
}
static void interval_tree_test_exit(void)
{
printk(KERN_ALERT "test exit\n");
}
module_init(interval_tree_test_init)
module_exit(interval_tree_test_exit)
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Michel Lespinasse");
MODULE_DESCRIPTION("Interval Tree test");