Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp277529ybt; Fri, 19 Jun 2020 01:32:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIfBB/lkBZw9i71T4asNKd9t4RBovzZAPCGHiOBEm7MYo++htATb2pYOtNUcnyu4I9uUj+ X-Received: by 2002:a17:906:198d:: with SMTP id g13mr2506222ejd.281.1592555565325; Fri, 19 Jun 2020 01:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592555565; cv=none; d=google.com; s=arc-20160816; b=jd512QYjMpFfIlJ/3FYEtJ+c/25V0QGhHcafIHxJhU6k5lJ/i5PGspNkR+hBpBNICt ZTjeYmS9XY7DDwGJ5PBAOLi1yZSVEfWFyHEDYIbWa1vgqy4WYx+TkC+m+b34KPXx/hSI cblH3oxQISQeLB7vsRZxRmaTO79MVknTv2M1x9UMb9xV5Mj/vxQFes2oUixVjGizo5pb 3sPRcTZKh4R5j6khpB3sPVfef+QScsNQj8Bsi+z5SbmWBpQKJXeZudxCQON/XuB8BZqR sww1TzakZyUVtq5AEkpJ7fBvfKIl7+WsihHCwjYvDvBjwkNJ6cXXeUjYqfhk7qMj0gpt idXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:date:to:cc:from :subject:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=bal/f6C5W3hI/7eEDoJMPCvhC5IDLMyLNXSt4/S+Z6w=; b=IENy+3FgtrQPj0jYPy1NuKC3XzAkL2EuGrYfh8ENgOCbpyMfrIBCg/bRcX0nuPG1gL lmqUnbROjSZrcEY3Vpw8vbzb8JczvjBMeYanZk3tYASfT3jqLGtHcm9qsPYvPj3ZhGyE v7/r3pp1gdZjKq70pT7zQmUOIgXai69hzn1dideHJQcAU7oh3umGwX/9CiRGqZfKDHFW 1wI7rJGFp+xfmOAm47L461KLtPG7DjKawQI+dEic5n1t2jVT6dermZAvtgyAS08JZxDW 9TSLM/qDSEnVq8Q1xyM9urFiE1LZR7lHdZigwU5cER2qd/BzCPVd8cMKbNSDMaI54kbe T4qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=asHKwznp; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si25si3290264ejb.43.2020.06.19.01.32.22; Fri, 19 Jun 2020 01:32:45 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b=asHKwznp; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731271AbgFSIaD (ORCPT + 99 others); Fri, 19 Jun 2020 04:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731022AbgFSIaB (ORCPT ); Fri, 19 Jun 2020 04:30:01 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B43EC06174E for ; Fri, 19 Jun 2020 01:30:01 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id m2so4010440pjv.2 for ; Fri, 19 Jun 2020 01:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=bal/f6C5W3hI/7eEDoJMPCvhC5IDLMyLNXSt4/S+Z6w=; b=asHKwznp8EZNJTx5F+A/9eKKgUGgsWkbC1twAT3301DPYW41sseSJwhpPeYQW2YpvB IjWQD8A0wDX/58ArkSviJh+wTiDlUhI4RX5exrXQ2fB89EmRq9QC+2EeGsn5/8xCNHcT dLdt/XKSjGAfV2aXSpQB0gjVamY2HLSon89Dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=bal/f6C5W3hI/7eEDoJMPCvhC5IDLMyLNXSt4/S+Z6w=; b=lrwMP4l06XCEiegq9aUrPVWadkYuZwTBmnKFJ2MtkNraMUZSiZcSRazy5JnSHurger 7yVb9UG2MOWxSDi4wD78/ACsefIqdmePiINynjMIWc0QvvMKCVPJtbWSNzNntkyzF9Q2 iwPL/hkPvID3Gl/r0TQvBGZSQnxWXxuS1UuFnBLank0grEvnTyMWOpUGyIRdGQW7CGlb QBN4x28+PTkxLVAjxzLa03Z8520Rno+sfllvxuw+gR1Hh/bEA46e7GpASYeHx3plQYM0 QmB/s6NXmOBozw0xHzcS6Yjz602EXy3/8MhUsfNmLZU9rGcjSxJiuT2dm0xHaEqrvdM5 7m4Q== X-Gm-Message-State: AOAM532GCY4mAU++WSgNe9XAKU5f/w6WeDJi+zALlEQcmysKOl26flb0 oin2Q+7sKwKPcJVdEYAw1hGgCw== X-Received: by 2002:a17:90a:284b:: with SMTP id p11mr2480021pjf.22.1592555400970; Fri, 19 Jun 2020 01:30:00 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id hi19sm4687515pjb.49.2020.06.19.01.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 01:30:00 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20200617113851.607706-1-alexandru.elisei@arm.com> <20200617113851.607706-4-alexandru.elisei@arm.com> <159242503203.62212.1690942414916053920@swboyd.mtv.corp.google.com> Subject: Re: [PATCH v5 3/7] arm64: perf: Remove PMU locking From: Stephen Boyd Cc: mark.rutland@arm.com, will@kernel.org, Julien Thierry , Peter Zijlstra , maz@kernel.org, Will Deacon , Arnaldo Carvalho de Melo , Alexander Shishkin , Ingo Molnar , catalin.marinas@arm.com, Namhyung Kim , Jiri Olsa To: Alexandru Elisei , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Fri, 19 Jun 2020 01:29:59 -0700 Message-ID: <159255539947.62212.6059916295459835174@swboyd.mtv.corp.google.com> User-Agent: alot/0.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Alexandru Elisei (2020-06-18 03:51:31) > Hi, >=20 > On 6/17/20 9:17 PM, Stephen Boyd wrote: > > Quoting Alexandru Elisei (2020-06-17 04:38:47) > >> From: Julien Thierry > >> > >> The PMU is disabled and enabled, and the counters are programmed from > >> contexts where interrupts or preemption is disabled. > >> > >> The functions to toggle the PMU and to program the PMU counters access= the > >> registers directly and don't access data modified by the interrupt han= dler. > >> That, and the fact that they're always called from non-preemptible > >> contexts, means that we don't need to disable interrupts or use a spin= lock. > > Maybe we should add a lockdep assertion that the code isn't preemptible? > > I.e. add a cant_sleep() call? Or is it more that we don't need locking > > because we're just doing register accesses and don't need to protect > > those accesses from each other? >=20 > It's both. The spinlocks were there to protect the functions from being p= reempted > and possibly migrated to another CPU, and from being interrupted by the P= MU irq > handler. >=20 > There was no data race with the interrupt handler, but before the previou= s patch > ("arm64: perf: Avoid PMXEV* indirection"), in order to read/write/program= a > counter, one had to write the counter number to a counter selection regis= ter, and > then write/read the desired value from another register. This was done fr= om both > the armv8pmu_{enable,disable}_event() functions and the irq handler, and = the > spinlock was necessary. Now that we can access a counter using a single r= egister > access, there's no need to protect the functions from being interrupted b= y the IRQ > handler. As for armv8pmu_{start,stop}(), they consist of one register wri= te, so > it's also safe for the irq handler to interrupt them. >=20 > For the preemption part of the locking. The armv8pmu_{enable,disable}_eve= nt(), > when called by the perf core code via the pmu->{start,stop,add,del} callb= acks, are > guaranteed to be called with IRQs and preemption disabled, as per the com= ment in > include/linux/perf_event.h. They are also called from the arm_pmu driver = by the > CPU PM notifiers, which should also be executed with interrupts disabled.= Should > we check here that the top level code respects these guarantees? >=20 > The armv8pmu_{start,stop}() functions are called from the irq handler, so= we're > safe from preemption in this case. They are also called via > pmu->pmu_{enable,disable} callbacks, and I didn't find an explicit contra= ct > regarding preemption in include/linux/perf_event.h. I've checked the othe= r call > sites, and I didn't find any instances where they are called with preempt= ion > enabled, which makes sense as we don't want to disable the PMU on a anoth= er CPU by > accident. If they're all callbacks then it's overkill to add this. Presumably it is better to enforce this wherever the callbacks are called from so as to not litter the callee with random cant_sleep() calls. Probably best to ignore my suggestion. >=20 > I would be inclined to add cant_sleep() calls to armv8pmu_{start,stop}().= In the > previous iteration, there were WARN_ONs in these functions, and Will said= [1] they > can be removed because they are per-CPU operations. Will, what do you thi= nk about > adding the lockdep assertions? >=20 > [1] https://www.spinics.net/lists/arm-kernel/msg745161.html >=20 If I read it correctly Will is saying the same thing in that thread.