diff --git a/arch/nvgpu-linux.yaml b/arch/nvgpu-linux.yaml index b647215de..dff9cbe94 100644 --- a/arch/nvgpu-linux.yaml +++ b/arch/nvgpu-linux.yaml @@ -86,6 +86,8 @@ debug: os/linux/debug_s_param.h, os/linux/debug_volt.c, os/linux/debug_volt.h, + os/linux/swprofile_debugfs.c, + os/linux/swprofile_debugfs.h, os/linux/fecs_trace_linux.c, os/linux/fecs_trace_linux.h, os/linux/nvlink_probe.c ] diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 63c2778b0..feb9aa705 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -408,7 +408,8 @@ nvgpu-$(CONFIG_DEBUG_FS) += \ os/linux/debug_clk_gm20b.o \ os/linux/debug_ltc.o \ os/linux/debug_volt.o \ - os/linux/debug_s_param.o + os/linux/debug_s_param.o \ + os/linux/swprofile_debugfs.o nvgpu-$(CONFIG_NVGPU_LOGGING) += os/linux/log.o diff --git a/drivers/gpu/nvgpu/os/linux/debug_fifo.c b/drivers/gpu/nvgpu/os/linux/debug_fifo.c index 39c555ecd..7a29325f7 100644 --- a/drivers/gpu/nvgpu/os/linux/debug_fifo.c +++ b/drivers/gpu/nvgpu/os/linux/debug_fifo.c @@ -12,22 +12,17 @@ */ #include "debug_fifo.h" +#include "swprofile_debugfs.h" #include "os_linux.h" #include #include -#include #include #include #include #include #include -#include - -#include - -void __gk20a_fifo_profile_free(struct nvgpu_ref *ref); static void *gk20a_fifo_sched_debugfs_seq_start( struct seq_file *s, loff_t *pos) @@ -143,87 +138,11 @@ static const struct file_operations gk20a_fifo_sched_debugfs_fops = { .release = seq_release }; -static int gk20a_fifo_profile_enable(void *data, u64 val) -{ - struct gk20a *g = (struct gk20a *) data; - struct nvgpu_fifo *f = &g->fifo; - - if (val == 0) { - nvgpu_swprofile_close(&f->kickoff_profiler); - return 0; - } else { - return nvgpu_swprofile_open(g, &f->kickoff_profiler); - } -} - -DEFINE_SIMPLE_ATTRIBUTE( - gk20a_fifo_profile_enable_debugfs_fops, - NULL, - gk20a_fifo_profile_enable, - "%llu\n" -); - -static void gk20a_fifo_write_to_seqfile_no_nl(void *ctx, const char *str) -{ - seq_printf((struct seq_file *)ctx, str); -} - -static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) -{ - struct gk20a *g = s->private; - struct nvgpu_debug_context o = { - .fn = gk20a_fifo_write_to_seqfile_no_nl, - .ctx = s, - }; - - nvgpu_swprofile_print_ranges(g, &g->fifo.kickoff_profiler, &o); - - return 0; -} - -static int gk20a_fifo_profile_stats_open(struct inode *inode, struct file *file) -{ - return single_open(file, gk20a_fifo_profile_stats, inode->i_private); -} - -static const struct file_operations gk20a_fifo_profile_stats_debugfs_fops = { - .open = gk20a_fifo_profile_stats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int gk20a_fifo_profile_raw_data(struct seq_file *s, void *unused) -{ - struct gk20a *g = s->private; - struct nvgpu_debug_context o = { - .fn = gk20a_fifo_write_to_seqfile_no_nl, - .ctx = s, - }; - - nvgpu_swprofile_print_raw_data(g, &g->fifo.kickoff_profiler, &o); - - return 0; -} - -static int gk20a_fifo_profile_raw_data_open(struct inode *inode, struct file *file) -{ - return single_open(file, gk20a_fifo_profile_raw_data, inode->i_private); -} - -static const struct file_operations gk20a_fifo_profile_raw_data_debugfs_fops = { - .open = gk20a_fifo_profile_raw_data_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - void gk20a_fifo_debugfs_init(struct gk20a *g) { struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); struct dentry *gpu_root = l->debugfs; struct dentry *fifo_root; - struct dentry *profile_root; fifo_root = debugfs_create_dir("fifo", gpu_root); if (IS_ERR_OR_NULL(fifo_root)) @@ -234,16 +153,5 @@ void gk20a_fifo_debugfs_init(struct gk20a *g) debugfs_create_file("sched", 0600, fifo_root, g, &gk20a_fifo_sched_debugfs_fops); - profile_root = debugfs_create_dir("profile", fifo_root); - if (IS_ERR_OR_NULL(profile_root)) - return; - - debugfs_create_file("enable", 0600, profile_root, g, - &gk20a_fifo_profile_enable_debugfs_fops); - - debugfs_create_file("stats", 0600, profile_root, g, - &gk20a_fifo_profile_stats_debugfs_fops); - - debugfs_create_file("raw_data", 0600, profile_root, g, - &gk20a_fifo_profile_raw_data_debugfs_fops); + nvgpu_debugfs_swprofile_init(g, fifo_root, &g->fifo.kickoff_profiler, "kickoff_profiler"); } diff --git a/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.c b/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.c new file mode 100644 index 000000000..0046670de --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2020 NVIDIA Corporation. All rights reserved. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include + +#include +#include + +static int nvgpu_debugfs_swprofile_enable(void *data, u64 val) +{ + struct nvgpu_swprofiler *p = (struct nvgpu_swprofiler *) data; + + if (val == 0) { + nvgpu_swprofile_close(p); + return 0; + } else { + return nvgpu_swprofile_open(p->g, p); + } +} + +DEFINE_SIMPLE_ATTRIBUTE( + nvgpu_debugfs_swprofile_enable_debugfs_fops, + NULL, + nvgpu_debugfs_swprofile_enable, + "%llu\n" +); + +static void nvgpu_debugfs_write_to_seqfile_no_nl(void *ctx, const char *str) +{ + seq_printf((struct seq_file *)ctx, str); +} + +static int nvgpu_debugfs_swprofile_stats(struct seq_file *s, void *unused) +{ + struct nvgpu_swprofiler *p = s->private; + struct nvgpu_debug_context o = { + .fn = nvgpu_debugfs_write_to_seqfile_no_nl, + .ctx = s, + }; + + nvgpu_swprofile_print_ranges(p->g, p, &o); + + return 0; +} + +static int nvgpu_debugfs_swprofile_stats_open(struct inode *inode, struct file *file) +{ + return single_open(file, nvgpu_debugfs_swprofile_stats, inode->i_private); +} + +static const struct file_operations nvgpu_debugfs_swprofile_stats_debugfs_fops = { + .open = nvgpu_debugfs_swprofile_stats_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int nvgpu_debugfs_swprofile_raw_data(struct seq_file *s, void *unused) +{ + struct nvgpu_swprofiler *p = s->private; + struct nvgpu_debug_context o = { + .fn = nvgpu_debugfs_write_to_seqfile_no_nl, + .ctx = s, + }; + + nvgpu_swprofile_print_raw_data(p->g, p, &o); + + return 0; +} + +static int nvgpu_debugfs_swprofile_raw_data_open(struct inode *inode, struct file *file) +{ + return single_open(file, nvgpu_debugfs_swprofile_raw_data, inode->i_private); +} + +static const struct file_operations nvgpu_debugfs_swprofile_raw_data_debugfs_fops = { + .open = nvgpu_debugfs_swprofile_raw_data_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +void nvgpu_debugfs_swprofile_init(struct gk20a *g, + struct dentry *root, + struct nvgpu_swprofiler *p, + const char *name) +{ + struct dentry *swprofile_root; + + swprofile_root = debugfs_create_dir(name, root); + if (IS_ERR_OR_NULL(swprofile_root)) + return; + + debugfs_create_file("enable", 0600, swprofile_root, p, + &nvgpu_debugfs_swprofile_enable_debugfs_fops); + + debugfs_create_file("percentiles", 0600, swprofile_root, p, + &nvgpu_debugfs_swprofile_stats_debugfs_fops); + + debugfs_create_file("raw_data", 0600, swprofile_root, p, + &nvgpu_debugfs_swprofile_raw_data_debugfs_fops); +} diff --git a/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.h b/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.h new file mode 100644 index 000000000..d319e9cdc --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/swprofile_debugfs.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 NVIDIA Corporation. All rights reserved. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __NVGPU_PROFILE_DEBUGFS_H__ +#define __NVGPU_PROFILE_DEBUGFS_H__ + +struct dentry; + +struct gk20a; +struct nvgpu_swprofiler; + +void nvgpu_debugfs_swprofile_init(struct gk20a *g, + struct dentry *root, + struct nvgpu_swprofiler *p, + const char *name); + +#endif /* __NVGPU_PROFILE_DEBUGFS_H__ */