Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp797164pxb; Tue, 3 Nov 2020 12:48:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJypju9x6XHzMs1yaJeOI/wTSKUH5YDK0X1raJM2v1GE8Tn0fJ1MxNNuOtRaBR+pXorc9Vsd X-Received: by 2002:a50:decd:: with SMTP id d13mr24005177edl.202.1604436511350; Tue, 03 Nov 2020 12:48:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604436511; cv=none; d=google.com; s=arc-20160816; b=HvKOX+qG6p/e0wdHLa0M+5MI/20soZJVi16u3X/PnY9N2Labu5Ldm87u4DsxtQd76r ej1RbP7orRqZaggs5h6bIgRHCrz7mAK9GNqD+A1mVkLHmNiQIzB+LLz1ABATksa9yX8+ xY9RXDMhpgq4UB/mgEN4XKNE9P8kT3/OqQPMx4QzAureJwikIDLyb4jKg+Dt89uPhnTh bYZcGuUVjFVijUKfp2mpkEGRObB2HIlzZjrjONuYglKlGAjyhwKfKFIGHRgpqtOAYfao yzx2Y1G348Jx7ageZqC/e/Z9UeplD7KksieNk3hN6Lp4Knl/S9HbunstFK6HBCB1esKp P8cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J728OJOhzSuw4Dttq6GJzzwf1BvO1yAGozF5EfAn9TY=; b=jbUWH3dm0udTTqmLd2pu2l6jRhVtlcTJ2GU7Xh2EaI61fm3Tk/ZermGQdOuTdehUE/ sxbaCp2iBGElfesE7H3CAu/AwNWUu42HTer3d2/rmqj3zdlYwN6NBchbpUc2cr4lPciE dD66nhEC7QodTCGUH5NXIjmLfj63jmHPVYaX8mxJvM8XmO4oEEDy5eQmuSJhfWGPoLo/ rtxT9jXJAsPXk/ltbIRn6Ku/+SHP+FHwiIslSoxXa2mFX/jR8tVe5xO8n5WdPvH3Q2ST 44c/euXOl5aVHrbTEUFn4BijJBFG8d6O7FsdZoON/G47icGE5QhwKOoyTvWWWRhCS+po Xbrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tjo1AgUB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co16si14060367edb.465.2020.11.03.12.48.08; Tue, 03 Nov 2020 12:48:31 -0800 (PST) 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=@kernel.org header.s=default header.b=tjo1AgUB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730687AbgKCUpJ (ORCPT + 99 others); Tue, 3 Nov 2020 15:45:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:32904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730119AbgKCUpG (ORCPT ); Tue, 3 Nov 2020 15:45:06 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 23FB3223EA; Tue, 3 Nov 2020 20:45:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436305; bh=faAbGekZaLAx+dyHkLrwgc6LUIqjVnWuO2oB2Wkbh1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tjo1AgUBOY1U9utImtxzIRsA+ruBURgCYhWt0bghp69ncBQjuYS7QREwb4bg5El/x LJNhn/Piw/7Ew511hkJGmyiCVSO1tuFICkwDZeNa7ZgRGXRak2p/eddoE1kvO3CHN+ cwMP3BbyuTbUrIgEw02EVXnjieMYVExYbUJu734c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kim Phillips , "Peter Zijlstra (Intel)" Subject: [PATCH 5.9 193/391] perf/amd/uncore: Set all slices and threads to restore perf stat -a behaviour Date: Tue, 3 Nov 2020 21:34:04 +0100 Message-Id: <20201103203359.913983956@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kim Phillips commit c8fe99d0701fec9fb849ec880a86bc5592530496 upstream. Commit 2f217d58a8a0 ("perf/x86/amd/uncore: Set the thread mask for F17h L3 PMCs") inadvertently changed the uncore driver's behaviour wrt perf tool invocations with or without a CPU list, specified with -C / --cpu=. Change the behaviour of the driver to assume the former all-cpu (-a) case, which is the more commonly desired default. This fixes '-a -A' invocations without explicit cpu lists (-C) to not count L3 events only on behalf of the first thread of the first core in the L3 domain. BEFORE: Activity performed by the first thread of the last core (CPU#43) in CPU#40's L3 domain is not reported by CPU#40: sudo perf stat -a -A -e l3_request_g1.caching_l3_cache_accesses taskset -c 43 perf bench mem memcpy -s 32mb -l 100 -f default ... CPU36 21,835 l3_request_g1.caching_l3_cache_accesses CPU40 87,066 l3_request_g1.caching_l3_cache_accesses CPU44 17,360 l3_request_g1.caching_l3_cache_accesses ... AFTER: The L3 domain activity is now reported by CPU#40: sudo perf stat -a -A -e l3_request_g1.caching_l3_cache_accesses taskset -c 43 perf bench mem memcpy -s 32mb -l 100 -f default ... CPU36 354,891 l3_request_g1.caching_l3_cache_accesses CPU40 1,780,870 l3_request_g1.caching_l3_cache_accesses CPU44 315,062 l3_request_g1.caching_l3_cache_accesses ... Fixes: 2f217d58a8a0 ("perf/x86/amd/uncore: Set the thread mask for F17h L3 PMCs") Signed-off-by: Kim Phillips Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200908214740.18097-2-kim.phillips@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/uncore.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -181,28 +181,16 @@ static void amd_uncore_del(struct perf_e } /* - * Convert logical CPU number to L3 PMC Config ThreadMask format + * Return a full thread and slice mask until per-CPU is + * properly supported. */ -static u64 l3_thread_slice_mask(int cpu) +static u64 l3_thread_slice_mask(void) { - u64 thread_mask, core = topology_core_id(cpu); - unsigned int shift, thread = 0; + if (boot_cpu_data.x86 <= 0x18) + return AMD64_L3_SLICE_MASK | AMD64_L3_THREAD_MASK; - if (topology_smt_supported() && !topology_is_primary_thread(cpu)) - thread = 1; - - if (boot_cpu_data.x86 <= 0x18) { - shift = AMD64_L3_THREAD_SHIFT + 2 * (core % 4) + thread; - thread_mask = BIT_ULL(shift); - - return AMD64_L3_SLICE_MASK | thread_mask; - } - - core = (core << AMD64_L3_COREID_SHIFT) & AMD64_L3_COREID_MASK; - shift = AMD64_L3_THREAD_SHIFT + thread; - thread_mask = BIT_ULL(shift); - - return AMD64_L3_EN_ALL_SLICES | core | thread_mask; + return AMD64_L3_EN_ALL_SLICES | AMD64_L3_EN_ALL_CORES | + AMD64_L3_F19H_THREAD_MASK; } static int amd_uncore_event_init(struct perf_event *event) @@ -232,7 +220,7 @@ static int amd_uncore_event_init(struct * For other events, the two fields do not affect the count. */ if (l3_mask && is_llc_event(event)) - hwc->config |= l3_thread_slice_mask(event->cpu); + hwc->config |= l3_thread_slice_mask(); uncore = event_to_amd_uncore(event); if (!uncore)