Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3455921pxb; Mon, 4 Apr 2022 17:32:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvRUOng9KDl2CCEZOFH0iAupOEfhzBPpOHdDcmeweg0C+nEOp7NIqyahxU06fQQLfcREI9 X-Received: by 2002:a17:90a:ce8b:b0:1c7:7567:9f7e with SMTP id g11-20020a17090ace8b00b001c775679f7emr1065377pju.10.1649118776145; Mon, 04 Apr 2022 17:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649118776; cv=none; d=google.com; s=arc-20160816; b=fcMd198OsZJ2d1vXxVnAMLcEpOGJQf6yqVLrLkOJ/TMfJJ6AzEYuL8A1mwoYge7j5q QZ+ytySZcM7Kp7gy0XnoRXwV1Ej0hqAR1xJ/S2SA2t5dV1Tx0uEJhzaBEXIMuhADUdSn FuDeUMMgixRuhseo4h1pX/UomPbmm68ZlxtxWrHUCXwVrHuAqnedUUMkOrjeMkGDLN74 OQqy5kgughvsIE+rlLArq38VL+ER8mBVNIwxe4dPkSEdB3F0RFZQyTjklc/ZduEkM8Xp P3sCSCzchFpn7bq14bzd+004wuOfK6EpKBw0kk5WghRbY7BZyVQCu2+ymr5hp5tS5n2z kkNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=UUhwBAwCiYtCMRaGLcsjzco2ISSTGQb0zfCSnAeRr/M=; b=SJyM41J8+QTDJ2wRLHR+h18WKPUCCDNosNHnsrv7iftcSnm4NOsARWrlrXxU5yMYj9 UmnOGXCQhw04MxBEnR4tCrcbzXsTkd4JOIg6gk0nTVjQUuN9+6l6UfenwMltxV5Ns8O2 /Kmzia39TjiYN7gQTFuS9kbv0h1utQXp3K7yNRRb6cLVQ778kCwFghxGJq7Jmzpappqt 9HYLPxzrBFvbRa9dawfgaVo+mUKro2owO2tI3Ft4wFipZlbDp3+0G1yYpFRr1ZxgRH1t J3EFHEn1apjiHx05xUYqk5ALUZLg8zeZLKqQ5WoqOMkgYY2/OZk6QZEtohjZ6eIf+9Eq 5PPg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w17-20020a63d751000000b00393c60e611esi10421018pgi.861.2022.04.04.17.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:32:56 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 32CDE84ED0; Mon, 4 Apr 2022 16:51:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380888AbiDDVWK (ORCPT + 99 others); Mon, 4 Apr 2022 17:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379166AbiDDQiD (ORCPT ); Mon, 4 Apr 2022 12:38:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 626472C11C for ; Mon, 4 Apr 2022 09:36:07 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 293D41480; Mon, 4 Apr 2022 09:36:07 -0700 (PDT) Received: from [10.57.24.6] (unknown [10.57.24.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F6D93F73B; Mon, 4 Apr 2022 09:36:04 -0700 (PDT) Message-ID: <30d85009-f4be-25b1-7eb8-eea4b3058e27@arm.com> Date: Mon, 4 Apr 2022 17:36:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v3 21/21] x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes Content-Language: en-US To: Rob Herring Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, Jamie Iles , D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com References: <20220217182110.7176-1-james.morse@arm.com> <20220217182110.7176-22-james.morse@arm.com> From: James Morse In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Hi Rob, On 3/23/22 21:17, Rob Herring wrote: > On Thu, Feb 17, 2022 at 06:21:10PM +0000, James Morse wrote: >> resctrl_arch_rmid_read() returns a value in chunks, as read from the >> hardware. This needs scaling to bytes by mon_scale, as provided by >> the architecture code. >> >> Now that resctrl_arch_rmid_read() performs the overflow and corrections >> itself, it may as well return a value in bytes directly. This allows >> the accesses to the architecture specific 'hw' structure to be removed. >> >> Move the mon_scale conversion into resctrl_arch_rmid_read(). >> mbm_bw_count() is updated to calculate bandwidth from bytes. >> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c >> index 3a6555f49720..437e7db77f93 100644 >> --- a/arch/x86/kernel/cpu/resctrl/monitor.c >> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c >> @@ -211,10 +211,11 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, >> if (am) { >> am->chunks += mbm_overflow_count(am->prev_msr, msr_val, >> hw_res->mbm_width); >> - *val = get_corrected_mbm_count(rmid, am->chunks); >> + chunks = get_corrected_mbm_count(rmid, am->chunks); >> + *val = chunks * hw_res->mon_scale; > > This can be moved out of the if/else if you make the following change: > >> am->prev_msr = msr_val; >> } else { >> - *val = msr_val; >> + *val = msr_val * hw_res->mon_scale; > > chunks = msr_val; > >> } Sure, I guess it makes sense to only set *val in one place. >> >> return 0; >> @@ -400,15 +397,14 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) >> */ >> static void mbm_bw_count(u32 rmid, struct rmid_read *rr) >> { >> - struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r); >> struct mbm_state *m = &rr->d->mbm_local[rmid]; >> - u64 cur_bw, chunks, cur_chunks; >> + u64 cur_bw, bytes, cur_bytes; >> >> - cur_chunks = rr->val; >> - chunks = cur_chunks - m->prev_bw_chunks; >> - m->prev_bw_chunks = cur_chunks; >> + cur_bytes = rr->val; >> + bytes = cur_bytes - m->prev_bw_bytes; >> + m->prev_bw_bytes = cur_bytes; >> >> - cur_bw = (chunks * hw_res->mon_scale) >> 20; >> + cur_bw = bytes >> 20; > > 'bytes / SZ_1M' would be more readable and any decent compiler should > optimize a power of 2 divide. But maybe that's a separate change as > there are other cases of bytes to MB. I agree its more readable. As I've touched this one, I'll change it. Thanks, James