Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3238491rwb; Mon, 7 Aug 2023 10:10:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5AIIyzvFU90wVnxx4k+061zDoVhiK9TwmzmtescneOTOwvVFpU8IBt8IlS+hbou65pTb0 X-Received: by 2002:a17:90a:1f4d:b0:263:f7ce:335e with SMTP id y13-20020a17090a1f4d00b00263f7ce335emr7662792pjy.43.1691428226627; Mon, 07 Aug 2023 10:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691428226; cv=none; d=google.com; s=arc-20160816; b=bLYVL2T2peca2mGk+dVkkA9DTf1h6c7SvfVkjIVdJputajLqbnDmOH158nUgRQ81lM AUk2DyRVm6dUkdwSsV6UBpRHSGmilWJ5TE67bPyVHV4jodl8aXN4+n7QXy+hmu3ecZrT 150Yz72K0+Wa8dqEhN4CbjVBzqX5NU1Czb0gHYAbu2hG2z9ibBrM0apPQJFRzZo3OkA7 ffh3GLleyN+6RKpd3JDm8HqkK9juiUQBbmTA7klr5cHVwCi14MlwPYYDtAflhuVd7V49 FTL7PtCxsi7EApxdhDoJGcaTAgIsso/B3XO75wl0zZzn6MGfk2ve/nuOS5idHzvvwPpS HlzA== 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=qxotLa6DvDG2l+YiJ/bokw4nq+pDW1v+BHlEFGI6H7c=; fh=8q6AS0ILVkE3nBTlvognVwbJ6bMmGRlYE3N5H/OivPE=; b=I8LjtunF7w/YppF9MkC8ta3uSi3GmKiduoRdMGO5XsfjONlZ5mLD/gLlGc9sL6AcJ7 woIdeQTWSWfyvgzhOaVoxDF8rMvs7xoqjIJHu224TEcBWurs61EZ6yVxoKaafSArAloE YDY6hqLZr0Ea+uL24odXOnLQczXAwwr38PwER9boiTvkGB8VkakRsVKSWLkeXiPx/py+ 4vxhCMIbaYZN97cTbaxd1+fOFialiwbbOKn4gAl3WUJMSp8hMf9bUYM2LCtUCaBUDrTX JsaVbvJOP13tA8uxbRMjrk8MiOSxPZxV3ulFHc10X80L81owivHBrqSiXaJxvTsKcF4G xdFQ== 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 a13-20020a17090aa50d00b002675d988010si2879415pjq.91.2023.08.07.10.10.13; Mon, 07 Aug 2023 10:10:26 -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 S231491AbjHGQXv convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Aug 2023 12:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjHGQXt (ORCPT ); Mon, 7 Aug 2023 12:23:49 -0400 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B421998; Mon, 7 Aug 2023 09:23:18 -0700 (PDT) Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-56d279a4d5cso930601eaf.1; Mon, 07 Aug 2023 09:23:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691425395; x=1692030195; 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=pixDtAKy9Cw9KBr/6zRS3zidTud25upCpNKC+6ucwwo=; b=bockYbKMgM2lI8LWSQ9MjvWY6pAvnM9ckGwbWSKW3tdLjHo5jSVdtisww40hiYYZlb 07LpJMV/hPVJ/ah/ZdiptXEWjr1FDHnxMmRu8HBCbtyNOORuWC5AYOmNofWjxmFdKp3T PtdIBwHR9YgoeCtxkRBSAKrb1dwAxvOzEB21FJ3iUf8qoTi8B5eNWJyYRm/OIbzEDf5h CmUx54CkC+owIqi6v2NJke7IYHVgPxZ+ZM0oSo+taeeBF3A99kA8mn7zDPRj8LFI6MaI Dz+5MaOTc9k97E1VRfLTxkD2A+UhYBu1f0cqwQTOLva46q8Lx+qv86wDqVS7itOB13ku FWsw== X-Gm-Message-State: ABy/qLZ7G2Y9WNbFjOJ8IAiVhrTXnsxQLESDvNkv8Oo5tz8LHqIa3yso 0WSy1cYcY5+fnV8KG1RkSWHRWeZm1kNuW3kJ3pI= X-Received: by 2002:a4a:e251:0:b0:566:951e:140c with SMTP id c17-20020a4ae251000000b00566951e140cmr17567127oot.1.1691425395557; Mon, 07 Aug 2023 09:23:15 -0700 (PDT) MIME-Version: 1.0 References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@kreacher> <1967710.PYKUYFuaPT@kreacher> <4bfabfce-574b-ed52-2956-d0d2b9502e60@linaro.org> In-Reply-To: <4bfabfce-574b-ed52-2956-d0d2b9502e60@linaro.org> From: "Rafael J. Wysocki" Date: Mon, 7 Aug 2023 18:23:04 +0200 Message-ID: Subject: Re: [PATCH v4 04/10] thermal: core: Add thermal_zone_update_trip_temp() helper routine To: Daniel Lezcano Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Linux ACPI , LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada 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_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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 Mon, Aug 7, 2023 at 6:17 PM Daniel Lezcano wrote: > > On 07/08/2023 17:40, Rafael J. Wysocki wrote: > > On Mon, Aug 7, 2023 at 1:34 PM Daniel Lezcano wrote: > >> > >> On 04/08/2023 23:05, Rafael J. Wysocki wrote: > >>> From: Rafael J. Wysocki > >>> > >>> Introduce a helper routine called thermal_zone_update_trip_temp() that > >>> can be used to update a trip point's temperature with the help of a > >>> pointer to local data associated with that trip point provided by > >>> the thermal driver that created it. > >>> > >>> Signed-off-by: Rafael J. Wysocki > >>> --- > >>> > >>> New patch in v4. > >>> > >>> --- > >>> drivers/thermal/thermal_trip.c | 37 +++++++++++++++++++++++++++++++++++++ > >>> include/linux/thermal.h | 4 ++++ > >>> 2 files changed, 41 insertions(+) > >>> > >>> Index: linux-pm/drivers/thermal/thermal_trip.c > >>> =================================================================== > >>> --- linux-pm.orig/drivers/thermal/thermal_trip.c > >>> +++ linux-pm/drivers/thermal/thermal_trip.c > >>> @@ -180,3 +180,40 @@ int thermal_zone_set_trip(struct thermal > >>> > >>> return 0; > >>> } > >>> + > >>> +/** > >>> + * thermal_zone_update_trip_temp - Update the trip point temperature. > >>> + * @tz: Thermal zone. > >>> + * @trip_priv: Trip tag. > >>> + * @temp: New trip temperature. > >>> + * > >>> + * This only works for thermal zones using trip tables and its caller must > >>> + * ensure that the zone lock is held before using it. > >>> + * > >>> + * @trip_priv is expected to be the value that has been stored by the driver > >>> + * in the struct thermal_trip representing the trip point in question, so it > >>> + * can be matched against the value of the priv field in that structure. > >>> + * > >>> + * If @trip_priv does not match any trip point in the trip table of @tz, > >>> + * nothing happens. > >>> + */ > >>> +void thermal_zone_update_trip_temp(struct thermal_zone_device *tz, > >>> + void *trip_priv, int temperature) > >>> +{ > >>> + int i; > >>> + > >>> + lockdep_assert_held(&tz->lock); > >>> + > >>> + if (!tz->trips || !trip_priv) > >>> + return; > >>> + > >>> + for (i = 0; i < tz->num_trips; i++) { > >>> + struct thermal_trip *trip = &tz->trips[i]; > >>> + > >>> + if (trip->priv == trip_priv) { > >>> + trip->temperature = temperature; > >>> + return; > >>> + } > >>> + } > >>> +} > >>> +EXPORT_SYMBOL_GPL(thermal_zone_update_trip_temp); > >> > >> This function would imply the comparator is always trip->priv but if we > >> want another comparison eg. trip->priv->id, that won't be possible. > >> > >> Actually, I think you can reuse an existing function with a simple > >> change, for_each_thermal_trip() located in thermal_core.h. > > > > for_each_thermal_trip() is only defined in tools/lib/thermal/thermal.c > > AFAICS, but this one could actually work, so I can copy that > > definition to somewhere else. > > > > But I suppose that you mean __for_each_thermal_trip() which won't > > work, because it makes a copy of the trip and passes that to the > > callback, but the callback would need to update the temperature of the > > original trip. > > > > It would work if it passed the original trip to the caller, so I can > > add something like that. > > As there is no user of this function yet, I think you can change that to > use the trip array instead of the __thermal_zone_get_trip(). This one > was used to have a compatibility with thermal zones using get_trip_* ops > but that is not really needed and with your series only one driver will > remain before dropping these ops. Sounds good. > >> The changes would be renaming it without the '__' prefix and moving it > >> in include/linux/thermal.h. > >> > >> Then the comparison function and the temperature change can be an ACPI > >> driver specific callback passed as parameter to for_each_thermal_zone > > > > I guess you mean for_each_thermal_trip(). > > Yes, __for_each_thermal_trip() OK