Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp419752lqp; Tue, 11 Jun 2024 08:13:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU4IPDHQlXpr3IAEIjPBATE2sT2ARSdG2gr0nve0fUPnuvc4jE0PQjPwVUAqxOkk6KHFcj3x8Qjv69U+FAQRA7VEeNRMjjaPGg8RCqtFA== X-Google-Smtp-Source: AGHT+IFsFHdsl3J1NzU64+L/HlEhnl6TfXhkCBW2dKSPhbOLkD7aNyz+qDZiU/7TD255mZv0o5Yz X-Received: by 2002:a50:c2d9:0:b0:57c:5fc8:c95d with SMTP id 4fb4d7f45d1cf-57c5fc8ca83mr7172806a12.18.1718118830754; Tue, 11 Jun 2024 08:13:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718118830; cv=pass; d=google.com; s=arc-20160816; b=LUfNdJv5881W4AMdGpc5p9OCdxhI8iw6LWpRPoSBcbp0zeJ/OEuGtpJn7MmH+iP0bT oLNCbvwDS53f8Ub9dtCklbB7civCAuwdNzAzt5aUp2KsKM1jM6/zPaGnWuxMJO1RJk8s r4oiBjwYnW27JP+GVI2ts50TayvH5GwNF+iz4GJlbMZPHSF/mE+fxK9/VklOEt3Mqarb ES+7HyGJvTOMy96B3EMzVaXQips5LQgkZoR7OIPNrdImvB2Kfc0j80l0RO8IzywQWFsf YgIx+nL0aw1fBre3DyNrWMVXZ3sd+wWxlby7tBdE5WlYot7QcyC32A1Bjg5p5ztubct+ IRcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=eQRUGQEXgPAyNQxJCgnhX7u3U7u5yt4Zz12ZFBhMAw8=; fh=2s+eIsKHHam+jMV7/s2ffLwy54AhQ8M2v8jHKEN3Fe4=; b=TOnmVdJwhCUgVpUszkYrq4REywkxsQ12PsDLOxV+cjKyJQkpvYm2sIZ2oawSrKiZzY Z+qkAsXm9FgHdYpTSKWdgCEImH/tP03HrAhd3yBmH0mnT97v8uTAtKIrutySA2cXYnW7 0mFe/USPf7JbLSobrr5jQp4skcPiLxdxKp0RXbZggaUKJrc6ZO78sahFVfDPkWg2gv6R oOSlts4kGhCRAZaWTWM4lK1hrCYP5uVhz5Tv5QdYTzhcHWMRZoScrUSYPW/jfmm/rKgw WHLcFOMW6PEpSqMa43n2I1q/7kvrQk9Hxgyt/ToK5F+h5tsETHa3hNPXObmTGnEXRfkr aHXw==; 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-210124-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210124-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-57c59c72873si4621396a12.654.2024.06.11.08.13.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:13:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210124-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-210124-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210124-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 018621F24C57 for ; Tue, 11 Jun 2024 15:06:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32DDB43156; Tue, 11 Jun 2024 15:03:58 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49BC24AEE9; Tue, 11 Jun 2024 15:03:56 +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=1718118237; cv=none; b=sX9TxSJBGNtRHG96J593JXydh2/EWibwsIdDRI9aSdKPujDN0LOTrKgHVCNGZKF19QNbVQjDqGNz4YvuiJnjTN46+Mbv6d7itZBMIafrhO5JjZAE4uekhHHdsa9nSdAWnnMDcH7jkUqBf4cMHmu7wittmSVbI32D+G7FIIgQOJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718118237; c=relaxed/simple; bh=h3XxyN6IXydL8e0zIIIS9V4ZStSl00kff0Mk919Sp94=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mYzzdVh1Fd0zK3gLYEpEW05rVSU2blSaChWA/Y43VWsSUMN5wBxY68hPXb3lWy72xrYPK8fsyCL5RC07Qg/Nxrv7Zm/BGYZmlW49/kRV6Vo40kIcYD+YOLDcd5/GFnuvFKkzzbTmQcRswEw6seudqrnThVEgQSkWErJQ8j141ss= 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 2FB80152B; Tue, 11 Jun 2024 08:04:20 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.41.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AF1CA3F64C; Tue, 11 Jun 2024 08:03:51 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , John Garry , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v3 10/14] coresight: Make CPU id map a property of a trace ID map Date: Tue, 11 Jun 2024 16:02:21 +0100 Message-Id: <20240611150228.1802828-11-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611150228.1802828-1-james.clark@arm.com> References: <20240611150228.1802828-1-james.clark@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The global CPU ID mappings won't work for per-sink ID maps so move it to the ID map struct. coresight_trace_id_release_all_pending() is hard coded to operate on the default map, but once Perf sessions use their own maps the pending release mechanism will be deleted. So it doesn't need to be extended to accept a trace ID map argument at this point. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-trace-id.c | 16 +++++++++------- include/linux/coresight.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwtracing/coresight/coresight-trace-id.c index 5561989a03fa..8a777c0af6ea 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -13,10 +13,12 @@ #include "coresight-trace-id.h" /* Default trace ID map. Used in sysfs mode and for system sources */ -static struct coresight_trace_id_map id_map_default; +static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0); +static struct coresight_trace_id_map id_map_default = { + .cpu_map = &id_map_default_cpu_ids +}; -/* maintain a record of the mapping of IDs and pending releases per cpu */ -static DEFINE_PER_CPU(atomic_t, cpu_id) = ATOMIC_INIT(0); +/* maintain a record of the pending releases per cpu */ static cpumask_t cpu_id_release_pending; /* perf session active counter */ @@ -49,7 +51,7 @@ static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map, /* unlocked read of current trace ID value for given CPU */ static int _coresight_trace_id_read_cpu_id(int cpu, struct coresight_trace_id_map *id_map) { - return atomic_read(&per_cpu(cpu_id, cpu)); + return atomic_read(per_cpu_ptr(id_map->cpu_map, cpu)); } /* look for next available odd ID, return 0 if none found */ @@ -145,7 +147,7 @@ static void coresight_trace_id_release_all_pending(void) clear_bit(bit, id_map->pend_rel_ids); } for_each_cpu(cpu, &cpu_id_release_pending) { - atomic_set(&per_cpu(cpu_id, cpu), 0); + atomic_set(per_cpu_ptr(id_map_default.cpu_map, cpu), 0); cpumask_clear_cpu(cpu, &cpu_id_release_pending); } spin_unlock_irqrestore(&id_map_lock, flags); @@ -181,7 +183,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map goto get_cpu_id_out_unlock; /* allocate the new id to the cpu */ - atomic_set(&per_cpu(cpu_id, cpu), id); + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id); get_cpu_id_clr_pend: /* we are (re)using this ID - so ensure it is not marked for release */ @@ -215,7 +217,7 @@ static void _coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_ma } else { /* otherwise clear id */ coresight_trace_id_free(id, id_map); - atomic_set(&per_cpu(cpu_id, cpu), 0); + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); } spin_unlock_irqrestore(&id_map_lock, flags); diff --git a/include/linux/coresight.h b/include/linux/coresight.h index c16c61a8411d..7d62b88bfb5c 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -234,6 +234,7 @@ struct coresight_sysfs_link { struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); + atomic_t __percpu *cpu_map; }; /** -- 2.34.1