Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1909327pxu; Tue, 24 Nov 2020 11:49:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzA6Rnwv9vTwLc1etHzvbxKBCDJv2+mbzzhJZyP3l9UtQo0khL+ZiWrHuOgh05X27/5rq+S X-Received: by 2002:a50:9b02:: with SMTP id o2mr127043edi.208.1606247364736; Tue, 24 Nov 2020 11:49:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606247364; cv=none; d=google.com; s=arc-20160816; b=ejUWVR7sXH1OvHPXD2fzKvwz1ACDPL6rdLWzWB77U0+MMnJvf81u+lhhrY0lafW4vG hLzixTKamhf4nf/ZQt1fLc0Ru1lOMBSo+nE4QbTPj4DKsWV6iXpajMBVCWfDDQFiO8tU erO72bLgsUE/ZFKw3fzhEIohBbU+ti8R6dKD7RZQtuUPPmPbj0QKV4wTCTYhnwnMhh90 9CSnC+iTqv2w0jkFINOi1ShxdSSs7OKdIR358nJXxW9sZPl6Qh07JD3o1FXxN9KkqoAK T5Q7/bVnNRnm31SQeEXzXm6efXUoJ2wdkw341+6QyCgRc8BoD9qph7ecfy6OqekL+Uol NSaw== 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=602FIqwWhz6vUm0jx2ZcCsqu08FcjrdaJmn8EM3RSdc=; b=pEctrpcqAZYUkcnZNYaE1WPlgicPbS3WmqNr53vZdNJl8jhIRgR18flH5lSImL1z7r C0zEtF4joq5MJ6WhmFJGYY9ITG9FPenlx/zaAJ9ctc6Xg8V0ipRBC/O4pzZnRQx3Dto9 yrYj88PWU3bCYDl9YdhgixOsDG9GiW6ju8yzjoZfr7IG6maqf4pNKwy5FtcHYybk/x6W 30lVU2JnOuYbO9dpwmCeHCuLFRjszHAwOhrkXe32s267iPQQ3Vwzu+EAqr0xcbuylQaa 1C6akLFGB7B/kG8y9ftqi0OlFc+fyQjCGd9/8raLy7hD37g8KygfDcO8VUn46NUScNpO LfMA== 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 n27si9176923eji.127.2020.11.24.11.49.02; Tue, 24 Nov 2020 11:49:24 -0800 (PST) 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 S1726715AbgKXEva (ORCPT + 99 others); Mon, 23 Nov 2020 23:51:30 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35509 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgKXEv3 (ORCPT ); Mon, 23 Nov 2020 23:51:29 -0500 Received: by mail-lj1-f195.google.com with SMTP id r18so5760944ljc.2 for ; Mon, 23 Nov 2020 20:51:28 -0800 (PST) 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=602FIqwWhz6vUm0jx2ZcCsqu08FcjrdaJmn8EM3RSdc=; b=Ea0YeT9YgeAlZn9Liv0jiqhNu4sg9x6ibX7Te7iJlYeaRI5yJAVSQIYZDxlX2/s3cJ U1ZG1OMiBR5JYSbE6dLcaymYmTB1R+MsmstBV0CLqIPgU1tjwDqVtq1iR4sGHhEXFFrZ 8jX5LvRmV1kRxy7ogjRhv1HXWn9HLNDH5Vg58sMgki2wt4Gh50S2qpUzvtyuCnSIoEDG M0xyzqBqmUijJNwrf5hC5OKtb+0igrYdb6KwUPERxno4K7zAPfKAXT9pY1TvpCiaffhh 67pHVCpsSiI6fHeyhQ4FEId3hKzADbJJWZt8chMVq41g5M5O7VVmQ1HThjTK4TZBVqTv ZGxw== X-Gm-Message-State: AOAM532rwbRCVdY9s/DqNVigLAgnwRLijDTylJD4nc+QrjEhywUekTkK NCTC8Fqc40mhEn28iULlaJcnSYrKoJqqPVAF7l0= X-Received: by 2002:a2e:84c7:: with SMTP id q7mr1051112ljh.415.1606193487259; Mon, 23 Nov 2020 20:51:27 -0800 (PST) MIME-Version: 1.0 References: <20201106212935.28943-1-kan.liang@linux.intel.com> <20201109095235.GC2594@hirez.programming.kicks-ass.net> <20201109110405.GN2651@hirez.programming.kicks-ass.net> <0a1db246-c34a-22a3-160c-3e0c0a38119d@linux.intel.com> <20201111162509.GW2611@hirez.programming.kicks-ass.net> <2dc483f6-7b29-c42b-13a4-4c549d720aa2@linux.intel.com> <87a6v81gou.fsf@mpe.ellerman.id.au> In-Reply-To: <87a6v81gou.fsf@mpe.ellerman.id.au> From: Namhyung Kim Date: Tue, 24 Nov 2020 13:51:15 +0900 Message-ID: Subject: Re: [PATCH 1/3] perf/core: Flush PMU internal buffers for per-CPU events To: Michael Ellerman Cc: "Liang, Kan" , Peter Zijlstra , Ingo Molnar , linux-kernel , Stephane Eranian , Ian Rogers , Gabriel Marin , Arnaldo Carvalho de Melo , Jiri Olsa , Andi Kleen , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Mon, Nov 23, 2020 at 8:00 PM Michael Ellerman wrote: > > Namhyung Kim writes: > > Hi Peter and Kan, > > > > (Adding PPC folks) > > > > On Tue, Nov 17, 2020 at 2:01 PM Namhyung Kim wrote: > >> > >> Hello, > >> > >> On Thu, Nov 12, 2020 at 4:54 AM Liang, Kan wrote: > >> > > >> > > >> > > >> > On 11/11/2020 11:25 AM, Peter Zijlstra wrote: > >> > > On Mon, Nov 09, 2020 at 09:49:31AM -0500, Liang, Kan wrote: > >> > > > >> > >> - When the large PEBS was introduced (9c964efa4330), the sched_task() should > >> > >> be invoked to flush the PEBS buffer in each context switch. However, The > >> > >> perf_sched_events in account_event() is not updated accordingly. The > >> > >> perf_event_task_sched_* never be invoked for a pure per-CPU context. Only > >> > >> per-task event works. > >> > >> At that time, the perf_pmu_sched_task() is outside of > >> > >> perf_event_context_sched_in/out. It means that perf has to double > >> > >> perf_pmu_disable() for per-task event. > >> > > > >> > >> - The patch 1 tries to fix broken per-CPU events. The CPU context cannot be > >> > >> retrieved from the task->perf_event_ctxp. So it has to be tracked in the > >> > >> sched_cb_list. Yes, the code is very similar to the original codes, but it > >> > >> is actually the new code for per-CPU events. The optimization for per-task > >> > >> events is still kept. > >> > >> For the case, which has both a CPU context and a task context, yes, the > >> > >> __perf_pmu_sched_task() in this patch is not invoked. Because the > >> > >> sched_task() only need to be invoked once in a context switch. The > >> > >> sched_task() will be eventually invoked in the task context. > >> > > > >> > > The thing is; your first two patches rely on PERF_ATTACH_SCHED_CB and > >> > > only set that for large pebs. Are you sure the other users (Intel LBR > >> > > and PowerPC BHRB) don't need it? > >> > > >> > I didn't set it for LBR, because the perf_sched_events is always enabled > >> > for LBR. But, yes, we should explicitly set the PERF_ATTACH_SCHED_CB > >> > for LBR. > >> > > >> > if (has_branch_stack(event)) > >> > inc = true; > >> > > >> > > > >> > > If they indeed do not require the pmu::sched_task() callback for CPU > >> > > events, then I still think the whole perf_sched_cb_{inc,dec}() interface > >> > > >> > No, LBR requires the pmu::sched_task() callback for CPU events. > >> > > >> > Now, The LBR registers have to be reset in sched in even for CPU events. > >> > > >> > To fix the shorter LBR callstack issue for CPU events, we also need to > >> > save/restore LBRs in pmu::sched_task(). > >> > https://lore.kernel.org/lkml/1578495789-95006-4-git-send-email-kan.liang@linux.intel.com/ > >> > > >> > > is confusing at best. > >> > > > >> > > Can't we do something like this instead? > >> > > > >> > I think the below patch may have two issues. > >> > - PERF_ATTACH_SCHED_CB is required for LBR (maybe PowerPC BHRB as well) now. > >> > - We may disable the large PEBS later if not all PEBS events support > >> > large PEBS. The PMU need a way to notify the generic code to decrease > >> > the nr_sched_task. > >> > >> Any updates on this? I've reviewed and tested Kan's patches > >> and they all look good. > >> > >> Maybe we can talk to PPC folks to confirm the BHRB case? > > > > Can we move this forward? I saw patch 3/3 also adds PERF_ATTACH_SCHED_CB > > for PowerPC too. But it'd be nice if ppc folks can confirm the change. > > Sorry I've read the whole thread, but I'm still not entirely sure I > understand the question. Thanks for your time and sorry about not being clear enough. We found per-cpu events are not calling pmu::sched_task() on context switches. So PERF_ATTACH_SCHED_CB was added to indicate the core logic that it needs to invoke the callback. The patch 3/3 added the flag to PPC (for BHRB) with other changes (I think it should be split like in the patch 2/3) and want to get ACKs from the PPC folks. Thanks, Namhyung