Rename "tsc" to "timestamp"
[lttng-modules.git] / include / instrumentation / events / writeback.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM writeback
4
5 #if !defined(LTTNG_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_WRITEBACK_H
7
8 #include <lttng/tracepoint-event.h>
9 #include <linux/tracepoint.h>
10 #include <linux/backing-dev.h>
11 #include <linux/writeback.h>
12 #include <lttng/kernel-version.h>
13
14 #ifndef _TRACE_WRITEBACK_DEF_
15 #define _TRACE_WRITEBACK_DEF_
16
17 /*
18 * Use the GPL-exported bdi_dev_name introduced in kernel 5.7. Do not use
19 * static inline bdi_dev_name in prior kernels because it uses the bdi_unknown_name
20 * symbol which is not exported to GPL modules.
21 */
22 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0))
23 static inline const char *lttng_bdi_dev_name(struct backing_dev_info *bdi)
24 {
25 return bdi_dev_name(bdi);
26 }
27 #else
28 static inline const char *lttng_bdi_dev_name(struct backing_dev_info *bdi)
29 {
30 if (!bdi || !bdi->dev)
31 return "(unknown)";
32 return dev_name(bdi->dev);
33 }
34 #endif
35 #endif
36
37 /*
38 * Keep this macro around to track changes in the valid values for `state`.
39 * Eventually, we will have a enum to describe that field. If the macro is
40 * changed by an upstream kernel, the fact that we have a redefinition here
41 * will generate a compiler warning.
42 */
43 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
44 LTTNG_KERNEL_RANGE(4,14,218, 4,15,0) || \
45 LTTNG_KERNEL_RANGE(4,19,172, 4,20,0) || \
46 LTTNG_KERNEL_RANGE(5,4,94, 5,5,0) || \
47 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,141, 4,16,0,0) || \
48 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
49 #define show_inode_state(state) \
50 __print_flags(state, "|", \
51 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
52 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
53 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
54 {I_NEW, "I_NEW"}, \
55 {I_WILL_FREE, "I_WILL_FREE"}, \
56 {I_FREEING, "I_FREEING"}, \
57 {I_CLEAR, "I_CLEAR"}, \
58 {I_SYNC, "I_SYNC"}, \
59 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
60 {I_REFERENCED, "I_REFERENCED"} \
61 )
62 #else
63 #define show_inode_state(state) \
64 __print_flags(state, "|", \
65 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
66 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
67 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
68 {I_NEW, "I_NEW"}, \
69 {I_WILL_FREE, "I_WILL_FREE"}, \
70 {I_FREEING, "I_FREEING"}, \
71 {I_CLEAR, "I_CLEAR"}, \
72 {I_SYNC, "I_SYNC"}, \
73 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
74 {I_DIRTY_TIME_EXPIRED, "I_DIRTY_TIME_EXPIRED"}, \
75 {I_REFERENCED, "I_REFERENCED"} \
76 )
77 #endif /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
78
79 LTTNG_TRACEPOINT_EVENT(writeback_dirty_page,
80 TP_PROTO(struct page *page, struct address_space *mapping),
81 TP_ARGS(page, mapping),
82 TP_FIELDS(
83 ctf_string(name, lttng_bdi_dev_name(mapping ? inode_to_bdi(mapping->host) : NULL))
84 ctf_integer(unsigned long, ino, mapping ? mapping->host->i_ino : 0)
85 ctf_integer(pgoff_t, index, page->index)
86 )
87 )
88
89 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_dirty_inode_template,
90 TP_PROTO(struct inode *inode, int flags),
91 TP_ARGS(inode, flags),
92 TP_FIELDS(
93 /* may be called for files on pseudo FSes w/ unregistered bdi */
94 ctf_string(name, lttng_bdi_dev_name(inode_to_bdi(inode)))
95 ctf_integer(unsigned long, ino, inode->i_ino)
96 ctf_integer(unsigned long, state, inode->i_state)
97 ctf_integer(unsigned long, flags, flags)
98 )
99 )
100 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(name) \
101 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_dirty_inode_template, name, \
102 TP_PROTO(struct inode *inode, int flags), \
103 TP_ARGS(inode, flags))
104 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode_start)
105 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode)
106 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_mark_inode_dirty)
107
108 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_write_inode_template,
109 TP_PROTO(struct inode *inode, struct writeback_control *wbc),
110 TP_ARGS(inode, wbc),
111 TP_FIELDS(
112 ctf_string(name, lttng_bdi_dev_name(inode_to_bdi(inode)))
113 ctf_integer(unsigned long, ino, inode->i_ino)
114 ctf_integer(int, sync_mode, wbc->sync_mode)
115 )
116 )
117
118 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(name) \
119 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_write_inode_template, name, \
120 TP_PROTO(struct inode *inode, struct writeback_control *wbc), \
121 TP_ARGS(inode, wbc))
122 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode_start)
123 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode)
124
125
126 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_work_class,
127 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work),
128 TP_ARGS(wb, work),
129 TP_FIELDS(
130 ctf_string(name, lttng_bdi_dev_name(wb->bdi))
131 )
132 )
133
134 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(name) \
135 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_work_class, name, \
136 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work), \
137 TP_ARGS(wb, work))
138
139 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_nothread)
140 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_queue)
141 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_exec)
142 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_start)
143 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_written)
144 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_wait)
145
146 LTTNG_TRACEPOINT_EVENT(writeback_pages_written,
147 TP_PROTO(long pages_written),
148 TP_ARGS(pages_written),
149 TP_FIELDS(
150 ctf_integer(long, pages, pages_written)
151 )
152 )
153
154 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_class,
155 TP_PROTO(struct bdi_writeback *wb),
156 TP_ARGS(wb),
157 TP_FIELDS(
158 ctf_string(name, lttng_bdi_dev_name(wb->bdi))
159 )
160 )
161
162 #undef DEFINE_WRITEBACK_EVENT
163 #define DEFINE_WRITEBACK_EVENT(name) \
164 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_class, name, \
165 TP_PROTO(struct bdi_writeback *wb), \
166 TP_ARGS(wb))
167
168 #define DEFINE_WRITEBACK_EVENT_MAP(name, map) \
169 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_class, name, map, \
170 TP_PROTO(struct bdi_writeback *wb), \
171 TP_ARGS(wb))
172
173 LTTNG_TRACEPOINT_EVENT(writeback_bdi_register,
174 TP_PROTO(struct backing_dev_info *bdi),
175 TP_ARGS(bdi),
176 TP_FIELDS(
177 ctf_string(name, lttng_bdi_dev_name(bdi))
178 )
179 )
180
181 DEFINE_WRITEBACK_EVENT(writeback_nowork)
182 DEFINE_WRITEBACK_EVENT(writeback_wake_background)
183 DEFINE_WRITEBACK_EVENT(writeback_wake_thread)
184 DEFINE_WRITEBACK_EVENT(writeback_wake_forker_thread)
185 DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister)
186 DEFINE_WRITEBACK_EVENT(writeback_thread_start)
187 DEFINE_WRITEBACK_EVENT(writeback_thread_stop)
188
189 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_wbc_class,
190 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi),
191 TP_ARGS(wbc, bdi),
192 TP_FIELDS(
193 ctf_string(name, lttng_bdi_dev_name(bdi))
194 ctf_integer(long, nr_to_write, wbc->nr_to_write)
195 ctf_integer(long, pages_skipped, wbc->pages_skipped)
196 ctf_integer(int, sync_mode, wbc->sync_mode)
197 ctf_integer(int, for_kupdate, wbc->for_kupdate)
198 ctf_integer(int, for_background, wbc->for_background)
199 ctf_integer(int, for_reclaim, wbc->for_reclaim)
200 ctf_integer(int, range_cyclic, wbc->range_cyclic)
201 ctf_integer(long, range_start, (long) wbc->range_start)
202 ctf_integer(long, range_end, (long) wbc->range_end)
203 )
204 )
205
206 #undef DEFINE_WBC_EVENT
207 #define LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(name, map) \
208 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_wbc_class, name, map, \
209 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
210 TP_ARGS(wbc, bdi))
211 LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(wbc_writepage, writeback_wbc_writepage)
212
213 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
214 LTTNG_KERNEL_RANGE(5,8,6, 5,9,0) || \
215 LTTNG_KERNEL_RANGE(5,4,62, 5,5,0) || \
216 LTTNG_KERNEL_RANGE(4,19,143, 4,20,0) || \
217 LTTNG_KERNEL_RANGE(4,14,196, 4,15,0) || \
218 LTTNG_KERNEL_RANGE(4,9,235, 4,10,0) || \
219 LTTNG_KERNEL_RANGE(4,4,235, 4,5,0) || \
220 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,119, 4,16,0,0) || \
221 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
222 LTTNG_TRACEPOINT_EVENT(writeback_queue_io,
223 TP_PROTO(struct bdi_writeback *wb,
224 struct wb_writeback_work *work,
225 unsigned long dirtied_before,
226 int moved),
227 TP_ARGS(wb, work, dirtied_before, moved),
228 TP_FIELDS(
229 ctf_string(name, lttng_bdi_dev_name(wb->bdi))
230 ctf_integer(unsigned long, older, dirtied_before)
231 ctf_integer(int, moved, moved)
232 )
233 )
234 #else
235 LTTNG_TRACEPOINT_EVENT(writeback_queue_io,
236 TP_PROTO(struct bdi_writeback *wb,
237 struct wb_writeback_work *work,
238 int moved),
239 TP_ARGS(wb, work, moved),
240 TP_FIELDS(
241 ctf_string(name, lttng_bdi_dev_name(wb->bdi))
242 ctf_integer(int, moved, moved)
243 )
244 )
245 #endif
246
247 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,8,0) || \
248 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
249 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state,
250
251 writeback_global_dirty_state,
252
253 TP_PROTO(unsigned long background_thresh,
254 unsigned long dirty_thresh
255 ),
256
257 TP_ARGS(background_thresh,
258 dirty_thresh
259 ),
260
261 TP_FIELDS(
262 ctf_integer(unsigned long, nr_dirty, global_node_page_state(NR_FILE_DIRTY))
263 ctf_integer(unsigned long, nr_writeback, global_node_page_state(NR_WRITEBACK))
264 ctf_integer(unsigned long, nr_dirtied, global_node_page_state(NR_DIRTIED))
265 ctf_integer(unsigned long, nr_written, global_node_page_state(NR_WRITTEN))
266 ctf_integer(unsigned long, background_thresh, background_thresh)
267 ctf_integer(unsigned long, dirty_thresh, dirty_thresh)
268 ctf_integer(unsigned long, dirty_limit, global_dirty_limit)
269 )
270 )
271 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0))
272 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state,
273
274 writeback_global_dirty_state,
275
276 TP_PROTO(unsigned long background_thresh,
277 unsigned long dirty_thresh
278 ),
279
280 TP_ARGS(background_thresh,
281 dirty_thresh
282 ),
283
284 TP_FIELDS(
285 ctf_integer(unsigned long, nr_dirty, global_node_page_state(NR_FILE_DIRTY))
286 ctf_integer(unsigned long, nr_writeback, global_node_page_state(NR_WRITEBACK))
287 ctf_integer(unsigned long, nr_unstable, global_node_page_state(NR_UNSTABLE_NFS))
288 ctf_integer(unsigned long, nr_dirtied, global_node_page_state(NR_DIRTIED))
289 ctf_integer(unsigned long, nr_written, global_node_page_state(NR_WRITTEN))
290 ctf_integer(unsigned long, background_thresh, background_thresh)
291 ctf_integer(unsigned long, dirty_thresh, dirty_thresh)
292 ctf_integer(unsigned long, dirty_limit, global_dirty_limit)
293 )
294 )
295 #else
296 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state,
297
298 writeback_global_dirty_state,
299
300 TP_PROTO(unsigned long background_thresh,
301 unsigned long dirty_thresh
302 ),
303
304 TP_ARGS(background_thresh,
305 dirty_thresh
306 ),
307
308 TP_FIELDS(
309 ctf_integer(unsigned long, nr_dirty, global_page_state(NR_FILE_DIRTY))
310 ctf_integer(unsigned long, nr_writeback, global_page_state(NR_WRITEBACK))
311 ctf_integer(unsigned long, nr_unstable, global_page_state(NR_UNSTABLE_NFS))
312 ctf_integer(unsigned long, nr_dirtied, global_page_state(NR_DIRTIED))
313 ctf_integer(unsigned long, nr_written, global_page_state(NR_WRITTEN))
314 ctf_integer(unsigned long, background_thresh, background_thresh)
315 ctf_integer(unsigned long, dirty_thresh, dirty_thresh)
316 ctf_integer(unsigned long, dirty_limit, global_dirty_limit)
317 )
318 )
319 #endif
320
321 #define KBps(x) ((x) << (PAGE_SHIFT - 10))
322
323 LTTNG_TRACEPOINT_EVENT_MAP(bdi_dirty_ratelimit,
324
325 writeback_bdi_dirty_ratelimit,
326
327 TP_PROTO(struct bdi_writeback *wb,
328 unsigned long dirty_rate,
329 unsigned long task_ratelimit),
330
331 TP_ARGS(wb, dirty_rate, task_ratelimit),
332
333 TP_FIELDS(
334 ctf_string(bdi, lttng_bdi_dev_name(wb->bdi))
335 ctf_integer(unsigned long, write_bw, KBps(wb->bdi->wb.write_bandwidth))
336 ctf_integer(unsigned long, avg_write_bw, KBps(wb->bdi->wb.avg_write_bandwidth))
337 ctf_integer(unsigned long, dirty_rate, KBps(dirty_rate))
338 ctf_integer(unsigned long, dirty_ratelimit, KBps(wb->bdi->wb.dirty_ratelimit))
339 ctf_integer(unsigned long, task_ratelimit, KBps(task_ratelimit))
340 ctf_integer(unsigned long, balanced_dirty_ratelimit,
341 KBps(wb->bdi->wb.balanced_dirty_ratelimit))
342 )
343 )
344
345 LTTNG_TRACEPOINT_EVENT_MAP(balance_dirty_pages,
346
347 writeback_balance_dirty_pages,
348
349 TP_PROTO(struct bdi_writeback *wb,
350 unsigned long thresh,
351 unsigned long bg_thresh,
352 unsigned long dirty,
353 unsigned long bdi_thresh,
354 unsigned long bdi_dirty,
355 unsigned long dirty_ratelimit,
356 unsigned long task_ratelimit,
357 unsigned long dirtied,
358 unsigned long period,
359 long pause,
360 unsigned long start_time),
361
362 TP_ARGS(wb, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty,
363 dirty_ratelimit, task_ratelimit,
364 dirtied, period, pause, start_time
365 ),
366
367 TP_FIELDS(
368 ctf_string(bdi, lttng_bdi_dev_name(wb->bdi))
369 ctf_integer(unsigned long, limit, global_dirty_limit)
370 ctf_integer(unsigned long, setpoint,
371 (global_dirty_limit + (thresh + bg_thresh) / 2) / 2)
372 ctf_integer(unsigned long, dirty, dirty)
373 ctf_integer(unsigned long, bdi_setpoint,
374 ((global_dirty_limit + (thresh + bg_thresh) / 2) / 2) *
375 bdi_thresh / (thresh + 1))
376 ctf_integer(unsigned long, bdi_dirty, bdi_dirty)
377 ctf_integer(unsigned long, dirty_ratelimit,
378 KBps(dirty_ratelimit))
379 ctf_integer(unsigned long, task_ratelimit,
380 KBps(task_ratelimit))
381 ctf_integer(unsigned int, dirtied, dirtied)
382 ctf_integer(unsigned int, dirtied_pause,
383 current->nr_dirtied_pause)
384 ctf_integer(unsigned long, paused,
385 (jiffies - start_time) * 1000 / HZ)
386 ctf_integer(long, pause, pause * 1000 / HZ)
387 ctf_integer(unsigned long, period,
388 period * 1000 / HZ)
389 ctf_integer(long, think,
390 current->dirty_paused_when == 0 ? 0 :
391 (long)(jiffies - current->dirty_paused_when) * 1000/HZ)
392 )
393 )
394
395 LTTNG_TRACEPOINT_EVENT(writeback_sb_inodes_requeue,
396
397 TP_PROTO(struct inode *inode),
398 TP_ARGS(inode),
399
400 TP_FIELDS(
401 ctf_string(name, lttng_bdi_dev_name(inode_to_bdi(inode)))
402 ctf_integer(unsigned long, ino, inode->i_ino)
403 ctf_integer(unsigned long, state, inode->i_state)
404 ctf_integer(unsigned long, dirtied_when, inode->dirtied_when)
405 )
406 )
407
408 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_congest_waited_template,
409
410 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
411
412 TP_ARGS(usec_timeout, usec_delayed),
413
414 TP_FIELDS(
415 ctf_integer(unsigned int, usec_timeout, usec_timeout)
416 ctf_integer(unsigned int, usec_delayed, usec_delayed)
417 )
418 )
419
420 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template, writeback_congestion_wait,
421
422 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
423
424 TP_ARGS(usec_timeout, usec_delayed)
425 )
426
427 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template, writeback_wait_iff_congested,
428
429 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
430
431 TP_ARGS(usec_timeout, usec_delayed)
432 )
433
434 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_single_inode_template,
435
436 TP_PROTO(struct inode *inode,
437 struct writeback_control *wbc,
438 unsigned long nr_to_write
439 ),
440
441 TP_ARGS(inode, wbc, nr_to_write),
442
443 TP_FIELDS(
444 ctf_string(name, lttng_bdi_dev_name(inode_to_bdi(inode)))
445 ctf_integer(unsigned long, ino, inode->i_ino)
446 ctf_integer(unsigned long, state, inode->i_state)
447 ctf_integer(unsigned long, dirtied_when, inode->dirtied_when)
448 ctf_integer(unsigned long, writeback_index,
449 inode->i_mapping->writeback_index)
450 ctf_integer(long, nr_to_write, nr_to_write)
451 ctf_integer(unsigned long, wrote,
452 nr_to_write - wbc->nr_to_write)
453 )
454 )
455
456 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_single_inode_template, writeback_single_inode,
457 TP_PROTO(struct inode *inode,
458 struct writeback_control *wbc,
459 unsigned long nr_to_write),
460 TP_ARGS(inode, wbc, nr_to_write)
461 )
462
463 #endif /* LTTNG_TRACE_WRITEBACK_H */
464
465 /* This part must be outside protection */
466 #include <lttng/define_trace.h>
This page took 0.04074 seconds and 5 git commands to generate.