Commit 0c63e8b7 authored by Michael Ellerman's avatar Michael Ellerman

selftests/powerpc: Import Anton's mmap & futex micro benchmarks

These are useful little loops for smoke testing performance.
Signed-off-by: default avatarAnton Blanchard <anton@samba.org>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent f2418ae8
gettimeofday gettimeofday
context_switch context_switch
mmap_bench
futex_bench
\ No newline at end of file
TEST_PROGS := gettimeofday context_switch TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench
CFLAGS += -O2 CFLAGS += -O2
......
/*
* Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
* Licensed under GPLv2.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
#include <linux/futex.h>
#include "utils.h"
#define ITERATIONS 100000000
#define futex(A, B, C, D, E, F) syscall(__NR_futex, A, B, C, D, E, F)
int test_futex(void)
{
struct timespec ts_start, ts_end;
unsigned long i = ITERATIONS;
clock_gettime(CLOCK_MONOTONIC, &ts_start);
while (i--) {
unsigned int addr = 0;
futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0);
}
clock_gettime(CLOCK_MONOTONIC, &ts_end);
printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
return 0;
}
int main(void)
{
return test_harness(test_futex, "futex_bench");
}
/*
* Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
* Licensed under GPLv2.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <time.h>
#include "utils.h"
#define ITERATIONS 5000000
#define MEMSIZE (128 * 1024 * 1024)
int test_mmap(void)
{
struct timespec ts_start, ts_end;
unsigned long i = ITERATIONS;
clock_gettime(CLOCK_MONOTONIC, &ts_start);
while (i--) {
char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
FAIL_IF(c == MAP_FAILED);
munmap(c, MEMSIZE);
}
clock_gettime(CLOCK_MONOTONIC, &ts_end);
printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
return 0;
}
int main(void)
{
return test_harness(test_mmap, "mmap_bench");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment