Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4081227pxa; Sun, 9 Aug 2020 23:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQswh4qC5W/vXklBGiIaZ/l5PvG5Xso+YaYWOOCtalbyCBqrM3r4gZYeTyxjMJRjfUGq8+ X-Received: by 2002:aa7:d596:: with SMTP id r22mr19851353edq.204.1597040594542; Sun, 09 Aug 2020 23:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597040594; cv=none; d=google.com; s=arc-20160816; b=STjBCHrQio261/PVoJatIn61v/XjTLx2F0znem9Fts1YA0+gK/T8t38tfpWdGY+Qwi TRWJKoUrk85hI7weW83gCJKJ44jlU9AFA0wtDcSLwCfcXejDs3yhqoAKQW7DhE0Jqjhb YqfZ/js9+FXrOe/+cs5pCjXJrUVX55GZtZQI3S8Fy2R3DFNNNVWBUa4BqsGz8vcA7mJA UBIJJ2/6HsOdVJshYkPtWtLca6iBRxsnWP2cMRoaUyoVpVrhtZx/rJWcY4BjJBfvhpe4 Q6S4677zt84NASbqetyfuEGdwH+pJuDsYWhc2PQj6kw1hCOm+GMD2z7xKV0c4X/qJdul t95A== 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:dkim-signature; bh=+vOVDz5vOViBE0HyVBNzS9vH4zM4sWUVSg7XjMPQCf4=; b=HwNuI3K1cBW3xovZiBm2k0FEGhXPSGe8PLV7D0LUa3AxbJD79FzvNgKO+8OMsRFUIM Btg2a2XodbJOIJpY7DGN6IUGVCovG8RGblRH4woSVq7Wqq4F4R0RWUlwLUb5jqi8v6/G 5h7ZNpYNuh9vRc0fiU9jcFzm4GwFGTf7Qj9m+uHgNnI2+7v18xLdqn2UpIQgDAcwfhl+ 6G6gpMS35YL1NM1ZUBQLqSi+5wZIQgCYwsNUsolJgNVnjIt3jMKJhZn7++2hZoB1jqso 39PUqbCX/aWquGAlyx3q+ETGJ3M7hMlyqdYmSMv0UkvFenkALtO+TBCrHpnfaE+//OcK BpUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Q77inBMn; 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=pass (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 by28si10525750ejc.510.2020.08.09.23.22.51; Sun, 09 Aug 2020 23:23:14 -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; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Q77inBMn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726401AbgHJGWV (ORCPT + 99 others); Mon, 10 Aug 2020 02:22:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33924 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgHJGWT (ORCPT ); Mon, 10 Aug 2020 02:22:19 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07A62mDr003317; Mon, 10 Aug 2020 02:22:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=+vOVDz5vOViBE0HyVBNzS9vH4zM4sWUVSg7XjMPQCf4=; b=Q77inBMnCSgf1lWojDBd58hgijbjvZL6j3rjSmQ0h43bKcmB5ODoAH8RqNBdEcmltyIx O4UAZumNUCbOHxtvmvyoN63re6IWAd/JSLyqMMSQefDmeooQ38wJzlpIRMiHx7tcf+o4 N3FtDTgyNlb9s+JeHC3wG3/t5HWGRUdgWn5lCcx0tBXEvDEjKtyBQbLLPf0s3hgTB8gT oSd5syQ+S/i5J2QguQEF8nscUsEE/AG+mAuv6yfzy7nhho8P4jZMGgjCtAlZsQ4L6tG1 RGOEYG2Y4duW9HUIl0K3zeEeE7VD6zpCk8XHtUJNuQuaTD9w7QLeLcxq4DdN2fduVQLP Lg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32src11uqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2020 02:22:08 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 07A62n9O003438; Mon, 10 Aug 2020 02:22:08 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 32src11uq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2020 02:22:08 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07A6LhxS016005; Mon, 10 Aug 2020 06:22:06 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 32skah9xcj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2020 06:22:05 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07A6M3UC13893912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Aug 2020 06:22:03 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF7F1A404D; Mon, 10 Aug 2020 06:22:03 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1F214A4055; Mon, 10 Aug 2020 06:22:03 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.20.209]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 10 Aug 2020 06:22:03 +0000 (GMT) From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: Alexander Gordeev , Satheesh Rajendran , Srikar Dronamraju , "Naveen N. Rao" , Balamuruhan S , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: [PATCH v2 1/3] perf bench numa: use numa_node_to_cpus() to bind tasks to nodes Date: Mon, 10 Aug 2020 08:21:58 +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-08-10_02:2020-08-06,2020-08-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008100043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is currently assumed that each node contains at most nr_cpus/nr_nodes CPUs and node CPU ranges do not overlap. That assumption is generally incorrect as there are archs where a CPU number does not depend on to its node number. This update removes the described assumption by simply calling numa_node_to_cpus() interface and using the returned mask for binding CPUs to nodes. It also tightens a cpumask allocation failure check a bit. Cc: Satheesh Rajendran Cc: Srikar Dronamraju Cc: Naveen N. Rao Cc: Balamuruhan S Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim 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..23e224e 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