Skip to content

Commit de7f7d8

Browse files
committed
fs: add percpu counters for significant multigrain timestamp events
JIRA: https://issues.redhat.com/browse/RHEL-121527 New percpu counters for counting various stats around multigrain timestamp events, and a new debugfs file for displaying them when CONFIG_DEBUG_FS is enabled: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches - number of floor value swap events Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Jan Kara <jack@suse.cz> Tested-by: Randy Dunlap <rdunlap@infradead.org> # documentation bits Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/20241002-mgtime-v10-7-d1c4717f5284@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org> (cherry picked from commit 73a47cf) Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
1 parent 343ee18 commit de7f7d8

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

fs/inode.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/list_lru.h>
2222
#include <linux/iversion.h>
2323
#include <linux/rw_hint.h>
24+
#include <linux/seq_file.h>
25+
#include <linux/debugfs.h>
2426
#include <trace/events/writeback.h>
2527
#define CREATE_TRACE_POINTS
2628
#include <trace/events/timestamp.h>
@@ -101,6 +103,70 @@ long get_nr_dirty_inodes(void)
101103
return nr_dirty > 0 ? nr_dirty : 0;
102104
}
103105

106+
#ifdef CONFIG_DEBUG_FS
107+
static DEFINE_PER_CPU(long, mg_ctime_updates);
108+
static DEFINE_PER_CPU(long, mg_fine_stamps);
109+
static DEFINE_PER_CPU(long, mg_ctime_swaps);
110+
111+
static unsigned long get_mg_ctime_updates(void)
112+
{
113+
unsigned long sum = 0;
114+
int i;
115+
116+
for_each_possible_cpu(i)
117+
sum += data_race(per_cpu(mg_ctime_updates, i));
118+
return sum;
119+
}
120+
121+
static unsigned long get_mg_fine_stamps(void)
122+
{
123+
unsigned long sum = 0;
124+
int i;
125+
126+
for_each_possible_cpu(i)
127+
sum += data_race(per_cpu(mg_fine_stamps, i));
128+
return sum;
129+
}
130+
131+
static unsigned long get_mg_ctime_swaps(void)
132+
{
133+
unsigned long sum = 0;
134+
int i;
135+
136+
for_each_possible_cpu(i)
137+
sum += data_race(per_cpu(mg_ctime_swaps, i));
138+
return sum;
139+
}
140+
141+
#define mgtime_counter_inc(__var) this_cpu_inc(__var)
142+
143+
static int mgts_show(struct seq_file *s, void *p)
144+
{
145+
unsigned long ctime_updates = get_mg_ctime_updates();
146+
unsigned long ctime_swaps = get_mg_ctime_swaps();
147+
unsigned long fine_stamps = get_mg_fine_stamps();
148+
unsigned long floor_swaps = timekeeping_get_mg_floor_swaps();
149+
150+
seq_printf(s, "%lu %lu %lu %lu\n",
151+
ctime_updates, ctime_swaps, fine_stamps, floor_swaps);
152+
return 0;
153+
}
154+
155+
DEFINE_SHOW_ATTRIBUTE(mgts);
156+
157+
static int __init mg_debugfs_init(void)
158+
{
159+
debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops);
160+
return 0;
161+
}
162+
late_initcall(mg_debugfs_init);
163+
164+
#else /* ! CONFIG_DEBUG_FS */
165+
166+
#define mgtime_counter_inc(__var) do { } while (0)
167+
168+
#endif /* CONFIG_DEBUG_FS */
169+
104170
/*
105171
* Handle nr_inode sysctl
106172
*/
@@ -2726,8 +2792,10 @@ struct timespec64 inode_set_ctime_current(struct inode *inode)
27262792
if (timespec64_compare(&now, &ctime) <= 0) {
27272793
ktime_get_real_ts64_mg(&now);
27282794
now = timestamp_truncate(now, inode);
2795+
mgtime_counter_inc(mg_fine_stamps);
27292796
}
27302797
}
2798+
mgtime_counter_inc(mg_ctime_updates);
27312799

27322800
/* No need to cmpxchg if it's exactly the same */
27332801
if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) {
@@ -2741,6 +2809,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode)
27412809
/* If swap occurred, then we're (mostly) done */
27422810
inode->i_ctime_sec = now.tv_sec;
27432811
trace_ctime_ns_xchg(inode, cns, now.tv_nsec, cur);
2812+
mgtime_counter_inc(mg_ctime_swaps);
27442813
} else {
27452814
/*
27462815
* Was the change due to someone marking the old ctime QUERIED?

0 commit comments

Comments
 (0)