Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3173385rwb; Mon, 7 Aug 2023 09:14:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkvWMZ6HdbrTON+MeTPZi10SFjzUjuLgg7c2lkieB3BVuBkV5kAfbz5l1mZiEu7NirCBLx X-Received: by 2002:a2e:93c3:0:b0:2b6:d9da:3d7e with SMTP id p3-20020a2e93c3000000b002b6d9da3d7emr6732504ljh.45.1691424868123; Mon, 07 Aug 2023 09:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691424868; cv=none; d=google.com; s=arc-20160816; b=wGVKLUwvkcD087C3ISlMNO29DuMLzEclsg8XHGeu+BNfdd7AxGPDX0TjPp7mBdm1LS HsLcNdhJBzODonlzy7akvyP3Rll9KrsI/aY/AHlx5IlWvMWX5pcClnWtvn0QI73WuR2+ BXpJytm9Al7eg6vZzIXqoZ0OXXT71wS/tCtQCqWHy2mLEuYezN1b7m6yv1sDceqEx4Em yJWmL/h52/szSN6kUasBqePAN2D+3LgWrzRUGmioKl87SU6nOI4GVqOJ+9riHF3ttFJQ 1bGuGCJuvbmC+i67oLroG8F4BrPAarJ60j90bsJhacsAmImp9fBjwy5kimILvuvItHSs P9nQ== 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=DTykvPZ5FRHDCwmR6b9Ylb8LGqmhzyI8PXmtzv54WuI=; fh=FQ/w6k7Qz6bMR8FOPJiFU9M7OR2iCyejlVLyqUye3Pc=; b=ko4riibEE4KwJ4uspXyJ9KaYpr56MsYrC3gmnv+wE/edGYUzAV7966bSxUDL633CX9 u0bhffS20xNlpeDVV/U/f6i4YSCFEws8DhPOiphHCtLkZS4XrzAwzgXZKrlLIZEotryz kLi8KKPcKSA7NZUTsfx/luBMveW4TlXKuHRrgIrW9aoCaqFOYBi2Pq4y1x3TKZYnxql2 b6AabdY3LF99s0FvETukOw06gyN1QNCtWsYDVADXll5Whs7o+n3qYFwHUKU2kTd5gS3s I5frJAckesHME1L5iTYyuBWj/7DyHGPhSO4vxUZd5hojAw0CVpSTiXFNdnUEPhfb6XNP z9Tw== 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 y9-20020a1709063a8900b00992d262ff61si3004674ejd.989.2023.08.07.09.14.03; Mon, 07 Aug 2023 09:14:28 -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 S230489AbjHGPkz convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Aug 2023 11:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjHGPkx (ORCPT ); Mon, 7 Aug 2023 11:40:53 -0400 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020A910E0; Mon, 7 Aug 2023 08:40:48 -0700 (PDT) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-56d0deeca09so720923eaf.0; Mon, 07 Aug 2023 08:40:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691422847; x=1692027647; 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=eW5ByB1kCbWvE4LvHZxA6DmVsnS3SGc4dZRlcaVebhA=; b=h8Toi/fXYwLqeg9ioVQ0qkDqA9uLBEH831CW6xRz99r3791bRiumXWFM20c13JSfZP X1BkL/13sOTbcN5AkBcZaG2qFwV6CiF7KiuCiR/OvYhSkYvxHh1Nc1FvUsQ+AlhoIgrZ xApZKl2dlRlha/WozzqlPeRAouuxnVC02pnWzcVqFoqOQZKo00jSI90WghBJBn3W37dr h474GmLXaUIWR2SPPO/muncGPsAlVFEQv2ENyAmhdyZ1gIS4B29XF+7VTcVDcjQZPoFL hyP8Nq/cJekpOYZEbVHLm4Mc4srLZnzMuYHrF/5rQb8c7O9A2CYH1q8zzKofASn4Ifke swww== X-Gm-Message-State: ABy/qLYGhebjEfCToWMC1VrEfWDqwerhtQPuWr4HQUv8jKiBBL0m+d0y 8X35CbqzU2CZ6FUIvVAI+Bds8Fq1h52WzKMN1O3X9XgrZt0= X-Received: by 2002:a4a:a585:0:b0:56c:484a:923d with SMTP id d5-20020a4aa585000000b0056c484a923dmr21423816oom.1.1691422847098; Mon, 07 Aug 2023 08:40:47 -0700 (PDT) MIME-Version: 1.0 References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@kreacher> <1967710.PYKUYFuaPT@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 7 Aug 2023 17:40:36 +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" , 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 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. > 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(). As per the above, not really, but I can do something along these lines.