aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c
blob: 97f592048e0b7cdfa57dd0432959925f634765f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-2.0
#include <config.h>

#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <pthread.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>

#include "int_typedefs.h"

#include "barriers.h"
#include "bug_on.h"
#include "locks.h"
#include "misc.h"
#include "preempt.h"
#include "percpu.h"
#include "workqueues.h"

#include <linux/srcu.h>

/* Functions needed from modify_srcu.c */
bool try_check_zero(struct srcu_struct *sp, int idx, int trycount);
void srcu_flip(struct srcu_struct *sp);

/* Simpler implementation of synchronize_srcu that ignores batching. */
void synchronize_srcu(struct srcu_struct *sp)
{
	int idx;
	/*
	 * This code assumes that try_check_zero will succeed anyway,
	 * so there is no point in multiple tries.
	 */
	const int trycount = 1;

	might_sleep();

	/* Ignore the lock, as multiple writers aren't working yet anyway. */

	idx = 1 ^ (sp->completed & 1);

	/* For comments see srcu_advance_batches. */

	assume(try_check_zero(sp, idx, trycount));

	srcu_flip(sp);

	assume(try_check_zero(sp, idx^1, trycount));
}