selftests, sched/membarrier: Add multi-threaded test
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>
This commit is contained in:
parent
227a4aadc7
commit
19a4ff534b
|
@ -1 +1,2 @@
|
|||
membarrier_test
|
||||
membarrier_test_multi_thread
|
||||
membarrier_test_single_thread
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
CFLAGS += -g -I../../../../usr/include/
|
||||
LDLIBS += -lpthread
|
||||
|
||||
TEST_GEN_PROGS := membarrier_test
|
||||
TEST_GEN_PROGS := membarrier_test_single_thread \
|
||||
membarrier_test_multi_thread
|
||||
|
||||
include ../lib.mk
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* 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 "../kselftest.h"
|
||||
|
||||
|
@ -223,7 +224,7 @@ static int test_membarrier_global_expedited_success(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int test_membarrier(void)
|
||||
static int test_membarrier_fail(void)
|
||||
{
|
||||
int status;
|
||||
|
||||
|
@ -233,10 +234,27 @@ static int test_membarrier(void)
|
|||
status = test_membarrier_flags_fail();
|
||||
if (status)
|
||||
return status;
|
||||
status = test_membarrier_global_success();
|
||||
status = test_membarrier_private_expedited_fail();
|
||||
if (status)
|
||||
return status;
|
||||
status = test_membarrier_private_expedited_fail();
|
||||
status = sys_membarrier(MEMBARRIER_CMD_QUERY, 0);
|
||||
if (status < 0) {
|
||||
ksft_test_result_fail("sys_membarrier() failed\n");
|
||||
return status;
|
||||
}
|
||||
if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) {
|
||||
status = test_membarrier_private_expedited_sync_core_fail();
|
||||
if (status)
|
||||
return status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_membarrier_success(void)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = test_membarrier_global_success();
|
||||
if (status)
|
||||
return status;
|
||||
status = test_membarrier_register_private_expedited_success();
|
||||
|
@ -251,9 +269,6 @@ static int test_membarrier(void)
|
|||
return status;
|
||||
}
|
||||
if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) {
|
||||
status = test_membarrier_private_expedited_sync_core_fail();
|
||||
if (status)
|
||||
return status;
|
||||
status = test_membarrier_register_private_expedited_sync_core_success();
|
||||
if (status)
|
||||
return status;
|
||||
|
@ -300,14 +315,3 @@ static int test_membarrier_query(void)
|
|||
ksft_test_result_pass("sys_membarrier available\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ksft_print_header();
|
||||
ksft_set_plan(13);
|
||||
|
||||
test_membarrier_query();
|
||||
test_membarrier();
|
||||
|
||||
return ksft_exit_pass();
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// 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();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// 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"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ksft_print_header();
|
||||
ksft_set_plan(13);
|
||||
|
||||
test_membarrier_query();
|
||||
|
||||
test_membarrier_fail();
|
||||
|
||||
test_membarrier_success();
|
||||
|
||||
return ksft_exit_pass();
|
||||
}
|
Loading…
Reference in New Issue