forked from alk3p/WSA-Linux-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
5 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
membarrier_test | ||
membarrier_test_multi_thread | ||
membarrier_test_single_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tools/testing/selftests/membarrier/membarrier_test_multi_thread.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
24 changes: 24 additions & 0 deletions
24
tools/testing/selftests/membarrier/membarrier_test_single_thread.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |