Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4528408pxb; Tue, 2 Nov 2021 11:10:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz09GmKAzjDe5xxDZxBjYdIENMjbcaTpeP/0Yjtv2OX8V8nwll5v4TIZhKwb3P5ghCbFr3T X-Received: by 2002:a05:6402:350a:: with SMTP id b10mr53841088edd.345.1635876628120; Tue, 02 Nov 2021 11:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635876628; cv=none; d=google.com; s=arc-20160816; b=yC5t75IxUnDJ3QYCTRjAq83+rwazMpEeAvskAJAbyHJvQKtzwjUl74foJogX8142ED BGh95X8kF6VJ+9ycxJEuEfhQ7WREranBzMFrSX2MC5MGhNfqgBUZiRFlqXeu3qllpcdf DYlNiUlcnqdga7czpRu5r+qfRCwJtXemjW/V9nqVbfGvgo/qLg3CZB78553I2xZfboS0 1K9EUeQz4z7xKyJ/FqSzEifBZ+vbNVzo94g3ELtT/j4jJQ6jMQ8DjouusVYhmm5gid/y bi4CmMcvhDe6sWAAIWICxn6eFiFrBdPn/WtLgS11VG2VPGNuqz5tgeM6ZfRNFEgoQXRY 3ecg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=jNWSg+CUPJBGXvbuVn3bxfAWC7C2hCYcN3oo4tx1NwI=; b=JH5ZWpzZsy20RdtyS3vcffNs+8XSmVTjPxMOkA9qjHgZjRRf+/baYNwmLT7dhtpY+d vEIRGTPCTiZPTPDTeoorTsMkw7NONFPcExCYbn10ZLUrO+GZeYF0RVYia6P7EzMrzbFD XXKC62Afu6H8Egi3QZCNwkTCusNBFgi0DDn20geU6DmvSRn14txREm52Eg4L5f4F40+v av19HjeIEfyqIKWmKg9/a6bcRUDNXch4bmyG/bk2C6IbbsEgEsBwnLG24NZ+Kh9XJkFF +TBrBWDYdOqT+WJE3IFrWbWeXtviOpfbm4AqDVzV7Ra0J4KJ2Ms99l6VcAcdowTpmbnf vTww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg16si33635581ejc.752.2021.11.02.11.10.01; Tue, 02 Nov 2021 11:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234823AbhKBSKi (ORCPT + 99 others); Tue, 2 Nov 2021 14:10:38 -0400 Received: from foss.arm.com ([217.140.110.172]:41294 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234834AbhKBSKh (ORCPT ); Tue, 2 Nov 2021 14:10:37 -0400 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 E3C6511D4; Tue, 2 Nov 2021 11:08:01 -0700 (PDT) Received: from ubuntu-18-04-aarch64-spe-2.warwick.arm.com (ubuntu-18-04-aarch64-spe-2.warwick.arm.com [10.32.33.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1243A3F7B4; Tue, 2 Nov 2021 11:07:59 -0700 (PDT) From: German Gomez To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: German Gomez , Namhyung Kim , John Garry , Will Deacon , Mathieu Poirier , Leo Yan , Mark Rutland , Alexander Shishkin , Jiri Olsa , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] perf arm-spe: Track task context switch for cpu-mode events Date: Tue, 2 Nov 2021 18:07:37 +0000 Message-Id: <20211102180739.18049-2-german.gomez@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211102180739.18049-1-german.gomez@arm.com> References: <20211102180739.18049-1-german.gomez@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When perf report synthesize events from ARM SPE data, it refers to current cpu, pid and tid in the machine. But there's no place to set them in the ARM SPE decoder. I'm seeing all pid/tid is set to -1 and user symbols are not resolved in the output. # perf record -a -e arm_spe_0/ts_enable=1/ sleep 1 # perf report -q | head 8.77% 8.77% :-1 [kernel.kallsyms] [k] format_decode 7.02% 7.02% :-1 [kernel.kallsyms] [k] seq_printf 7.02% 7.02% :-1 [unknown] [.] 0x0000ffff9f687c34 5.26% 5.26% :-1 [kernel.kallsyms] [k] vsnprintf 3.51% 3.51% :-1 [kernel.kallsyms] [k] string 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f66ae20 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f670b3c 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f67c040 1.75% 1.75% :-1 [kernel.kallsyms] [k] ___cache_free 1.75% 1.75% :-1 [kernel.kallsyms] [k] __count_memcg_events Like Intel PT, add context switch records to track task info. As ARM SPE support was added later than PERF_RECORD_SWITCH_CPU_WIDE, I think we can safely set the attr.context_switch bit and use it. Signed-off-by: Namhyung Kim Signed-off-by: German Gomez --- tools/perf/arch/arm64/util/arm-spe.c | 6 +++++- tools/perf/util/arm-spe.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index a4420d4df..58ba8d15c 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -166,8 +166,12 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, tracking_evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__empty(cpus)) + if (!perf_cpu_map__empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); + evsel__set_sample_bit(tracking_evsel, CPU); + /* also track task context switch */ + tracking_evsel->core.attr.context_switch = 1; + } return 0; } diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c index 58b7069c5..230bc7ab2 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -681,6 +681,25 @@ static int arm_spe_process_timeless_queues(struct arm_spe *spe, pid_t tid, return 0; } +static int arm_spe_context_switch(struct arm_spe *spe, union perf_event *event, + struct perf_sample *sample) +{ + pid_t pid, tid; + int cpu; + + if (!(event->header.misc & PERF_RECORD_MISC_SWITCH_OUT)) + return 0; + + pid = event->context_switch.next_prev_pid; + tid = event->context_switch.next_prev_tid; + cpu = sample->cpu; + + if (tid == -1) + pr_warning("context_switch event has no tid\n"); + + return machine__set_current_tid(spe->machine, cpu, pid, tid); +} + static int arm_spe_process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, @@ -718,6 +737,12 @@ static int arm_spe_process_event(struct perf_session *session, } } else if (timestamp) { err = arm_spe_process_queues(spe, timestamp); + if (err) + return err; + + if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE || + event->header.type == PERF_RECORD_SWITCH) + err = arm_spe_context_switch(spe, event, sample); } return err; -- 2.25.1