Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp78340pxf; Tue, 23 Mar 2021 22:49:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP2fs3ig2MAE7W+QB02608BzrF60+VT8f7hwKrtz99Ta/mp5Iqs0UjcyyFcPwvKPE7cHuf X-Received: by 2002:aa7:c98f:: with SMTP id c15mr1560767edt.231.1616564986359; Tue, 23 Mar 2021 22:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616564986; cv=none; d=google.com; s=arc-20160816; b=VZdRhPAoTO4y0az2uS5yZODTISmCEMeJuwALBuI9rBOjLzPxnrVPRjjRZPf6iHsGIw e3Yacrxv/wTUa/E0yoQpoezMWIweOuc5to+9O7UZc2zY2W5pQp1EIHDt6f30KavH8/DW Nka8UeA2ZGLiLA+vmN517HzyqFwQc2vWDCnlKFu+P+gzI9DGlD8NeZQlweC5xZfUxVqS zhoG59gTCK//q9KJqMeagACRK2QXac61dRL38+UqfrRplbnt45FJCGruPMAv/QLRdBYH PBU08PJUyWvgQXPHbIKG+y3seizw+rkNw/KNuDF+aFJ5Dks7AKFWgq7DXJasUn/9jhdG R0zg== 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:sender:dkim-signature; bh=+Ebklfl3SHR/N104RwQtLuvRpZ2abvFafvN8X7QJACg=; b=SQQ5Tgtsz15gxUd1nYMGjz21EGMYkCHwDE/eXoaeSZ4nVMyykZ0f5DvAUYvi/6k9FN p2v5qYcbndncJoy0EoihxbeBkhr6Os43BnbUhMo8oHA4z4x2M/eJhQzxDYegqMrSWM2J FRelVGKXghgKGMvDXAZ2oD+TAauHfzOLuOZJX8ZbqLcG8PbYpX3lcoqjzF2latXtAJCN XrIMGKRxKfiGJLXniqObR3MOHlLP5VqzToMBEKnCSdtCYylrzerHN/0QdhNRUXXuTQ2J wTgn6VpO+hoTsw53Kq2ih27zeGphpMc/08LWD5b2jcS6b9QhTQtHaiRvpfDiWkabKrE1 CqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DcWKUsGm; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si965384ejx.646.2021.03.23.22.49.24; Tue, 23 Mar 2021 22:49:46 -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=@gmail.com header.s=20161025 header.b=DcWKUsGm; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233208AbhCWQWg (ORCPT + 99 others); Tue, 23 Mar 2021 12:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233030AbhCWQWD (ORCPT ); Tue, 23 Mar 2021 12:22:03 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 135B9C061574 for ; Tue, 23 Mar 2021 09:22:03 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id v186so12222785pgv.7 for ; Tue, 23 Mar 2021 09:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+Ebklfl3SHR/N104RwQtLuvRpZ2abvFafvN8X7QJACg=; b=DcWKUsGmP3cKyAx1vWNeOGsSmNWJk/jR0RilrqN8DKg4yjX+UA9xJFYYeAnyMvFIXd An2HwChhjiU9u9uoquaEj8Gw/dlbttD9yCbSzlwk54jUR1cylEpSOL0LsQu+R+uy/5gb BSEJlWem4hoz9sz6HArDkX3W4YRLh0bwp9XGgiorleDDmKjNKYImSyiqL6Foy9/CvQ94 wjBbyO6s3+YSJ5CuavjieAqmYBVEkRA2FdywmaRjQs6YKoP+ndSsPfjjRTiHa4yS4oUC yH2AOxTLtdKP/JckH3SKkOrx+zBdYD4LcIixq/1iySWQiRAyGGNnyxEe6dg0q+uFFkYO RNrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=+Ebklfl3SHR/N104RwQtLuvRpZ2abvFafvN8X7QJACg=; b=QjulNU3WJzSqZl/KDC8EO0DzWkwDC0nx0RigFChARgWHcvkYMy8wv85r5jf7GJT7En 0Fu0tCPayojmp+pn7a3n9dpQ6QohFJuwGz9Y9Ky0nKbMQ5NNbYgHe50FkhDf9cvl8Z9q cD0rVkymegmalsX1AEJztfdx7Xauo0BUwP9tOW+WR8G0rgIklzkyMPnQWqzFYSFwzo4k rJNyMcpV/iH5IpYV1DMuYZeTFWkGAsYcO4L4OFtaYBkh9tuaQ3woJe8zkrrL/ZIH602f 4Cfx+7C9C02lshb5PFTP58FdgxoIRo7yimVxYIgHrstVaFrptGlS4mB5prkRxxmo49L9 aPyA== X-Gm-Message-State: AOAM5308wXb/SAToJOQe+k5khba13Cn141HPY6DdD99YgXUL/sB93YPL sjwRs52Mehw7BQ5Xt2b0FqI= X-Received: by 2002:a17:902:f28b:b029:e4:5039:9f03 with SMTP id k11-20020a170902f28bb02900e450399f03mr6781693plc.62.1616516522679; Tue, 23 Mar 2021 09:22:02 -0700 (PDT) Received: from balhae.roam.corp.google.com ([101.235.31.111]) by smtp.gmail.com with ESMTPSA id e6sm5615766pfc.159.2021.03.23.09.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 09:22:02 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Andi Kleen , Ian Rogers , Song Liu Subject: [RFC 0/2] perf core: Sharing events with multiple cgroups Date: Wed, 24 Mar 2021 01:21:54 +0900 Message-Id: <20210323162156.1340260-1-namhyung@kernel.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, This work is to make perf stat more scalable with a lot of cgroups. Currently we need to open a separate perf_event to count an event in a cgroup. For a big machine, this requires lots of events like 256 cpu x 8 events x 200 cgroups = 409600 events This is very wasteful and not scalable. In this case, the perf stat actually counts exactly same events for each cgroup. I think we can just use a single event to measure all cgroups running on that cpu. So I added new ioctl commands to add per-cgroup counters to an existing perf_event and to read the per-cgroup counters from the event. The per-cgroup counters are updated during the context switch if tasks' cgroups are different (and no need to change the HW PMU). It keeps the counters in a hash table with cgroup id as a key. With this change, average processing time of my internal test workload which runs tasks in a different cgroup and communicates by pipes dropped from 11.3 usec to 5.8 usec. Thanks, Namhyung Namhyung Kim (2): perf/core: Share an event with multiple cgroups perf/core: Support reading group events with shared cgroups include/linux/perf_event.h | 22 ++ include/uapi/linux/perf_event.h | 2 + kernel/events/core.c | 588 ++++++++++++++++++++++++++++++-- 3 files changed, 585 insertions(+), 27 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog