Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp432856lqh; Tue, 7 May 2024 03:52:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJZDjIr0yH76D3sT2rI0IXv0+ag8A/bT7N2GGYagfzDEdEQL88Rdz3kxgoRtU9QB8Gb6HOxYIrNuD1FNlRizw+6Ej/NUdQvMAHhy0aJg== X-Google-Smtp-Source: AGHT+IGEiTMarLskQ1FLPnH7tSGoO3+36kKMpHGLTO+Bzz3szFqMFw3zedzJj9ZYFZuLjr1tfTnT X-Received: by 2002:a17:907:829b:b0:a59:9b8e:aa61 with SMTP id mr27-20020a170907829b00b00a599b8eaa61mr6703727ejc.35.1715079178624; Tue, 07 May 2024 03:52:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715079178; cv=pass; d=google.com; s=arc-20160816; b=A/CwBuSwJp5Uv7HhNjE4p59UlukPNtuasjNLMw6JGjteq6ndhrX0Y27+zgyszQVg8L LX17AqtCOSzVJN0AsddD58EmTe6jF4qzrBkM5YIzvRTbttPyjTARwrf4jo88RztY+A2l wRjsqunZ4NzMsgLYBKfOK3JZgj2vVgwK4V9WOa4riRW2AJz8UJ7qbkaV/P7UPRWQvryo L9H19ZmT4jrYTXMj8LecUGpUJaDvlnjCXrOjJ90/LZ8zNGF9YAs67WEQzao/Bbki2Q0w 5xs5EtxTKxk88nqFSlVh7rLKz3uXUwfolg3ANm/JCtfOyP4OaWhk2L6MtpJebqpU4Mlc E7OA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=KVVRtcr7udMoBWkcoRDnjRZlfye8fmvDV+sQLedBCZc=; fh=im8hDodNVMZvlQ1vbFrK3buvHwOLIqGt/s2qXZ26vNE=; b=icEL20ZMPQSBvkuquadHaoe8qSHlXTuBDDZFVRQ/oRe7EWrPo7cf+FewHQKjxzYPIZ bUemYmy49bLOfMOVmoKTccM0Ae/trWXzo4cfaTgbHdBKp90F/UabzonZykh3eStPLF/f ep8dxwHwIKiEaciFP00KuElR88JzqeOR27So/UnCjJyBA7qg+2IYq7b+vIfpx14/cb/J jKmp3nZz4ITM/7kgcrawMdYyLp6SG64gPqZdaS2pKAO0sZw9HvPA3nWY1eQ+mICAYNL6 LgDagT+Q4lR0mtH+kfADFVFpzdY7c5ukdsjG6t5CZHjE4Jp5v9DUT5gkFPPeplgg6euo rhNQ==; 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-171142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171142-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go35-20020a1709070da300b00a59bace2915si3453535ejc.506.2024.05.07.03.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 03:52:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-171142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171142-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 9FD701F25B04 for ; Tue, 7 May 2024 10:52:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB8631509A0; Tue, 7 May 2024 10:52:41 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18A6814EC77; Tue, 7 May 2024 10:52:38 +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=1715079161; cv=none; b=Yn4/374Fs3nirpy7618F+dioGGNUdV3VK/PzbG5wipmJoCkQ6dqkR5D6gW5ixGLawRnce9gbhEYIeqJ4JPj5qWImTNIq+P7Zodqn9Qt+ZHY1GopfD4BJ04eJOAULUiTPGAQZGidHTKtcvuqC14nsN3OBI7JO2RWYneSp5vnTbAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715079161; c=relaxed/simple; bh=XL3ufL40J2O1QuQ7klcMbNbpYpQn7hiXcBzFLETGSEk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rF+czUn83b6iVxx2hQsAx2OJDelwkWBdBBF6eZu/yZO6+k+qEyk9yeGuRBxXu9c2ZO4VjqwZBQTQrYS6DEhMc7Er1lS0WxxFoy5SuEdyxNZLxtFmNSmYEMjzXrLOeNBzPMALJ4uFqGja76qdnGsCGliVjdCxwHpX9NQ1c6omQoo= 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 62F461063; Tue, 7 May 2024 03:53:04 -0700 (PDT) Received: from [10.1.197.1] (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD45C3F587; Tue, 7 May 2024 03:52:35 -0700 (PDT) Message-ID: <3923dc07-c037-452a-9e77-d407703876cd@arm.com> Date: Tue, 7 May 2024 11:52:34 +0100 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 14/17] coresight: Use per-sink trace ID maps for Perf sessions To: James Clark , linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, scclevenger@os.amperecomputing.com, coresight@lists.linaro.org, mike.leach@linaro.org Cc: Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , John Garry , Will Deacon , Leo Yan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com References: <20240429152207.479221-1-james.clark@arm.com> <20240429152207.479221-16-james.clark@arm.com> Content-Language: en-US From: Suzuki K Poulose In-Reply-To: <20240429152207.479221-16-james.clark@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 29/04/2024 16:22, James Clark wrote: > This will allow sessions with more than CORESIGHT_TRACE_IDS_MAX ETMs > as long as there are fewer than that many ETMs connected to each sink. > > Each sink owns its own trace ID map, and any Perf session connecting to > that sink will allocate from it, even if the sink is currently in use by > other users. This is similar to the existing behavior where the dynamic > trace IDs are constant as long as there is any concurrent Perf session > active. It's not completely optimal because slightly more IDs will be > used than necessary, but the optimal solution involves tracking the PIDs > of each session and allocating ID maps based on the session owner. This > is difficult to do with the combination of per-thread and per-cpu modes > and some scheduling issues. The complexity of this isn't likely to worth > it because even with multiple users they'd just see a difference in the > ordering of ID allocations rather than hitting any limits (unless the > hardware does have too many ETMs connected to one sink). > > Signed-off-by: James Clark > --- > drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ > drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++------- > include/linux/coresight.h | 1 + > 3 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index 9fc6f6b863e0..d1adff467670 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev) > struct coresight_device *csdev = to_coresight_device(dev); > > fwnode_handle_put(csdev->dev.fwnode); > + free_percpu(csdev->perf_id_map.cpu_map); > kfree(csdev); > } > > @@ -1159,6 +1160,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) > csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev)); > dev_set_name(&csdev->dev, "%s", desc->name); > > + if (csdev->type == CORESIGHT_DEV_TYPE_SINK || > + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) { > + csdev->perf_id_map.cpu_map = alloc_percpu(atomic_t); > + if (!csdev->perf_id_map.cpu_map) { > + ret = -ENOMEM; > + goto err_out; > + } > + } > /* > * Make sure the device registration and the connection fixup > * are synchronised, so that we don't see uninitialised devices > @@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) > err_out: > /* Cleanup the connection information */ > coresight_release_platform_data(NULL, desc->dev, desc->pdata); > + kfree(csdev); > return ERR_PTR(ret); > } > EXPORT_SYMBOL_GPL(coresight_register); > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c > index 177cecae38d9..86ca1a9d09a7 100644 > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c > @@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work) > struct list_head **ppath; > > ppath = etm_event_cpu_path_ptr(event_data, cpu); > - if (!(IS_ERR_OR_NULL(*ppath))) > + if (!(IS_ERR_OR_NULL(*ppath))) { > + struct coresight_device *sink = coresight_get_sink(*ppath); > + > + coresight_trace_id_put_cpu_id(cpu, &sink->perf_id_map); > coresight_release_path(*ppath); > + } > *ppath = NULL; > - coresight_trace_id_put_cpu_id(cpu, coresight_trace_id_map_default()); > } > > /* mark perf event as done for trace id allocator */ > @@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, > } > > /* ensure we can allocate a trace ID for this CPU */ > - trace_id = coresight_trace_id_get_cpu_id(cpu, > - coresight_trace_id_map_default()); > + trace_id = coresight_trace_id_get_cpu_id(cpu, &sink->perf_id_map); We could either store the perf_id_map or the traceid itself in the event_data isn't it ? Rather than passing the idmap to enable_source ? Suzuki