Skip to content

Commit fdbc9c3

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_time_stats_reset()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent b36f679 commit fdbc9c3

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

fs/bcachefs/sysfs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ write_attribute(perf_test);
233233

234234
#define x(_name) \
235235
static struct attribute sysfs_time_stat_##_name = \
236-
{ .name = #_name, .mode = 0444 };
236+
{ .name = #_name, .mode = 0644 };
237237
BCH_TIME_STATS()
238238
#undef x
239239

@@ -722,6 +722,13 @@ SHOW(bch2_fs_time_stats)
722722

723723
STORE(bch2_fs_time_stats)
724724
{
725+
struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
726+
727+
#define x(name) \
728+
if (attr == &sysfs_time_stat_##name) \
729+
bch2_time_stats_reset(&c->times[BCH_TIME_##name]);
730+
BCH_TIME_STATS()
731+
#undef x
725732
return size;
726733
}
727734
SYSFS_OPS(bch2_fs_time_stats);

fs/bcachefs/time_stats.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ void __bch2_time_stats_update(struct bch2_time_stats *stats, u64 start, u64 end)
151151
}
152152
}
153153

154+
void bch2_time_stats_reset(struct bch2_time_stats *stats)
155+
{
156+
spin_lock_irq(&stats->lock);
157+
unsigned offset = offsetof(struct bch2_time_stats, min_duration);
158+
memset((void *) stats + offset, 0, sizeof(*stats) - offset);
159+
160+
if (stats->buffer) {
161+
int cpu;
162+
for_each_possible_cpu(cpu)
163+
per_cpu_ptr(stats->buffer, cpu)->nr = 0;
164+
}
165+
spin_unlock_irq(&stats->lock);
166+
}
167+
154168
void bch2_time_stats_exit(struct bch2_time_stats *stats)
155169
{
156170
free_percpu(stats->buffer);

fs/bcachefs/time_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct time_stat_buffer {
7070
struct bch2_time_stats {
7171
spinlock_t lock;
7272
bool have_quantiles;
73+
struct time_stat_buffer __percpu *buffer;
7374
/* all fields are in nanoseconds */
7475
u64 min_duration;
7576
u64 max_duration;
@@ -87,7 +88,6 @@ struct bch2_time_stats {
8788

8889
struct mean_and_variance_weighted duration_stats_weighted;
8990
struct mean_and_variance_weighted freq_stats_weighted;
90-
struct time_stat_buffer __percpu *buffer;
9191
};
9292

9393
struct bch2_time_stats_quantiles {
@@ -142,6 +142,7 @@ static inline bool track_event_change(struct bch2_time_stats *stats, bool v)
142142
return false;
143143
}
144144

145+
void bch2_time_stats_reset(struct bch2_time_stats *);
145146
void bch2_time_stats_exit(struct bch2_time_stats *);
146147
void bch2_time_stats_init(struct bch2_time_stats *);
147148

0 commit comments

Comments
 (0)