mm, compaction: export tracepoints status strings to userspace
[cascardo/linux.git] / include / trace / events / compaction.h
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM compaction
3
4 #if !defined(_TRACE_COMPACTION_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_COMPACTION_H
6
7 #include <linux/types.h>
8 #include <linux/list.h>
9 #include <linux/tracepoint.h>
10 #include <trace/events/gfpflags.h>
11
12 #define COMPACTION_STATUS                                       \
13         EM( COMPACT_DEFERRED,           "deferred")             \
14         EM( COMPACT_SKIPPED,            "skipped")              \
15         EM( COMPACT_CONTINUE,           "continue")             \
16         EM( COMPACT_PARTIAL,            "partial")              \
17         EM( COMPACT_COMPLETE,           "complete")             \
18         EM( COMPACT_NO_SUITABLE_PAGE,   "no_suitable_page")     \
19         EMe(COMPACT_NOT_SUITABLE_ZONE,  "not_suitable_zone")
20
21 /*
22  * First define the enums in the above macros to be exported to userspace
23  * via TRACE_DEFINE_ENUM().
24  */
25 #undef EM
26 #undef EMe
27 #define EM(a, b)        TRACE_DEFINE_ENUM(a);
28 #define EMe(a, b)       TRACE_DEFINE_ENUM(a);
29
30 COMPACTION_STATUS
31
32 /*
33  * Now redefine the EM() and EMe() macros to map the enums to the strings
34  * that will be printed in the output.
35  */
36 #undef EM
37 #undef EMe
38 #define EM(a, b)        {a, b},
39 #define EMe(a, b)       {a, b}
40
41 DECLARE_EVENT_CLASS(mm_compaction_isolate_template,
42
43         TP_PROTO(
44                 unsigned long start_pfn,
45                 unsigned long end_pfn,
46                 unsigned long nr_scanned,
47                 unsigned long nr_taken),
48
49         TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken),
50
51         TP_STRUCT__entry(
52                 __field(unsigned long, start_pfn)
53                 __field(unsigned long, end_pfn)
54                 __field(unsigned long, nr_scanned)
55                 __field(unsigned long, nr_taken)
56         ),
57
58         TP_fast_assign(
59                 __entry->start_pfn = start_pfn;
60                 __entry->end_pfn = end_pfn;
61                 __entry->nr_scanned = nr_scanned;
62                 __entry->nr_taken = nr_taken;
63         ),
64
65         TP_printk("range=(0x%lx ~ 0x%lx) nr_scanned=%lu nr_taken=%lu",
66                 __entry->start_pfn,
67                 __entry->end_pfn,
68                 __entry->nr_scanned,
69                 __entry->nr_taken)
70 );
71
72 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_migratepages,
73
74         TP_PROTO(
75                 unsigned long start_pfn,
76                 unsigned long end_pfn,
77                 unsigned long nr_scanned,
78                 unsigned long nr_taken),
79
80         TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
81 );
82
83 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_freepages,
84
85         TP_PROTO(
86                 unsigned long start_pfn,
87                 unsigned long end_pfn,
88                 unsigned long nr_scanned,
89                 unsigned long nr_taken),
90
91         TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
92 );
93
94 TRACE_EVENT(mm_compaction_migratepages,
95
96         TP_PROTO(unsigned long nr_all,
97                 int migrate_rc,
98                 struct list_head *migratepages),
99
100         TP_ARGS(nr_all, migrate_rc, migratepages),
101
102         TP_STRUCT__entry(
103                 __field(unsigned long, nr_migrated)
104                 __field(unsigned long, nr_failed)
105         ),
106
107         TP_fast_assign(
108                 unsigned long nr_failed = 0;
109                 struct list_head *page_lru;
110
111                 /*
112                  * migrate_pages() returns either a non-negative number
113                  * with the number of pages that failed migration, or an
114                  * error code, in which case we need to count the remaining
115                  * pages manually
116                  */
117                 if (migrate_rc >= 0)
118                         nr_failed = migrate_rc;
119                 else
120                         list_for_each(page_lru, migratepages)
121                                 nr_failed++;
122
123                 __entry->nr_migrated = nr_all - nr_failed;
124                 __entry->nr_failed = nr_failed;
125         ),
126
127         TP_printk("nr_migrated=%lu nr_failed=%lu",
128                 __entry->nr_migrated,
129                 __entry->nr_failed)
130 );
131
132 TRACE_EVENT(mm_compaction_begin,
133         TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
134                 unsigned long free_pfn, unsigned long zone_end, bool sync),
135
136         TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync),
137
138         TP_STRUCT__entry(
139                 __field(unsigned long, zone_start)
140                 __field(unsigned long, migrate_pfn)
141                 __field(unsigned long, free_pfn)
142                 __field(unsigned long, zone_end)
143                 __field(bool, sync)
144         ),
145
146         TP_fast_assign(
147                 __entry->zone_start = zone_start;
148                 __entry->migrate_pfn = migrate_pfn;
149                 __entry->free_pfn = free_pfn;
150                 __entry->zone_end = zone_end;
151                 __entry->sync = sync;
152         ),
153
154         TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s",
155                 __entry->zone_start,
156                 __entry->migrate_pfn,
157                 __entry->free_pfn,
158                 __entry->zone_end,
159                 __entry->sync ? "sync" : "async")
160 );
161
162 TRACE_EVENT(mm_compaction_end,
163         TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
164                 unsigned long free_pfn, unsigned long zone_end, bool sync,
165                 int status),
166
167         TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync, status),
168
169         TP_STRUCT__entry(
170                 __field(unsigned long, zone_start)
171                 __field(unsigned long, migrate_pfn)
172                 __field(unsigned long, free_pfn)
173                 __field(unsigned long, zone_end)
174                 __field(bool, sync)
175                 __field(int, status)
176         ),
177
178         TP_fast_assign(
179                 __entry->zone_start = zone_start;
180                 __entry->migrate_pfn = migrate_pfn;
181                 __entry->free_pfn = free_pfn;
182                 __entry->zone_end = zone_end;
183                 __entry->sync = sync;
184                 __entry->status = status;
185         ),
186
187         TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s status=%s",
188                 __entry->zone_start,
189                 __entry->migrate_pfn,
190                 __entry->free_pfn,
191                 __entry->zone_end,
192                 __entry->sync ? "sync" : "async",
193                 __print_symbolic(__entry->status, COMPACTION_STATUS))
194 );
195
196 TRACE_EVENT(mm_compaction_try_to_compact_pages,
197
198         TP_PROTO(
199                 int order,
200                 gfp_t gfp_mask,
201                 enum migrate_mode mode),
202
203         TP_ARGS(order, gfp_mask, mode),
204
205         TP_STRUCT__entry(
206                 __field(int, order)
207                 __field(gfp_t, gfp_mask)
208                 __field(enum migrate_mode, mode)
209         ),
210
211         TP_fast_assign(
212                 __entry->order = order;
213                 __entry->gfp_mask = gfp_mask;
214                 __entry->mode = mode;
215         ),
216
217         TP_printk("order=%d gfp_mask=0x%x mode=%d",
218                 __entry->order,
219                 __entry->gfp_mask,
220                 (int)__entry->mode)
221 );
222
223 DECLARE_EVENT_CLASS(mm_compaction_suitable_template,
224
225         TP_PROTO(struct zone *zone,
226                 int order,
227                 int ret),
228
229         TP_ARGS(zone, order, ret),
230
231         TP_STRUCT__entry(
232                 __field(int, nid)
233                 __field(char *, name)
234                 __field(int, order)
235                 __field(int, ret)
236         ),
237
238         TP_fast_assign(
239                 __entry->nid = zone_to_nid(zone);
240                 __entry->name = (char *)zone->name;
241                 __entry->order = order;
242                 __entry->ret = ret;
243         ),
244
245         TP_printk("node=%d zone=%-8s order=%d ret=%s",
246                 __entry->nid,
247                 __entry->name,
248                 __entry->order,
249                 __print_symbolic(__entry->ret, COMPACTION_STATUS))
250 );
251
252 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_finished,
253
254         TP_PROTO(struct zone *zone,
255                 int order,
256                 int ret),
257
258         TP_ARGS(zone, order, ret)
259 );
260
261 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_suitable,
262
263         TP_PROTO(struct zone *zone,
264                 int order,
265                 int ret),
266
267         TP_ARGS(zone, order, ret)
268 );
269
270 #ifdef CONFIG_COMPACTION
271 DECLARE_EVENT_CLASS(mm_compaction_defer_template,
272
273         TP_PROTO(struct zone *zone, int order),
274
275         TP_ARGS(zone, order),
276
277         TP_STRUCT__entry(
278                 __field(int, nid)
279                 __field(char *, name)
280                 __field(int, order)
281                 __field(unsigned int, considered)
282                 __field(unsigned int, defer_shift)
283                 __field(int, order_failed)
284         ),
285
286         TP_fast_assign(
287                 __entry->nid = zone_to_nid(zone);
288                 __entry->name = (char *)zone->name;
289                 __entry->order = order;
290                 __entry->considered = zone->compact_considered;
291                 __entry->defer_shift = zone->compact_defer_shift;
292                 __entry->order_failed = zone->compact_order_failed;
293         ),
294
295         TP_printk("node=%d zone=%-8s order=%d order_failed=%d consider=%u limit=%lu",
296                 __entry->nid,
297                 __entry->name,
298                 __entry->order,
299                 __entry->order_failed,
300                 __entry->considered,
301                 1UL << __entry->defer_shift)
302 );
303
304 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_deferred,
305
306         TP_PROTO(struct zone *zone, int order),
307
308         TP_ARGS(zone, order)
309 );
310
311 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_compaction,
312
313         TP_PROTO(struct zone *zone, int order),
314
315         TP_ARGS(zone, order)
316 );
317
318 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_reset,
319
320         TP_PROTO(struct zone *zone, int order),
321
322         TP_ARGS(zone, order)
323 );
324 #endif
325
326 #endif /* _TRACE_COMPACTION_H */
327
328 /* This part must be outside protection */
329 #include <trace/define_trace.h>