From patchwork Thu May 26 11:51:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 576405 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 7F173C433EF for ; Thu, 26 May 2022 11:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbiEZLvd (ORCPT ); Thu, 26 May 2022 07:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbiEZLvb (ORCPT ); Thu, 26 May 2022 07:51:31 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE379D0280 for ; Thu, 26 May 2022 04:51:30 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id f21so1514178pfa.3 for ; Thu, 26 May 2022 04:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b6k3SV/2S1GAZa9ElYwCPu3QFpy6+7ouZdodLYF77Eg=; b=legUHLb2Ee0bshJ1QbJG8LcjSMIqtKRbixMePTPiZEcUDPkkQFN267HpCA1jFH2J7i rGS0iYDVjK1GC0GvSFOiqQLKen+vc+VtZ8EOXdLo/qPxcFmymLIexh6kgJumiN7mYFj+ J6rKWsicVRH3v9GpAakUPk4AfDJntjsKM5FLceeHrpnToV+987nv/FzLNy3S4+K3FZ2F rUV23pJ0j80ZpHT6uoNmAWM4IrQSfpzcR66leo/NeCjGXGFkvm28a/h8bynAShdfBsGL 45+k1NsfTemXBUIlqh9sUL4pzdUAroSSOqM4749wgnNV1SQRFxgG6KXvm19oZ0GjzMsN f4xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b6k3SV/2S1GAZa9ElYwCPu3QFpy6+7ouZdodLYF77Eg=; b=Pdj9pjrWxAR53ZDFdUVZwe/LEOhoNcymEtpjyaqJ3fdTvJ8bF5iCtDvrjUadF9x4fX B9F/nvqDh/CZUlgKM6A+XVF347PNyI0HHnvQ47zLjBbqiMgu11bm5KETtTUFpSBMuKRb 41fZKCCkQpFs3Tp9/q1VFBmQk916uWSYdvzqDb4B+43EhD+TX53+/1qLSQ8ROEebSBOe A2dlEjdN0ECVFtVL0OWQRTNhVU3qIHO+H9HeizyG9sGFt+fY7HKQsFydX4eNYo4uckIm ARHY91Ln5rtqFKy/Vc7pgrRlTXet/EK5prSXIoxjxP7gOvq2MmoDTj/ohD18mDvB/RiZ X7Yg== X-Gm-Message-State: AOAM533g3zVQoF7MUF9NANnQycL1Ljo2OobFsgndF26jq9w05HcLjsUX +EIi3AFG7y15k3y3jvaASqSMAw== X-Google-Smtp-Source: ABdhPJwZOiTJevyRe6XAQM2vVij0hiPhs8czMbGSWZxAAmYgERefN9RdPvVJGaeJvUfNt/FVir8xcA== X-Received: by 2002:a63:5cb:0:b0:3f6:3a45:a479 with SMTP id 194-20020a6305cb000000b003f63a45a479mr31263406pgf.242.1653565890428; Thu, 26 May 2022 04:51:30 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ab8700b0015e8d4eb272sm1295713plr.188.2022.05.26.04.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:51:30 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] cpufreq: Optimize cpufreq_show_cpus() Date: Thu, 26 May 2022 17:21:19 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Instead of specially adding a space for each CPU, except the first one, lets add space for each of them and remove it at the end. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2cad42774164..e24aa5d4bca5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -843,12 +843,14 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf) unsigned int cpu; for_each_cpu(cpu, mask) { - if (i) - i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); - i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); + i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); if (i >= (PAGE_SIZE - 5)) break; } + + /* Remove the extra space at the end */ + i--; + i += sprintf(&buf[i], "\n"); return i; } From patchwork Thu May 26 11:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 576404 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 D532DC433F5 for ; Thu, 26 May 2022 11:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbiEZLvk (ORCPT ); Thu, 26 May 2022 07:51:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238901AbiEZLvh (ORCPT ); Thu, 26 May 2022 07:51:37 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849F9D0280 for ; Thu, 26 May 2022 04:51:36 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id b135so1479051pfb.12 for ; Thu, 26 May 2022 04:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SuD+IeYmhbuPPKbQaLeWJifIw5WrOViKtE4MNYTGhEc=; b=MJJd8mcwXvIYK+3ZoefV3P1LDFLFmU/DxrSHxJ8Vka7Kv6sxUV8BnlK+0vXwRxHixY tNBrQt9GXuWP8kXRPSHXCv6ojYuE8EV0NU05t4AK2TH0Xj/6/zPOR9OfDlX/5uP5ANB2 RmtnwdCPsKZAPGd0uY8O+QTFOYriS/QSf+0EUW2rAxuJzYcRx+DmKDSXggFk4puyrJ+s JHcylp38zsVwVlNXaARQe6evH15qH0AkCuKcBLyFVlw1oowL4MePCxaxQIoC1NbcNeRd aZUNGKNpirsCqabwjXStlm53jUOOI0DTTtG8Ewl9YaUlHMXCyGXE9T6i3en2Vufvac4w 4KjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SuD+IeYmhbuPPKbQaLeWJifIw5WrOViKtE4MNYTGhEc=; b=pjHvuZWn+cd/GM7CByM8HpdKygHOaVf3AhMIAr+D3T46eMEbvCVJZ1pFpUw3o4Qo0X gYiWqdaC1UoqzXPeb1D+sHAi7miWknGHsfVXHGc4miTVfEyiZS7j0m1z7+/au2SxAprQ 5xQLBkFAFSWOqaLBxc5hDJKH994FRGn7PV7U3+bDypVY9nnMPix5fYlRWAyEpnYCFKTt Z/Lpf2YlLRuJUbqwDUM8tCjb07O29S0757F/zl3XI+GjxP7UwHl57v4Ptq2j/iZ9wxsV AZ//ivsUpvxTRtvQfJGx9WbAMqaMkvRb02Yqa9Wxn1y8YovtDRSeDh9796g9H00qecNk P4Ag== X-Gm-Message-State: AOAM5327Z5PRx98iBQQzAoyc8w8mjo3dMPooSydu569us0z90o0UOEME W25KNLBrNS4qeSCQwHUDxGYzBw== X-Google-Smtp-Source: ABdhPJy+86/Oq5RBDJQwemDyFUTj+4rVrb8/nToo3syC1YcNDL0LwghNJ1zctJtPfY9rpOGF2aVx1g== X-Received: by 2002:a63:8ac1:0:b0:3fa:d86b:c76d with SMTP id y184-20020a638ac1000000b003fad86bc76dmr7334098pgd.418.1653565895674; Thu, 26 May 2022 04:51:35 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id b11-20020aa7810b000000b0050dc762814bsm1317345pfi.37.2022.05.26.04.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:51:35 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] cpufreq: Drop unnecessary cpus locking from store() Date: Thu, 26 May 2022 17:21:21 +0530 Message-Id: <0a6620ff5a330126b21d00244d4fad62cff4f230.1653565641.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This change was introduced long back by: commit 4f750c930822 ("cpufreq: Synchronize the cpufreq store_*() routines with CPU hotplug") Since then, both cpufreq and hotplug core have been reworked and have much better locking in place. The race mentioned in commit 4f750c930822 isn't possible anymore. Drop the unnecessary locking. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 53d163a84e06..bb237d1ce5e7 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -973,21 +973,10 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, if (!fattr->store) return -EIO; - /* - * cpus_read_trylock() is used here to work around a circular lock - * dependency problem with respect to the cpufreq_register_driver(). - */ - if (!cpus_read_trylock()) - return -EBUSY; - - if (cpu_online(policy->cpu)) { - down_write(&policy->rwsem); - if (likely(!policy_is_inactive(policy))) - ret = fattr->store(policy, buf, count); - up_write(&policy->rwsem); - } - - cpus_read_unlock(); + down_write(&policy->rwsem); + if (likely(!policy_is_inactive(policy))) + ret = fattr->store(policy, buf, count); + up_write(&policy->rwsem); return ret; }