From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 D15F2199E94 for ; Tue, 28 Jan 2025 11:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738065356; cv=none; b=HeexcqXOoJKGkUYvsCv4C53wku/JXzrfkpQjw0q8h0DBGmyeiaOGLcptD9jccd20+JMfrSV/8t/JAGiLxHUIfgPowkWsofQPh7oEJzu9EAE67IstZHnEp6Y30Z9Vd6T0CUO1IMb9BITtVsoWBhxwc2zN07ZkJg6WE3gIWy18xvo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738065356; c=relaxed/simple; bh=TVJohnIE7XYTgO4Zculp6caadDqgxguvz19Y+s61Op4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f5gskuiOvL2JjVG+VsGIg018h+aUDYyWLsgzqnkSG8YGF3QxrvjmiuptIbXy1Du1Wqxff8tcmQEcQ2GV3w9cOzH0ERtz4dVasAnylSs+R+o4QWm3IM7NMXmu3pfWGYlzFxS/LncDC/1wDXr2Pw685n3mwDzWGvT0C8hjqRCUWzQ= 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=guFtvIeG; arc=none smtp.client-ip=209.85.128.52 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="guFtvIeG" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-437a92d7b96so56641445e9.2 for ; Tue, 28 Jan 2025 03:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738065353; x=1738670153; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pLXaRDqxo+mIH84hjRiHW1wB2c5SwAr+CdumW+V6OgA=; b=guFtvIeGUMiPD4+UMu2n0t95yHuBp1eQCyQOgOAv90eHju3FSicn12/6rp6rqRjqov votVC304P96r0UaChnltbpzxlw21OkCYv0U56b5ckhI/xpQEkeTzDWKDZSvEV0N2jEy2 ICssD4z057zI24Xi21x6WLAQHN1QEMXsW+EkFiIQdvFAZJGP1n4GoP+Ib2fvjSRfaK6z pODJy74T8oFfV21pdV2noJWbks2ey7hwcW1bx6C2UdHZwa5pP4cHAJmwqEwIL7xd/C+V A/hFI6ta8cZvigrg7LZ/mmvjuKVSQ4hKMLeih5/Q3u1sLmcu/PVfMs/V4g8OhgnijOrE 1z9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738065353; x=1738670153; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pLXaRDqxo+mIH84hjRiHW1wB2c5SwAr+CdumW+V6OgA=; b=UDk0NE5CzBVHQF5iWjUUDMBe4yqBH+q59znIdgW6xMSUp+Mi+b/9kZSoMSbGVf9zmQ 1E8rqJy4P0KVx4RGqEHQu/8lO0GUANWds94GrytByXLLNKE1i49sxr84GDylLSI7aP1S XMPOmQbdqX8QakNWMVDayVWMbFnN2k8nsFqByPPf0F0ZcrZ/J3E1TmpxsMqTgMCdVmNT QUPfIgJlxdpABh0XP2547LBVveas+/OMFbdzLrRIvCm32C2PUSdbTmqy8DoxHpIUzwwZ tDA9fcQB0EkT8v+F6yM0BxLO63YrG8rsJejV8K1FsKOF9VqVDjoXR0jPHE4nKWVKBBas KWxQ== X-Forwarded-Encrypted: i=1; AJvYcCUEOE+TCfL1KPwvqmTH2uMw/ztLT6FcD7UvfBsHTmQluU1fSCZxbKCpVzgt2YERdPpQlNxHgBBMxR1SeQQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyiUcYgl/KAFSKqzuOqgAOIfDB4IFWibYv8s8bBeFWlq8Fl9Bjz VXr4pC65Rbp/EzvqMdwzmnQ5piP3wHfsPYCuzEXPEF80kxoBDhV1SegR9yvfvak= X-Gm-Gg: ASbGnctkHCQD+1DMSOJSBUbFFxf1GQ0BmNenYkDHFuZYtCnCViLDVfS3EnkpJbMHWBM 1rlS56XOfsU9/Z4dt/buwzjNPaTNSCHA/69wHipR92DCnagX4AptbSRagPp7W//UNObssVwk3Qd scnK2CJhthzeUgvB+vIka+cZobSYwlXh32UTU48h79ySJ7dufIAWIK9yFn2l3PrwL6YsFKCu3jr kvN1OBKWj/L8hSfjs4IuyNjmmjxqex1jNMRT4x5GQUMMP+rjVZYN5ZWmYtG1zi7Iso7u1W9NszC a+QcMoPAGpa7ZLChDoFkrKZ7Aw== X-Google-Smtp-Source: AGHT+IFARZscANUjyT1VVjHj9FJwPk0o4/Th44Oh6jzNuT8s/RE6rZZ0WJ9ZR9mNGMKADe5Y64JxbA== X-Received: by 2002:a05:600c:3d05:b0:436:469f:2210 with SMTP id 5b1f17b1804b1-438af40851bmr234818545e9.1.1738065353123; Tue, 28 Jan 2025 03:55:53 -0800 (PST) Received: from [192.168.68.163] ([145.224.65.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa599sm174728255e9.7.2025.01.28.03.55.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jan 2025 03:55:52 -0800 (PST) Message-ID: <44bd0d5e-a232-49c3-ba2f-e63e2f2c99be@linaro.org> Date: Tue, 28 Jan 2025 11:55:51 +0000 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 v9 5/6] Coresight: Add Coresight TMC Control Unit driver To: Jie Gan Cc: Tingwei Zhang , Jinlong Mao , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Suzuki K Poulose , Mike Leach , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio References: <20250124072537.1801030-1-quic_jiegan@quicinc.com> <20250124072537.1801030-6-quic_jiegan@quicinc.com> Content-Language: en-US From: James Clark In-Reply-To: <20250124072537.1801030-6-quic_jiegan@quicinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 24/01/2025 7:25 am, Jie Gan wrote: > The Coresight TMC Control Unit hosts miscellaneous configuration registers > which control various features related to TMC ETR sink. > > Based on the trace ID, which is programmed in the related CTCU ATID > register of a specific ETR, trace data with that trace ID gets into > the ETR buffer, while other trace data gets dropped. > > Enabling source device sets one bit of the ATID register based on > source device's trace ID. > Disabling source device resets the bit according to the source > device's trace ID. > > Signed-off-by: Jie Gan > --- > drivers/hwtracing/coresight/Kconfig | 12 + > drivers/hwtracing/coresight/Makefile | 1 + > drivers/hwtracing/coresight/coresight-ctcu.c | 276 +++++++++++++++++++ > drivers/hwtracing/coresight/coresight-ctcu.h | 30 ++ > include/linux/coresight.h | 3 +- > 5 files changed, 321 insertions(+), 1 deletion(-) > create mode 100644 drivers/hwtracing/coresight/coresight-ctcu.c > create mode 100644 drivers/hwtracing/coresight/coresight-ctcu.h > [...] > +/* > + * ctcu_set_etr_traceid: Retrieve the ATID offset and trace ID. > + * > + * Returns 0 indicates success. None-zero result means failure. > + */ > +static int ctcu_set_etr_traceid(struct coresight_device *csdev, struct coresight_path *cs_path, > + bool enable) > +{ > + struct coresight_device *sink = coresight_get_sink(cs_path->path); > + struct ctcu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); > + u8 trace_id = cs_path->trace_id; > + int port_num; > + > + if ((sink == NULL) || !IS_VALID_CS_TRACE_ID(trace_id) || IS_ERR_OR_NULL(drvdata)) { > + dev_err(&csdev->dev, "Invalid parameters\n"); > + return -EINVAL; > + } > + > + port_num = ctcu_get_active_port(sink, csdev); > + if (port_num < 0) > + return -EINVAL; > + > + /* > + * Skip the disable session if more than one TPDM device that > + * connected to the same TPDA device has been enabled. > + */ > + if (enable) > + atomic_inc(&drvdata->traceid_refcnt[port_num][trace_id]); > + else { > + if (atomic_dec_return(&drvdata->traceid_refcnt[port_num][trace_id]) > 0) { > + dev_dbg(&csdev->dev, "Skip the disable session\n"); > + return 0; > + } > + } > + > + dev_dbg(&csdev->dev, "traceid is %d\n", cs_path->trace_id); > + > + return __ctcu_set_etr_traceid(csdev, trace_id, port_num, enable); Hi Jie, Using atomic_dec_return() here doesn't prevent __ctcu_set_etr_traceid() from running concurrent enable and disables. Once you pass the atomic_dec_return() a second call to enable it will mess it up. I think you need a spinlock around the whole thing and then the refcounts don't need to be atomics.