Commit 96539f1c authored by Björn Töpel's avatar Björn Töpel Committed by Alexei Starovoitov

selftests: xsk: Remove mutex and condition variable

The usage of the condition variable is broken, and overkill. Replace it
with a pthread barrier.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210329224316.17793-17-maciej.fijalkowski@intel.com
parent 76519102
...@@ -126,18 +126,6 @@ static void __exit_with_error(int error, const char *file, const char *func, int ...@@ -126,18 +126,6 @@ static void __exit_with_error(int error, const char *file, const char *func, int
test_type == TEST_TYPE_STATS ? "Stats" : "",\ test_type == TEST_TYPE_STATS ? "Stats" : "",\
test_type == TEST_TYPE_BPF_RES ? "BPF RES" : "")) test_type == TEST_TYPE_BPF_RES ? "BPF RES" : ""))
static void init_sync_resources(void)
{
pthread_mutex_init(&sync_mutex, NULL);
pthread_cond_init(&signal_rx_condition, NULL);
}
static void destroy_sync_resources(void)
{
pthread_mutex_destroy(&sync_mutex);
pthread_cond_destroy(&signal_rx_condition);
}
static void *memset32_htonl(void *dest, u32 val, u32 size) static void *memset32_htonl(void *dest, u32 val, u32 size)
{ {
u32 *ptr = (u32 *)dest; u32 *ptr = (u32 *)dest;
...@@ -876,9 +864,7 @@ static void *worker_testapp_validate_rx(void *arg) ...@@ -876,9 +864,7 @@ static void *worker_testapp_validate_rx(void *arg)
fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk);
fds[0].events = POLLIN; fds[0].events = POLLIN;
pthread_mutex_lock(&sync_mutex); pthread_barrier_wait(&barr);
pthread_cond_signal(&signal_rx_condition);
pthread_mutex_unlock(&sync_mutex);
while (1) { while (1) {
if (test_type != TEST_TYPE_STATS) { if (test_type != TEST_TYPE_STATS) {
...@@ -903,24 +889,19 @@ static void *worker_testapp_validate_rx(void *arg) ...@@ -903,24 +889,19 @@ static void *worker_testapp_validate_rx(void *arg)
static void testapp_validate(void) static void testapp_validate(void)
{ {
struct timespec max_wait = { 0, 0 };
bool bidi = test_type == TEST_TYPE_BIDI; bool bidi = test_type == TEST_TYPE_BIDI;
bool bpf = test_type == TEST_TYPE_BPF_RES; bool bpf = test_type == TEST_TYPE_BPF_RES;
pthread_mutex_lock(&sync_mutex); if (pthread_barrier_init(&barr, NULL, 2))
exit_with_error(errno);
/*Spawn RX thread */ /*Spawn RX thread */
pthread_create(&t0, NULL, ifdict_rx->func_ptr, ifdict_rx); pthread_create(&t0, NULL, ifdict_rx->func_ptr, ifdict_rx);
if (clock_gettime(CLOCK_REALTIME, &max_wait)) pthread_barrier_wait(&barr);
exit_with_error(errno); if (pthread_barrier_destroy(&barr))
max_wait.tv_sec += TMOUT_SEC;
if (pthread_cond_timedwait(&signal_rx_condition, &sync_mutex, &max_wait) == ETIMEDOUT)
exit_with_error(errno); exit_with_error(errno);
pthread_mutex_unlock(&sync_mutex);
/*Spawn TX thread */ /*Spawn TX thread */
pthread_create(&t1, NULL, ifdict_tx->func_ptr, ifdict_tx); pthread_create(&t1, NULL, ifdict_tx->func_ptr, ifdict_tx);
...@@ -1160,15 +1141,11 @@ int main(int argc, char **argv) ...@@ -1160,15 +1141,11 @@ int main(int argc, char **argv)
ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX);
init_sync_resources();
for (i = 0; i < TEST_MODE_MAX; i++) { for (i = 0; i < TEST_MODE_MAX; i++) {
for (j = 0; j < TEST_TYPE_MAX; j++) for (j = 0; j < TEST_TYPE_MAX; j++)
run_pkt_test(i, j); run_pkt_test(i, j);
} }
destroy_sync_resources();
cleanup: cleanup:
for (int i = 0; i < MAX_INTERFACES; i++) { for (int i = 0; i < MAX_INTERFACES; i++) {
if (ifdict[i]->ns_fd != -1) if (ifdict[i]->ns_fd != -1)
......
...@@ -148,8 +148,7 @@ static struct ifobject *ifdict_rx; ...@@ -148,8 +148,7 @@ static struct ifobject *ifdict_rx;
static struct ifobject *ifdict_tx; static struct ifobject *ifdict_tx;
/*threads*/ /*threads*/
pthread_mutex_t sync_mutex; pthread_barrier_t barr;
pthread_cond_t signal_rx_condition;
pthread_t t0, t1; pthread_t t0, t1;
TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head); TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment