Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp557319lqt; Thu, 6 Jun 2024 11:04:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLcZN7t7V3S3eoLnN1IvcakN2BfAyqllpGljY6CcroRPOJVshsBgz1Lze8f1eyNLQ5rCWpvUcnTUpOkfT0j90ii5/UsZKPeLvHGghnpQ== X-Google-Smtp-Source: AGHT+IEleqFhiI+VrpLUJ4h8+ZK/pkkaS+96hnELqV5ugQTsW/sIR2X2gpXyzcDUHCBjq9K7f3cE X-Received: by 2002:a05:6830:18e9:b0:6f9:3773:dcbf with SMTP id 46e09a7af769-6f9572dacd2mr158986a34.31.1717697096045; Thu, 06 Jun 2024 11:04:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717697096; cv=pass; d=google.com; s=arc-20160816; b=07B/60M+yQR7QMRTQrqi7G8XaRy8qe9FYbIK462VQC5CG4TUJ4S3W+c3Iz9dbftmdT PcuEfFavQ1edbnANUxkaZbOs0zalF7Ji4ohYLU6vR1Y9mm2e2WIMQlTXq7t6RZ5kxOej XU/YYp2y8w0ZrlpcEzIEW4uMpIujCZ0yOy0n2xq/+catBBZ4Ghnlv+LSCLifZLbAJuS3 eZGKkvgj9ayERn0CuMArZibh4cq2kpAn05UYHQnpVRCT8BNQRRr+FrLefw9alU1GrrnO 7gRqVQgS0muiA7GaA+eqPPE7rXNciB/UB6p5ZdIMSBmHMKVzxJs8WWcUBLNGOV2BeFs4 CCzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=tpgKcn2Q11Gdf4JWr5omRoQrbYWt0jfP0xhwsd28ims=; fh=R6vlulLCMblno0evipVFd402axpzJTFMW03MpqzBwVI=; b=e8O2rRpcQypHjpfdwDppOsDV2RIOItgTDrkBtdzQrTeBTaj3e++Uo/GceQZRmU2UB9 Oy1lgZ9QVN9UIdWqxsfOBx20B+HvMU1tGTnPCQGS7RJGdIoL36r9XIsEcbosFYIdedR7 Y8Plv7lMCgQkFLaXRvT+Z5BSFk2n+i2PZduJeIDOJ69ErYJrCPWXhFtQDKZLOfGMapRc ZiDS/piKWDtJT2NOT6pjDBblc2tasUQEHgUOWaeqxqD44JE6xmQBQCbnPrfazKgPYm94 IYKNCItNP07hYcQCCQfcUA0m/4FPu8VhRh/uSNtQNFARTJyFwCSqTuUMbhsrK73ChjX0 i8kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mZzKpqVD; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-204853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ada2fe7eead31-48c1a0f656esi534081137.77.2024.06.06.11.04.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 11:04:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mZzKpqVD; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-204853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B10541C231DA for ; Thu, 6 Jun 2024 18:04:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 870D91993BC; Thu, 6 Jun 2024 18:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mZzKpqVD" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F14F5199246; Thu, 6 Jun 2024 18:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717697074; cv=none; b=s1xuDjB5HIxbDN1EyiE1rG0uOYUz0cb6MudJmFNw1X3cjw7fgrz/Wh05l/eK03w8STofF+F3cz4RhX0UYJpJlbLhcrnJN+L9t8btM9vilRH5b6m4CzbQKYsim81q5PBcESr1NYfrG9CE4k1BgkSxaOUpR4Bi6Ph1J0hR7rkO95M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717697074; c=relaxed/simple; bh=N7urc3PGrVRVyhlP4ECO2cQhX6mwjAHqaA+2X4Nkxno=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cUud3b8UpAzB7VmB+jFF0kRQt2sroz2hs9RvpqyHEVcTG6TncUR2cYTPm4jCMqIf8LUjLM7toTvJpZ1uwYrPqGEJuZRS7Lpju/LKry+EFejf22ajLPY1bBMpWSiNnwdvBRDbmkLpNI+TaiXH+YMW1rhHtnHEQy41avnPF81kVNo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mZzKpqVD; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717697073; x=1749233073; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=N7urc3PGrVRVyhlP4ECO2cQhX6mwjAHqaA+2X4Nkxno=; b=mZzKpqVDKEietPZXO0iIp42rsdp1TSRgTuAlzSeG9CQYlv9NyM0S3Ag0 ywCQ92CS3D6TJkP8a3897Ec72D1af3VUDw3Kf29KEvr8jrC8OucHRbD4X KjN0gK68QGqW9iGEI/5X/dt88wDEnqr1N2imPzo6erBMy9INMLnaktW6Z g2JTLQvVAQeMXrvLZzdTv66hMgbs786OSaiaPU5vIdpIqYo9+prBRp3XZ 1gYFWnKyJU+vhqV6Mn4C6g+C8iDgZhwHOhYUMH2/TZD4433D6eGJ4wV+P 3FnA3KqmFaofTeWVMJ+q3Fc50vNEGBmpOb21k4fcBi6HdzDM+Mf8Sjah0 w==; X-CSE-ConnectionGUID: xf/xh1ygRbSJ4DanRJfXXw== X-CSE-MsgGUID: nJT56psGSaOIP6QEeT/t1Q== X-IronPort-AV: E=McAfee;i="6600,9927,11095"; a="31883375" X-IronPort-AV: E=Sophos;i="6.08,219,1712646000"; d="scan'208";a="31883375" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2024 11:04:32 -0700 X-CSE-ConnectionGUID: 7+a/ImkFSuKYq4D81JiMGA== X-CSE-MsgGUID: fLEw+7VUQS+oeVZ2UqNCIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,219,1712646000"; d="scan'208";a="38170025" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmviesa009.fm.intel.com with ESMTP; 06 Jun 2024 11:04:31 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, namhyung@kernel.org, irogers@google.com, jolsa@kernel.org, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kan Liang , "Khalil, Amiri" , stable@vger.kernel.org Subject: [PATCH V2] perf stat: Fix the hard-coded metrics calculation on the hybrid Date: Thu, 6 Jun 2024 11:03:16 -0700 Message-Id: <20240606180316.4122904-1-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kan Liang The hard-coded metrics is wrongly calculated on the hybrid machine. $ perf stat -e cycles,instructions -a sleep 1 Performance counter stats for 'system wide': 18,205,487 cpu_atom/cycles/ 9,733,603 cpu_core/cycles/ 9,423,111 cpu_atom/instructions/ # 0.52 insn per cycle 4,268,965 cpu_core/instructions/ # 0.23 insn per cycle The insn per cycle for cpu_core should be 4,268,965 / 9,733,603 = 0.44. When finding the metric events, the find_stat() doesn't take the PMU type into account. The cpu_atom/cycles/ is wrongly used to calculate the IPC of the cpu_core. In the hard-coded metrics, the events from a different PMU are only SW_CPU_CLOCK and SW_TASK_CLOCK. They both have the stat type, STAT_NSECS. Except the SW CLOCK events, check the PMU type as well. Fixes: 0a57b910807a ("perf stat: Use counts rather than saved_value") Reported-by: "Khalil, Amiri" Reviewed-by: Ian Rogers Signed-off-by: Kan Liang Cc: stable@vger.kernel.org --- Changes since V1: - Don't check the PMU of the SW CLOCK events tools/perf/util/stat-shadow.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 3466aa952442..6bb975e46de3 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -176,6 +176,13 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type if (type != evsel__stat_type(cur)) continue; + /* + * Except the SW CLOCK events, + * ignore if not the PMU we're looking for. + */ + if ((type != STAT_NSECS) && (evsel->pmu != cur->pmu)) + continue; + aggr = &cur->stats->aggr[aggr_idx]; if (type == STAT_NSECS) return aggr->counts.val; -- 2.35.1