Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp968930iob; Fri, 13 May 2022 18:04:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRC/5/ECGxQBdpeeBAJ0ow47SlFkQIaochd+NXfOynzxc4Z5aA4b7YnsLj9yhAeMNAlfHX X-Received: by 2002:a05:600c:1d9f:b0:394:7a51:cb8b with SMTP id p31-20020a05600c1d9f00b003947a51cb8bmr6814654wms.163.1652490246003; Fri, 13 May 2022 18:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652490245; cv=none; d=google.com; s=arc-20160816; b=BZqhYg2Oo7famz2I63YFmmtbYFg6t6LACy1csr+wjw9BJR8D09OPPUblE8vyApZyUW 86LVg/0GgwpAL9ikmp+CQOIdMxY55pu1A5sFubOxD4FvhrZMumB0/zW4o816s4KMyfmZ ulLUN1bOlqsmfgQkIqrKVa0fdoRIQOqwGnChnBOA5w90vZMVuOrGbXIqmwCnsu11Z/Lf AeuhQLzE4qz2zjz9cmkRU/SgYULWECYy12ZcRzn75p8k9ljM5gaZkN+6m/S7MAG0hS7v TrKBsKhCJ7sez9bAoseHfrkyARMtuz/1NnEdpe24JSSCPHCh2JAkd/czeMKF5HiTrKY9 NODA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kUZ2JsyK3ZUZK31g+pozQdNwm9zwv4kOdXsDjmRgytw=; b=GnNawgZgOnGPnxozt8SX7FxsVzrWisqjRGmDC603x5ISAJblRK6QfAhNjBsoc+UmX6 wlQbvgPG4JANScIrfkoW0Am7hVJWTeQpidQW99vhqHVctsafwwunTKIwaR2CeJ2TRkLh F3srnux/E2azXiYjBBz2We3KA579vRYXe8mI2mNNLtFsyMBb8A54+A3OOMgW2/x2ZmoN velIYMTacrtRYZlQe42b/yfV7Fwh3YiJJ5T0xFWs5eoxyIXdx9YtoAqQ5ewSEIlWj25Z 1ZVeqi7eF86UVI2OUSSXeh2zoE72aoG2YRB0cpRtEXn4ntGYdr6qe544vfP4DOycQm8b bDmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b/B7oTts"; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n15-20020a5d660f000000b0020c6a37e16dsi3191642wru.286.2022.05.13.18.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:04:05 -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=@linaro.org header.s=google header.b="b/B7oTts"; 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=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D070D375C00; Fri, 13 May 2022 16:37:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350008AbiEMGNx (ORCPT + 99 others); Fri, 13 May 2022 02:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350874AbiEMGNt (ORCPT ); Fri, 13 May 2022 02:13:49 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBD3826CC7D for ; Thu, 12 May 2022 23:13:46 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id l20-20020a17090a409400b001dd2a9d555bso6930792pjg.0 for ; Thu, 12 May 2022 23:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=kUZ2JsyK3ZUZK31g+pozQdNwm9zwv4kOdXsDjmRgytw=; b=b/B7oTtsYLzf9v+BgX7A5Op62ccI59r0/Gjhdo9XmmKLpZcCFvpRLYh0T1diKGFssq +D1oFMpGEgS3dedSc1hx7m+97/PBP5klDt+XFKkZOa+SOzIrkbz1GdHO++9ofGkrxJ8X OBDyJBz9lVt6T0PwBvZcESLXtdeww0QiyN1QSBOVKTRVdoug+uWnUXaqBTcI+SLZlGxW d/wFh1WGoXM3hXFZh7/R2JE+MWVpg8YQJxBo/MMDlZxsxswQtP3iucxs3+7+Pc7+G1bj VpvgDRFalC1lZluL98subl2H3sTFs2PpA4Lk0apLT2FNL5FZHn4AE6GtfzHwPMSkRun1 p1Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kUZ2JsyK3ZUZK31g+pozQdNwm9zwv4kOdXsDjmRgytw=; b=C1hWLyrHx0gTMUcMtvHsdtt1Upbd0hrZF0CzrAuEq9wupubSEVAIGuDDKzuHDkfiCo jmV++TIYV7zQzFgHAb4i8J63zICK9ydXcoF/P5HqllsllUrtEjEdaE1Vk1QDKnzMKITT nHt0d4SZf0E48l+kAD6IbPdAMK4K79W+BHSrErjOqCFlI9bQGzoin7EWef99/SNCigfa wIpt7cbM+J0RLBzU2SwIU+J41saw/8VGwVjMDKO+0jf4pzra4RH7cHaOKLZc+bhdk8pp T4hrHit9Xk4YRd14B8RIf+8q7RxfhpjHtk77681WNJT5PAaH10QarMSDw9vyHDTju0Bv rHdA== X-Gm-Message-State: AOAM532zNECOwlx9kJSnQ+ABn8LL5BPVI4Yy12PjRfX9bxTM4p6aCVFs IGwLer83PYVS1hX7/g6z0CQWzw== X-Received: by 2002:a17:90a:e517:b0:1d7:5bbd:f9f0 with SMTP id t23-20020a17090ae51700b001d75bbdf9f0mr3233860pjy.77.1652422426455; Thu, 12 May 2022 23:13:46 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id u11-20020a17090341cb00b0015e8d4eb219sm941603ple.99.2022.05.12.23.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 23:13:45 -0700 (PDT) Date: Fri, 13 May 2022 11:43:43 +0530 From: Viresh Kumar To: Schspa Shi Cc: "Rafael J. Wysocki" , Linux PM , Linux Kernel Mailing List Subject: Re: [PATCH v4 1/2] cpufreq: fix race on cpufreq online Message-ID: <20220513061343.wndyhjeehoqmfofp@vireshk-i7> References: <20220512135231.10076-1-schspa@gmail.com> <20220513041833.mcubozfhl2qd2rps@vireshk-i7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 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. -- viresh