Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp24010pxy; Tue, 20 Apr 2021 11:38:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwxCXB1NL67hWZmRVQIuwR5prduhsppN4zKTsc4DWq9pKDF79b4LRkErrdghZwsnfdp7Hh X-Received: by 2002:a62:7cc7:0:b029:25a:cb9f:1c9 with SMTP id x190-20020a627cc70000b029025acb9f01c9mr19543092pfc.71.1618943893373; Tue, 20 Apr 2021 11:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618943893; cv=none; d=google.com; s=arc-20160816; b=OzioxW4yIsGv40Udll9WH5urTX2M+HgFQxLU01fWepiLoEgFQtn7DustrvzdFapAjz bXilsjgKsgcsWNN09d6QbkQg/9AsvZh269i6rVCwiXDsoxWJ3VAye0+urnDx8W9HTC4I WisSZvHvhobDGRKMZBJB9srSq33dwAnOrTVmuFW2b9+NfA+lA5Bc8hrZoaj5lNtKzkUv Vk5T8II5afBfDv3hWrFHmCWFVosQpNFUSdAvBwm2s8fKqVGH8PaYJs8U5XGq7B1cg94c vRhJHVKXYhjq0O8bNmk6N2nIGGsY/HlL+xCq1gDoGpyB7Okz+qikhwBxkaB+z2Zawm86 ibLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=lStF9MK/8yS06upemmH0HWNt9F0SraomB6Sr+wgIJH8=; b=WT7o4Rgpu2BWlZWwc0VVw6GdtrPnQv+c5qYazFHfF2EXVqxqiOlrTart1sAdx2YCyx 38QyINboypgII+YbcL8lPvP3EA6OfALL+GW1cUoOQE5bZeOgW7ATD3vA8QR9PullDyXV aKxQhKrN/ABBa7/qvfao//PoGsqSximepcPHXFrn++6/tqcZGrea3qULAH8OBYhwyZLx hTwr0SuMT8rIHIbrrY9vcUkV5DfWrOSkspyjgn1EdVmCAk0sg1AhvT8Y7oyVM74j13Eo sXDmPxpQ3gEeal+ZEX5fBN70lh80Hf3urdnh9/H04fK/0/TWsQlM4JBKZY1zIcexZKO6 v7bw== ARC-Authentication-Results: i=1; mx.google.com; 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 z22si21298934pga.97.2021.04.20.11.38.00; Tue, 20 Apr 2021 11:38:13 -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; 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 S233513AbhDTSh4 (ORCPT + 99 others); Tue, 20 Apr 2021 14:37:56 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:41644 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233363AbhDTSh4 (ORCPT ); Tue, 20 Apr 2021 14:37:56 -0400 Received: by mail-lf1-f44.google.com with SMTP id q22so522358lfu.8 for ; Tue, 20 Apr 2021 11:37:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lStF9MK/8yS06upemmH0HWNt9F0SraomB6Sr+wgIJH8=; b=fcycPbNul/XOWSjyDY3MdGKW8LDAIzRgNIHoKGt2ZE43jTuPvh4luhcy0/u+ERs5nZ NH7DVF6zn/kMg+mFcRSdoaty6hLvxAkNlHd9+DdbSOcK9NVujIC2f3RQoxKIb1KClwkQ epNUGGXaPlqaiP7mJHhefAK/I7gd/4yDgxjANWb2H1GeO3z8mJ2wJ9312BA88FDaxHlQ dlmSTlCIGYmnMBwEXEvY6nYI4C5y0ta43y+2ZyGB6cCj1+0EkcgzgXh4/MFIUyjiLLbu whe4IA27q0KQZrJjuOPLzViDW1jaEhyVwsI/Q4RPW9LYfZ6ttvViAW05KQ409GIP3U79 cUXQ== X-Gm-Message-State: AOAM530FlKo+lWoa/mQJC5rvsiQ7nAqxfPvqKnZxDT5vPlvtL2sE8+il eIFs+9DxhPWp8RwcdkfiizV4b3f4YRUaO5JFKeM= X-Received: by 2002:a19:9106:: with SMTP id t6mr13839417lfd.300.1618943843573; Tue, 20 Apr 2021 11:37:23 -0700 (PDT) MIME-Version: 1.0 References: <20210413155337.644993-1-namhyung@kernel.org> <20210413155337.644993-2-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Wed, 21 Apr 2021 03:37:11 +0900 Message-ID: Subject: Re: [PATCH v3 1/2] perf/core: Share an event with multiple cgroups 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 , Tejun Heo , kernel test robot , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Tue, Apr 20, 2021 at 7:28 PM Peter Zijlstra wrote: > > 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. Thanks for your explanation. Maybe I'm missing something but this event is basically for counting and doesn't allow sampling. Do you say it's affected by other sampling events? Note that it's not reading from the PMU here, what it reads is a snapshot of last pmu->read(event) afaik. Thanks, Namhyung