Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2284334imm; Mon, 28 May 2018 05:22:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoTH+aMbZjVj5yFRyPbtresvCoOcfvECLaBrIiydmeh6M7F9lN1doAZlHW7WNRurooDO1w/ X-Received: by 2002:a63:b54b:: with SMTP id u11-v6mr10451171pgo.365.1527510175722; Mon, 28 May 2018 05:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527510175; cv=none; d=google.com; s=arc-20160816; b=fu0z3bmg3dvz8iceVL+IHMRirAA5SAHnRzhK36l0NEvZnEswL6hQzodKoItWG2uDEL Pa9ToO7g58GSKKsi6ilE+sz+Ry3/wr6GPeFIrqYpExunt3K4sanbEY1fUTN4B1amy/4I jHmzpiK74dlMZ+XttSiUdV3+jLdb2GpWUjiqSFt/cnx+5W60h+c7o3SlguoL9SZAV6+E Ktt0YbxnTqA0FJjvDFhg3f081laXQMjO5Edtv8p2jCmB2ejJD4z+Y2fgkDB0CP5Mb7Oc htC6UamBbkB6OZqAfDExbNwM1dwuB2jR5fYS5nwln4jwR2v/2CK7O/YdghwrTOtECchc We3w== 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=/J2FBV9JgRqw64CN10RFfa+dDHgvtIEthiujZra7aJA=; b=DpaCD5PJdALPPjrdAcj6GzzebydUgCFlRsgeuyBHZBkea16/AEtmiTDteNS8gJrZM/ gFw4WQyOhcqhWs8hTdBuMROM54qA/W9bY6LyU/eu2O2spHYUvZi3FN7pH8bza7atam6W SDS9iYTwaRCI+1UTQmExKW0ClRutMe7YxW+QEnMPZfWess8A5oC6NdP4nmmiqX76EYjk m4BgAPpcvs031rDjnmjPby97e9ufoyGgwSffL3RKThb9Y8AbewMFZW/PaLJmQEXMqOQ7 0xKXl1MTzHMrv5OKFA7ztWY2ADB07Ebcqv5u3YcKAsE54dsEPL1khibeENqVpOMjsvEb 7WKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m+K3cBVv; 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 g8-v6si24382586pgr.474.2018.05.28.05.22.40; Mon, 28 May 2018 05:22:55 -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=m+K3cBVv; 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 S938760AbeE1MVv (ORCPT + 99 others); Mon, 28 May 2018 08:21:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:49414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422751AbeE1LB7 (ORCPT ); Mon, 28 May 2018 07:01:59 -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 815E520845; Mon, 28 May 2018 11:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505319; bh=YjDiGqFSkigcKTNhFfe4tEpkKMDy0GoTv8IXCHvMhQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+K3cBVv5kXoAoA9oKKEj8Tl5Yy1WNhnJbq1xsZmPsljhdTCmvUjGV6Ue4zqQZhf0 avzoEix+VrBJ2i2IWYR4mbnL//LPaIKKs5PwsNQp5yJ+CrMm/D+xSwsX1nzB7vJ9QV M5yxCJl6l5TN6hdoCXM/F9RIGvvSHnpk1xTREXvE= 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.14 423/496] perf/core: Fix installing cgroup events on CPU Date: Mon, 28 May 2018 12:03:28 +0200 Message-Id: <20180528100337.574909363@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@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.14-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 @@ -900,27 +900,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 */ @@ -2404,6 +2416,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);