From 40cefb666f3767059383052346d4c0faa9195a48 Mon Sep 17 00:00:00 2001 From: seshendra Gadagottu Date: Tue, 20 Mar 2018 12:28:04 -0700 Subject: gpu: nvgpu: gpu railgate handling with runtime pm Earlier implementation of railgate disable config is disabling runtime pm during pm_init. This is causing multiple issues: 1. gpu rail will be on as soon as nvgpu driver probe is called. Actual gpu hw init may happen at much later point of time. 2. This is breaking railgate_enable sysfs node functionality. railgate_enable is not working if runtime pm is disabled. To avoid all these issues for railgate disable, enable runtime pm during pm_init and set auto-suspend delay to negative (-1), which will disable runtime pm suspend calls. Also fixed following issues along with this: 1. Updated railgate_enable debugfs implementation to use auto-suspend delay. To disable railgating: Set auto-suspend delay with negative value(-1) which will disable runtime pm suspend. To enable railgating: Set auto-suspend delay with railgate_delay value. Also removed redundant user_railgate_disabled gk20a device data and replaced with can_railgate, where ever it is applicable. 2. Initialized default railgate_delay to 500msec to avoid railgate on/off transitions with railigate enable from disabled state. 3. Created railgate_residency debug fs node irrespective of can_railgate initial state. This is helping with the case, where initial state of railgate state off and then railgate enable is done through sysfs node. Bug 2073029 Change-Id: I531da6d93ba8907e806f65a1de2a447c1ec2665c Signed-off-by: seshendra Gadagottu Reviewed-on: https://git-master.nvidia.com/r/1694944 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/debug.c | 3 --- drivers/gpu/nvgpu/common/linux/driver_common.c | 6 ++++- drivers/gpu/nvgpu/common/linux/module.c | 32 +++++++++++--------------- drivers/gpu/nvgpu/common/linux/sysfs.c | 17 +++++++------- drivers/gpu/nvgpu/gk20a/gk20a.c | 3 --- drivers/gpu/nvgpu/gk20a/gk20a.h | 1 - drivers/gpu/nvgpu/include/nvgpu/defaults.h | 4 +++- 7 files changed, 30 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/nvgpu/common/linux/debug.c b/drivers/gpu/nvgpu/common/linux/debug.c index ee93a901..8738f3e7 100644 --- a/drivers/gpu/nvgpu/common/linux/debug.c +++ b/drivers/gpu/nvgpu/common/linux/debug.c @@ -267,9 +267,6 @@ static int gk20a_railgating_debugfs_init(struct gk20a *g) struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); struct dentry *d; - if (!g->can_railgate) - return 0; - d = debugfs_create_file( "railgate_residency", S_IRUGO|S_IWUSR, l->debugfs, g, &railgate_residency_fops); diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index 015046dd..2475912a 100644 --- a/drivers/gpu/nvgpu/common/linux/driver_common.c +++ b/drivers/gpu/nvgpu/common/linux/driver_common.c @@ -168,8 +168,12 @@ static void nvgpu_init_pm_vars(struct gk20a *g) g->ptimer_src_freq = platform->ptimer_src_freq; g->support_pmu = support_gk20a_pmu(dev_from_gk20a(g)); g->can_railgate = platform->can_railgate_init; - g->railgate_delay = platform->railgate_delay_init; g->ldiv_slowdown_factor = platform->ldiv_slowdown_factor_init; + /* if default delay is not set, set default delay to 500msec */ + if (platform->railgate_delay_init) + g->railgate_delay = platform->railgate_delay_init; + else + g->railgate_delay = NVGPU_DEFAULT_RAILGATE_IDLE_TIMEOUT; __nvgpu_set_enabled(g, NVGPU_PMU_PERFMON, platform->enable_perfmon); /* set default values to aelpg parameters */ diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index 86abd36b..a7289b66 100644 --- a/drivers/gpu/nvgpu/common/linux/module.c +++ b/drivers/gpu/nvgpu/common/linux/module.c @@ -458,10 +458,10 @@ int __gk20a_do_idle(struct gk20a *g, bool force_reset) * If User disables rail gating, we take one more * extra refcount */ - if (g->user_railgate_disabled) - target_ref_cnt = 2; - else + if (g->can_railgate) target_ref_cnt = 1; + else + target_ref_cnt = 2; nvgpu_mutex_acquire(&platform->railgate_lock); nvgpu_timeout_init(g, &timeout, GK20A_WAIT_FOR_IDLE_MS, @@ -964,7 +964,7 @@ static int gk20a_pm_suspend(struct device *dev) struct gk20a_platform *platform = dev_get_drvdata(dev); struct gk20a *g = get_gk20a(dev); int ret = 0; - int idle_usage_count = g->user_railgate_disabled ? 1 : 0; + int idle_usage_count = 0; if (!g->power_on) { if (!pm_runtime_enabled(dev)) @@ -1020,23 +1020,19 @@ static int gk20a_pm_init(struct device *dev) nvgpu_log_fn(g, " "); - /* Initialise pm runtime */ - if (g->railgate_delay) { + /* + * Initialise pm runtime. For railgate disable + * case, set autosuspend delay to negative which + * will suspend runtime pm + */ + if (g->railgate_delay && g->can_railgate) pm_runtime_set_autosuspend_delay(dev, g->railgate_delay); - pm_runtime_use_autosuspend(dev); - } + else + pm_runtime_set_autosuspend_delay(dev, -1); - if (g->can_railgate) { - pm_runtime_enable(dev); - if (!pm_runtime_enabled(dev)) - gk20a_pm_unrailgate(dev); - else - gk20a_pm_railgate(dev); - } else { - __pm_runtime_disable(dev, false); - gk20a_pm_unrailgate(dev); - } + pm_runtime_use_autosuspend(dev); + pm_runtime_enable(dev); return err; } diff --git a/drivers/gpu/nvgpu/common/linux/sysfs.c b/drivers/gpu/nvgpu/common/linux/sysfs.c index e425e153..7a887beb 100644 --- a/drivers/gpu/nvgpu/common/linux/sysfs.c +++ b/drivers/gpu/nvgpu/common/linux/sysfs.c @@ -305,24 +305,23 @@ static ssize_t railgate_enable_store(struct device *dev, unsigned long railgate_enable = 0; /* dev is guaranteed to be valid here. Ok to de-reference */ struct gk20a *g = get_gk20a(dev); - int err = 0; + int err; if (kstrtoul(buf, 10, &railgate_enable) < 0) return -EINVAL; if (railgate_enable && !g->can_railgate) { - /* release extra ref count */ - gk20a_idle(g); g->can_railgate = true; - g->user_railgate_disabled = false; + pm_runtime_set_autosuspend_delay(dev, g->railgate_delay); } else if (railgate_enable == 0 && g->can_railgate) { - /* take extra ref count */ - err = gk20a_busy(g); - if (err) - return err; g->can_railgate = false; - g->user_railgate_disabled = true; + pm_runtime_set_autosuspend_delay(dev, -1); } + /* wake-up system to make rail-gating setting effective */ + err = gk20a_busy(g); + if (err) + return err; + gk20a_idle(g); nvgpu_info(g, "railgate is %s.", g->can_railgate ? "enabled" : "disabled"); diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 9ce2ef53..b502ef02 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -370,9 +370,6 @@ int gk20a_wait_for_idle(struct gk20a *g) if (!g) return -ENODEV; - if (g->user_railgate_disabled) - target_usage_count = 1; - while ((nvgpu_atomic_read(&g->usage_count) != target_usage_count) && (wait_length-- >= 0)) nvgpu_msleep(20); diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 07ff28f6..77e6e759 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -1358,7 +1358,6 @@ struct gk20a { u32 ptimer_src_freq; bool can_railgate; - bool user_railgate_disabled; int railgate_delay; u8 ldiv_slowdown_factor; unsigned int aggressive_sync_destroy_thresh; diff --git a/drivers/gpu/nvgpu/include/nvgpu/defaults.h b/drivers/gpu/nvgpu/include/nvgpu/defaults.h index 2d7a42b1..cae380a7 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/defaults.h +++ b/drivers/gpu/nvgpu/include/nvgpu/defaults.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -28,4 +28,6 @@ */ #define NVGPU_DEFAULT_GR_IDLE_TIMEOUT 3000 +#define NVGPU_DEFAULT_RAILGATE_IDLE_TIMEOUT 500 + #endif -- cgit v1.2.2