From patchwork Wed Feb 9 10:56:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mao Jinlong X-Patchwork-Id: 12740090 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BB8FEC433F5 for ; Wed, 9 Feb 2022 10:59:19 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M84orEFadMWAaULkEBDGspu6NuZWNeX/1z7azUJZ58Q=; b=o2lPRf/1TxtWeE RIwgKLOTYxsQuclqGYBGiU8MaRM0dGXVpQriyvfb4wLTjnOJa4vsvDjo167EWQQiQeMEe4HJkWOD2 XWUY+kSDgl3Ou12F+AueWfkF7suKqOo/qCsNx+6vKI15OEz0IB0cad2lSVb3DaoqxwSOdT/EZJFNb 4ocyQKqSQo71hsycrhJ9WbQ/+DmpgpOacI3feT9g73hf2g7X25YRHzDeV3SWQzVQbxNmMf21s5Wr1 Yapc9Q5DhifCZR6qA+XpihfZpx+WIJVQYd5aWKeIm00K2IbX/28E3AvpStWrWBQubQmLGt3ZDlWse O+NSaujWRtBz6CkAjNEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHkfb-00HLW1-5j; Wed, 09 Feb 2022 10:57:55 +0000 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHkfL-00HLSJ-CG for linux-arm-kernel@lists.infradead.org; Wed, 09 Feb 2022 10:57:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1644404259; x=1675940259; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=cg10MGlJrKIR3nLHa7WUVaDqw03CeaDXenuWD5LOhV4=; b=zc1ndM4v1AXUwvV0vGTAOh5KMzguQteht5oEBstRB8jIShK4hPX+w4LE gI51mw4ZqRsuesQv8GiZjffDWNxRIC3E9y4FgkqGPbG8s4PlgXaSolmVK 0jqyWrZy3hH9tPp69+nW8KfFUMNuGck1UNRCtznN1yM8wzNhTn7OmB1pO A=; Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by alexa-out-sd-01.qualcomm.com with ESMTP; 09 Feb 2022 02:57:38 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg02-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 02:57:37 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 9 Feb 2022 02:57:37 -0800 Received: from jinlmao-gv.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 9 Feb 2022 02:57:33 -0800 From: Mao Jinlong To: Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin CC: Mao Jinlong , Mike Leach , Leo Yan , Greg Kroah-Hartman , , , , Tingwei Zhang , Yuanfang Zhang , Tao Zhang , Trilok Soni , Hao Zhang , Subject: [PATCH v3 02/10] coresight: Use bitmap to assign trace id to the sources Date: Wed, 9 Feb 2022 18:56:58 +0800 Message-ID: <20220209105706.18852-3-quic_jinlmao@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220209105706.18852-1-quic_jinlmao@quicinc.com> References: <20220209105706.18852-1-quic_jinlmao@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220209_025739_483577_812B8407 X-CRM114-Status: GOOD ( 18.60 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Except from STM and ETM/ETE, there could be other sources. Each source needs a unique trace id. Define a bitmap for the trace ids. The position of each bit represents trace id of the source. Signed-off-by: Mao Jinlong --- drivers/hwtracing/coresight/coresight-core.c | 48 ++++++++++++++++++++ include/linux/coresight-pmu.h | 11 +++++ 2 files changed, 59 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index a90097f88425..6cb55c3f41d5 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -25,8 +26,11 @@ #include "coresight-syscfg.h" static DEFINE_MUTEX(coresight_mutex); +static DEFINE_MUTEX(coresight_id_mutex); static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); +static DECLARE_BITMAP(coresight_trace_id, CORESIGHT_TRACE_ID_NUM); + /* * Use IDR to map the hash length of the source's device name * to the pointer of path for the source @@ -51,6 +55,48 @@ struct coresight_node { const u32 coresight_barrier_pkt[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; EXPORT_SYMBOL_GPL(coresight_barrier_pkt); +/* Init the coresight_trace_id bit map. */ +static void coresight_init_trace_id(void) +{ + int i; + + /* Trace id 0 is invalid. */ + set_bit(CORESIGHT_TRACE_ID_0, coresight_trace_id); + /* Trace id 1 is fixed for STM. */ + set_bit(CORESIGHT_TRACE_ID_1, coresight_trace_id); + /* Trace id from 112 to 127 are reserved. */ + for (i = CORESIGHT_TRACE_ID_112; i <= CORESIGHT_TRACE_ID_127; i++) + set_bit(i, coresight_trace_id); + /* Skip the trace ids of ETM/ETE. */ + for (i = 0; i <= cpumask_last(cpu_possible_mask); i++) + set_bit(coresight_get_trace_id(i), coresight_trace_id); + +} + +/* + * Return the first zero bit position of bitmap coresight_trace_id + * as source's trace id. + * + */ +int coresight_get_system_trace_id(void) +{ + int id; + + mutex_lock(&coresight_id_mutex); + id = find_first_zero_bit(coresight_trace_id, CORESIGHT_TRACE_ID_NUM); + /* If no zero bit is found, return error value. */ + if (id == CORESIGHT_TRACE_ID_NUM) { + mutex_unlock(&coresight_id_mutex); + return -EINVAL; + } + + set_bit(id, coresight_trace_id); + mutex_unlock(&coresight_id_mutex); + + return id; +} +EXPORT_SYMBOL(coresight_get_system_trace_id); + static const struct cti_assoc_op *cti_assoc_ops; void coresight_set_cti_ops(const struct cti_assoc_op *cti_op) @@ -1750,6 +1796,8 @@ static int __init coresight_init(void) return 0; etm_perf_exit(); + + coresight_init_trace_id(); exit_bus_unregister: bus_unregister(&coresight_bustype); return ret; diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index 4ac5c081af93..1e2c5ca4c6e6 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -32,6 +32,14 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 +/* Coresight component supports 7 bits trace id. */ +#define CORESIGHT_TRACE_ID_NUM 128 + +#define CORESIGHT_TRACE_ID_0 0 +#define CORESIGHT_TRACE_ID_1 1 +#define CORESIGHT_TRACE_ID_112 112 +#define CORESIGHT_TRACE_ID_127 127 + static inline int coresight_get_trace_id(int cpu) { /* @@ -43,4 +51,7 @@ static inline int coresight_get_trace_id(int cpu) return (CORESIGHT_ETM_PMU_SEED + (cpu * 2)); } +/* Get the trace id for the sources except from STM, ETM/ETE. */ +extern int coresight_get_system_trace_id(void); + #endif