1010#include "eytzinger.h"
1111#include "time_stats.h"
1212
13+ /* disable automatic switching to percpu mode */
14+ #define TIME_STATS_NONPCPU ((unsigned long) 1)
15+
1316static const struct time_unit time_units [] = {
1417 { "ns" , 1 },
1518 { "us" , NSEC_PER_USEC },
@@ -123,11 +126,12 @@ void __bch2_time_stats_update(struct bch2_time_stats *stats, u64 start, u64 end)
123126{
124127 unsigned long flags ;
125128
126- if (! stats -> buffer ) {
129+ if (( unsigned long ) stats -> buffer <= TIME_STATS_NONPCPU ) {
127130 spin_lock_irqsave (& stats -> lock , flags );
128131 time_stats_update_one (stats , start , end );
129132
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 &&
131135 stats -> duration_stats .n > 1024 )
132136 stats -> buffer =
133137 alloc_percpu_gfp (struct time_stat_buffer ,
@@ -157,7 +161,7 @@ void bch2_time_stats_reset(struct bch2_time_stats *stats)
157161 unsigned offset = offsetof(struct bch2_time_stats , min_duration );
158162 memset ((void * ) stats + offset , 0 , sizeof (* stats ) - offset );
159163
160- if (stats -> buffer ) {
164+ if (( unsigned long ) stats -> buffer > TIME_STATS_NONPCPU ) {
161165 int cpu ;
162166 for_each_possible_cpu (cpu )
163167 per_cpu_ptr (stats -> buffer , cpu )-> nr = 0 ;
@@ -167,7 +171,9 @@ void bch2_time_stats_reset(struct bch2_time_stats *stats)
167171
168172void bch2_time_stats_exit (struct bch2_time_stats * stats )
169173{
170- free_percpu (stats -> buffer );
174+ if ((unsigned long ) stats -> buffer > TIME_STATS_NONPCPU )
175+ free_percpu (stats -> buffer );
176+ stats -> buffer = NULL ;
171177}
172178
173179void bch2_time_stats_init (struct bch2_time_stats * stats )
@@ -177,3 +183,9 @@ void bch2_time_stats_init(struct bch2_time_stats *stats)
177183 stats -> min_freq = U64_MAX ;
178184 spin_lock_init (& stats -> lock );
179185}
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