Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3982542pxu; Mon, 12 Oct 2020 06:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvtqRHAYLAzQOyRfbQHkfELkFWQDObQHEHc4swrJAoH1rioANnyVhzYIORzoQ2V0v1nJCn X-Received: by 2002:aa7:c7cd:: with SMTP id o13mr14284330eds.114.1602509800786; Mon, 12 Oct 2020 06:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602509800; cv=none; d=google.com; s=arc-20160816; b=tplmHeRVJrwrLUeyvj/0i32aF+Vunf6uTnbKLUhv+o32IVaOsxV+tbjTP5Fpbk0dYz vRzM/eCv2fmlfWsBsJee7BNp5Zl1BFH+DVuU5Z4siivvLnnY1k9JkQkY0VCo+BjYy9Ny zRvI59XmL51rfOPSD5koWZJ9+SfnEV5zfkO5EO4GDiHKek7ZiWUEElR5QPJNA5ptONFb Og2nB0YswUSUhFRQewyEG7AnfqfPi0oUdavBwjdPh72H27mBA6vKd2rns+LkIhbhIdse OE0lN6SBCtNrmEn7mlPZ/qkBhdOLG8eBfxMNjlf9mat6t1XZ4BO/cjbT5RJAYu2veHvq gOtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XlL7umVsvWUu9nC85NmIJJazhDfhIvxS22WEywbwFsQ=; b=WJCL1UcsdtVSHYF1SF948MGJTfeNrMg3HjnQHihVad34MN7xcmMjLcsWfJ+bKfxqt1 c81pUMolI/Qzw2iCODNPbQ/XHX3ELNN+To6Zus9unl6O05elTNgOSodj0ciaNX7m8AT4 79yBdPA8euQuZbsI4FJ9I1CQA+VSNXMJhfGf4IDZrfwaFTCX5uxId0Aa/Ci40aified6 Mq5m1SWRw8G4/Bw7y4EjnWqtNM1N73IgfpQYBLp2h9/YYO8XefDHAzt6bLvFY3bpm3UE 4oBT4SMZiG9Gd+jx1+aJGld6ZPW5e0CldrNq5Rz9lWd/tyEQHiia7bh8OUgAtCJ1I1Na iRtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tmRYrzcg; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pk8si11625485ejb.729.2020.10.12.06.36.17; Mon, 12 Oct 2020 06:36:40 -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=@google.com header.s=20161025 header.b=tmRYrzcg; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729054AbgJLNFI (ORCPT + 99 others); Mon, 12 Oct 2020 09:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgJLNFH (ORCPT ); Mon, 12 Oct 2020 09:05:07 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD63C0613D0 for ; Mon, 12 Oct 2020 06:05:07 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j136so17475746wmj.2 for ; Mon, 12 Oct 2020 06:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XlL7umVsvWUu9nC85NmIJJazhDfhIvxS22WEywbwFsQ=; b=tmRYrzcgKlzAUQKgP5vXL9/uTTj7B/U9f0202gf3G2SLvMnx87gE1KviAzRDfa8QX/ HCwSellky3Y8J5DozzR6KX7VZQOLBD/jORIAj8cGGdvCoZu92TJjNlQj3h8QnZYfX5Ln 44oCi3Ixv0AJbVa7MF/B2Nz21Nf74thJ6GOz8VVyfQ+lbZfAXWPuja//CDmOjR2rqyh3 AqXDj8eHPBmUhTIvnZJB6Qpf3vW5eTEBErBlGKdUUw4V+JwfxBrBInm1KjG5aEvGL22X CPKWlcctVUb9/sZU9oaNzezZKHlwcr36YeIBCZIf1BI7azSCqFVGZJ3SM5LAG7ZX2kte 9EoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XlL7umVsvWUu9nC85NmIJJazhDfhIvxS22WEywbwFsQ=; b=Ie4AMAmeoivjFztpoT532GMSo8h73QqEaxJJMe54BD9laDLdujuxRpTzo0qj2nyXcH kqqW52GFmzAraHCCaqhRcXBGF+vv4eGaiftwJghribkaqpeq+HEaKQGDUPjUM59R+J8J kLMcbSqszQcWKB5kSXazAALoNF+7qXOyKlQGYUxZ8LHRBBIP++BIpMst39WWJX4vGThn 2qdF0FtT7OUUBU6w78vunASccp/OGOLNjEUuimm8v2yhO9z2+9t7Cr5AEqUNMIoZWgtx g7q/EBD91NeJSXyqfM7fPU4Yc+4XBAGglNPwpmV5SLs7YMAyiY9Nj+UArFM3WwBB6M56 gBrg== X-Gm-Message-State: AOAM531TSUQmkrZ7AiyATZhblZsXICBjhcSov1uZDhslFPdVSBdpMFxn XXAnHyVgCQ+KsmIhIHfFHfoqlQ== X-Received: by 2002:a1c:1b15:: with SMTP id b21mr11006430wmb.143.1602507905993; Mon, 12 Oct 2020 06:05:05 -0700 (PDT) Received: from google.com ([2a00:79e0:d:110:f693:9fff:fef4:a7ef]) by smtp.gmail.com with ESMTPSA id 64sm4434430wmd.3.2020.10.12.06.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 06:05:05 -0700 (PDT) Date: Mon, 12 Oct 2020 14:05:01 +0100 From: Quentin Perret To: zhuguangqing83@gmail.com Cc: lukasz.luba@arm.com, quentin.perret@arm.com, rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, zhuguangqing Subject: Re: [PATCH] PM / EM: consult something about cpumask in em_dev_register_perf_domain Message-ID: <20201012130501.GA3366383@google.com> References: <20201012124136.4147-1-zhuguangqing83@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201012124136.4147-1-zhuguangqing83@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Monday 12 Oct 2020 at 20:41:36 (+0800), zhuguangqing83@gmail.com wrote: > From: zhuguangqing > > Hi, Lukasz, Quentin > I have three questions to consult about cpumask in energy_model.c. OK, let's see if we can help :) > 1, The first one is about the meanings of the following two parameters, > [1] and [2]. > [1]: "cpumask_t *cpus" in function em_dev_register_perf_domain(): Pointer > to cpumask_t, which in case of a CPU device is obligatory. It can be taken > from i.e. 'policy->cpus'. > [2]: "unsigned long cpus[]" in struct em_perf_domain: Cpumask covering the > CPUs of the domain. It's here for performance reasons to avoid potential > cache misses during energy calculations in the scheduler and simplifies > allocating/freeing that memory region. > > From the current code, we see [2] is copied from [1]. But from comments, > accorinding to my understanding, [2] and [1] have different meanings. > [1] can be taken from i.e. 'policy->cpus', according to the comment in the > defination of struct cpufreq_policy, it means Online CPUs only. Actually, > 'policy->cpus' is not always Online CPUs. > [2] means each_possible_cpus in the same domain, including phycical > hotplug cpus(just possible), logically hotplug cpus(just present) and > online cpus. > > > So, the first question is, what are the meanings of [1] and [2]? > I guess maybe there are the following 4 possible choices. > A), for_each_possible_cpu in the same domain, maybe phycical hotplug > B), for_each_present_cpu in the same domain, maybe logically hotplug > C), for_each_online_cpu in the same domain, online > D), others So, if the comments are confusing we should update them, but from the EM framework perspective, all cpumasks must be the _possible_ CPUs in the domain. It's up to the clients (e.g. the scheduler) to deal with hotplug and so on, but the EM framework should cover non-online CPUs too. > 2, The second question is about the function em_dev_register_perf_domain(). > If multiple clients register the same performance domain with different > *dev or *cpus, how should we handle? > > int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, > struct em_data_callback *cb, cpumask_t *cpus) > > For example, say cpu0 and cpu1 are in the same performance domain, > cpu0 is registered first. As part of the init process, > em_dev_register_perf_domain() is called, then *dev = cpu0_dev, > *cpus = 01b(cpu1 is initially offline). It creates a em_pd for cpu0_dev. > After a while, cpu1 is online, em_dev_register_perf_domain() is called > again as part of init process for cpu1, then *dev =cpu1_dev, > *cpus = 11b(cpu1 is online). In this case, for the current code, > cpu1_dev can not get its em_pd. As per the above, the registration should be done once, with the mask of all possible CPUs in the domain. If CPUs 0 and 1 share the same domain, a single call to em_dev_register_perf_domain() should be sufficient to register both of them at once. > 3, The third question is, how can we ensure cpu_dev as follows is not > NULL? If we can't ensure that, maybe we should add a check before using > it. > /kernel/power/energy_model.c > 174) static int em_create_pd(struct device *dev, int nr_states, > 175) struct em_data_callback *cb, cpumask_t *cpus) > 176) { > 199) if (_is_cpu_device(dev)) > 200) for_each_cpu(cpu, cpus) { > 201) cpu_dev = get_cpu_device(cpu); > 202) cpu_dev->em_pd = pd; > 203) } And that should not be necessary as we check for the !dev case at the top of em_dev_register_perf_domain(). Or were you thinking about something else? Thanks, Quentin