From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/7] fzsync: Add self tests
Date: Thu, 8 Apr 2021 17:13:55 +0200 [thread overview]
Message-ID: <YG8ds1Xl53rAWoQc@yuki> (raw)
In-Reply-To: <20210319091837.27319-2-rpalethorpe@suse.com>
Hi!
> --- a/lib/newlib_tests/test16.c
> +++ b/lib/newlib_tests/test16.c
> @@ -9,6 +9,8 @@
> * which they should take it in turns to update.
> */
>
> +#define _GNU_SOURCE
This isn't needed anymore, right?
> #include <stdlib.h>
> #include "tst_test.h"
> #include "tst_safe_pthread.h"
> diff --git a/lib/newlib_tests/tst_fuzzy_sync01.c b/lib/newlib_tests/tst_fuzzy_sync01.c
> new file mode 100644
> index 000000000..8db102bdc
> --- /dev/null
> +++ b/lib/newlib_tests/tst_fuzzy_sync01.c
> @@ -0,0 +1,232 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 Richard Palethorpe <rpalethorpe@suse.com>
> + */
> +/*\
> + * [DESCRIPTION]
> + *
> + * This verifies Fuzzy Sync's basic ability to reproduce a particular
> + * outcome to a data race when the critical sections are not aligned.
> + *
> + * We make the simplifying assumptions that:
> + * - Each thread contains a single contiguous critical section.
> + * - The threads only interact through a single variable.
> + * - The various timings are constant except for variations introduced
> + * by the environment.
> + *
> + * If a single data race has N critical sections then we may remove
> + * N-1 sections to produce a more difficult race. We may then test
> + * only the more difficult race and induce from this the outcome of
> + * testing the easier races.
> + *
> + * In real code, the threads may interact through many side
> + * effects. While some of these side effects may not result in a bug,
> + * they may effect the total time it takes to execute either
> + * thread. This will be handled in tst_fuzzy_sync02.
> + *
> + * The number of variables which two threads interact through is
> + * irrelevant as the combined state of two variables can be
> + * represented with a single variable. We may also reduce the number
> + * of states to simply those required to show the thread is inside or
> + * outside of the critical section.
> + *
> + * There are two fundamental races which require alignment under these
> + * assumptions:
> + * 1 2
> + * A +-----+ +----+ The outer box is total execution time.
> + * | # | | # | The '#' is the critical section.
> + *
> + * | # | | # |
> + * B +----+ +-----+
> + *
> + * So we can either have the critical section of the shorter race
> + * before that of the longer one. Or the critical section of the
> + * longer one before the shorter.
> + *
> + * In reality both threads will never be the same length, but we can
> + * test that anyway. We also test with both A as the shorter and B as
> + * the shorter. We also vary the distance of the critical section from
> + * the start or end. The delay times are cubed to ensure that a delay
> + * range is required.
> + *
> + * When entering their critical sections, both threads increment the
> + * 'c' counter variable atomically. They both also increment it when
> + * leaving their critical sections. We record the value of 'c' when A
> + * increments it. From the recorded values of 'c' we can deduce if the
> + * critical sections overlap and their ordering.
> + *
> + * Start (cs) | End (ct) | Ordering
> + * --------------------------------------------
> + * 1 | 2 | A before B
> + * 3 | 4 | B before A
> + *
> + * Any other combination of 'cs' and 'ct' means the critical sections
> + * overlapped.
> +\*/
> +
> +#define _GNU_SOURCE
And here as well.
> +#include "tst_test.h"
> +#include "tst_fuzzy_sync.h"
...
> +static void delay(const int t)
> +{
> + int k = TIME_SCALE(t);
> +
> + while (k--)
> + sched_yield();
> +}
The TIME_SCALE() is not explained anywhere. Also I do wonder if we need
some kind of runtime tuning for this.
Otherwise I find these tests much easier to understand over the first
version. Thanks a lot for the detailed descriptions, they really help a
lot.
With the _GNU_SOURCE revoved you can consider this:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2021-04-08 15:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 9:18 [LTP] [PATCH v3 0/7] Fuzzy Sync single core support and tests Richard Palethorpe
2021-03-19 9:18 ` [LTP] [PATCH v3 1/7] fzsync: Add self tests Richard Palethorpe
2021-04-08 15:13 ` Cyril Hrubis [this message]
2021-04-09 9:34 ` Richard Palethorpe
2021-04-12 13:57 ` Li Wang
2021-04-13 6:42 ` Richard Palethorpe
2021-03-19 9:18 ` [LTP] [PATCH v3 2/7] fzsync: Reset delay bias Richard Palethorpe
2021-04-07 15:38 ` Cyril Hrubis
2021-03-19 9:18 ` [LTP] [PATCH v3 3/7] fzsync: Correctly print positive lower delay range bound Richard Palethorpe
2021-04-07 15:40 ` Cyril Hrubis
2021-03-19 9:18 ` [LTP] [PATCH v3 4/7] fzsync: Add sched_yield for single core machine Richard Palethorpe
2021-03-19 9:18 ` [LTP] [PATCH v3 5/7] fzsync: Move yield check out of loop and add yield to delay Richard Palethorpe
2021-04-08 12:45 ` Cyril Hrubis
2021-03-19 9:18 ` [LTP] [PATCH v3 6/7] API: Add tst_ncpus_available Richard Palethorpe
2021-04-07 15:39 ` Cyril Hrubis
2021-03-19 9:18 ` [LTP] [PATCH v3 7/7] fzsync: Check processor affinity Richard Palethorpe
2021-04-08 12:47 ` Cyril Hrubis
2021-04-09 7:18 ` Li Wang
2021-04-09 9:50 ` Richard Palethorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YG8ds1Xl53rAWoQc@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox