Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp704685pxb; Mon, 25 Oct 2021 17:03:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbVkG+JnmmePHRPyT9sP3durW63mDWYgMqEpUXt4R2LyyQ+qvXP6r+mUjf8wZndVNpWjn9 X-Received: by 2002:a17:907:7293:: with SMTP id dt19mr8992081ejc.158.1635206598985; Mon, 25 Oct 2021 17:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635206598; cv=none; d=google.com; s=arc-20160816; b=r0tQm1VJ5P0bwGkpDNBArmv9zqozr8MWKwzhdGf2qhM5HBxbKrs5yv7UsrJmtiswc1 uJSU4MHspbk1c0nj9axrzGZhwlAHBxyqMHV4730bsijWANP66ROpx0/ml1BFc5VzUAtm +gW4ngrUm4XMyHf8bZi3sqyJwstwZ0IUYbuhr3pQpZuF99D+mTpj25l5VhVsR9RSsHBN bziHhQ2OGhDb5fbYxiS7U8GbscBxjVgtsAj5SNIosX5Ze49V3DQKqRmUHkDj/ZnaH/Op v0KFgt6Zza4WELSc9srdvOk65d0olTzuF5FIB+Jcv8l+GTnrCcsR0DoruUfr4O80gAvg 6UcQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gcf74RY/ni/5MbSOtlf4ssO+4k8G6vWzzttR0fBJ+5M=; b=xsp5d/7dvQwenkLl2LhhuWCM4Cvz/gjg/gMOpm6qdxU0QyBA57LnM9VUqM8pVfEfsN h6UUYDYQ1ywWlOHlNOZ/wJRnaj5gUdxLx84fe6utDUIPRdW3guTZEcUcHSf67C7rpKy3 ISeq0Fr1mAu/i7i6oYh+8TMzZpuIqcnvd7QGob1m4B7b8ya0vqGHF46I4oAeDLbVvChX SCqoNrdNneFoXDfgJ3jF5bEU0sXZb8sWRl/TVSoZC8ZMdBkeSOzcofvY/zML4QH168uu SyObrUZw96HWX2wOkqBT1+UmnnUI5I85ZEopb8Yq4unSv2gzL3rHWkBu3jzU9uSY5bmP BPVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FimIYjiO; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y69si776814ede.35.2021.10.25.17.02.47; Mon, 25 Oct 2021 17:03:18 -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=@linuxfoundation.org header.s=korg header.b=FimIYjiO; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236678AbhJYTpC (ORCPT + 99 others); Mon, 25 Oct 2021 15:45:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:53486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235906AbhJYThg (ORCPT ); Mon, 25 Oct 2021 15:37:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 52CC6610D2; Mon, 25 Oct 2021 19:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190446; bh=+0OJ+/xPdQhiJbG4hSuQ86RgnzKxAiGQXSJv8/cpzIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FimIYjiOLw72qq/7MfM0zlHwdaEUDe7TA/6c+ZUX/YgFEO40BubcIl1wunOaXqhnu H5sNQ96jTw1mvGgcQrM1BqsXmUIKGbTcHZeo+8D62kpoSWi7YmgI4hk73ZC6Ze9g87 ydIx6M5jVIz+4WDcZXjkMUWrPcWw1KZr31rO2ciI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shunsuke Nakamura , Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 78/95] libperf tests: Fix test_stat_cpu Date: Mon, 25 Oct 2021 21:15:15 +0200 Message-Id: <20211025191008.240587204@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190956.374447057@linuxfoundation.org> References: <20211025190956.374447057@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shunsuke Nakamura [ Upstream commit 3ff6d64e68abc231955d216236615918797614ae ] The `cpu` argument of perf_evsel__read() must specify the cpu index. perf_cpu_map__for_each_cpu() is for iterating the cpu number (not index) and is thus not appropriate for use with perf_evsel__read(). 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(). Testing it: # 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 Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20211011083704.4108720-1-nakamura.shun@fujitsu.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 bd19cabddaf6..60b5d1801103 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -38,7 +38,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); @@ -64,10 +64,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 0ad82d7a2a51..2de98768d844 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -21,7 +21,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); @@ -32,10 +32,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.33.0