Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2905908rdb; Tue, 12 Sep 2023 16:30:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoMESySyxRANt33P0w7Nt1wAdbBrGicSlLS/8kU/IBg34eKeZz7V3yNE6GwP4wphzLAJb5 X-Received: by 2002:a05:6870:d5a6:b0:1b3:8cfd:fecf with SMTP id u38-20020a056870d5a600b001b38cfdfecfmr898018oao.0.1694561416943; Tue, 12 Sep 2023 16:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694561416; cv=none; d=google.com; s=arc-20160816; b=neMvUBsQ8UkWg1Kb4zxKOSGwVfMC0N30jt47OeZIFP/IhpozVD5BRO9pbR8TsuHZYb JFzVBvn212H8BEDYjy7GVlHpgCRHLdCCfe/NJp8TyWmKWA21rM4EWI9UsQ8CudOVcz/b 8U3Hc5sRVCx90QPKq9d2aSJp3k9GI2sBTlQFVVJHkb+vGjMeVTny4x7vgcyP5aFf5/3u VSXlqVwFDmYaeXhcTkz++KdEljabGDnrT4X35DAsmy++/uTAHWyrqB+K46gB89fbwNxI pzq4DEJw3q1kw6g5T+LGuZqdFxyXfrHZ4A9kLmvu2Aqw/u93yCB9xLfH4KIGpNoNapM5 ikwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+IkmhIoAmzyqAjdSiTgMfX4/vBTRmE0t9jxT50CvoxI=; fh=0vaYOzzn3Z5SQEjgoqvxffIotvjIeDSv5QGTvx6cK/U=; b=BAFWk/jyMXNtTgnJ16UJ7HvgEfvJ0cfPVLWrPviSAe0oYoLLpPshaI/rzw6C/A8zdX hLKInVLYF2Sr4Z5r0nqFTd9A/5uHYhbZ/vJrjSfRdhlfpRHX/cJMVtjC2hkDFqMVQJJg PJdnifbBbsokjdwCRr/xpf13qg++Ze3v5PCxVe8fLtx333ozaoVNeRfZXCca3ygowUR1 GV79M9TSlAtLK8hgqCYoF5xgKYf6mpHfKjrC4xSf3oIcOTISstfPeckQK7HX60jVJddV IDFHOGZQr9k7XKQPqQeHUplavqP7Y7uhLJdur9kdsO5dzj+vvi+fYtzcWe3Gmyd/020J Gj3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d64-20020a633643000000b0057764b2f3dfsi5181529pga.198.2023.09.12.16.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 16:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 45F1682EBE4F; Mon, 11 Sep 2023 23:13:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjILGNW (ORCPT + 99 others); Tue, 12 Sep 2023 02:13:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjILGNU (ORCPT ); Tue, 12 Sep 2023 02:13:20 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285EBE77; Mon, 11 Sep 2023 23:13:16 -0700 (PDT) Received: from kwepemd200002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RlCq00hj0zMlJ0; Tue, 12 Sep 2023 14:09:48 +0800 (CST) Received: from huawei.com (10.67.174.28) by kwepemd200002.china.huawei.com (7.221.188.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 12 Sep 2023 14:13:14 +0800 From: Liao Chang To: , CC: , Subject: [PATCH 2/2] cpufreq: userspace: Move is_managed indicator into per-policy structure Date: Tue, 12 Sep 2023 06:10:57 +0000 Message-ID: <20230912061057.2516963-2-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912061057.2516963-1-liaochang1@huawei.com> References: <20230912061057.2516963-1-liaochang1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.28] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd200002.china.huawei.com (7.221.188.186) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Sep 2023 23:13:23 -0700 (PDT) The userspace governor use the 'cpu' field of cpufreq_policy structure to track if it is allowed to set the speed of policy. However, there is a window where the 'cpu' field is equal to the value of nr_cpus_id when all affected CPUs of policy are offline, which is an illegal value to get the per-CPU variable. To avoid this issue, this patch uses a per-policy indicator to track if the policy is managed. Signed-off-by: Liao Chang --- drivers/cpufreq/cpufreq_userspace.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c index 442e31060d62..2c42fee76daa 100644 --- a/drivers/cpufreq/cpufreq_userspace.c +++ b/drivers/cpufreq/cpufreq_userspace.c @@ -15,9 +15,8 @@ #include #include -static DEFINE_PER_CPU(unsigned int, cpu_is_managed); - struct userspace_policy { + unsigned int is_managed; unsigned int setspeed; struct mutex mutex; }; @@ -37,7 +36,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) pr_debug("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); mutex_lock(&userspace->mutex); - if (!per_cpu(cpu_is_managed, policy->cpu)) + if (!userspace->is_managed) goto err; userspace->setspeed = freq; @@ -85,7 +84,7 @@ static int cpufreq_userspace_policy_start(struct cpufreq_policy *policy) pr_debug("started managing cpu %u\n", policy->cpu); mutex_lock(&userspace->mutex); - per_cpu(cpu_is_managed, policy->cpu) = 1; + userspace->is_managed = 1; userspace->setspeed = policy->cur; mutex_unlock(&userspace->mutex); return 0; @@ -98,7 +97,7 @@ static void cpufreq_userspace_policy_stop(struct cpufreq_policy *policy) pr_debug("managing cpu %u stopped\n", policy->cpu); mutex_lock(&userspace->mutex); - per_cpu(cpu_is_managed, policy->cpu) = 0; + userspace->is_managed = 0; userspace->setspeed = 0; mutex_unlock(&userspace->mutex); } -- 2.34.1