Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp302973lqo; Thu, 16 May 2024 06:56:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZprajUxDW0aBFbVAYCrZ5zgQb5bQZe3e9JyNY+QPg2OTHRzr8JeJzfA4MtVK8TGwPvR5HqjzoDpBAp6N08ZU5GQLpneiiTSWaRye/OQ== X-Google-Smtp-Source: AGHT+IF7I7SDeY91LT54rxFWrENjNCfuYCCp4C8e95U4Y4FRJYY5AfVXuqFL+xC3Xe0wBJlKqMlw X-Received: by 2002:a50:c082:0:b0:575:9a8:be1a with SMTP id 4fb4d7f45d1cf-57509a8be78mr1515971a12.16.1715867797648; Thu, 16 May 2024 06:56:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715867797; cv=pass; d=google.com; s=arc-20160816; b=HPXvf9Nc6LTNr5u98nKskpLK3zZKqJPQoPdJaKXDsiPdfdAX8kTnvoI2M0X9A1Yd2e aZV+Ch+dnsVsPSQ0htrj+M4H7BnWXgLWSoFBTMLhYo9SmI//QgW5GuI9cV43Qa8gv59X 21NQPhyRClxR+7KhFdjMOImt0Zv8gflbNzHG82Dx7/BC5DMe6oJBJ9AWVbifBMnPhl3u L+uhix5nCGhG0iGExrzArju34vXluhlyxbRSkW8QL7j/qZVdPOaFImY8OauAU0VWDzKc znjF7RqCOyx/mMHd/jxnMiUePU5VQGC2Np93n7PsDkaddR2rHJSSUEWFh/Hr9g42zep6 iDrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=RhPZmB5EOFpEfN9jo45MQLh9tmcAvAoTQOlO+2jhyDA=; fh=Fq+KCX6Ku7jNmflO64NTneV4ekI9QHkkyOlGghDpIBg=; b=0jroDP4aap1tqEu9t1V+T6bFTFFNt68EDJVS64nsJ+uNYkqO3ZHXqo14FeKT7dsVYK PL9do5ZYVo4MH93Z1MnjETXYI9gixfWNPABjl8u3JtPzBFfgeTl/cXQ362i/K8tpxPxF YbeLFir9/gWDX9M/utg04PB4yhHvp/JQxIOl2lsMj/tFzXl8pSnmwgSrTFq8VsnlDZwg EViLcyO9+NwxBYlcy/rSoM91ONNBEqcMD9CMiyuITn+CjFRRGeQpzoyHsjS6gzsatIo6 akSk7O7Qv6hBbYPLRxWi6IYXCIADDQXzwHgp1TQoswH8OV58WS09UxLEKBQZwOW2JFt/ 6hUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-181139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c3780a0si9146377a12.642.2024.05.16.06.56.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 06:56:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-181139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3DBCA1F23318 for ; Thu, 16 May 2024 13:56:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 072B014884E; Thu, 16 May 2024 13:56:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B6F34206C; Thu, 16 May 2024 13:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715867787; cv=none; b=asNcqzG3+OboJaHZg/tiWFFGtdV9VP90qI/AVo3V1VMLZwYTzoGd+uwZ0mdu1kqQXo424sMWkmSZXABSfrsKLWn7g4Bc1uKj1HOTX9H65lHeFuespm3uQg5rfWJfoa9oDgkLnXXDmotM45UMIKpe8YOK5YWbYBabDXap7bP5CNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715867787; c=relaxed/simple; bh=ufVV9p+KR5KWRUPFyPw4/PLj0QNqQJpk5Penf19fI4E=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=KSIi/8BkNDsuWh5rMnnuQ/szgxX42CWqI5eIRIsET2TVuOqCAhtEadBSBZFCzRPCHqGe7XZi+o0q57CDoYJ9Qjwu/i/knA0/RruV1OhJHeHcBglZpdh/Z9OyaTHYv/yGGjITY2LQP82erYgf/RtGr610ek2eGXMkTroVyo4EUpk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82BEDDA7; Thu, 16 May 2024 06:56:48 -0700 (PDT) Received: from [10.91.2.16] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E147D3F7A6; Thu, 16 May 2024 06:56:21 -0700 (PDT) Message-ID: Date: Thu, 16 May 2024 15:56:26 +0200 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 v1 2/3] coresight: Add reserve trace id support From: James Clark To: Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Tingwei Zhang , Yuanfang Zhang , Tao Zhang , songchai , Suzuki K Poulose , Mike Leach , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexander Shishkin References: <20240516025644.4383-1-quic_jinlmao@quicinc.com> <20240516025644.4383-3-quic_jinlmao@quicinc.com> <34e8c1b9-e351-46c9-abbc-2cef9d0a71db@arm.com> Content-Language: en-US In-Reply-To: <34e8c1b9-e351-46c9-abbc-2cef9d0a71db@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 16/05/2024 15:23, James Clark wrote: > > > On 16/05/2024 04:56, Mao Jinlong wrote: >> Dynamic trace id was introduced in coresight subsystem so trace id is >> allocated dynamically. However, some hardware ATB source has static trace >> id and it cannot be changed via software programming. Reserve trace id >> for this kind of hardware source. >> >> Signed-off-by: Mao Jinlong >> --- >> .../hwtracing/coresight/coresight-platform.c | 26 +++++++++++++++++++ >> .../hwtracing/coresight/coresight-trace-id.c | 24 +++++++++++++++++ >> .../hwtracing/coresight/coresight-trace-id.h | 11 ++++++++ >> include/linux/coresight.h | 1 + >> 4 files changed, 62 insertions(+) >> >> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c >> index 9d550f5697fa..d3e22a2608df 100644 >> --- a/drivers/hwtracing/coresight/coresight-platform.c >> +++ b/drivers/hwtracing/coresight/coresight-platform.c >> @@ -183,6 +183,17 @@ static int of_coresight_get_cpu(struct device *dev) >> return cpu; >> } >> >> +/* >> + * of_coresight_get_trace_id: Get the atid of a source device. >> + * >> + * Returns 0 on success. >> + */ >> +static int of_coresight_get_trace_id(struct device *dev, u32 *id) >> +{ >> + >> + return of_property_read_u32(dev->of_node, "trace-id", id); >> +} >> + >> /* >> * of_coresight_parse_endpoint : Parse the given output endpoint @ep >> * and fill the connection information in @pdata->out_conns >> @@ -315,6 +326,12 @@ static inline int of_coresight_get_cpu(struct device *dev) >> { >> return -ENODEV; >> } >> + >> +static int of_coresight_get_trace_id(struct device *dev, u32 *id) >> +{ >> + return -ENODEV; >> +} >> + >> #endif >> >> #ifdef CONFIG_ACPI >> @@ -794,6 +811,15 @@ int coresight_get_cpu(struct device *dev) >> } >> EXPORT_SYMBOL_GPL(coresight_get_cpu); >> >> +int coresight_get_trace_id(struct device *dev, u32 *id) >> +{ >> + if (!is_of_node(dev->fwnode)) >> + return -EINVAL; >> + >> + return of_coresight_get_trace_id(dev, id); Can we somehow make this function name distinct from the trace ID functions. It's a bit hard to read that it's called coresight_get_trace_id() but it doesn't actually get an ID from the existing trace ID stuff. >> +} >> +EXPORT_SYMBOL_GPL(coresight_get_trace_id); >> + >> struct coresight_platform_data * >> coresight_get_platform_data(struct device *dev) >> { >> diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwtracing/coresight/coresight-trace-id.c >> index af5b4ef59cea..536a34e9de6f 100644 >> --- a/drivers/hwtracing/coresight/coresight-trace-id.c >> +++ b/drivers/hwtracing/coresight/coresight-trace-id.c >> @@ -110,6 +110,24 @@ static int coresight_trace_id_alloc_new_id(struct coresight_trace_id_map *id_map >> return id; >> } >> >> +static int coresight_trace_id_set(int id, struct coresight_trace_id_map *id_map) >> +{ >> + unsigned long flags; >> + >> + spin_lock_irqsave(&id_map_lock, flags); >> + >> + if (WARN(!IS_VALID_CS_TRACE_ID(id), "Invalid Trace ID %d\n", id)) >> + return -EINVAL; >> + if (WARN(test_bit(id, id_map->used_ids), "ID is already used: %d\n", id)) >> + return -EINVAL; > > Do these returns not skip unlocking the spinlock? > > It might be slightly fewer changes if we update the existing > coresight_trace_id_alloc_new_id() to add a new "only_preferred" option. > > Then use the existing system id allocator which already handles the lock > and unlock properly: > > static int coresight_trace_id_map_get_system_id(struct > coresight_trace_id_map *id_map, int id, > > bool only_preferred) > { > ... > spin_lock_irqsave(&id_map_lock, flags); > /* prefer odd IDs for system components to avoid legacy CPU IDS > id = coresight_trace_id_alloc_new_id(id_map, id, true, > only_preferred); > spin_unlock_irqrestore(&id_map_lock, flags); > ... > > I suppose the end result is the same as your implementation, but it > trades making one existing function slightly more complicated instead of > adding some new ones. It's also not that obvious that there is the new reserve function, but you still free the ID with the same coresight_trace_id_put_system_id(). Another benefit of adding arguments to the existing functions is that we keep just ...get...() and ...put...(). 'Reserve' implies some other new mechanism, but it's really a normal get. I think we should do one of these two options for the top level API: #1 (when id != 0, then it's an "only preferred" preferred ID: coresight_trace_id_get_system_id(int id) coresight_trace_id_put_system_id(int id) #2 coresight_trace_id_get_system_id() coresight_trace_id_get_system_id_resrv(int id) coresight_trace_id_put_system_id(int id)