Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1395113pxb; Mon, 11 Oct 2021 05:14:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxwocjNwTEmDKTEs/sOV2shonK9MSq9EX/LUWehbSsHpNbmo68fNPINMIB/zTwf5MtoANg X-Received: by 2002:a05:6402:4382:: with SMTP id o2mr5927555edc.271.1633954448426; Mon, 11 Oct 2021 05:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633954448; cv=none; d=google.com; s=arc-20160816; b=CR4DDtW1AQbM3IhYLPAwPvE/c+vcdgvgM0IyPB6UE3gDpdAOHLsVXRl7wIruPH9/j7 Tur6pA3zx72udJ+psVsz4fsvti3pjRCCMqv23/qAqfb2g/K6vQOSW0OMlflPALBuG6kT VWFpVHxyyFSMpTKhK90+3XlEoVzW6qKXnZ79w5cIDOcItQgFB3i5MnhXKmHBKQyHbTZP 2kHxdtuoReNHQ2YFj01ZdwAkuCmcILzVnCesxOHRtXDqPELMtQ2A9BfYi0AXmDb/eLUV TF8GrsaFhxEdgAiZdEHcwLy+3LOYOepG8u6c+bHQodmYOQOAQqf16dej6hY8nYCF3oNJ NVdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr; bh=dP3NIIRJh33tHQCxu0jHoX9ADc6WHzmXo5IXZ5QzpfE=; b=eSP4caS778lDc+RaEP6O/oJFhNOfTAtw2hmNRzysRLVDI0sKkeJcyQKQlZo9EVg6jL jF8s+VIman7fgWRM6k+CKISAugkYFn2edYifI2I/fmF/OxQeqD4oeY8eAa46LgM/invN 3pm8ayd1SEJYInLe2yOlr1755pGE2klegGQH52AshG1/TO5PS39wpbM6ol7mXfWHGa6f z8Nz78P1rkPmpRQb6dWdYk50RrGQB9Uyd/AQxolk/6znr26gZjhasv8z53N5w+Xh5fIn 2xE7j0ASS1SKQGG4Gzk8zDVwSbCLugD6H8N00ZhcUwjBv4eU2mw0dF5+ruGfiBHD2QPx Zneg== 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=fujitsu.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di1si17140169ejc.420.2021.10.11.05.13.43; Mon, 11 Oct 2021 05:14:08 -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=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235160AbhJKIjR (ORCPT + 99 others); Mon, 11 Oct 2021 04:39:17 -0400 Received: from esa11.hc1455-7.c3s2.iphmx.com ([207.54.90.137]:30335 "EHLO esa11.hc1455-7.c3s2.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234885AbhJKIjQ (ORCPT ); Mon, 11 Oct 2021 04:39:16 -0400 IronPort-SDR: U0VjdClWbSGtL1ulqKHnOxVlsXjCx8+fLEl3lakAdsdlmEYSJSB2PcCEuNHJk9+qSKiy4x/atV O373nA8/Vk4G209ArQLurqdo3Ti96fGpsnxIse1myYoXuScHTqr2KXws1pTYY7Ew/LtBx3tkPo ZdJA8kcEfqOpSmAAGwY3yP7VU7Qlv9WSeNPsqXe2jc7wJ1oTnO6Ozr/plqtiUO5OmfpAdhH625 tnDA+A/mZbQzG8EQHFRse6aupF2mRVu00jcUqpkI2amFEEU+n1wpsXGEucY5fO7JdFi/fgA1Pb 5JN5FqvyU9ETt/OS3zoyHPuV X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="28062049" X-IronPort-AV: E=Sophos;i="5.85,364,1624287600"; d="scan'208";a="28062049" Received: from unknown (HELO oym-r2.gw.nic.fujitsu.com) ([210.162.30.90]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Oct 2021 17:37:14 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id D892AE6800; Mon, 11 Oct 2021 17:37:13 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 170AECA703; Mon, 11 Oct 2021 17:37:13 +0900 (JST) Received: from pumpkin.openstacklocal (pumpkin.fct.css.fujitsu.com [10.130.70.189]) by yto-om3.fujitsu.com (Postfix) with ESMTP id F3F584005EA44; Mon, 11 Oct 2021 17:37:12 +0900 (JST) From: Shunsuke Nakamura To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH v3] libperf tests: Fix test_stat_cpu Date: Mon, 11 Oct 2021 17:37:04 +0900 Message-Id: <20211011083704.4108720-1-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `cpu` of perf_evsel__read() must be specified the cpu index. perf_cpu_map__for_each_cpu is for iterating the cpu number (not index) and is not appropriate. So, if there is an offline CPU, the cpu number specified in the argument may point out of range because the cpu number and the cpu index are different. Fix test_stat_cpu. Committer testing: # make tests -C tools/lib/perf/ make: Entering directory '/home/nakamura/kernel_src/linux-5.15-rc4_fix/tools/lib/perf' running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c...OK - running tests/test-evsel.c...OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c...OK - running tests/test-evsel.c...OK make: Leaving directory '/home/nakamura/kernel_src/linux-5.15-rc4_fix/tools/lib/perf' Signed-off-by: Shunsuke Nakamura --- Previous version at: https://lore.kernel.org/lkml/20211006094817.477494-1-nakamura.shun@fujitsu.com/ Changes in v3: - Fix build error Changes in v2: - Remove "2/2" from Patch Subject tools/lib/perf/tests/test-evlist.c | 6 +++--- tools/lib/perf/tests/test-evsel.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c index c67c83399170..ce91a582f0e4 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -40,7 +40,7 @@ static int test_stat_cpu(void) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK, }; - int err, cpu, tmp; + int err, idx; cpus = perf_cpu_map__new(NULL); __T("failed to create cpus", cpus); @@ -70,10 +70,10 @@ static int test_stat_cpu(void) perf_evlist__for_each_evsel(evlist, evsel) { cpus = perf_evsel__cpus(evsel); - perf_cpu_map__for_each_cpu(cpu, tmp, cpus) { + for (idx = 0; idx < perf_cpu_map__nr(cpus); idx++) { struct perf_counts_values counts = { .val = 0 }; - perf_evsel__read(evsel, cpu, 0, &counts); + perf_evsel__read(evsel, idx, 0, &counts); __T("failed to read value for evsel", counts.val != 0); } } diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-evsel.c index 9abd4c0bf6db..33ae9334861a 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -22,7 +22,7 @@ static int test_stat_cpu(void) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_CLOCK, }; - int err, cpu, tmp; + int err, idx; cpus = perf_cpu_map__new(NULL); __T("failed to create cpus", cpus); @@ -33,10 +33,10 @@ static int test_stat_cpu(void) err = perf_evsel__open(evsel, cpus, NULL); __T("failed to open evsel", err == 0); - perf_cpu_map__for_each_cpu(cpu, tmp, cpus) { + for (idx = 0; idx < perf_cpu_map__nr(cpus); idx++) { struct perf_counts_values counts = { .val = 0 }; - perf_evsel__read(evsel, cpu, 0, &counts); + perf_evsel__read(evsel, idx, 0, &counts); __T("failed to read value for evsel", counts.val != 0); } -- 2.25.1