10
10
#include "eytzinger.h"
11
11
#include "time_stats.h"
12
12
13
+ /* disable automatic switching to percpu mode */
14
+ #define TIME_STATS_NONPCPU ((unsigned long) 1)
15
+
13
16
static const struct time_unit time_units [] = {
14
17
{ "ns" , 1 },
15
18
{ "us" , NSEC_PER_USEC },
@@ -123,11 +126,12 @@ void __bch2_time_stats_update(struct bch2_time_stats *stats, u64 start, u64 end)
123
126
{
124
127
unsigned long flags ;
125
128
126
- if (! stats -> buffer ) {
129
+ if (( unsigned long ) stats -> buffer <= TIME_STATS_NONPCPU ) {
127
130
spin_lock_irqsave (& stats -> lock , flags );
128
131
time_stats_update_one (stats , start , end );
129
132
130
- if (mean_and_variance_weighted_get_mean (stats -> freq_stats_weighted , TIME_STATS_MV_WEIGHT ) < 32 &&
133
+ if (!stats -> buffer &&
134
+ mean_and_variance_weighted_get_mean (stats -> freq_stats_weighted , TIME_STATS_MV_WEIGHT ) < 32 &&
131
135
stats -> duration_stats .n > 1024 )
132
136
stats -> buffer =
133
137
alloc_percpu_gfp (struct time_stat_buffer ,
@@ -157,7 +161,7 @@ void bch2_time_stats_reset(struct bch2_time_stats *stats)
157
161
unsigned offset = offsetof(struct bch2_time_stats , min_duration );
158
162
memset ((void * ) stats + offset , 0 , sizeof (* stats ) - offset );
159
163
160
- if (stats -> buffer ) {
164
+ if (( unsigned long ) stats -> buffer > TIME_STATS_NONPCPU ) {
161
165
int cpu ;
162
166
for_each_possible_cpu (cpu )
163
167
per_cpu_ptr (stats -> buffer , cpu )-> nr = 0 ;
@@ -167,7 +171,9 @@ void bch2_time_stats_reset(struct bch2_time_stats *stats)
167
171
168
172
void bch2_time_stats_exit (struct bch2_time_stats * stats )
169
173
{
170
- free_percpu (stats -> buffer );
174
+ if ((unsigned long ) stats -> buffer > TIME_STATS_NONPCPU )
175
+ free_percpu (stats -> buffer );
176
+ stats -> buffer = NULL ;
171
177
}
172
178
173
179
void bch2_time_stats_init (struct bch2_time_stats * stats )
@@ -177,3 +183,9 @@ void bch2_time_stats_init(struct bch2_time_stats *stats)
177
183
stats -> min_freq = U64_MAX ;
178
184
spin_lock_init (& stats -> lock );
179
185
}
186
+
187
+ void bch2_time_stats_init_no_pcpu (struct bch2_time_stats * stats )
188
+ {
189
+ bch2_time_stats_init (stats );
190
+ stats -> buffer = (struct time_stat_buffer __percpu * ) TIME_STATS_NONPCPU ;
191
+ }
0 commit comments