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 E698AC433EF for ; Thu, 11 Nov 2021 12:44:31 +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 ABDD461108 for ; Thu, 11 Nov 2021 12:44:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ABDD461108 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=ep0O1u3TvgMGGCFuZG8yuXUzdzhJczQ+39ERpxM4fQo=; b=lISMKQ/9JtnjzB 0XTtn6pLWEWRYbnH9VJoo5oHL10K7xrle5a750CanPHeIhh9e8mxUYokh6dzrcqCeYEayfPglkaGc SG77iSHlMLTE9IokN/NEI90cBnPQfG/4tA9ti8Wh1Cbp2klKxfq/X0Z4zD6yrtcAMRRF3EL81evD4 nliQ7hdrgFSkC1f9Bk9k2WuHtKFcla7a9wGoURquAvVuf+PXG3J5OO+90A25oswdRNzLQHuR4SJMT ibNnRAxkZXVJxbq4dXI99waxWevV8Os5g8POQP+0XmmQ2MiteVYyx6WXcu/OmuZ4HBUyQfGW7kO4L itkpH3VE1mwmNzMajyhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ml9Q7-007tVt-Cl; Thu, 11 Nov 2021 12:43:11 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ml9Q4-007tVG-9Y for linux-arm-kernel@lists.infradead.org; Thu, 11 Nov 2021 12:43:09 +0000 Received: by mail-pl1-x631.google.com with SMTP id p18so5612074plf.13 for ; Thu, 11 Nov 2021 04:43:07 -0800 (PST) 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=USmt7anIX2PGWTer7zUxYY8feegDwUP1c/up9xPpWxQ=; b=EV7cgYZzVbRJqEkWsNadZUif+UZxU2GpYogF9EHqzIXFbNQMV1fbnXo0aNC2CEk/Zc JQa8SHrgnN9l+GejMu0tLcIRL+P5eTtfip1eAbX+VxE5S1sLOIo5wCKSO7AzboFR8LY1 e2HicZy+kn/B9YxEjDbemf6+WZKncJHwLWIJO6+gv3Ch7GmDlDDOKSiE8JBIWneeMUPk CpZ0SeRNn44CddAC9GPjPMV9pvM6xWM01UuzboVvUKxEWWwAo51zX4icFdeqnwf4BiJK cSoCrJSXD8M1KAZmljromnbmXaekELJTrwrU70ULoXLrsulpJRQcOrJNk+i9pgbfagfl FTBg== 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=USmt7anIX2PGWTer7zUxYY8feegDwUP1c/up9xPpWxQ=; b=jQ+ZRfpRdA1BqRERfBrl/Ao6J1rA5UayBfe/396B0MNITtrwVvGF3wvlHZOYV2OHIv B2CklSOxIdiA/t2/Y5ZAwgXeWsX2fZ8vzyAEcST5dO2CSrcXXhjSWjhR4kNoB7MlxOcs xGmYXWEqkcmTVOsoEWx9JwnqAAtvh4kstx7XV4GPwR+oS1/p2OHIMj0rXK4ReRX/uoO3 Q8tBhgETX2WGFv4yROL7mfKqVtxUkJwmhCv8THrTjm2QPoGtJvBHB3wtG9vnPbYOBoS3 0u0gIxpELpeHrYRDob6COovVGuqsUhXqSDK0gsh6D2v6vjBSFsXMVY0fzT0USwVlPzMU padw== X-Gm-Message-State: AOAM5312mKfJxClcScsDz47OPOQoHn5kmMIlXwNbe2X7TWT6q866pnTT NKIY1lyOEyXX/VvM+gONdyMy+g== X-Google-Smtp-Source: ABdhPJy7hrsMSt+vPE9iMVSb0pdsSDnMMkt91nNIT+76HeRNO/Dd8x46k3CwmJaSmj+JwZhALbwwcA== X-Received: by 2002:a17:90b:380e:: with SMTP id mq14mr26585493pjb.74.1636634586974; Thu, 11 Nov 2021 04:43:06 -0800 (PST) Received: from leoy-ThinkPad-X240s ([148.163.172.147]) by smtp.gmail.com with ESMTPSA id j7sm8888551pjf.41.2021.11.11.04.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 04:43:06 -0800 (PST) Date: Thu, 11 Nov 2021 20:42:57 +0800 From: Leo Yan To: German Gomez Cc: Namhyung Kim , linux-kernel , linux-perf-users , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , John Garry , Will Deacon , Mathieu Poirier , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 4/4] perf arm-spe: Support hardware-based PID tracing Message-ID: <20211111124257.GB106654@leoy-ThinkPad-X240s> References: <20211109115020.31623-1-german.gomez@arm.com> <20211109115020.31623-5-german.gomez@arm.com> <20211111074148.GC102075@leoy-ThinkPad-X240s> <20211111083002.GA106401@leoy-ThinkPad-X240s> <5c0e255b-e140-d157-7dfd-b27a43e128c9@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5c0e255b-e140-d157-7dfd-b27a43e128c9@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211111_044308_393202_1956728A X-CRM114-Status: GOOD ( 24.25 ) 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 On Thu, Nov 11, 2021 at 12:23:08PM +0000, German Gomez wrote: > On 11/11/2021 08:30, Leo Yan wrote: > > On Wed, Nov 10, 2021 at 11:59:05PM -0800, Namhyung Kim wrote: [...] > >>>>> +static int arm_spe_set_tid(struct arm_spe_queue *speq, pid_t tid) > >>>>> +{ > >>>>> + struct arm_spe *spe = speq->spe; > >>>>> + int err = machine__set_current_tid(spe->machine, speq->cpu, tid, tid); > >>>> > >>>> I think we should pass -1 as pid as we don't know the real pid. > >>>> > >>> AFAICT, I observe one case for machine__set_current_tid() returning error > >>> is 'speq->cpu' is -1 (this is the case for per-thread tracing). In > >>> this case, if pass '-1' for pid/tid, it still will return failure. > >>> > >>> So here should return the error as it is. Am I missing anything? > >> > >> I'm not saying about the error. It's about thread status. > >> In the machine__set_current_tid(), it calls > >> machine__findnew_thread() with given pid and tid. > >> > >> I suspect it can set pid to a wrong value if the thread has > >> no pid value at the moment. > > > > Here we should avoid to write pid '-1' with > > machine__set_current_tid(). > > If the kernel is writing the tids to the contextidr, isn't it wrong to > assume tid == pid when decoding the context packets here? I haven't > observed any impact in the built-in commands though, so there must be > something I'm not seeing. Okay, let me correct myself :) I checked Intel-pt's implementation, I understand now that we need to distinguish the cases for pid/tid from context switch event and only tid from SPE context packet. Since the context switch event contains the correct pid and tid values, we should set both of them, see Intel-PT's implementation [1]. As Namhyung pointed, we need to set pid as '-1' when we only know the tid value from SPE context packet; see [2]. So we should use the same with Intel-pt. Sorry for I didn't really understand well Namhyung's suggestion and thanks you both pointed out the issue. Leo P.s. an offline topic is we should send a patch to fix cs-etm issue as well [3]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/intel-pt.c#n2920 [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/intel-pt.c#n2215 [3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/cs-etm.c#n1121 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel