From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E72BC433EF for ; Sun, 24 Oct 2021 10:27:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B1B86023F for ; Sun, 24 Oct 2021 10:27:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B1B86023F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/QvRZL455nxcmKIqAhffCOZ8FeohJAdVlWemcz9cWQY=; b=yCpB7pirVFk8SD XvUIWz0ZboIIHOsp7bMot8USIWLvaC/Vf4z84V0GXSy7LlNzHiZLBS0GgUK69MgyLL2KFhHwloWc4 bFHDZCftFaQJmXg+DpJZLu4eSK5nmoIPgLdGnfn5F1CCyLcMvMj5+dJorpvY+NJB99iX1Qhrdvnnh loIxz2J6m3CMhQkpLa2t07Y+pwe53evIGRGN7cm2H6R+Yze6WDrfaAbCNvUF46Pj/Q5PoTrfXfQQw u4StuU4DXlOu/98c7bLnURA2nv7ozKykz1AbFB1/bvlPsAfxsQ6nk7FPYlPHOmfyWSA9O3UrMfCoK sjZkKYIVdQns1pTZueUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1meahH-00DvYK-Dg; Sun, 24 Oct 2021 10:25:47 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1meahD-00DvXd-TS for linux-arm-kernel@lists.infradead.org; Sun, 24 Oct 2021 10:25:45 +0000 Received: by mail-pl1-x634.google.com with SMTP id s1so5876742plg.12 for ; Sun, 24 Oct 2021 03:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iGbgQOCj+oOFbXt9SNh5T326Ohx0VeTB83ysW3crHq4=; b=ZpaNlTJVE9SqNuE3roG2fOTn1h1LCC6cadV/n51nWUQf/ij4fyBn3zbbZ6DVJqC3eF q1zwIcA6BgLRPe+Monfd+MZuneGdETiXG0TwomI717i2yaTrpQ5k7Z+E50k/hrEp9V/m 68Ej0tlsblvLPj0GlzgtZxitFLE44catnBca1/y331ahbGzf0rPbzXGHmy73hbMdKiMG yjYu1kgDY9z6ptZdaoj4Nc8C0imm5eq9qUuDkORi1nbiSDsZjr+cgsCQ6tOppVRRBxbI NDrVivpYePU7na8ORZa4smSSSB6xfoO9xR3nzgB3NUTbhxvtGB4l2yOL2ybW9F9puyHi EhMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iGbgQOCj+oOFbXt9SNh5T326Ohx0VeTB83ysW3crHq4=; b=B4bUcmH3p/nKOxOKU2UzGpO2R2ZZZSWWosgRbC8V5oDT6JfxiabSyMJr9tXovDYEMe Ud8viEfodzfJJ+JaZzj+DXYm6GvSJ9ZfnYUt1V5k0vhhjI8IcI5Rui4BP9zV3SdNuuxt N7khe0DFo01VXEsSu46DCSf/Rm48j/DXz2pYBSRsO8TEGJoTOWPqriH3xGJ1kHrPkTK0 DKZfcBUHI0J4+kgaYCUF69Cp6oefcXr0FuyGeVa9vTpf1CFVmgAsQ+43ziiacdMwK358 UtA2jf8QWnMUmh2N2UArRAQzbF5oLCVoiL/jyqSivbOz0zFMhAl8lBx/0xxNno8QyFdf x7Ow== X-Gm-Message-State: AOAM532b5OpFa+c4s202/K0+zH8Cdk7j+NTh/LDVwtQ475C3/1oNmLGc IdY7+/Fsi0ph0JBZEBUvRY+/Uk30InSVXdqK4yWTDw== X-Google-Smtp-Source: ABdhPJx7xGCImrwIIU5NtCCRc0JJd5vvNjByWn2LVwUmGWeXBpQYu8NjDbna0Iet2lZZ47hjTx5xdg== X-Received: by 2002:a17:902:aa02:b0:13a:6c8f:407f with SMTP id be2-20020a170902aa0200b0013a6c8f407fmr9745675plb.59.1635071142161; Sun, 24 Oct 2021 03:25:42 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id q8sm16587197pfu.167.2021.10.24.03.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 03:25:41 -0700 (PDT) Date: Sun, 24 Oct 2021 18:25:30 +0800 From: Leo Yan To: James Clark Cc: Catalin Marinas , Will Deacon , Mark Rutland , Kees Cook , Ard Biesheuvel , Sami Tolvanen , Nicholas Piggin , James Morse , Marc Zyngier , Joey Gouly , Peter Collingbourne , Vincenzo Frascino , "Peter Zijlstra (Intel)" , Stephane Eranian , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFCv1 4/4] perf: arm_spe: Dynamically switch PID tracing to contextidr Message-ID: <20211024102530.GI213960@leoy-ThinkPad-X240s> References: <20211021134530.206216-1-leo.yan@linaro.org> <20211021134530.206216-5-leo.yan@linaro.org> <854fb1a2-e5f1-f237-685f-8ddb0557c98b@arm.com> <0a53529a-576c-05b0-4fe5-906195faf243@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0a53529a-576c-05b0-4fe5-906195faf243@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211024_032544_033217_2E81CDAD X-CRM114-Status: GOOD ( 26.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi James, On Fri, Oct 22, 2021 at 05:23:23PM +0100, James Clark wrote: > On 22/10/2021 16:36, James Clark wrote: > > > > > > On 21/10/2021 14:45, Leo Yan wrote: > >> Now Arm64 provides API for enabling and disable PID tracing, Arm SPE > >> driver invokes these functions to dynamically enable it during > >> profiling when the program runs in root PID name space, and disable PID > >> tracing when the perf event is stopped. > >> > >> Device drivers should not depend on CONFIG_PID_IN_CONTEXTIDR for PID > >> tracing, so this patch uses the consistent condition for setting bit > >> EL1_CX for PMSCR. > > > > Hi Leo, > > > > I've been testing this change, but I'm seeing something strange. Not sure > > if it's a problem on my side or not yet. With this command: > > > > sudo ./perf record -vvv -e arm_spe//u -- taskset --cpu-list 1 bash -c ls > > > > I'm only seeing 0 values for context: > > > > sudo ./perf report -D | grep CONTEXT > > > > . 00038dce: 65 00 00 00 00 CONTEXT 0x0 el2 > > . 00038e0e: 65 00 00 00 00 CONTEXT 0x0 el2 Good catch! I reproduced this issue at my side and looked into the flow, the root cause is relevant with timing. When perf launches the program 'taskset --cpu-list 1 bash -c ls', it forks a new process and 'ls' program is scheduled in, then function arm_spe_pmu_start() invokes contextidr_enable() to enable the PID tracing in contextidr. Since 'ls' program executes very short and it simply runs to the end (so in the middle of 'ls' there have no any context switching on the CPU), there have no any new PID is written into contextidr and CPU's contextidr keeps zero. This is the reason we see the context packets contain zeros for PID. To fix this issue, we should enable PID tracing when setup AUX ring buffer, at this phase, the profiled program has not been started yet. So when the profiled program is scheduled in at the first time, PID traing is getting ready and we can see the expected context packet in Arm SPE trace data. So this patch should be updated as below, I will apply it in next spin if no objection. diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index c21cf1385cc0..85aa2eab0c2e 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -876,6 +867,13 @@ static void *arm_spe_pmu_setup_aux(struct perf_event *event, void **pages, buf->nr_pages = nr_pages; buf->snapshot = snapshot; + /* + * Enable tracing PID to contextidr if profiling program runs in + * root PID namespace. + */ + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) + contextidr_enable(); + kfree(pglist); return buf; @@ -890,6 +888,9 @@ static void arm_spe_pmu_free_aux(void *aux) { struct arm_spe_pmu_buf *buf = aux; + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) + contextidr_disable(); + vunmap(buf->base); kfree(buf); } Thanks a lot for detailed testing! Leo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel