From nobody Mon Oct 6 06:46:44 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 CD6262ED847 for ; Thu, 24 Jul 2025 16:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374824; cv=none; b=XfZZppyAZ7TwTTkO5qN4+g1crDR0af8bY1auSX8sve6/RM2GI6sav6kDKwHW5aQ8VeRDIUbjBTYYzukdFDN51yQ8wuZ2LELIaJAuOHAdEYkJUaNSjxcenJnVdPb11AZc8bQw/QW6ejkS4b8eSB644pilHxWI41NJx9htfgHhHLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374824; c=relaxed/simple; bh=yGSh4X7XdoDwP/XNm5tByh8EInjitmt1+/yS78PRG70=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Kuv+YVasOnNjhcHPZa6WJWRM8siq6ttYwFyMig2KF45h2U48rQkpB+fBgH2eM8qJwO6adb8GfhdCMkejEXTrGu1oK1ryHDN5k860DDOUgOWCI8iDz7vZjrxdu3qrz6z44YShPeNwuSgZo9WGXsY0osdDlFeTVMDHRlc/bJi5ixU= 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=F+zXjG31; arc=none smtp.client-ip=209.85.215.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="F+zXjG31" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2fa1a84566so1044144a12.1 for ; Thu, 24 Jul 2025 09:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753374822; x=1753979622; 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=vPNCzyxfy4XXIcb2fDEErvAFWE2sdBLPvOrMGYrTagM=; b=F+zXjG31yUpQKiXTjZkv+DarH17nI7r6/u8kmLf/aChqGphth266qt85+dUTSEmFXz 5jPTIom/IZar9uYQJ7k+Okn0J60E8XpDguvxIxY+J+dzEg9foQcNk0zGNzZT0Jtipy6e QlNwcG0gO/ZYdDHYNQEooqb675WeYEb8706Scr0O8XUjJSMK3bpDkXSO02iqko7sstHP u8suCHOWSGlD2A3zngw2hZlWo6pVUmSvolpUNUv4I48z5Q9JmKWcRNlPKy0oh2veDLwR ycYIl+bA2rZGvHq/3Z8nWDdQkw5IyFlpTusN+5ffoxCaGBWlv44sDjv/Sq4fzcInNgCR TOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753374822; x=1753979622; 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=vPNCzyxfy4XXIcb2fDEErvAFWE2sdBLPvOrMGYrTagM=; b=LKYpbPw47Yu4YzKVNNlKCm7VzZtx5WkeyvdPfgEKBeFxlUqNftj4pdGhewWKXIPsKz VIEAP3eiyfyP1sLgdB4hPkLMDLF/KseqYq+Gy4HOzJ8bMI97eXeXAjOwWnRbDhIt3vOB MhD9uhYXE73Cbz5RgZp1OjAmD7lwByx+ZQO7GCqAtFL2Zd5CRGKeiur7D7yBiE2i4cs5 Ivssm7bajijzuWu4sihOYYbuJ+ujtP4FvrEhJCHK0ZCpwUG6Cgb9ThqYiaeLdMKMzn3+ sxHlEOGtnf1kNzgKyIj3rAmCzbgT1h2eOSxTRYBHjjA5+S4XLgKktVVSOZXTWMxAe9FE EVcQ== X-Forwarded-Encrypted: i=1; AJvYcCWInC/Px5qEtHP4FGl+ss11wmnfU0yHnqsXf5rijwsHpcaRhdYYeRzdNSp27Pg2ab8bN9eg4SHahG6bPpM=@vger.kernel.org X-Gm-Message-State: AOJu0YxASDtCeNSNVDEuPbV3JJWwAdKqvCzWk43XYO7NOPWJYO0VgJq7 c4uk5gTxHUXdYL/i4ug7JCBdFr3V1/KJ7qu0dmeWyqOuE8YP2WF7V50ae0UHbYirdtlOzDbe1zM ni+UIE7rbng== X-Google-Smtp-Source: AGHT+IFWT6BOL+6aTxUcrq+uPDzVJYv31JbUGlhLrN873B2nul9RqKGgG9i36nst6mAyrhy7TnmoJaqt5YdK X-Received: from pjyr5.prod.google.com ([2002:a17:90a:e185:b0:31c:2fe4:33be]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:46ce:b0:234:c5c1:9b7a with SMTP id d9443c01a7336-23f9816414dmr86102115ad.8.1753374822125; Thu, 24 Jul 2025 09:33:42 -0700 (PDT) Date: Thu, 24 Jul 2025 09:32:51 -0700 In-Reply-To: <20250724163302.596743-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: <20250724163302.596743-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250724163302.596743-12-irogers@google.com> Subject: [PATCH v6 11/22] perf header: Clean up use of perf_env From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , "Masami Hiramatsu (Google)" , Ravi Bangoria , Charlie Jenkins , Colin Ian King , Andi Kleen , Dmitry Vyukov , Graham Woodward , Ilkka Koskinen , Zhongqiu Han , Yicong Yang , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , Stephen Brennan , Chun-Tse Shao , Yujie Liu , "Dr. David Alan Gilbert" , Levi Yun , Howard Chu , Weilin Wang , Thomas Falcon , Matt Fleming , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Zixian Cai , Steve Clevenger , Ben Gainey , Chaitanya S Prakash , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Always use the perf_env from the feat_fd's perf_header. Cache the value on entry to a function in `env` and use `env->` consistently in the code. Ensure the header is initialized for use in perf_session__do_write_header. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 174 ++++++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 76 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index dcef7f815fa1..b493399f9fc6 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -557,6 +557,7 @@ static int write_event_desc(struct feat_fd *ff, static int write_cmdline(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; char pbuf[MAXPATHLEN], *buf; int i, ret, n; =20 @@ -564,7 +565,7 @@ static int write_cmdline(struct feat_fd *ff, buf =3D perf_exe(pbuf, MAXPATHLEN); =20 /* account for binary path */ - n =3D perf_env.nr_cmdline + 1; + n =3D env->nr_cmdline + 1; =20 ret =3D do_write(ff, &n, sizeof(n)); if (ret < 0) @@ -574,8 +575,8 @@ static int write_cmdline(struct feat_fd *ff, if (ret < 0) return ret; =20 - for (i =3D 0 ; i < perf_env.nr_cmdline; i++) { - ret =3D do_write_string(ff, perf_env.cmdline_argv[i]); + for (i =3D 0 ; i < env->nr_cmdline; i++) { + ret =3D do_write_string(ff, env->cmdline_argv[i]); if (ret < 0) return ret; } @@ -586,6 +587,7 @@ static int write_cmdline(struct feat_fd *ff, static int write_cpu_topology(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; struct cpu_topology *tp; u32 i; int ret, j; @@ -613,17 +615,17 @@ static int write_cpu_topology(struct feat_fd *ff, break; } =20 - ret =3D perf_env__read_cpu_topology_map(&perf_env); + ret =3D perf_env__read_cpu_topology_map(env); if (ret < 0) goto done; =20 - for (j =3D 0; j < perf_env.nr_cpus_avail; j++) { - ret =3D do_write(ff, &perf_env.cpu[j].core_id, - sizeof(perf_env.cpu[j].core_id)); + for (j =3D 0; j < env->nr_cpus_avail; j++) { + ret =3D do_write(ff, &env->cpu[j].core_id, + sizeof(env->cpu[j].core_id)); if (ret < 0) return ret; - ret =3D do_write(ff, &perf_env.cpu[j].socket_id, - sizeof(perf_env.cpu[j].socket_id)); + ret =3D do_write(ff, &env->cpu[j].socket_id, + sizeof(env->cpu[j].socket_id)); if (ret < 0) return ret; } @@ -641,9 +643,9 @@ static int write_cpu_topology(struct feat_fd *ff, goto done; } =20 - for (j =3D 0; j < perf_env.nr_cpus_avail; j++) { - ret =3D do_write(ff, &perf_env.cpu[j].die_id, - sizeof(perf_env.cpu[j].die_id)); + for (j =3D 0; j < env->nr_cpus_avail; j++) { + ret =3D do_write(ff, &env->cpu[j].die_id, + sizeof(env->cpu[j].die_id)); if (ret < 0) return ret; } @@ -2123,17 +2125,18 @@ static void print_cpu_pmu_caps(struct feat_fd *ff, = FILE *fp) =20 static void print_pmu_caps(struct feat_fd *ff, FILE *fp) { + struct perf_env *env =3D &ff->ph->env; struct pmu_caps *pmu_caps; =20 - for (int i =3D 0; i < ff->ph->env.nr_pmus_with_caps; i++) { - pmu_caps =3D &ff->ph->env.pmu_caps[i]; + for (int i =3D 0; i < env->nr_pmus_with_caps; i++) { + pmu_caps =3D &env->pmu_caps[i]; __print_pmu_caps(fp, pmu_caps->nr_caps, pmu_caps->caps, pmu_caps->pmu_name); } =20 - if (strcmp(perf_env__arch(&ff->ph->env), "x86") =3D=3D 0 && - perf_env__has_pmu_mapping(&ff->ph->env, "ibs_op")) { - char *max_precise =3D perf_env__find_pmu_cap(&ff->ph->env, "cpu", "max_p= recise"); + if (strcmp(perf_env__arch(env), "x86") =3D=3D 0 && + perf_env__has_pmu_mapping(env, "ibs_op")) { + char *max_precise =3D perf_env__find_pmu_cap(env, "cpu", "max_precise"); =20 if (max_precise !=3D NULL && atoi(max_precise) =3D=3D 0) fprintf(fp, "# AMD systems uses ibs_op// PMU for some precise events, e= .g.: cycles:p, see the 'perf list' man page for further details.\n"); @@ -2142,18 +2145,19 @@ static void print_pmu_caps(struct feat_fd *ff, FILE= *fp) =20 static void print_pmu_mappings(struct feat_fd *ff, FILE *fp) { + struct perf_env *env =3D &ff->ph->env; const char *delimiter =3D "# pmu mappings: "; char *str, *tmp; u32 pmu_num; u32 type; =20 - pmu_num =3D ff->ph->env.nr_pmu_mappings; + pmu_num =3D env->nr_pmu_mappings; if (!pmu_num) { fprintf(fp, "# pmu mappings: not available\n"); return; } =20 - str =3D ff->ph->env.pmu_mappings; + str =3D env->pmu_mappings; =20 while (pmu_num) { type =3D strtoul(str, &tmp, 0); @@ -2235,17 +2239,18 @@ static void memory_node__fprintf(struct memory_node= *n, =20 static void print_mem_topology(struct feat_fd *ff, FILE *fp) { + struct perf_env *env =3D &ff->ph->env; struct memory_node *nodes; int i, nr; =20 - nodes =3D ff->ph->env.memory_nodes; - nr =3D ff->ph->env.nr_memory_nodes; + nodes =3D env->memory_nodes; + nr =3D env->nr_memory_nodes; =20 fprintf(fp, "# memory nodes (nr %d, block size 0x%llx):\n", - nr, ff->ph->env.memory_bsize); + nr, env->memory_bsize); =20 for (i =3D 0; i < nr; i++) { - memory_node__fprintf(&nodes[i], ff->ph->env.memory_bsize, fp); + memory_node__fprintf(&nodes[i], env->memory_bsize, fp); } } =20 @@ -2443,6 +2448,7 @@ static int process_build_id(struct feat_fd *ff, void = *data __maybe_unused) =20 static int process_nrcpus(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; int ret; u32 nr_cpus_avail, nr_cpus_online; =20 @@ -2453,20 +2459,21 @@ static int process_nrcpus(struct feat_fd *ff, void = *data __maybe_unused) ret =3D do_read_u32(ff, &nr_cpus_online); if (ret) return ret; - ff->ph->env.nr_cpus_avail =3D (int)nr_cpus_avail; - ff->ph->env.nr_cpus_online =3D (int)nr_cpus_online; + env->nr_cpus_avail =3D (int)nr_cpus_avail; + env->nr_cpus_online =3D (int)nr_cpus_online; return 0; } =20 static int process_total_mem(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; u64 total_mem; int ret; =20 ret =3D do_read_u64(ff, &total_mem); if (ret) return -1; - ff->ph->env.total_mem =3D (unsigned long long)total_mem; + env->total_mem =3D (unsigned long long)total_mem; return 0; } =20 @@ -2527,13 +2534,14 @@ process_event_desc(struct feat_fd *ff, void *data _= _maybe_unused) =20 static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; char *str, *cmdline =3D NULL, **argv =3D NULL; u32 nr, i, len =3D 0; =20 if (do_read_u32(ff, &nr)) return -1; =20 - ff->ph->env.nr_cmdline =3D nr; + env->nr_cmdline =3D nr; =20 cmdline =3D zalloc(ff->size + nr + 1); if (!cmdline) @@ -2553,8 +2561,8 @@ static int process_cmdline(struct feat_fd *ff, void *= data __maybe_unused) len +=3D strlen(str) + 1; free(str); } - ff->ph->env.cmdline =3D cmdline; - ff->ph->env.cmdline_argv =3D (const char **) argv; + env->cmdline =3D cmdline; + env->cmdline_argv =3D (const char **) argv; return 0; =20 error: @@ -2568,18 +2576,18 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) u32 nr, i; char *str =3D NULL; struct strbuf sb; - int cpu_nr =3D ff->ph->env.nr_cpus_avail; + struct perf_env *env =3D &ff->ph->env; + int cpu_nr =3D env->nr_cpus_avail; u64 size =3D 0; - struct perf_header *ph =3D ff->ph; =20 - ph->env.cpu =3D calloc(cpu_nr, sizeof(*ph->env.cpu)); - if (!ph->env.cpu) + env->cpu =3D calloc(cpu_nr, sizeof(*env->cpu)); + if (!env->cpu) return -1; =20 if (do_read_u32(ff, &nr)) goto free_cpu; =20 - ph->env.nr_sibling_cores =3D nr; + env->nr_sibling_cores =3D nr; size +=3D sizeof(u32); if (strbuf_init(&sb, 128) < 0) goto free_cpu; @@ -2595,12 +2603,12 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) size +=3D string_size(str); zfree(&str); } - ph->env.sibling_cores =3D strbuf_detach(&sb, NULL); + env->sibling_cores =3D strbuf_detach(&sb, NULL); =20 if (do_read_u32(ff, &nr)) return -1; =20 - ph->env.nr_sibling_threads =3D nr; + env->nr_sibling_threads =3D nr; size +=3D sizeof(u32); =20 for (i =3D 0; i < nr; i++) { @@ -2614,14 +2622,14 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) size +=3D string_size(str); zfree(&str); } - ph->env.sibling_threads =3D strbuf_detach(&sb, NULL); + env->sibling_threads =3D strbuf_detach(&sb, NULL); =20 /* * The header may be from old perf, * which doesn't include core id and socket id information. */ if (ff->size <=3D size) { - zfree(&ph->env.cpu); + zfree(&env->cpu); return 0; } =20 @@ -2629,13 +2637,13 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) if (do_read_u32(ff, &nr)) goto free_cpu; =20 - ph->env.cpu[i].core_id =3D nr; + env->cpu[i].core_id =3D nr; size +=3D sizeof(u32); =20 if (do_read_u32(ff, &nr)) goto free_cpu; =20 - ph->env.cpu[i].socket_id =3D nr; + env->cpu[i].socket_id =3D nr; size +=3D sizeof(u32); } =20 @@ -2649,7 +2657,7 @@ static int process_cpu_topology(struct feat_fd *ff, v= oid *data __maybe_unused) if (do_read_u32(ff, &nr)) return -1; =20 - ph->env.nr_sibling_dies =3D nr; + env->nr_sibling_dies =3D nr; size +=3D sizeof(u32); =20 for (i =3D 0; i < nr; i++) { @@ -2663,13 +2671,13 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) size +=3D string_size(str); zfree(&str); } - ph->env.sibling_dies =3D strbuf_detach(&sb, NULL); + env->sibling_dies =3D strbuf_detach(&sb, NULL); =20 for (i =3D 0; i < (u32)cpu_nr; i++) { if (do_read_u32(ff, &nr)) goto free_cpu; =20 - ph->env.cpu[i].die_id =3D nr; + env->cpu[i].die_id =3D nr; } =20 return 0; @@ -2678,12 +2686,13 @@ static int process_cpu_topology(struct feat_fd *ff,= void *data __maybe_unused) strbuf_release(&sb); zfree(&str); free_cpu: - zfree(&ph->env.cpu); + zfree(&env->cpu); return -1; } =20 static int process_numa_topology(struct feat_fd *ff, void *data __maybe_un= used) { + struct perf_env *env =3D &ff->ph->env; struct numa_node *nodes, *n; u32 nr, i; char *str; @@ -2718,8 +2727,8 @@ static int process_numa_topology(struct feat_fd *ff, = void *data __maybe_unused) if (!n->map) goto error; } - ff->ph->env.nr_numa_nodes =3D nr; - ff->ph->env.numa_nodes =3D nodes; + env->nr_numa_nodes =3D nr; + env->numa_nodes =3D nodes; return 0; =20 error: @@ -2729,6 +2738,7 @@ static int process_numa_topology(struct feat_fd *ff, = void *data __maybe_unused) =20 static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unu= sed) { + struct perf_env *env =3D &ff->ph->env; char *name; u32 pmu_num; u32 type; @@ -2742,7 +2752,7 @@ static int process_pmu_mappings(struct feat_fd *ff, v= oid *data __maybe_unused) return 0; } =20 - ff->ph->env.nr_pmu_mappings =3D pmu_num; + env->nr_pmu_mappings =3D pmu_num; if (strbuf_init(&sb, 128) < 0) return -1; =20 @@ -2761,14 +2771,14 @@ static int process_pmu_mappings(struct feat_fd *ff,= void *data __maybe_unused) goto error; =20 if (!strcmp(name, "msr")) - ff->ph->env.msr_pmu_type =3D type; + env->msr_pmu_type =3D type; =20 free(name); pmu_num--; } /* AMD may set it by evlist__has_amd_ibs() from perf_session__new() */ - free(ff->ph->env.pmu_mappings); - ff->ph->env.pmu_mappings =3D strbuf_detach(&sb, NULL); + free(env->pmu_mappings); + env->pmu_mappings =3D strbuf_detach(&sb, NULL); return 0; =20 error: @@ -2778,6 +2788,7 @@ static int process_pmu_mappings(struct feat_fd *ff, v= oid *data __maybe_unused) =20 static int process_group_desc(struct feat_fd *ff, void *data __maybe_unuse= d) { + struct perf_env *env =3D &ff->ph->env; size_t ret =3D -1; u32 i, nr, nr_groups; struct perf_session *session; @@ -2791,7 +2802,7 @@ static int process_group_desc(struct feat_fd *ff, voi= d *data __maybe_unused) if (do_read_u32(ff, &nr_groups)) return -1; =20 - ff->ph->env.nr_groups =3D nr_groups; + env->nr_groups =3D nr_groups; if (!nr_groups) { pr_debug("group desc not available\n"); return 0; @@ -2875,6 +2886,7 @@ static int process_auxtrace(struct feat_fd *ff, void = *data __maybe_unused) =20 static int process_cache(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; struct cpu_cache_level *caches; u32 cnt, i, version; =20 @@ -2915,8 +2927,8 @@ static int process_cache(struct feat_fd *ff, void *da= ta __maybe_unused) #undef _R } =20 - ff->ph->env.caches =3D caches; - ff->ph->env.caches_cnt =3D cnt; + env->caches =3D caches; + env->caches_cnt =3D cnt; return 0; out_free_caches: for (i =3D 0; i < cnt; i++) { @@ -2952,6 +2964,7 @@ static int process_sample_time(struct feat_fd *ff, vo= id *data __maybe_unused) static int process_mem_topology(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; struct memory_node *nodes; u64 version, i, nr, bsize; int ret =3D -1; @@ -2990,9 +3003,9 @@ static int process_mem_topology(struct feat_fd *ff, nodes[i] =3D n; } =20 - ff->ph->env.memory_bsize =3D bsize; - ff->ph->env.memory_nodes =3D nodes; - ff->ph->env.nr_memory_nodes =3D nr; + env->memory_bsize =3D bsize; + env->memory_nodes =3D nodes; + env->nr_memory_nodes =3D nr; ret =3D 0; =20 out: @@ -3004,7 +3017,9 @@ static int process_mem_topology(struct feat_fd *ff, static int process_clockid(struct feat_fd *ff, void *data __maybe_unused) { - if (do_read_u64(ff, &ff->ph->env.clock.clockid_res_ns)) + struct perf_env *env =3D &ff->ph->env; + + if (do_read_u64(ff, &env->clock.clockid_res_ns)) return -1; =20 return 0; @@ -3013,6 +3028,7 @@ static int process_clockid(struct feat_fd *ff, static int process_clock_data(struct feat_fd *ff, void *_data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; u32 data32; u64 data64; =20 @@ -3027,26 +3043,27 @@ static int process_clock_data(struct feat_fd *ff, if (do_read_u32(ff, &data32)) return -1; =20 - ff->ph->env.clock.clockid =3D data32; + env->clock.clockid =3D data32; =20 /* TOD ref time */ if (do_read_u64(ff, &data64)) return -1; =20 - ff->ph->env.clock.tod_ns =3D data64; + env->clock.tod_ns =3D data64; =20 /* clockid ref time */ if (do_read_u64(ff, &data64)) return -1; =20 - ff->ph->env.clock.clockid_ns =3D data64; - ff->ph->env.clock.enabled =3D true; + env->clock.clockid_ns =3D data64; + env->clock.enabled =3D true; return 0; } =20 static int process_hybrid_topology(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; struct hybrid_node *nodes, *n; u32 nr, i; =20 @@ -3070,8 +3087,8 @@ static int process_hybrid_topology(struct feat_fd *ff, goto error; } =20 - ff->ph->env.nr_hybrid_nodes =3D nr; - ff->ph->env.hybrid_nodes =3D nodes; + env->nr_hybrid_nodes =3D nr; + env->hybrid_nodes =3D nodes; return 0; =20 error: @@ -3224,19 +3241,21 @@ static int process_bpf_btf(struct feat_fd *ff, void= *data __maybe_unused) static int process_compressed(struct feat_fd *ff, void *data __maybe_unused) { - if (do_read_u32(ff, &(ff->ph->env.comp_ver))) + struct perf_env *env =3D &ff->ph->env; + + if (do_read_u32(ff, &(env->comp_ver))) return -1; =20 - if (do_read_u32(ff, &(ff->ph->env.comp_type))) + if (do_read_u32(ff, &(env->comp_type))) return -1; =20 - if (do_read_u32(ff, &(ff->ph->env.comp_level))) + if (do_read_u32(ff, &(env->comp_level))) return -1; =20 - if (do_read_u32(ff, &(ff->ph->env.comp_ratio))) + if (do_read_u32(ff, &(env->comp_ratio))) return -1; =20 - if (do_read_u32(ff, &(ff->ph->env.comp_mmap_len))) + if (do_read_u32(ff, &(env->comp_mmap_len))) return -1; =20 return 0; @@ -3308,19 +3327,21 @@ static int __process_pmu_caps(struct feat_fd *ff, i= nt *nr_caps, static int process_cpu_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) { - int ret =3D __process_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps, - &ff->ph->env.cpu_pmu_caps, - &ff->ph->env.max_branches, - &ff->ph->env.br_cntr_nr, - &ff->ph->env.br_cntr_width); + struct perf_env *env =3D &ff->ph->env; + int ret =3D __process_pmu_caps(ff, &env->nr_cpu_pmu_caps, + &env->cpu_pmu_caps, + &env->max_branches, + &env->br_cntr_nr, + &env->br_cntr_width); =20 - if (!ret && !ff->ph->env.cpu_pmu_caps) + if (!ret && !env->cpu_pmu_caps) pr_debug("cpu pmu capabilities not available\n"); return ret; } =20 static int process_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) { + struct perf_env *env =3D &ff->ph->env; struct pmu_caps *pmu_caps; u32 nr_pmu, i; int ret; @@ -3358,8 +3379,8 @@ static int process_pmu_caps(struct feat_fd *ff, void = *data __maybe_unused) } } =20 - ff->ph->env.nr_pmus_with_caps =3D nr_pmu; - ff->ph->env.pmu_caps =3D pmu_caps; + env->nr_pmus_with_caps =3D nr_pmu; + env->pmu_caps =3D pmu_caps; return 0; =20 err: @@ -3657,6 +3678,7 @@ static int perf_session__do_write_header(struct perf_= session *session, struct perf_header *header =3D &session->header; struct evsel *evsel; struct feat_fd ff =3D { + .ph =3D header, .fd =3D fd, }; u64 attr_offset =3D sizeof(f_header), attr_size =3D 0; --=20 2.50.0.727.gbf7dc18ff4-goog