2 * drivers/misc/tegra-profiler/mmap.c
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/slab.h>
22 #include <linux/err.h>
23 #include <linux/sched.h>
25 #include <linux/tegra_profiler.h>
32 put_mmap_sample(struct quadd_mmap_data *s, char *filename,
35 struct quadd_record_data r;
36 struct quadd_iovec vec;
38 r.magic = QUADD_RECORD_MAGIC;
39 r.record_type = QUADD_RECORD_TYPE_MMAP;
41 memcpy(&r.mmap, s, sizeof(*s));
42 r.mmap.filename_length = length;
47 pr_debug("MMAP: pid: %u, file_name: '%s', addr: %#llx - %#llx, len: %llx, pgoff: %#x\n",
48 s->pid, filename, s->addr, s->addr + s->len, s->len, s->pgoff);
50 quadd_put_sample(&r, &vec, 1);
53 void quadd_process_mmap(struct vm_area_struct *vma)
57 char *file_name, *tmp_buf;
58 struct quadd_mmap_data sample;
59 size_t length, length_aligned;
64 if (!(vma->vm_flags & VM_EXEC))
67 vm_file = vma->vm_file;
71 path = &vm_file->f_path;
73 tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
77 file_name = d_path(path, tmp_buf, PATH_MAX);
78 if (IS_ERR(file_name))
81 if (strstr(file_name, " (deleted)"))
84 sample.addr = vma->vm_start;
85 sample.len = vma->vm_end - vma->vm_start;
86 sample.pgoff = vma->vm_pgoff;
88 length = strlen(file_name) + 1;
89 length_aligned = ALIGN(length, sizeof(u64));
91 put_mmap_sample(&sample, file_name, length_aligned);
97 int quadd_get_current_mmap(pid_t pid)
99 struct vm_area_struct *vma;
100 struct file *vm_file;
103 struct task_struct *task;
104 struct mm_struct *mm;
105 struct quadd_mmap_data sample;
106 size_t length, length_aligned;
110 task = pid_task(find_vpid(pid), PIDTYPE_PID);
113 pr_err("Process not found: %d\n", pid);
119 pr_warn("mm is not existed for task: %d\n", pid);
123 pr_info("Get mapped memory objects\n");
125 tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
129 for (vma = mm->mmap; vma; vma = vma->vm_next) {
130 if (!(vma->vm_flags & VM_EXEC))
133 vm_file = vma->vm_file;
137 path = &vm_file->f_path;
139 file_name = d_path(path, tmp_buf, PATH_MAX);
140 if (IS_ERR(file_name))
143 if (strstr(file_name, " (deleted)"))
146 length = strlen(file_name) + 1;
147 length_aligned = ALIGN(length, sizeof(u64));
150 sample.addr = vma->vm_start;
151 sample.len = vma->vm_end - vma->vm_start;
152 sample.pgoff = vma->vm_pgoff;
154 put_mmap_sample(&sample, file_name, length_aligned);