Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp159469pxu; Wed, 2 Dec 2020 18:13:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8ZGAW3g3eXxIOAi++JerNKjADBc00DXzjDTvNja+zqJ91QYC+Cv5ZOeiS2tNZw5j9FApF X-Received: by 2002:a50:b586:: with SMTP id a6mr895851ede.206.1606961596025; Wed, 02 Dec 2020 18:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606961596; cv=none; d=google.com; s=arc-20160816; b=JWRZY73qkq+icg9qB1S+UDz7Vx0BRIldYKzrs8TPrqtDEsyeY/7tfgssnj2yryi/ON MbVhEioA2YLj9hzqXMUJUn6a0DChhsQJhogDYf4i1Ug8ZqIQ39Z3jr0eVNnGE37yv1qy +DcnpAzYBfVdCpHVOx3lSVyViiw+oehv0vifP5AKXYvpjmkIxq/MUKdaNN18aFvEJfYg qztDIuKK2DZT5ch5GIPvMB1rVejPqgftBh9FAaYcjFa3+jO/OG1fZ/Mvl0bgV9ARrw2G se38VuE3fHwMEtQgf7PTX7ToXcl26FMG9ViPJtJU1KnTE8zLCJ9i6s7sQ/zJygHKl/Hb GtHg== 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=CODcqWU9dJfympMWTdQNPabcVNI+FJqAgdc2bmt5Tvw=; b=zlYOzldHuHFuHfN2Tk0+4n4uslAIMoI7qhxxjINr2/wS01lj9aoAdNc+Orq42EsHp9 FBJ4e3Fk+ytEYoFfihER4j31ZbpHUj5zCSEA/AF9xXGcaXiK3GtHKim1WYM45QhiIQFF XP/sQQz3tlr+ltY+bKTYQ7P6gb8aPkKdAQ/7gLuM3CtGyE+/nrJFflIj75jqfxYXSjdk pQ8PY2qGIJz8g0oXgsaUusAQZ4qKCDwdVcrYYNVGTgD7uRsYzOR/4Zq8khbHZVQydoVa 8v9j51nb+06VMWkI0ZHy7B+CUEWbcbt8SnWc3OjNPoGyvJN9C6IQ35y/8eYjkkAqAuQw JJEw== 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 j10si97993edt.142.2020.12.02.18.12.52; Wed, 02 Dec 2020 18:13:16 -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 S1729500AbgLCCLZ (ORCPT + 99 others); Wed, 2 Dec 2020 21:11:25 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:35950 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725893AbgLCCLY (ORCPT ); Wed, 2 Dec 2020 21:11:24 -0500 Received: by mail-lf1-f65.google.com with SMTP id v14so454352lfo.3 for ; Wed, 02 Dec 2020 18:11:08 -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=CODcqWU9dJfympMWTdQNPabcVNI+FJqAgdc2bmt5Tvw=; b=TFDNVj+kAvjOQR3hqqAKwisSqi3bGJXbiuJXdAUKKXqvOCQaQjhFqBkHHNcSH+2nkl ST5ZbY0+ZJSEcAVYm8pvlnkR4EmsPXEuPeBk/RydRcVXIRUcSPrkMUKtYJlWMsc3sLB6 ZGc0TUnpnEBjEPeLtMIlb5BV2Ets+usl62DmrRnMVHyg7eveb0ajcPn5GLbHrC7H1+lr AsM9mW5quBlbNwHxVSNGdSFGOI8OS5uB07WE5NVrO0KfX52ommXUr4Rr7Ipl/K/I9Xi1 oNmNhDvfTgZx4rp+GVdOnp9T2TYO8PQvsGeK/0uOxPe5rSEhudwAJwjpD0CXwQZhX7Z8 P8SA== X-Gm-Message-State: AOAM532lDF28Jpw0PvrH5/Jf41sUSO9xSD5wk0f7lVRbi/53uHwxcYn3 Da6oIutZ5H9YJ8yqQFgPFcYlhYUnr/yYti7UEzE= X-Received: by 2002:a19:38e:: with SMTP id 136mr367231lfd.593.1606961442392; Wed, 02 Dec 2020 18:10:42 -0800 (PST) MIME-Version: 1.0 References: <20201202150205.35750-1-namhyung@kernel.org> <20201202161934.GL3021@hirez.programming.kicks-ass.net> In-Reply-To: <20201202161934.GL3021@hirez.programming.kicks-ass.net> From: Namhyung Kim Date: Thu, 3 Dec 2020 11:10:30 +0900 Message-ID: Subject: Re: [RFC 1/2] perf core: Add PERF_COUNT_SW_CGROUP_SWITCHES event To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Ian Rogers , Andi Kleen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 3, 2020 at 1:19 AM Peter Zijlstra wrote: > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index 9a38f579bc76..5eb284819ee5 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -1174,25 +1174,19 @@ DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]); > * which is guaranteed by us not actually scheduling inside other swevents > * because those disable preemption. > */ > -static __always_inline void > -perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) > +static __always_inline void __perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) It'd be nice to avoid the __ prefix if possible. > { > - if (static_key_false(&perf_swevent_enabled[event_id])) { > - struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]); > + struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]); > > - perf_fetch_caller_regs(regs); > - ___perf_sw_event(event_id, nr, regs, addr); > - } > + perf_fetch_caller_regs(regs); > + ___perf_sw_event(event_id, nr, regs, addr); > } > > extern struct static_key_false perf_sched_events; > > -static __always_inline bool > -perf_sw_migrate_enabled(void) > +static __always_inline bool __perf_sw_enabled(int swevt) Ditto. > { > - if (static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_CPU_MIGRATIONS])) > - return true; > - return false; > + return static_key_false(&perf_swevent_enabled[swevt]); > } > > static inline void perf_event_task_migrate(struct task_struct *task) > @@ -1207,11 +1201,9 @@ static inline void perf_event_task_sched_in(struct task_struct *prev, > if (static_branch_unlikely(&perf_sched_events)) > __perf_event_task_sched_in(prev, task); > > - if (perf_sw_migrate_enabled() && task->sched_migrated) { > - struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]); > - > - perf_fetch_caller_regs(regs); > - ___perf_sw_event(PERF_COUNT_SW_CPU_MIGRATIONS, 1, regs, 0); > + if (__perf_sw_enabled(PERF_COUNT_SW_CPU_MIGRATIONS) && > + task->sched_migrated) { It seems task->sched_migrate is set only if the event is enabled, then can we just check the value here? > + __perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0); > task->sched_migrated = 0; > } > } > @@ -1219,7 +1211,13 @@ static inline void perf_event_task_sched_in(struct task_struct *prev, > static inline void perf_event_task_sched_out(struct task_struct *prev, > struct task_struct *next) > { > - perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0); > + if (__perf_sw_enabled(PERF_COUNT_SW_CONTEXT_SWITCHES)) > + __perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0); > + > + if (__perf_sw_enabled(PERF_COUNT_SW_CGROUP_SWITCHES) && > + (task_css_check(prev, perf_event_cgrp_id, 1)->cgroup != > + task_css_check(next, perf_event_cgrp_id, 1)->cgroup)) > + __perf_sw_event_sched(PERF_COUNT_SW_CGROUP_SWITCHES, 1, 0); I was not clear about the RCU protection here. Is it ok to access the task's css_set directly? Thanks, Namhyung > > if (static_branch_unlikely(&perf_sched_events)) > __perf_event_task_sched_out(prev, next); > @@ -1475,8 +1473,6 @@ static inline int perf_event_refresh(struct perf_event *event, int refresh) > static inline void > perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { } > static inline void > -perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) { } > -static inline void > perf_bp_event(struct perf_event *event, void *data) { } > > static inline int perf_register_guest_info_callbacks