Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3222615pxb; Tue, 20 Apr 2021 03:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRaLUyHyLcwgKqibfIDrUuqzP/ftQ1Pi6+hnklIEEnGNLNuh0GEnLZehh2z+BjkC6Du1LJ X-Received: by 2002:a05:6402:51d4:: with SMTP id r20mr31470913edd.112.1618914655631; Tue, 20 Apr 2021 03:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618914655; cv=none; d=google.com; s=arc-20160816; b=ln2K5kiri56icwIOBVAVCxp8S8AE/NRb5Oemuuih5cfCkv0aTPOAygfiz1mECdbw/R GVSkto9OFS7/AwMSJRSd1fM32axPzsCW3wYCaIqxi0tJMyMcN2OIOLoMhq7WxWyw88cN DGqhS4qajA/nzoUW6If1ut7uWqcgBOeKS5xCBCjJjMCAkR5XHFgh2Vac6AjTDmWhdRkZ 4kJuDt15L57whXTWaUZ719BavEd1tF8Djb3bK+UDN/rW+ZV63S78cB+W7WHaFKUVtCkT El5BAoClUatgzJi/w54/7IfH5Pgv4bwnKOaONCalLaAAmQy96g2GUFKA4hpe0TWbNscA 5U6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7yvM6pYzBdl1pwAS1vOZXn92e4fG6hqABm03un7jGEY=; b=ENWjbf6mYN8WZSWuVClTAz8C3mqOTE15JCkeHLgeVgt81w2TUVPmW3cp12K4I41dL7 RouN7GKtTvFrlUPCBpbumZl/+3jVyoB0nquk7p7zyZZrZPU89ePwDI7ujyQPOb13nCgS Ds38w9hgT3BLdUPf1xC0pAGoTbxnA/O9T4163NNcQLx967fHmK/Rye6DrgbvFdVAROgL SPQOUOK/KNkigFxYe1Td65/8xs2U1MxV2fXviMN2NuwC4SP2g93e1Yo0cIUekhwwVn1Z zvphwtq2uMcbRnmNAThiw3tX5rX6my8xLNgjNXZJ2IwzcY26qdUCOUxHRQTUexy+1gV9 CYiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DySRbJzx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si14140004eje.57.2021.04.20.03.30.32; Tue, 20 Apr 2021 03:30:55 -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=@infradead.org header.s=desiato.20200630 header.b=DySRbJzx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbhDTK3g (ORCPT + 99 others); Tue, 20 Apr 2021 06:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbhDTK3e (ORCPT ); Tue, 20 Apr 2021 06:29:34 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E323C06138A for ; Tue, 20 Apr 2021 03:29:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7yvM6pYzBdl1pwAS1vOZXn92e4fG6hqABm03un7jGEY=; b=DySRbJzxWjR3dFFRXhVsSB9n7X lFEfEUPPX/Zn3KLaDEmuq1i5niTBWj7Skf73DDQWesSlHL2w2sBbonaMdsWGynZz1oBjK+BP06cgN hoikbJ+jArK00fe5kK/1h7CRVg9r+Jf9Xj6eXzj3eSGiJLukVmCrcspSl/nTuKhJ6Xi2T9Bc/HaIg MsCVfSCBbJ3Pmbaz7QnTSnVWxawIycpV3e4DiPYf5AHwIeaSL+bG8MlgfeBry3m656r6HyVMBLuR0 UPTld7lc6pQ0H1n1YrYJZ3bh7p0T0lUPz6LfixxbNkwUwiMmsUnIwW+MgiII7OrmfQOUEfxTqNOra UUu7yKhg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYncb-00Bsln-U2; Tue, 20 Apr 2021 10:28:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CD73F30020C; Tue, 20 Apr 2021 12:28:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B736D2C48E3A3; Tue, 20 Apr 2021 12:28:44 +0200 (CEST) Date: Tue, 20 Apr 2021 12:28:44 +0200 From: Peter Zijlstra To: Namhyung Kim Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Andi Kleen , Ian Rogers , Song Liu , Tejun Heo , kernel test robot , Thomas Gleixner Subject: Re: [PATCH v3 1/2] perf/core: Share an event with multiple cgroups Message-ID: References: <20210413155337.644993-1-namhyung@kernel.org> <20210413155337.644993-2-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 06:49:09PM +0900, Namhyung Kim wrote: > On Thu, Apr 15, 2021 at 11:51 PM Peter Zijlstra wrote: > > > +static void perf_update_cgroup_node(struct perf_event *event, struct cgroup *cgrp) > > > +{ > > > + u64 delta_count, delta_time_enabled, delta_time_running; > > > + int i; > > > + > > > + if (event->cgrp_node_count == 0) > > > + goto out; > > > + > > > + delta_count = local64_read(&event->count) - event->cgrp_node_count; From here... > > > + delta_time_enabled = event->total_time_enabled - event->cgrp_node_time_enabled; > > > + delta_time_running = event->total_time_running - event->cgrp_node_time_running; > > > + > > > + /* account delta to all ancestor cgroups */ > > > + for (i = 0; i <= cgrp->level; i++) { > > > + struct perf_cgroup_node *node; > > > + > > > + node = find_cgroup_node(event, cgrp->ancestor_ids[i]); > > > + if (node) { > > > + node->count += delta_count; > > > + node->time_enabled += delta_time_enabled; > > > + node->time_running += delta_time_running; > > > + } > > > + } ... till here, NMI could hit and increment event->count, which then means that: > > > + > > > +out: > > > + event->cgrp_node_count = local64_read(&event->count); This load doesn't match the delta_count load and events will go missing. Obviously correct solution is: event->cgrp_node_count += delta_count; > > > + event->cgrp_node_time_enabled = event->total_time_enabled; > > > + event->cgrp_node_time_running = event->total_time_running; And while total_time doesn't have that problem, consistency would then have you do: event->cgrp_node_time_foo += delta_time_foo; > > > > This is wrong; there's no guarantee these are the same values you read > > at the begin, IOW you could be loosing events. > > Could you please elaborate? You forgot NMI.