mirror of
https://github.com/memtest86plus/memtest86plus.git
synced 2024-11-23 08:26:23 -06:00
4078b7760e
The old barrier implementation was very slow when running on a multi-socket machine (pcmemtest issue 16). The new implementation provides two options: - when blocked, spin on a thread-local flag - when blocked, execute a HLT instruction and wait for a NMI The first option might be faster, but we need to measure it to find out. A new boot command line option is provided to select between the two, with a third setting that uses a mixture of the two.
50 lines
953 B
C
50 lines
953 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef BARRIER_H
|
|
#define BARRIER_H
|
|
/**
|
|
* \file
|
|
*
|
|
* Provides a barrier synchronisation primitive.
|
|
*
|
|
*//*
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
|
*/
|
|
|
|
#include "cpulocal.h"
|
|
|
|
#include "spinlock.h"
|
|
|
|
/**
|
|
* A barrier object.
|
|
*/
|
|
typedef struct
|
|
{
|
|
int flag_num;
|
|
int num_threads;
|
|
int count;
|
|
} barrier_t;
|
|
|
|
/**
|
|
* Initialises a new barrier to block the specified number of threads.
|
|
*/
|
|
void barrier_init(barrier_t *barrier, int num_threads);
|
|
|
|
/**
|
|
* Resets an existing barrier to block the specified number of threads.
|
|
*/
|
|
void barrier_reset(barrier_t *barrier, int num_threads);
|
|
|
|
/**
|
|
* Waits for all threads to arrive at the barrier. A CPU core spins in an
|
|
* idle loop when waiting.
|
|
*/
|
|
void barrier_spin_wait(barrier_t *barrier);
|
|
|
|
/**
|
|
* Waits for all threads to arrive at the barrier. A CPU core halts when
|
|
* waiting.
|
|
*/
|
|
void barrier_halt_wait(barrier_t *barrier);
|
|
|
|
#endif // BARRIER_H
|