Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2965749ybt; Mon, 29 Jun 2020 11:39:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3r4R24SUddessT4bFGgEIcYyiXO3AH82wxWTD6XijXG/mzT70tv+TfeSa8wC0zv0O3bIj X-Received: by 2002:aa7:cb55:: with SMTP id w21mr11561338edt.380.1593455955968; Mon, 29 Jun 2020 11:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593455955; cv=none; d=google.com; s=arc-20160816; b=iYlIdD0H6YfvvVwg3lxaAWjbTBb7bnY9Z0ofWqm760JjbdQ2OE1BgG3+wzoj2P/Yu4 BqogqSGBkMkF5bO2Wi2ijCZD/zXo16Z5iijJPY3Y2m8Yi02cKIZdD1qzt+ZPl7jndwlY fxZ1GRKgc3bFmosAhQIdumsu4akkF3eWLE/en6+DKIAbzCUJsT3Qf4928ikmKOi/5SnX 8w4gfqZX7mwPOldYtePgkOBN9OWABXObWgUOunTaavcZYpzMsv5OYgvvQ2qazdkANCpO BrOUoPHSkRZlMzT+YoO91z/DITYYCQ9Z1YuQldyYo/EPgnDfQwUlo4mgQMj5F2BPgCpt Dstw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ySBy3v2ZoevrpP0eXSpa4fz7WViv69nc/szg8X5gT5o=; b=rj1iDcRMIwmZumMRxynNAMXniYpLZNxCMm19Sv4ox0XijnQySvZtsutTVE6WhfrP99 TyEEIcnffxV/xwOzJ4n97jSSDFDRLOMvYuDpXa2poZyz4EYamNXVB2iRBiUZ/tdxbYs1 Cz+5SJyXxWnKDAx6pM/nTrICgoor2AF4uOVVGocutwUnIPtvaI1zV7S58fa/60Hp60q8 uVqn9Yxg2q9DYnu6Dzr6srNqSUCzaOcUp/P3Vpbe7MpWG0d2j69C7t67Cj3s2QGD/x1v ckE4Ov3ZhG1GftLDASFa/POXJqAz3H/ErTZvTDLDZUl5m0WZoN+Gn88OuluvMjjeSY9s hLMw== ARC-Authentication-Results: i=1; mx.google.com; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si236581ejr.391.2020.06.29.11.38.51; Mon, 29 Jun 2020 11:39:15 -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; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgF2ShP (ORCPT + 99 others); Mon, 29 Jun 2020 14:37:15 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:5512 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbgF2ShN (ORCPT ); Mon, 29 Jun 2020 14:37:13 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05TFd8GP052220; Mon, 29 Jun 2020 11:50:18 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31ycd47q58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Jun 2020 11:50:18 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05TFibkT078882; Mon, 29 Jun 2020 11:50:17 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 31ycd47q48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Jun 2020 11:50:17 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05TFo8Xi024870; Mon, 29 Jun 2020 15:50:15 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma05fra.de.ibm.com with ESMTP id 31wwr896gp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Jun 2020 15:50:15 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05TFoCXP61997140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Jun 2020 15:50:12 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C516FAE051; Mon, 29 Jun 2020 15:50:12 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 765E0AE055; Mon, 29 Jun 2020 15:50:12 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.156.24]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 Jun 2020 15:50:12 +0000 (GMT) From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: Alexander Gordeev , Arnaldo Carvalho de Melo , Ingo Molnar Subject: [PATCH 1/3] perf bench numa: fix incorrect NUMA toplogy assumption Date: Mon, 29 Jun 2020 17:50:07 +0200 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-06-29_15:2020-06-29,2020-06-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 cotscore=-2147483648 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=1 phishscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006290103 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current code assumes that CPUs are evenly spread among NUMA nodes. That is generally incorrect and leads to failure on systems that have different NUMA topology. Cc: Arnaldo Carvalho de Melo Cc: Ingo Molnar Signed-off-by: Alexander Gordeev --- tools/perf/bench/numa.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 5797253..5497c74 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -247,12 +247,13 @@ static int is_node_present(int node) */ static bool node_has_cpus(int node) { - struct bitmask *cpu = numa_allocate_cpumask(); + struct bitmask *cpumask = numa_allocate_cpumask(); unsigned int i; - if (cpu && !numa_node_to_cpus(node, cpu)) { - for (i = 0; i < cpu->size; i++) { - if (numa_bitmask_isbitset(cpu, i)) + BUG_ON(cpumask); + if (!numa_node_to_cpus(node, cpumask)) { + for (i = 0; i < cpumask->size; i++) { + if (numa_bitmask_isbitset(cpumask, i)) return true; } } @@ -288,14 +289,10 @@ static cpu_set_t bind_to_cpu(int target_cpu) static cpu_set_t bind_to_node(int target_node) { - int cpus_per_node = g->p.nr_cpus / nr_numa_nodes(); cpu_set_t orig_mask, mask; int cpu; int ret; - BUG_ON(cpus_per_node * nr_numa_nodes() != g->p.nr_cpus); - BUG_ON(!cpus_per_node); - ret = sched_getaffinity(0, sizeof(orig_mask), &orig_mask); BUG_ON(ret); @@ -305,13 +302,15 @@ static cpu_set_t bind_to_node(int target_node) for (cpu = 0; cpu < g->p.nr_cpus; cpu++) CPU_SET(cpu, &mask); } else { - int cpu_start = (target_node + 0) * cpus_per_node; - int cpu_stop = (target_node + 1) * cpus_per_node; - - BUG_ON(cpu_stop > g->p.nr_cpus); + struct bitmask *cpumask = numa_allocate_cpumask(); - for (cpu = cpu_start; cpu < cpu_stop; cpu++) - CPU_SET(cpu, &mask); + BUG_ON(!cpumask); + if (!numa_node_to_cpus(target_node, cpumask)) { + for (cpu = 0; cpu < (int)cpumask->size; cpu++) { + if (numa_bitmask_isbitset(cpumask, cpu)) + CPU_SET(cpu, &mask); + } + } } ret = sched_setaffinity(0, sizeof(mask), &mask); -- 1.8.3.1