Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1769598ybl; Sat, 11 Jan 2020 02:27:25 -0800 (PST) X-Google-Smtp-Source: APXvYqx2b23PYoCzSQn46vc8Gvy7vjx2/tX01YtDkXnw4IM2QyhsmdI3daPDPIG120Ycy881riK7 X-Received: by 2002:a9d:67d2:: with SMTP id c18mr6070748otn.362.1578738445361; Sat, 11 Jan 2020 02:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578738445; cv=none; d=google.com; s=arc-20160816; b=c2Qwj0L9IonxrULQJPvjXT6pkA9+LtL2ce02pf7Rliu4U7ocxiRHQkJ3pjl/2FPtxD YdIFFPbEJhTBdfRGEhdPNYpagbOpSp9nAepS0T1Up4PflYqY/eqeTUOajiZdQ7kHDwpA iyXsxbycsWmjXOHojiOBK2sjEDzQKQHcTmyey0WF1PcAh33joe1MQKIZnr75Ott2DufL +3Lsjl/FOeyeCCdccusxUXMCGbN7ZVYtf82NSygDWZCbB9WXBbsCzRtiYH8LMDogb/Zd fq/Ea0o7ekY7Tp78R4zWbgGLULgn9wOEN13qg6bSPCCgATb5r1zWbpYVIxOcTk5nRvlx uDOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5Ocqvstg1zNp6rfyacP50dwhEQQ7fc+tOrQ6jj58iGA=; b=KPVkbM34aNCJlCaf9Oy0hzBz5JUZTNewXkKAX595Vp55RHzBGh0SrhGerab7ThBUVS C5efFBn5Jom3YwD7Bk8Zhk0IYzi1mACuIkbgl9Of4aGg0fHQoQIvLVi1o2sr6E60npBD Tm/41YFhpb7LND28fVTdm00bYR3YjASzdjWT1qHRxLapTS3kNAz7z4krNfmvVQRpOHvk m6w25M8EmUHqQVAiEPzy1EV1fsbEnVR2pu3ItilIajYcAAFbZC7X8CgihwdElulYdeh1 pbd/ZTQH0xRTvMuBRH8b2XyhIMXjT9Y/Oix9N1XANlRdF+GlAAewaiqlbs7hvp0e1GZ7 oh+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ADkuKq29; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si2755464oii.249.2020.01.11.02.27.14; Sat, 11 Jan 2020 02:27:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ADkuKq29; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730989AbgAKKZ1 (ORCPT + 99 others); Sat, 11 Jan 2020 05:25:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:56178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730662AbgAKKZZ (ORCPT ); Sat, 11 Jan 2020 05:25:25 -0500 Received: from localhost (unknown [62.119.166.9]) (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 D93AA20848; Sat, 11 Jan 2020 10:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738324; bh=jV0Fn+92D1zShlnjiLkLneWO8c8R5+UdB7LDaQECXz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADkuKq29ojjbrfn7VQEVde6E8+nsPm/lnJ9+K5m3zK1HARelSnnwQ9vrROOm4Se0n kG8VeugDzQZICiTjhX0DoR6U0HepeHLVpTyIQikKqfUUEqQOV1t/Fwcj7tD/rzuEg/ 2x9zzTG9/O+ggSf3alBT3W+bfw9R+wxz3rNay1Wg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Petlan , Jiri Olsa , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.4 057/165] perf header: Fix false warning when there are no duplicate cache entries Date: Sat, 11 Jan 2020 10:49:36 +0100 Message-Id: <20200111094926.006892306@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Petlan [ Upstream commit 28707826877f84bce0977845ea529cbdd08e4e8d ] Before this patch, perf expected that there might be NPROC*4 unique cache entries at max, however, it also expected that some of them would be shared and/or of the same size, thus the final number of entries would be reduced to be lower than NPROC*4. In case the number of entries hadn't been reduced (was NPROC*4), the warning was printed. However, some systems might have unusual cache topology, such as the following two-processor KVM guest: cpu level shared_cpu_list size 0 1 0 32K 0 1 0 64K 0 2 0 512K 0 3 0 8192K 1 1 1 32K 1 1 1 64K 1 2 1 512K 1 3 1 8192K This KVM guest has 8 (NPROC*4) unique cache entries, which used to make perf printing the message, although there actually aren't "way too many cpu caches". v2: Removing unused argument. v3: Unifying the way we obtain number of cpus. v4: Removed '& UINT_MAX' construct which is redundant. Signed-off-by: Michael Petlan Acked-by: Jiri Olsa LPU-Reference: 20191208162056.20772-1-mpetlan@redhat.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/header.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index becc2d109423..d3412f2c0d18 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1089,21 +1089,18 @@ static void cpu_cache_level__fprintf(FILE *out, struct cpu_cache_level *c) fprintf(out, "L%d %-15s %8s [%s]\n", c->level, c->type, c->size, c->map); } -static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp) +#define MAX_CACHE_LVL 4 + +static int build_caches(struct cpu_cache_level caches[], u32 *cntp) { u32 i, cnt = 0; - long ncpus; u32 nr, cpu; u16 level; - ncpus = sysconf(_SC_NPROCESSORS_CONF); - if (ncpus < 0) - return -1; - - nr = (u32)(ncpus & UINT_MAX); + nr = cpu__max_cpu(); for (cpu = 0; cpu < nr; cpu++) { - for (level = 0; level < 10; level++) { + for (level = 0; level < MAX_CACHE_LVL; level++) { struct cpu_cache_level c; int err; @@ -1123,18 +1120,12 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp) caches[cnt++] = c; else cpu_cache_level__free(&c); - - if (WARN_ONCE(cnt == size, "way too many cpu caches..")) - goto out; } } - out: *cntp = cnt; return 0; } -#define MAX_CACHE_LVL 4 - static int write_cache(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { @@ -1143,7 +1134,7 @@ static int write_cache(struct feat_fd *ff, u32 cnt = 0, i, version = 1; int ret; - ret = build_caches(caches, max_caches, &cnt); + ret = build_caches(caches, &cnt); if (ret) goto out; -- 2.20.1