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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
* Copyright (c) 2012 Andrej Podzimek
* Copyright (c) 2012 Martin Decky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup sync
* @{
*/
/** @file
*
* This file provides a standard RCU interface also known as "RCU Classic"
* in the Linux kernel. The implementation differs significantly. It includes
* some improvements over the original algorithm, such as clock tick
* independence and multiple callback handling options.
*
* Several Linux RCU algorithms have been designed and published by
* Paul E. McKenney.
*/
#ifndef KERN_RCU_H_
#define KERN_RCU_H_
#include <typedefs.h>
#include <adt/list.h>
#include <synch/mutex.h>
#define RCU_WEIGHT_UNIT 1024
#define RCU_WEIGHT(units, size) \
(RCU_WEIGHT_UNIT * (units) + (size))
#define RCU_VOLATILE(type, lvalue) \
(*((type volatile *) &(lvalue)))
// FIXME: Shouldn't this be atomic_count_t?
typedef uint32_t gp_t;
/* Forward declaration */
struct rcu;
typedef void (*rcu_cb_t)(struct rcu *);
typedef enum {
RCU_CB_DEFAULT,
RCU_CB_EXCL
} rcu_cb_type_t;
typedef struct rcu {
link_t link;
rcu_cb_t func; /* Callback function to invoke */
rcu_cb_type_t type; /* Callback type (default/exclusive) */
atomic_count_t weight; /* Callback importance estimate */
} rcu_t;
typedef struct {
mutex_t lock; /* Reclaimer exclusivity */
struct thread *reclaimer; /* Reclaimer thread */
/*
* Fields used by readers, writers and per-CPU reclaimer threads.
*/
semaphore_t queue_sema; /* Wakes up the reclaimer */
list_t curlist; /* Callbacks waiting for this GP */
list_t nextlist; /* Callbacks waiting for the next GP */
atomic_t weight; /* Current weight of the whole queue */
uint32_t nesting; /* Nesting level of read locks */
gp_t gp_ctr; /* Local (observed) GP counter */
atomic_t *sync; /* Request to synchronize callbacks */
/*
* Fields used by the detector thread.
*/
struct cpu *next_cpu; /* Next CPU that needs a swtch() */
uint64_t pswitch; /* Snapshot of the last csw counter */
} cpu_rcu_t;
/*
* The following might be possibly needed on some weakly ordered machines
* that could fetch a pointer sooner than the data it points at. According
* to McKenney, the only CPU where this can happen is Alpha.
*/
#define rcu_access_pointer(pointer) \
({ \
typeof(pointer) __pointer = (pointer); \
membar_consumer(); \
(__pointer); \
})
#define rcu_access(type, pointer) \
RCU_VOLATILE(type, pointer)
#define rcu_assign(pointer, rvalue) \
({ \
if (rvalue) \
membar_producer(); \
\
(pointer) = (rvalue); \
})
#define rcu_read_lock_held() \
(CPU->rcu.nesting)
extern void rcu_init(void);
extern void rcu_read_lock(void);
extern void rcu_read_unlock(void);
extern void rcu_call(rcu_cb_t callb, rcu_t *, atomic_count_t);
extern void rcu_call_excl(rcu_cb_t, rcu_t *, atomic_count_t);
extern void rcu_synchronize(void);
extern void rcu_synchronize_shared(uint32_t);
extern void rcu_call_synchronize(void);
extern uint32_t rcu_get_gp(void);
#endif
|