Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10401527rwd; Wed, 21 Jun 2023 22:40:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wpY+46ddOR0jH1pKSpiGMMutCxrV0D04TBfaq3JVuCM8iqJEYzmvPti3Aw7awdzwNONz4 X-Received: by 2002:a05:6a21:9988:b0:122:4a17:8534 with SMTP id ve8-20020a056a21998800b001224a178534mr12702672pzb.1.1687412420456; Wed, 21 Jun 2023 22:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687412420; cv=none; d=google.com; s=arc-20160816; b=M6m2fZgICc+SI4LaGYAtY2vyafVZM2FrMHM0o0ClS5j6JGZ6+WVAe/9GaDyp563Cdb E/xvlIMShMpeRfn+4GA59asPADOj3HEO641beQHfeL4RMpTypUt3S89v0k8MpJIfk+Y+ AHyr0+LBYc5OYyuBQCeEH4YaCekIE1SvAx0vbKausOaDa4EbL8QT7XchCFISEeWWZ67b XO+Guu3eHlwdsMEWagMtdgNHeYf2YkGLTMrcvlT/ES4oeDXRADfReY+jQ3jXzheV3KHC u8/15ckaA/78x/8sLwP37R4ARBLzxH4ajjcOUNvQf9sRw2V3ypbiksNDSlRtCHo7TZiK Z72w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8tWZIJHNCeNHopsgROt99NAlnCyyYkb9Bpqw1pz4xS0=; b=c+6P8mm5Z0pwsHH6UbhRt/4SBojEP07Ctm5wm5b8m3wKZSAfUk7sS3RRvkHinVuSGH TTcQLAN+7SU0ehFw1zuZaNllXKOC6AM/KabhYYNslAfMnCSx2Ybf4P+syRi79v+Dpoy3 xzHpnV17Oumr5oktELBNYJPz97DgxvC6BAEaNWCy9wdtosBpaCe1fIv98604BqdhUt4w /vt52SUVXh+tbT7VOMHFN2sNqhg/mghs6N6ncqMMJuigfuefP8SoFRX1AOs0t14PSqF5 k1g3SOoUywM/U6vNQBnvCrchOKf7FUljsdd3pqy4DCyhnVRkrTpK7CwM/MzGjxCjdZdC Bhig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r31Utikv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k129-20020a633d87000000b00551bb2b99besi5959419pga.85.2023.06.21.22.40.08; Wed, 21 Jun 2023 22:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r31Utikv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjFVE40 (ORCPT + 99 others); Thu, 22 Jun 2023 00:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbjFVE4Y (ORCPT ); Thu, 22 Jun 2023 00:56:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B24F19A1; Wed, 21 Jun 2023 21:56:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF31961725; Thu, 22 Jun 2023 04:56:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3A41C433C8; Thu, 22 Jun 2023 04:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687409780; bh=lri1nd5wS7oB4FBbQf+NRYb9hZNLJZy73nB3fVrApqU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r31UtikvdakxdEF/Lk+BBD/pvE7TkJ4piHbWdl9rXyV1XzRU28MG5Cg0JLGpgjU1y OzZfsYHCJuSBPUk41TmcwLSh5rqxUIsnMgDcxa9yGahdaHdUG9MKMM6CyOhn57Rjt6 U119Ox/smMeb61R/h7fy5ls7ggpsQx2YNSNyQHEG9xXAr0keo/+ZsBEvlYtK7zltoO DpMlWUfiR/sQ5XkT2FsRVnnEZmfATBl9ghM99fWnhf3kIwzcFfRLYcnAV/vAeF/hWk RhDAWZoih7g0ls+lnZAXFLGGOHmvJuh3kl2IBGHQt/lp5mzRKJ3Jl4zCs2v/ijhUVP OlUDyLP5cMPNQ== Date: Wed, 21 Jun 2023 21:56:18 -0700 From: Eduardo Valentin To: Daniel Lezcano Cc: Eduardo Valentin , eduval@amazon.com, rafael@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria , Zhang Rui Subject: [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs Message-ID: References: <20230607003721.834038-1-evalenti@kernel.org> <7616fd9d-aa0d-2ecd-8751-894b1c9073c0@linaro.org> <75eba2da-593f-f3bd-4eac-5155fcf5aee8@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <75eba2da-593f-f3bd-4eac-5155fcf5aee8@linaro.org> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 21, 2023 at 01:43:26PM +0200, Daniel Lezcano wrote: > > > > On 21/06/2023 07:06, Eduardo Valentin wrote: > > On Mon, Jun 12, 2023 at 10:17:51AM +0200, Daniel Lezcano wrote: > > > > > > > > > > > > Hi Eduardo, > > > > > > On 08/06/2023 19:44, Eduardo Valentin wrote: > > > > > > [ ... ] > > > > > > > > Do you have a use case with some measurements to spot an issue or is it > > > > > a potential issue you identified ? > > > > > > > > > > > > yes, a governor that is using I2C device as input, behind I2C fast mode (100KHz) > > > > and needs to update the zone every 100ms. Each read in this bus, if done alone > > > > would be around 500us, takes 10bytes to read the device, it is 10 clocks per byte, > > > > well technically 9, but rounding for the sake of the example, which gets you > > > > 50 / 100KHz = 500 us. That is for a single read. You add one single extra > > > > userspace read triggering an unused device update, that is already a 1ms drift. > > > > Basically you looking at 0.5% for each extra userspace read competing in this > > > > sysfs node. You add extra devices in the same I2C bus, your governor is looking > > > > at more than 1% overhead. And I am talking also about a main CPU of ~800MHz. > > > > I did not even include the lock overhead considered for this CPU ;-) > > > > > > > > Again, this is not about controlling the DIE temperature of the CPU you > > > > are running the thermal subsystem. This is about controlling > > > > a target device. > > > > > > Ok. The target device is on a bus which is slow and prone to contention. > > > > > > This hardware is not designed to be monitored with a high precision, so > > > reading the temperature at a high rate does not really make sense. > > > > On the contrary, it needs even more precision and any extra delay adds to > > loss on accuracy :-) > > What I meant is if the hardware designer thought there could be a > problem with the thermal zone they would have put another kind of > sensor, not one with a i2c based communication. No, that is not a problem in the physical thermal zone. Or to cover for a hardware design flaw. This is an actual typical case. However, yes, designer must take into account any sort of delays or jittering in the control system, and typically one would add some thermal margins on the control system. But to the original point here, we should eliminate unnecessary jittering or delay in the control system. > > > > > Moreover (putting apart a potential contention), the delayed read does > > > not change the time interval, which remains the same from the governor > > > point of view. > > > > It does not change the governor update interval and that is a property of > > the thermal zone. Correct. And that is the intention of the change. > > The actual temperature updates driven by the governor will always > > result in a driver call. While a userspace call will not be in the way > > of the governor update. > > > > Sysfs reads, However, with the current code as is, it may cause > > jittering on the actual execution of the governor throttle function. > > causing the computation of the desired outcome cooling device being skewed. > > > > > > > > In addition, i2c sensors are usually handled in the hwmon subsystem > > > which are registered in the thermal framework from there. Those have > > > most of their 'read' callback with a cached value in a jiffies based way > > > eg. [1]. > > > > I guess what you are really saying is: go read the hwmon sysfs node, > > or, hwmon solves this for us, which unfortunately is not true for all devices. > > I meant the i2c sensors are under the hwmon subsystem. This subsystem is > connected with the thermal framework, so when a hwmon sensor is created, > it register this sensor as a thermal zone. > > > > > So the feature already exists for slow devices and are handled in the > > > drivers directly via the hwmon subsystem. > > > > > > From my POV, the feature is not needed in the thermal framework. > > > > The fact that hwmon does it in some way is another evidence of the > > actual problem. > > Not really, it shows the i2c sensors are in the hwmon subsystems. They are there too. And hwmon also sees same problem of too frequent device update. The problem is there regardless of the subsystem we use to represent the device. Also, I dont buy the argument that this is a problem of hwmon because it is already supported to plug in hwmon devices in the thermal subsystem. That is actually the original design in fact :-). So running a control in the thermal subsystem on top of inputs from hwmon, which happens to support I2C devices, is not a problem for hwmon to solve, since the control is in the thermal subsystem, and hwmon does not offer control solutions. > > > > Telling that this has to be solved by another subsystem > > for a sysfs node that is part of thermal subsystem does not really solve > > the problem. Also as I mentioned, this is not common on all hwmon > > devices, and not all I2C devices are hwmon devices. In fact, I2C > > was just one example of a slow device. There are more I can quote > > that are not necessarily under the hwmon case. > > Yes, please. Can you give examples with existing drivers in the thermal > framework and observed issues on specific platforms ? Numbers would help. I believe I already gave you numbers. And as I explained above, the driver does not need to sit on thermal subsystem only, we already support plugging in I2C/pmbus devices on the thermal subsystem, so basically all drivers on hwmon that has the REGISTER_TZ flag are actual samples for this problem -- All the best, Eduardo Valentin