Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp231856pxa; Tue, 11 Aug 2020 01:12:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyTcvLi0fzV7J7EUErTKzEkzYV3H8uXh4WOqLtQo5VZfSndJYm2QQxYAnPmu8wzGoPaFj+ X-Received: by 2002:a05:6402:33a:: with SMTP id q26mr26187099edw.8.1597133558072; Tue, 11 Aug 2020 01:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597133558; cv=none; d=google.com; s=arc-20160816; b=czIgirkb2D4rZdiuCTCr5Fgl1OKQRrpUxyxp0jTgHuosq6lAgzZY+Cghk9Jnrjg7RR oChC82PDr7UH68vexdHhd3UNVlZ9ID7zOF6NX9w4TWKaw+dxR6sEJ6+k4BOBdQjJ3e+7 jCT/YLSVErBhOfJtR+mnETmemxR4SYttBOGQBxXTvRUkT6tjwUL94lXX/jFopg611s88 gAQo1wKi5YVrzh7AkhROnjzRjG4CKUlrmZX8Zuw532haidKwxk8sWPSSI8+N2y7NthUQ EQxEOBpLSaUNc8EE0Fph5EjfcLYyGpOPBaybL3Npg549W2AO18j+P8L7SoHkWyH1ZiA3 sRQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2QKqibQLkfC4+NATjrERYrmrCWhFdQCQXQuGVrIRjAc=; b=Mu81V16rnMWx3YiIcQEfJbJtJi+nrwfcxgCN2M+2c2nYOiRlEIrec5zNwjvf8JXgYw ykK6lSaxBMNmabtbKW75xBFotYIGLs3gLFVR8uMS7N40YlKcEr7VgXBwmVwtly5PXwvr b3Wgs2Q/R0E9gpCr0SiqrWI31sc3cqUI9hEdEj3dt+oCbwo0GYSF8pZPsJ2nCNN5pwZj ByIAKOECgWBsk+rENm2wmcEkzGk612fBv/GgXsMCploEtx1BU7bOeo1QacoM68SaT0N2 TrOW4yN+gpWy5PTxk+1hK4pi4NrKEtBzKMOho+EtYtbPuAxfDnU2FfVRmS+ACfdJQTMe bQZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Cf3h+MJU; 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 c21si5996351edv.187.2020.08.11.01.12.14; Tue, 11 Aug 2020 01:12:38 -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=Cf3h+MJU; 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 S1728293AbgHKILa (ORCPT + 99 others); Tue, 11 Aug 2020 04:11:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59076 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728225AbgHKILa (ORCPT ); Tue, 11 Aug 2020 04:11:30 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07B82WpA143054; Tue, 11 Aug 2020 04:11:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=2QKqibQLkfC4+NATjrERYrmrCWhFdQCQXQuGVrIRjAc=; b=Cf3h+MJUwx1wL/YD6z1GILlhIvkXo8yG8xnTwQBVj7fsYpP6tO9K+ldCX6Q0HlYtQk9K PikA824ZMiPhaJlz1YV4R9y+DzcM57KL3m3jsZ8V+fXiDfZfmjqq8NBFnTvbjmEmKP/W GTdvPFKL8azgriAt1oIHB1d8dBwMJvdbqqOg4RnkPSTCpcwibG1+1t0J2odLYfAacJD/ 0LX7F+b0/LlE/PKATShFboILxZKx1BnjUl8s7IlY5iztkbLuWkSVxX+Q7EXrdEHU6wTD J/9kZ2wRWnLi/myUJ/ug+1lKI9m16JDwhRsSfDIOifFhWwoBN/uCKg0cO8MrDwfjHhJ/ Og== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 32sr7veh8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Aug 2020 04:11:19 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 07B83NX9148010; Tue, 11 Aug 2020 04:11:18 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 32sr7veh82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Aug 2020 04:11:18 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07B8BGSF001946; Tue, 11 Aug 2020 08:11:16 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 32skp7swvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Aug 2020 08:11:16 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07B8BEaA33817052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Aug 2020 08:11:14 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CF0152052; Tue, 11 Aug 2020 08:11:14 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.21.82]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 67E8D5204E; Tue, 11 Aug 2020 08:11:13 +0000 (GMT) Date: Tue, 11 Aug 2020 10:11:11 +0200 From: Alexander Gordeev To: Namhyung Kim Cc: linux-kernel , Satheesh Rajendran , Srikar Dronamraju , "Naveen N. Rao" , Balamuruhan S , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa Subject: Re: [PATCH v2 1/3] perf bench numa: use numa_node_to_cpus() to bind tasks to nodes Message-ID: <20200811081111.GA31614@oc3871087118.ibm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-11_07:2020-08-06,2020-08-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=2 mlxlogscore=999 impostorscore=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008110047 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 04:26:50PM +0900, Namhyung Kim wrote: > Hello, > > On Mon, Aug 10, 2020 at 3:22 PM Alexander Gordeev > wrote: > > > > 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); > > + } > > + } > > It seems you need to call numa_free_cpumask() for both functions. Well, the whole approach to memory allocation is rather relaxed troughout the code. I.e cpumasks do not get deallocated (*), strdup() return values are not checked etc. If it worth fixing all that then it would be a separate effort, as far as I am concerned. > Thanks > Namhyung > > > } > > > > ret = sched_setaffinity(0, sizeof(mask), &mask); > > -- > > 1.8.3.1 > >