From patchwork Mon Jul 22 10:11:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13738648 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 2EB87C3DA59 for ; Mon, 22 Jul 2024 10:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gac0SAR3KAIOUnKehRmkrRiaYS0y2TNr3epiBL0LQk8=; b=P1+erd1blWNUs5VXIn7XRkKsXu eHOC3ccd8q6PY0hQ85f+oxTeSgPZgKGIQ5JJznxVYGNd6sqUUc4fVFcGy/NA/QlBe3BkwCVGdHL1M ye6nuCMsuv9w/NLr0zktNxddH2Z4ZkvVGYXwfxUMftNAR8pcY4qpdNaT0rBwsib161wDk6WxuozPO NRDiYUdAwejagGJqDkfnbLrJaMrFcsTNLcDbnK56DnCCKDJfDTwyZpejd5TXv5rzq7t+9v65tCVit rLu7ZWqoIG9qnozDWTw/6J7ZvFX2qz8PKJyGSWRE86Hni+R5r4K2lApNKe2lMtguIslu+mvReCFaF uNKSyq4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVq6z-00000009E2o-0FB2; Mon, 22 Jul 2024 10:17:45 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVq2v-00000009CWJ-3Li3 for linux-arm-kernel@lists.infradead.org; Mon, 22 Jul 2024 10:13:36 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ef2ed592f6so10134921fa.0 for ; Mon, 22 Jul 2024 03:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643212; x=1722248012; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gac0SAR3KAIOUnKehRmkrRiaYS0y2TNr3epiBL0LQk8=; b=O4vY+tXXWUC5Pei/b6z0xYRgPNWRdEDASDn1j+SkGL+smZk2e2DsunpefCPcCug6Bv g0EvjXChqQIo1c3BjGFGCMDf5hwLqcHCd8zdMDvex55aBE6aoYh5hsOdv5Vt7t2DFa0X eEljSfgj9qCabApMlnV/VRT3nLtvw8d8FXAM02hQ7ZASJS21SMyae7rjLcO3awEUPweL tAufx7LubeXTx/Xusi4WAuO74NxG3yEop7x7lOGsmEk/qqaWzWTOnZB3Q81MXE543rjx JYLnSEXJ91QpquWUClHzD59/ZdwQ5wDxiFi4m7aHrtYLvXMEdcKbRZjEVOwSVzh3LbeL /Pfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643212; x=1722248012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gac0SAR3KAIOUnKehRmkrRiaYS0y2TNr3epiBL0LQk8=; b=mYohCK+A2wfJFO0HUL6fyk2kOlViHRssjWLKRKmDKZSbDMfX9c72Wml9FXcf+3PT7s yd+r720BV0TfSVGrJLP+oRBrnyObG23B6n3OzowCqRU2rGscPJNDS4oqzE2Vi6OfSZMh DvII/OQy4iQJuBwwHxK24vkaV2C8uAkYvqEdz16lQRbiXU5E5/m21lU1jzYJMkRmZZ9Q WQxIh3BxunlX8JJ1/EpW0Ij51ZCWz9VLVFrU+euSYvj8RHmXwSSu2+VICn2cwOANRHX7 b/aGgsYKnBQlwQkLVfgIN/2MsOcqNS8mpIKj7hDSLquOTQe2XVq7mY1VbsQA0A3lQ4Jz xAww== X-Forwarded-Encrypted: i=1; AJvYcCWw29B56GsyxxgE5nBnl7h5EVbHHqMEmIsuA0f567Bq7vIYF/L/jYdSLxsuLONxVXfCzAtXTawWreAtRe389mv4kQvt1tpds8/iRpBOI1O8hBYEkgA= X-Gm-Message-State: AOJu0YzgN0477BPWEh9B7ydDe6Qd6f9WQ3QLLRSo23n1jSeRch04CiMp 3zz30G/tj9F66AcQTcN8zUgzumP/MTlLuiQ/hmwLE/5uzVJqOO2ixApeBMYJKnU= X-Google-Smtp-Source: AGHT+IGTZQIhy3gNPKPI7DGy65qUrKCQGhBq5C4l1bUGJPNsWt1iC1rZkJ6h0IJVzpzgCf+Q3zsCVw== X-Received: by 2002:a2e:92d5:0:b0:2ef:2cbc:9074 with SMTP id 38308e7fff4ca-2ef2cbc91c3mr21432381fa.21.1721643212217; Mon, 22 Jul 2024 03:13:32 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:31 -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 , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 13/17] coresight: Make CPU id map a property of a trace ID map Date: Mon, 22 Jul 2024 11:11:55 +0100 Message-Id: <20240722101202.26915-14-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240722_031333_918732_CF573AE3 X-CRM114-Status: GOOD ( 18.57 ) 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 From: James Clark 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 Reviewed-by: Mike Leach Tested-by: Leo Yan 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; }; /**