Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1294971pxa; Thu, 13 Aug 2020 05:45:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfQJUOQx5kwsUk9pnv/QH7RNVBsq1sDseyd0XfGPwbOb2zdy10pcfUqwFoMAi2N0HdkJNY X-Received: by 2002:a17:906:374f:: with SMTP id e15mr4391906ejc.528.1597322709365; Thu, 13 Aug 2020 05:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597322709; cv=none; d=google.com; s=arc-20160816; b=fO8od5Ar4mFd5GUajN89fFI02mcR9SjGSaNmmV/WfMMZoRDRli/66vyBwmyTlzXvS+ 2Pq1Q6AaGGlUH2T7voEFUdz/h9bCyiEafDpvA0zJphRzlmGHfcP/abK1kkHK7744TrBT 7fzSfUeFXejCzL+LvW/1z8ABlMThye7KiTXh6x/bqUZeXhP+smc0IYpcpn4SVNp79n2x G79fZd/4B0Iauz3oovXXuJ353+1Xm7jVy/S5kTyDT39+Ga+gW9dVaYomaIfq/7JtuMYT AnAIoxXdrVHa/y3z+qubC4mM7auL2kzGLEYK8wmx7AW9hljdBEsG29vsLYXl6M57QMCO oehw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DuaKe1mZfbQOEy3vU0IvOh3qvOEZnjiR99rYX0WAkfY=; b=Hs0nDrqZC39cOQE1U//ivyvs8F9oPfI0ynG9S8iH9ZIVtJiN1dTjtjiy11h7uMqqco 1DBq91PiQLIWVBa6foo4Yt0UFx3Pby4DeA0qE2ecudbT18TEfkOCEp/lxTTa2nt/Iqqe uE8S11wi1Xk8vVwoJnDNFJj6RDrPHj/PMPiiz+WzrU++pk9XKUBXAAmk1PCee6Bzwxmd bNV6P1c/vj2Q8aRdyyDRYK3dOdvQ7dJy4Hrs44/B94YhFeXbv929KH012KmlZoPOOdi8 IyXsIKRBb0rdm0faX1glbPgN55hzMf1H+3Y4zq9ffPPwNoQ++Mh1WG+9+pzfwoODubn/ MmRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SmiBT0ln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yk11si3266864ejb.113.2020.08.13.05.44.44; Thu, 13 Aug 2020 05:45:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SmiBT0ln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726167AbgHMMoR (ORCPT + 99 others); Thu, 13 Aug 2020 08:44:17 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:22220 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726053AbgHMMoN (ORCPT ); Thu, 13 Aug 2020 08:44:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597322651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DuaKe1mZfbQOEy3vU0IvOh3qvOEZnjiR99rYX0WAkfY=; b=SmiBT0lnFaHbkRZKsWrJ2eaa4lllHXVa9oOwfSUtxgz+M7+RljwhJq1pTCbijUxkd2hhIo n3JC03Isml0iPa22zJdA7lemKEsIKhqNIHGThgKeVeLpc/uwXr5qMzVlmNJWm0Fm+uZiFK kq1/cdCWyKrEhrBXbrSTFfhM7JE+InQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-OdL8TFQBP9qnSm2Hcaj50Q-1; Thu, 13 Aug 2020 08:44:09 -0400 X-MC-Unique: OdL8TFQBP9qnSm2Hcaj50Q-1 Received: by mail-qk1-f198.google.com with SMTP id z1so3798538qkg.23 for ; Thu, 13 Aug 2020 05:44:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DuaKe1mZfbQOEy3vU0IvOh3qvOEZnjiR99rYX0WAkfY=; b=VLuISregqkKOch4GNCEqft8Rn75X0qOtnckD1aGHXzS7UpDrm3mmmwI9YvGOG4vfWp ufC4Zq+0zCr1i7AO8tj2N47kXNr4prsrIBF9JKzM7ZSv107h5Ny03kyH3sgq7Qc0KJ5E 8DPIPy8A3X/pHQcXRDAsPi8WnklExccrCBTS9Z40b3DxuutaOcN1RvHSCP6svDln+b/K 0ZRVaqBF8k4pAHVmEeJaD+hH4W7gHK6m/UVqL2YKm3KYVY8ViK+9el3/5K7tx3o2Pi3L etmGXrm27EwCIqwBgEn6UaewWeNOiU+QS65UvAz4r8IHjER+MIHTvdAuRFYg5slFsNM4 rECg== X-Gm-Message-State: AOAM531D7vQcqhZpmJ7V/zEqxvgcJqGz06vpUsvU6tXyC5AzcjEzM+GC WSIGblGMaq8+vwZzO56VRpL4hC56Az8mcI4KYnP88Hd5DZoBEEPImMyuOFsORRGETNnhAnGo5ag IA022zi9wwg1tN0fnwoB7MkMksU/6KH7QxAjwjR1y X-Received: by 2002:ac8:74c7:: with SMTP id j7mr4944631qtr.254.1597322648938; Thu, 13 Aug 2020 05:44:08 -0700 (PDT) X-Received: by 2002:ac8:74c7:: with SMTP id j7mr4944601qtr.254.1597322648679; Thu, 13 Aug 2020 05:44:08 -0700 (PDT) MIME-Version: 1.0 References: <20200812204952.1921587-1-jcline@redhat.com> In-Reply-To: <20200812204952.1921587-1-jcline@redhat.com> From: Karol Herbst Date: Thu, 13 Aug 2020 14:43:57 +0200 Message-ID: Subject: Re: [PATCH] drm/nouveau: Add fine-grain temperature reporting To: Jeremy Cline Cc: Ben Skeggs , David Airlie , Daniel Vetter , dri-devel , nouveau , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reviewed-by: Karol Herbst On Wed, Aug 12, 2020 at 10:50 PM Jeremy Cline wrote: > > Commit d32656373857 ("drm/nouveau/therm/gp100: initial implementation of > new gp1xx temperature sensor") added support for reading finer-grain > temperatures, but continued to report temperatures in 1 degree Celsius > increments via nvkm_therm_temp_get(). > > Rather than altering nvkm_therm_temp_get() to report finer-grain > temperatures, which would be inconvenient for other users of the > function, a second interface has been added to line up with hwmon's > native unit of temperature. > > Signed-off-by: Jeremy Cline > --- > .../drm/nouveau/include/nvkm/subdev/therm.h | 18 +++++++++++++ > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 4 +-- > .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 16 ++++++++++++ > .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 25 +++++++++++++++++-- > .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 1 + > 5 files changed, 60 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > index 62c34f98c930..7b9928dd001c 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > @@ -100,6 +100,24 @@ struct nvkm_therm { > }; > > int nvkm_therm_temp_get(struct nvkm_therm *); > + > +/** > + * nvkm_therm_temp_millidegree_get() - get the temperature in millidegrees > + * @therm: The thermal device to read from. > + * > + * This interface reports temperatures in units of millidegree Celsius to > + * align with the hwmon API. Some cards may only be capable of reporting in > + * units of Celsius, and those that report finer grain temperatures may not be > + * capable of millidegree Celsius accuracy, > + * > + * For cases where millidegree temperature is too fine-grain, the > + * nvkm_therm_temp_get() interface reports temperatures in one degree Celsius > + * increments. > + * > + * Return: The temperature in millidegrees Celsius, or -ENODEV if temperature > + * reporting is not supported. > + */ > +int nvkm_therm_temp_millidegree_get(struct nvkm_therm *therm); > int nvkm_therm_fan_sense(struct nvkm_therm *); > int nvkm_therm_cstate(struct nvkm_therm *, int, int); > void nvkm_therm_clkgate_init(struct nvkm_therm *, > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > index 1c3104d20571..e96355f93ce5 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val) > case hwmon_temp_input: > if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) > return -EINVAL; > - ret = nvkm_therm_temp_get(therm); > - *val = ret < 0 ? ret : (ret * 1000); > + ret = nvkm_therm_temp_millidegree_get(therm); > + *val = ret; > break; > case hwmon_temp_max: > *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > index 4a4d1e224126..e655b32c78b8 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > @@ -34,6 +34,22 @@ nvkm_therm_temp_get(struct nvkm_therm *therm) > return -ENODEV; > } > > +int > +nvkm_therm_temp_millidegree_get(struct nvkm_therm *therm) > +{ > + int ret = -ENODEV; > + > + if (therm->func->temp_millidegree_get) > + return therm->func->temp_millidegree_get(therm); > + > + if (therm->func->temp_get) { > + ret = therm->func->temp_get(therm); > + if (ret > 0) > + ret *= 1000; > + } > + return ret; > +} > + > static int > nvkm_therm_update_trip(struct nvkm_therm *therm) > { > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c > index 9f0dea3f61dc..4c3c2895a3cb 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c > @@ -24,7 +24,7 @@ > #include "priv.h" > > static int > -gp100_temp_get(struct nvkm_therm *therm) > +gp100_temp_get_raw(struct nvkm_therm *therm) > { > struct nvkm_device *device = therm->subdev.device; > struct nvkm_subdev *subdev = &therm->subdev; > @@ -37,14 +37,35 @@ gp100_temp_get(struct nvkm_therm *therm) > > /* device valid */ > if (tsensor & 0x20000000) > - return (inttemp >> 8); > + return inttemp; > else > return -ENODEV; > } > > +static int > +gp100_temp_millidegree_get(struct nvkm_therm *therm) > +{ > + int raw_temp = gp100_temp_get_raw(therm); > + > + if (raw_temp < 0) > + return raw_temp; > + return raw_temp * 1000 >> 8; > +} > + > +static int > +gp100_temp_get(struct nvkm_therm *therm) > +{ > + int raw_temp = gp100_temp_get_raw(therm); > + > + if (raw_temp < 0) > + return raw_temp; > + return raw_temp >> 8; > +} > + > static const struct nvkm_therm_func > gp100_therm = { > .temp_get = gp100_temp_get, > + .temp_millidegree_get = gp100_temp_millidegree_get, > .program_alarms = nvkm_therm_program_alarms_polling, > }; > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h > index 21659daf1864..a53068b4f0b9 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h > @@ -92,6 +92,7 @@ struct nvkm_therm_func { > int (*pwm_clock)(struct nvkm_therm *, int line); > > int (*temp_get)(struct nvkm_therm *); > + int (*temp_millidegree_get)(struct nvkm_therm *therm); > > int (*fan_sense)(struct nvkm_therm *); > > -- > 2.26.2 >