From 9e4bbd2c9b4d5d9712921a7db058061e4f8cd389 Mon Sep 17 00:00:00 2001 From: Nicolin Chen Date: Thu, 30 Aug 2018 14:52:16 -0700 Subject: gpu: nvgpu: Add configurable comptag_mem_deduct sysfs node per device Adding a comptag_mem_deduct in the platform_gk20a has certain problems: 1) It's not really convenient for platform users to configure it. 2) All products using the same GPU have to share the same configuration. So this patch moves this comptag_mem_deduct from struct platform_gk20a to struct gr_gk20a (per device). And it adds an sysfs node for products or platform users to easily configure from user space. Note: The comptag memory will not be allocated until the GPU driver goes through the final poweron routine. So the user space has a small window to configure this sysfs node. Bug 2327574 Bug 2284925 Change-Id: Ie7d00b082704e422645c0ea254b59e22f9fc3b7f Signed-off-by: Nicolin Chen Reviewed-on: https://git-master.nvidia.com/r/1810334 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/driver_common.c | 9 ------- drivers/gpu/nvgpu/os/linux/platform_gk20a.h | 6 ----- drivers/gpu/nvgpu/os/linux/sysfs.c | 39 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) (limited to 'drivers/gpu/nvgpu/os') diff --git a/drivers/gpu/nvgpu/os/linux/driver_common.c b/drivers/gpu/nvgpu/os/linux/driver_common.c index 4d345aaa..6375030b 100644 --- a/drivers/gpu/nvgpu/os/linux/driver_common.c +++ b/drivers/gpu/nvgpu/os/linux/driver_common.c @@ -94,19 +94,10 @@ static void nvgpu_init_vars(struct gk20a *g) static void nvgpu_init_gr_vars(struct gk20a *g) { - struct gk20a_platform *platform = dev_get_drvdata(dev_from_gk20a(g)); gk20a_init_gr(g); nvgpu_log_info(g, "total ram pages : %lu", totalram_pages); g->gr.max_comptag_mem = totalram_size_in_mb; - - /* Deduct the part taken by the running system */ - if (platform->comptag_mem_deduct && - g->gr.max_comptag_mem > platform->comptag_mem_deduct) { - g->gr.max_comptag_mem -= platform->comptag_mem_deduct; - nvgpu_log_info(g, "deducted max memory for comptag: %u", - g->gr.max_comptag_mem); - } } static void nvgpu_init_timeout(struct gk20a *g) diff --git a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h index 5848a5ef..f3e80b8c 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h +++ b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h @@ -272,12 +272,6 @@ struct gk20a_platform { /* stream id to use */ u32 ltc_streamid; - /* - * The deductible memory size for max_comptag_mem (in MBytes) - * Usually close to memory size that running system is taking - */ - u32 comptag_mem_deduct; - /* scaling rate */ unsigned long cached_rate; }; diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index a42070d4..5eef8bfa 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -22,6 +22,7 @@ #include #include +#include "os_linux.h" #include "sysfs.h" #include "platform_gk20a.h" #include "gk20a/gr_gk20a.h" @@ -1159,6 +1160,40 @@ static DEVICE_ATTR(gfxp_wfi_timeout_count, (S_IRWXU|S_IRGRP|S_IROTH), static DEVICE_ATTR(gfxp_wfi_timeout_unit, (S_IRWXU|S_IRGRP|S_IROTH), gfxp_wfi_timeout_unit_read, gfxp_wfi_timeout_unit_store); +static ssize_t comptag_mem_deduct_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct gk20a *g = get_gk20a(dev); + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + if (val >= totalram_size_in_mb) { + dev_err(dev, "comptag_mem_deduct can not be set above %lu", + totalram_size_in_mb); + return -EINVAL; + } + + g->gr.comptag_mem_deduct = val; + /* Deduct the part taken by the running system */ + g->gr.max_comptag_mem -= val; + + return count; +} + +static ssize_t comptag_mem_deduct_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gk20a *g = get_gk20a(dev); + + return sprintf(buf, "%d\n", g->gr.comptag_mem_deduct); +} + +static DEVICE_ATTR(comptag_mem_deduct, ROOTRW, + comptag_mem_deduct_show, comptag_mem_deduct_store); + void nvgpu_remove_sysfs(struct device *dev) { device_remove_file(dev, &dev_attr_elcg_enable); @@ -1200,6 +1235,8 @@ void nvgpu_remove_sysfs(struct device *dev) device_remove_file(dev, &dev_attr_gfxp_wfi_timeout_count); device_remove_file(dev, &dev_attr_gfxp_wfi_timeout_unit); + device_remove_file(dev, &dev_attr_comptag_mem_deduct); + if (strcmp(dev_name(dev), "gpu.0")) { struct kobject *kobj = &dev->kobj; struct device *parent = container_of((kobj->parent), @@ -1252,6 +1289,8 @@ int nvgpu_create_sysfs(struct device *dev) error |= device_create_file(dev, &dev_attr_gfxp_wfi_timeout_count); error |= device_create_file(dev, &dev_attr_gfxp_wfi_timeout_unit); + error |= device_create_file(dev, &dev_attr_comptag_mem_deduct); + if (strcmp(dev_name(dev), "gpu.0")) { struct kobject *kobj = &dev->kobj; struct device *parent = container_of((kobj->parent), -- cgit v1.2.2