XenevaOS
Loading...
Searching...
No Matches
XenevaOS
BaseHdr
linux
seqlock_types.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0 */
2
#ifndef __LINUX_SEQLOCK_TYPES_H
3
#define __LINUX_SEQLOCK_TYPES_H
4
5
/*
6
* DCL delta: mainline includes <linux/lockdep_types.h> and
7
* <linux/mutex_types.h> here. Neither exists in this tree and neither is
8
* reachable for what it would supply:
9
*
10
* - struct lockdep_map, only inside seqcount_t's `#ifdef
11
* CONFIG_DEBUG_LOCK_ALLOC` field -- that option is not in autoconf.h;
12
* - struct mutex, only as `__SEQ_LOCK(struct mutex *lock)` inside
13
* SEQCOUNT_LOCKNAME's seqcount_mutex_t, and __SEQ_LOCK expands to
14
* nothing unless CONFIG_LOCKDEP or CONFIG_PREEMPT_RT is set -- neither is.
15
*
16
* Porting mainline's mutex_types.h would be the wrong move anyway: DCL's
17
* <linux/mutex.h> is `typedef int mutex`, and mainline's struct mutex pulls
18
* in atomic_long_t, osq_lock and ww_acquire_ctx to describe a lock this tree
19
* spells as an int. The include is dropped rather than retargeted so that a
20
* future CONFIG_DEBUG_LOCK_ALLOC turns into a missing type here instead of a
21
* silently different one.
22
*/
23
#include <
linux/spinlock_types.h
>
24
25
/*
26
* Sequence counters (seqcount_t)
27
*
28
* This is the raw counting mechanism, without any writer protection.
29
*
30
* Write side critical sections must be serialized and non-preemptible.
31
*
32
* If readers can be invoked from hardirq or softirq contexts,
33
* interrupts or bottom halves must also be respectively disabled before
34
* entering the write section.
35
*
36
* This mechanism can't be used if the protected data contains pointers,
37
* as the writer can invalidate a pointer that a reader is following.
38
*
39
* If the write serialization mechanism is one of the common kernel
40
* locking primitives, use a sequence counter with associated lock
41
* (seqcount_LOCKNAME_t) instead.
42
*
43
* If it's desired to automatically handle the sequence counter writer
44
* serialization and non-preemptibility requirements, use a sequential
45
* lock (seqlock_t) instead.
46
*
47
* See Documentation/locking/seqlock.rst
48
*/
49
typedef
struct
seqcount
{
50
unsigned
sequence
;
51
#ifdef CONFIG_DEBUG_LOCK_ALLOC
52
struct
lockdep_map
dep_map;
53
#endif
54
}
seqcount_t
;
55
56
/*
57
* For PREEMPT_RT, seqcount_LOCKNAME_t write side critical sections cannot
58
* disable preemption. It can lead to higher latencies, and the write side
59
* sections will not be able to acquire locks which become sleeping locks
60
* (e.g. spinlock_t).
61
*
62
* To remain preemptible while avoiding a possible livelock caused by the
63
* reader preempting the writer, use a different technique: let the reader
64
* detect if a seqcount_LOCKNAME_t writer is in progress. If that is the
65
* case, acquire then release the associated LOCKNAME writer serialization
66
* lock. This will allow any possibly-preempted writer to make progress
67
* until the end of its writer serialization lock critical section.
68
*
69
* This lock-unlock technique must be implemented for all of PREEMPT_RT
70
* sleeping locks. See Documentation/locking/locktypes.rst
71
*/
72
#if defined(CONFIG_LOCKDEP) || defined(CONFIG_PREEMPT_RT)
73
#define __SEQ_LOCK(expr) expr
74
#else
75
#define __SEQ_LOCK(expr)
76
#endif
77
78
#define SEQCOUNT_LOCKNAME(lockname, locktype, preemptible, lockbase) \
79
typedef struct seqcount_##lockname { \
80
seqcount_t seqcount; \
81
__SEQ_LOCK(locktype *lock); \
82
} seqcount_##lockname##_t;
83
84
SEQCOUNT_LOCKNAME
(
raw_spinlock
, raw_spinlock_t,
false
, raw_spin)
85
SEQCOUNT_LOCKNAME
(spinlock,
spinlock_t
,
__SEQ_RT
, spin)
86
SEQCOUNT_LOCKNAME
(rwlock,
rwlock_t
,
__SEQ_RT
,
read
)
87
SEQCOUNT_LOCKNAME
(
mutex
,
struct
mutex
,
true
,
mutex
)
88
#undef SEQCOUNT_LOCKNAME
89
90
/*
91
* Sequential locks (seqlock_t)
92
*
93
* Sequence counters with an embedded spinlock for writer serialization
94
* and non-preemptibility.
95
*
96
* For more info, see:
97
* - Comments on top of seqcount_t
98
* - Documentation/locking/seqlock.rst
99
*/
100
context_lock_struct
(seqlock) {
101
/*
102
* Make sure that readers don't starve writers on PREEMPT_RT: use
103
* seqcount_spinlock_t instead of seqcount_t. Check __SEQ_LOCK().
104
*/
105
seqcount_spinlock_t
seqcount
;
106
spinlock_t
lock;
107
};
108
typedef
struct
seqlock
seqlock_t
;
109
110
#endif
/* __LINUX_SEQLOCK_TYPES_H */
read
#define read
Definition
acwin.h:180
context_lock_struct
#define context_lock_struct(name,...)
Definition
compiler-context-analysis.h:188
spinlock_t
int spinlock_t
Definition
kernel.h:44
rwlock_t
spinlock_t rwlock_t
Definition
spinlock.h:200
__SEQ_RT
#define __SEQ_RT
Definition
seqlock.h:222
SEQCOUNT_LOCKNAME
#define SEQCOUNT_LOCKNAME(lockname, locktype, preemptible, lockbase)
Definition
seqlock_types.h:78
seqcount_t
struct seqcount seqcount_t
seqlock_t
struct seqlock seqlock_t
Definition
seqlock_types.h:108
spinlock_types.h
lockdep_map
Definition
lockdep.h:161
mutex
Definition
mutex.h:59
raw_spinlock
Definition
spinlock.h:210
seqcount
Definition
seqlock_types.h:49
seqcount::sequence
unsigned sequence
Definition
seqlock_types.h:50
Generated by
1.9.8