Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2725434rdb; Wed, 4 Oct 2023 09:32:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIGoLps18WQ0sJJkFR6VtmZehy643o54g8ldWbtMEEUWpmfdfvoLWuEkAZgqP4NJikVft/ X-Received: by 2002:a17:903:2451:b0:1c8:7364:a3ab with SMTP id l17-20020a170903245100b001c87364a3abmr3015549pls.17.1696437171120; Wed, 04 Oct 2023 09:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696437171; cv=none; d=google.com; s=arc-20160816; b=M7Nftr7Un+IkoIIM2KMv7/j1kBNVW0KJYFU3Rfa/5MEdPrLm4KzR80Zz5Ao2vUeMIM BRZbLAkXjLPY1Bq7iLCCdSq9JCeICjfnd7tysQtBIKcV4spT9QH1m8J+atr7RmLDzEWH b36cVWsOkPv9cliVHLyD7BSuIKVHoRV8wiSkWDYbygud9+4abdKihnqxC0+WQZNYS/dd LTfxRKsnfX/J7Xu4PdfbQflk8t0H01MhQlyToA8rFzhanCqAk5PxJnUKuWiknDxbn2R1 e38Ycr2jWOTIYwU/SXV5SLB5wqmFd4Vi1yIwJoHsv/bzAerqkMVr+OPrZQ7kS/m5YkZQ 9iXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=4QcQ+guWY1gCpe4z2nlVJ6CU/7BKngXheXIUuiLHjfs=; fh=0JnCpCnN9GAn/HU+tGYhP4h78bQbJJUrVd+YrGKptf0=; b=DvhSdcUFFo3ygxu4N2afArtyz4LrGzlvfY9Xsk18O0ADPU5gJ8nTovQaTmP1hRFf2S 5padnhwudnmTs22lcp2TZ4Cy0Ec+Ol3muvkhpCgLjHiTifzJw3R3ie7rUNERuRMfdUcq Upe8FW48k7qA26SfGcy5Ldp649KvhF0JVajmelvPSj9JOPjcVIGswrr9kF/9nhqixrgn GsZ4fgWN0/bPX037dM+RtPliT+8MOs/qkQwN9o5ibvAZ4CZJwftDKM9WB/kTL+FgeBAH Hz1Z1Lm/kmx/SmNepG1Nt9MZT/4eH0rgI1Umm2pNfY+l4S9mkgF1MjvK/Z7oZKujjY6U 9+bA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ko8-20020a17090307c800b001c604fdbb14si3689594plb.81.2023.10.04.09.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C70CA809B754; Wed, 4 Oct 2023 09:32:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243359AbjJDQcm convert rfc822-to-8bit (ORCPT + 99 others); Wed, 4 Oct 2023 12:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243290AbjJDQcl (ORCPT ); Wed, 4 Oct 2023 12:32:41 -0400 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86919B; Wed, 4 Oct 2023 09:32:37 -0700 (PDT) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-690ba63891dso1860468b3a.2; Wed, 04 Oct 2023 09:32:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696437157; x=1697041957; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bpOILGaPzFme8eJnGnR7nEZgZ9N3yDhRVdNPBjXB47c=; b=b+YejCkoEdwopGfDPgAGjaHWPvDM7ZsfMdewoH0wvRXcHLwmEYmxGZjCs4/B6uTG+n 7q5xNNGxTaaM0fcpI3dpuVMlza53HXHvmj8T6L5SfDngig1vF26ezuREEEpnhTAmY588 5DcJHripshVPKqMH9sPip8SvIS7vZW7/rTaAhk+ewlUBDyaNgL9n4bg9fpRPuU9NPS65 2zXcts/gycDWv3+W0BDTvXmUR1C76WVFTRqDZ3a5+IVmOOMVGrW6DOUrlO2hEDuLy4Ih aGe/Sc3m4tmxISMVTpFQSBe8orm8mcAn9cw+KC9Z7VnyIv0TxCnduA5Hstc4rdYatBk/ wJpA== X-Gm-Message-State: AOJu0YzeHq1VCiiP9/oqS8dPVoOp+bM7pX38Suop24+pWgG3VeyUjIUL NfKkQivw20gqJCOoZ8oOrUDbgyEKARFUda/Lms0= X-Received: by 2002:a17:90b:1047:b0:277:6985:a3ff with SMTP id gq7-20020a17090b104700b002776985a3ffmr2429510pjb.3.1696437156981; Wed, 04 Oct 2023 09:32:36 -0700 (PDT) MIME-Version: 1.0 References: <20231004040844.797044-1-namhyung@kernel.org> <20231004160224.GB6307@noisy.programming.kicks-ass.net> In-Reply-To: <20231004160224.GB6307@noisy.programming.kicks-ass.net> From: Namhyung Kim Date: Wed, 4 Oct 2023 09:32:24 -0700 Message-ID: Subject: Re: [PATCH] perf/core: Introduce cpuctx->cgrp_ctx_list To: Peter Zijlstra Cc: Ingo Molnar , Mark Rutland , Alexander Shishkin , Arnaldo Carvalho de Melo , LKML , Stephane Eranian , Kan Liang , Ravi Bangoria , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 04 Oct 2023 09:32:48 -0700 (PDT) Hi Peter, On Wed, Oct 4, 2023 at 9:02 AM Peter Zijlstra wrote: > > On Tue, Oct 03, 2023 at 09:08:44PM -0700, Namhyung Kim wrote: > > > But after the change, it ended up iterating all pmus/events in the cpu > > context if there's a cgroup event somewhere on the cpu context. > > Unfortunately it includes uncore pmus which have much longer latency to > > control. > > Can you describe the problem in more detail please? Sure. > > We have cgrp as part of the tree key: {cpu, pmu, cgroup, idx}, > so it should be possible to find a specific cgroup for a cpu and or skip > to the next cgroup on that cpu in O(log n) time. This is about a single (core) pmu when it has a lot of events. But this problem is different, it's about accessing more pmus unnecessarily. Say we have the following events for CPU 0. sw: context-switches core: cycles, cycles-for-cgroup-A uncore: whatever The cpu context has a cgroup event so it needs to call perf_cgroup_switch() at every context switch. But actually it only needs to resched the 'core' pmu since it only has a cgroup event. Other pmu events (like context-switches or any uncore event) should not be bothered by that. But perf_cgroup_switch() calls the general functions which iterate all pmus in the (cpu) context. cpuctx.ctx.pmu_ctx_list: +-> sw -> core -> uncore (pmu_ctx_entry) Then it disables pmus, sched-out current events, switch cgroup pointer, sched-in new events and enable pmus. This gives a lot more overhead when it has uncore pmus since accessing MSRs for uncore pmus has longer latency. But uncore pmus cannot have cgroup events in the first place. So we need a separate list to keep pmus that have active cgroup events. cpuctx.cgrp_ctx_list: +-> core (cgrp_ctx_entry) And we also need a logic to do the same work only for this list. Hope this helps. > > > To fix the issue, I restored a linked list equivalent to cgrp_cpuctx_list > > in the perf_cpu_context and link perf_cpu_pmu_contexts that have cgroup > > events only. Also add new helpers to enable/disable and does ctx sched > > in/out for cgroups. > > Adding a list and duplicating the whole scheduling infrastructure seems > 'unfortunate' at best. Yeah, I know.. but I couldn't come up with a better solution. Thanks, Namhyung