Re: [Nouveau] [RFC PATCH 16/29] clk: parse thermal policies for throttling thresholds

2017-10-08 Thread Karol Herbst
On Sun, Oct 8, 2017 at 8:36 PM, Pierre Moreau  wrote:
> On 2017-09-15 — 17:11, Karol Herbst wrote:
>> v2: use min_t
>>
>> Signed-off-by: Karol Herbst 
>> ---
>>  drm/nouveau/include/nvkm/subdev/clk.h |  2 ++
>>  drm/nouveau/nvkm/subdev/clk/base.c| 42 
>> +++
>>  2 files changed, 44 insertions(+)
>>
>> diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
>> b/drm/nouveau/include/nvkm/subdev/clk.h
>> index f35518c3..f5ff1fd9 100644
>> --- a/drm/nouveau/include/nvkm/subdev/clk.h
>> +++ b/drm/nouveau/include/nvkm/subdev/clk.h
>> @@ -104,6 +104,8 @@ struct nvkm_clk {
>>   struct nvkm_cstate *cstate;
>>   int exp_cstateid;
>>   u8  temp;
>> + u8  max_temp;
>> + u8  relax_temp;
>
> I guess those should be int, similar to the changes you made in patch 1.
>
>>
>>   bool allow_reclock;
>>  #define NVKM_CLK_BOOST_NONE 0x0
>> diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
>> b/drm/nouveau/nvkm/subdev/clk/base.c
>> index 54188d2b..54e14936 100644
>> --- a/drm/nouveau/nvkm/subdev/clk/base.c
>> +++ b/drm/nouveau/nvkm/subdev/clk/base.c
>> @@ -27,6 +27,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -659,6 +660,44 @@ nvkm_clk = {
>>   .fini = nvkm_clk_fini,
>>  };
>>
>> +static void
>> +nvkm_clk_parse_max_temp(struct nvkm_clk *clk)
>> +{
>> + struct nvkm_subdev *subdev = >subdev;
>> + struct nvkm_bios *bios = subdev->device->bios;
>> + struct nvbios_thermal_policies_header header;
>> + struct nvbios_thermal_policies_entry entry;
>> + u8 i;
>> + s16 mt = 0xff;
>> + s16 rt = 0xff;
>
> Why 0xff? I mean, sure, there is a high possibility that the GPU won’t like
> temperatures above 255℃, but still.

just a hack to properly check if we set any values we can use and make
available.

>
>> +
>> + if (nvbios_thermal_policies_parse(bios, ))
>> + return;
>> +
>> + if (!header.ecount)
>> + return;
>> +
>> + for (i = 0; i < header.ecount; i++) {
>> + if (nvbios_thermal_policies_entry(bios, , i, ))
>> + return;
>> +
>> + if (entry.mode != 1)
>> + continue;
>> +
>> + mt = min_t(s16, mt, (entry.t0 + entry.down_offset) / 32);
>> + rt = min_t(s16, rt, (entry.t0 + entry.up_offset) / 32);
>> + }
>> +
>> + if (mt == 0xff || rt == 0xff)
>> + return;
>> +
>> + clk->max_temp = mt;
>> + clk->relax_temp = rt;
>> +
>> + nvkm_debug(subdev, "setting up sw throttling thresholds (%u/%u°C)\n",
>> +clk->max_temp, clk->relax_temp);
>> +}
>> +
>>  int
>>  nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
>> int index, bool allow_reclock, struct nvkm_clk *clk)
>> @@ -733,6 +772,9 @@ nvkm_clk_ctor(const struct nvkm_clk_func *func, struct 
>> nvkm_device *device,
>>
>>   clk->boost_mode = nvkm_longopt(device->cfgopt, "NvBoost",
>>  NVKM_CLK_BOOST_NONE);
>> +
>> + nvkm_clk_parse_max_temp(clk);
>> +
>>   return 0;
>>  }
>>
>> --
>> 2.14.1
>>
>> ___
>> Nouveau mailing list
>> Nouveau@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/nouveau
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [RFC PATCH 16/29] clk: parse thermal policies for throttling thresholds

2017-10-08 Thread Pierre Moreau
On 2017-09-15 — 17:11, Karol Herbst wrote:
> v2: use min_t
> 
> Signed-off-by: Karol Herbst 
> ---
>  drm/nouveau/include/nvkm/subdev/clk.h |  2 ++
>  drm/nouveau/nvkm/subdev/clk/base.c| 42 
> +++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
> b/drm/nouveau/include/nvkm/subdev/clk.h
> index f35518c3..f5ff1fd9 100644
> --- a/drm/nouveau/include/nvkm/subdev/clk.h
> +++ b/drm/nouveau/include/nvkm/subdev/clk.h
> @@ -104,6 +104,8 @@ struct nvkm_clk {
>   struct nvkm_cstate *cstate;
>   int exp_cstateid;
>   u8  temp;
> + u8  max_temp;
> + u8  relax_temp;

I guess those should be int, similar to the changes you made in patch 1.

>  
>   bool allow_reclock;
>  #define NVKM_CLK_BOOST_NONE 0x0
> diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
> b/drm/nouveau/nvkm/subdev/clk/base.c
> index 54188d2b..54e14936 100644
> --- a/drm/nouveau/nvkm/subdev/clk/base.c
> +++ b/drm/nouveau/nvkm/subdev/clk/base.c
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -659,6 +660,44 @@ nvkm_clk = {
>   .fini = nvkm_clk_fini,
>  };
>  
> +static void
> +nvkm_clk_parse_max_temp(struct nvkm_clk *clk)
> +{
> + struct nvkm_subdev *subdev = >subdev;
> + struct nvkm_bios *bios = subdev->device->bios;
> + struct nvbios_thermal_policies_header header;
> + struct nvbios_thermal_policies_entry entry;
> + u8 i;
> + s16 mt = 0xff;
> + s16 rt = 0xff;

Why 0xff? I mean, sure, there is a high possibility that the GPU won’t like
temperatures above 255℃, but still.

> +
> + if (nvbios_thermal_policies_parse(bios, ))
> + return;
> +
> + if (!header.ecount)
> + return;
> +
> + for (i = 0; i < header.ecount; i++) {
> + if (nvbios_thermal_policies_entry(bios, , i, ))
> + return;
> +
> + if (entry.mode != 1)
> + continue;
> +
> + mt = min_t(s16, mt, (entry.t0 + entry.down_offset) / 32);
> + rt = min_t(s16, rt, (entry.t0 + entry.up_offset) / 32);
> + }
> +
> + if (mt == 0xff || rt == 0xff)
> + return;
> +
> + clk->max_temp = mt;
> + clk->relax_temp = rt;
> +
> + nvkm_debug(subdev, "setting up sw throttling thresholds (%u/%u°C)\n",
> +clk->max_temp, clk->relax_temp);
> +}
> +
>  int
>  nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
> int index, bool allow_reclock, struct nvkm_clk *clk)
> @@ -733,6 +772,9 @@ nvkm_clk_ctor(const struct nvkm_clk_func *func, struct 
> nvkm_device *device,
>  
>   clk->boost_mode = nvkm_longopt(device->cfgopt, "NvBoost",
>  NVKM_CLK_BOOST_NONE);
> +
> + nvkm_clk_parse_max_temp(clk);
> +
>   return 0;
>  }
>  
> -- 
> 2.14.1
> 
> ___
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau


signature.asc
Description: PGP signature
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 16/29] clk: parse thermal policies for throttling thresholds

2017-09-15 Thread Karol Herbst
v2: use min_t

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  2 ++
 drm/nouveau/nvkm/subdev/clk/base.c| 42 +++
 2 files changed, 44 insertions(+)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index f35518c3..f5ff1fd9 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -104,6 +104,8 @@ struct nvkm_clk {
struct nvkm_cstate *cstate;
int exp_cstateid;
u8  temp;
+   u8  max_temp;
+   u8  relax_temp;
 
bool allow_reclock;
 #define NVKM_CLK_BOOST_NONE 0x0
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 54188d2b..54e14936 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -659,6 +660,44 @@ nvkm_clk = {
.fini = nvkm_clk_fini,
 };
 
+static void
+nvkm_clk_parse_max_temp(struct nvkm_clk *clk)
+{
+   struct nvkm_subdev *subdev = >subdev;
+   struct nvkm_bios *bios = subdev->device->bios;
+   struct nvbios_thermal_policies_header header;
+   struct nvbios_thermal_policies_entry entry;
+   u8 i;
+   s16 mt = 0xff;
+   s16 rt = 0xff;
+
+   if (nvbios_thermal_policies_parse(bios, ))
+   return;
+
+   if (!header.ecount)
+   return;
+
+   for (i = 0; i < header.ecount; i++) {
+   if (nvbios_thermal_policies_entry(bios, , i, ))
+   return;
+
+   if (entry.mode != 1)
+   continue;
+
+   mt = min_t(s16, mt, (entry.t0 + entry.down_offset) / 32);
+   rt = min_t(s16, rt, (entry.t0 + entry.up_offset) / 32);
+   }
+
+   if (mt == 0xff || rt == 0xff)
+   return;
+
+   clk->max_temp = mt;
+   clk->relax_temp = rt;
+
+   nvkm_debug(subdev, "setting up sw throttling thresholds (%u/%u°C)\n",
+  clk->max_temp, clk->relax_temp);
+}
+
 int
 nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
  int index, bool allow_reclock, struct nvkm_clk *clk)
@@ -733,6 +772,9 @@ nvkm_clk_ctor(const struct nvkm_clk_func *func, struct 
nvkm_device *device,
 
clk->boost_mode = nvkm_longopt(device->cfgopt, "NvBoost",
   NVKM_CLK_BOOST_NONE);
+
+   nvkm_clk_parse_max_temp(clk);
+
return 0;
 }
 
-- 
2.14.1

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau