2020-05-24 15:30:55 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef TEST_HELPER_H
|
|
|
|
#define TEST_HELPER_H
|
|
|
|
/*
|
|
|
|
* Provides some common definitions and helper functions for the memory
|
|
|
|
* tests.
|
|
|
|
*
|
2022-01-31 16:59:14 -06:00
|
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
2021-12-23 03:46:01 -06:00
|
|
|
/*
|
|
|
|
* Test word atomic read and write functions.
|
|
|
|
*/
|
|
|
|
#ifdef __x86_64__
|
|
|
|
#include "memrw64.h"
|
|
|
|
#define read_word read64
|
|
|
|
#define write_word write64
|
|
|
|
#else
|
|
|
|
#include "memrw32.h"
|
|
|
|
#define read_word read32
|
|
|
|
#define write_word write32
|
|
|
|
#endif
|
|
|
|
|
2020-05-24 15:30:55 -05:00
|
|
|
/*
|
|
|
|
* A wrapper for guiding branch prediction.
|
|
|
|
*/
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The block size processed between each update of the progress bars and
|
|
|
|
* spinners. This also affects how quickly the program will respond to the
|
|
|
|
* keyboard.
|
|
|
|
*/
|
|
|
|
#define SPIN_SIZE (1 << 27) // in testwords
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A macro to perform test bailout when requested.
|
|
|
|
*/
|
|
|
|
#define BAILOUT if (bail) return ticks
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns value rounded down to the nearest multiple of align_size.
|
|
|
|
*/
|
|
|
|
static inline uintptr_t round_down(uintptr_t value, size_t align_size)
|
|
|
|
{
|
|
|
|
return value & ~(align_size - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns value rounded up to the nearest multiple of align_size.
|
|
|
|
*/
|
|
|
|
static inline uintptr_t round_up(uintptr_t value, size_t align_size)
|
|
|
|
{
|
|
|
|
return (value + (align_size - 1)) & ~(align_size - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-01-31 16:59:14 -06:00
|
|
|
* Seeds the psuedo-random number generator for my_cpu.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
void random_seed(int my_cpu, uint64_t seed);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
|
|
|
/*
|
2022-01-31 16:59:14 -06:00
|
|
|
* Returns a psuedo-random number for my_cpu. The sequence of numbers returned
|
2020-05-24 15:30:55 -05:00
|
|
|
* is repeatable for a given starting seed. The sequence repeats after 2^64 - 1
|
|
|
|
* numbers. Within that period, no number is repeated.
|
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
testword_t random(int my_cpu);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculates the start and end word address for the chunk of segment that is
|
2022-01-31 16:59:14 -06:00
|
|
|
* to be tested by my_cpu. The chunk start will be aligned to a multiple of
|
2020-05-24 15:30:55 -05:00
|
|
|
* chunk_align.
|
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
void calculate_chunk(testword_t **start, testword_t **end, int my_cpu, int segment, size_t chunk_align);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2021-12-23 05:00:10 -06:00
|
|
|
/*
|
|
|
|
* Flushes the CPU caches. If SMP is enabled, synchronises the threads before
|
|
|
|
* and after issuing the cache flush instruction.
|
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
void flush_caches(int my_cpu);
|
2021-12-23 05:00:10 -06:00
|
|
|
|
2020-05-24 15:30:55 -05:00
|
|
|
#endif // TEST_HELPER_H
|