device.h: audit and cleanup users in main include dir
[linux-2.6.git] / include / trace / events / writeback.h
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM writeback
3
4 #if !defined(_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_WRITEBACK_H
6
7 #include <linux/backing-dev.h>
8 #include <linux/writeback.h>
9
10 #define show_inode_state(state)                                 \
11         __print_flags(state, "|",                               \
12                 {I_DIRTY_SYNC,          "I_DIRTY_SYNC"},        \
13                 {I_DIRTY_DATASYNC,      "I_DIRTY_DATASYNC"},    \
14                 {I_DIRTY_PAGES,         "I_DIRTY_PAGES"},       \
15                 {I_NEW,                 "I_NEW"},               \
16                 {I_WILL_FREE,           "I_WILL_FREE"},         \
17                 {I_FREEING,             "I_FREEING"},           \
18                 {I_CLEAR,               "I_CLEAR"},             \
19                 {I_SYNC,                "I_SYNC"},              \
20                 {I_REFERENCED,          "I_REFERENCED"}         \
21         )
22
23 #define WB_WORK_REASON                                                  \
24                 {WB_REASON_BACKGROUND,          "background"},          \
25                 {WB_REASON_TRY_TO_FREE_PAGES,   "try_to_free_pages"},   \
26                 {WB_REASON_SYNC,                "sync"},                \
27                 {WB_REASON_PERIODIC,            "periodic"},            \
28                 {WB_REASON_LAPTOP_TIMER,        "laptop_timer"},        \
29                 {WB_REASON_FREE_MORE_MEM,       "free_more_memory"},    \
30                 {WB_REASON_FS_FREE_SPACE,       "fs_free_space"},       \
31                 {WB_REASON_FORKER_THREAD,       "forker_thread"}
32
33 struct wb_writeback_work;
34
35 DECLARE_EVENT_CLASS(writeback_work_class,
36         TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work),
37         TP_ARGS(bdi, work),
38         TP_STRUCT__entry(
39                 __array(char, name, 32)
40                 __field(long, nr_pages)
41                 __field(dev_t, sb_dev)
42                 __field(int, sync_mode)
43                 __field(int, for_kupdate)
44                 __field(int, range_cyclic)
45                 __field(int, for_background)
46                 __field(int, reason)
47         ),
48         TP_fast_assign(
49                 strncpy(__entry->name, dev_name(bdi->dev), 32);
50                 __entry->nr_pages = work->nr_pages;
51                 __entry->sb_dev = work->sb ? work->sb->s_dev : 0;
52                 __entry->sync_mode = work->sync_mode;
53                 __entry->for_kupdate = work->for_kupdate;
54                 __entry->range_cyclic = work->range_cyclic;
55                 __entry->for_background = work->for_background;
56                 __entry->reason = work->reason;
57         ),
58         TP_printk("bdi %s: sb_dev %d:%d nr_pages=%ld sync_mode=%d "
59                   "kupdate=%d range_cyclic=%d background=%d reason=%s",
60                   __entry->name,
61                   MAJOR(__entry->sb_dev), MINOR(__entry->sb_dev),
62                   __entry->nr_pages,
63                   __entry->sync_mode,
64                   __entry->for_kupdate,
65                   __entry->range_cyclic,
66                   __entry->for_background,
67                   __print_symbolic(__entry->reason, WB_WORK_REASON)
68         )
69 );
70 #define DEFINE_WRITEBACK_WORK_EVENT(name) \
71 DEFINE_EVENT(writeback_work_class, name, \
72         TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work), \
73         TP_ARGS(bdi, work))
74 DEFINE_WRITEBACK_WORK_EVENT(writeback_nothread);
75 DEFINE_WRITEBACK_WORK_EVENT(writeback_queue);
76 DEFINE_WRITEBACK_WORK_EVENT(writeback_exec);
77 DEFINE_WRITEBACK_WORK_EVENT(writeback_start);
78 DEFINE_WRITEBACK_WORK_EVENT(writeback_written);
79 DEFINE_WRITEBACK_WORK_EVENT(writeback_wait);
80
81 TRACE_EVENT(writeback_pages_written,
82         TP_PROTO(long pages_written),
83         TP_ARGS(pages_written),
84         TP_STRUCT__entry(
85                 __field(long,           pages)
86         ),
87         TP_fast_assign(
88                 __entry->pages          = pages_written;
89         ),
90         TP_printk("%ld", __entry->pages)
91 );
92
93 DECLARE_EVENT_CLASS(writeback_class,
94         TP_PROTO(struct backing_dev_info *bdi),
95         TP_ARGS(bdi),
96         TP_STRUCT__entry(
97                 __array(char, name, 32)
98         ),
99         TP_fast_assign(
100                 strncpy(__entry->name, dev_name(bdi->dev), 32);
101         ),
102         TP_printk("bdi %s",
103                   __entry->name
104         )
105 );
106 #define DEFINE_WRITEBACK_EVENT(name) \
107 DEFINE_EVENT(writeback_class, name, \
108         TP_PROTO(struct backing_dev_info *bdi), \
109         TP_ARGS(bdi))
110
111 DEFINE_WRITEBACK_EVENT(writeback_nowork);
112 DEFINE_WRITEBACK_EVENT(writeback_wake_background);
113 DEFINE_WRITEBACK_EVENT(writeback_wake_thread);
114 DEFINE_WRITEBACK_EVENT(writeback_wake_forker_thread);
115 DEFINE_WRITEBACK_EVENT(writeback_bdi_register);
116 DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister);
117 DEFINE_WRITEBACK_EVENT(writeback_thread_start);
118 DEFINE_WRITEBACK_EVENT(writeback_thread_stop);
119
120 DECLARE_EVENT_CLASS(wbc_class,
121         TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi),
122         TP_ARGS(wbc, bdi),
123         TP_STRUCT__entry(
124                 __array(char, name, 32)
125                 __field(long, nr_to_write)
126                 __field(long, pages_skipped)
127                 __field(int, sync_mode)
128                 __field(int, for_kupdate)
129                 __field(int, for_background)
130                 __field(int, for_reclaim)
131                 __field(int, range_cyclic)
132                 __field(long, range_start)
133                 __field(long, range_end)
134         ),
135
136         TP_fast_assign(
137                 strncpy(__entry->name, dev_name(bdi->dev), 32);
138                 __entry->nr_to_write    = wbc->nr_to_write;
139                 __entry->pages_skipped  = wbc->pages_skipped;
140                 __entry->sync_mode      = wbc->sync_mode;
141                 __entry->for_kupdate    = wbc->for_kupdate;
142                 __entry->for_background = wbc->for_background;
143                 __entry->for_reclaim    = wbc->for_reclaim;
144                 __entry->range_cyclic   = wbc->range_cyclic;
145                 __entry->range_start    = (long)wbc->range_start;
146                 __entry->range_end      = (long)wbc->range_end;
147         ),
148
149         TP_printk("bdi %s: towrt=%ld skip=%ld mode=%d kupd=%d "
150                 "bgrd=%d reclm=%d cyclic=%d "
151                 "start=0x%lx end=0x%lx",
152                 __entry->name,
153                 __entry->nr_to_write,
154                 __entry->pages_skipped,
155                 __entry->sync_mode,
156                 __entry->for_kupdate,
157                 __entry->for_background,
158                 __entry->for_reclaim,
159                 __entry->range_cyclic,
160                 __entry->range_start,
161                 __entry->range_end)
162 )
163
164 #define DEFINE_WBC_EVENT(name) \
165 DEFINE_EVENT(wbc_class, name, \
166         TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
167         TP_ARGS(wbc, bdi))
168 DEFINE_WBC_EVENT(wbc_writepage);
169
170 TRACE_EVENT(writeback_queue_io,
171         TP_PROTO(struct bdi_writeback *wb,
172                  struct wb_writeback_work *work,
173                  int moved),
174         TP_ARGS(wb, work, moved),
175         TP_STRUCT__entry(
176                 __array(char,           name, 32)
177                 __field(unsigned long,  older)
178                 __field(long,           age)
179                 __field(int,            moved)
180                 __field(int,            reason)
181         ),
182         TP_fast_assign(
183                 unsigned long *older_than_this = work->older_than_this;
184                 strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
185                 __entry->older  = older_than_this ?  *older_than_this : 0;
186                 __entry->age    = older_than_this ?
187                                   (jiffies - *older_than_this) * 1000 / HZ : -1;
188                 __entry->moved  = moved;
189                 __entry->reason = work->reason;
190         ),
191         TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s",
192                 __entry->name,
193                 __entry->older, /* older_than_this in jiffies */
194                 __entry->age,   /* older_than_this in relative milliseconds */
195                 __entry->moved,
196                 __print_symbolic(__entry->reason, WB_WORK_REASON)
197         )
198 );
199
200 TRACE_EVENT(global_dirty_state,
201
202         TP_PROTO(unsigned long background_thresh,
203                  unsigned long dirty_thresh
204         ),
205
206         TP_ARGS(background_thresh,
207                 dirty_thresh
208         ),
209
210         TP_STRUCT__entry(
211                 __field(unsigned long,  nr_dirty)
212                 __field(unsigned long,  nr_writeback)
213                 __field(unsigned long,  nr_unstable)
214                 __field(unsigned long,  background_thresh)
215                 __field(unsigned long,  dirty_thresh)
216                 __field(unsigned long,  dirty_limit)
217                 __field(unsigned long,  nr_dirtied)
218                 __field(unsigned long,  nr_written)
219         ),
220
221         TP_fast_assign(
222                 __entry->nr_dirty       = global_page_state(NR_FILE_DIRTY);
223                 __entry->nr_writeback   = global_page_state(NR_WRITEBACK);
224                 __entry->nr_unstable    = global_page_state(NR_UNSTABLE_NFS);
225                 __entry->nr_dirtied     = global_page_state(NR_DIRTIED);
226                 __entry->nr_written     = global_page_state(NR_WRITTEN);
227                 __entry->background_thresh = background_thresh;
228                 __entry->dirty_thresh   = dirty_thresh;
229                 __entry->dirty_limit = global_dirty_limit;
230         ),
231
232         TP_printk("dirty=%lu writeback=%lu unstable=%lu "
233                   "bg_thresh=%lu thresh=%lu limit=%lu "
234                   "dirtied=%lu written=%lu",
235                   __entry->nr_dirty,
236                   __entry->nr_writeback,
237                   __entry->nr_unstable,
238                   __entry->background_thresh,
239                   __entry->dirty_thresh,
240                   __entry->dirty_limit,
241                   __entry->nr_dirtied,
242                   __entry->nr_written
243         )
244 );
245
246 #define KBps(x)                 ((x) << (PAGE_SHIFT - 10))
247
248 TRACE_EVENT(bdi_dirty_ratelimit,
249
250         TP_PROTO(struct backing_dev_info *bdi,
251                  unsigned long dirty_rate,
252                  unsigned long task_ratelimit),
253
254         TP_ARGS(bdi, dirty_rate, task_ratelimit),
255
256         TP_STRUCT__entry(
257                 __array(char,           bdi, 32)
258                 __field(unsigned long,  write_bw)
259                 __field(unsigned long,  avg_write_bw)
260                 __field(unsigned long,  dirty_rate)
261                 __field(unsigned long,  dirty_ratelimit)
262                 __field(unsigned long,  task_ratelimit)
263                 __field(unsigned long,  balanced_dirty_ratelimit)
264         ),
265
266         TP_fast_assign(
267                 strlcpy(__entry->bdi, dev_name(bdi->dev), 32);
268                 __entry->write_bw       = KBps(bdi->write_bandwidth);
269                 __entry->avg_write_bw   = KBps(bdi->avg_write_bandwidth);
270                 __entry->dirty_rate     = KBps(dirty_rate);
271                 __entry->dirty_ratelimit = KBps(bdi->dirty_ratelimit);
272                 __entry->task_ratelimit = KBps(task_ratelimit);
273                 __entry->balanced_dirty_ratelimit =
274                                           KBps(bdi->balanced_dirty_ratelimit);
275         ),
276
277         TP_printk("bdi %s: "
278                   "write_bw=%lu awrite_bw=%lu dirty_rate=%lu "
279                   "dirty_ratelimit=%lu task_ratelimit=%lu "
280                   "balanced_dirty_ratelimit=%lu",
281                   __entry->bdi,
282                   __entry->write_bw,            /* write bandwidth */
283                   __entry->avg_write_bw,        /* avg write bandwidth */
284                   __entry->dirty_rate,          /* bdi dirty rate */
285                   __entry->dirty_ratelimit,     /* base ratelimit */
286                   __entry->task_ratelimit, /* ratelimit with position control */
287                   __entry->balanced_dirty_ratelimit /* the balanced ratelimit */
288         )
289 );
290
291 TRACE_EVENT(balance_dirty_pages,
292
293         TP_PROTO(struct backing_dev_info *bdi,
294                  unsigned long thresh,
295                  unsigned long bg_thresh,
296                  unsigned long dirty,
297                  unsigned long bdi_thresh,
298                  unsigned long bdi_dirty,
299                  unsigned long dirty_ratelimit,
300                  unsigned long task_ratelimit,
301                  unsigned long dirtied,
302                  unsigned long period,
303                  long pause,
304                  unsigned long start_time),
305
306         TP_ARGS(bdi, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty,
307                 dirty_ratelimit, task_ratelimit,
308                 dirtied, period, pause, start_time),
309
310         TP_STRUCT__entry(
311                 __array(         char,  bdi, 32)
312                 __field(unsigned long,  limit)
313                 __field(unsigned long,  setpoint)
314                 __field(unsigned long,  dirty)
315                 __field(unsigned long,  bdi_setpoint)
316                 __field(unsigned long,  bdi_dirty)
317                 __field(unsigned long,  dirty_ratelimit)
318                 __field(unsigned long,  task_ratelimit)
319                 __field(unsigned int,   dirtied)
320                 __field(unsigned int,   dirtied_pause)
321                 __field(unsigned long,  paused)
322                 __field(         long,  pause)
323                 __field(unsigned long,  period)
324                 __field(         long,  think)
325         ),
326
327         TP_fast_assign(
328                 unsigned long freerun = (thresh + bg_thresh) / 2;
329                 strlcpy(__entry->bdi, dev_name(bdi->dev), 32);
330
331                 __entry->limit          = global_dirty_limit;
332                 __entry->setpoint       = (global_dirty_limit + freerun) / 2;
333                 __entry->dirty          = dirty;
334                 __entry->bdi_setpoint   = __entry->setpoint *
335                                                 bdi_thresh / (thresh + 1);
336                 __entry->bdi_dirty      = bdi_dirty;
337                 __entry->dirty_ratelimit = KBps(dirty_ratelimit);
338                 __entry->task_ratelimit = KBps(task_ratelimit);
339                 __entry->dirtied        = dirtied;
340                 __entry->dirtied_pause  = current->nr_dirtied_pause;
341                 __entry->think          = current->dirty_paused_when == 0 ? 0 :
342                          (long)(jiffies - current->dirty_paused_when) * 1000/HZ;
343                 __entry->period         = period * 1000 / HZ;
344                 __entry->pause          = pause * 1000 / HZ;
345                 __entry->paused         = (jiffies - start_time) * 1000 / HZ;
346         ),
347
348
349         TP_printk("bdi %s: "
350                   "limit=%lu setpoint=%lu dirty=%lu "
351                   "bdi_setpoint=%lu bdi_dirty=%lu "
352                   "dirty_ratelimit=%lu task_ratelimit=%lu "
353                   "dirtied=%u dirtied_pause=%u "
354                   "paused=%lu pause=%ld period=%lu think=%ld",
355                   __entry->bdi,
356                   __entry->limit,
357                   __entry->setpoint,
358                   __entry->dirty,
359                   __entry->bdi_setpoint,
360                   __entry->bdi_dirty,
361                   __entry->dirty_ratelimit,
362                   __entry->task_ratelimit,
363                   __entry->dirtied,
364                   __entry->dirtied_pause,
365                   __entry->paused,      /* ms */
366                   __entry->pause,       /* ms */
367                   __entry->period,      /* ms */
368                   __entry->think        /* ms */
369           )
370 );
371
372 DECLARE_EVENT_CLASS(writeback_congest_waited_template,
373
374         TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
375
376         TP_ARGS(usec_timeout, usec_delayed),
377
378         TP_STRUCT__entry(
379                 __field(        unsigned int,   usec_timeout    )
380                 __field(        unsigned int,   usec_delayed    )
381         ),
382
383         TP_fast_assign(
384                 __entry->usec_timeout   = usec_timeout;
385                 __entry->usec_delayed   = usec_delayed;
386         ),
387
388         TP_printk("usec_timeout=%u usec_delayed=%u",
389                         __entry->usec_timeout,
390                         __entry->usec_delayed)
391 );
392
393 DEFINE_EVENT(writeback_congest_waited_template, writeback_congestion_wait,
394
395         TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
396
397         TP_ARGS(usec_timeout, usec_delayed)
398 );
399
400 DEFINE_EVENT(writeback_congest_waited_template, writeback_wait_iff_congested,
401
402         TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
403
404         TP_ARGS(usec_timeout, usec_delayed)
405 );
406
407 DECLARE_EVENT_CLASS(writeback_single_inode_template,
408
409         TP_PROTO(struct inode *inode,
410                  struct writeback_control *wbc,
411                  unsigned long nr_to_write
412         ),
413
414         TP_ARGS(inode, wbc, nr_to_write),
415
416         TP_STRUCT__entry(
417                 __array(char, name, 32)
418                 __field(unsigned long, ino)
419                 __field(unsigned long, state)
420                 __field(unsigned long, dirtied_when)
421                 __field(unsigned long, writeback_index)
422                 __field(long, nr_to_write)
423                 __field(unsigned long, wrote)
424         ),
425
426         TP_fast_assign(
427                 strncpy(__entry->name,
428                         dev_name(inode->i_mapping->backing_dev_info->dev), 32);
429                 __entry->ino            = inode->i_ino;
430                 __entry->state          = inode->i_state;
431                 __entry->dirtied_when   = inode->dirtied_when;
432                 __entry->writeback_index = inode->i_mapping->writeback_index;
433                 __entry->nr_to_write    = nr_to_write;
434                 __entry->wrote          = nr_to_write - wbc->nr_to_write;
435         ),
436
437         TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu "
438                   "index=%lu to_write=%ld wrote=%lu",
439                   __entry->name,
440                   __entry->ino,
441                   show_inode_state(__entry->state),
442                   __entry->dirtied_when,
443                   (jiffies - __entry->dirtied_when) / HZ,
444                   __entry->writeback_index,
445                   __entry->nr_to_write,
446                   __entry->wrote
447         )
448 );
449
450 DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode_requeue,
451         TP_PROTO(struct inode *inode,
452                  struct writeback_control *wbc,
453                  unsigned long nr_to_write),
454         TP_ARGS(inode, wbc, nr_to_write)
455 );
456
457 DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode,
458         TP_PROTO(struct inode *inode,
459                  struct writeback_control *wbc,
460                  unsigned long nr_to_write),
461         TP_ARGS(inode, wbc, nr_to_write)
462 );
463
464 #endif /* _TRACE_WRITEBACK_H */
465
466 /* This part must be outside protection */
467 #include <trace/define_trace.h>