mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-09 15:24:32 +08:00
19a4ff534b
membarrier commands cover very different code paths if they are in a single-threaded vs multi-threaded process. Therefore, exercise both scenarios in the kernel selftests to increase coverage of this selftest. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Chris Metcalf <cmetcalf@ezchip.com> Cc: Christoph Lameter <cl@linux.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kirill Tkhai <tkhai@yandex.ru> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paul E. McKenney <paulmck@linux.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Russell King - ARM Linux admin <linux@armlinux.org.uk> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20190919173705.2181-6-mathieu.desnoyers@efficios.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
74 lines
1.7 KiB
C
74 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#define _GNU_SOURCE
|
|
#include <linux/membarrier.h>
|
|
#include <syscall.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <pthread.h>
|
|
|
|
#include "membarrier_test_impl.h"
|
|
|
|
static int thread_ready, thread_quit;
|
|
static pthread_mutex_t test_membarrier_thread_mutex =
|
|
PTHREAD_MUTEX_INITIALIZER;
|
|
static pthread_cond_t test_membarrier_thread_cond =
|
|
PTHREAD_COND_INITIALIZER;
|
|
|
|
void *test_membarrier_thread(void *arg)
|
|
{
|
|
pthread_mutex_lock(&test_membarrier_thread_mutex);
|
|
thread_ready = 1;
|
|
pthread_cond_broadcast(&test_membarrier_thread_cond);
|
|
pthread_mutex_unlock(&test_membarrier_thread_mutex);
|
|
|
|
pthread_mutex_lock(&test_membarrier_thread_mutex);
|
|
while (!thread_quit)
|
|
pthread_cond_wait(&test_membarrier_thread_cond,
|
|
&test_membarrier_thread_mutex);
|
|
pthread_mutex_unlock(&test_membarrier_thread_mutex);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static int test_mt_membarrier(void)
|
|
{
|
|
int i;
|
|
pthread_t test_thread;
|
|
|
|
pthread_create(&test_thread, NULL,
|
|
test_membarrier_thread, NULL);
|
|
|
|
pthread_mutex_lock(&test_membarrier_thread_mutex);
|
|
while (!thread_ready)
|
|
pthread_cond_wait(&test_membarrier_thread_cond,
|
|
&test_membarrier_thread_mutex);
|
|
pthread_mutex_unlock(&test_membarrier_thread_mutex);
|
|
|
|
test_membarrier_fail();
|
|
|
|
test_membarrier_success();
|
|
|
|
pthread_mutex_lock(&test_membarrier_thread_mutex);
|
|
thread_quit = 1;
|
|
pthread_cond_broadcast(&test_membarrier_thread_cond);
|
|
pthread_mutex_unlock(&test_membarrier_thread_mutex);
|
|
|
|
pthread_join(test_thread, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ksft_print_header();
|
|
ksft_set_plan(13);
|
|
|
|
test_membarrier_query();
|
|
|
|
/* Multi-threaded */
|
|
test_mt_membarrier();
|
|
|
|
return ksft_exit_pass();
|
|
}
|