Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2562917ybd; Thu, 27 Jun 2019 14:48:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWFzIIJy01ZpSPws0ZMm5kSR/M6QLFLj496GOHb5dypbFl9vanGSZHEHYwthMX/Hk+kCwt X-Received: by 2002:a17:90a:2743:: with SMTP id o61mr8690267pje.59.1561672096537; Thu, 27 Jun 2019 14:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561672096; cv=none; d=google.com; s=arc-20160816; b=O2K4tKKb66pVvCcvVrI+8OASIC0TB1ikzbTJEyrCIy3B2y69+5b/Y6NabPJG1pHt+j CXdLEyl/F6n2Q+FAr03u5Wf1mCNQIedxQntkfYyE/NGLP/1i5GiBJd2+zUs95MBnb28h 2HGDBf6tke1y/srdhDI2gcY2uGf5oGsS+UrK3DQcI/qUvJujl2TNJKab+KtlY/OyD2CR EKhgdVATeSGrw99HZP0mcKDUCtW+VKkzJQPJxq0yjxFCAxJtj1ppN5E2piQGyZlEg9PQ fbl86k4noYDFR34lYbawMsU0mbVguGI+O1c+Zn5CVivpT740FOW8K39YM0ENgDocsOOy aCcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PzZt6XuMzPi+f0gEcTLAkPhPkafzoXJbDf8oWpxJ0aU=; b=NRcWV4iGlxikPd9b4BzD6YIOM3LBMBsBfM5MkP6NHMMml9ZH/26U30Lc+7VW6Y3irt 2ASbfM7KuFnhSsUsJixe2aUlBEFErOKoFJWvKGApLC5u7IMYB7cypRInh2YpQhYaGvU8 V9S+b0OrT88BcJT7H/nzG+GfXaWf3c49/C2tQuJegjiiG469Z31RYZQnjkQssUi9qVi3 C02KfaTxLkesbdiW/UYwaY+8AW//Lx+PWu56O9zmAkN1ZksiwjaOogCaRD6DH6NE6mlJ DJikpfFqswDB2iJjn2OTh/5MM6RC8kViXweTi9g1x8rBoWIKdw/I+B/siBZ0SNeG1Gbb Jb/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DxN5X3ra; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cl7si83160plb.267.2019.06.27.14.48.00; Thu, 27 Jun 2019 14:48:16 -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=@google.com header.s=20161025 header.b=DxN5X3ra; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbfF0Vr1 (ORCPT + 99 others); Thu, 27 Jun 2019 17:47:27 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34830 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfF0Vr0 (ORCPT ); Thu, 27 Jun 2019 17:47:26 -0400 Received: by mail-wr1-f68.google.com with SMTP id f15so4150803wrp.2 for ; Thu, 27 Jun 2019 14:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PzZt6XuMzPi+f0gEcTLAkPhPkafzoXJbDf8oWpxJ0aU=; b=DxN5X3raZefiu0gnkZ/CQkYMwgsr6oMmNER685hAq7U93AFkM/Co0/DMW+0/4AJwRz JZmmWfS0oEaSTqvWMYhLgnQa2C+Qb0FCOx03ArngRGKzfHW714j9UkK296+dH+cxr5HW 39LXgMgNAwFsp38qXR01o/LC719A9geKjjisG/VIFhQCWCVpPSLG4XJt555THZ39Xgek rlYOTPHOXYZqRWMitz0+gXLK54OFj5Az1/p/UQod0gan8gMC4uy3KvphKHaSH7H0MlMy CivAqCKNix0IytJmSR/Ikj4UEYNDUYb3MPseNNpFvttQorRkz/LP94RnFJknIF9ke3Q7 l99g== 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=PzZt6XuMzPi+f0gEcTLAkPhPkafzoXJbDf8oWpxJ0aU=; b=EXUOQRW6bf4zx5ddbqBwwPQL9fJaoN8KttzKGcnXnFRDOkNbIb7YJWM0vI2BfSXZVi s1kYmH//AXlFjMpmZFzugF751nyjDuHVqRTQmcHANsVH6wAM70rpS9BekVQeydrzhgoM aMlGTsrMhTXWidtX5g0Bp6P3+D0INcbUIsURmmDfRfIejUGvOLL4i5wR9Ny5iiNRVZ5B GyfpAbva5T+5f1UYV0rk6mKI79JpwrgmPeUDSsfBzCigTWYEnjV920WH9dt6dRayFPNK BhSTZCqJLxRBC6pFwdcfjLtSSNjB+fB1jnVx+cFSjQ9pUOTRVDm9R+MvmgrZ5grk0Xuo rsMg== X-Gm-Message-State: APjAAAUk8EaEsmuB8Ng9OrYfISRTsCKgVuMcQbcfv+8wfvtM8uTNI0QB t6Xsblgc8CdHFwd2Cg7+PVBfIKfWfksZc8zsi7mamg== X-Received: by 2002:adf:db12:: with SMTP id s18mr4475065wri.335.1561672043602; Thu, 27 Jun 2019 14:47:23 -0700 (PDT) MIME-Version: 1.0 References: <20190601082722.44543-1-irogers@google.com> <20190621082422.GH3436@hirez.programming.kicks-ass.net> <20190624075520.GC3436@hirez.programming.kicks-ass.net> In-Reply-To: <20190624075520.GC3436@hirez.programming.kicks-ass.net> From: Ian Rogers Date: Thu, 27 Jun 2019 14:47:12 -0700 Message-ID: Subject: Re: [PATCH] perf cgroups: Don't rotate events for cgroups unnecessarily To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , LKML , Kan Liang , Andi Kleen , Stephane Eranian 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 group_index On Mon, Jun 24, 2019 at 12:55 AM Peter Zijlstra wrote: > > On Fri, Jun 21, 2019 at 11:01:29AM -0700, Ian Rogers wrote: > > On Fri, Jun 21, 2019 at 1:24 AM Peter Zijlstra wrote: > > > > > > On Sat, Jun 01, 2019 at 01:27:22AM -0700, Ian Rogers wrote: > > > > @@ -3325,6 +3331,15 @@ static int flexible_sched_in(struct perf_event *event, void *data) > > > > sid->can_add_hw = 0; > > > > } > > > > > > > > + /* > > > > + * If the group wasn't scheduled then set that multiplexing is necessary > > > > + * for the context. Note, this won't be set if the event wasn't > > > > + * scheduled due to event_filter_match failing due to the earlier > > > > + * return. > > > > + */ > > > > + if (event->state == PERF_EVENT_STATE_INACTIVE) > > > > + sid->ctx->rotate_necessary = 1; > > > > + > > > > return 0; > > > > } > > > > > > That looked odd; which had me look harder at this function which > > > resulted in the below. Should we not terminate the context interation > > > the moment one flexible thingy fails to schedule? > > > > If we knew all the events were hardware events then this would be > > true, as there may be software events that always schedule then the > > continued iteration is necessary. > > But this is the 'old' code, where this is guaranteed by the context. > That is, if this is a hardware context; there wil only be software > events due to them being in a group with hardware events. > > If this is a software group, then we'll never fail to schedule and we'll > not get in this branch to begin with. > > Or am I now confused for having been staring at two different code-bases > at the same time? I believe you're right and I'd overlooked this. I think there is a more efficient version of this code possible that I can follow up with. There are 3 perf_event_contexts, potentially a sw and hw context within the task_struct and one per-CPU in perf_cpu_context. With this change I'm focussed on improving rotation of cgroup events that appear system wide within the per-CPU context. Without cgroup events the system wide events don't need to be iterated over during scheduling in. The branch that can set rotate_necessary will only be necessary for the task hardware events. For system wide events, considered with cgroup mode scheduling in, the branch is necessary as rotation may be necessary. It'd be possible to have variants of flexible_sched_in that behave differently in the task software event context, and the system wide and task hardware contexts. I have a series of patches related to Kan Liang's cgroup perf_event_groups improvements. I'll mail these out and see if I can avoid the branch in the task software event context case. Thanks, Ian