Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3226186ybg; Sun, 20 Oct 2019 09:18:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEzBvowUEDoCNjnFpkbPQOYpCqEl4ZCDlwx1lL85efsFgWrPA71i/Lu1gJLNjR6O6DJtnE X-Received: by 2002:a05:6402:503:: with SMTP id m3mr20535158edv.157.1571588316170; Sun, 20 Oct 2019 09:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571588316; cv=none; d=google.com; s=arc-20160816; b=sb1OLmhhUSFsjM90d/bO/N9hUo0E1A8zUPtDn2XVYiPVtyw8CC712KvYAKu5ajf176 eKKbiEIHr5v73L+YLie2qR8NzqwxtQL5zNFxFflDeJ93COrCm1hTr+mG+fNqq+Lqhj5u EYTLmskzjaHSmc/tXsD8dzvneiTGkvfxI7P4mUlTaqFkyH0ILjbIzebLQ+VJMyTImhYI itx647aqYtiM1MzONgQE9Sk0KnNH8ZGZHmabTHg2EA3KpqNsPTixBY/ZXHYiotSbvkes ckz8wGXafOpN+sDCr0jNoa8jX4fvtUuXYLF8OvW5kS4PwXSYTlSUhz7Ie9UbLFXjjgEH Kq0A== 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:mime-version :message-id:date:subject:cc:to:from; bh=a2qtUd7NSRrgfXDBVDZyGygcNseQBKEx5Z16MTmlHt8=; b=OZSc75s5KFRmPBHAeeGnSytPwrAiojz64taewqcUOzxIrmT55IzmxdKdpGGHUeHgPE YfEcI5c0dzbcjl2cX4rSGCMjJyFLC1oxkCO7nh/QTtq8jpuq/iYKvnRpPCpZWLWTih4r OTpnyvXP/YDl2HdGN/VUb6UDoEWgAR0rqolP6YDRJspgLVQeBSY41TbmE32TPl3K1XRR 7qpj+/B7gIov1+WzSYJyBxou+mWbRWyLnIG0Gy1bEr5cp38dqWKo5iqlkzORV6Qt4bUx 9/vujDch/fcmNIpNnKaZxZYUkVWN48AyRO1b8tu4Chypnpn+5LhRlWF19lrQWc8K80Yo lHEw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gw6si7098945ejb.176.2019.10.20.09.18.12; Sun, 20 Oct 2019 09:18:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726561AbfJTQN7 (ORCPT + 99 others); Sun, 20 Oct 2019 12:13:59 -0400 Received: from mga17.intel.com ([192.55.52.151]:25889 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbfJTQN7 (ORCPT ); Sun, 20 Oct 2019 12:13:59 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2019 09:13:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,320,1566889200"; d="scan'208";a="195909354" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by fmsmga008.fm.intel.com with ESMTP; 20 Oct 2019 09:13:58 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id 229A43002BE; Sun, 20 Oct 2019 09:13:58 -0700 (PDT) From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, eranian@google.com, kan.liang@linux.intel.com, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: Optimize perf stat for large number of events/cpus v1 Date: Sun, 20 Oct 2019 09:13:37 -0700 Message-Id: <20191020161346.18938-1-andi@firstfloor.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch kit optimizes perf stat for a large number of events on systems with many CPUs and PMUs. Some profiling shows that the most overhead is doing IPIs to all the target CPUs. We can optimize this by using sched_setaffinity to set the affinity to a target CPU once and then doing the perf operation for all events on that CPU. This requires some restructuring, but cuts the set up time quite a bit. In theory we could go further by parallelizing these setups too, but that would be much more complicated and for now just batching it per CPU seems to be sufficient. At some point with many more cores parallelization or a better bulk perf setup API might be needed though. In addition perf does a lot of redundant /sys accesses with many PMUs, which can be also expensve. This is also optimized. On a large test case (>700 events with many weak groups) on a 94 CPU system I go from real 0m8.607s user 0m0.550s sys 0m8.041s to real 0m3.269s user 0m0.760s sys 0m1.694s so shaving ~6 seconds of system time, at slightly more cost in perf stat itself. On a 4 socket system with the savings are more dramatic: real 0m15.641s user 0m0.873s sys 0m14.729s to real 0m4.493s user 0m1.578s sys 0m2.444s so 11s difference in the user visible set up time. Also available in git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc perf/stat-scale-3 v1: Initial post. -Andi