]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/f2fs/trace.c
Merge tag 'sound-4.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[mirror_ubuntu-artful-kernel.git] / fs / f2fs / trace.c
CommitLineData
63f92ddc
JK
1/*
2 * f2fs IO tracer
3 *
4 * Copyright (c) 2014 Motorola Mobility
5 * Copyright (c) 2014 Jaegeuk Kim <jaegeuk@kernel.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/fs.h>
12#include <linux/f2fs_fs.h>
13#include <linux/sched.h>
351f4fba 14#include <linux/radix-tree.h>
63f92ddc
JK
15
16#include "f2fs.h"
17#include "trace.h"
18
29e7043f 19static RADIX_TREE(pids, GFP_ATOMIC);
08e4126e 20static spinlock_t pids_lock;
29e7043f 21static struct last_io_info last_io;
0e689d03
JK
22
23static inline void __print_last_io(void)
24{
25 if (!last_io.len)
26 return;
27
04d328de 28 trace_printk("%3x:%3x %4x %-16s %2x %5x %5x %12x %4x\n",
0e689d03
JK
29 last_io.major, last_io.minor,
30 last_io.pid, "----------------",
31 last_io.type,
04d328de 32 last_io.fio.op, last_io.fio.op_flags,
7a9d7548 33 last_io.fio.new_blkaddr,
0e689d03
JK
34 last_io.len);
35 memset(&last_io, 0, sizeof(last_io));
36}
37
38static int __file_type(struct inode *inode, pid_t pid)
39{
40 if (f2fs_is_atomic_file(inode))
41 return __ATOMIC_FILE;
42 else if (f2fs_is_volatile_file(inode))
43 return __VOLATILE_FILE;
44 else if (S_ISDIR(inode->i_mode))
45 return __DIR_FILE;
46 else if (inode->i_ino == F2FS_NODE_INO(F2FS_I_SB(inode)))
47 return __NODE_FILE;
48 else if (inode->i_ino == F2FS_META_INO(F2FS_I_SB(inode)))
49 return __META_FILE;
50 else if (pid)
51 return __NORMAL_FILE;
52 else
53 return __MISC_FILE;
54}
55
63f92ddc
JK
56void f2fs_trace_pid(struct page *page)
57{
0e689d03
JK
58 struct inode *inode = page->mapping->host;
59 pid_t pid = task_pid_nr(current);
60 void *p;
61
5f4c3dec 62 set_page_private(page, (unsigned long)pid);
0e689d03 63
c0508650
JK
64 if (radix_tree_preload(GFP_NOFS))
65 return;
66
67 spin_lock(&pids_lock);
0e689d03
JK
68 p = radix_tree_lookup(&pids, pid);
69 if (p == current)
c0508650 70 goto out;
0e689d03
JK
71 if (p)
72 radix_tree_delete(&pids, pid);
73
74 f2fs_radix_tree_insert(&pids, pid, current);
75
76 trace_printk("%3x:%3x %4x %-16s\n",
77 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
78 pid, current->comm);
c0508650
JK
79out:
80 spin_unlock(&pids_lock);
81 radix_tree_preload_end();
63f92ddc
JK
82}
83
05ca3632 84void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
63f92ddc 85{
0e689d03
JK
86 struct inode *inode;
87 pid_t pid;
88 int major, minor;
89
90 if (flush) {
91 __print_last_io();
92 return;
93 }
94
05ca3632
JK
95 inode = fio->page->mapping->host;
96 pid = page_private(fio->page);
0e689d03
JK
97
98 major = MAJOR(inode->i_sb->s_dev);
99 minor = MINOR(inode->i_sb->s_dev);
100
101 if (last_io.major == major && last_io.minor == minor &&
102 last_io.pid == pid &&
103 last_io.type == __file_type(inode, pid) &&
04d328de
MC
104 last_io.fio.op == fio->op &&
105 last_io.fio.op_flags == fio->op_flags &&
7a9d7548
CY
106 last_io.fio.new_blkaddr + last_io.len ==
107 fio->new_blkaddr) {
0e689d03
JK
108 last_io.len++;
109 return;
110 }
111
112 __print_last_io();
113
114 last_io.major = major;
115 last_io.minor = minor;
116 last_io.pid = pid;
117 last_io.type = __file_type(inode, pid);
118 last_io.fio = *fio;
119 last_io.len = 1;
120 return;
63f92ddc 121}
c0508650
JK
122
123void f2fs_build_trace_ios(void)
124{
125 spin_lock_init(&pids_lock);
126}
351f4fba
JK
127
128#define PIDVEC_SIZE 128
129static unsigned int gang_lookup_pids(pid_t *results, unsigned long first_index,
130 unsigned int max_items)
131{
132 struct radix_tree_iter iter;
133 void **slot;
134 unsigned int ret = 0;
135
136 if (unlikely(!max_items))
137 return 0;
138
139 radix_tree_for_each_slot(slot, &pids, &iter, first_index) {
140 results[ret] = iter.index;
b0beab50 141 if (++ret == max_items)
351f4fba
JK
142 break;
143 }
144 return ret;
145}
146
147void f2fs_destroy_trace_ios(void)
148{
149 pid_t pid[PIDVEC_SIZE];
150 pid_t next_pid = 0;
151 unsigned int found;
152
153 spin_lock(&pids_lock);
154 while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
155 unsigned idx;
156
157 next_pid = pid[found - 1] + 1;
158 for (idx = 0; idx < found; idx++)
159 radix_tree_delete(&pids, pid[idx]);
160 }
161 spin_unlock(&pids_lock);
162}