From patchwork Fri May 28 16:15:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12287253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16141C47087 for ; Fri, 28 May 2021 16:17:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C4ED0613F0 for ; Fri, 28 May 2021 16:17:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4ED0613F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=H9z2d0qf+5Tb81Ngz9jQLdxr9SM3xhAcMx1uyOwRWqo=; b=UALjTiQn0gNxNq R5oArNtOarHXCeLDq4n6XWyIHq/1ZMgdbbCT78L1qt0VTbBXiGWP0v0audebAM45/VAbqb1weRaxE erPyPs1HTnneO6bgdyG9maEsbhXltsATKw938wd44qJuBPV4V0NnS/wU+mhNvkZlgg4RgtnDf59R9 5SUAtC96WTcb6hINhi4SQARGUvx5HBdaxDFKNHlBnrs/18pThrvZhyJgebCoC4LFO0TgTryZYpcRb pzKesr5EbAdmId3SdJDMDfOXY3jHbwkWmGoQuQzRDGaNETgEjhHNPmX4kabfszqMVgAgCOWdnamrs 9Tm8hbStMhGUSYc3D6Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmf9o-00GtqG-Ov; Fri, 28 May 2021 16:16:20 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmf9a-00Gtef-Dd for linux-arm-kernel@lists.infradead.org; Fri, 28 May 2021 16:16:09 +0000 Received: by mail-pj1-x102c.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso7480124pjx.1 for ; Fri, 28 May 2021 09:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0AesoJC8dwORvJZMJlCBYhqk7Et+XhC6wlAE9oBGZmU=; b=BNXlCVIv2yFGtr4/5VcBsHUBS2FUvwvMCBbr83tzJOADVrNRwJT3qG9QbbauwZsa8N lL9oJx+4kgTstdtKP2uGfkK/4cF/valjhPq9GUC61cxGP8xE5IzliKNVw1LEtjibvEwc onD/pkaMmPlH1pHZhtNIY/6OyMVI/Ln1WeX8qXdHlrPYcgLHtAcKNTupIfGXTHAMZFdy ksb4/tAItKPY01+c97xaNU8jjlKgWiFMffVFhMLKTsVdmVKrs0PvHYmvHRK1OvktOgQB tqlQuxXtpsGxnTGnY3/l3oaNve7p1749MDSqPlx38u6gJ/6DZ9r2azPE90FmhhDQ6phi 14xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0AesoJC8dwORvJZMJlCBYhqk7Et+XhC6wlAE9oBGZmU=; b=OusVRo8W8oa/MAIQPbcQ2B3YAWBFgM3vvTaVWgzPfumSjn3NPdBNitxVrDiRTFlO5/ Z4H2cIY6OMHRgYEOlhnplnq0kMyVyz5LlmXKN/f+8o3VFd2NuotPdtzCO44Ox/UkWD4K MyiFHSQYxlG8S8uMcihkI6yY7oJO4WfKYgUxilc0DaVwELB9go8b7DJpRj7VIIr0DZKk CVpF/d2lKOhh1Ix8ALU8kat3JK4B+AQWNxzVkrGHMEDsvMQW3/vXWlJyIM28xMAB92Hu dXDA6XEM9kjWKBzlkN0LOhnZGOwB7S7XK1BIU2tupCgJH9KBqjUCvW+99J5SLAD/wqGl GKxg== X-Gm-Message-State: AOAM532ifElH3HDB3xbAseVdWEGeAk+DU0yB+Cq+LvtwRov8DyM55pWd n1nbkj/mtqZa2g+II8in1ObWMA== X-Google-Smtp-Source: ABdhPJz3sQx7BOFbfTjpVcSP7iMwnq4OEB+6a7He3sKx3CCRW9+RzFVmw36Z/fxwU+MxNrYLviZu8A== X-Received: by 2002:a17:902:d88e:b029:ff:1df8:f8b8 with SMTP id b14-20020a170902d88eb02900ff1df8f8b8mr7095746plz.4.1622218565185; Fri, 28 May 2021 09:16:05 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id u8sm4775604pgg.51.2021.05.28.09.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 09:16:04 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 1/3] coresight: etm-perf: Correct buffer syncing for snapshot Date: Sat, 29 May 2021 00:15:50 +0800 Message-Id: <20210528161552.654907-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210528161552.654907-1-leo.yan@linaro.org> References: <20210528161552.654907-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210528_091606_511754_DEF14FF3 X-CRM114-Status: GOOD ( 31.07 ) 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 The perf tool records the Arm CoreSight trace data with snapshot mode with the option '-S', when receiving USR2 signal, it is observed the captured trace data size is very varied: from several MBs to ~20MBs. This can be reproduced with the command: perf record -e cs_etm// -S \ -- dd if=/dev/zero of=/dev/null > /dev/null 2>&1 & PERFPID=$! sleep 1 kill -USR2 $PERFPID It's different for only specifying option '-S' than options '-a -S'. If without option '-a', perf tool creates separate AUX buffers for every CPU, but the tracer will be enabled only when the profiled program is scheduled onto the corresponding CPU, this might lead to record very old trace data when snapshot. Let's see below diagram: snapshot CPU0: ______###P1###__________________________________________| CPU1: __________________________###P3###____________###P5###__| CPU2: ____________________________________###P4###____________| CPU3: ________________###P2###________________________________V In this diagram, the program runs for 5 periods (from P1 to P5), these 5 periods show the task run on different CPUs, e.g. during P1 period the program runs on CPU0, and during P2 period the program is migrated to CPU1, and so on. At the end of P1 period when the program is switched out from CPU0, the ETR trace data is saved into AUX trace buffer, this AUX buffer is a dedicated buffer for CPU0's tracer. With the same logic, P2's trace data is saved into CPU3's tracer buffer, P4's trace data is saved into CPU2's buffer, P3 and P5's trace data is saved into CPU1's. Therefore, when snapshot, it saves the trace data from all AUX ring buffers (in this case, it have total 4 AUX ring buffers) into perf data file. This is why we can see varied trace data size, it's quite dependent on the task scheduling on CPUs, if the task is spinned to only one CPU and without scheduling out, it will only record trace data from only one AUX trace buffer. If the task is frequently scheduled in and out, then it gives more chance to fill trace data into the AUX buffer. In this example, it also causes the discontinuous trace data. If P3's trace data is lost after P5's trace data overwrites the AUX trace data, thus perf tool fails to record continuous trace data if only have trace data for P1/P2/P4/P5. For snapshot mode, usually the user only wants to capture the trace data for the specific time point and prior to the that point the tracer should work with free run mode. This means it's not necessary to capture trace data for task's scheduling in and out until the perf tool explicitly disables tracers for snapshot. This can be fulfilled by checking the variable "event->ctx->is_active", when the task is scheduled out this variable is set to zero, and when snapshot this variable is still non-zero value. So the driver can only record trace data only when "event->ctx->is_active" is non-zero. After applying this change, the perf tool can record the consistent trace data size for snapshot. Signed-off-by: Leo Yan --- .../hwtracing/coresight/coresight-etm-perf.c | 30 +++++++++++++++++-- .../hwtracing/coresight/coresight-etm-perf.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 6f398377fec9..fd36d0530087 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -284,6 +284,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, if (!event_data) return NULL; INIT_WORK(&event_data->work, free_event_data); + event_data->overwrite = overwrite; /* First get the selected sink from user space. */ if (event->attr.config2) { @@ -517,9 +518,32 @@ static void etm_event_stop(struct perf_event *event, int mode) if (!sink_ops(sink)->update_buffer) return; - size = sink_ops(sink)->update_buffer(sink, handle, - event_data->snk_config); - perf_aux_output_end(handle, size); + /* + * In the snapshot mode, if only specifies option '-S' (note, + * user doesn't specify option '-a' in this case), the AUX ring + * buffers are allocated for every CPU but the AUX trace is + * recorded in per-thread mode. In this mode, it's needless to + * save AUX trace data into the AUX ring buffer when the + * profiled program is scheduled out from a CPU, alternatively, + * the driver should only capture AUX trace data when the perf + * tool receives USR2 signal for taking snapshot. + * + * The variable "event->ctx->is_active" can be used to + * distinguish the cases between the program scheduling out and + * snapshot: its value is zero when the profiled task scheduled + * out, and it is a non-zero value when perf tool invokes ioctl + * PERF_EVENT_IOC_DISABLE for snapshot. + * + * Only updates AUX ring buffer for snapshot, or for the perf + * session which is not in snapshot mode. + */ + if (!event_data->overwrite || event->ctx->is_active) { + size = sink_ops(sink)->update_buffer(sink, handle, + event_data->snk_config); + perf_aux_output_end(handle, size); + } else { + perf_aux_output_end(handle, 0); + } } /* Disabling the path make its elements available to other sessions */ diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 3e4f2ad5e193..2cc3af05495f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -49,12 +49,14 @@ struct etm_filters { * @mask: Hold the CPU(s) this event was set for. * @snk_config: The sink configuration. * @path: An array of path, each slot for one CPU. + * @overwrite: Flag for snapshot mode. */ struct etm_event_data { struct work_struct work; cpumask_t mask; void *snk_config; struct list_head * __percpu *path; + bool overwrite; }; #if IS_ENABLED(CONFIG_CORESIGHT) From patchwork Fri May 28 16:15:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12287257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4778FC2B9F7 for ; Fri, 28 May 2021 16:19:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0AAA0610A2 for ; Fri, 28 May 2021 16:19:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AAA0610A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=UWd23A58EOJJz7y2WLBPqgpL8x5K012V4U4aIhgu4zU=; b=OgsqBQQjL9IGyV K7b6daLNFsyDmPhjm6aWehR4/WnxQ9oyhjOH3K4PSy9JF+zOtedEeD6c7YJMqu6vZp0ZzPhGsPJVy cD2pblkf9gdwI5cYSLioGVSXk6/vG83Os/0EKhk1+VVZQQJE2IaOqKMtVO650eF94ciuzzyhSR+KU K4ugwzvoTiuUhtEWL0Y4+SH1ZWI2stczaiqzbDT745POq2idCGgjuheBieeRXczYV1pNzCU2QZQk1 voPJvQ0D3FVCxH2kAHaOo9YQ0l/i38uUmSmDz4+blDVYh+iMulr5znDN5airvWs3g+eMD40B3PZ03 h4cwAHe/6doMsPrUy1dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmfA0-00GtuE-V2; Fri, 28 May 2021 16:16:33 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmf9d-00GtjN-QQ for linux-arm-kernel@lists.infradead.org; Fri, 28 May 2021 16:16:11 +0000 Received: by mail-pl1-x62c.google.com with SMTP id b7so1886613plg.0 for ; Fri, 28 May 2021 09:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m+tAACSiahm/3bs5QyHkgVkOiDzxcYl6AR00a4SXPyA=; b=DMBbK/3FdRkBNsXYjrHYxhpz+cpO4xoNu51B9B+KILxtBH7zeHAiPXTs8bgG2shCmY huJxTQsT3I4OOJ1KiNLd7FrCH1u++zokheKEvPOkj1TnzD9nqznY03CuJIMhyolVb5UW QUAT+x1A4CwJT6pxPGYVHLvXaAtx4VH0ZIppJwSUaW6GL/qaku99A1SezAk2Wv0hfRmE eOb/ZrT44TUTWf0MOJVq5dfSJciA0MrIFrzTVH5v/pc1ZsU8UvZ7kMrjP2nxhpxI3S3L slLg4ifDakQBJMPBFr4H2Jwtp5eiSua0s6dX/k5ZSXxPqLJWotLktncPg+4n3yXjXffx plow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m+tAACSiahm/3bs5QyHkgVkOiDzxcYl6AR00a4SXPyA=; b=TNlMxH2EmZytGYayfmfqq/phS/DFi2t9e+x6eXVG2QReJAFa1IlPfFBXbaJGHpKAum FsaiDvj5y35vQfHZ96/Pqrb73a3UUxb7wxkD7jrhPPJqE7plAHLbmpgm14x/OfpbPMO4 kTCC4GWRTvNwnEuam3ZMK8v4p2tcHAFLXP7LqoAHfdNh3bcaaOYx/QHX4t3b2pyYMkk1 H1oU56GRY7CEOMzdSfG7nLSPjL44yYoreTI/iGLHaWapuczD/i6+DWc5OaATd0wT4iMq s5Kuj9JNApyC4udv9TLGUBlLwBzC89A9Plp4/N1YmMqe7nd5Hv7aRxRYYjlM4X5cQ1So CdPA== X-Gm-Message-State: AOAM533An+hkXRfxZMmdQbKRysCkBuBSOv1Re5k1ocdwo84mK0QddsDQ GUIpd/Rt8WXeWm8hOuSVARpJ8w== X-Google-Smtp-Source: ABdhPJxp/UoP5wXTVBLkZnpvdt5dCtJPyVsBdueMl6crk5z5hQy/GERw2/4jzCQ29gVMQVESpwxMjg== X-Received: by 2002:a17:90b:1003:: with SMTP id gm3mr5256275pjb.126.1622218568621; Fri, 28 May 2021 09:16:08 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id d15sm1132273pgu.84.2021.05.28.09.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 09:16:08 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 2/3] coresight: tmc-etr: Use perf_output_handle::head for AUX ring buffer Date: Sat, 29 May 2021 00:15:51 +0800 Message-Id: <20210528161552.654907-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210528161552.654907-1-leo.yan@linaro.org> References: <20210528161552.654907-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210528_091609_868779_2EDD35C4 X-CRM114-Status: GOOD ( 19.52 ) 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 When enable the Arm CoreSight PMU event, the context for AUX ring buffer is prepared in the structure perf_output_handle, and its field "head" points the head of the AUX ring buffer and it is updated after filling AUX trace data into buffer. Current code uses an extra field etr_perf_buffer::head to maintain the header for the AUX ring buffer, thus it's not necessary and it's better to directly perf_output_handle::head. This patch removes the header etr_perf_buffer::head and directly used perf_output_handle::head as the header for AUX ring buffer. Signed-off-by: Leo Yan Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index acdb59e0e661..b22823d67680 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -32,7 +32,6 @@ struct etr_flat_buf { * @etr_buf - Actual buffer used by the ETR * @pid - The PID this etr_perf_buffer belongs to. * @snaphost - Perf session mode - * @head - handle->head at the beginning of the session. * @nr_pages - Number of pages in the ring buffer. * @pages - Array of Pages in the ring buffer. */ @@ -41,7 +40,6 @@ struct etr_perf_buffer { struct etr_buf *etr_buf; pid_t pid; bool snapshot; - unsigned long head; int nr_pages; void **pages; }; @@ -1437,16 +1435,16 @@ static void tmc_free_etr_buffer(void *config) * buffer to the perf ring buffer. */ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, + unsigned long head, unsigned long src_offset, unsigned long to_copy) { long bytes; long pg_idx, pg_offset; - unsigned long head = etr_perf->head; char **dst_pages, *src_buf; struct etr_buf *etr_buf = etr_perf->etr_buf; - head = etr_perf->head; + head = PERF_IDX2OFF(head, etr_perf); pg_idx = head >> PAGE_SHIFT; pg_offset = head & (PAGE_SIZE - 1); dst_pages = (char **)etr_perf->pages; @@ -1553,7 +1551,7 @@ tmc_update_etr_buffer(struct coresight_device *csdev, /* Insert barrier packets at the beginning, if there was an overflow */ if (lost) tmc_etr_buf_insert_barrier_packet(etr_buf, offset); - tmc_etr_sync_perf_buffer(etr_perf, offset, size); + tmc_etr_sync_perf_buffer(etr_perf, handle->head, offset, size); /* * In snapshot mode we simply increment the head by the number of byte @@ -1605,8 +1603,6 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) goto unlock_out; } - etr_perf->head = PERF_IDX2OFF(handle->head, etr_perf); - /* * No HW configuration is needed if the sink is already in * use for this session. From patchwork Fri May 28 16:15:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12287259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60B96C2B9F7 for ; Fri, 28 May 2021 16:19:23 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 21ACA61073 for ; Fri, 28 May 2021 16:19:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21ACA61073 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=pJhIpwAG4SJLQ/4TwHpxfm66D16xumoDQGg0KrtMpuI=; b=1NrSB4x5wPqYmG WJhRAv6B0BYgAehVKwy+kdM1nOzETg7L/NaC38VFvRF+4vb2SYfVm+T7VjXRV+2pODKfUlD/KP54k aLERvohZ6PVvWghSYCq0A1sAr8LWFAFFxvaJmU5iK1YgqOcBoCFnZTVk2Ot290uigqPZ4jrOH11mM eO77nzm4rkRxU3D97N7uRyBIWXtif7Nb4MydeDhwIGcR9IasqlOg9hEgtMywr1qylxE+oW8rsjUIe JvxmctXjwkyvUX9GxelNxY/NE9+P+4d7BniA6I8K0duap8EOenjmjSav+U88nEnTT3QV9DIojP06j YQDpJ4PIlVXkHpQ+YqMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmfAF-00Gu0N-U9; Fri, 28 May 2021 16:16:48 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmf9h-00Gtlq-5S for linux-arm-kernel@lists.infradead.org; Fri, 28 May 2021 16:16:15 +0000 Received: by mail-pf1-x431.google.com with SMTP id p39so3593631pfw.8 for ; Fri, 28 May 2021 09:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y/uR6UFjy823T9h1mlTve3racnPLNFNFuE+dPsqOMg0=; b=rLZdoGDa22YFMNbVWyy1ldrXjbW2JYyYk4cZBwQOu1kGE/UxQM1uuewC52PpIaskGh XH+ueTHtVwVHg53MLkzr6N1ekbvnDY3cgGIN/xQrdHepkPF1L444UxwHfhjjtBnWHG2C S7ItZCkTTAopN1RCOTMAqroGu8bghVgOy9XZOhfyQZvAb5303lv3j+T5xyrN2MqMQwWP g4h6tadBZBpYfohNEwqrzENLTnZ8++xfmQqpx3sk1mtgA4zZWALsjlsp4K+JMZO8c/TP pDU/FMbfoxp1FWCS/Xp90rjkQkeF9yXEQYzE8PFBEMz0ZFcSEiOTZd76U28fZl1JJsdE t5Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y/uR6UFjy823T9h1mlTve3racnPLNFNFuE+dPsqOMg0=; b=PJd0jHwaSYU6JSdtHZxd+ynnRpQk8MoC0ij+qO0WPigxWQiDRKgPGBDCOhHuKjFK0l miLLVUoFfxgd6gT0aqcRRno/7k+erlZ5JxE1AszxEZFvCdPcxodmjsBHQyXz7Yumrd1x ZNV57Cn3HwoZjCSU7QppZyKxi3CoIM3T2fpwf/xL+E5ApPR7WDKc+MA0HBOBRe0g3zIT O+E5hnkhABnuZ7szISlys0sSVsrH0SWkKVzGkeEGQjam1BPc+HEeDytkDYngcObPr0n6 IrVKO25RmMasoc+/0d8BqRxbqx0x1z1uqRo6pYLRDZOMgWLrRj15bpQFz7emtVh4M06m yGVA== X-Gm-Message-State: AOAM530cfiDxR8M02feID0M5aJRd4Wy5JH7W5gruieWBI8kzVxdv7P+k EpVA81l2FN4HfesYy0x6HkkvXA== X-Google-Smtp-Source: ABdhPJxBApn4DIy9lwwZWSS4A3P7mLCvPpxj1osq9Z0K0uNkJ0X+DpKM5inRd7ySKCdXdsiCqRVAxQ== X-Received: by 2002:a63:d213:: with SMTP id a19mr9803271pgg.28.1622218571827; Fri, 28 May 2021 09:16:11 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id k20sm4809997pgl.72.2021.05.28.09.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 09:16:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 3/3] perf cs-etm: Remove callback cs_etm_find_snapshot() Date: Sat, 29 May 2021 00:15:52 +0800 Message-Id: <20210528161552.654907-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210528161552.654907-1-leo.yan@linaro.org> References: <20210528161552.654907-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210528_091613_227487_3EC0F77B X-CRM114-Status: GOOD ( 29.42 ) 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 The callback cs_etm_find_snapshot() is invoked for snapshot mode, its main purpose is to find the correct AUX trace data and returns "head" and "old" (we can call "old" as "old head") to the caller, the caller __auxtrace_mmap__read() uses these two pointers to decide the AUX trace data size. cs_etm_find_snapshot() should be removed with below reasons: - The first thing in cs_etm_find_snapshot() is to check if the head has wrapped around, if it is not, directly bails out. The checking is pointless, this is because the "head" and "old" pointers both are monotonical increasing so they never wrap around. - cs_etm_find_snapshot() adjusts the "head" and "old" pointers and assumes the AUX ring buffer is fully filled with the hardware trace data, so it always calculates the difference "mm->len" between "head" and "old". Let's imagine the snapshot is taken in very short interval, the tracers only fill a small chunk of the trace data into the AUX ring buffer, in this case, it's wrongly to copy the whole the AUX ring buffer to perf file. - As the "head" and "old" pointers are monotonically increased, the function __auxtrace_mmap__read() handles these two pointers properly. It calculates the reminders for these two pointers, and the size is clamped to be never more than "snapshot_size". We can simply reply on the function __auxtrace_mmap__read() to calculate the correct result for data copying, it's not necessary to add Arm CoreSight specific callback. Signed-off-by: Leo Yan Reviewed-by: James Clark Tested-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 133 ------------------------------ 1 file changed, 133 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index d942f118d32c..85168d87b2d7 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -38,8 +38,6 @@ struct cs_etm_recording { struct auxtrace_record itr; struct perf_pmu *cs_etm_pmu; struct evlist *evlist; - int wrapped_cnt; - bool *wrapped; bool snapshot_mode; size_t snapshot_size; }; @@ -734,135 +732,6 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, return 0; } -static int cs_etm_alloc_wrapped_array(struct cs_etm_recording *ptr, int idx) -{ - bool *wrapped; - int cnt = ptr->wrapped_cnt; - - /* Make @ptr->wrapped as big as @idx */ - while (cnt <= idx) - cnt++; - - /* - * Free'ed in cs_etm_recording_free(). Using realloc() to avoid - * cross compilation problems where the host's system supports - * reallocarray() but not the target. - */ - wrapped = realloc(ptr->wrapped, cnt * sizeof(bool)); - if (!wrapped) - return -ENOMEM; - - wrapped[cnt - 1] = false; - ptr->wrapped_cnt = cnt; - ptr->wrapped = wrapped; - - return 0; -} - -static bool cs_etm_buffer_has_wrapped(unsigned char *buffer, - size_t buffer_size, u64 head) -{ - u64 i, watermark; - u64 *buf = (u64 *)buffer; - size_t buf_size = buffer_size; - - /* - * We want to look the very last 512 byte (chosen arbitrarily) in - * the ring buffer. - */ - watermark = buf_size - 512; - - /* - * @head is continuously increasing - if its value is equal or greater - * than the size of the ring buffer, it has wrapped around. - */ - if (head >= buffer_size) - return true; - - /* - * The value of @head is somewhere within the size of the ring buffer. - * This can be that there hasn't been enough data to fill the ring - * buffer yet or the trace time was so long that @head has numerically - * wrapped around. To find we need to check if we have data at the very - * end of the ring buffer. We can reliably do this because mmap'ed - * pages are zeroed out and there is a fresh mapping with every new - * session. - */ - - /* @head is less than 512 byte from the end of the ring buffer */ - if (head > watermark) - watermark = head; - - /* - * Speed things up by using 64 bit transactions (see "u64 *buf" above) - */ - watermark >>= 3; - buf_size >>= 3; - - /* - * If we find trace data at the end of the ring buffer, @head has - * been there and has numerically wrapped around at least once. - */ - for (i = watermark; i < buf_size; i++) - if (buf[i]) - return true; - - return false; -} - -static int cs_etm_find_snapshot(struct auxtrace_record *itr, - int idx, struct auxtrace_mmap *mm, - unsigned char *data, - u64 *head, u64 *old) -{ - int err; - bool wrapped; - struct cs_etm_recording *ptr = - container_of(itr, struct cs_etm_recording, itr); - - /* - * Allocate memory to keep track of wrapping if this is the first - * time we deal with this *mm. - */ - if (idx >= ptr->wrapped_cnt) { - err = cs_etm_alloc_wrapped_array(ptr, idx); - if (err) - return err; - } - - /* - * Check to see if *head has wrapped around. If it hasn't only the - * amount of data between *head and *old is snapshot'ed to avoid - * bloating the perf.data file with zeros. But as soon as *head has - * wrapped around the entire size of the AUX ring buffer it taken. - */ - wrapped = ptr->wrapped[idx]; - if (!wrapped && cs_etm_buffer_has_wrapped(data, mm->len, *head)) { - wrapped = true; - ptr->wrapped[idx] = true; - } - - pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n", - __func__, idx, (size_t)*old, (size_t)*head, mm->len); - - /* No wrap has occurred, we can just use *head and *old. */ - if (!wrapped) - return 0; - - /* - * *head has wrapped around - adjust *head and *old to pickup the - * entire content of the AUX buffer. - */ - if (*head >= mm->len) { - *old = *head - mm->len; - } else { - *head += mm->len; - *old = *head - mm->len; - } - - return 0; -} - static int cs_etm_snapshot_start(struct auxtrace_record *itr) { struct cs_etm_recording *ptr = @@ -900,7 +769,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr) struct cs_etm_recording *ptr = container_of(itr, struct cs_etm_recording, itr); - zfree(&ptr->wrapped); free(ptr); } @@ -928,7 +796,6 @@ struct auxtrace_record *cs_etm_record_init(int *err) ptr->itr.recording_options = cs_etm_recording_options; ptr->itr.info_priv_size = cs_etm_info_priv_size; ptr->itr.info_fill = cs_etm_info_fill; - ptr->itr.find_snapshot = cs_etm_find_snapshot; ptr->itr.snapshot_start = cs_etm_snapshot_start; ptr->itr.snapshot_finish = cs_etm_snapshot_finish; ptr->itr.reference = cs_etm_reference;