Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp963608iob; Fri, 13 May 2022 17:54:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRWBMx1IW2/A3ReVh/pxQctd3VlNTR7+y4lVxpeBOoUt4iRXngH5dAyF39YXsG05nVltPW X-Received: by 2002:a5d:4649:0:b0:20a:e17e:56de with SMTP id j9-20020a5d4649000000b0020ae17e56demr5885488wrs.450.1652489662766; Fri, 13 May 2022 17:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652489662; cv=none; d=google.com; s=arc-20160816; b=IhyumoGsz0NgKwtWW0iWC4opNJcIe4H+0Sr358YnXR0XbQXuiym1uEDfadJsXdYJpQ H737RERId0ilvQJ5acfCyDOaE7hSHv6iWopsCJ6uS7gYZwPu4Fsp5909SCKEyrVxA3fZ Xouc72y5FxblFKdX/K7xX7nwm3W7s6M8K+DDSdsI4Vac+pe4FZZS/Bf5qP8O2Nn2efBB t+Pv3rCFyub7JslFZLpmGxdC+BmvC2nI6LAeAIMCOtPzU7KCV9FeilyZOZxCB2Qu6VUT M5OPYuaDetqdKJrbEhXRjBhg/K1BdDR6xuwi2PbinTPSsUE2M2aEHoYuH1wMgx4zR/xf qZcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vBhBc4igSr5lkTEDPBacehSjxXJjowFEHzx5Vf8m4fc=; b=d4luf4Q7ovio9olNilzAOPggzY2NaIozWM2srWUatlz0D8zjgafhXxFUgXiUMsthI4 k1eAEXh4t0Zjlgler7m+48wI/oeawVr5gmf1pNnHhmcEbzmcPUY4CaOgXnGgQNOoUwfM m7KP+WH/vvJdWux0SQ5sUgBnXfQCM31TjcDpCc88VURUKmK4TaInlO1CJ71Y+eeCgR7f uHKzXRe9H6K14U09DrIvwUAb+5PRbTSQtzsrQI8rKuEfszWOi+vpQQhNKvUNB4NHNIgT cItvFBXgY0c/4UUkWAWf1ucN7E+hf3ElWeP/pMAh6dPz7AumUUHETlypD0GkJIJ3RzVX crdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Y3HANqTF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l4-20020a5d4104000000b0020c46f9cc94si3133785wrp.793.2022.05.13.17.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:54:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Y3HANqTF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28CC4350708; Fri, 13 May 2022 16:30:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379832AbiEMLQ2 (ORCPT + 99 others); Fri, 13 May 2022 07:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379849AbiEMLQO (ORCPT ); Fri, 13 May 2022 07:16:14 -0400 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E40932497D; Fri, 13 May 2022 04:16:12 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id y63so9721975oia.7; Fri, 13 May 2022 04:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vBhBc4igSr5lkTEDPBacehSjxXJjowFEHzx5Vf8m4fc=; b=Y3HANqTF+N/856tejKBCenQuJ0ulUY/RfjPBUwD3eBBkEHkFnYR8KRQrl1vqY7AJRN dciWsFYxtSoy5Rszs1C9tUXo7kcJUzwMsLHVtoe1bbB2hUlZue4gsvGLSiM7hEVfed/W ZVtEHMXHxmcgk/4el0nRixdpwveu4ab8p5bS+XvfPA5IfNgu8sr+1apNsaHscqwSeGcL /8cnEtTva+LSO7DiSRIriIG8Df5OMbL5lCxA5v3RBat2pEBU4HgCpH6mCFthLyEA8cfg OZamTyZhG/33/L5fBA6Dot3n/t3aa8zSHPsmTrplg8eOrV2ulCcvPR05KO5UT0Kncv1u hlFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vBhBc4igSr5lkTEDPBacehSjxXJjowFEHzx5Vf8m4fc=; b=0e0MaZM3najvv560bDKQH3Q+E4wNzD2HBj3vq8P/lY3y9z+5PgJlbFESGGIxKz/dOR vmOo8+4PV0iK1OpiXCmHlVYCEymLs7cuxGLe5EAp2GuMTS/GVpg5POBtm/Y+O0KDoMQ2 LDk4oxnwoOUP3jsJhqnlQMYnzo7xDHUfhkGdBUrmAT0yYLK4rshVA0acjgMtPymeiVF0 tUkjwgYZzVQmLdVqeMI80Ceh+IHurFlPUWAhoazhhEQOyrWFEkF698ZO40dLCqDs3YC0 +Vrx0qsLwuQWAweCwnKbB5Wi+NfkSiJR3EwOIv1Uvv4L1H+cJFZy24kYhQYRqiGnlug0 h4Vw== X-Gm-Message-State: AOAM533hT5xvr+dbwlrsBb9t8Re54l0EELF24Zqj2nHA1d8eXvPAsw7s eEUMKlp1WSAxmKaJFTIAYjfa2/s6dbblzQRp7oY= X-Received: by 2002:a05:6808:690:b0:325:9655:d782 with SMTP id k16-20020a056808069000b003259655d782mr2197475oig.276.1652440572190; Fri, 13 May 2022 04:16:12 -0700 (PDT) MIME-Version: 1.0 References: <20220512135231.10076-1-schspa@gmail.com> <20220513041833.mcubozfhl2qd2rps@vireshk-i7> <20220513061343.wndyhjeehoqmfofp@vireshk-i7> In-Reply-To: <20220513061343.wndyhjeehoqmfofp@vireshk-i7> From: Schspa Shi Date: Fri, 13 May 2022 19:16:01 +0800 Message-ID: Subject: Re: [PATCH v4 1/2] cpufreq: fix race on cpufreq online To: Viresh Kumar Cc: "Rafael J. Wysocki" , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Viresh Kumar writes: > On 13-05-22, 14:06, Schspa Shi wrote: >> Viresh Kumar writes: >> > On 12-05-22, 21:52, Schspa Shi wrote: >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> >> index 80f535cc8a75..35dffd738580 100644 >> >> --- a/drivers/cpufreq/cpufreq.c >> >> +++ b/drivers/cpufreq/cpufreq.c >> >> @@ -953,7 +953,10 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) >> >> return -EIO; >> >> >> >> down_read(&policy->rwsem); >> >> - ret = fattr->show(policy, buf); >> >> + if (unlikely(policy_is_inactive(policy))) >> >> + ret = -EBUSY; >> >> + else >> >> + ret = fattr->show(policy, buf); >> > >> > I like it the way I have done earlier, initialize ret to -EBUSY and >> > get rid of the else part and call show/store in if itself. Same for >> > below. >> > >> >> I add a unlikely here, to avoid branch prediction failed. > > I am not asking you to drop it, I also added the unlikely within the > implementation of policy_is_inactive() then. It can be written as: > > if (likely(!policy_is_inactive(policy))) > ret = fattr->show(policy, buf); > >> And move the >> to the fail path to avoid a register assignment to -EBUSY. > > We don't care about such assignments for performance to be honest. > This makes the code smaller by few lines, that's enough. OK, I have uploaded a v5 patch for this. Please review it. -- Schspa Shi BRs