From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2460C004D4 for ; Thu, 19 Jan 2023 10:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbjASKZr (ORCPT ); Thu, 19 Jan 2023 05:25:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbjASKZj (ORCPT ); Thu, 19 Jan 2023 05:25:39 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17C694DE20 for ; Thu, 19 Jan 2023 02:25:34 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id r30so1357647wrr.10 for ; Thu, 19 Jan 2023 02:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eZPsqFx3N2mmetQ9IPUz/o5Ei0eo+cmPrq1DjOstt2U=; b=MJWEQ5YxvQO/KtG8yraOUX4CV9Y94kp3bly+P+taebUCUPTqA0FTLAry7ndjC4Jcds IdpXITWz5/oqJM4/9/4q1ign137txyKrOaBVi0V6Rt5v7sPuuFStqGlcDJWhzd4mKQKN VoWoppK5uodLiYc974plSupqfQv9Rm3le1E95l71rZ3SW+ddppk6Rn1keyY5l6eK5/7k Ak9je9NrfgzPego6uUFZM09G5FXG2pyXBw4ehu0ElKXA8zAQF4ma981HCuza3wyDorF0 Q+PUWxYc/Seo7nnxPoiRAbH7kB4YqmKmo6J5DByveueUQGcTcYwmgEATQarpfrvCVaha 4Fwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eZPsqFx3N2mmetQ9IPUz/o5Ei0eo+cmPrq1DjOstt2U=; b=NlAfLbQDHSk9+bkLjFZcPrlDpPm0IaYtQ3K8DLAtow3L/B/3QD9+ythiY9ryhNcVTl w+NnmoOdeYw91/fxTodMaUZt/NsI6OmUE3JW8CPWYD4NEMJNKZ7mJIBm+HBFwBcGE4UB CtA1V3Odoz28NWSWLQkXKFtOSNJ/zumWtGnzjxI3Yym+oLpCkalKgnvhBIQXCdshl0Fi hCVl5gcHoZ9LdkgO8hXm9ef0+aDX81M1MO5H3c8OkQql72ovwemglttM6fOaAaZg2ctD NVmQUbfEKIV1FufRLNx/T8C8vL4ZnBuN+XZxdHqJZdZ0uIvP9Hm8qdHZ2hNQkZ/jxUot f1Rw== X-Gm-Message-State: AFqh2kq4cTrdUbDrgI6nX/0e7nKmkR4tkMDLq9fdlOS4QaQGi15WFOuo k0ISHlA+bIQNWkXNNyiWWFwiKQ== X-Google-Smtp-Source: AMrXdXtzkD23ITweixx6i2fklGVpeNFgVYzuFJhdqSjGlRzgFPKyYkDuQ9kwqM141fy6sRseX/gLkw== X-Received: by 2002:a5d:5e85:0:b0:2b6:2eb3:82a1 with SMTP id ck5-20020a5d5e85000000b002b62eb382a1mr5497731wrb.67.1674123932401; Thu, 19 Jan 2023 02:25:32 -0800 (PST) Received: from [192.168.10.46] (146725694.box.freepro.com. [130.180.211.218]) by smtp.googlemail.com with ESMTPSA id r11-20020adff70b000000b002bdf290efdasm10768285wrp.58.2023.01.19.02.25.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Jan 2023 02:25:32 -0800 (PST) Message-ID: Date: Thu, 19 Jan 2023 11:25:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH 5/5] thermal/core: Sort the trip points when registering a thermal zone Content-Language: en-US To: "Zhang, Rui" , "rafael@kernel.org" Cc: "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "amitk@kernel.org" References: <20230118211123.111493-1-daniel.lezcano@linaro.org> <20230118211123.111493-5-daniel.lezcano@linaro.org> From: Daniel Lezcano In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Hi Rui, On 19/01/2023 08:22, Zhang, Rui wrote: > On Wed, 2023-01-18 at 22:11 +0100, Daniel Lezcano wrote: [ ... ] >> +int thermal_trip_sort(struct thermal_trip *trips, int num_trips) >> +{ >> + struct thermal_trip tt; >> + int sorted = 0; >> + int i, j; >> + >> + for (i = 0; i < num_trips; i++) { >> + >> + for (j = i + 1; j < num_trips; j++) { >> + >> + if (trips[i].temperature < >> trips[j].temperature) { >> + tt = trips[i]; >> + trips[i] = trips[j]; >> + trips[j] = tt; >> + sorted++; >> + } >> + } >> + } >> + >> + return sorted; >> +} >> + > When this happens, the index(trip_id) of each trip is changed, but we > pass the new trip_id to .get_trip_temp()/.set_trip_temp() callbacks. If we pass the thermal trips to the thermal_zone_device_register_with_trips(), .get_trip_temp, .get_trip_hyst and .get_trip_type are not used. .set_trip_temp is called from sysfs, where the trip_id is read from the file name. This trip_id will be correct in this case, as the files are created after sorting the array. > This will confuse the drivers and update the wrong trips, right? No, because at the moment we use the generic trip structure, it is handled by the thermal framework. The drivers do not have to deal with the trip id or assuming its value given a trip point after registering the thermal zone. If it does, we should fix the driver as the trip_id is a framework internal value. The trip_id is just an index to be passed around, so whatever the value, it should point to the right trip point. For instance, the device tree describes the trip point and they could be in any order, all the DT based drivers are agnostic of the trip_id. If there is an update of the trip points, we read the trip points definition again and do an update of all of them. > IMO, we need a map between thermal core trips and unsorted driver > trips. That what I proposed several months ago but we concluded that would another extra level of complexity. So we decided to replace all the .get_trip_* by a generic trip point structure handled by the thermal framework itself. Hopefully, soon we will have all .get_trip* gone with a nice cleanup of the drivers and the core framework. -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog