Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2221996imm; Mon, 28 May 2018 04:13:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpsBrHZ0VMLNerCzL2I4H8a4KiKe9Xftl0rRW1fzCA9h+XPtygoEA369tJz35Cw++bdUip3 X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr13067540plt.378.1527506039448; Mon, 28 May 2018 04:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527506039; cv=none; d=google.com; s=arc-20160816; b=n63X5fWcnis7Vpo7Uc5Fdu0S1yQqMB9gAXDDo5fBlLP8mpHuz2sxvCKY6NpXcr0plC gZ0dhqm9/UE/tKsh9xq1cnp8QVo2Dwzf4e8ufuc1Tk0SD6CTx5D0Gdo5sFtP6Y7ef5hx Wxsa6njOxv3BgLZ5uDIF2+aCLjMu/VGuP1Gg6kX6mj1RWE59+CPCCJ5jOyc1HUnuX+wi gZv5oOuFXm1jBNkwoe+biwQYITEwGeNHxce7MDujHKPbcsijVUwlm2cNgWyq8w7YbEyP 6vrGuukTsx1Yi5+ZV+v8kduAW75xAwf8EJqRSxpl8D4TuLIWoty8VUFW9HSBQh5dobNZ /fKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=k9qUvBtpBkhlrV96p2Zvt/yxoiF5xMufR4Fh4y61ohw=; b=lNGaN7K6+Br8QFckqDrUK/Apb6fhG5xhLyc7F4bXFYlKABHKdfE+wfZsWPwbYQt7Oj ExVTpQ4YV93HhymnL9f3fJdCMZwqOdK7Bi0ZgYHbtPTuHudabFM8rrduEsgJfC99Ep+C YAYpMGKiz/ja2ZMArI30WZmLIf1+o2IDvFoMFoA5IDB5G4EZGsZroFrkLLRbvfKQRV1W Mu1Zj6DUpXicD8dKTsU0PgniTq2xD4QPiGR2KNQV0NnUnANzrICzgfKm8ZyM//rTbTnp aPC6iaMfiePtJlAXfXSNVzt6Vm8FbBgk8y7YrpCFlEYvlBUvE+3eZ55u6WiaWo5h/xTR jIpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tY1VxXAS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si29591701pfj.267.2018.05.28.04.13.44; Mon, 28 May 2018 04:13:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tY1VxXAS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424213AbeE1LMx (ORCPT + 99 others); Mon, 28 May 2018 07:12:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:60376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423949AbeE1LMl (ORCPT ); Mon, 28 May 2018 07:12:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA8E4206B7; Mon, 28 May 2018 11:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505961; bh=Oi6q7yas6QB7KHIVdMB35Qrbev19s5j46OX2SsuBh5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tY1VxXASlN2WOC8ca5s/9bfjM8fXBh17iZ71M+yjVdvShzQe1EzuCDlUqw9baN6Z0 Ca3X/vfux5caS0jm3iUfiuE1ZoYOWyrIjQrZQy01l8FhCTDSBmY4KR42U/XBMBzUkV i2S+Irf80FOMCjpvFDTjKwJsFtXhHn3qmh3Yi/5Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "leilei.lin" , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , brendan.d.gregg@gmail.com, eranian@gmail.com, yang_oliver@hotmail.com, Ingo Molnar , Sasha Levin Subject: [PATCH 4.16 183/272] perf/core: Fix installing cgroup events on CPU Date: Mon, 28 May 2018 12:03:36 +0200 Message-Id: <20180528100256.049554911@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: "leilei.lin" [ Upstream commit 33801b94741d6c3be9713c10aa627477216c21e2 ] There's two problems when installing cgroup events on CPUs: firstly list_update_cgroup_event() only tries to set cpuctx->cgrp for the first event, if that mismatches on @cgrp we'll not try again for later additions. Secondly, when we install a cgroup event into an active context, only issue an event reprogram when the event matches the current cgroup context. This avoids a pointless event reprogramming. Signed-off-by: leilei.lin [ Improved the changelog and comments. ] Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: brendan.d.gregg@gmail.com Cc: eranian@gmail.com Cc: linux-kernel@vger.kernel.org Cc: yang_oliver@hotmail.com Link: http://lkml.kernel.org/r/20180306093637.28247-1-linxiulei@gmail.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -948,27 +948,39 @@ list_update_cgroup_event(struct perf_eve if (!is_cgroup_event(event)) return; - if (add && ctx->nr_cgroups++) - return; - else if (!add && --ctx->nr_cgroups) - return; /* * Because cgroup events are always per-cpu events, * this will always be called from the right CPU. */ cpuctx = __get_cpu_context(ctx); - cpuctx_entry = &cpuctx->cgrp_cpuctx_entry; - /* cpuctx->cgrp is NULL unless a cgroup event is active in this CPU .*/ - if (add) { + + /* + * Since setting cpuctx->cgrp is conditional on the current @cgrp + * matching the event's cgroup, we must do this for every new event, + * because if the first would mismatch, the second would not try again + * and we would leave cpuctx->cgrp unset. + */ + if (add && !cpuctx->cgrp) { struct perf_cgroup *cgrp = perf_cgroup_from_task(current, ctx); - list_add(cpuctx_entry, this_cpu_ptr(&cgrp_cpuctx_list)); if (cgroup_is_descendant(cgrp->css.cgroup, event->cgrp->css.cgroup)) cpuctx->cgrp = cgrp; - } else { - list_del(cpuctx_entry); - cpuctx->cgrp = NULL; } + + if (add && ctx->nr_cgroups++) + return; + else if (!add && --ctx->nr_cgroups) + return; + + /* no cgroup running */ + if (!add) + cpuctx->cgrp = NULL; + + cpuctx_entry = &cpuctx->cgrp_cpuctx_entry; + if (add) + list_add(cpuctx_entry, this_cpu_ptr(&cgrp_cpuctx_list)); + else + list_del(cpuctx_entry); } #else /* !CONFIG_CGROUP_PERF */ @@ -2328,6 +2340,18 @@ static int __perf_install_in_context(vo raw_spin_lock(&task_ctx->lock); } +#ifdef CONFIG_CGROUP_PERF + if (is_cgroup_event(event)) { + /* + * If the current cgroup doesn't match the event's + * cgroup, we should not try to schedule it. + */ + struct perf_cgroup *cgrp = perf_cgroup_from_task(current, ctx); + reprogram = cgroup_is_descendant(cgrp->css.cgroup, + event->cgrp->css.cgroup); + } +#endif + if (reprogram) { ctx_sched_out(ctx, cpuctx, EVENT_TIME); add_event_to_ctx(event, ctx);