Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3455534pxv; Mon, 12 Jul 2021 18:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFe5y/qXmM1W4ltNXX7z9OMs1MsmNlTMG/shr+NwOC88LB6zhxlO+tLVjG1S+z89LYDbYm X-Received: by 2002:a05:6402:13c6:: with SMTP id a6mr2120204edx.213.1626139194684; Mon, 12 Jul 2021 18:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626139194; cv=none; d=google.com; s=arc-20160816; b=Za+/mIltk+WeTArksxYmHEVCWoYsZFn8UDoOy/VA3cR09BtKY405HqLlT9KEi09Esm HFfyQ+kK3n7/mq3a5D3QyGfBX9mV5syeFKPnMNdDAwt3Jr0xiRPFsfD/VvG1y6JgZM/T 6isL8ln8QyziQQyToqsu0/vwrL1SKdYxHfexcyjz0u/M/PFoH/hhZ+JoMGOuQAvmFxXJ 6DHPSteDxqgTBTTGrZAhSYddM11CBiXjH0v3uwtY6xWffNj8S9x2LMm1dAgrBy5g+8B7 ADdHs6/D6sTH2hku+pv/bEfMp86d9euYYQUL36VoyxY74khiocGuoDH/ZkVNyj4J5Klo cxjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=DrmYRl9BF9d3iatBQwzwYcnmOf/PKMScaARgXZNfTEg=; b=N6AWbwofQukySUUVNEcOXVT+0+SEO3QpwLm2zbHUVwZBkpX7vWB+0QN9ym/T90FLYy aBjpPmrLePf5yuZ1P/Yh9nN6h0E6mb/qo5HLIWaPhVkB6UHlBnuP8jgVG/amrwbG01yC 0jpruEiyDqINGICR1sO20EMgf6jkcuKdS2AIow01bij/z0v9I7lEmR+I8FtnYWkESzdx 7moMSWsBemMy+Ruvg8q5W+pl/Ag+6wyrii1NGhjNxvSqIMAIkx/2UME2OvVNiBuTRYDd RRxUx93iOmtJ3CQl0KWLH19P+6UrwINH8FqyuiuGnA+UkSyu4b76y7E93x/aIkNa2caw i9Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BGg4Y9yf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f16si20080245edy.166.2021.07.12.18.19.28; Mon, 12 Jul 2021 18:19:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BGg4Y9yf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233688AbhGMBVS (ORCPT + 99 others); Mon, 12 Jul 2021 21:21:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233015AbhGMBVR (ORCPT ); Mon, 12 Jul 2021 21:21:17 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1731C0613EE for ; Mon, 12 Jul 2021 18:18:27 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id j184so19991513qkd.6 for ; Mon, 12 Jul 2021 18:18:27 -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=DrmYRl9BF9d3iatBQwzwYcnmOf/PKMScaARgXZNfTEg=; b=BGg4Y9yfZ8aO0n2dQiUMFe4/T8Pzu7P6FwAuotW9PRRRRA3P2VAZvrYEcSlkT6F2au n68NRdiMxM/jwElgMufLj9V+Dw+oWi/aCGQXBHARGxpOdxWqYuz5Q6CmPokbM9RLqyKu qvQ6xkmBQDrcMh+EZ31nzPTNQqX+yKQdyN8GO1i6fdpcOZLX01Wz8eWcg0wXxP/MXbhe EplA5WRbmY3+lt9947hSi/AwHo7G3N579KeVEkN8XUwjmoXDhnYbtijnngNtKw/iDvEG hncgFXl1nFDUt5KS4NzW3JfGL4gsjfnRWWrY6LZMjeXIG/ubi5QI936WAV483Gsm1Khp CpKg== 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=DrmYRl9BF9d3iatBQwzwYcnmOf/PKMScaARgXZNfTEg=; b=Bf0+G86apY4oe7zeGwg5Fyly2FoGYBee9WK14wW5MGKIkGdZSSVmG6Y9ur1vBxyJy1 l3caGsZ9oA/f1pHIwC/F2iZZes5eF9R+jS9Oxfyd77sUM9ADr0N6wxqYwnmoRSGEXZ8L zAV1vPySKL+qg7TDbqmoX9ezsM/lP/zEFebrrJth5xWbEab5OU1bkpGWxyjQU6XFrOjf 5sxRF7W6PNZrxnRFEEdyOvoM5JT1R0ujYtCI9T9+P5HBITje75u9qYfmC73NZZjCyihp mx8dW0+mp5twtGkIuqifwaJ87hl+/d/esHTVoXw6BK3HeJKftUtNKud1QdcnOk559YJC eqRw== X-Gm-Message-State: AOAM532q0VNAMXHgAJdk3UDmJDTHFUhQvYGiU2mdeQ+w9JyuAhy0voXG 0tzT9L5D20kOyIoSF6WPxUDIHQ== X-Received: by 2002:a05:620a:1a19:: with SMTP id bk25mr1708352qkb.38.1626139106830; Mon, 12 Jul 2021 18:18:26 -0700 (PDT) Received: from [192.168.1.93] (pool-71-163-245-5.washdc.fios.verizon.net. [71.163.245.5]) by smtp.gmail.com with ESMTPSA id f62sm3363273qke.135.2021.07.12.18.18.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jul 2021 18:18:26 -0700 (PDT) Subject: Re: [Patch v3 3/6] cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support To: Viresh Kumar Cc: agross@kernel.org, bjorn.andersson@linaro.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, rjw@rjwysocki.net, robh+dt@kernel.org, tdas@codeaurora.org, mka@chromium.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org References: <20210708120656.663851-1-thara.gopinath@linaro.org> <20210708120656.663851-4-thara.gopinath@linaro.org> <20210709064646.7vjgiba2o7beudly@vireshk-i7> <5a98ef2a-d170-f52d-cc48-b838cddaa5c2@linaro.org> <20210712044112.svhlagrktcfvyj35@vireshk-i7> From: Thara Gopinath Message-ID: Date: Mon, 12 Jul 2021 21:18:25 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210712044112.svhlagrktcfvyj35@vireshk-i7> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/12/21 12:41 AM, Viresh Kumar wrote: > On 09-07-21, 11:37, Thara Gopinath wrote: >> On 7/9/21 2:46 AM, Viresh Kumar wrote: >>>> @@ -389,6 +503,10 @@ static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) >>>> dev_pm_opp_remove_all_dynamic(cpu_dev); >>>> dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); >>>> + if (data->lmh_dcvs_irq > 0) { >>>> + devm_free_irq(cpu_dev, data->lmh_dcvs_irq, data); >>> >>> Why using devm variants here and while requesting the irq ? > > Missed this one ? Yep. I just replied to Bjorn's email on this. I will move to non devm version. > >>> >>>> + cancel_delayed_work_sync(&data->lmh_dcvs_poll_work); >>>> + } >>> >>> Please move this to qcom_cpufreq_hw_lmh_exit() or something. >> >> Ok. >> >>> >>> Now with sequence of disabling interrupt, etc, I see a potential >>> problem. >>> >>> CPU0 CPU1 >>> >>> qcom_cpufreq_hw_cpu_exit() >>> -> devm_free_irq(); >>> qcom_lmh_dcvs_poll() >>> -> qcom_lmh_dcvs_notify() >>> -> enable_irq() >>> >>> -> cancel_delayed_work_sync(); >>> >>> >>> What will happen if enable_irq() gets called after freeing the irq ? >>> Not sure, but it looks like you will hit this then from manage.c: >>> >>> WARN(!desc->irq_data.chip, KERN_ERR "enable_irq before >>> setup/request_irq: irq %u\n", irq)) >>> >>> ? >>> >>> You got a chicken n egg problem :) >> >> Yes indeed! But also it is a very rare chicken and egg problem. >> The scenario here is that the cpus are busy and running load causing a >> thermal overrun and lmh is engaged. At the same time for this issue to be >> hit the cpu is trying to exit/disable cpufreq. > > Yes, it is a very specific case but it needs to be resolved anyway. You don't > want to get this ever :) > >> Calling >> cancel_delayed_work_sync first could solve this issue, right ? >> cancel_delayed_work_sync guarantees the work not to be pending even if >> it requeues itself on return. So once the delayed work is cancelled, the >> interrupts can be safely disabled. Thoughts ? > > I don't think even that would provide such guarantees to you here, as there is > a chance the work gets queued again because of an interrupt that triggers right > after you cancel the work. > > The basic way of solving such issues is that once you cancel something, you need > to guarantee that it doesn't get triggered again, no matter what. > > The problem here I see is with your design itself, both delayed work and irq can > enable each other, so no matter which one you disable first, won't be > sufficient. You need to fix that design somehow. So I really need the interrupt to fire and then the timer to kick in and take up the monitoring. I can think of introducing a variable is_disabled which is updated and read under a spinlock. qcom_cpufreq_hw_cpu_exit can hold the spinlock and set is_disabled to true prior to cancelling the work queue or disabling the interrupt. Before re-enabling the interrupt or re-queuing the work in qcom_lmh_dcvs_notify, is_disabled can be read and checked. But does this problem not exist in target_index , fast_switch etc also ? One cpu can be disabling and the other one can be updating the target right? > -- Warm Regards Thara (She/Her/Hers)