From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55DAC42A795 for ; Thu, 20 Aug 2026 11:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787225277; cv=none; b=AGkTSS2t16OtM2TL5X2deIBdG0cp9PgHDRyUzGHipJOiibhHP5Pavlms59ZhUv2w+VyH3/bPqxLa5bz9qJ3wC6kG0h+xa0egkfimr5Nj3G/6bF2dTRjkkVglknC2YkOWZ5e8lzAy9lht3foccluKT/ALWvPWzdWFZQfOF4rTIUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787225277; c=relaxed/simple; bh=Srahal2eH7xWHE/CtY7E9POghtjnWqvek+sHhvA5W2I=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=GBAtPtQnWSdvt5z+QSV+1h56a5anRJAYUFgpgDyb6BGPbSV8xQUJbec6s7Hf8m1+7Sz1YT87YAnMcv3cOb070kI54rvbA0j7fpX8sq6o12c9WbiUOZqo27Ym4FiBGTQXhpFyczWVSrokcBvh1nRBchvwRDmuBAg0EutrDr1z190= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=AxNXBe6B; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AxNXBe6B" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-49954b88fffso21672345e9.0 for ; Thu, 20 Aug 2026 04:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787225273; x=1787830073; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PTRdsREDtSKZ/ZMnpJEUBQv+gdf+FU1Wtr3RxWfnMP4=; b=AxNXBe6B5boSbOJxux3ZvOHsldtGJwVftfuQEGZTQ1Io5l1+Ct0doyZQwu1Fu0cpLL BbpdFuKj3qgAnQUlaiUQd6VltfhaOX30AmH6BcdlWWAe+d99doCzfnjh9TF4u0qyUcs2 ZBx5nviIsJmbV1Zcwyk+XCwy0sh2un+NRUbL/2d95MPRHKKr0xlg+McCmZ3G40AmdNYa spZ80Qe0mTrmba1uOzoByLjBTadJvFPSwlOhq9bCuqAAbxahP0FVsgesjzfQN6Ke3OJB L8ML9DMMtnokmE/44SfHVYLr/vIdoWJGJE+DSIZ2UhSAYKJVhuqCUOTy1r4qTaOqa/VW 2P7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787225273; x=1787830073; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PTRdsREDtSKZ/ZMnpJEUBQv+gdf+FU1Wtr3RxWfnMP4=; b=DUr61GkC3WDcFnFbQ3OA8DC2uB3gGUXFrJnKSmlxl07QOHtgTsR5T56jehE47MXmvO LxKASPnTNSwzSCVcPwU6e6/L1m/h4LuQSB4zWAyI3QdUWyRvrc6//cygK2HXe7C9l/rS BoQobZ8PKTmcbt/uKTLsGu7Owb0hclDunuOKDuQSnU2kqS+ByBeR7DrOqqXxJH5eRiSY vy6jZ527ghPXBvlJGRC1z8O83tGUc8dDPG9+HkYM/v8V/CVio/8ETD6ok8O3f+fQY57W nh8g1ePPVMGr60LM5Q0crsn1vglgG5BJ87dFgMeEjG/uxsvZ7DaFdP0YWkKcjd9Rgqs2 670Q== X-Forwarded-Encrypted: i=1; AHgh+RqxnlutHk8oxXvo2T1WIOUyxHmhszQHQoVbqTqLGtdFA3FqRhVBNwwULfvR1Du+10XFsgX9PB0jsiOksXw=@vger.kernel.org X-Gm-Message-State: AOJu0YzT586DAy+kAvVHh+p1Cd2KXqwv7WW2Hbos8bDk2243WtTd918T m6xsYkX7FEBjaGUCFRuxRKxVTqzJfhaklKGEuV/jUvk5rPGkUJSHK534Sn8jfDJZEW4= X-Gm-Gg: AR+sD12RnbOmUEp5s2yWCCQqWNhWFtCtES/GLHUKmdtdl5hOypnpoGf4ApVeIVRb5oc l+OY87xIypXsAU+Ck7jSALrrPvMfDu+r4hrxaQBulY9XvpNb+O9x+RqslY5NmkpcouocTAwhVqF clQVy707wybk5LWLTgcrvYnglLzXaCh6VENdZnjCCEoXRtezol0KO1ar6coN7ZAXGogElQhfuim wtsDYc80lcnkGWifXu8o9zHzihlcCEIWEeMDT9Uo0ziaY0v3ErCKB4iz9CQwQ8K7jAs5AhY0b2r G+/wVSODOkCSUI6w/c7ILhNAbCzcokv7aYVCJQkF7MFQGY/uQPnVvaKekPdGZiNv3fzsRORD7gU oicibj95oeTb3+yaDwE2XT99N23DRshYyDe9lFiLqYjTq+RuzFBUwfTEKbz3kPaJ2/EHHN3tZGv yO0Pw0a4D2IAm01vWI5AWdWLqqsQw+6dxv50RkLyIQc+FsUKMjRvw8DHpn1TIyBXoajg== X-Received: by 2002:a05:600c:4e12:b0:499:b000:b828 with SMTP id 5b1f17b1804b1-499b000b8f5mr136887005e9.4.1787225273549; Thu, 20 Aug 2026 04:27:53 -0700 (PDT) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499b2269ba6sm34124935e9.1.2026.08.20.04.27.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2026 04:27:53 -0700 (PDT) Message-ID: <04f3681c-71c6-467c-a859-ab5d39f3c928@linaro.org> Date: Thu, 20 Aug 2026 12:27:52 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/8] coresight: tmc-etr: Prevent per-thread events from sharing a sink From: James Clark To: Leo Yan Cc: Suzuki K Poulose , Mike Leach , Suyash Mahar , Yeoreum Yun , Greg Kroah-Hartman , Qi Liu , Junhao He , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jonathan Cameron References: <20260728-james-cs-multiple-per-threads-v3-0-6aee7579f1dc@linaro.org> <20260728-james-cs-multiple-per-threads-v3-4-6aee7579f1dc@linaro.org> <20260813160504.GC8904@e132581.arm.com> <20260819084515.GF8904@e132581.arm.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 20/08/2026 12:09, James Clark wrote: > > > On 19/08/2026 09:45, Leo Yan wrote: >> On Fri, Aug 14, 2026 at 10:09:01AM +0100, James Clark wrote: >> >> [...] >> >>> There isn't any sharing with "another perf session", unless there is a >>> mistake somewhere? Checking that the owners are equivalent enforces >>> this. Or >>> do you mean another event owned by the same process? >> >> Now I understand that the problem is constrained to different events >> within the same session. >> >>> I'm not sure the exact model you had in mind was that still supports >>> this >>> and fixes the bugs? >> >> Let me try to describe my understanding of the problem. >> >>    ./perf test -w named_threads 2 1000000 & >>    ./perf record -e cs_etm//u --per-thread --pid $! >> >> We can simplify the flow as: >> >>                  | T1 | >>    CPU0        ------------------------------ >>                     |   T2      | >>    CPU1        ------------------------------ >>                                 `> T2 stops and the driver reports >>                                    the warning when trying to sync >>                                    ETR_BUF(T1), while T2 is associated >>                                    with ETR_BUF(T2). >> >>    AUX_BUF(T1) |                            | >>    ETR_BUF(T1) | Bounce buf0                |  -> Used by H/W trace >> >> >>    AUX_BUF(T2) |                            | >>    ETR_BUF(T2) | Bounce buf1                |  -> Not used by H/W trace >> >> With `--per-thread --pid $PID`, perf creates separate events for the >> child threads, say T1 and T2. Perf allocates a separate AUX buffer >> for each event, and the ETR driver also allocates a separate bounce >> buffer for each event. However, because there is only one shared ETR >> sink, only one of those bounce buffers can actually be used by the >> hardware at a time. >> >> If T1 stops while T2 is still running, the ETR remains enabled. Later, >> when T2 stops, the ETR is still using ETR_BUF(T1). This mismatch >> triggers the warning and prevents the data from being copied. >> >> I am just wandering if we can improve the sink driver to only allocate >> a single bounce buffer that is independent of any threads (and any >> associated events). >> >>                  | T1 | >>    CPU0        ------------------------------ >>                     |   T2      | >>    CPU1        ------------------------------ >>                                 `> T2 stops and can sync trace >>                                    from the shared bounce buffer >>                                    to AUX_BUF(T2). >> >>    AUX_BUF(T1) |                            | >>    AUX_BUF(T2) |                            | >> >>    ETR_BUF     | Bounce buf                 |  -> Used by H/W trace >> >> This might also simplify the CPU-wide case. Each CPU would still have >> its own AUX buffer, but the ETR driver would maintain only one bounce >> buffer for the shared sink. A reference count could track how many >> events are using the sink, with the final event responsible for > > Isn't this how it's already working? get_perf_etr_buf_cpu_wide() > allocates a single shared buffer with a refcount. I didn't change this, > I only changed the rules about what is considered shared or not so that > it matches the semantics of the perf events that back the tracing session. > >> stopping the sink and copying the trace data from bounce buffer to aux >> buffer. >> >>> The one in this change is pretty complete and only does 4 comparisons, >>> which seems quite simple to me. >> >> Before going further with the heavily sink buffer refactoring, perhaps >> a more pragmatic solution would be to reject the problematic case for >> now. Can we do something like below? >> >> +void coresight_trace_id_is_perf_started(struct coresight_trace_id_map >> *id_map) >> +{ >> +    PERF_SESSION(atomic_read(&id_map->perf_cs_etm_session_active)); >> +} >> >> @@ -399,6 +399,15 @@ etm_event_build_path(struct perf_event *event, >> int cpu, >>               goto out; >>       } >> +    if (!coresight_trace_id_is_perf_started(&sink->perf_sink_id_map)) { >> +        sink->perf_owner = event->owner; >> +        sink->perf_target = event->hw.target; >> +    } else { >> +        if (sink->perf_owner != event->owner || >> +            sink->perf_target != event->hw.target) >> +            goto out; >> +    } >> + >> >> We use a central place etm_event_build_path() to record and compare >> event's owner and target process, then we don't need to spread the >> check into sink drivers. We only care about if owner and target must >> be consistent. > > But we don't know where the target will run when the event is created. > That's why the check is delayed until etm_event_start() and the process > has been scheduled. Where it runs needs to be taken into account to > calculate if this sink can be shared. > > Moving the check to event creation time would cause a regression for two > users that plan to trace two different threads (or different CPUs where > the processes are known to never run on a shared sink at the same time). > With your example the second user is completely prohibited from opening > per-thread events, but with the existing driver and this change it > works. I think that's quite a significant change in functionality, > what's the justification for taking those use cases away from users? > Another way to put it is that the current code checks the PID, and I made it also check the target PID in the same place. That's the extent of the change. Everything else are minor fixes to things that were already broken like we shouldn't be comparing PIDs numerically because they can be re-used. I can't see how adding one more condition to an existing comparison is complicated or is too big of a change. >> >> Regard of the inherit/inherit_thread, I always see they are consistent >> within the same session. Should we ignore them? > > Do you mean they are always consistent in Perf? I don't think the driver > can afford to bend the rules just because Perf promises to never do it. > It might not always do that, and any tool can do perf_event_open(), not > just Perf. > > It's quite easy to imagine the bug report being: "I opened one event > with inherit set, and one event without. Why do I get trace from other > threads in my event without inherit set? I expect to see only trace from > one process". > >> >> Thanks, >> Leo >