1
2#ifndef _LINUX_U64_STATS_SYNC_H
3#define _LINUX_U64_STATS_SYNC_H
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#include <linux/seqlock.h>
67
68struct u64_stats_sync {
69#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
70 seqcount_t seq;
71#endif
72};
73
74#if BITS_PER_LONG == 64
75#include <asm/local64.h>
76
77typedef struct {
78 local64_t v;
79} u64_stats_t ;
80
81static inline u64 u64_stats_read(const u64_stats_t *p)
82{
83 return local64_read(&p->v);
84}
85
86static inline void u64_stats_add(u64_stats_t *p, unsigned long val)
87{
88 local64_add(val, &p->v);
89}
90
91static inline void u64_stats_inc(u64_stats_t *p)
92{
93 local64_inc(&p->v);
94}
95
96#else
97
98typedef struct {
99 u64 v;
100} u64_stats_t;
101
102static inline u64 u64_stats_read(const u64_stats_t *p)
103{
104 return p->v;
105}
106
107static inline void u64_stats_add(u64_stats_t *p, unsigned long val)
108{
109 p->v += val;
110}
111
112static inline void u64_stats_inc(u64_stats_t *p)
113{
114 p->v++;
115}
116#endif
117
118#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
119#define u64_stats_init(syncp) seqcount_init(&(syncp)->seq)
120#else
121static inline void u64_stats_init(struct u64_stats_sync *syncp)
122{
123}
124#endif
125
126static inline void u64_stats_update_begin(struct u64_stats_sync *syncp)
127{
128#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
129 write_seqcount_begin(&syncp->seq);
130#endif
131}
132
133static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
134{
135#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
136 write_seqcount_end(&syncp->seq);
137#endif
138}
139
140static inline unsigned long
141u64_stats_update_begin_irqsave(struct u64_stats_sync *syncp)
142{
143 unsigned long flags = 0;
144
145#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
146 local_irq_save(flags);
147 write_seqcount_begin(&syncp->seq);
148#endif
149 return flags;
150}
151
152static inline void
153u64_stats_update_end_irqrestore(struct u64_stats_sync *syncp,
154 unsigned long flags)
155{
156#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
157 write_seqcount_end(&syncp->seq);
158 local_irq_restore(flags);
159#endif
160}
161
162static inline unsigned int __u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
163{
164#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
165 return read_seqcount_begin(&syncp->seq);
166#else
167 return 0;
168#endif
169}
170
171static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
172{
173#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
174 preempt_disable();
175#endif
176 return __u64_stats_fetch_begin(syncp);
177}
178
179static inline bool __u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
180 unsigned int start)
181{
182#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
183 return read_seqcount_retry(&syncp->seq, start);
184#else
185 return false;
186#endif
187}
188
189static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
190 unsigned int start)
191{
192#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
193 preempt_enable();
194#endif
195 return __u64_stats_fetch_retry(syncp, start);
196}
197
198
199
200
201
202
203
204static inline unsigned int u64_stats_fetch_begin_irq(const struct u64_stats_sync *syncp)
205{
206#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
207 local_irq_disable();
208#endif
209 return __u64_stats_fetch_begin(syncp);
210}
211
212static inline bool u64_stats_fetch_retry_irq(const struct u64_stats_sync *syncp,
213 unsigned int start)
214{
215#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
216 local_irq_enable();
217#endif
218 return __u64_stats_fetch_retry(syncp, start);
219}
220
221#endif
222