Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp463898ybh; Thu, 12 Mar 2020 05:22:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuXXZkGkxzqb5BAJs+4G3y+HLWnPwAkxLl3Kr0daO6ZSFUVE0g6hpv53irhd4O2/a7Kc374 X-Received: by 2002:a9d:600d:: with SMTP id h13mr5927699otj.213.1584015773041; Thu, 12 Mar 2020 05:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584015773; cv=none; d=google.com; s=arc-20160816; b=zzCi1bxN4NoH9Gyzebhmk9POwcJn23Og/ytBX+zhDaYjsSO4+P0SIb6byh2JlUhYr/ oN0iOKDNnTC9mIWn2uiYK7cfcCNKuJ39KhOQfdSYqfU7kxeeWkGcgzi2Utzb+xOT5LA4 BoA04D3EqgJYJKWCFpxrV6SMXZXbepDx4ih3K2VG2BUDaIZKVPqSDUo8/GVJXg9TF6vk RWipHLkC6Kh/plYGf61IhNaOcQUKCr87dnR3i1q1jsZfUEPUHLoJn30G0gh2svtNkL/a TKCm5rFv1YMZLEZbaa4FjLhHmPY3oNU26uy2juDh3EOp32zYG0aE1kt4R4T7FLW8P5A8 bHHg== 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 :content-language:mime-version:user-agent:date:message-id :organization:cc:to:subject:from; bh=9gaOQ4y0nlIq+fBY+GhLedHEEDkg/lkkKHIUHd7DgEY=; b=sUlKCHA56n0WS3m4wuVlGZaYTBN/vGA4d3XNY+rlruUqRu+W2+3f1szl022+zmyEVD auXOBQv29uVmInP9hQr4yaFaU7A3qSmjJmD28MGQTTvJDfnX5JscEViSzsMDPd4STVbL T/+du/b1v8oLfKXLaHyQhGcNOqBA1DBQifIttIbLbQLpEqyUBZwulu2jSr1Loyb4E1D3 j5d/2dObPGNO1CqxEuMd2UfyVdouXTK9cMzitqedSydpMtOYzxN6tVGELP1QvDETwgmj s+LiQo7agzhKxUqRo5iaa5ZmjtMomqFaplgiR3hGmXNVA1pcH8AImrwYrCqUkEM+SfZy hViQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w129si2150930oia.232.2020.03.12.05.22.40; Thu, 12 Mar 2020 05:22:53 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbgCLMVv (ORCPT + 99 others); Thu, 12 Mar 2020 08:21:51 -0400 Received: from mga03.intel.com ([134.134.136.65]:22186 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726254AbgCLMVv (ORCPT ); Thu, 12 Mar 2020 08:21:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Mar 2020 05:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,544,1574150400"; d="scan'208";a="235010057" Received: from linux.intel.com ([10.54.29.200]) by fmsmga007.fm.intel.com with ESMTP; 12 Mar 2020 05:21:49 -0700 Received: from [10.125.252.216] (abudanko-mobl.ccr.corp.intel.com [10.125.252.216]) by linux.intel.com (Postfix) with ESMTP id 1866058010D; Thu, 12 Mar 2020 05:21:46 -0700 (PDT) From: Alexey Budankov Subject: [PATCH v1] perf record: fix binding of AIO user space buffers to nodes To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel Organization: Intel Corp. Message-ID: Date: Thu, 12 Mar 2020 15:21:45 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Correct maxnode parameter value passed to mbind() syscall to be the amount of node mask bits to analyze plus 1. Dynamically allocate node mask memory depending on the index of node of cpu being profiled. Fixes: c44a8b44ca9f ("perf record: Bind the AIO user space buffers to nodes") Signed-off-by: Alexey Budankov --- tools/perf/util/mmap.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 3b664fa673a6..6d604cd67a95 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -98,20 +98,29 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity) { void *data; size_t mmap_len; - unsigned long node_mask; + unsigned long *node_mask; + unsigned long node_index; + int err = 0; if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) { data = map->aio.data[idx]; mmap_len = mmap__mmap_len(map); - node_mask = 1UL << cpu__get_node(cpu); - if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) { - pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n", - data, data + mmap_len, cpu__get_node(cpu)); + node_index = cpu__get_node(cpu); + node_mask = bitmap_alloc(node_index + 1); + if (!node_mask) { + pr_err("Failed to allocate node mask for mbind: error %m\n"); return -1; } + set_bit(node_index, node_mask); + if (mbind(data, mmap_len, MPOL_BIND, node_mask, node_index + 1 + 1/*nr_bits + 1*/, 0)) { + pr_err("Failed to bind [%p-%p] AIO buffer to node %lu: error %m\n", + data, data + mmap_len, node_index); + err = -1; + } + bitmap_free(node_mask); } - return 0; + return err; } #else /* !HAVE_LIBNUMA_SUPPORT */ static int perf_mmap__aio_alloc(struct mmap *map, int idx) -- 2.24.1