From nobody Sat Feb 7 06:13:47 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0B072D47E4 for ; Fri, 23 Jan 2026 22:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206950; cv=none; b=E3MYq8q6l54zGMT+ZDnwm/B/ol+pP85bgD2Vwob5RdlmxUtdsFGhrTLOK/0ij+vxQYYZ1Cpj90kEDemKrjZ/1hOHIEt2ZLZxDuOvwjExaa8/I9ytM9RNArUjnqA3z7iwKMDoaG1S1g7x15GWy67irxZAR4f4nADgReNDC0gsnPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206950; c=relaxed/simple; bh=EkQnCI1q2pDYkyyeg8Nk3WtRPBP8LP0/xBc6aVriJtU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oFN0H4PCwRSpz9gubaME4yd0KxHU9WaU/RkUs2oWV21L1aVRXK5zz8Ar0PuD0AY0NYW0l5VdDgxGQ64Ko8JBaULwsBikO7SS2WtbDJGqCI1qbpPUCHfH2DtAff9bKKY2RaNv6gFBea8nPHj1/yFnPCFxeqi+QHECcdXm/jyiTV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MOucuvzS; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MOucuvzS" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b7174ab5faso3663408eec.1 for ; Fri, 23 Jan 2026 14:22:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769206947; x=1769811747; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=4oNTQ1SpPeomHkYYljia0MlXVcvHzoqRR2FSTzw2VhE=; b=MOucuvzSR+lz8hnVeqH3Vq9KyMGwVUGP6XD6pBkz60plKAkoPLb3sKhGIrqe/XQqAW 098H3EOAmt3A0DMxawZEVmeC/dHT33SYTenfs9hSfEnp3Kvmty+VKBlDtEsNYNIzt2NY ZHjDX20Ou+vH0o8AkZDouI388dbrr3q1Q43uLyPvv83WNBZufaf2l6nOHSBJuUNyC3tS dI+YQeqBIjv/lM1GMW+MIU1/2yY3sv8oScOWHngvSigFRJfX7mH3PtOQRYimvtvpMGGD +jO+rUgPyYq90P2ZwVVGF4aiofqdKvHObwUm+bdv/Qh3nd+9PFcKeUwOdD/zxyDbaiDf wJzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769206947; x=1769811747; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4oNTQ1SpPeomHkYYljia0MlXVcvHzoqRR2FSTzw2VhE=; b=xCI7an/VX0VqBxrr3H1Bt3cpBwTh3ts54TAe8RRR0aQ9Gx4c50KNnEJn+DRkRFf6Hl S6OOykLDq40WLj3oatBukiBM3uBV7/7dbIa0Ro5CiCL91vUUqZeNgjCDOGkpP3h/KPjY 5p+CKidhPEPzT7j79RlKfXjIZ1RLcuCzb9lKkRfgeAhW8j3r65uV1Wv8PSjYSWwgkaVR fhvHdj7/75Nbycwfo1d3XduV4aPq/qBhH3NQR/Gd0P5EkQElpnguyZR7J4IphguD8VAT oNPMUZMSGiZTblHTunSTi//dhJyLot9U9Qs7/o9x+pt5X58cSGgPqILfRhglssnonOLa rY3g== X-Forwarded-Encrypted: i=1; AJvYcCWP+XoQGhb3r51ibCg3bOtBK+ixfVAGhZo32ytMO87VCXz1ieaNsThE2N/HFFKYi/mGMn/ReZ8RDwEO3fU=@vger.kernel.org X-Gm-Message-State: AOJu0YzvFBMwv/mWjD6BoEgVE9m5/mCz5uHD0gMfqvRuvYDKS/ggHMel 892YHs90sHslaV/r3e3nw5F/bzCry83GVsm/EJg+HTY8SQjHQmreixxPxJ5bE9yS6B3liKVJQN4 uXeiokd2gLQ== X-Received: from dycqb8.prod.google.com ([2002:a05:7300:fe88:b0:2b7:4519:63a4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ef89:b0:2a4:3593:646a with SMTP id 5a478bee46e88-2b739b748d6mr2243173eec.26.1769206946998; Fri, 23 Jan 2026 14:22:26 -0800 (PST) Date: Fri, 23 Jan 2026 14:22:06 -0800 In-Reply-To: <20260123222209.1181249-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260123222209.1181249-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260123222209.1181249-2-irogers@google.com> Subject: [PATCH v1 1/4] perf dso: Factor out e_machine reading for use in thread From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Guo Ren , Tianyou Li , Athira Rajeev , Stephen Brennan , Aditya Bodkhe , Chun-Tse Shao , Swapnil Sapkal , Howard Chu , Sergei Trofimovich , Shimin Guo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the resilient e_machine reading code in dso so that it may be used in thread. As there is no dso in that case, make the dso optional. This makes some minor other changes as the swap type from the dso cannot be ascertained. Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 110 ++++++++++++++++++++++++--------------- tools/perf/util/dso.h | 10 ++-- tools/perf/util/thread.c | 5 +- 3 files changed, 75 insertions(+), 50 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 3b272a6fae24..91c9f7cb9d8c 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1203,6 +1203,68 @@ ssize_t dso__data_read_offset(struct dso *dso, struc= t machine *machine, return data_read_write_offset(dso, machine, offset, data, size, true); } =20 +static enum dso_swap_type dso_swap_type__from_elf_data(unsigned char eidat= a) +{ + static const unsigned int endian =3D 1; + + switch (eidata) { + case ELFDATA2LSB: + /* We are big endian, DSO is little endian. */ + return (*(unsigned char const *)&endian !=3D 1) ? DSO_SWAP__YES : DSO_SW= AP__NO; + case ELFDATA2MSB: + /* We are little endian, DSO is big endian. */ + return (*(unsigned char const *)&endian !=3D 0) ? DSO_SWAP__YES : DSO_SW= AP__NO; + default: + return DSO_SWAP__UNSET; + } +} + +/* Reads e_machine from fd, optionally caching data in dso. */ +uint16_t dso__read_e_machine(struct dso *optional_dso, int fd) +{ + uint16_t e_machine =3D EM_NONE; + unsigned char e_ident[EI_NIDENT]; + enum dso_swap_type swap_type; + + _Static_assert(offsetof(Elf32_Ehdr, e_ident) =3D=3D 0, "Unexpected offset= "); + _Static_assert(offsetof(Elf64_Ehdr, e_ident) =3D=3D 0, "Unexpected offset= "); + if (pread(fd, &e_ident, sizeof(e_ident), 0) !=3D sizeof(e_ident)) + return EM_NONE; // Read failed. + + if (memcmp(e_ident, ELFMAG, SELFMAG) !=3D 0) + return EM_NONE; // Not an ELF file. + + if (e_ident[EI_CLASS] =3D=3D ELFCLASSNONE || e_ident[EI_CLASS] >=3D ELFCL= ASSNUM) + return EM_NONE; // Bad ELF class (32 or 64-bit objects). + + if (e_ident[EI_VERSION] !=3D EV_CURRENT) + return EM_NONE; // Bad ELF version. + + swap_type =3D dso_swap_type__from_elf_data(e_ident[EI_DATA]); + if (swap_type =3D=3D DSO_SWAP__UNSET) + return EM_NONE; // Bad ELF data encoding. + + /* Cache the need for swapping. */ + if (optional_dso) { + assert(dso__needs_swap(optional_dso) =3D=3D DSO_SWAP__UNSET || + dso__needs_swap(optional_dso) =3D=3D swap_type); + dso__set_needs_swap(optional_dso, swap_type); + } + + { + _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + if (pread(fd, &e_machine, sizeof(e_machine), 18) !=3D sizeof(e_machine)) + return EM_NONE; // e_machine read failed. + } + + e_machine =3D DSO_SWAP_TYPE__SWAP(swap_type, uint16_t, e_machine); + if (e_machine >=3D EM_NUM) + return EM_NONE; // Bad ELF machine number. + + return e_machine; +} + uint16_t dso__e_machine(struct dso *dso, struct machine *machine) { uint16_t e_machine =3D EM_NONE; @@ -1248,30 +1310,9 @@ uint16_t dso__e_machine(struct dso *dso, struct mach= ine *machine) */ try_to_open_dso(dso, machine); fd =3D dso__data(dso)->fd; - if (fd >=3D 0) { - unsigned char e_ident[EI_NIDENT]; - - _Static_assert(offsetof(Elf32_Ehdr, e_ident) =3D=3D 0, "Unexpected offse= t"); - _Static_assert(offsetof(Elf64_Ehdr, e_ident) =3D=3D 0, "Unexpected offse= t"); - if (pread(fd, &e_ident, sizeof(e_ident), 0) =3D=3D sizeof(e_ident) && - memcmp(e_ident, ELFMAG, SELFMAG) =3D=3D 0 && - e_ident[EI_CLASS] > ELFCLASSNONE && e_ident[EI_CLASS] < ELFCLASSNUM = && - e_ident[EI_DATA] > ELFDATANONE && e_ident[EI_DATA] < ELFDATANUM && - e_ident[EI_VERSION] =3D=3D EV_CURRENT) { - _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected o= ffset"); - _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected o= ffset"); - - if (dso__needs_swap(dso) =3D=3D DSO_SWAP__UNSET) - dso__swap_init(dso, e_ident[EI_DATA]); - - if (dso__needs_swap(dso) !=3D DSO_SWAP__UNSET && - pread(fd, &e_machine, sizeof(e_machine), 18) =3D=3D sizeof(e_machin= e) && - e_machine < EM_NUM) - e_machine =3D DSO__SWAP(dso, uint16_t, e_machine); - else - e_machine =3D EM_NONE; - } - } + if (fd >=3D 0) + e_machine =3D dso__read_e_machine(dso, fd); + mutex_unlock(dso__data_open_lock()); return e_machine; } @@ -1656,28 +1697,13 @@ void dso__put(struct dso *dso) =20 int dso__swap_init(struct dso *dso, unsigned char eidata) { - static unsigned int const endian =3D 1; - - dso__set_needs_swap(dso, DSO_SWAP__NO); + enum dso_swap_type type =3D dso_swap_type__from_elf_data(eidata); =20 - switch (eidata) { - case ELFDATA2LSB: - /* We are big endian, DSO is little endian. */ - if (*(unsigned char const *)&endian !=3D 1) - dso__set_needs_swap(dso, DSO_SWAP__YES); - break; - - case ELFDATA2MSB: - /* We are little endian, DSO is big endian. */ - if (*(unsigned char const *)&endian !=3D 0) - dso__set_needs_swap(dso, DSO_SWAP__YES); - break; - - default: + dso__set_needs_swap(dso, type); + if (type =3D=3D DSO_SWAP__UNSET) { pr_err("unrecognized DSO data encoding %d\n", eidata); return -EINVAL; } - return 0; } =20 diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index ac725bc8ea74..a95fee7d634b 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -160,12 +160,11 @@ enum dso_load_errno { __DSO_LOAD_ERRNO__END, }; =20 -#define DSO__SWAP(dso, type, val) \ +#define DSO_SWAP_TYPE__SWAP(swap_type, type, val) \ ({ \ type ____r =3D val; \ - enum dso_swap_type ___dst =3D dso__needs_swap(dso); \ - BUG_ON(___dst =3D=3D DSO_SWAP__UNSET); \ - if (___dst =3D=3D DSO_SWAP__YES) { \ + BUG_ON(swap_type =3D=3D DSO_SWAP__UNSET); \ + if (swap_type =3D=3D DSO_SWAP__YES) { \ switch (sizeof(____r)) { \ case 2: \ ____r =3D bswap_16(val); \ @@ -183,6 +182,8 @@ enum dso_load_errno { ____r; \ }) =20 +#define DSO__SWAP(dso, type, val) DSO_SWAP_TYPE__SWAP(dso__needs_swap(dso)= , type, val) + #define DSO__DATA_CACHE_SIZE 4096 #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) =20 @@ -865,6 +866,7 @@ int dso__data_file_size(struct dso *dso, struct machine= *machine); off_t dso__data_size(struct dso *dso, struct machine *machine); ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size); +uint16_t dso__read_e_machine(struct dso *optional_dso, int fd); uint16_t dso__e_machine(struct dso *dso, struct machine *machine); ssize_t dso__data_read_addr(struct dso *dso, struct map *map, struct machine *machine, u64 addr, diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index aa9c58bbf9d3..3642858e6cbc 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -458,10 +458,7 @@ static uint16_t read_proc_e_machine_for_pid(pid_t pid) snprintf(path, sizeof(path), "/proc/%d/exe", pid); fd =3D open(path, O_RDONLY); if (fd >=3D 0) { - _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); - _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); - if (pread(fd, &e_machine, sizeof(e_machine), 18) !=3D sizeof(e_machine)) - e_machine =3D EM_NONE; + e_machine =3D dso__read_e_machine(/*optional_dso=3D*/NULL, fd); close(fd); } return e_machine; --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 06:13:47 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB8772D8365 for ; Fri, 23 Jan 2026 22:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206951; cv=none; b=mC2swwgNJyqI0WLwSqlly7+P7z6CHfFItJA2GuDPnH2iCpkWsn9xflg5PcInmKjlvDL/9lLqErtwtn4J1KXvbKlKKzgWhIBdtr8bjSCxGeBaHJxGQbRbbVrojky3FEiN+Blaw8j3ObEoSeIismCJc5PodiivaJsLtXE2RZ/N6eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206951; c=relaxed/simple; bh=wWcDCBThkRzjxvkI58nrHd4ls94KVV87sGI/wAQ5CMQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=V37w0iM4sJfpO4JlrDadbMB86dbFpxNJKOXabp3EJiVucrnoPxxHaYuKjaf6M000/Il8NOC8harfzGAnxoEWTMUTiW9IjWVEUh04x9xrbh4uEqtZrdg0aLQCxB275GtQSAGgu/iUCleW+mK+/5FTVrd68WCjO0QGeCgP8NzbxII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iakSTq1q; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iakSTq1q" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b71d3ac508so2669603eec.0 for ; Fri, 23 Jan 2026 14:22:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769206949; x=1769811749; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cf7Y7FADq4PznKGJpGCjRHvBcF+nvW6t+j6b4wRmujU=; b=iakSTq1q0lVt8qbWV/1MbSXbUqZg2/4mfcEY44knmuhNyVYttgpMbbkuBXxV0B1GZH jIaKOqmz/5ZKM7RqLPprE1SoVzWN5oDmhPMMsTFw/rw7jp5NgqnHbUXCBsZblndg/5ju rVFHUAuzEwD9zVF8KncPAEv7jtqReXvAZcwtyvf+B3PoYo0hxYQlyLav7tl1dhupD30/ m7Jk5PdLKcg+BqYuv3oqFj9o1yJPJd7bHwEKpoBu4haF8B1ZJtL1Og+hUI98JS1SrsIo JMpRLscgTcn+00j3Mf0O66DrrVC5H5Q45ZmoswibkkhKDRB8I0nyfki16Eu18HkJ+RaO LZwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769206949; x=1769811749; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cf7Y7FADq4PznKGJpGCjRHvBcF+nvW6t+j6b4wRmujU=; b=U0vGfja7JGIeDyUmkclGChQnU9LoPLObslKfHOPXO2wRfS94o5qiWQak/vI17nIqgq Os4Me9k2nNy3Uu1HmdQG9iRYRW8+ETtwkgUCrQZLEM5D7IlK4EW2jHIUWNYeQwrOC+LA bynRJNSWfwB/Utl61evSuhErpEdsdksr4JwCqwqwlyZpRfbsYfuanbHMyED4XggIdCzc ZWohOvoMYAKATVRvs8GbZK5RJjRXBogCr+YsgtNwcge7vf5VH2obEipMmGUK3xviqwMU Hn/d3ywKMi746gp353pYsDDfmOwws0JNOxDIpZro2OfeMcCDO4FChBoqXJiYsY5MhNco p/Fw== X-Forwarded-Encrypted: i=1; AJvYcCX8c94+De84jKRezKa1/zMvd8clPsrVi6Cw9CPXEp1QKKD2eRmN/DjicAXD2XTV5Vc+7hGch+C4vjzjNO4=@vger.kernel.org X-Gm-Message-State: AOJu0YzilDijLFr7+dVpwPUsGdEfTNrMwjMDa5P9iPhPsVT2uRpc7Her lqFcRgM4PNmvnDU4uJLLYU6/NjHCcb3n5lBJJ/7cR+bF2JdKnM9vxX+tVU6JpVWhw6JXrtPz6BA zQJSKo5Ax7w== X-Received: from dlbto2.prod.google.com ([2002:a05:7022:3b02:b0:121:a019:8a44]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:438a:b0:11b:9386:8271 with SMTP id a92af1059eb24-1247dc14cbbmr2482480c88.46.1769206948958; Fri, 23 Jan 2026 14:22:28 -0800 (PST) Date: Fri, 23 Jan 2026 14:22:07 -0800 In-Reply-To: <20260123222209.1181249-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260123222209.1181249-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260123222209.1181249-3-irogers@google.com> Subject: [PATCH v1 2/4] perf thread: Add optional e_flags output argument to thread__e_machine From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Guo Ren , Tianyou Li , Athira Rajeev , Stephen Brennan , Aditya Bodkhe , Chun-Tse Shao , Swapnil Sapkal , Howard Chu , Sergei Trofimovich , Shimin Guo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The e_flags are needed to accurately compute complete perf register information for CSKY. Add the ability to read and have this value associated with a thread. This change doesn't wire up the use of the e_flags except in disasm where use already exists but just wasn't set up yet. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 14 +++-- tools/perf/builtin-trace.c | 12 ++-- tools/perf/util/annotate.c | 5 +- tools/perf/util/disasm.c | 5 +- tools/perf/util/disasm.h | 2 +- tools/perf/util/dso.c | 43 +++++++++++--- tools/perf/util/dso.h | 4 +- .../scripting-engines/trace-event-python.c | 2 +- tools/perf/util/session.c | 4 +- tools/perf/util/thread.c | 59 +++++++++++++------ tools/perf/util/thread.h | 16 ++++- tools/perf/util/unwind-libdw.c | 4 +- 12 files changed, 122 insertions(+), 48 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 372bede30230..8c0de27a9713 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2504,11 +2504,17 @@ static void process_event(struct perf_script *scrip= t, symbol_conf.bt_stop_list, fp); } =20 - if (PRINT_FIELD(IREGS)) - perf_sample__fprintf_iregs(sample, attr, thread__e_machine(thread, machi= ne), fp); + if (PRINT_FIELD(IREGS)) { + perf_sample__fprintf_iregs(sample, attr, + thread__e_machine(thread, machine, /*e_flags=3D*/NULL), + fp); + } =20 - if (PRINT_FIELD(UREGS)) - perf_sample__fprintf_uregs(sample, attr, thread__e_machine(thread, machi= ne), fp); + if (PRINT_FIELD(UREGS)) { + perf_sample__fprintf_uregs(sample, attr, + thread__e_machine(thread, machine, /*e_flags=3D*/NULL), + fp); + } =20 if (PRINT_FIELD(BRSTACK)) perf_sample__fprintf_brstack(sample, thread, evsel, fp); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 8df5ca44e4f9..311d9da9896a 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2789,7 +2789,7 @@ static int trace__sys_enter(struct trace *trace, stru= ct evsel *evsel, struct thread_trace *ttrace; =20 thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); - e_machine =3D thread__e_machine(thread, trace->host); + e_machine =3D thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL); sc =3D trace__syscall_info(trace, evsel, e_machine, id); if (sc =3D=3D NULL) goto out_put; @@ -2868,7 +2868,7 @@ static int trace__fprintf_sys_enter(struct trace *tra= ce, struct evsel *evsel, =20 =20 thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); - e_machine =3D thread__e_machine(thread, trace->host); + e_machine =3D thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL); sc =3D trace__syscall_info(trace, evsel, e_machine, id); if (sc =3D=3D NULL) goto out_put; @@ -2934,7 +2934,7 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, struct thread_trace *ttrace; =20 thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); - e_machine =3D thread__e_machine(thread, trace->host); + e_machine =3D thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL); sc =3D trace__syscall_info(trace, evsel, e_machine, id); if (sc =3D=3D NULL) goto out_put; @@ -3285,7 +3285,9 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, =20 if (evsel =3D=3D trace->syscalls.events.bpf_output) { int id =3D perf_evsel__sc_tp_uint(evsel, id, sample); - int e_machine =3D thread ? thread__e_machine(thread, trace->host) : EM_H= OST; + int e_machine =3D thread + ? thread__e_machine(thread, trace->host, /*e_flags=3D*/NULL) + : EM_HOST; struct syscall *sc =3D trace__syscall_info(trace, evsel, e_machine, id); =20 if (sc) { @@ -4916,7 +4918,7 @@ static size_t trace__fprintf_thread(FILE *fp, struct = thread *thread, struct trac { size_t printed =3D 0; struct thread_trace *ttrace =3D thread__priv(thread); - int e_machine =3D thread__e_machine(thread, trace->host); + int e_machine =3D thread__e_machine(thread, trace->host, /*e_flags=3D*/NU= LL); double ratio; =20 if (ttrace =3D=3D NULL) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c16c6dfaa959..880b1bd300c2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -984,6 +984,7 @@ int thread__get_arch(struct thread *thread, const struc= t arch **parch) { const struct arch *arch; struct machine *machine; + uint32_t e_flags; uint16_t e_machine; =20 if (!thread) { @@ -992,8 +993,8 @@ int thread__get_arch(struct thread *thread, const struc= t arch **parch) } =20 machine =3D maps__machine(thread__maps(thread)); - e_machine =3D thread__e_machine(thread, machine); - arch =3D arch__find(e_machine, machine->env ? machine->env->cpuid : NULL); + e_machine =3D thread__e_machine(thread, machine, &e_flags); + arch =3D arch__find(e_machine, e_flags, machine->env ? machine->env->cpui= d : NULL); if (arch =3D=3D NULL) { pr_err("%s: unsupported arch %d\n", __func__, e_machine); return errno; diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 9b0ba1fc5aec..6b36287f30fe 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -134,7 +134,7 @@ static int arch__cmp(const void *a, const void *b) return e_machine_and_eflags__cmp(&(*aa)->id, &(*ab)->id); } =20 -const struct arch *arch__find(uint16_t e_machine, const char *cpuid) +const struct arch *arch__find(uint16_t e_machine, uint32_t e_flags, const = char *cpuid) { static const struct arch *(*const arch_new_fn[])(const struct e_machine_a= nd_e_flags *id, const char *cpuid) =3D { @@ -157,8 +157,7 @@ const struct arch *arch__find(uint16_t e_machine, const= char *cpuid) static size_t num_archs; struct e_machine_and_e_flags key =3D { .e_machine =3D e_machine, - // TODO: e_flags should really come from the same source as e_machine. - .e_flags =3D EF_HOST, + .e_flags =3D e_flags, }; const struct arch *result =3D NULL, **tmp; =20 diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 6a1905f9d4fc..a6e478caf61a 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -108,7 +108,7 @@ struct annotate_args { char *fileloc; }; =20 -const struct arch *arch__find(uint16_t e_machine, const char *cpuid); +const struct arch *arch__find(uint16_t e_machine, uint32_t e_flags, const = char *cpuid); bool arch__is_x86(const struct arch *arch); bool arch__is_powerpc(const struct arch *arch); =20 diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 91c9f7cb9d8c..b791e1b6b2cf 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1220,14 +1220,20 @@ static enum dso_swap_type dso_swap_type__from_elf_d= ata(unsigned char eidata) } =20 /* Reads e_machine from fd, optionally caching data in dso. */ -uint16_t dso__read_e_machine(struct dso *optional_dso, int fd) +uint16_t dso__read_e_machine(struct dso *optional_dso, int fd, uint32_t *e= _flags) { uint16_t e_machine =3D EM_NONE; unsigned char e_ident[EI_NIDENT]; enum dso_swap_type swap_type; + bool need_e_flags; =20 - _Static_assert(offsetof(Elf32_Ehdr, e_ident) =3D=3D 0, "Unexpected offset= "); - _Static_assert(offsetof(Elf64_Ehdr, e_ident) =3D=3D 0, "Unexpected offset= "); + if (e_flags) + *e_flags =3D 0; + + { + _Static_assert(offsetof(Elf32_Ehdr, e_ident) =3D=3D 0, "Unexpected offse= t"); + _Static_assert(offsetof(Elf64_Ehdr, e_ident) =3D=3D 0, "Unexpected offse= t"); + } if (pread(fd, &e_ident, sizeof(e_ident), 0) !=3D sizeof(e_ident)) return EM_NONE; // Read failed. =20 @@ -1254,18 +1260,35 @@ uint16_t dso__read_e_machine(struct dso *optional_d= so, int fd) { _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); - if (pread(fd, &e_machine, sizeof(e_machine), 18) !=3D sizeof(e_machine)) - return EM_NONE; // e_machine read failed. } + if (pread(fd, &e_machine, sizeof(e_machine), 18) !=3D sizeof(e_machine)) + return EM_NONE; // e_machine read failed. =20 e_machine =3D DSO_SWAP_TYPE__SWAP(swap_type, uint16_t, e_machine); if (e_machine >=3D EM_NUM) return EM_NONE; // Bad ELF machine number. =20 +#ifdef NDEBUG + /* In production code the e_flags are only needed on CSKY. */ + need_e_flags =3D e_flags && e_machine =3D=3D EM_CSKY; +#else + /* Debug code will always read the e_flags. */ + need_e_flags =3D e_flags !=3D NULL; +#endif + if (need_e_flags) { + off_t offset =3D e_ident[EI_CLASS] =3D=3D ELFCLASS32 + ? offsetof(Elf32_Ehdr, e_flags) + : offsetof(Elf64_Ehdr, e_flags); + + if (pread(fd, e_flags, sizeof(*e_flags), offset) !=3D sizeof(*e_flags)) { + *e_flags =3D 0; + return EM_NONE; // e_flags read failed. + } + } return e_machine; } =20 -uint16_t dso__e_machine(struct dso *dso, struct machine *machine) +uint16_t dso__e_machine(struct dso *dso, struct machine *machine, uint32_t= *e_flags) { uint16_t e_machine =3D EM_NONE; int fd; @@ -1285,6 +1308,8 @@ uint16_t dso__e_machine(struct dso *dso, struct machi= ne *machine) case DSO_BINARY_TYPE__BPF_IMAGE: case DSO_BINARY_TYPE__OOL: case DSO_BINARY_TYPE__JAVA_JIT: + if (e_flags) + *e_flags =3D EF_HOST; return EM_HOST; case DSO_BINARY_TYPE__DEBUGLINK: case DSO_BINARY_TYPE__BUILD_ID_CACHE: @@ -1299,6 +1324,8 @@ uint16_t dso__e_machine(struct dso *dso, struct machi= ne *machine) break; case DSO_BINARY_TYPE__NOT_FOUND: default: + if (e_flags) + *e_flags =3D 0; return EM_NONE; } =20 @@ -1311,7 +1338,9 @@ uint16_t dso__e_machine(struct dso *dso, struct machi= ne *machine) try_to_open_dso(dso, machine); fd =3D dso__data(dso)->fd; if (fd >=3D 0) - e_machine =3D dso__read_e_machine(dso, fd); + e_machine =3D dso__read_e_machine(dso, fd, e_flags); + else if (e_flags) + *e_flags =3D 0; =20 mutex_unlock(dso__data_open_lock()); return e_machine; diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index a95fee7d634b..ede691e9a249 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -866,8 +866,8 @@ int dso__data_file_size(struct dso *dso, struct machine= *machine); off_t dso__data_size(struct dso *dso, struct machine *machine); ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size); -uint16_t dso__read_e_machine(struct dso *optional_dso, int fd); -uint16_t dso__e_machine(struct dso *dso, struct machine *machine); +uint16_t dso__read_e_machine(struct dso *optional_dso, int fd, uint32_t *e= _flags); +uint16_t dso__e_machine(struct dso *dso, struct machine *machine, uint32_t= *e_flags); ssize_t dso__data_read_addr(struct dso *dso, struct map *map, struct machine *machine, u64 addr, u8 *data, ssize_t size); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index b90edc147796..50f0d16520cc 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -925,7 +925,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, =20 if (al->thread) { machine =3D maps__machine(thread__maps(al->thread)); - e_machine =3D thread__e_machine(al->thread, machine); + e_machine =3D thread__e_machine(al->thread, machine, /*e_flags=3D*/NULL); } if (set_regs_in_dict(dict, sample, evsel, e_machine)) Py_FatalError("Failed to setting regs in dict"); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c0231bc000e7..0e8a128d7c04 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1124,7 +1124,7 @@ static void dump_sample(struct machine *machine, stru= ct evsel *evsel, union perf if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_REGS_INTR)) { struct thread *thread =3D machine__find_thread(machine, sample->pid, sam= ple->pid); =20 - e_machine =3D thread__e_machine(thread, machine); + e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/NULL); } =20 printf("(IP, 0x%x): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRI= x64 "\n", @@ -2965,7 +2965,7 @@ static int perf_session__e_machine_cb(struct thread *= thread, uint16_t *result =3D arg; struct machine *machine =3D maps__machine(thread__maps(thread)); =20 - *result =3D thread__e_machine(thread, machine); + *result =3D thread__e_machine(thread, machine, /*e_flags=3D*/NULL); return *result !=3D EM_NONE ? 1 : 0; } =20 diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 3642858e6cbc..618f29afb160 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -449,7 +449,7 @@ void thread__find_cpumode_addr_location(struct thread *= thread, u64 addr, } } =20 -static uint16_t read_proc_e_machine_for_pid(pid_t pid) +static uint16_t read_proc_e_machine_for_pid(pid_t pid, uint32_t *e_flags) { char path[6 /* "/proc/" */ + 11 /* max length of pid */ + 5 /* "/exe\0" *= /]; int fd; @@ -458,30 +458,46 @@ static uint16_t read_proc_e_machine_for_pid(pid_t pid) snprintf(path, sizeof(path), "/proc/%d/exe", pid); fd =3D open(path, O_RDONLY); if (fd >=3D 0) { - e_machine =3D dso__read_e_machine(/*optional_dso=3D*/NULL, fd); + e_machine =3D dso__read_e_machine(/*optional_dso=3D*/NULL, fd, e_flags); close(fd); } return e_machine; } =20 -static int thread__e_machine_callback(struct map *map, void *machine) +struct thread__e_machine_callback_args { + struct machine *machine; + uint32_t e_flags; + uint16_t e_machine; +}; + +static int thread__e_machine_callback(struct map *map, void *_args) { + struct thread__e_machine_callback_args *args =3D _args; struct dso *dso =3D map__dso(map); =20 - _Static_assert(0 =3D=3D EM_NONE, "Unexpected EM_NONE"); if (!dso) - return EM_NONE; + return 0; // No dso, continue search. =20 - return dso__e_machine(dso, machine); + args->e_machine =3D dso__e_machine(dso, args->machine, &args->e_flags); + return args->e_machine !=3D EM_NONE ? 1 /* stop search */ : 0 /* continue= search */; } =20 -uint16_t thread__e_machine(struct thread *thread, struct machine *machine) +uint16_t thread__e_machine(struct thread *thread, struct machine *machine,= uint32_t *e_flags) { pid_t tid, pid; uint16_t e_machine =3D RC_CHK_ACCESS(thread)->e_machine; + uint32_t local_e_flags =3D 0; + struct thread__e_machine_callback_args args =3D { + .machine =3D machine, + .e_flags =3D 0, + .e_machine =3D EM_NONE, + }; =20 - if (e_machine !=3D EM_NONE) + if (e_machine !=3D EM_NONE) { + if (e_flags) + *e_flags =3D thread__e_flags(thread); return e_machine; + } =20 tid =3D thread__tid(thread); pid =3D thread__pid(thread); @@ -489,18 +505,19 @@ uint16_t thread__e_machine(struct thread *thread, str= uct machine *machine) struct thread *parent =3D machine__findnew_thread(machine, pid, pid); =20 if (parent) { - e_machine =3D thread__e_machine(parent, machine); + e_machine =3D thread__e_machine(parent, machine, &local_e_flags); thread__put(parent); - thread__set_e_machine(thread, e_machine); - return e_machine; + goto out; } /* Something went wrong, fallback. */ } /* Reading on the PID thread. First try to find from the maps. */ - e_machine =3D maps__for_each_map(thread__maps(thread), - thread__e_machine_callback, - machine); - if (e_machine =3D=3D EM_NONE) { + maps__for_each_map(thread__maps(thread), thread__e_machine_callback, &arg= s); + + if (args.e_machine !=3D EM_NONE) { + e_machine =3D args.e_machine; + local_e_flags =3D args.e_flags; + } else { /* Maps failed, perhaps we're live with map events disabled. */ bool is_live =3D machine->machines =3D=3D NULL; =20 @@ -514,12 +531,18 @@ uint16_t thread__e_machine(struct thread *thread, str= uct machine *machine) } /* Read from /proc/pid/exe if live. */ if (is_live) - e_machine =3D read_proc_e_machine_for_pid(pid); + e_machine =3D read_proc_e_machine_for_pid(pid, &local_e_flags); } - if (e_machine !=3D EM_NONE) +out: + if (e_machine !=3D EM_NONE) { thread__set_e_machine(thread, e_machine); - else + thread__set_e_flags(thread, local_e_flags); + } else { e_machine =3D EM_HOST; + local_e_flags =3D EF_HOST; + } + if (e_flags) + *e_flags =3D local_e_flags; return e_machine; } =20 diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 310eaea344bb..f5792d3e8a16 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -60,6 +60,10 @@ DECLARE_RC_STRUCT(thread) { struct srccode_state srccode_state; bool filter; int filter_entry_depth; + /** + * @e_flags: The ELF EF_* associated with the thread. Valid if e_machine = !=3D EM_NONE. + */ + uint16_t e_flags; /** * @e_machine: The ELF EM_* associated with the thread. EM_NONE if not * computed. @@ -307,13 +311,23 @@ static inline void thread__set_filter_entry_depth(str= uct thread *thread, int dep RC_CHK_ACCESS(thread)->filter_entry_depth =3D depth; } =20 -uint16_t thread__e_machine(struct thread *thread, struct machine *machine); +uint16_t thread__e_machine(struct thread *thread, struct machine *machine,= uint32_t *e_flags); =20 static inline void thread__set_e_machine(struct thread *thread, uint16_t e= _machine) { RC_CHK_ACCESS(thread)->e_machine =3D e_machine; } =20 +static inline uint32_t thread__e_flags(const struct thread *thread) +{ + return RC_CHK_ACCESS(thread)->e_flags; +} + +static inline void thread__set_e_flags(struct thread *thread, uint32_t e_f= lags) +{ + RC_CHK_ACCESS(thread)->e_flags =3D e_flags; +} + =20 static inline bool thread__lbr_stitch_enable(const struct thread *thread) { diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 9cb0960ef905..3fdcfa06bf22 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -213,7 +213,7 @@ static bool memory_read(Dwfl *dwfl __maybe_unused, Dwar= f_Addr addr, Dwarf_Word * { struct dwfl_ui_thread_info *dwfl_ui_ti =3D arg; struct unwind_info *ui =3D dwfl_ui_ti->ui; - uint16_t e_machine =3D thread__e_machine(ui->thread, ui->machine); + uint16_t e_machine =3D thread__e_machine(ui->thread, ui->machine, /*e_fla= gs=3D*/NULL); struct stack_dump *stack =3D &ui->sample->user_stack; u64 start, end; int offset; @@ -348,7 +348,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, { struct maps *maps =3D thread__maps(thread); struct machine *machine =3D maps__machine(maps); - uint16_t e_machine =3D thread__e_machine(thread, machine); + uint16_t e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/N= ULL); struct dwfl_ui_thread_info *dwfl_ui_ti; static struct unwind_info *ui; Dwfl *dwfl; --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 06:13:47 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D46C826B971 for ; Fri, 23 Jan 2026 22:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206953; cv=none; b=T1TrTpq6+prU6wYCWwJ5Ltn/3wzxp6N9O5jcRjeQTcDYxsHmaBV+q0s2SWOQttwj/fY7eO8J/j1+o0XjnJ4BywuM7XbEfFrCrmjAivH871ZDmoUJ+1VPD9b9AOwRzLO+EervUvb7YBeGnSH1l0faalnetJyo9Efp3K4iwDKDTI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206953; c=relaxed/simple; bh=X+j6IMHaSqoAmjhFlIdC9P156kMZjNmv94D2iyUpGOA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=leiwo+Irx6zqD/ho96csmU3a0c+xEsh6JfhUc3pPGY8fKp8B6NuKS0y76ZTghcWze0BtA4QJkeDXjBkBQdvIlttWejNa2849DXhWivRhKgW8dGJKxb41HFfxj02SDeQEAkB5VLjMZgdvY06oN+/AJD9oCLFT+zxr+0pK+rJL/kI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mc5qzRas; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mc5qzRas" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b713fa927dso1630144eec.0 for ; Fri, 23 Jan 2026 14:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769206951; x=1769811751; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=nNKLtKIqPJ9pdKccuJ/RLnEYZDsb6fUVRBWn7Y4Nmvo=; b=mc5qzRasM8DWVCf5P0LM/LCdM5ThEZNfEIQATmCYAmIy47Mr/hsb8bytu/UUSt6Ty5 n0Z2FgAPczXEr5fGzN3FUkhinlU6qYLQbrIi83dWthhJ/MBnLU99il3Cbl123lx85t/u v+hdrB8P0DwDIh3I0B9Y5CQUxfT+fjJW9kO1E/VugD2dJOCVaFFp9o080FS9RQLkZWOa 5+XhdHqbbrhVGHPODdQ4qfV69zJ02S5/12vPdtUfBV+2MNxzvqyQ1uS20hH6QZ+ZBL6N ukzQfeBOESTjNDrQE1QUJjjujdipEzp8aInFfdY5q3OUANBfiAZ8KrFaDvKY8ejVi5Ds 6/lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769206951; x=1769811751; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nNKLtKIqPJ9pdKccuJ/RLnEYZDsb6fUVRBWn7Y4Nmvo=; b=RgQqD6o7f5HOG+RhpTJrzdiAji3oIBU/B3weMS+XCHtdfj2Ra82Dg5wv3bO+JyeOvz z/7DPbhDqr1eTRAp1v7aiZoNi2+vtdP15+Xqcd5XCM+ufXDNsJGUSsQVLvSjaoB+wp6x dv63HA7bfxblh5gKMtIIyNuoJeyIey9oGwbyDPeT++A0gyvGzrIlCRQD+FEg0o+4/iP/ vMxmIrXb0xI8dkf5lEVs7Hp+94fUP0mKQjtKXIvcGPdx0U3ViH5hZpAbpTzR1wWTES+h VR0ZW8jf0+t/AxfevJ2Nf9dHpx+jKFXxj3t9C1WyLR7/iM3Xe5jenGTEqC2bBNU4LQF+ YHTw== X-Forwarded-Encrypted: i=1; AJvYcCVOpDIzgHp4tOuPxl6E3t5DYjFp03S4k0KvaQsnKqiO5UCw3tn2UhfIEFGal5jCutgfIPG3r3aR/lPO4jM=@vger.kernel.org X-Gm-Message-State: AOJu0Yypwl253a1Z9vEN7IU4EFZEm3oT+XzoJcjZbO6yb7SziURbRTMI Ik1LgHqTtXtCkuwDKuLkFdoihpLe4nYqJXeLlImujFkwNP7bPM3P44oeLwKNjHvMVgbmzFVo+9u isMCgPyC8/w== X-Received: from dyon5.prod.google.com ([2002:a05:7300:6d05:b0:2a4:733c:4a27]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4195:b0:2b6:bb18:c70a with SMTP id 5a478bee46e88-2b724819b28mr3711949eec.15.1769206950958; Fri, 23 Jan 2026 14:22:30 -0800 (PST) Date: Fri, 23 Jan 2026 14:22:08 -0800 In-Reply-To: <20260123222209.1181249-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260123222209.1181249-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260123222209.1181249-4-irogers@google.com> Subject: [PATCH v1 3/4] perf perf_regs: Accurately compute register names for CSKY From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Guo Ren , Tianyou Li , Athira Rajeev , Stephen Brennan , Aditya Bodkhe , Chun-Tse Shao , Swapnil Sapkal , Howard Chu , Sergei Trofimovich , Shimin Guo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CSKY needs the e_flags to determine the ABI level and know whether additional registers are encoded or not. Wire this up now that the e_flags for a thread can be determined. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 28 +++++++++++++------ tools/perf/util/parse-regs-options.c | 4 +-- .../perf/util/perf-regs-arch/perf_regs_csky.c | 13 +++++---- tools/perf/util/perf_regs.c | 4 +-- tools/perf/util/perf_regs.h | 4 +-- .../scripting-engines/trace-event-python.c | 17 ++++++----- tools/perf/util/session.c | 24 ++++++++-------- 7 files changed, 56 insertions(+), 38 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8c0de27a9713..6ec225c697a4 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -717,7 +717,8 @@ static int perf_session__check_output_opt(struct perf_s= ession *session) return 0; } =20 -static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask= , uint16_t e_machine, +static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask, + uint16_t e_machine, uint32_t e_flags, FILE *fp) { unsigned i =3D 0, r; @@ -730,7 +731,9 @@ static int perf_sample__fprintf_regs(struct regs_dump *= regs, uint64_t mask, uint =20 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { u64 val =3D regs->regs[i++]; - printed +=3D fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r, e_machine)= , val); + printed +=3D fprintf(fp, "%5s:0x%"PRIx64" ", + perf_reg_name(r, e_machine, e_flags), + val); } =20 return printed; @@ -787,23 +790,29 @@ tod_scnprintf(struct perf_script *script, char *buf, = int buflen, } =20 static int perf_sample__fprintf_iregs(struct perf_sample *sample, - struct perf_event_attr *attr, uint16_t e_machine, FILE *fp) + struct perf_event_attr *attr, + uint16_t e_machine, + uint32_t e_flags, + FILE *fp) { if (!sample->intr_regs) return 0; =20 return perf_sample__fprintf_regs(perf_sample__intr_regs(sample), - attr->sample_regs_intr, e_machine, fp); + attr->sample_regs_intr, e_machine, e_flags, fp); } =20 static int perf_sample__fprintf_uregs(struct perf_sample *sample, - struct perf_event_attr *attr, uint16_t e_machine, FILE *fp) + struct perf_event_attr *attr, + uint16_t e_machine, + uint32_t e_flags, + FILE *fp) { if (!sample->user_regs) return 0; =20 return perf_sample__fprintf_regs(perf_sample__user_regs(sample), - attr->sample_regs_user, e_machine, fp); + attr->sample_regs_user, e_machine, e_flags, fp); } =20 static int perf_sample__fprintf_start(struct perf_script *script, @@ -2418,6 +2427,7 @@ static void process_event(struct perf_script *script, struct evsel_script *es =3D evsel->priv; FILE *fp =3D es->fp; char str[PAGE_SIZE_NAME_LEN]; + uint32_t e_flags; =20 if (output[type].fields =3D=3D 0) return; @@ -2506,13 +2516,15 @@ static void process_event(struct perf_script *scrip= t, =20 if (PRINT_FIELD(IREGS)) { perf_sample__fprintf_iregs(sample, attr, - thread__e_machine(thread, machine, /*e_flags=3D*/NULL), + thread__e_machine(thread, machine, &e_flags), + e_flags, fp); } =20 if (PRINT_FIELD(UREGS)) { perf_sample__fprintf_uregs(sample, attr, - thread__e_machine(thread, machine, /*e_flags=3D*/NULL), + thread__e_machine(thread, machine, &e_flags), + e_flags, fp); } =20 diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-r= egs-options.c index c0d0ef9fd495..8dd35f50f644 100644 --- a/tools/perf/util/parse-regs-options.c +++ b/tools/perf/util/parse-regs-options.c @@ -21,7 +21,7 @@ static void list_perf_regs(FILE *fp, uint64_t mask) if (((1ULL << reg) & mask) =3D=3D 0) continue; =20 - name =3D perf_reg_name(reg, EM_HOST); + name =3D perf_reg_name(reg, EM_HOST, EF_HOST); if (name && (!last_name || strcmp(last_name, name))) fprintf(fp, "%s%s", reg > 0 ? " " : "", name); last_name =3D name; @@ -39,7 +39,7 @@ static uint64_t name_to_perf_reg_mask(const char *to_matc= h, uint64_t mask) if (((1ULL << reg) & mask) =3D=3D 0) continue; =20 - name =3D perf_reg_name(reg, EM_HOST); + name =3D perf_reg_name(reg, EM_HOST, EF_HOST); if (!name) continue; =20 diff --git a/tools/perf/util/perf-regs-arch/perf_regs_csky.c b/tools/perf/u= til/perf-regs-arch/perf_regs_csky.c index 75b461ef2eba..d685b3fe418f 100644 --- a/tools/perf/util/perf-regs-arch/perf_regs_csky.c +++ b/tools/perf/util/perf-regs-arch/perf_regs_csky.c @@ -1,10 +1,15 @@ // SPDX-License-Identifier: GPL-2.0 - +#include #include "../perf_regs.h" +#undef __CSKYABIV2__ +#define __CSKYABIV2__ 1 // Always want the V2 register definitions. #include "../../arch/csky/include/uapi/asm/perf_regs.h" =20 -const char *__perf_reg_name_csky(int id) +const char *__perf_reg_name_csky(int id, uint32_t e_flags) { + if (id >=3D PERF_REG_CSKY_EXREGS0 && (e_flags & EF_CSKY_ABIMASK) =3D=3D E= F_CSKY_ABIV2) + return NULL; + switch (id) { case PERF_REG_CSKY_A0: return "a0"; @@ -40,7 +45,6 @@ const char *__perf_reg_name_csky(int id) return "lr"; case PERF_REG_CSKY_PC: return "pc"; -#if defined(__CSKYABIV2__) case PERF_REG_CSKY_EXREGS0: return "exregs0"; case PERF_REG_CSKY_EXREGS1: @@ -77,12 +81,9 @@ const char *__perf_reg_name_csky(int id) return "hi"; case PERF_REG_CSKY_LO: return "lo"; -#endif default: return NULL; } - - return NULL; } =20 uint64_t __perf_reg_ip_csky(void) diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c index cd5acee3dc62..14b7be30ab20 100644 --- a/tools/perf/util/perf_regs.c +++ b/tools/perf/util/perf_regs.c @@ -23,7 +23,7 @@ uint64_t __weak arch__user_reg_mask(void) return 0; } =20 -const char *perf_reg_name(int id, uint16_t e_machine) +const char *perf_reg_name(int id, uint16_t e_machine, uint32_t e_flags) { const char *reg_name =3D NULL; =20 @@ -35,7 +35,7 @@ const char *perf_reg_name(int id, uint16_t e_machine) reg_name =3D __perf_reg_name_arm64(id); break; case EM_CSKY: - reg_name =3D __perf_reg_name_csky(id); + reg_name =3D __perf_reg_name_csky(id, e_flags); break; case EM_LOONGARCH: reg_name =3D __perf_reg_name_loongarch(id); diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h index 2c2a8de6912d..ed7c1b1358fa 100644 --- a/tools/perf/util/perf_regs.h +++ b/tools/perf/util/perf_regs.h @@ -16,7 +16,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op); uint64_t arch__intr_reg_mask(void); uint64_t arch__user_reg_mask(void); =20 -const char *perf_reg_name(int id, uint16_t e_machine); +const char *perf_reg_name(int id, uint16_t e_machine, uint32_t e_flags); int perf_reg_value(u64 *valp, struct regs_dump *regs, int id); uint64_t perf_arch_reg_ip(uint16_t e_machine); uint64_t perf_arch_reg_sp(uint16_t e_machine); @@ -26,7 +26,7 @@ uint64_t __perf_reg_sp_arm64(void); const char *__perf_reg_name_arm(int id); uint64_t __perf_reg_ip_arm(void); uint64_t __perf_reg_sp_arm(void); -const char *__perf_reg_name_csky(int id); +const char *__perf_reg_name_csky(int id, uint32_t e_flags); uint64_t __perf_reg_ip_csky(void); uint64_t __perf_reg_sp_csky(void); const char *__perf_reg_name_loongarch(int id); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 50f0d16520cc..62c9c73daef5 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -714,7 +714,8 @@ static void set_sample_datasrc_in_dict(PyObject *dict, _PyUnicode_FromString(decode)); } =20 -static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_mac= hine, char *bf, int size) +static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_mac= hine, uint32_t e_flags, + char *bf, int size) { unsigned int i =3D 0, r; int printed =3D 0; @@ -732,7 +733,7 @@ static void regs_map(struct regs_dump *regs, uint64_t m= ask, uint16_t e_machine, =20 printed +=3D scnprintf(bf + printed, size - printed, "%5s:0x%" PRIx64 " ", - perf_reg_name(r, e_machine), val); + perf_reg_name(r, e_machine, e_flags), val); } } =20 @@ -741,7 +742,8 @@ static void regs_map(struct regs_dump *regs, uint64_t m= ask, uint16_t e_machine, static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, struct evsel *evsel, - uint16_t e_machine) + uint16_t e_machine, + uint32_t e_flags) { struct perf_event_attr *attr =3D &evsel->core.attr; =20 @@ -753,7 +755,7 @@ static int set_regs_in_dict(PyObject *dict, if (!bf) return -1; =20 - regs_map(sample->intr_regs, attr->sample_regs_intr, e_machine, bf, size); + regs_map(sample->intr_regs, attr->sample_regs_intr, e_machine, e_flags, = bf, size); =20 pydict_set_item_string_decref(dict, "iregs", _PyUnicode_FromString(bf)); @@ -765,7 +767,7 @@ static int set_regs_in_dict(PyObject *dict, if (!bf) return -1; } - regs_map(sample->user_regs, attr->sample_regs_user, e_machine, bf, size); + regs_map(sample->user_regs, attr->sample_regs_user, e_machine, e_flags, = bf, size); =20 pydict_set_item_string_decref(dict, "uregs", _PyUnicode_FromString(bf)); @@ -837,6 +839,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; struct machine *machine; uint16_t e_machine =3D EM_HOST; + uint32_t e_flags =3D EF_HOST; =20 dict =3D PyDict_New(); if (!dict) @@ -925,9 +928,9 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, =20 if (al->thread) { machine =3D maps__machine(thread__maps(al->thread)); - e_machine =3D thread__e_machine(al->thread, machine, /*e_flags=3D*/NULL); + e_machine =3D thread__e_machine(al->thread, machine, &e_flags); } - if (set_regs_in_dict(dict, sample, evsel, e_machine)) + if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); =20 return dict; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 0e8a128d7c04..7c7c65b0f536 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -959,7 +959,7 @@ static void branch_stack__printf(struct perf_sample *sa= mple, } } =20 -static void regs_dump__printf(u64 mask, u64 *regs, uint16_t e_machine) +static void regs_dump__printf(u64 mask, u64 *regs, uint16_t e_machine, uin= t32_t e_flags) { unsigned rid, i =3D 0; =20 @@ -967,7 +967,7 @@ static void regs_dump__printf(u64 mask, u64 *regs, uint= 16_t e_machine) u64 val =3D regs[i++]; =20 printf(".... %-5s 0x%016" PRIx64 "\n", - perf_reg_name(rid, e_machine), val); + perf_reg_name(rid, e_machine, e_flags), val); } } =20 @@ -985,7 +985,8 @@ static inline const char *regs_dump_abi(struct regs_dum= p *d) return regs_abi[d->abi]; } =20 -static void regs__printf(const char *type, struct regs_dump *regs, uint16_= t e_machine) +static void regs__printf(const char *type, struct regs_dump *regs, + uint16_t e_machine, uint32_t e_flags) { u64 mask =3D regs->mask; =20 @@ -994,10 +995,10 @@ static void regs__printf(const char *type, struct reg= s_dump *regs, uint16_t e_ma mask, regs_dump_abi(regs)); =20 - regs_dump__printf(mask, regs->regs, e_machine); + regs_dump__printf(mask, regs->regs, e_machine, e_flags); } =20 -static void regs_user__printf(struct perf_sample *sample, uint16_t e_machi= ne) +static void regs_user__printf(struct perf_sample *sample, uint16_t e_machi= ne, uint32_t e_flags) { struct regs_dump *user_regs; =20 @@ -1007,10 +1008,10 @@ static void regs_user__printf(struct perf_sample *s= ample, uint16_t e_machine) user_regs =3D perf_sample__user_regs(sample); =20 if (user_regs->regs) - regs__printf("user", user_regs, e_machine); + regs__printf("user", user_regs, e_machine, e_flags); } =20 -static void regs_intr__printf(struct perf_sample *sample, uint16_t e_machi= ne) +static void regs_intr__printf(struct perf_sample *sample, uint16_t e_machi= ne, uint32_t e_flags) { struct regs_dump *intr_regs; =20 @@ -1020,7 +1021,7 @@ static void regs_intr__printf(struct perf_sample *sam= ple, uint16_t e_machine) intr_regs =3D perf_sample__intr_regs(sample); =20 if (intr_regs->regs) - regs__printf("intr", intr_regs, e_machine); + regs__printf("intr", intr_regs, e_machine, e_flags); } =20 static void stack_user__printf(struct stack_dump *dump) @@ -1115,6 +1116,7 @@ static void dump_sample(struct machine *machine, stru= ct evsel *evsel, union perf u64 sample_type; char str[PAGE_SIZE_NAME_LEN]; uint16_t e_machine =3D EM_NONE; + uint32_t e_flags =3D 0; =20 if (!dump_trace) return; @@ -1124,7 +1126,7 @@ static void dump_sample(struct machine *machine, stru= ct evsel *evsel, union perf if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_REGS_INTR)) { struct thread *thread =3D machine__find_thread(machine, sample->pid, sam= ple->pid); =20 - e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/NULL); + e_machine =3D thread__e_machine(thread, machine, &e_flags); } =20 printf("(IP, 0x%x): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRI= x64 "\n", @@ -1138,10 +1140,10 @@ static void dump_sample(struct machine *machine, st= ruct evsel *evsel, union perf branch_stack__printf(sample, evsel); =20 if (sample_type & PERF_SAMPLE_REGS_USER) - regs_user__printf(sample, e_machine); + regs_user__printf(sample, e_machine, e_flags); =20 if (sample_type & PERF_SAMPLE_REGS_INTR) - regs_intr__printf(sample, e_machine); + regs_intr__printf(sample, e_machine, e_flags); =20 if (sample_type & PERF_SAMPLE_STACK_USER) stack_user__printf(&sample->user_stack); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 06:13:47 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73D3C2D0622 for ; Fri, 23 Jan 2026 22:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206954; cv=none; b=uwATpVwqQ4fznqNN3sBJzndH/CYRax/ty+9Hm58ynjXA1DnG6PUaCwU89UBzG1D0ZI3skmD5yY20cSerNTJizfZEqVhNdYDR0k0843WKYMSJEaMe14YbQna8ODpjB/nQbh6FkEVhLelzQ3LbTQbK1veIaiS1mC/LUJGIGQTwYmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769206954; c=relaxed/simple; bh=kC9AZtpAHUdBYY6O6Nxkfi+ezy8yHcBLFEIPAVk6JdQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=e0tquUqzbwp/WEkZ6vrxbZh91IeJf0goY7XoWhI/Vzwaa01XdkzoSmUE9rnaq82rqqvE8AXm0KUFMBfHHDbdvO6o1xNb1KTYZOBtJ9Dlh0M5OgmPJlaHlxmjcPHoFlKvl9ygbxEjiGLQFPj8mnGC1dRONcCebyaPTXR+7xg+Ufk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QjRB6D3B; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QjRB6D3B" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b713fa927dso1630166eec.0 for ; Fri, 23 Jan 2026 14:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769206953; x=1769811753; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=M71H9eDQwgF4ql2WlmE8laY3Y552yAYpetkw1WK6z+k=; b=QjRB6D3B1yyIHL6WKTP04dcfdQQVfMZDVevlH55HFOqk6PzzIAQWVJNgjjcHcUAY3k 7dYaGrvNTUBto1zon0GcrWDYvuPc4naloDtxOesX0GOePUtVwiabh3d/UXqGzLo4V6oQ qJVd/+/8LNT6WhWI0wVxkUCrPrLaRPhBx9qe/KdUIZah8Yu2NPxeUSI5FloLJwKfz1MG AvuGLOuVpZ917g854P/F7Nl6n/GlDajJn21JfSL6L2DuP9ZAoq/SkGXPiLu3wRJU/XZZ FdIcuxZ9FxjkU2/RFdUQ+eeoGKSrokhsJyShKt36OzZjXgaxk8d63dw7TJA+lXIVlhaj aBaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769206953; x=1769811753; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M71H9eDQwgF4ql2WlmE8laY3Y552yAYpetkw1WK6z+k=; b=pLJVE/bbubDdZvGDrXSAC2ttshkW4QAGtIIWitQo0ET/wtOuX+KlP5VJEEgXOjuc2c QJUuqnM0Ccma8Z1NQrHBLREfAxbnS6c/NSLipUt0olMeFHDNMGLZzpIccuotoOEpnVRN 7surL429BP+PTpKTWuiXfHd4OoVTAmQPO/9phazZfD6Cztr0ysnTUnokmyBcP6ZyMvTD gZammEWNgIUeczoJDyCzRuFDWDyo6SQbxmaxA9b5MC4twQGXqs2e+Uq27GA8js/ZXpCY FTroKUdySrp+4EMI0CF+/imfB7mvaVXXrXUjOJPc2pTUqBxa3Ek7PO+tE86DVSFLgOcO kAfQ== X-Forwarded-Encrypted: i=1; AJvYcCWqgb7rgNStN0xAsCo9P3LKsVWW+s6F/dU8uJEm516JWrBnz1UEzYZymIOc0jJXqKASBn29kasgsKRrSNI=@vger.kernel.org X-Gm-Message-State: AOJu0YyvnYvFM3Ow688hTPwHcENzr4lrCznQxKRv2tQ1sk6AnNXecsDS Q9+1PxQPdu5qK+zEH/9JpCkgalWVxw5vb0wJyEKNVdh+VIvGjSUrim2EAditDC425CoMm2sqTsV Z8jBh6ZwGcQ== X-Received: from dyjm31.prod.google.com ([2002:a05:7300:169f:b0:2b6:fdc8:cdf6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:8622:b0:2b0:6a03:f08c with SMTP id 5a478bee46e88-2b72471588cmr4230043eec.5.1769206952582; Fri, 23 Jan 2026 14:22:32 -0800 (PST) Date: Fri, 23 Jan 2026 14:22:09 -0800 In-Reply-To: <20260123222209.1181249-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260123222209.1181249-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260123222209.1181249-5-irogers@google.com> Subject: [PATCH v1 4/4] perf unwind-libdw: Wire up e_flags for CSKY From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Guo Ren , Tianyou Li , Athira Rajeev , Stephen Brennan , Aditya Bodkhe , Chun-Tse Shao , Swapnil Sapkal , Howard Chu , Sergei Trofimovich , Shimin Guo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Wire up the e_flags now it can be read for a thread. The e_flags encode the CSKY ABI level and this can impact which perf registers need setting up for unwinding. Signed-off-by: Ian Rogers --- tools/perf/util/unwind-libdw.c | 9 +++++---- tools/perf/util/unwind-libdw.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 3fdcfa06bf22..05e8e68bd49c 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -213,7 +213,6 @@ static bool memory_read(Dwfl *dwfl __maybe_unused, Dwar= f_Addr addr, Dwarf_Word * { struct dwfl_ui_thread_info *dwfl_ui_ti =3D arg; struct unwind_info *ui =3D dwfl_ui_ti->ui; - uint16_t e_machine =3D thread__e_machine(ui->thread, ui->machine, /*e_fla= gs=3D*/NULL); struct stack_dump *stack =3D &ui->sample->user_stack; u64 start, end; int offset; @@ -223,7 +222,7 @@ static bool memory_read(Dwfl *dwfl __maybe_unused, Dwar= f_Addr addr, Dwarf_Word * return false; =20 ret =3D perf_reg_value(&start, ui->sample->user_regs, - perf_arch_reg_sp(e_machine)); + perf_arch_reg_sp(ui->e_machine)); if (ret) return false; =20 @@ -260,7 +259,7 @@ static bool libdw_set_initial_registers(Dwfl_Thread *th= read, void *arg) int max_dwarf_reg =3D 0; bool ret; uint16_t e_machine =3D ui->e_machine; - int e_flags =3D 0; + int e_flags =3D ui->e_flags; uint64_t ip_perf_reg =3D perf_arch_reg_ip(e_machine); Dwarf_Word val =3D 0; =20 @@ -348,7 +347,8 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, { struct maps *maps =3D thread__maps(thread); struct machine *machine =3D maps__machine(maps); - uint16_t e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/N= ULL); + uint32_t e_flags =3D 0; + uint16_t e_machine =3D thread__e_machine(thread, machine, &e_flags); struct dwfl_ui_thread_info *dwfl_ui_ti; static struct unwind_info *ui; Dwfl *dwfl; @@ -370,6 +370,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, .arg =3D arg, .max_stack =3D max_stack, .e_machine =3D e_machine, + .e_flags =3D e_flags, .best_effort =3D best_effort }; =20 diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h index 3dec0ab8bd50..6423bf5a2492 100644 --- a/tools/perf/util/unwind-libdw.h +++ b/tools/perf/util/unwind-libdw.h @@ -20,6 +20,7 @@ struct unwind_info { void *arg; int max_stack; int idx; + uint32_t e_flags; uint16_t e_machine; bool best_effort; struct unwind_entry entries[]; --=20 2.52.0.457.g6b5491de43-goog