Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp21933104rwd; Fri, 30 Jun 2023 01:26:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHKFMJl0SKrqsYl5U1PWjRCG+NVOFXXTcs8WwdHXrMR+lBtGpVbkQ9vJprViEkuA3nMZX9 X-Received: by 2002:a05:6359:220:b0:134:e323:f11d with SMTP id ej32-20020a056359022000b00134e323f11dmr864899rwb.11.1688113615812; Fri, 30 Jun 2023 01:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688113615; cv=none; d=google.com; s=arc-20160816; b=u7gl2rwuCRSh3qNnzrslykfITn4uZonkMMx1QWFYrxMmBYAOTw8lw5wOc0sPmvwovk 38zGJOSvgMGZP4RvBbX9spULxFWJLUz+zJ2ivsGM+fAwCf+6W9OhVmyrUDw7zpZr8L9/ ZG4I55+eveEMqP2fnVQ1pgTY6Ff3VfZ8nR8NUTtKnnde4Svqoa8O1ppUXlpEehvPNC1L 9geTpauoktl8KDhyZR7mQDcvxtEbxwQW8E8iKyTB+GVGQObEccvbINCXo5Xln5G0hHEI E0i3QVkTLQsWFoXB0Ysglhq4tPOKp6scQ4hav/DPIkQ4pSXFfhsvxXnEdZkdCezPd7zY OZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=0ADLQ1uHYsWCRbPuxWBaK3TMiUkd20j4aRHvrs6iNHs=; fh=PevGh9ELH6uE3bIH8Tkdytiseb0v4HKc2x6LW3/Z19A=; b=i+Jn7kfXQVnyW5XznpZIsi9v2VOjJqWnU8ht7ghCAS+GJcYceEmxsuX8ALsC/B8ryE m7MxWzxr+s7M7SLfzXaguLYap2dE1VmZ5wDPctpwYPXBT5Ou7a0i0XzdvO072bo3y4RE AB2UD8WoYI4bSUC6j4j1qGMaNkI5SnzaQD5ZNLbZ2wZc9BSUfWr1++as6Y7mS6DFsWZm UauD+1/F4Yu5W57JAHExn/4ra2rCNo2kG7S6UzQHgz/srubcXmQk00qFO/YjyPbNQ7a8 /RCdbsm0nLsdmpmgUha1atW+voprcK/ysb8XX2e7sG3cIsm4Z5+lNK38E+WESPYuanz9 3aug== ARC-Authentication-Results: i=1; mx.google.com; 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 c34-20020a634e22000000b00547a1922957si12072304pgb.407.2023.06.30.01.26.18; Fri, 30 Jun 2023 01:26:55 -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; 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 S232410AbjF3IQ4 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 30 Jun 2023 04:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230158AbjF3IQy (ORCPT ); Fri, 30 Jun 2023 04:16:54 -0400 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D56F1FCD; Fri, 30 Jun 2023 01:16:52 -0700 (PDT) Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-98273ae42d0so44974766b.0; Fri, 30 Jun 2023 01:16:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688113011; x=1690705011; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lfxbwdpeMQQvTv31Oc0SVR3lIYY6m47WR3xIKyZ9hIw=; b=cV4rvpaQSJY6zb+kuZYYrOQWkPmNRDnjih616XOInM3L5I9ZL9x6s7hCaac/Vy9BuK 9GfaCtiELyn5itKgQqqpka+nmZN35W68NC1YQKdAEOqfYwz9ysKpxrJ0w1Fm0CGHdlna bMBHGKSgr+ZcQJsIwXlF/KsMXQ0BMjQ0Oo3n1z6Ps+F4sGkE+pzaFX6vSbJua+ZMtF99 erm3ceM/hLnavqa1XuAQoAYKnA37+su7I2xIeiEoBZVdOW6cV+KTRU2+zqwQnkTRhQ9w KuAEVpl9iQzA6PLSRn3QrXVcRQfSAzVE0eR63wUQan2fpPZYZGFZAA9FFaN5CoT54Cnq 36yw== X-Gm-Message-State: ABy/qLZBZwyozK2yhIU45CFnEMSRoX+sFrW0Vy69fM2U/arMbyVlXjfB FV0GHU31oS6PxJxDY0bDVgOlIP9gntPJNtsnGXo= X-Received: by 2002:a17:906:ccc3:b0:98e:46f:3eab with SMTP id ot3-20020a170906ccc300b0098e046f3eabmr1362190ejb.6.1688113010602; Fri, 30 Jun 2023 01:16:50 -0700 (PDT) MIME-Version: 1.0 References: <20230607003721.834038-1-evalenti@kernel.org> <7616fd9d-aa0d-2ecd-8751-894b1c9073c0@linaro.org> <75eba2da-593f-f3bd-4eac-5155fcf5aee8@linaro.org> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 30 Jun 2023 10:16:38 +0200 Message-ID: Subject: Re: [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs To: Eduardo Valentin Cc: "Rafael J. Wysocki" , Daniel Lezcano , eduval@amazon.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria , Zhang Rui Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 28, 2023 at 11:10 PM Eduardo Valentin wrote: > > On Fri, Jun 23, 2023 at 07:31:43PM +0200, Rafael J. Wysocki wrote: > > [cut] > > > > Regardless of where the problem is etc, if my understanding of the > > patch is correct, it is proposing to change the behavior of a > > well-known sysfs interface in a way that is likely to be incompatible > > with at least some of its users. This is an obvious no-go in kernel > > development and I would expect you to be well aware of it. > > yeah I get it. > > > > > IOW, if you want the cached value to be returned, a new interface (eg. > > a new sysfs attribute) is needed. > > Yeah, I am fine with either a new sysfs entry to return the cached value, > or a new sysfs entry to change the behavior of the existing /temp, as I > mentioned before, either way works for me, if changing the existing one > is too intrusive. > > > > > And I think that the use case is not really i2c sensors in general, > > I2C was just the factual example I had, but you are right, the use case > is not isolated to I2C sensor. Rather, to be clear I am not blaming I2C, > the actual issue just happen to be easier to see when I2C devices, slower > than typical MMIO devices, are being used as input for the control. > > > because at least in some cases they work just fine AFAICS, but a > > platform with a control loop running in the kernel that depends on > > sensor reads carried out at a specific, approximately constant, rate > > that can be disturbed by user space checking the sensor temperature > > via sysfs at "wrong" times. If at the same time the user space > > program in question doesn't care about the most recent values reported > > by the sensor, it may very well use the values cached by the in-kernel > > control loop. > > That is right, the balance between supporting user space reads and > running the control timely is the actual original concern. The problem > fades out a bit when you have device reads in the us / ns time scale > and control update is in 100s of ms. But becomes more apparent on slower > devices, when reads are in ms and policy update is in the 100s ms, that is > why the I2C case was quoted. But nothing wrong with I2C, or supporting > I2C on the thermal subsystem as we do today via the hwmon interface REGISTER_TZ, > the problem is on having to support the control in kernel and a read in > userspace that can create jitter to the control. > > And as you properly stated, for this use case, the userspace does not care > about the most recent value of the device, so that is why the change > proposes to give cached values. > > On the flip side though, there may be user space based policies that > require the most recent device value. But in this case, the expectation > is to disable the in kernel policy and switch the thermal zone to > mode == disabled. And that is also why this patch will go the path > to request the most recent device value when the /temp sysfs entry > is read and the mode is disabled. > > I would suggest to have an addition sysfs entry that sets the > thermal zone into cached mode or not, let's say for the sake of the > discussion, we call it 'cached_values', with default to 'not cached'. > This way, we could support: > > a) Default, current situation, where all reads in /temp are always backed up > with an actual device .get_temp(). Nothing changes here, keeps reading > under /temp, and so long system designer is satisfied with jittering, > no need to change anything. > > b) When one has control in kernel, and frequent userspace reads on /temp > but system designer wants to protect the control in kernel to avoid jittering. > Just keep reading from /temp but set the new sysfs property 'cached_values' to 'cached'. > Then userspace will get updated values as frequent as the kernel control has > and the kernel control will not be disturbed by frequent device reads. > > c) When one has control in userspace, and wants to have the most frequent > device read. Here, one can simply disable the in kernel control by > setting the 'mode' sysfs entry to 'disabled', and making sure the new sysfs property is set > to 'not cached'. Well in fact, the way I thought this originally in this patch > was to simply always read the device when /temp is read is 'mode' is 'disabled'. > > I believe you proposed to have another sysfs entry sysfs entry for reading cached temperature. > Something like 'temp_cached'. Thinking of it, as I mentioned before, it will work. > The only possible downside is to have two entries to read temperature. > > Strong opinions on any of the above? So what about adding a new zone attribute that can be used to specify the preferred caching time for the temperature? That is, if the time interval between two consecutive updates of the cached temperature value is less than the value of the new attribute, the cached temperature value will be returned by "temp". Otherwise, it will cause the sensor to be read and the value obtained from it will be returned to user space and cached. If the value of the new attribute is 0, everything will work as it does now (which will also need to be the default behavior).