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 X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3047C433B4 for ; Tue, 20 Apr 2021 15:24:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA0AE61354 for ; Tue, 20 Apr 2021 15:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232938AbhDTPZL (ORCPT ); Tue, 20 Apr 2021 11:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232836AbhDTPZG (ORCPT ); Tue, 20 Apr 2021 11:25:06 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E89C06138A for ; Tue, 20 Apr 2021 08:24:34 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id w186so15892062wmg.3 for ; Tue, 20 Apr 2021 08:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GFSKpzQJQZPhNu8hc1kWWJ/QfS/c4/ErGH6wh4S9JqQ=; b=c0uSuoro9RcMeNl9/7Sh1xd0t6JoGVZQPMZWB2Y7Kh1sTaYkJiijNfH584cPOdaryd zMTeMDdLgrQyiiaa2R4fYfD03bEN9FcYmtvIt2eIj+YJZvPa0syKLmnGcYectMJUkeTN rIorpbXSw6gFn2h2ww86hFmewVsB96Tac5LfH5g/bNYbb+zN8M4iVyQqu82U17RijPDe KhoKai9cMHQxR+zpiQ1TmX5/zhBcDyJTx5EDAWzHYV2/XWA9B67QqShb4bNduOsXpJXF jO3vSqrpNgnBryyyg9mFz024Za+BuzVQRnH3LjU0yVGou3+3SgoOwKsHQVaO/Kyz0NwK aE4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GFSKpzQJQZPhNu8hc1kWWJ/QfS/c4/ErGH6wh4S9JqQ=; b=EhcjqdNGNNQTzdpwZxeLdFOthg4WkewpgK4V6Duc5f1q8pVDHjhfYWLmHi4HaidYTA J8d1QkIqaF431G0FQ/uPXTxs8j1y6LujKSf5y6ltUA1sHyElwzHktPaoN1o2V4E6YbIK Vy51DZ8VCp93umdhv94kxFAq6f5wy8rzewDVBUYSjJ/DnJnLUa9U9dVG75AIVnHH6h+G CEcb/fPWg9pcskmhCWlTDD2XdBMqZ2lhg7EQrb0VeTwIEDzJBcfgWB4looo585gql2xh BHFnIphjQHUzxm6GXpOL9Kvm33IoIgaCB9tufuXGWUxHSuqb/XJA07iuW1ub3LPr5zSD EKcw== X-Gm-Message-State: AOAM5311nh1qn7g64XZRKsUgoXYuq9t2prx5KJMAlf1zxsR7vairrhTB osnHlI0pTdn1JyFLW1KYbeVJhA== X-Google-Smtp-Source: ABdhPJwHRvUm6Zw5aHm17c2DLLyhHdn2PLZW1y0wMiOT4sTXYwG+4oNwlyCAePBefA8RJiX1DAbHiw== X-Received: by 2002:a05:600c:4f96:: with SMTP id n22mr3560868wmq.117.1618932273101; Tue, 20 Apr 2021 08:24:33 -0700 (PDT) Received: from ?IPv6:2a01:e34:ed2f:f020:a079:f96:da87:2d00? ([2a01:e34:ed2f:f020:a079:f96:da87:2d00]) by smtp.googlemail.com with ESMTPSA id o1sm29459651wrw.95.2021.04.20.08.24.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Apr 2021 08:24:32 -0700 (PDT) Subject: Re: [PATCH v2 2/2] thermal: power_allocator: update once cooling devices when temp is low To: Lukasz Luba Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, amitk@kernel.org, rui.zhang@intel.com References: <20210419084536.25000-1-lukasz.luba@arm.com> <20210419084536.25000-3-lukasz.luba@arm.com> <55943d6f-0f72-215d-1dd4-bf3996092df7@arm.com> From: Daniel Lezcano Message-ID: <91411c9c-d78e-8ba6-1cd3-da6879bc5ceb@linaro.org> Date: Tue, 20 Apr 2021 17:24:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <55943d6f-0f72-215d-1dd4-bf3996092df7@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/04/2021 16:21, Lukasz Luba wrote: > Hi Daniel, > > On 4/20/21 2:30 PM, Daniel Lezcano wrote: >> On 19/04/2021 10:45, Lukasz Luba wrote: > > [snip] > >>> -        instance->cdev->updated = false; >>> +        if (update) >>> +            instance->cdev->updated = false; >>> + >>>           mutex_unlock(&instance->cdev->lock); >>> -        (instance->cdev); >>> + >>> +        if (update) >>> +            thermal_cdev_update(instance->cdev); >> >> This cdev update has something bad IMHO. It is protected by a mutex but >> the 'updated' field is left unprotected before calling >> thermal_cdev_update(). >> >> It is not the fault of this code but how the cooling device are updated >> and how it interacts with the thermal instances. >> >> IMO, part of the core code needs to revisited. > > I agree, but please check my comments below. > >> >> This change tight a bit more the knot. >> >> Would it make sense to you if we create a function eg. >> __thermal_cdev_update() > > I'm not sure if I assume it right that the function would only have the: > list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) > > loop from the thermal_cdev_update(). But if it has only this loop then > it's too little. > >> >> And then we have: >> >> void thermal_cdev_update(struct thermal_cooling_device *cdev) >> { >>          mutex_lock(&cdev->lock); >>          /* cooling device is updated*/ >>          if (cdev->updated) { >>                  mutex_unlock(&cdev->lock); >>                  return; >>          } >> >>     __thermal_cdev_update(cdev); >> >>          thermal_cdev_set_cur_state(cdev, target); > > Here we are actually setting the 'target' state via: > cdev->ops->set_cur_state(cdev, target) > > then we notify, then updating stats. > >> >>          cdev->updated = true; >>          mutex_unlock(&cdev->lock); >>          trace_cdev_update(cdev, target); > > Also this trace is something that I'm using in my tests... Yeah, I noticed right after sending the comments. All that should be moved in the lockless function. So this function becomes: void thermal_cdev_update(struct thermal_cooling_device *cdev) { mutex_lock(&cdev->lock); if (!cdev->updated) { __thermal_cdev_update(cdev); cdev->updated = true; } mutex_unlock(&cdev->lock); dev_dbg(&cdev->device, "set to state %lu\n", target); } We end up with the trace_cdev_update(cdev, target) inside the mutex section but that should be fine. >>          dev_dbg(&cdev->device, "set to state %lu\n", target); >> } >> >> And in this file we do instead: >> >> -        instance->cdev->updated = false; >> +        if (update) >> +            __thermal_cdev_update(instance->cdev); >>            mutex_unlock(&instance->cdev->lock); >> -        thermal_cdev_update(instance->cdev); > > Without the line above, we are not un-throttling the devices. Is it still true with the amended function thermal_cdev_update() ? -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog