From patchwork Wed Apr 28 01:36:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12227873 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.0 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 1CD88C433B4 for ; Wed, 28 Apr 2021 01:39:23 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8A572613D8 for ; Wed, 28 Apr 2021 01:39:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A572613D8 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References:List-Owner; bh=Db14nPeskVmFEhzb6oYCddjKktXl2nKZ/4/B1D4CUtc=; b=ij6jQgUo3gEXYWoJIsjTZPaT7u N2kN7apar5KGCbnOYHv3jUO0dVqHZBcDZs3pZsE5z/x3giJ9XFawDF8THI5eV+e8Vt9Rn2erskCxo 9sglGoEsSaUmydFvOIcYqgRjRaj5c3oHtXwBS7XXfnb9w14ZqYEMZwxw5WoJLFJ1jfh6ZEarKGZ76 ktgd0Z0jWuzBEFFkSsAFBDUh1M3dO3XBH2xzS008TjJtYL0n0RBmT2XfSsHaPnLiok0RZYM/4kYRy CGFMM0jWHw3gtpNaLj3kOIS8ZvCfg9mSp3eSYYv4dh+Me+BtfA2l+H3mbeLX15FUsybrHR64TeVSp f9SdVYbw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbZ8p-002YMz-Dj; Wed, 28 Apr 2021 01:37:27 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbZ8g-002YMj-FJ for linux-arm-kernel@desiato.infradead.org; Wed, 28 Apr 2021 01:37:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=SzD+/k6rA+JOUB658aiLpUQHhdrlTF2H7tv6i/bGzhs=; b=igi5pwvtVjD4/afhUwljVTL14h 9rRFwYbLqA+m+639O12Yl6edNqrg4SkX1cvVMLpo3A4YXNT6m/EEZmyHAoG8HpM6WtfAOERGWNp6K 2t8LA+tIiaZqjh+e+9gD2oqnms8XeK2a99BGId3ECjvwJ+H5wI7lomSW72EkXMTeflLDGzPlrmCLl 48QT4UMDLRaCScoqLLYPtI4+u12MY3c0XfySQR/amnxdocOplmgdZBfVfK8HM2MHMiyvxTmPT8gPS wr1yeON2AjXtE92FtqYzFPmw+RP3YWIkCtIe960m75hcORnztOThXr2hG7B9koE+ZhQEzHQcBTU85 RLx4nf2A==; Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbZ8d-00H89r-Ar for linux-arm-kernel@lists.infradead.org; Wed, 28 Apr 2021 01:37:17 +0000 Received: by mail-pg1-x531.google.com with SMTP id j7so34210732pgi.3 for ; Tue, 27 Apr 2021 18:37:14 -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:mime-version :content-transfer-encoding; bh=SzD+/k6rA+JOUB658aiLpUQHhdrlTF2H7tv6i/bGzhs=; b=LKO9ybR3WXZpW4l4K5jLqcfgE3Fjk4wMHf3VJOD8ONXQ/Q3Nr9RwaOBBbicxNyJi4r ZM7AkBLEGz5Lt2S68WUPHYOILVnpPumeOpZi7g2bL1r06nPuBWE5kIENYONRvwr5TqN+ W5mhrGFgnWiwz2ZsRQh5/W1hGtzbnZ6Tn22RYmQf4FTJ8FOLxnIf9tn7pykHihFMmGju zcL3Wdl1na+Mhs1HxYqAM/UC77mePeHRWN0j9lcro4jh+0Ypt6tm0jyaRW5I38kALFLF oeVwJwOIQDKWSPdCW34m2H1WzG0Qp4zSBFbEg7p8Gm+l6o3cNSlJWf64JjECTuOfWyO/ t6Sg== 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:mime-version :content-transfer-encoding; bh=SzD+/k6rA+JOUB658aiLpUQHhdrlTF2H7tv6i/bGzhs=; b=mebc5uDi//oPkR+tsC7dA/7Ivz9zydt1o5aVNkLNXk/swFTMrccgn4BSAX2CxRFOFE sWLYlV1MGpNhaM5loTUZntlTQFnoimexyw8tL/f9zIOyTCJeip6jTKSMiFsaQfAHlJMn Uw7kpllmtHlNLl/CRJ/O3jJMOqLqG3nsATEN9uxsHMNl0vxztPpgIZ7/kJ36M7GxqX0L zPEs0JtOjRXLec69/3aj0F2GJ3GYZZSYJwWTtk4/yzkfcGNXZELru7gyZpAHJWehG4jE z8OSm50SDfVfeqeh+BTr/1xEWDg/Y7YqqoKMsq84ByL070swMtMcEmr+vFLT5Mfzp1tp vJBA== X-Gm-Message-State: AOAM532c697VYJZkL2rCpcnqN/lA1b4Jd17CKCGjN0PpaUzUjhBeAGez acF/RtBju78IYmIDOWa57qbf7w== X-Google-Smtp-Source: ABdhPJwHh287a2xHsz+3p+Lqn4sw53twlNkguGUX9tnRKAqE4Yhnk5riqtyW0/z90DQhrs82Wo7lwQ== X-Received: by 2002:a63:f30b:: with SMTP id l11mr24157262pgh.129.1619573834032; Tue, 27 Apr 2021 18:37:14 -0700 (PDT) Received: from localhost (ec2-18-167-84-74.ap-east-1.compute.amazonaws.com. [18.167.84.74]) by smtp.gmail.com with ESMTPSA id p22sm3216538pjg.39.2021.04.27.18.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 18:37:13 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [RFC PATCH] coresight: etm-perf: Correct buffer syncing for snapshot Date: Wed, 28 Apr 2021 09:36:59 +0800 Message-Id: <20210428013659.324230-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210427_183715_401100_73060EA0 X-CRM114-Status: GOOD ( 26.01 ) 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 | 21 ++++++++++++++++--- .../hwtracing/coresight/coresight-etm-perf.h | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 0f603b4094f2..5fceefe9513c 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -245,6 +245,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) { @@ -424,9 +425,23 @@ 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, here should avoid to record trace data + * when the profiled program is scheduled out and only capture + * trace data when the perf tool receives USR2 signal. + * + * This is distinguished by variable "event->ctx->is_active", + * its value is zero for profiled task scheduling out, and it + * is a non-zero value when perf tool invokes ioctl + * PERF_EVENT_IOC_DISABLE. + */ + 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)