3 * modules/us_manager/img/img_proc.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin: SWAP us_manager implement
26 #include <linux/slab.h>
27 #include <linux/list.h>
28 #include <linux/spinlock.h>
29 #include <us_manager/sspt/sspt_proc.h>
30 #include <us_manager/sspt/sspt_file.h>
37 struct list_head file_list;
42 static void img_del_file_by_list(struct img_file *file);
45 * @brief Create img_proc struct
47 * @return Pointer to the created img_proc struct
49 struct img_proc *create_img_proc(void)
51 struct img_proc *proc;
53 proc = kmalloc(sizeof(*proc), GFP_ATOMIC);
55 INIT_LIST_HEAD(&proc->file_list);
56 rwlock_init(&proc->rwlock);
63 * @brief Remove img_proc struct
65 * @param file remove object
68 void free_img_proc(struct img_proc *proc)
70 struct img_file *file, *tmp;
72 list_for_each_entry_safe(file, tmp, &proc->file_list, list) {
73 img_del_file_by_list(file);
80 /* called with write_[lock/unlock](&proc->rwlock) */
81 static void img_add_file_by_list(struct img_proc *proc, struct img_file *file)
83 list_add(&file->list, &proc->file_list);
86 /* called with write_[lock/unlock](&proc->rwlock) */
87 static void img_del_file_by_list(struct img_file *file)
89 list_del(&file->list);
92 /* called with read_[lock/unlock](&proc->rwlock) */
93 static struct img_file *find_img_file(struct img_proc *proc,
94 struct dentry *dentry)
96 struct img_file *file;
98 list_for_each_entry(file, &proc->file_list, list) {
99 if (file->dentry == dentry)
107 * @brief Add instrumentation pointer
109 * @param proc Pointer to the img_proc struct
110 * @param dentry Dentry of file
111 * @param addr Function address
112 * @param probe_i Pointer to a probe_info struct related with the probe
115 int img_proc_add_ip(struct img_proc *proc, struct dentry *dentry,
116 unsigned long addr, struct probe_info *probe_i)
119 struct img_file *file;
121 write_lock(&proc->rwlock);
122 file = find_img_file(proc, dentry);
124 ret = img_file_add_ip(file, addr, probe_i);
128 file = create_img_file(dentry);
134 ret = img_file_add_ip(file, addr, probe_i);
136 printk(KERN_INFO "Cannot add ip to img file\n");
139 img_add_file_by_list(proc, file);
143 write_unlock(&proc->rwlock);
148 * @brief Remove instrumentation pointer
150 * @param proc Pointer to the img_proc struct
151 * @param dentry Dentry of file
152 * @param args Function address
155 int img_proc_del_ip(struct img_proc *proc,
156 struct dentry *dentry,
160 struct img_file *file;
162 write_lock(&proc->rwlock);
163 file = find_img_file(proc, dentry);
169 ret = img_file_del_ip(file, addr);
170 if (ret == 0 && img_file_empty(file)) {
171 img_del_file_by_list(file);
176 write_unlock(&proc->rwlock);
180 void img_proc_copy_to_sspt(struct img_proc *i_proc, struct sspt_proc *proc)
182 struct sspt_file *file;
183 struct img_file *i_file;
185 read_lock(&i_proc->rwlock);
186 list_for_each_entry(i_file, &i_proc->file_list, list) {
187 file = sspt_proc_find_file_or_new(proc, i_file->dentry);
192 list_for_each_entry(i_ip, &i_file->ip_list, list)
193 sspt_file_add_ip(file, i_ip->addr, i_ip->info);
196 read_unlock(&i_proc->rwlock);
202 * @param proc Pointer to the img_proc struct
207 void img_proc_print(struct img_proc *proc)
209 struct img_file *file;
211 printk(KERN_INFO "### img_proc_print:\n");
213 read_lock(&proc->rwlock);
214 list_for_each_entry(file, &proc->file_list, list) {
215 img_file_print(file);
217 read_unlock(&proc->rwlock);