Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp152740ybl; Tue, 3 Dec 2019 23:55:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzqz7D3F+ItxiVMab57kQ1AVDH9pfbDpesAEbjCEwg4iMvXkrvPaKCzilgo8i99/tGN63Ho X-Received: by 2002:a9d:6196:: with SMTP id g22mr1590527otk.204.1575446146755; Tue, 03 Dec 2019 23:55:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575446146; cv=none; d=google.com; s=arc-20160816; b=goo1BE++p6X+6GPkH2rnm9COASOu+hm0Dd9J3gBMbIkF5eHBEcHCemiXN0DZcXJEeu dhBr6bSDeg1cqlYbq4I04LhY9xt9wKTq0fyFsFu05lfunORuRktsqi/FUhTC9mEYxhYU 4PuE8PBRS4qUKG2ECulDhk4NzmIkbor5qUOSiT+VrGkZhxPVQ3LIEhTGxi3T6AnABXrI GQrwHkNpIbS9BqVqNv8n8Lbc13B9NsvQ1Cjf5Jmh5VKWEBYgL+XS9A5oPcympgx/GKzm SRFJvYcjOsrHpuzoj7aWMZKc6YiQniRrIwvtpsod1ULbiGH5OWnL8QJ6Wxh3h2CrvJAp l7Wg== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=92FfKllG+9icjKn2ebWxvWRLv58msVlHXEDdHrK98NM=; b=GSug2/SKZqES4Aez9O/bMpJhUkj1eHfDutC8RFSLVC+dj1VKzvkUM9ZuYLXEh8ymXU ded4SFd0y19nKoyIilmG9uXHFASEmJWzgYiI+pQ9gDU3pEcevJCQ8EtA6MUAV3uxt9p2 v1KsaaIy095/chILjcbZo15di+uzLrnT1b6ahiSPBQl1T6oK6gwP/jPFqwiw+HdZquLy 27ttMCjk9bWivr32tnAZRd/QhR4cbbrUqMW9/I5zcok3u0CCehbCDe2rPhe06wn/jc1X qKRGbveBgIFRdM9IYEcwDXSHIRxaUOJ4bVeQx8mP2J84k08AIlgfiBYlE1224dVbs+PM zmQA== ARC-Authentication-Results: i=1; mx.google.com; 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 8si2566682ota.266.2019.12.03.23.55.33; Tue, 03 Dec 2019 23:55:46 -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; 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 S1727526AbfLDHyf (ORCPT + 99 others); Wed, 4 Dec 2019 02:54:35 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:56168 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727426AbfLDHyK (ORCPT ); Wed, 4 Dec 2019 02:54:10 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1icPU5-0004Ym-MX; Wed, 04 Dec 2019 08:54:05 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id B48EB1C2652; Wed, 4 Dec 2019 08:53:55 +0100 (CET) Date: Wed, 04 Dec 2019 07:53:55 -0000 From: "tip-bot2 for Andi Kleen" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf cpumap: Maintain cpumaps ordered and without dups Cc: Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo , x86 , LKML In-Reply-To: <20191121001522.180827-4-andi@firstfloor.org> References: <20191121001522.180827-4-andi@firstfloor.org> MIME-Version: 1.0 Message-ID: <157544603562.21853.4057591064934185705.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 7074674e7338863e6404909c9761d4d3a610a379 Gitweb: https://git.kernel.org/tip/7074674e7338863e6404909c9761d4d3a610a379 Author: Andi Kleen AuthorDate: Wed, 20 Nov 2019 16:15:13 -08:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Fri, 29 Nov 2019 12:20:45 -03:00 perf cpumap: Maintain cpumaps ordered and without dups Enforce this in _trim() Needed for followon change. Signed-off-by: Andi Kleen Acked-by: Jiri Olsa Link: http://lore.kernel.org/lkml/20191121001522.180827-4-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/cpumap.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index 2ca1faf..d81656b 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c @@ -68,14 +68,28 @@ static struct perf_cpu_map *cpu_map__default_new(void) return cpus; } +static int cmp_int(const void *a, const void *b) +{ + return *(const int *)a - *(const int*)b; +} + static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) { size_t payload_size = nr_cpus * sizeof(int); struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size); + int i, j; if (cpus != NULL) { - cpus->nr = nr_cpus; memcpy(cpus->map, tmp_cpus, payload_size); + qsort(cpus->map, nr_cpus, sizeof(int), cmp_int); + /* Remove dups */ + j = 0; + for (i = 0; i < nr_cpus; i++) { + if (i == 0 || cpus->map[i] != cpus->map[i - 1]) + cpus->map[j++] = cpus->map[i]; + } + cpus->nr = j; + assert(j <= nr_cpus); refcount_set(&cpus->refcnt, 1); }