Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5614925pxv; Wed, 28 Jul 2021 15:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcFIdPoT+CHWjh0OewtNPJ5IN2NH2cAUVmzlEzEQw4QIQknl/5b6Va8a1B8Ekvdl2cKWzV X-Received: by 2002:a5e:8208:: with SMTP id l8mr1338792iom.197.1627510821666; Wed, 28 Jul 2021 15:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627510821; cv=none; d=google.com; s=arc-20160816; b=J5cjqg/TMedA0Q143YQY1V5Ll5Ki3O/alc2xr85jy9o0UQBQ71CMaJO1iLhjXFPHNl t8tlg33vQ2ai8OtahKqqBZ/HTDwMWBFNQbAJRHjFk503K3IEzCR3ntiRlAHOqb2KKq4U Cm2DbjVzt90eN0u4js+te4A1Y650Kw3ourCx6an/moIadSNmuxiso8+67pkmPyrGrr2u mYAyabLUvxaf316Rt1z9VEMqeR4wmi42kJZHp7cD8WHoDBL8yZ/P+LfaH584imECaHJi 9tRWkwBPduIJX+LXZaQ5wVnbIZY5prKo5uEjDrTSyh2wAUf5RJtuKATLpBCm3S07uOM5 VX6Q== 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=Srjf0aL7kHAVVp8xOjNVibfUf0NYqsilKH/clpF6XdM=; b=ZfHs0KnFBzT0AvLn3b1P35Kw+srmLVamWWEMspKenE7MZpY7CUvkq3VKPJ2Y13Q8LI qBlvQcHnXcLdnTI5Xj6yFRQ71nLWBdfcg66tK3kQpL1+M52b3OOkQwOSA4Ivqo5wFOYZ BSsY6pbS3riaox/o75KIT4QmzWDDKVqq7T3+pQjWCYH4qGzulLAkcPWoyIyjfaQ1Qqhy 60BssoGRyAnmNJXa0ncUY4GQa2Wnh8nAn0j1reQwvCJLh2RGeeQDmQTvAAZjUmkP8aMi Mfr23xhK3M+HgNlldtRR4n6ohzvzhFCdlDz//JRsFGIarnbKPM4EZUrdbYWPgdevlvod EgKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UsieRyKW; 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 k14si1243146ion.22.2021.07.28.15.20.09; Wed, 28 Jul 2021 15:20:21 -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=UsieRyKW; 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 S231989AbhG1WTM (ORCPT + 99 others); Wed, 28 Jul 2021 18:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbhG1WTK (ORCPT ); Wed, 28 Jul 2021 18:19:10 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5906C061757 for ; Wed, 28 Jul 2021 15:19:07 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id 190so3845552qkk.12 for ; Wed, 28 Jul 2021 15:19:07 -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=Srjf0aL7kHAVVp8xOjNVibfUf0NYqsilKH/clpF6XdM=; b=UsieRyKWGPZS8uLn0zEzD+tYsGMx8iEd2JshbEJ87il9BCsUc5DGd5DDnzaJaJviAF hG6b6fha0xukyKUjebYyRg0RrxT9FsdMzUMZ9jSObEtjydk98dW1tmfkegE6nX7XN4ry Tyv+nRIS+dO8htCj8kgMgdYm0tPiOxAUYo3Dmb9mK7Zp+roGAoZ6rT5MxxklKcrMcoqG E1KUkTurjqjl1U8Yi31iYwNM31HsnJ9UU/Zi/l9TBxNsp6w+GoyhGcXa0qk5uC/hKALu MY8jcdHO5aIbEAiWNOGVUxUE973rDiVItbVoT64OVo2sgpl9ErORVX5OYIlRVahnA7qQ TPHQ== 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=Srjf0aL7kHAVVp8xOjNVibfUf0NYqsilKH/clpF6XdM=; b=FNBlPBgQNH3j+M/lR/Gn+IY6fZ/eU8lOQDLv9Dd+bn0NyZiwsrCfNfTLRVfAAvBkKI Fh8UODSuIF5qPBLkOmPtgfengH6eG/ES+y/1L1AJJHlIhUyI/DegRwW8nbXkV1nEIXaK wtGcWp0eNXqhj7R3FZOu//WR8WLe4LRCg3WJP24+oSzZ3nLDDhpeE8LxgKphJ2eDoHjp MNsWryjnrlgLMXT0eV65zin4vzX4+446PdmjVyg11ETWaIkxEfPOgHW7oss768CgLRyA cakquGzK+BKAeDhjFb/xmk7zDKCBJ4nJ2W547wa4aSSHYZvIVroLR5RkqzFkeJfKgVsZ YUIA== X-Gm-Message-State: AOAM530QqTOJ3+I/7qoFgRg7Vk33zi1Y+zaQ06aZQE9/ihYkOvOztLw8 kQMBs575LySJtZGdh1Djm1b0DA== X-Received: by 2002:a37:a004:: with SMTP id j4mr1950099qke.499.1627510746886; Wed, 28 Jul 2021 15:19:06 -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 n188sm745065qke.54.2021.07.28.15.19.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Jul 2021 15:19:06 -0700 (PDT) Subject: Re: [Patch v4 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, steev@kali.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org References: <20210727152512.1098329-1-thara.gopinath@linaro.org> <20210727152512.1098329-4-thara.gopinath@linaro.org> <20210728035014.25mgvrpnraxfslq7@vireshk-i7> From: Thara Gopinath Message-ID: <9a257605-d282-cd06-cc44-5ad5a5f8484d@linaro.org> Date: Wed, 28 Jul 2021 18:19:05 -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: <20210728035014.25mgvrpnraxfslq7@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/27/21 11:50 PM, Viresh Kumar wrote: > On 27-07-21, 11:25, Thara Gopinath wrote: >> +static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data) >> +{ > >> + /* In the unlikely case cpufreq is de-registered do not enable polling or h/w interrupt */ >> + >> + spin_lock(&data->throttle_lock); >> + if (data->cancel_throttle) { >> + spin_unlock(&data->throttle_lock); >> + return; >> + } >> + spin_unlock(&data->throttle_lock); >> + >> + /* >> + * If h/w throttled frequency is higher than what cpufreq has requested for, stop >> + * polling and switch back to interrupt mechanism >> + */ >> + >> + if (throttled_freq >= qcom_cpufreq_hw_get(cpumask_first(policy->cpus))) >> + /* Clear the existing interrupts and enable it back */ >> + enable_irq(data->throttle_irq); >> + else >> + mod_delayed_work(system_highpri_wq, &data->throttle_work, >> + msecs_to_jiffies(10)); >> +} > >> +static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data) >> +{ >> + if (data->throttle_irq <= 0) >> + return; >> + >> + spin_lock(&data->throttle_lock); >> + data->cancel_throttle = true; >> + spin_unlock(&data->throttle_lock); >> + cancel_delayed_work_sync(&data->throttle_work); >> + free_irq(data->throttle_irq, data); >> +} > > Lets see if we can still make it break :) > > CPU0 CPU1 > > qcom_lmh_dcvs_notify() qcom_cpufreq_hw_lmh_exit() > > spin_unlock() > spin_lock(), > cancel_throttle = true > spin_unlock() > > cancel_delayed_work_sync() > mod_delayed_work() > free_irq() > kfree(data) > qcom_lmh_dcvs_poll() > Uses data. > > > Sorry, locking is fun :) Ha! I was too lazy to write this down! So how about I make this a mutex and put mod_delayed_work() inside the lock. So it will be something like below qcom_lmh_dcvs_notify() qcom_cpufreq_hw_lmh_exit() mutex_lock() mutex_lock() if (data->cancel_throttle) { cancel_throttle = true mutex_unlock() mutex_unlock() return cancel_delayed_work_sync() } free_irq() enable_irq() / mod_delayed_work() mutex_unlock() I will let you break it! > -- Warm Regards Thara (She/Her/Hers)