From ee5b3823ffa6fe4db38708d931d5a3d7f55b4304 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 15 Apr 2019 17:41:22 +0530 Subject: [PATCH] gpu: nvgpu: move force preemption flags to gr_ctx_desc Debug boolean flags force_preemption_gfxp and force_preemption_cilp are right now stored in gr_gk20a.ctx_vars struct These flags logically are property of gr.ctx units since they indicate whether each context should be forced to gfxp/cilp preemption mode by default Move these flags to struct nvgpu_gr_ctx_desc and remove them from gr_gk20a.ctx_vars Expose below APIs from gr.ctx unit to check if flags are set nvgpu_gr_ctx_desc_force_preemption_gfxp() nvgpu_gr_ctx_desc_force_preemption_cilp() 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 these variables from platform specific probe functions Jira NVGPU-3112 Change-Id: I8b2de27f0c71dd2ea5abcf94221c2e15c80073ea Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/2099398 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Vinod Gopalakrishnakurup Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/gr/ctx.c | 10 ++ drivers/gpu/nvgpu/common/gr/ctx_priv.h | 3 + drivers/gpu/nvgpu/common/gr/obj_ctx.c | 4 +- drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c | 5 +- drivers/gpu/nvgpu/gk20a/gr_gk20a.h | 3 - drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h | 4 + drivers/gpu/nvgpu/os/linux/debug.c | 9 -- drivers/gpu/nvgpu/os/linux/debug_gr.c | 123 +++++++++++++++++- drivers/gpu/nvgpu/os/linux/os_linux.h | 2 - .../gpu/nvgpu/os/linux/platform_gp10b_tegra.c | 3 - .../gpu/nvgpu/os/linux/platform_gv11b_tegra.c | 3 - 11 files changed, 144 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/nvgpu/common/gr/ctx.c b/drivers/gpu/nvgpu/common/gr/ctx.c index 2ba41525d..664ca32c7 100644 --- a/drivers/gpu/nvgpu/common/gr/ctx.c +++ b/drivers/gpu/nvgpu/common/gr/ctx.c @@ -959,3 +959,13 @@ bool nvgpu_gr_ctx_get_boosted_ctx(struct nvgpu_gr_ctx *gr_ctx) { return gr_ctx->boosted_ctx; } + +bool nvgpu_gr_ctx_desc_force_preemption_gfxp(struct nvgpu_gr_ctx_desc *gr_ctx_desc) +{ + return gr_ctx_desc->force_preemption_gfxp; +} + +bool nvgpu_gr_ctx_desc_force_preemption_cilp(struct nvgpu_gr_ctx_desc *gr_ctx_desc) +{ + return gr_ctx_desc->force_preemption_cilp; +} diff --git a/drivers/gpu/nvgpu/common/gr/ctx_priv.h b/drivers/gpu/nvgpu/common/gr/ctx_priv.h index 328e5b893..62837fc6c 100644 --- a/drivers/gpu/nvgpu/common/gr/ctx_priv.h +++ b/drivers/gpu/nvgpu/common/gr/ctx_priv.h @@ -44,6 +44,9 @@ struct pm_ctx_desc { struct nvgpu_gr_ctx_desc { u32 size[NVGPU_GR_CTX_COUNT]; + + bool force_preemption_gfxp; + bool force_preemption_cilp; }; struct nvgpu_gr_ctx { diff --git a/drivers/gpu/nvgpu/common/gr/obj_ctx.c b/drivers/gpu/nvgpu/common/gr/obj_ctx.c index d552476e6..2fe2cb3fd 100644 --- a/drivers/gpu/nvgpu/common/gr/obj_ctx.c +++ b/drivers/gpu/nvgpu/common/gr/obj_ctx.c @@ -114,12 +114,12 @@ int nvgpu_gr_obj_ctx_set_ctxsw_preemption_mode(struct gk20a *g, } if (g->ops.class.is_valid_gfx(class) && - g->gr->ctx_vars.force_preemption_gfxp) { + nvgpu_gr_ctx_desc_force_preemption_gfxp(gr_ctx_desc)) { graphics_preempt_mode = NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP; } if (g->ops.class.is_valid_compute(class) && - g->gr->ctx_vars.force_preemption_cilp) { + nvgpu_gr_ctx_desc_force_preemption_cilp(gr_ctx_desc)) { compute_preempt_mode = NVGPU_PREEMPTION_MODE_COMPUTE_CILP; } diff --git a/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c b/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c index 9fd085c23..98addc4d3 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c +++ b/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c @@ -55,6 +55,7 @@ #include "common/vgpu/ivc/comm_vgpu.h" #include "common/gr/gr_config_priv.h" +#include "common/gr/ctx_priv.h" #include "common/gr/zcull_priv.h" #include "common/gr/zbc_priv.h" @@ -1292,12 +1293,12 @@ static int vgpu_gr_set_ctxsw_preemption_mode(struct gk20a *g, int err = 0; if (g->ops.class.is_valid_gfx(class) && - g->gr->ctx_vars.force_preemption_gfxp) { + g->gr->gr_ctx_desc->force_preemption_gfxp) { graphics_preempt_mode = NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP; } if (g->ops.class.is_valid_compute(class) && - g->gr->ctx_vars.force_preemption_cilp) { + g->gr->gr_ctx_desc->force_preemption_cilp) { compute_preempt_mode = NVGPU_PREEMPTION_MODE_COMPUTE_CILP; } diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.h b/drivers/gpu/nvgpu/gk20a/gr_gk20a.h index bcee6196a..70d87b3ae 100644 --- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.h @@ -92,9 +92,6 @@ struct nvgpu_gr { u32 zcull_image_size; - bool force_preemption_gfxp; - bool force_preemption_cilp; - bool dump_ctxsw_stats_on_channel_close; } ctx_vars; diff --git a/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h b/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h index 691a7470e..c0816f10c 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gr/ctx.h @@ -231,5 +231,9 @@ void nvgpu_gr_ctx_set_boosted_ctx(struct nvgpu_gr_ctx *gr_ctx, bool boost); bool nvgpu_gr_ctx_get_boosted_ctx(struct nvgpu_gr_ctx *gr_ctx); +bool nvgpu_gr_ctx_desc_force_preemption_gfxp( + struct nvgpu_gr_ctx_desc *gr_ctx_desc); +bool nvgpu_gr_ctx_desc_force_preemption_cilp( + 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 e40b82579..1496f62bb 100644 --- a/drivers/gpu/nvgpu/os/linux/debug.c +++ b/drivers/gpu/nvgpu/os/linux/debug.c @@ -410,15 +410,6 @@ void gk20a_debug_init(struct gk20a *g, const char *debugfs_symlink) S_IRUGO|S_IWUSR, l->debugfs, &g->runlist_interleave); - l->debugfs_force_preemption_gfxp = - debugfs_create_bool("force_preemption_gfxp", S_IRUGO|S_IWUSR, - l->debugfs, - &g->gr->ctx_vars.force_preemption_gfxp); - - l->debugfs_force_preemption_cilp = - debugfs_create_bool("force_preemption_cilp", S_IRUGO|S_IWUSR, - l->debugfs, - &g->gr->ctx_vars.force_preemption_cilp); l->debugfs_dump_ctxsw_stats = debugfs_create_bool("dump_ctxsw_stats_on_channel_close", diff --git a/drivers/gpu/nvgpu/os/linux/debug_gr.c b/drivers/gpu/nvgpu/os/linux/debug_gr.c index 532cdd0af..51bc70002 100644 --- a/drivers/gpu/nvgpu/os/linux/debug_gr.c +++ b/drivers/gpu/nvgpu/os/linux/debug_gr.c @@ -12,9 +12,14 @@ * */ +#include + +#include "common/gr/ctx_priv.h" + #include "debug_gr.h" #include "os_linux.h" +#include #include static int gr_default_attrib_cb_size_show(struct seq_file *s, void *data) @@ -40,6 +45,110 @@ static const struct file_operations gr_default_attrib_cb_size_fops= { .release = single_release, }; +static ssize_t force_preemption_gfxp_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->force_preemption_gfxp) { + 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 force_preemption_gfxp_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->force_preemption_gfxp = val; + } + + return count; +} + +static struct file_operations force_preemption_gfxp_fops = { + .open = simple_open, + .read = force_preemption_gfxp_read, + .write = force_preemption_gfxp_write, +}; + +static ssize_t force_preemption_cilp_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->force_preemption_cilp) { + 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 force_preemption_cilp_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->force_preemption_cilp = val; + } + + return count; +} + +static struct file_operations force_preemption_cilp_fops = { + .open = simple_open, + .read = force_preemption_cilp_read, + .write = force_preemption_cilp_write, +}; + int gr_gk20a_debugfs_init(struct gk20a *g) { struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); @@ -47,7 +156,19 @@ int gr_gk20a_debugfs_init(struct gk20a *g) d = debugfs_create_file( "gr_default_attrib_cb_size", S_IRUGO, l->debugfs, g, - &gr_default_attrib_cb_size_fops); + &gr_default_attrib_cb_size_fops); + if (!d) + return -ENOMEM; + + d = debugfs_create_file( + "force_preemption_gfxp", S_IRUGO|S_IWUSR, l->debugfs, g, + &force_preemption_gfxp_fops); + if (!d) + return -ENOMEM; + + d = debugfs_create_file( + "force_preemption_cilp", S_IRUGO|S_IWUSR, l->debugfs, g, + &force_preemption_cilp_fops); if (!d) return -ENOMEM; diff --git a/drivers/gpu/nvgpu/os/linux/os_linux.h b/drivers/gpu/nvgpu/os/linux/os_linux.h index 83d71fdc6..1d54656bf 100644 --- a/drivers/gpu/nvgpu/os/linux/os_linux.h +++ b/drivers/gpu/nvgpu/os/linux/os_linux.h @@ -157,8 +157,6 @@ struct nvgpu_os_linux { struct dentry *debugfs_hal; struct dentry *debugfs_ltc; - struct dentry *debugfs_force_preemption_cilp; - struct dentry *debugfs_force_preemption_gfxp; struct dentry *debugfs_dump_ctxsw_stats; #endif DECLARE_HASHTABLE(ecc_sysfs_stats_htable, 5); diff --git a/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c index 58ee4eddf..f9f24c8c0 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gp10b_tegra.c @@ -163,9 +163,6 @@ static int gp10b_tegra_probe(struct device *dev) platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close = false; - platform->g->gr->ctx_vars.force_preemption_gfxp = false; - platform->g->gr->ctx_vars.force_preemption_cilp = 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 325a7677f..af6aed635 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c @@ -91,9 +91,6 @@ static int gv11b_tegra_probe(struct device *dev) platform->g->gr->ctx_vars.dump_ctxsw_stats_on_channel_close = false; - platform->g->gr->ctx_vars.force_preemption_gfxp = false; - platform->g->gr->ctx_vars.force_preemption_cilp = false; - gp10b_tegra_get_clocks(dev); nvgpu_linux_init_clk_support(platform->g);