xref: /openbmc/linux/include/trace/events/writeback.h (revision 9fb0a7da0c528d9bd49b597aa63b1fe2216c7203)
1455b2864SDave Chinner #undef TRACE_SYSTEM
2455b2864SDave Chinner #define TRACE_SYSTEM writeback
3455b2864SDave Chinner 
4455b2864SDave Chinner #if !defined(_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
5455b2864SDave Chinner #define _TRACE_WRITEBACK_H
6455b2864SDave Chinner 
7455b2864SDave Chinner #include <linux/backing-dev.h>
8455b2864SDave Chinner #include <linux/writeback.h>
9455b2864SDave Chinner 
10251d6a47SWu Fengguang #define show_inode_state(state)					\
11251d6a47SWu Fengguang 	__print_flags(state, "|",				\
12251d6a47SWu Fengguang 		{I_DIRTY_SYNC,		"I_DIRTY_SYNC"},	\
13251d6a47SWu Fengguang 		{I_DIRTY_DATASYNC,	"I_DIRTY_DATASYNC"},	\
14251d6a47SWu Fengguang 		{I_DIRTY_PAGES,		"I_DIRTY_PAGES"},	\
15251d6a47SWu Fengguang 		{I_NEW,			"I_NEW"},		\
16251d6a47SWu Fengguang 		{I_WILL_FREE,		"I_WILL_FREE"},		\
17251d6a47SWu Fengguang 		{I_FREEING,		"I_FREEING"},		\
18251d6a47SWu Fengguang 		{I_CLEAR,		"I_CLEAR"},		\
19251d6a47SWu Fengguang 		{I_SYNC,		"I_SYNC"},		\
20251d6a47SWu Fengguang 		{I_REFERENCED,		"I_REFERENCED"}		\
21251d6a47SWu Fengguang 	)
22251d6a47SWu Fengguang 
23b3bba872SWu Fengguang #define WB_WORK_REASON							\
24b3bba872SWu Fengguang 		{WB_REASON_BACKGROUND,		"background"},		\
25b3bba872SWu Fengguang 		{WB_REASON_TRY_TO_FREE_PAGES,	"try_to_free_pages"},	\
26b3bba872SWu Fengguang 		{WB_REASON_SYNC,		"sync"},		\
27b3bba872SWu Fengguang 		{WB_REASON_PERIODIC,		"periodic"},		\
28b3bba872SWu Fengguang 		{WB_REASON_LAPTOP_TIMER,	"laptop_timer"},	\
29b3bba872SWu Fengguang 		{WB_REASON_FREE_MORE_MEM,	"free_more_memory"},	\
30b3bba872SWu Fengguang 		{WB_REASON_FS_FREE_SPACE,	"fs_free_space"},	\
31b3bba872SWu Fengguang 		{WB_REASON_FORKER_THREAD,	"forker_thread"}
32b3bba872SWu Fengguang 
33455b2864SDave Chinner struct wb_writeback_work;
34455b2864SDave Chinner 
35*9fb0a7daSTejun Heo TRACE_EVENT(writeback_dirty_page,
36*9fb0a7daSTejun Heo 
37*9fb0a7daSTejun Heo 	TP_PROTO(struct page *page, struct address_space *mapping),
38*9fb0a7daSTejun Heo 
39*9fb0a7daSTejun Heo 	TP_ARGS(page, mapping),
40*9fb0a7daSTejun Heo 
41*9fb0a7daSTejun Heo 	TP_STRUCT__entry (
42*9fb0a7daSTejun Heo 		__array(char, name, 32)
43*9fb0a7daSTejun Heo 		__field(unsigned long, ino)
44*9fb0a7daSTejun Heo 		__field(pgoff_t, index)
45*9fb0a7daSTejun Heo 	),
46*9fb0a7daSTejun Heo 
47*9fb0a7daSTejun Heo 	TP_fast_assign(
48*9fb0a7daSTejun Heo 		strncpy(__entry->name,
49*9fb0a7daSTejun Heo 			mapping ? dev_name(mapping->backing_dev_info->dev) : "(unknown)", 32);
50*9fb0a7daSTejun Heo 		__entry->ino = mapping ? mapping->host->i_ino : 0;
51*9fb0a7daSTejun Heo 		__entry->index = page->index;
52*9fb0a7daSTejun Heo 	),
53*9fb0a7daSTejun Heo 
54*9fb0a7daSTejun Heo 	TP_printk("bdi %s: ino=%lu index=%lu",
55*9fb0a7daSTejun Heo 		__entry->name,
56*9fb0a7daSTejun Heo 		__entry->ino,
57*9fb0a7daSTejun Heo 		__entry->index
58*9fb0a7daSTejun Heo 	)
59*9fb0a7daSTejun Heo );
60*9fb0a7daSTejun Heo 
61*9fb0a7daSTejun Heo DECLARE_EVENT_CLASS(writeback_dirty_inode_template,
62*9fb0a7daSTejun Heo 
63*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, int flags),
64*9fb0a7daSTejun Heo 
65*9fb0a7daSTejun Heo 	TP_ARGS(inode, flags),
66*9fb0a7daSTejun Heo 
67*9fb0a7daSTejun Heo 	TP_STRUCT__entry (
68*9fb0a7daSTejun Heo 		__array(char, name, 32)
69*9fb0a7daSTejun Heo 		__field(unsigned long, ino)
70*9fb0a7daSTejun Heo 		__field(unsigned long, flags)
71*9fb0a7daSTejun Heo 	),
72*9fb0a7daSTejun Heo 
73*9fb0a7daSTejun Heo 	TP_fast_assign(
74*9fb0a7daSTejun Heo 		struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info;
75*9fb0a7daSTejun Heo 
76*9fb0a7daSTejun Heo 		/* may be called for files on pseudo FSes w/ unregistered bdi */
77*9fb0a7daSTejun Heo 		strncpy(__entry->name,
78*9fb0a7daSTejun Heo 			bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32);
79*9fb0a7daSTejun Heo 		__entry->ino		= inode->i_ino;
80*9fb0a7daSTejun Heo 		__entry->flags		= flags;
81*9fb0a7daSTejun Heo 	),
82*9fb0a7daSTejun Heo 
83*9fb0a7daSTejun Heo 	TP_printk("bdi %s: ino=%lu flags=%s",
84*9fb0a7daSTejun Heo 		__entry->name,
85*9fb0a7daSTejun Heo 		__entry->ino,
86*9fb0a7daSTejun Heo 		show_inode_state(__entry->flags)
87*9fb0a7daSTejun Heo 	)
88*9fb0a7daSTejun Heo );
89*9fb0a7daSTejun Heo 
90*9fb0a7daSTejun Heo DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode_start,
91*9fb0a7daSTejun Heo 
92*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, int flags),
93*9fb0a7daSTejun Heo 
94*9fb0a7daSTejun Heo 	TP_ARGS(inode, flags)
95*9fb0a7daSTejun Heo );
96*9fb0a7daSTejun Heo 
97*9fb0a7daSTejun Heo DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode,
98*9fb0a7daSTejun Heo 
99*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, int flags),
100*9fb0a7daSTejun Heo 
101*9fb0a7daSTejun Heo 	TP_ARGS(inode, flags)
102*9fb0a7daSTejun Heo );
103*9fb0a7daSTejun Heo 
104*9fb0a7daSTejun Heo DECLARE_EVENT_CLASS(writeback_write_inode_template,
105*9fb0a7daSTejun Heo 
106*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, struct writeback_control *wbc),
107*9fb0a7daSTejun Heo 
108*9fb0a7daSTejun Heo 	TP_ARGS(inode, wbc),
109*9fb0a7daSTejun Heo 
110*9fb0a7daSTejun Heo 	TP_STRUCT__entry (
111*9fb0a7daSTejun Heo 		__array(char, name, 32)
112*9fb0a7daSTejun Heo 		__field(unsigned long, ino)
113*9fb0a7daSTejun Heo 		__field(int, sync_mode)
114*9fb0a7daSTejun Heo 	),
115*9fb0a7daSTejun Heo 
116*9fb0a7daSTejun Heo 	TP_fast_assign(
117*9fb0a7daSTejun Heo 		strncpy(__entry->name,
118*9fb0a7daSTejun Heo 			dev_name(inode->i_mapping->backing_dev_info->dev), 32);
119*9fb0a7daSTejun Heo 		__entry->ino		= inode->i_ino;
120*9fb0a7daSTejun Heo 		__entry->sync_mode	= wbc->sync_mode;
121*9fb0a7daSTejun Heo 	),
122*9fb0a7daSTejun Heo 
123*9fb0a7daSTejun Heo 	TP_printk("bdi %s: ino=%lu sync_mode=%d",
124*9fb0a7daSTejun Heo 		__entry->name,
125*9fb0a7daSTejun Heo 		__entry->ino,
126*9fb0a7daSTejun Heo 		__entry->sync_mode
127*9fb0a7daSTejun Heo 	)
128*9fb0a7daSTejun Heo );
129*9fb0a7daSTejun Heo 
130*9fb0a7daSTejun Heo DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode_start,
131*9fb0a7daSTejun Heo 
132*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, struct writeback_control *wbc),
133*9fb0a7daSTejun Heo 
134*9fb0a7daSTejun Heo 	TP_ARGS(inode, wbc)
135*9fb0a7daSTejun Heo );
136*9fb0a7daSTejun Heo 
137*9fb0a7daSTejun Heo DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode,
138*9fb0a7daSTejun Heo 
139*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode, struct writeback_control *wbc),
140*9fb0a7daSTejun Heo 
141*9fb0a7daSTejun Heo 	TP_ARGS(inode, wbc)
142*9fb0a7daSTejun Heo );
143*9fb0a7daSTejun Heo 
144455b2864SDave Chinner DECLARE_EVENT_CLASS(writeback_work_class,
145455b2864SDave Chinner 	TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work),
146455b2864SDave Chinner 	TP_ARGS(bdi, work),
147455b2864SDave Chinner 	TP_STRUCT__entry(
148455b2864SDave Chinner 		__array(char, name, 32)
149455b2864SDave Chinner 		__field(long, nr_pages)
150455b2864SDave Chinner 		__field(dev_t, sb_dev)
151455b2864SDave Chinner 		__field(int, sync_mode)
152455b2864SDave Chinner 		__field(int, for_kupdate)
153455b2864SDave Chinner 		__field(int, range_cyclic)
154455b2864SDave Chinner 		__field(int, for_background)
1550e175a18SCurt Wohlgemuth 		__field(int, reason)
156455b2864SDave Chinner 	),
157455b2864SDave Chinner 	TP_fast_assign(
158977b7e3aSWu Fengguang 		struct device *dev = bdi->dev;
159977b7e3aSWu Fengguang 		if (!dev)
160977b7e3aSWu Fengguang 			dev = default_backing_dev_info.dev;
161977b7e3aSWu Fengguang 		strncpy(__entry->name, dev_name(dev), 32);
162455b2864SDave Chinner 		__entry->nr_pages = work->nr_pages;
163455b2864SDave Chinner 		__entry->sb_dev = work->sb ? work->sb->s_dev : 0;
164455b2864SDave Chinner 		__entry->sync_mode = work->sync_mode;
165455b2864SDave Chinner 		__entry->for_kupdate = work->for_kupdate;
166455b2864SDave Chinner 		__entry->range_cyclic = work->range_cyclic;
167455b2864SDave Chinner 		__entry->for_background	= work->for_background;
1680e175a18SCurt Wohlgemuth 		__entry->reason = work->reason;
169455b2864SDave Chinner 	),
170455b2864SDave Chinner 	TP_printk("bdi %s: sb_dev %d:%d nr_pages=%ld sync_mode=%d "
1710e175a18SCurt Wohlgemuth 		  "kupdate=%d range_cyclic=%d background=%d reason=%s",
172455b2864SDave Chinner 		  __entry->name,
173455b2864SDave Chinner 		  MAJOR(__entry->sb_dev), MINOR(__entry->sb_dev),
174455b2864SDave Chinner 		  __entry->nr_pages,
175455b2864SDave Chinner 		  __entry->sync_mode,
176455b2864SDave Chinner 		  __entry->for_kupdate,
177455b2864SDave Chinner 		  __entry->range_cyclic,
1780e175a18SCurt Wohlgemuth 		  __entry->for_background,
179b3bba872SWu Fengguang 		  __print_symbolic(__entry->reason, WB_WORK_REASON)
180455b2864SDave Chinner 	)
181455b2864SDave Chinner );
182455b2864SDave Chinner #define DEFINE_WRITEBACK_WORK_EVENT(name) \
183455b2864SDave Chinner DEFINE_EVENT(writeback_work_class, name, \
184455b2864SDave Chinner 	TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work), \
185455b2864SDave Chinner 	TP_ARGS(bdi, work))
186455b2864SDave Chinner DEFINE_WRITEBACK_WORK_EVENT(writeback_nothread);
187455b2864SDave Chinner DEFINE_WRITEBACK_WORK_EVENT(writeback_queue);
188455b2864SDave Chinner DEFINE_WRITEBACK_WORK_EVENT(writeback_exec);
189d46db3d5SWu Fengguang DEFINE_WRITEBACK_WORK_EVENT(writeback_start);
190d46db3d5SWu Fengguang DEFINE_WRITEBACK_WORK_EVENT(writeback_written);
191d46db3d5SWu Fengguang DEFINE_WRITEBACK_WORK_EVENT(writeback_wait);
192455b2864SDave Chinner 
193455b2864SDave Chinner TRACE_EVENT(writeback_pages_written,
194455b2864SDave Chinner 	TP_PROTO(long pages_written),
195455b2864SDave Chinner 	TP_ARGS(pages_written),
196455b2864SDave Chinner 	TP_STRUCT__entry(
197455b2864SDave Chinner 		__field(long,		pages)
198455b2864SDave Chinner 	),
199455b2864SDave Chinner 	TP_fast_assign(
200455b2864SDave Chinner 		__entry->pages		= pages_written;
201455b2864SDave Chinner 	),
202455b2864SDave Chinner 	TP_printk("%ld", __entry->pages)
203455b2864SDave Chinner );
204455b2864SDave Chinner 
205455b2864SDave Chinner DECLARE_EVENT_CLASS(writeback_class,
206455b2864SDave Chinner 	TP_PROTO(struct backing_dev_info *bdi),
207455b2864SDave Chinner 	TP_ARGS(bdi),
208455b2864SDave Chinner 	TP_STRUCT__entry(
209455b2864SDave Chinner 		__array(char, name, 32)
210455b2864SDave Chinner 	),
211455b2864SDave Chinner 	TP_fast_assign(
212455b2864SDave Chinner 		strncpy(__entry->name, dev_name(bdi->dev), 32);
213455b2864SDave Chinner 	),
214455b2864SDave Chinner 	TP_printk("bdi %s",
215455b2864SDave Chinner 		  __entry->name
216455b2864SDave Chinner 	)
217455b2864SDave Chinner );
218455b2864SDave Chinner #define DEFINE_WRITEBACK_EVENT(name) \
219455b2864SDave Chinner DEFINE_EVENT(writeback_class, name, \
220455b2864SDave Chinner 	TP_PROTO(struct backing_dev_info *bdi), \
221455b2864SDave Chinner 	TP_ARGS(bdi))
222455b2864SDave Chinner 
223455b2864SDave Chinner DEFINE_WRITEBACK_EVENT(writeback_nowork);
22471927e84SWu Fengguang DEFINE_WRITEBACK_EVENT(writeback_wake_background);
22560332023SArtem Bityutskiy DEFINE_WRITEBACK_EVENT(writeback_wake_thread);
22660332023SArtem Bityutskiy DEFINE_WRITEBACK_EVENT(writeback_wake_forker_thread);
227455b2864SDave Chinner DEFINE_WRITEBACK_EVENT(writeback_bdi_register);
228455b2864SDave Chinner DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister);
229455b2864SDave Chinner DEFINE_WRITEBACK_EVENT(writeback_thread_start);
230455b2864SDave Chinner DEFINE_WRITEBACK_EVENT(writeback_thread_stop);
231455b2864SDave Chinner 
232028c2dd1SDave Chinner DECLARE_EVENT_CLASS(wbc_class,
233028c2dd1SDave Chinner 	TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi),
234028c2dd1SDave Chinner 	TP_ARGS(wbc, bdi),
235028c2dd1SDave Chinner 	TP_STRUCT__entry(
236028c2dd1SDave Chinner 		__array(char, name, 32)
237028c2dd1SDave Chinner 		__field(long, nr_to_write)
238028c2dd1SDave Chinner 		__field(long, pages_skipped)
239028c2dd1SDave Chinner 		__field(int, sync_mode)
240028c2dd1SDave Chinner 		__field(int, for_kupdate)
241028c2dd1SDave Chinner 		__field(int, for_background)
242028c2dd1SDave Chinner 		__field(int, for_reclaim)
243028c2dd1SDave Chinner 		__field(int, range_cyclic)
244028c2dd1SDave Chinner 		__field(long, range_start)
245028c2dd1SDave Chinner 		__field(long, range_end)
246028c2dd1SDave Chinner 	),
247028c2dd1SDave Chinner 
248028c2dd1SDave Chinner 	TP_fast_assign(
249028c2dd1SDave Chinner 		strncpy(__entry->name, dev_name(bdi->dev), 32);
250028c2dd1SDave Chinner 		__entry->nr_to_write	= wbc->nr_to_write;
251028c2dd1SDave Chinner 		__entry->pages_skipped	= wbc->pages_skipped;
252028c2dd1SDave Chinner 		__entry->sync_mode	= wbc->sync_mode;
253028c2dd1SDave Chinner 		__entry->for_kupdate	= wbc->for_kupdate;
254028c2dd1SDave Chinner 		__entry->for_background	= wbc->for_background;
255028c2dd1SDave Chinner 		__entry->for_reclaim	= wbc->for_reclaim;
256028c2dd1SDave Chinner 		__entry->range_cyclic	= wbc->range_cyclic;
257028c2dd1SDave Chinner 		__entry->range_start	= (long)wbc->range_start;
258028c2dd1SDave Chinner 		__entry->range_end	= (long)wbc->range_end;
259028c2dd1SDave Chinner 	),
260028c2dd1SDave Chinner 
261028c2dd1SDave Chinner 	TP_printk("bdi %s: towrt=%ld skip=%ld mode=%d kupd=%d "
262d46db3d5SWu Fengguang 		"bgrd=%d reclm=%d cyclic=%d "
263028c2dd1SDave Chinner 		"start=0x%lx end=0x%lx",
264028c2dd1SDave Chinner 		__entry->name,
265028c2dd1SDave Chinner 		__entry->nr_to_write,
266028c2dd1SDave Chinner 		__entry->pages_skipped,
267028c2dd1SDave Chinner 		__entry->sync_mode,
268028c2dd1SDave Chinner 		__entry->for_kupdate,
269028c2dd1SDave Chinner 		__entry->for_background,
270028c2dd1SDave Chinner 		__entry->for_reclaim,
271028c2dd1SDave Chinner 		__entry->range_cyclic,
272028c2dd1SDave Chinner 		__entry->range_start,
273028c2dd1SDave Chinner 		__entry->range_end)
274028c2dd1SDave Chinner )
275028c2dd1SDave Chinner 
276028c2dd1SDave Chinner #define DEFINE_WBC_EVENT(name) \
277028c2dd1SDave Chinner DEFINE_EVENT(wbc_class, name, \
278028c2dd1SDave Chinner 	TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
279028c2dd1SDave Chinner 	TP_ARGS(wbc, bdi))
2809e094383SDave Chinner DEFINE_WBC_EVENT(wbc_writepage);
281028c2dd1SDave Chinner 
282e84d0a4fSWu Fengguang TRACE_EVENT(writeback_queue_io,
283e84d0a4fSWu Fengguang 	TP_PROTO(struct bdi_writeback *wb,
284ad4e38ddSCurt Wohlgemuth 		 struct wb_writeback_work *work,
285e84d0a4fSWu Fengguang 		 int moved),
286ad4e38ddSCurt Wohlgemuth 	TP_ARGS(wb, work, moved),
287e84d0a4fSWu Fengguang 	TP_STRUCT__entry(
288e84d0a4fSWu Fengguang 		__array(char,		name, 32)
289e84d0a4fSWu Fengguang 		__field(unsigned long,	older)
290e84d0a4fSWu Fengguang 		__field(long,		age)
291e84d0a4fSWu Fengguang 		__field(int,		moved)
2920e175a18SCurt Wohlgemuth 		__field(int,		reason)
293e84d0a4fSWu Fengguang 	),
294e84d0a4fSWu Fengguang 	TP_fast_assign(
295ad4e38ddSCurt Wohlgemuth 		unsigned long *older_than_this = work->older_than_this;
296e84d0a4fSWu Fengguang 		strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
297e84d0a4fSWu Fengguang 		__entry->older	= older_than_this ?  *older_than_this : 0;
298e84d0a4fSWu Fengguang 		__entry->age	= older_than_this ?
299e84d0a4fSWu Fengguang 				  (jiffies - *older_than_this) * 1000 / HZ : -1;
300e84d0a4fSWu Fengguang 		__entry->moved	= moved;
3010e175a18SCurt Wohlgemuth 		__entry->reason	= work->reason;
302e84d0a4fSWu Fengguang 	),
3030e175a18SCurt Wohlgemuth 	TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s",
304e84d0a4fSWu Fengguang 		__entry->name,
305e84d0a4fSWu Fengguang 		__entry->older,	/* older_than_this in jiffies */
306e84d0a4fSWu Fengguang 		__entry->age,	/* older_than_this in relative milliseconds */
3070e175a18SCurt Wohlgemuth 		__entry->moved,
308b3bba872SWu Fengguang 		__print_symbolic(__entry->reason, WB_WORK_REASON)
309b3bba872SWu Fengguang 	)
310e84d0a4fSWu Fengguang );
311e84d0a4fSWu Fengguang 
312e1cbe236SWu Fengguang TRACE_EVENT(global_dirty_state,
313e1cbe236SWu Fengguang 
314e1cbe236SWu Fengguang 	TP_PROTO(unsigned long background_thresh,
315e1cbe236SWu Fengguang 		 unsigned long dirty_thresh
316e1cbe236SWu Fengguang 	),
317e1cbe236SWu Fengguang 
318e1cbe236SWu Fengguang 	TP_ARGS(background_thresh,
319e1cbe236SWu Fengguang 		dirty_thresh
320e1cbe236SWu Fengguang 	),
321e1cbe236SWu Fengguang 
322e1cbe236SWu Fengguang 	TP_STRUCT__entry(
323e1cbe236SWu Fengguang 		__field(unsigned long,	nr_dirty)
324e1cbe236SWu Fengguang 		__field(unsigned long,	nr_writeback)
325e1cbe236SWu Fengguang 		__field(unsigned long,	nr_unstable)
326e1cbe236SWu Fengguang 		__field(unsigned long,	background_thresh)
327e1cbe236SWu Fengguang 		__field(unsigned long,	dirty_thresh)
328e1cbe236SWu Fengguang 		__field(unsigned long,	dirty_limit)
329e1cbe236SWu Fengguang 		__field(unsigned long,	nr_dirtied)
330e1cbe236SWu Fengguang 		__field(unsigned long,	nr_written)
331e1cbe236SWu Fengguang 	),
332e1cbe236SWu Fengguang 
333e1cbe236SWu Fengguang 	TP_fast_assign(
334e1cbe236SWu Fengguang 		__entry->nr_dirty	= global_page_state(NR_FILE_DIRTY);
335e1cbe236SWu Fengguang 		__entry->nr_writeback	= global_page_state(NR_WRITEBACK);
336e1cbe236SWu Fengguang 		__entry->nr_unstable	= global_page_state(NR_UNSTABLE_NFS);
337e1cbe236SWu Fengguang 		__entry->nr_dirtied	= global_page_state(NR_DIRTIED);
338e1cbe236SWu Fengguang 		__entry->nr_written	= global_page_state(NR_WRITTEN);
339e1cbe236SWu Fengguang 		__entry->background_thresh = background_thresh;
340e1cbe236SWu Fengguang 		__entry->dirty_thresh	= dirty_thresh;
341e1cbe236SWu Fengguang 		__entry->dirty_limit = global_dirty_limit;
342e1cbe236SWu Fengguang 	),
343e1cbe236SWu Fengguang 
344e1cbe236SWu Fengguang 	TP_printk("dirty=%lu writeback=%lu unstable=%lu "
345e1cbe236SWu Fengguang 		  "bg_thresh=%lu thresh=%lu limit=%lu "
346e1cbe236SWu Fengguang 		  "dirtied=%lu written=%lu",
347e1cbe236SWu Fengguang 		  __entry->nr_dirty,
348e1cbe236SWu Fengguang 		  __entry->nr_writeback,
349e1cbe236SWu Fengguang 		  __entry->nr_unstable,
350e1cbe236SWu Fengguang 		  __entry->background_thresh,
351e1cbe236SWu Fengguang 		  __entry->dirty_thresh,
352e1cbe236SWu Fengguang 		  __entry->dirty_limit,
353e1cbe236SWu Fengguang 		  __entry->nr_dirtied,
354e1cbe236SWu Fengguang 		  __entry->nr_written
355e1cbe236SWu Fengguang 	)
356e1cbe236SWu Fengguang );
357e1cbe236SWu Fengguang 
358b48c104dSWu Fengguang #define KBps(x)			((x) << (PAGE_SHIFT - 10))
359b48c104dSWu Fengguang 
360b48c104dSWu Fengguang TRACE_EVENT(bdi_dirty_ratelimit,
361b48c104dSWu Fengguang 
362b48c104dSWu Fengguang 	TP_PROTO(struct backing_dev_info *bdi,
363b48c104dSWu Fengguang 		 unsigned long dirty_rate,
364b48c104dSWu Fengguang 		 unsigned long task_ratelimit),
365b48c104dSWu Fengguang 
366b48c104dSWu Fengguang 	TP_ARGS(bdi, dirty_rate, task_ratelimit),
367b48c104dSWu Fengguang 
368b48c104dSWu Fengguang 	TP_STRUCT__entry(
369b48c104dSWu Fengguang 		__array(char,		bdi, 32)
370b48c104dSWu Fengguang 		__field(unsigned long,	write_bw)
371b48c104dSWu Fengguang 		__field(unsigned long,	avg_write_bw)
372b48c104dSWu Fengguang 		__field(unsigned long,	dirty_rate)
373b48c104dSWu Fengguang 		__field(unsigned long,	dirty_ratelimit)
374b48c104dSWu Fengguang 		__field(unsigned long,	task_ratelimit)
375b48c104dSWu Fengguang 		__field(unsigned long,	balanced_dirty_ratelimit)
376b48c104dSWu Fengguang 	),
377b48c104dSWu Fengguang 
378b48c104dSWu Fengguang 	TP_fast_assign(
379b48c104dSWu Fengguang 		strlcpy(__entry->bdi, dev_name(bdi->dev), 32);
380b48c104dSWu Fengguang 		__entry->write_bw	= KBps(bdi->write_bandwidth);
381b48c104dSWu Fengguang 		__entry->avg_write_bw	= KBps(bdi->avg_write_bandwidth);
382b48c104dSWu Fengguang 		__entry->dirty_rate	= KBps(dirty_rate);
383b48c104dSWu Fengguang 		__entry->dirty_ratelimit = KBps(bdi->dirty_ratelimit);
384b48c104dSWu Fengguang 		__entry->task_ratelimit	= KBps(task_ratelimit);
385b48c104dSWu Fengguang 		__entry->balanced_dirty_ratelimit =
386b48c104dSWu Fengguang 					  KBps(bdi->balanced_dirty_ratelimit);
387b48c104dSWu Fengguang 	),
388b48c104dSWu Fengguang 
389b48c104dSWu Fengguang 	TP_printk("bdi %s: "
390b48c104dSWu Fengguang 		  "write_bw=%lu awrite_bw=%lu dirty_rate=%lu "
391b48c104dSWu Fengguang 		  "dirty_ratelimit=%lu task_ratelimit=%lu "
392b48c104dSWu Fengguang 		  "balanced_dirty_ratelimit=%lu",
393b48c104dSWu Fengguang 		  __entry->bdi,
394b48c104dSWu Fengguang 		  __entry->write_bw,		/* write bandwidth */
395b48c104dSWu Fengguang 		  __entry->avg_write_bw,	/* avg write bandwidth */
396b48c104dSWu Fengguang 		  __entry->dirty_rate,		/* bdi dirty rate */
397b48c104dSWu Fengguang 		  __entry->dirty_ratelimit,	/* base ratelimit */
398b48c104dSWu Fengguang 		  __entry->task_ratelimit, /* ratelimit with position control */
399b48c104dSWu Fengguang 		  __entry->balanced_dirty_ratelimit /* the balanced ratelimit */
400b48c104dSWu Fengguang 	)
401b48c104dSWu Fengguang );
402b48c104dSWu Fengguang 
403ece13ac3SWu Fengguang TRACE_EVENT(balance_dirty_pages,
404ece13ac3SWu Fengguang 
405ece13ac3SWu Fengguang 	TP_PROTO(struct backing_dev_info *bdi,
406ece13ac3SWu Fengguang 		 unsigned long thresh,
407ece13ac3SWu Fengguang 		 unsigned long bg_thresh,
408ece13ac3SWu Fengguang 		 unsigned long dirty,
409ece13ac3SWu Fengguang 		 unsigned long bdi_thresh,
410ece13ac3SWu Fengguang 		 unsigned long bdi_dirty,
411ece13ac3SWu Fengguang 		 unsigned long dirty_ratelimit,
412ece13ac3SWu Fengguang 		 unsigned long task_ratelimit,
413ece13ac3SWu Fengguang 		 unsigned long dirtied,
41483712358SWu Fengguang 		 unsigned long period,
415ece13ac3SWu Fengguang 		 long pause,
416ece13ac3SWu Fengguang 		 unsigned long start_time),
417ece13ac3SWu Fengguang 
418ece13ac3SWu Fengguang 	TP_ARGS(bdi, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty,
419ece13ac3SWu Fengguang 		dirty_ratelimit, task_ratelimit,
42083712358SWu Fengguang 		dirtied, period, pause, start_time),
421ece13ac3SWu Fengguang 
422ece13ac3SWu Fengguang 	TP_STRUCT__entry(
423ece13ac3SWu Fengguang 		__array(	 char,	bdi, 32)
424ece13ac3SWu Fengguang 		__field(unsigned long,	limit)
425ece13ac3SWu Fengguang 		__field(unsigned long,	setpoint)
426ece13ac3SWu Fengguang 		__field(unsigned long,	dirty)
427ece13ac3SWu Fengguang 		__field(unsigned long,	bdi_setpoint)
428ece13ac3SWu Fengguang 		__field(unsigned long,	bdi_dirty)
429ece13ac3SWu Fengguang 		__field(unsigned long,	dirty_ratelimit)
430ece13ac3SWu Fengguang 		__field(unsigned long,	task_ratelimit)
431ece13ac3SWu Fengguang 		__field(unsigned int,	dirtied)
432ece13ac3SWu Fengguang 		__field(unsigned int,	dirtied_pause)
433ece13ac3SWu Fengguang 		__field(unsigned long,	paused)
434ece13ac3SWu Fengguang 		__field(	 long,	pause)
43583712358SWu Fengguang 		__field(unsigned long,	period)
43683712358SWu Fengguang 		__field(	 long,	think)
437ece13ac3SWu Fengguang 	),
438ece13ac3SWu Fengguang 
439ece13ac3SWu Fengguang 	TP_fast_assign(
440ece13ac3SWu Fengguang 		unsigned long freerun = (thresh + bg_thresh) / 2;
441ece13ac3SWu Fengguang 		strlcpy(__entry->bdi, dev_name(bdi->dev), 32);
442ece13ac3SWu Fengguang 
443ece13ac3SWu Fengguang 		__entry->limit		= global_dirty_limit;
444ece13ac3SWu Fengguang 		__entry->setpoint	= (global_dirty_limit + freerun) / 2;
445ece13ac3SWu Fengguang 		__entry->dirty		= dirty;
446ece13ac3SWu Fengguang 		__entry->bdi_setpoint	= __entry->setpoint *
447ece13ac3SWu Fengguang 						bdi_thresh / (thresh + 1);
448ece13ac3SWu Fengguang 		__entry->bdi_dirty	= bdi_dirty;
449ece13ac3SWu Fengguang 		__entry->dirty_ratelimit = KBps(dirty_ratelimit);
450ece13ac3SWu Fengguang 		__entry->task_ratelimit	= KBps(task_ratelimit);
451ece13ac3SWu Fengguang 		__entry->dirtied	= dirtied;
452ece13ac3SWu Fengguang 		__entry->dirtied_pause	= current->nr_dirtied_pause;
45383712358SWu Fengguang 		__entry->think		= current->dirty_paused_when == 0 ? 0 :
45483712358SWu Fengguang 			 (long)(jiffies - current->dirty_paused_when) * 1000/HZ;
45583712358SWu Fengguang 		__entry->period		= period * 1000 / HZ;
456ece13ac3SWu Fengguang 		__entry->pause		= pause * 1000 / HZ;
457ece13ac3SWu Fengguang 		__entry->paused		= (jiffies - start_time) * 1000 / HZ;
458ece13ac3SWu Fengguang 	),
459ece13ac3SWu Fengguang 
460ece13ac3SWu Fengguang 
461ece13ac3SWu Fengguang 	TP_printk("bdi %s: "
462ece13ac3SWu Fengguang 		  "limit=%lu setpoint=%lu dirty=%lu "
463ece13ac3SWu Fengguang 		  "bdi_setpoint=%lu bdi_dirty=%lu "
464ece13ac3SWu Fengguang 		  "dirty_ratelimit=%lu task_ratelimit=%lu "
465ece13ac3SWu Fengguang 		  "dirtied=%u dirtied_pause=%u "
46683712358SWu Fengguang 		  "paused=%lu pause=%ld period=%lu think=%ld",
467ece13ac3SWu Fengguang 		  __entry->bdi,
468ece13ac3SWu Fengguang 		  __entry->limit,
469ece13ac3SWu Fengguang 		  __entry->setpoint,
470ece13ac3SWu Fengguang 		  __entry->dirty,
471ece13ac3SWu Fengguang 		  __entry->bdi_setpoint,
472ece13ac3SWu Fengguang 		  __entry->bdi_dirty,
473ece13ac3SWu Fengguang 		  __entry->dirty_ratelimit,
474ece13ac3SWu Fengguang 		  __entry->task_ratelimit,
475ece13ac3SWu Fengguang 		  __entry->dirtied,
476ece13ac3SWu Fengguang 		  __entry->dirtied_pause,
477ece13ac3SWu Fengguang 		  __entry->paused,	/* ms */
47883712358SWu Fengguang 		  __entry->pause,	/* ms */
47983712358SWu Fengguang 		  __entry->period,	/* ms */
48083712358SWu Fengguang 		  __entry->think	/* ms */
481ece13ac3SWu Fengguang 	  )
482ece13ac3SWu Fengguang );
483ece13ac3SWu Fengguang 
484cc1676d9SJan Kara TRACE_EVENT(writeback_sb_inodes_requeue,
485cc1676d9SJan Kara 
486cc1676d9SJan Kara 	TP_PROTO(struct inode *inode),
487cc1676d9SJan Kara 	TP_ARGS(inode),
488cc1676d9SJan Kara 
489cc1676d9SJan Kara 	TP_STRUCT__entry(
490cc1676d9SJan Kara 		__array(char, name, 32)
491cc1676d9SJan Kara 		__field(unsigned long, ino)
492cc1676d9SJan Kara 		__field(unsigned long, state)
493cc1676d9SJan Kara 		__field(unsigned long, dirtied_when)
494cc1676d9SJan Kara 	),
495cc1676d9SJan Kara 
496cc1676d9SJan Kara 	TP_fast_assign(
497cc1676d9SJan Kara 		strncpy(__entry->name,
498cc1676d9SJan Kara 		        dev_name(inode_to_bdi(inode)->dev), 32);
499cc1676d9SJan Kara 		__entry->ino		= inode->i_ino;
500cc1676d9SJan Kara 		__entry->state		= inode->i_state;
501cc1676d9SJan Kara 		__entry->dirtied_when	= inode->dirtied_when;
502cc1676d9SJan Kara 	),
503cc1676d9SJan Kara 
504cc1676d9SJan Kara 	TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu",
505cc1676d9SJan Kara 		  __entry->name,
506cc1676d9SJan Kara 		  __entry->ino,
507cc1676d9SJan Kara 		  show_inode_state(__entry->state),
508cc1676d9SJan Kara 		  __entry->dirtied_when,
509cc1676d9SJan Kara 		  (jiffies - __entry->dirtied_when) / HZ
510cc1676d9SJan Kara 	)
511cc1676d9SJan Kara );
512cc1676d9SJan Kara 
51352bb9198SMel Gorman DECLARE_EVENT_CLASS(writeback_congest_waited_template,
51452bb9198SMel Gorman 
51552bb9198SMel Gorman 	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
51652bb9198SMel Gorman 
51752bb9198SMel Gorman 	TP_ARGS(usec_timeout, usec_delayed),
51852bb9198SMel Gorman 
51952bb9198SMel Gorman 	TP_STRUCT__entry(
52052bb9198SMel Gorman 		__field(	unsigned int,	usec_timeout	)
52152bb9198SMel Gorman 		__field(	unsigned int,	usec_delayed	)
52252bb9198SMel Gorman 	),
52352bb9198SMel Gorman 
52452bb9198SMel Gorman 	TP_fast_assign(
52552bb9198SMel Gorman 		__entry->usec_timeout	= usec_timeout;
52652bb9198SMel Gorman 		__entry->usec_delayed	= usec_delayed;
52752bb9198SMel Gorman 	),
52852bb9198SMel Gorman 
52952bb9198SMel Gorman 	TP_printk("usec_timeout=%u usec_delayed=%u",
53052bb9198SMel Gorman 			__entry->usec_timeout,
53152bb9198SMel Gorman 			__entry->usec_delayed)
53252bb9198SMel Gorman );
53352bb9198SMel Gorman 
53452bb9198SMel Gorman DEFINE_EVENT(writeback_congest_waited_template, writeback_congestion_wait,
53552bb9198SMel Gorman 
53652bb9198SMel Gorman 	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
53752bb9198SMel Gorman 
53852bb9198SMel Gorman 	TP_ARGS(usec_timeout, usec_delayed)
53952bb9198SMel Gorman );
54052bb9198SMel Gorman 
5410e093d99SMel Gorman DEFINE_EVENT(writeback_congest_waited_template, writeback_wait_iff_congested,
5420e093d99SMel Gorman 
5430e093d99SMel Gorman 	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
5440e093d99SMel Gorman 
5450e093d99SMel Gorman 	TP_ARGS(usec_timeout, usec_delayed)
5460e093d99SMel Gorman );
5470e093d99SMel Gorman 
548251d6a47SWu Fengguang DECLARE_EVENT_CLASS(writeback_single_inode_template,
549251d6a47SWu Fengguang 
550251d6a47SWu Fengguang 	TP_PROTO(struct inode *inode,
551251d6a47SWu Fengguang 		 struct writeback_control *wbc,
552251d6a47SWu Fengguang 		 unsigned long nr_to_write
553251d6a47SWu Fengguang 	),
554251d6a47SWu Fengguang 
555251d6a47SWu Fengguang 	TP_ARGS(inode, wbc, nr_to_write),
556251d6a47SWu Fengguang 
557251d6a47SWu Fengguang 	TP_STRUCT__entry(
558251d6a47SWu Fengguang 		__array(char, name, 32)
559251d6a47SWu Fengguang 		__field(unsigned long, ino)
560251d6a47SWu Fengguang 		__field(unsigned long, state)
561c8ad6206SWu Fengguang 		__field(unsigned long, dirtied_when)
562251d6a47SWu Fengguang 		__field(unsigned long, writeback_index)
563251d6a47SWu Fengguang 		__field(long, nr_to_write)
564251d6a47SWu Fengguang 		__field(unsigned long, wrote)
565251d6a47SWu Fengguang 	),
566251d6a47SWu Fengguang 
567251d6a47SWu Fengguang 	TP_fast_assign(
568251d6a47SWu Fengguang 		strncpy(__entry->name,
56915eb77a0SWu Fengguang 			dev_name(inode_to_bdi(inode)->dev), 32);
570251d6a47SWu Fengguang 		__entry->ino		= inode->i_ino;
571251d6a47SWu Fengguang 		__entry->state		= inode->i_state;
572c8ad6206SWu Fengguang 		__entry->dirtied_when	= inode->dirtied_when;
573251d6a47SWu Fengguang 		__entry->writeback_index = inode->i_mapping->writeback_index;
574251d6a47SWu Fengguang 		__entry->nr_to_write	= nr_to_write;
575251d6a47SWu Fengguang 		__entry->wrote		= nr_to_write - wbc->nr_to_write;
576251d6a47SWu Fengguang 	),
577251d6a47SWu Fengguang 
578c8ad6206SWu Fengguang 	TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu "
579251d6a47SWu Fengguang 		  "index=%lu to_write=%ld wrote=%lu",
580251d6a47SWu Fengguang 		  __entry->name,
581251d6a47SWu Fengguang 		  __entry->ino,
582251d6a47SWu Fengguang 		  show_inode_state(__entry->state),
583c8ad6206SWu Fengguang 		  __entry->dirtied_when,
584c8ad6206SWu Fengguang 		  (jiffies - __entry->dirtied_when) / HZ,
585251d6a47SWu Fengguang 		  __entry->writeback_index,
586251d6a47SWu Fengguang 		  __entry->nr_to_write,
587251d6a47SWu Fengguang 		  __entry->wrote
588251d6a47SWu Fengguang 	)
589251d6a47SWu Fengguang );
590251d6a47SWu Fengguang 
591*9fb0a7daSTejun Heo DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode_start,
592*9fb0a7daSTejun Heo 	TP_PROTO(struct inode *inode,
593*9fb0a7daSTejun Heo 		 struct writeback_control *wbc,
594*9fb0a7daSTejun Heo 		 unsigned long nr_to_write),
595*9fb0a7daSTejun Heo 	TP_ARGS(inode, wbc, nr_to_write)
596*9fb0a7daSTejun Heo );
597*9fb0a7daSTejun Heo 
598251d6a47SWu Fengguang DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode,
599251d6a47SWu Fengguang 	TP_PROTO(struct inode *inode,
600251d6a47SWu Fengguang 		 struct writeback_control *wbc,
601251d6a47SWu Fengguang 		 unsigned long nr_to_write),
602251d6a47SWu Fengguang 	TP_ARGS(inode, wbc, nr_to_write)
603251d6a47SWu Fengguang );
604251d6a47SWu Fengguang 
605455b2864SDave Chinner #endif /* _TRACE_WRITEBACK_H */
606455b2864SDave Chinner 
607455b2864SDave Chinner /* This part must be outside protection */
608455b2864SDave Chinner #include <trace/define_trace.h>
609