introduce DVFS for GK20A
cover introduce DVFS for GK20A
Hi,
This is a try to have some simple DVFS (Dynamic Voltage and Frequency Scaling) support for GK20A. Instead of relying on other existing frequency scaling framework, we create a simple subdev in Nouveau for the same purpose. That's because we don't want to make the DVFS implementation for GK20A far more than enough in the beginning and hinder the implementation for dGPU in the future.
Thanks,
Vince
Vince Hsu (3):
clk: allow non-blocking for nouveau_clock_astate()
dvfs: add support for GK20A
clk: allow users to enable auto mode when loading driver
drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/clock.h | 2 +- nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/clock/base.c | 7 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 15 files changed, 382 insertions(+), 5 deletions(-) create mode 120000 drm/core/include/subdev/dvfs.h create mode 120000 drm/core/subdev/dvfs/base.c create mode 120000 drm/core/subdev/dvfs/gk20a.c create mode 120000 drm/core/subdev/dvfs/priv.h create mode 100644 nvkm/include/subdev/dvfs.h create mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644 nvkm/subdev/dvfs/base.c create mode 100644 nvkm/subdev/dvfs/gk20a.c create mode 100644 nvkm/subdev/dvfs/priv.h
Signature · 6 lines
1.9.1 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): 1418884092-14448-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
RFC PATCH 1/3 clk: allow non-blocking for nouveau_clock_astate()
There might be some callers of nouveau_clock_astate(), and they are from inetrrupt context. So we must ensure that this function can be atomic in that condition. This patch adds one parameter which is subsequently passed to nouveau_pstate_calc(). Therefore we can choose whether we want to wait for the pstate work's completion or not.
--- nvkm/include/subdev/clock.h | 2 +- nvkm/subdev/clock/base.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
nvkm/include/subdev/clock.h +1 -1
@@ -159,7 +159,7 @@ int nva3_clock_pll_calc(struct nouveau_clock *, struct nvbios_pll *, int clk, struct nouveau_pll_vals *);int nouveau_clock_ustate (struct nouveau_clock *,int req,int pwr); -int nouveau_clock_astate (struct nouveau_clock *,int req,int rel); +int nouveau_clock_astate (struct nouveau_clock *,int req,int rel,bool wait);int nouveau_clock_dstate (struct nouveau_clock *,int req,int rel);int nouveau_clock_tstate (struct nouveau_clock *,int req,int rel);
nvkm/subdev/clock/base.c +2 -2
@@ -430,13 +430,13 @@ nouveau_clock_ustate(struct nouveau_clock *clk, int req, int pwr) }int -nouveau_clock_astate (struct nouveau_clock *clk,int req,int rel) +nouveau_clock_astate (struct nouveau_clock *clk,int req,int rel,bool wait) {if (!rel) clk->astate = req;if ( rel) clk->astate += rel; clk->astate =min (clk->astate, clk->state_nr -1 ); clk->astate =max (clk->astate,0 ); -return nouveau_pstate_calc (clk, true); +return nouveau_pstate_calc (clk, wait); }int
Signature · 6 lines
1.9.1 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
RFC PATCH 2/3 dvfs: add support for GK20A
In reply to a message not in the archiveThis patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling) support in Nouveau. This subdev refers to the status information provided by the NVIDIA hardware and tries to adjust the performance level based on the calculated target. Only the GK20A is supported right now.
--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-) create mode 120000 drm/core/include/subdev/dvfs.h create mode 120000 drm/core/subdev/dvfs/base.c create mode 120000 drm/core/subdev/dvfs/gk20a.c create mode 120000 drm/core/subdev/dvfs/priv.h create mode 100644 nvkm/include/subdev/dvfs.h create mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644 nvkm/subdev/dvfs/base.c create mode 100644 nvkm/subdev/dvfs/gk20a.c create mode 100644 nvkm/subdev/dvfs/priv.h
drm/Kbuild +2 -0
@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.o
drm/core/include/subdev/dvfs.h new file +1 -0
@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.h
drm/core/subdev/dvfs/base.c new file +1 -0
@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.c
drm/core/subdev/dvfs/gk20a.c new file +1 -0
@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.c
drm/core/subdev/dvfs/priv.h new file +1 -0
@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.h
nvkm/engine/device/nve0.c +2 -0
@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h>
@@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break ;case 0xf0 : device->cname ="GK110" ;
nvkm/include/core/device.h +1 -0
@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,
nvkm/include/subdev/dvfs.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif
nvkm/subdev/Makefile.am +3 -2
@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la
@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.la
nvkm/subdev/dvfs/Makefile.am new file +6 -0
@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdev
nvkm/subdev/dvfs/base.c new file +129 -0
129 lines not on this page · raw message
nvkm/subdev/dvfs/gk20a.c new file +156 -0
156 lines not on this page · raw message
nvkm/subdev/dvfs/priv.h new file +43 -0
43 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): 1418884092-14448-3-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
Quoted 4 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling) support in Nouveau. This subdev refers to the status information provided by the NVIDIA hardware and tries to adjust the performance level based on the calculated target. Only the GK20A is supported right now.
Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
Thanks,
Ben.
Quoted 519 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-) create mode 120000 drm/core/include/subdev/dvfs.h create mode 120000 drm/core/subdev/dvfs/base.c create mode 120000 drm/core/subdev/dvfs/gk20a.c create mode 120000 drm/core/subdev/dvfs/priv.h create mode 100644 nvkm/include/subdev/dvfs.h create mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644 nvkm/subdev/dvfs/base.c create mode 100644 nvkm/subdev/dvfs/gk20a.c create mode 100644 nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break ;case 0xf0 : device->cname ="GK110" ;nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +129
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct nouveau_dvfs, + alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization =div_u64 ((u64 )status.busy *100 , status.total); + + data->avg_load = (data->p_smooth * data->avg_load) + utilization; + data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_subdev_create_ (parent, engine, oclass,0 ,"DVFS" , +"dvfs" , size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state (struct nouveau_dvfs *dvfs,int *state,int load) +{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate */ + level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level =min (clk->state_nr -1 , level + (clk->state_nr /3 )); + }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + +nv_trace (dvfs,"cur level = %d, new level = %d\n" , cur_level, level); + + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor (struct nouveau_object *parent,struct nouveau_object *engine, +struct nouveau_oclass *oclass,void *data,u32 size, +struct nouveau_object **pobject) +{ +struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +43
-1@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { +unsigned long total; +unsigned long busy; +int cur_state; +}; + +struct nouveau_dvfs_impl { +struct nouveau_oclass base; +int (*get_dev_status)(struct nouveau_dvfs *, +struct nouveau_dvfs_dev_status *); +void (*reset_dev_status)(struct nouveau_dvfs *); +int (*target)(struct nouveau_dvfs *,int *state); +int (*get_cur_state)(struct nouveau_dvfs *,int *state); +int (*get_target_state)(struct nouveau_dvfs *,int *state,int load); +}; + +#define nouveau_dvfs_create (p,e,o,d) \ + nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_dtor(nv_object(d)); \ +}) +#define nouveau_dvfs_init (p) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_init(nv_object(d)); \ +}) +#define nouveau_dvfs_fini (p,s) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_fini(nv_object(d), (s)); \ +}) + +int nouveau_dvfs_create_ (struct nouveau_object *,struct nouveau_object *, +struct nouveau_oclass *,int ,void **); +void _nouveau_dvfs_dtor (struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif --1.9.1
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): CACAvsv6ZaDf2YUvdK_HNtO4FA-K0nr7G5qvvunKbrkDWfrvfig-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
Hello Ben,
Quoted 5 lines · Ben Skeggs
Quoted 4 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling) support in Nouveau. This subdev refers to the status information provided by the NVIDIA hardware and tries to adjust the performance level based on the calculated target. Only the GK20A is supported right now.
Quoted 7 lines
Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
Yeah, I know we have the counters defined in daemon.c. Martin reminded me that Roy had a patch to remove that, sorry that I could not find the link now. Another reason I did not use the nouveau_specsig is because I had to create some nvif structures to access the counters and that's not straightforward. I'm happy to hear you're fine with the on-host implementation. :)
I will move all to PWR subdev in the next version.
Quoted 4 lines
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
So currently there is no dGPU using the PMU? I just don't want to break any dGPU functions. ;)
Quoted 4 lines
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
BTW, can we add some execution time information for pstate? I mean something like "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we don't want to change the user space ABI though.
Thanks,
Vince
Quoted 522 lines
Thanks,
Ben.Quoted 518 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-)create mode 120000
drm/core/include/subdev/dvfs.hcreate mode 120000drm/core/subdev/dvfs/base.ccreate mode 120000drm/core/subdev/dvfs/gk20a.ccreate mode 120000drm/core/subdev/dvfs/priv.hcreate mode 100644nvkm/include/subdev/dvfs.hcreate mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644nvkm/subdev/dvfs/base.ccreate mode 100644nvkm/subdev/dvfs/gk20a.ccreate mode 100644nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break ;case 0xf0 : device->cname ="GK110" ;nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +129
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct nouveau_dvfs, + alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization =div_u64 ((u64 )status.busy *100 , status.total); + + data->avg_load = (data->p_smooth * data->avg_load) + utilization; + data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_subdev_create_ (parent, engine, oclass,0 ,"DVFS" , +"dvfs" , size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state (struct nouveau_dvfs *dvfs,int *state,int load) +{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate */ + level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level =min (clk->state_nr -1 , level + (clk->state_nr /3 )); + }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + +nv_trace (dvfs,"cur level = %d, new level = %d\n" , cur_level, level); + + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor (struct nouveau_object *parent,struct nouveau_object *engine, +struct nouveau_oclass *oclass,void *data,u32 size, +struct nouveau_object **pobject) +{ +struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +43
-1@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { +unsigned long total; +unsigned long busy; +int cur_state; +}; + +struct nouveau_dvfs_impl { +struct nouveau_oclass base; +int (*get_dev_status)(struct nouveau_dvfs *, +struct nouveau_dvfs_dev_status *); +void (*reset_dev_status)(struct nouveau_dvfs *); +int (*target)(struct nouveau_dvfs *,int *state); +int (*get_cur_state)(struct nouveau_dvfs *,int *state); +int (*get_target_state)(struct nouveau_dvfs *,int *state,int load); +}; + +#define nouveau_dvfs_create (p,e,o,d) \ + nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_dtor(nv_object(d)); \ +}) +#define nouveau_dvfs_init (p) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_init(nv_object(d)); \ +}) +#define nouveau_dvfs_fini (p,s) ({ \ + struct nouveau_dvfs *d = (p); \ + _nouveau_dvfs_fini(nv_object(d), (s)); \ +}) + +int nouveau_dvfs_create_ (struct nouveau_object *,struct nouveau_object *, +struct nouveau_oclass *,int ,void **); +void _nouveau_dvfs_dtor (struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif --1.9.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
Quoted 32 lines · Vince Hsu
Hello Ben,
Quoted 11 lines · Ben Skeggs
Quoted 8 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling)
support in Nouveau. This subdev refers to the status information provided by
the NVIDIA hardware and tries to adjust the performance level based on the
calculated target. Only the GK20A is supported right now.Quoted 7 lines
Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
Yeah, I know we have the counters defined in
daemon.c. Martin reminded me that Roy had a patch to remove that, sorry that I could not find the link now. Another reason I did not use thenouveau_specsigis because I had to create some nvif structures to access the counters and that's not straightforward. I'm happy to hear you're fine with the on-host implementation. :)I will move all to PWR subdev in the next version.
Quoted 2 lines
Quoted 6 lines
Quoted 3 lines
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
So currently there is no dGPU using the PMU? I just don't want to break any dGPU functions. ;)
We upload a custom firmware to it, which we (currently) only use as a script interpreter for memory clock changes. But for your needs right now, it'd be fine to ignore all the common code there for GK20A.
Quoted 580 lines
Quoted 5 lines
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
BTW, can we add some execution time information for pstate? I mean something like "
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we don't want to change the user space ABI though.Thanks,
VinceQuoted 566 lines
Thanks,
Ben.Quoted 562 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-)create mode 120000
drm/core/include/subdev/dvfs.hcreate mode 120000drm/core/subdev/dvfs/base.ccreate mode 120000drm/core/subdev/dvfs/gk20a.ccreate mode 120000drm/core/subdev/dvfs/priv.hcreate mode 100644nvkm/include/subdev/dvfs.hcreate mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644nvkm/subdev/dvfs/base.ccreate mode 100644nvkm/subdev/dvfs/gk20a.ccreate mode 100644nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break; case 0xf0: device->cname = "GK110";nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +4
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/base.c new file +13
-0+ +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct
nouveau_dvfs,nvkm/subdev/dvfs/base.c new file +16
-0+ alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization = div_u64((u64)status.busy * 100,status.total);
nvkm/subdev/dvfs/base.c new file +79
-0+ + data->avg_load = (data->p_smooth * data->avg_load) + utilization; + data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_subdev_create_ (parent, engine, oclass,0 ,"DVFS" , +"dvfs" , size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +4
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/gk20a.c new file +33
-0+ +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state(struct nouveau_dvfs *dvfs, int *state, intload)
nvkm/subdev/dvfs/gk20a.c new file +6
-0+{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate */
nvkm/subdev/dvfs/gk20a.c new file +4
-0+ level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level = min(clk->state_nr - 1, level + (clk->state_nr /3));
nvkm/subdev/dvfs/gk20a.c new file +8
-0+ }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + + nv_trace(dvfs, "cur level = %d, new level = %d\n", cur_level,level);
nvkm/subdev/dvfs/gk20a.c new file +51
-0+ + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor(struct nouveau_object *parent, struct nouveau_object*engine,
nvkm/subdev/dvfs/gk20a.c new file +33
-0+ struct nouveau_oclass *oclass, void *data, u32 size, + struct nouveau_object **pobject) +{ + struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +19
-0@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { + unsigned long total; + unsigned long busy; + int cur_state; +}; + +struct nouveau_dvfs_impl { + struct nouveau_oclass base; + int (*get_dev_status)(struct nouveau_dvfs *, + struct nouveau_dvfs_dev_status *); + void (*reset_dev_status)(struct nouveau_dvfs *); + int (*target)(struct nouveau_dvfs *, int *state); + int (*get_cur_state)(struct nouveau_dvfs *, int *state); + int (*get_target_state)(struct nouveau_dvfs *, int *state, intload);
nvkm/subdev/dvfs/priv.h new file +3
-0+}; + +#define nouveau_dvfs_create (p,e,o,d)\
nvkm/subdev/dvfs/priv.h new file +2
-0+ nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_dtor(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_init (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_init(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_fini (p,s) ({\
+ structnouveau_dvfs*d = (p);
\
+_nouveau_dvfs_fini(nv_object(d), (s));
\nvkm/subdev/dvfs/priv.h new file +3
-0+}) + +int nouveau_dvfs_create_(struct nouveau_object *, struct nouveau_object*,
nvkm/subdev/dvfs/priv.h new file +6
-1+ struct nouveau_oclass *, int, void **); +void _nouveau_dvfs_dtor(struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif --1.9.1
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): CACAvsv76LkHkk-1Z+pBwNO=81nUgVBcdyhaEWCrt3nfO_2YjyA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
Quoted 28 lines · Ben Skeggs
Quoted 27 lines · Vince Hsu
Hello Ben,
Quoted 8 lines · Ben Skeggs
Quoted 7 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling)
support in Nouveau. This subdev refers to the status information provided by
the NVIDIA hardware and tries to adjust the performance level based on the
calculated target. Only the GK20A is supported right now.Quoted 7 lines
Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
Yeah, I know we have the counters defined in
daemon.c. Martin reminded me that Roy had a patch to remove that, sorry that I could not find the link now. Another reason I did not use thenouveau_specsigis because I had to create some nvif structures to access the counters and that's not straightforward. I'm happy to hear you're fine with the on-host implementation. :)I will move all to PWR subdev in the next version.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
So currently there is no dGPU using the PMU? I just don't want to break any dGPU functions. ;)
We upload a custom firmware to it, which we (currently) only use as a script interpreter for memory clock changes. But for your needs right now, it'd be fine to ignore all the common code there for GK20A.
Understand. Thanks!
Vince
Quoted 578 lines
Quoted 578 lines
Quoted 5 lines
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
BTW, can we add some execution time information for pstate? I mean something like "
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we don't want to change the user space ABI though.Thanks,
VinceQuoted 565 lines
Thanks,
Ben.Quoted 562 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-)create mode 120000
drm/core/include/subdev/dvfs.hcreate mode 120000drm/core/subdev/dvfs/base.ccreate mode 120000drm/core/subdev/dvfs/gk20a.ccreate mode 120000drm/core/subdev/dvfs/priv.hcreate mode 100644nvkm/include/subdev/dvfs.hcreate mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644nvkm/subdev/dvfs/base.ccreate mode 100644nvkm/subdev/dvfs/gk20a.ccreate mode 100644nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break; case 0xf0: device->cname = "GK110";nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +4
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/base.c new file +13
-0+ +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct
nouveau_dvfs,nvkm/subdev/dvfs/base.c new file +16
-0+ alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization = div_u64((u64)status.busy * 100,status.total);
nvkm/subdev/dvfs/base.c new file +79
-0+ + data->avg_load = (data->p_smooth * data->avg_load) + utilization; + data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_subdev_create_ (parent, engine, oclass,0 ,"DVFS" , +"dvfs" , size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +4
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/gk20a.c new file +33
-0+ +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state(struct nouveau_dvfs *dvfs, int *state, intload)
nvkm/subdev/dvfs/gk20a.c new file +6
-0+{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate */
nvkm/subdev/dvfs/gk20a.c new file +4
-0+ level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level = min(clk->state_nr - 1, level + (clk->state_nr /3));
nvkm/subdev/dvfs/gk20a.c new file +8
-0+ }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + + nv_trace(dvfs, "cur level = %d, new level = %d\n", cur_level,level);
nvkm/subdev/dvfs/gk20a.c new file +51
-0+ + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor(struct nouveau_object *parent, struct nouveau_object*engine,
nvkm/subdev/dvfs/gk20a.c new file +33
-0+ struct nouveau_oclass *oclass, void *data, u32 size, + struct nouveau_object **pobject) +{ + struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +19
-0@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { + unsigned long total; + unsigned long busy; + int cur_state; +}; + +struct nouveau_dvfs_impl { + struct nouveau_oclass base; + int (*get_dev_status)(struct nouveau_dvfs *, + struct nouveau_dvfs_dev_status *); + void (*reset_dev_status)(struct nouveau_dvfs *); + int (*target)(struct nouveau_dvfs *, int *state); + int (*get_cur_state)(struct nouveau_dvfs *, int *state); + int (*get_target_state)(struct nouveau_dvfs *, int *state, intload);
nvkm/subdev/dvfs/priv.h new file +3
-0+}; + +#define nouveau_dvfs_create (p,e,o,d)\
nvkm/subdev/dvfs/priv.h new file +2
-0+ nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_dtor(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_init (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_init(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_fini (p,s) ({\
+ structnouveau_dvfs*d = (p);
\
+_nouveau_dvfs_fini(nv_object(d), (s));
\nvkm/subdev/dvfs/priv.h new file +3
-0+}) + +int nouveau_dvfs_create_(struct nouveau_object *, struct nouveau_object*,
nvkm/subdev/dvfs/priv.h new file +6
-1+ struct nouveau_oclass *, int, void **); +void _nouveau_dvfs_dtor(struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif --1.9.1
Quoted 15 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveauQuoted 9 lines
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
In reply to a message not in the archiveQuoted 19 lines · Ben Skeggs
Quoted 18 lines · Vince Hsu
Hello Ben,
Quoted 15 lines · Ben Skeggs
Quoted 7 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling)
support in Nouveau. This subdev refers to the status information provided by
the NVIDIA hardware and tries to adjust the performance level based on the
calculated target. Only the GK20A is supported right now.Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
Quoted 6 lines
Quoted 6 lines
Yeah, I know we have the counters defined in
daemon.c. Martin reminded me that Roy had a patch to remove that, sorry that I could not find the link now. Another reason I did not use thenouveau_specsigis because I had to create some nvif structures to access the counters and that's not straightforward. I'm happy to hear you're fine with the on-host implementation. :)
Hey Vince,
It's not Roy but me who had submitted a patch which removes PDAEMON signals. :-)
However, the patch is not ready to be upstream because we don't have any other ways to expose these performance counters.
Currently, I'm working on perfmon and nvif to expose hardware events to the userspace for NV50. I hope to submit the bunch of patches as soon as possible but unfortunately, I don't have my full time on this, so it takes more time than expected.
Quoted 604 lines
Quoted 8 lines
I will move all to PWR subdev in the next version.
Quoted 4 lines
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
So currently there is no dGPU using the PMU? I just don't want to break any dGPU functions. ;)
We upload a custom firmware to it, which we (currently) only use as a script interpreter for memory clock changes. But for your needs right now, it'd be fine to ignore all the common code there for GK20A.
Quoted 577 lines
Quoted 4 lines
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
BTW, can we add some execution time information for pstate? I mean something like "
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we don't want to change the user space ABI though.Thanks,
VinceQuoted 565 lines
Thanks,
Ben.Quoted 562 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-)create mode 120000
drm/core/include/subdev/dvfs.hcreate mode 120000drm/core/subdev/dvfs/base.ccreate mode 120000drm/core/subdev/dvfs/gk20a.ccreate mode 120000drm/core/subdev/dvfs/priv.hcreate mode 100644nvkm/include/subdev/dvfs.hcreate mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644nvkm/subdev/dvfs/base.ccreate mode 100644nvkm/subdev/dvfs/gk20a.ccreate mode 100644nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] = gk20a_dvfs_oclass;break; case 0xf0: device->cname = "GK110";nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +4
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/base.c new file +13
-0+ +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct
nouveau_dvfs,nvkm/subdev/dvfs/base.c new file +16
-0+ alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization = div_u64((u64)status.busy * 100,status.total);
nvkm/subdev/dvfs/base.c new file +79
-0+ + data->avg_load = (data->p_smooth * data->avg_load) + utilization; + data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_subdev_create_ (parent, engine, oclass,0 ,"DVFS" , +"dvfs" , size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +4
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/gk20a.c new file +33
-0+ +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state(struct nouveau_dvfs *dvfs, int *state, intload)
nvkm/subdev/dvfs/gk20a.c new file +6
-0+{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate */
nvkm/subdev/dvfs/gk20a.c new file +4
-0+ level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level = min(clk->state_nr - 1, level + (clk->state_nr /3));
nvkm/subdev/dvfs/gk20a.c new file +8
-0+ }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + + nv_trace(dvfs, "cur level = %d, new level = %d\n", cur_level,level);
nvkm/subdev/dvfs/gk20a.c new file +51
-0+ + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor(struct nouveau_object *parent, struct nouveau_object*engine,
nvkm/subdev/dvfs/gk20a.c new file +33
-0+ struct nouveau_oclass *oclass, void *data, u32 size, + struct nouveau_object **pobject) +{ + struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +19
-0@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { + unsigned long total; + unsigned long busy; + int cur_state; +}; + +struct nouveau_dvfs_impl { + struct nouveau_oclass base; + int (*get_dev_status)(struct nouveau_dvfs *, + struct nouveau_dvfs_dev_status *); + void (*reset_dev_status)(struct nouveau_dvfs *); + int (*target)(struct nouveau_dvfs *, int *state); + int (*get_cur_state)(struct nouveau_dvfs *, int *state); + int (*get_target_state)(struct nouveau_dvfs *, int *state, intload);
nvkm/subdev/dvfs/priv.h new file +3
-0+}; + +#define nouveau_dvfs_create (p,e,o,d)\
nvkm/subdev/dvfs/priv.h new file +2
-0+ nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_dtor(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_init (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_init(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_fini (p,s) ({\
+ structnouveau_dvfs*d = (p);
\
+_nouveau_dvfs_fini(nv_object(d), (s));
\nvkm/subdev/dvfs/priv.h new file +3
-0+}) + +int nouveau_dvfs_create_(struct nouveau_object *, struct nouveau_object*,
nvkm/subdev/dvfs/priv.h new file +6
-1+ struct nouveau_oclass *, int, void **); +void _nouveau_dvfs_dtor(struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif --1.9.1
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 2/3] dvfs: add support for GK20A
Quoted 27 lines · Samuel Pitoiset
Quoted 19 lines · Ben Skeggs
Quoted 18 lines · Vince Hsu
Hello Ben,
Quoted 15 lines · Ben Skeggs
Quoted 7 lines · Vince Hsu
This patch creates a subdev for DVFS (Dynamic Voltage and Frequency Scaling)
support in Nouveau. This subdev refers to the status information provided by
the NVIDIA hardware and tries to adjust the performance level based on the
calculated target. Only the GK20A is supported right now.Hey Vince,
I'd not make a new subdev, but implement this in the PMU (PWR currently) subdev. The ucode that's supposed to be running there can do the performance monitoring in a more complex implementation, and it's PMU counters you're touching to get the usage stats :) But the simpler on-host implementation is totally fine.
Quoted 6 lines
Quoted 6 lines
Yeah, I know we have the counters defined in
daemon.c. Martin reminded me that Roy had a patch to remove that, sorry that I could not find the link now. Another reason I did not use thenouveau_specsigis because I had to create some nvif structures to access the counters and that's not straightforward. I'm happy to hear you're fine with the on-host implementation. :)
Quoted 3 lines
Hey Vince,
It's not Roy but me who had submitted a patch which removes PDAEMON signals. :-)
Oops. Sorry for the wrong name, my bad.
Quoted 637 lines
However, the patch is not ready to be upstream because we don't have any other ways to expose these performance counters.
Currently, I'm working on perfmon and nvif to expose hardware events to the userspace for NV50. I hope to submit the bunch of patches as soon as possible but unfortunately, I don't have my full time on this, so it takes more time than expected.
Quoted 630 lines
Quoted 8 lines
I will move all to PWR subdev in the next version.
Quoted 4 lines
The current base PMU implementation tries to do a lot of stuff that you don't need, just override the implementation entirely for GK20A for now if that's easier than reworking it.
So currently there is no dGPU using the PMU? I just don't want to break any dGPU functions. ;)
We upload a custom firmware to it, which we (currently) only use as a script interpreter for memory clock changes. But for your needs right now, it'd be fine to ignore all the common code there for GK20A.
Quoted 605 lines
Quoted 4 lines
Aside from the subdev move, it looks good so far to me. Glad to see the CLK stuff isn't totally useless, despite it needing a *lot* of work.
BTW, can we add some execution time information for pstate? I mean something like "
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we don't want to change the user space ABI though.Thanks,
VinceQuoted 585 lines
Thanks,
Ben.Quoted 582 lines
Signed-off-by Vince Hsu <[email protected]>--- drm/Kbuild | 2 + drm/core/include/subdev/dvfs.h | 1 + drm/core/subdev/dvfs/base.c | 1 + drm/core/subdev/dvfs/gk20a.c | 1 + drm/core/subdev/dvfs/priv.h | 1 + nvkm/engine/device/nve0.c | 2 + nvkm/include/core/device.h | 1 + nvkm/include/subdev/dvfs.h | 30 ++++++++ nvkm/subdev/Makefile.am | 5 +- nvkm/subdev/dvfs/Makefile.am | 6 ++ nvkm/subdev/dvfs/base.c | 129 ++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/gk20a.c | 156 +++++++++++++++++++++++++++++++++++++++++ nvkm/subdev/dvfs/priv.h | 43 ++++++++++++ 13 files changed, 376 insertions(+), 2 deletions(-)create mode 120000
drm/core/include/subdev/dvfs.hcreate mode 120000drm/core/subdev/dvfs/base.ccreate mode 120000drm/core/subdev/dvfs/gk20a.ccreate mode 120000drm/core/subdev/dvfs/priv.hcreate mode 100644nvkm/include/subdev/dvfs.hcreate mode 100644 nvkm/subdev/dvfs/Makefile.am create mode 100644nvkm/subdev/dvfs/base.ccreate mode 100644nvkm/subdev/dvfs/gk20a.ccreate mode 100644nvkm/subdev/dvfs/priv.hdrm/Kbuild +2
-0@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o nouveau-y += core/subdev/volt/gpio.o nouveau-y += core/subdev/volt/nv40.o nouveau-y += core/subdev/volt/gk20a.o +nouveau-y += core/subdev/dvfs/base.o +nouveau-y += core/subdev/dvfs/gk20a.o nouveau-y += core/engine/falcon.o nouveau-y += core/engine/xtensa.odrm/core/include/subdev/dvfs.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/include/subdev/dvfs.hdrm/core/subdev/dvfs/base.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/base.cdrm/core/subdev/dvfs/gk20a.c new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/gk20a.cdrm/core/subdev/dvfs/priv.h new file +1
-0@@ -0,0 +1 @@ +../../../../nvkm/subdev/dvfs/priv.hnvkm/engine/device/nve0.c +2
-0@@ -41,6 +41,7 @@#include <subdev/bar.h> #include <subdev/pwr.h> #include <subdev/volt.h> +#include <subdev/dvfs.h> #include <engine/device.h> #include <engine/dmaobj.h> @@ -180,6 +181,7 @@ nve0_identify(struct nouveau_device *device) device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass; device->oclass[NVDEV_ENGINE_PERFMON ] = &gk20a_perfmon_oclass; device->oclass[NVDEV_SUBDEV_VOLT ] = &gk20a_volt_oclass; + device->oclass[NVDEV_SUBDEV_DVFS ] =gk20a_dvfs_oclass; break; case 0xf0: device->cname = "GK110";nvkm/include/core/device.h +1
-0@@ -39,6 +39,7 @@ enum nv_subdev_type {NVDEV_SUBDEV_VOLT ,NVDEV_SUBDEV_THERM ,NVDEV_SUBDEV_CLOCK , +NVDEV_SUBDEV_DVFS ,NVDEV_ENGINE_FIRST , NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,nvkm/include/subdev/dvfs.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_DVFS_H__ +#define __NOUVEAU_DVFS_H__ + +#include <core/subdev.h> +#include <core/device.h> + +#include <subdev/timer.h> + +struct nouveau_dvfs_data { +int p_load_target; +int p_load_max; +int p_smooth; +unsigned int avg_load; +}; + +struct nouveau_dvfs { +struct nouveau_subdev base; +struct nouveau_alarm alarm; +struct nouveau_dvfs_data *data; +}; + +static inline struct nouveau_dvfs * +nouveau_dvfs (void *obj) +{ +return (void *)nv_device (obj)->subdev[NVDEV_SUBDEV_DVFS ]; +} + +extern struct nouveau_oclass *gk20a_dvfs_oclass; + +#endif nvkm/subdev/Makefile.am +3
-2@@ -1,5 +1,5 @@ SUBDIRS = bar bus bios clock devinit fb fuse gpio i2c ibus instmem \ - ltc mc mxm pwr therm timer vm volt + ltc mc mxm pwr therm timer vm volt dvfs noinst_LTLIBRARIES = libsubdev.la@@ -22,4 +22,5 @@ libsubdev_la_LIBADD = bar/libbar.la \ therm/libtherm.la \ timer/libtimer.la \ vm/libvm.la \ - volt/libvolt.la + volt/libvolt.la \ + dvfs/dvfs.lanvkm/subdev/dvfs/Makefile.am new file +6
-0@@ -0,0 +1,6 @@ +noinst_LTLIBRARIES = libdvfs.la + +libdvfs_la_SOURCES = base.c \ + gk20a.c + +include $(srcdir)/../Makefile.subdevnvkm/subdev/dvfs/base.c new file +4
-0@@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/base.c new file +13
-0+ +#include <core/option.h> + +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +static void +_nouveau_dvfs_work (struct nouveau_alarm *alarm) +{ + struct nouveau_dvfs *dvfs = container_of(alarm, struct
nouveau_dvfs,nvkm/subdev/dvfs/base.c new file +16
-0+ alarm); +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_object *object =nv_object (dvfs); +struct nouveau_dvfs_impl *impl = (void *)object->oclass; +struct nouveau_dvfs_dev_status status; +u32 utilization =0 ; +int state, ret; + + ret = impl->get_dev_status (dvfs, &status); +if (ret) { +nv_warn (dvfs,"failed to get device status\n" ); + goto resched; + } + +if (status.total) + utilization = div_u64((u64)status.busy * 100,status.total);
nvkm/subdev/dvfs/base.c new file +2
-0+ + data->avg_load = (data->p_smooth * data->avg_load) +utilization;
nvkm/subdev/dvfs/base.c new file +68
-0+ data->avg_load /= data->p_smooth +1 ; +nv_trace (dvfs,"utilization = %d %%, avg_load = %d %%\n" , + utilization, data->avg_load); + + ret = impl->get_cur_state (dvfs, &state); +if (ret) { +nv_warn (dvfs,"failed to get current state\n" ); + goto resched; + } + +if (impl->get_target_state (dvfs, &state, data->avg_load)) { +nv_trace (dvfs,"set new state to %d\n" , state); + impl->target (dvfs, &state); + } + +resched: + impl->reset_dev_status (dvfs); +nouveau_timer_alarm (dvfs,100000000 , alarm); +} + +int +_nouveau_dvfs_fini (struct nouveau_object *object,bool suspend) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_timer_alarm_cancel (dvfs, &dvfs->alarm); + +return nouveau_subdev_fini (&dvfs->base, suspend); +} + +int +_nouveau_dvfs_init (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; +struct nouveau_clock *clk =nouveau_clock (object); +struct nouveau_volt *volt =nouveau_volt (object); +int ret; + + ret =nouveau_subdev_init (&dvfs->base); +if (ret) +return ret; + +if (!clk || !volt) +return -EINVAL ; + +nouveau_timer_alarm (dvfs,2000000000 , &dvfs->alarm); + +return 0 ; +} + +void +_nouveau_dvfs_dtor (struct nouveau_object *object) +{ +struct nouveau_dvfs *dvfs = (void *)object; + +nouveau_subdev_destroy (&dvfs->base); +} + +int +nouveau_dvfs_create_ (struct nouveau_object *parent, +struct nouveau_object *engine, +struct nouveau_oclass *oclass, +int size,void **pobject) +{ +struct nouveau_dvfs *dvfs; +int ret; + + ret = nouveau_subdev_create_(parent, engine, oclass, 0,"DVFS",
nvkm/subdev/dvfs/base.c new file +9
-0+ "dvfs", size, pobject); + dvfs = *pobject; +if (ret) +return ret; + +nouveau_alarm_init (&dvfs->alarm, _nouveau_dvfs_work); + +return 0 ; +}nvkm/subdev/dvfs/gk20a.c new file +4
-0@@ -0,0 +1,156 @@ +/* +* Copyright (c) 2014, 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */nvkm/subdev/dvfs/gk20a.c new file +33
-0+ +#include <subdev/clock.h> +#include <subdev/dvfs.h> +#include <subdev/volt.h> + +#include "priv.h" + +#define BUSY_SLOT 0 +#define CLK_SLOT 7 + +struct gk20a_dvfs_priv { +struct nouveau_dvfs base; +}; + +static int +gk20a_dvfs_target (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + +return nouveau_clock_astate (clk, *state,0 , false); +} + +static int +gk20a_dvfs_get_cur_state (struct nouveau_dvfs *dvfs,int *state) +{ +struct nouveau_clock *clk =nouveau_clock (dvfs); + + *state = clk->pstate; +return 0 ; +} + +static int +gk20a_dvfs_get_target_state(struct nouveau_dvfs *dvfs, int*state, int
load)nvkm/subdev/dvfs/gk20a.c new file +6
-0+{ +struct nouveau_dvfs_data *data = dvfs->data; +struct nouveau_clock *clk =nouveau_clock (dvfs); +int cur_level, level; + +/* For GK20A, the performance level is directly mapped to pstate
*/nvkm/subdev/dvfs/gk20a.c new file +4
-0+ level = cur_level = clk->pstate; + +if (load > data->p_load_max) { + level = min(clk->state_nr - 1, level +(
clk->state_nr/
3));nvkm/subdev/dvfs/gk20a.c new file +8
-0+ }else { + level += ((load - data->p_load_target) *10 / + data->p_load_target) /2 ; + level =max (0 , level); + level =min (clk->state_nr -1 , level); + } + + nv_trace(dvfs, "cur level = %d, new level = %d\n", cur_level,level);
nvkm/subdev/dvfs/gk20a.c new file +51
-0+ + *state = level; + +if (level == cur_level) +return 0 ; +else +return 1 ; +} + +static int +gk20a_dvfs_get_dev_status (struct nouveau_dvfs *dvfs, +struct nouveau_dvfs_dev_status *status) +{ + status->busy =nv_rd32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 )); + status->total=nv_rd32 (dvfs,0x10a508 + (CLK_SLOT *0x10 )); +return 0 ; +} + +static void +gk20a_dvfs_reset_dev_status (struct nouveau_dvfs *dvfs) +{ +nv_wr32 (dvfs,0x10a508 + (BUSY_SLOT *0x10 ),0x80000000 ); +nv_wr32 (dvfs,0x10a508 + (CLK_SLOT *0x10 ),0x80000000 ); +} + +static int +gk20a_dvfs_init (struct nouveau_object *object) +{ +struct gk20a_dvfs_priv *priv = (void *)object; +int ret; + +/* init pwr perf counter */ +nv_wr32 (priv,0x10a504 + (BUSY_SLOT *0x10 ),0x00200001 ); +nv_wr32 (priv,0x10a50c + (BUSY_SLOT *0x10 ),0x00000002 ); +nv_wr32 (priv,0x10a50c + (CLK_SLOT *0x10 ),0x00000003 ); + + ret =nouveau_dvfs_init (&priv->base); +if (ret) +return ret; + +return 0 ; +} + +struct nouveau_dvfs_data gk20a_dvfs_data = { + .p_load_target =70 , + .p_load_max =90 , + .p_smooth =1 , +}; + +static int +gk20a_dvfs_ctor(struct nouveau_object *parent, struct nouveau_object*engine,
nvkm/subdev/dvfs/gk20a.c new file +33
-0+ struct nouveau_oclass *oclass, void *data, u32 size, + struct nouveau_object **pobject) +{ + struct gk20a_dvfs_priv *priv; +struct nouveau_dvfs *dvfs; +int ret; + + ret =nouveau_dvfs_create (parent, engine, oclass, &priv); + *pobject =nv_object (priv); +if (ret) +return ret; + + dvfs = &priv->base; + dvfs->data = &gk20a_dvfs_data; + +return 0 ; +} + +struct nouveau_oclass * +gk20a_dvfs_oclass = &(struct nouveau_dvfs_impl ) { + .base.handle =NV_SUBDEV (DVFS ,0xea ), + .base.ofuncs = &(struct nouveau_ofuncs ) { + .ctor = gk20a_dvfs_ctor, + .dtor = _nouveau_dvfs_dtor, + .init = gk20a_dvfs_init, + .fini = _nouveau_dvfs_fini, + }, + .get_dev_status = gk20a_dvfs_get_dev_status, + .reset_dev_status = gk20a_dvfs_reset_dev_status, + .target = gk20a_dvfs_target, + .get_cur_state = gk20a_dvfs_get_cur_state, + .get_target_state = gk20a_dvfs_get_target_state, +}.base;nvkm/subdev/dvfs/priv.h new file +19
-0@@ -0,0 +1,43 @@ +#ifndef __NVKM_DVFS_PRIV_H__ +#define __NVKM_DVFS_PRIV_H__ + +#include <subdev/dvfs.h> + +struct nouveau_dvfs_dev_status { + unsigned long total; + unsigned long busy; + int cur_state; +}; + +struct nouveau_dvfs_impl { + struct nouveau_oclass base; + int (*get_dev_status)(struct nouveau_dvfs *, + struct nouveau_dvfs_dev_status *); + void (*reset_dev_status)(struct nouveau_dvfs *); + int (*target)(struct nouveau_dvfs *, int *state); + int (*get_cur_state)(struct nouveau_dvfs *, int *state); + int (*get_target_state)(struct nouveau_dvfs *, int *state,int
load);nvkm/subdev/dvfs/priv.h new file +3
-0+}; + +#define nouveau_dvfs_create (p,e,o,d)\
nvkm/subdev/dvfs/priv.h new file +2
-0+ nouveau_dvfs_create_((p), (e), (o), sizeof(**d), (void **)d) +#define nouveau_dvfs_destroy (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_dtor(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_init (p) ({\
+ structnouveau_dvfs*d = (p);
\
+ _nouveau_dvfs_init(nv_object(d));
\nvkm/subdev/dvfs/priv.h new file +2
-0+}) +#define nouveau_dvfs_fini (p,s) ({\
+ structnouveau_dvfs*d = (p);
\
+_nouveau_dvfs_fini(nv_object(d), (s));
\nvkm/subdev/dvfs/priv.h new file +3
-0+}) + +int nouveau_dvfs_create_(struct nouveau_object *, struct
nouveau_object
*,nvkm/subdev/dvfs/priv.h new file +6
-0+ struct nouveau_oclass *, int, void **); +void _nouveau_dvfs_dtor(struct nouveau_object *); +int _nouveau_dvfs_init (struct nouveau_object *); +int _nouveau_dvfs_fini (struct nouveau_object *,bool suspend); + +#endif Signature · 1 line
1.9.1Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau-----------------------------------------------------------------------------------
Quoted 9 lines
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
RFC PATCH 3/3 clk: allow users to enable auto mode when loading driver
In reply to a message not in the archiveThis patch adds one option for the boot config strings "NvClkMode*", so that we can enable the "auto" mode when loading module.
--- nvkm/subdev/clock/base.c | 3 +++ 1 file changed, 3 insertions(+)
nvkm/subdev/clock/base.c +3 -0
@@ -401,6 +401,9 @@ nouveau_clock_nstate(struct nouveau_clock *clk, const char *mode, int arglen) {int ret =1 ; +if (clk->allow_reclock && !strncasecmpz (mode,"auto" , arglen)) +return -2 ; +if (strncasecmpz (mode,"disabled" , arglen)) {char save = mode[arglen];long v;
Signature · 6 lines
1.9.1 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau