From 77140c1a841d97aef1df6fed2d84ad390621cf9d Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 15 Apr 2019 17:23:17 +0530 Subject: [PATCH] gpu: nvgpu: move dump_ctxsw_stats_on_channel_close flag to gr_ctx_desc Debug boolean flag dump_ctxsw_stats_on_channel_close is right now stored in gr_gk20a.ctx_vars struct This flag logically is property of gr.ctx units since it indicates whether each context should dump ctxsw stats on channel/context close Move this flag to struct nvgpu_gr_ctx_desc and remove it from gr_gk20a.ctx_vars Expose below API from gr.ctx unit to check if flag is set nvgpu_gr_ctx_desc_dump_ctxsw_stats_on_channel_close() Move debugfs creation code to create corresponding debugfs to gr_gk20a_debugfs_init() and change debugfs type from "u32" to "file" Struct gr.gr_ctx_desc is created only during first poweron. Return error if this struct is not available. Remove unnecessary initialization of this variable from platform specific probe functions Jira NVGPU-3112 Change-Id: Id675e047237f82e9b8198a42082e99c95824578f Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/2099399 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra GVS: Gerrit_Virtual_Submit Reviewed-by: Vinod Gopalakrishnakurup Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/gr/ctx.c | 6 ++ drivers/gpu/nvgpu/common/gr/ctx_priv.h | 2 + drivers/gpu/nvgpu/common/gr/gr_setup.c | 3 +- drivers/gpu/nvgpu/gk20a/gr_gk20a.h | 2 - drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h | 3 + drivers/gpu/nvgpu/os/linux/debug.c | 5 -- drivers/gpu/nvgpu/os/linux/debug_gr.c | 59 +++++++++++++++++++ .../gpu/nvgpu/os/linux/platform_gp10b_tegra.c | 5 -- .../gpu/nvgpu/os/linux/platform_gv11b_tegra.c | 5 -- 9 files changed, 72 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/nvgpu/common/gr/ctx.c b/drivers/gpu/nvgpu/common/gr/ctx.c index 664ca32c7..62e699b75 100644 --- a/drivers/gpu/nvgpu/common/gr/ctx.c +++ b/drivers/gpu/nvgpu/common/gr/ctx.c @@ -969,3 +969,9 @@ bool nvgpu_gr_ctx_desc_force_preemption_cilp(struct nvgpu_gr_ctx_desc *gr_ctx_de { return gr_ctx_desc->force_preemption_cilp; } + +bool nvgpu_gr_ctx_desc_dump_ctxsw_stats_on_channel_close( + struct nvgpu_gr_ctx_desc *gr_ctx_desc) +{ + return gr_ctx_desc->dump_ctxsw_stats_on_channel_close; +} diff --git a/drivers/gpu/nvgpu/common/gr/ctx_priv.h b/drivers/gpu/nvgpu/common/gr/ctx_priv.h index 62837fc6c..7017eef9b 100644 --- a/drivers/gpu/nvgpu/common/gr/ctx_priv.h +++ b/drivers/gpu/nvgpu/common/gr/ctx_priv.h @@ -47,6 +47,8 @@ struct nvgpu_gr_ctx_desc { bool force_preemption_gfxp; bool force_preemption_cilp; + + bool dump_ctxsw_stats_on_channel_close; }; struct nvgpu_gr_ctx { diff --git a/drivers/gpu/nvgpu/common/gr/gr_setup.c b/drivers/gpu/nvgpu/common/gr/gr_setup.c index afc0aad33..362e73a46 100644 --- a/drivers/gpu/nvgpu/common/gr/gr_setup.c +++ b/drivers/gpu/nvgpu/common/gr/gr_setup.c @@ -181,7 +181,8 @@ void nvgpu_gr_setup_free_gr_ctx(struct gk20a *g, if (gr_ctx != NULL) { if ((g->ops.gr.ctxsw_prog.dump_ctxsw_stats != NULL) && - g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close) { + nvgpu_gr_ctx_desc_dump_ctxsw_stats_on_channel_close( + g->gr->gr_ctx_desc)) { g->ops.gr.ctxsw_prog.dump_ctxsw_stats(g, nvgpu_gr_ctx_get_ctx_mem(gr_ctx)); } diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.h b/drivers/gpu/nvgpu/gk20a/gr_gk20a.h index 70d87b3ae..14035a0b3 100644 --- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.h @@ -91,8 +91,6 @@ struct nvgpu_gr { u32 preempt_image_size; u32 zcull_image_size; - - bool dump_ctxsw_stats_on_channel_close; } ctx_vars; struct nvgpu_mutex ctx_mutex; /* protect golden ctx init */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h b/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h index c0816f10c..74d8395e0 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h @@ -236,4 +236,7 @@ bool nvgpu_gr_ctx_desc_force_preemption_gfxp( bool nvgpu_gr_ctx_desc_force_preemption_cilp( struct nvgpu_gr_ctx_desc *gr_ctx_desc); +bool nvgpu_gr_ctx_desc_dump_ctxsw_stats_on_channel_close( + struct nvgpu_gr_ctx_desc *gr_ctx_desc); + #endif /* NVGPU_INCLUDE_GR_CTX_H */ diff --git a/drivers/gpu/nvgpu/os/linux/debug.c b/drivers/gpu/nvgpu/os/linux/debug.c index 1496f62bb..5f8e03414 100644 --- a/drivers/gpu/nvgpu/os/linux/debug.c +++ b/drivers/gpu/nvgpu/os/linux/debug.c @@ -411,11 +411,6 @@ void gk20a_debug_init(struct gk20a *g, const char *debugfs_symlink) l->debugfs, &g->runlist_interleave); - l->debugfs_dump_ctxsw_stats = - debugfs_create_bool("dump_ctxsw_stats_on_channel_close", - S_IRUGO|S_IWUSR, l->debugfs, - &g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close); - gr_gk20a_debugfs_init(g); gk20a_pmu_debugfs_init(g); gk20a_railgating_debugfs_init(g); diff --git a/drivers/gpu/nvgpu/os/linux/debug_gr.c b/drivers/gpu/nvgpu/os/linux/debug_gr.c index 51bc70002..cf8ee5c04 100644 --- a/drivers/gpu/nvgpu/os/linux/debug_gr.c +++ b/drivers/gpu/nvgpu/os/linux/debug_gr.c @@ -149,6 +149,58 @@ static struct file_operations force_preemption_cilp_fops = { .write = force_preemption_cilp_write, }; +static ssize_t dump_ctxsw_stats_on_channel_close_read(struct file *file, + char __user *user_buf, size_t count, loff_t *ppos) +{ + char buf[3]; + struct gk20a *g = file->private_data; + + if (g->gr->gr_ctx_desc == NULL) { + return -EFAULT; + } + + if (g->gr->gr_ctx_desc->dump_ctxsw_stats_on_channel_close) { + buf[0] = 'Y'; + } else { + buf[0] = 'N'; + } + + buf[1] = '\n'; + buf[2] = 0x00; + + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); +} + +static ssize_t dump_ctxsw_stats_on_channel_close_write(struct file *file, + const char __user *user_buf, size_t count, loff_t *ppos) +{ + char buf[32]; + int buf_size; + bool val; + struct gk20a *g = file->private_data; + + if (g->gr->gr_ctx_desc == NULL) { + return -EFAULT; + } + + buf_size = min(count, (sizeof(buf)-1)); + if (copy_from_user(buf, user_buf, buf_size)) { + return -EFAULT; + } + + if (strtobool(buf, &val) == 0) { + g->gr->gr_ctx_desc->dump_ctxsw_stats_on_channel_close = val; + } + + return count; +} + +static struct file_operations dump_ctxsw_stats_on_channel_close_fops = { + .open = simple_open, + .read = dump_ctxsw_stats_on_channel_close_read, + .write = dump_ctxsw_stats_on_channel_close_write, +}; + int gr_gk20a_debugfs_init(struct gk20a *g) { struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); @@ -172,6 +224,13 @@ int gr_gk20a_debugfs_init(struct gk20a *g) if (!d) return -ENOMEM; + d = debugfs_create_file( + "dump_ctxsw_stats_on_channel_close", S_IRUGO|S_IWUSR, + l->debugfs, g, + &dump_ctxsw_stats_on_channel_close_fops); + if (!d) + return -ENOMEM; + return 0; } diff --git a/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c index f9f24c8c0..4750c5722 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c @@ -158,11 +158,6 @@ static int gp10b_tegra_probe(struct device *dev) platform->disable_bigpage = !dev->archdata.iommu; - platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close - = false; - platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close - = false; - gp10b_tegra_get_clocks(dev); nvgpu_linux_init_clk_support(platform->g); diff --git a/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c index af6aed635..c5ee846c0 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c @@ -86,11 +86,6 @@ static int gv11b_tegra_probe(struct device *dev) platform->disable_bigpage = !dev->archdata.iommu; - platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close - = false; - platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close - = false; - gp10b_tegra_get_clocks(dev); nvgpu_linux_init_clk_support(platform->g);