From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 49BCC12BF34 for ; Thu, 21 Mar 2024 16:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036993; cv=none; b=X2O/aRmeMe2CrPqa8A8jNPl+EyamVKcLoJjQIMcjsFhVvBc9RV2kXhhqM5Y4fI6Tj0qeFBPiMByrK63lzG8ahjd4e5HowuLpmoyi75DmTAFUdDGHNdrYm5gF8dQf/D9NDyrIvsu8AERwbEGTWgRpKxtQP7EZWpJlk1sNyfzReFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036993; c=relaxed/simple; bh=RBrB5BXaNoo1IQoJ9V9QDA+EU1D4Wq30rZpNB+sQ3mE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=H6q+gOU09dVXGGgX2bfvlD9xtWeK9Upujpx9M3moJEpKrzxUQYyiyL5RPROCgxgLW4LMlhT0XHJZdfuoFazbQ3aRzwQk96UPBgWykT2ZEu8nAdd8RqgQt9HJ/2mECLdbB6tJUi3Qzrk7QkgQjf7v2c9/84FxD4M/rAKm+OGDTDM= 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=xQ8TQAhU; arc=none smtp.client-ip=209.85.128.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="xQ8TQAhU" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cd62fa20fso22939707b3.3 for ; Thu, 21 Mar 2024 09:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036989; x=1711641789; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=f+MEbM++g16iMexStgeW5mWbub1tgw8efwRK0qIdUcA=; b=xQ8TQAhUpQZW/nj8RuwbyUQz8RtuI9qMw9Dud1a6giL8MFhn+V7ejMrnb0/0MV8TFT IXotjNJGtnbQOtx1ns3N8DN+O92S/0LNsfVMhlAmwF+gm7wV5nkTLWjrNDj5vjiVTQrh JQJ3CcgSK10GsZoqwrFDdUcoTYfx7bx4LbuKB1x1CwywnmV2YqySXEwTW1YJ4jUjWAX0 ComgBD3LB/WhRRzFcSbMEhrC9h3n4d3W+P0fkR9aK4vEH3Wvj8k+0VkPQxITbcQYIihd Pi/5/KSRBH2r4NixZMeemwKZIA5GxVAjOKOx6a4LwGe09/Cq6YrjvYCSy11Vpngz59/f Qh3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036989; x=1711641789; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f+MEbM++g16iMexStgeW5mWbub1tgw8efwRK0qIdUcA=; b=mNWfez2zGJsHX7lMPNN3nGFiM5U2ICrO1l4Jn7urHDS6GiR6XNLUlkW7RlYg4S4gEX 6LPoEfFhmwGiaX19KlncSE81PQr/k9AbzCe+PTXbcLqds2Nu8d69uVUmOCozjM85wr6o c901BXiKnzwoJbf1TwMSVsevB0nfRwpzUI8fRsrrPuKIFKVr8HWmjIcfiQXYKFPemOZq pWu0LqRQfh/W+d5B8MzHTT9D5sx5dVltAjWXnlVKLnzwf+FJUkdtq8loyJx1eBOGpJZH E5aWR+ijIOxvDUBXjRg5N25fQ/Xiak9UCIa3Lz9LNj+DrtQLKTLttK3F+iceY/iVJu36 aXmw== X-Forwarded-Encrypted: i=1; AJvYcCVgEwKsyPjnJK91FPusUZXW6DguzrhvSHtlGlvJZl8HEvY9DAN3Wc3RA+ILl1lnRViXjl5rVOzm4bN9H32RtW7ONHghVHtoXHZrfq9b X-Gm-Message-State: AOJu0YxChFgZT18X1cavgAsbPJq4iI14vebzkvKE278uwlnjB3YvzkAS AVi1QY3qCZc/MjewI8XQGaaCOSIzTgndhN6ofpBRfZRv/mYgGhGzf6z4YYvEMbVUzuuKHPC+/gv FT3aHkg== X-Google-Smtp-Source: AGHT+IFpBo6k8tuUdOIJKcJBl2RWui1ScCSnQi70hMgOd5Gzx9PU8JVNw6XG+ulNbwPBSK4Y37K+Mi/3q7As X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:240f:b0:dc6:e20f:80cb with SMTP id dr15-20020a056902240f00b00dc6e20f80cbmr1122314ybb.3.1711036989312; Thu, 21 Mar 2024 09:03:09 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:48 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 01/13] perf dso: Reorder variables to save space in struct dso From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Save 40 bytes and move from 8 to 7 cache lines. Make variable dwfl dependent on being a powerpc build. Squeeze bits of int/enum types when appropriate. Remove holes/padding by reordering variables. Before: ``` struct dso { struct mutex lock; /* 0 40 */ struct list_head node; /* 40 16 */ struct rb_node rb_node __attribute__((__aligned__(8)));= /* 56 24 */ /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */ struct rb_root * root; /* 80 8 */ struct rb_root_cached symbols; /* 88 16 */ struct symbol * * symbol_names; /* 104 8 */ size_t symbol_names_len; /* 112 8 */ struct rb_root_cached inlined_nodes; /* 120 16 */ /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */ struct rb_root_cached srclines; /* 136 16 */ struct { u64 addr; /* 152 8 */ struct symbol * symbol; /* 160 8 */ } last_find_result; /* 152 16 */ void * a2l; /* 168 8 */ char * symsrc_filename; /* 176 8 */ unsigned int a2l_fails; /* 184 4 */ enum dso_space_type kernel; /* 188 4 */ /* --- cacheline 3 boundary (192 bytes) --- */ _Bool is_kmod; /* 192 1 */ /* XXX 3 bytes hole, try to pack */ enum dso_swap_type needs_swap; /* 196 4 */ enum dso_binary_type symtab_type; /* 200 4 */ enum dso_binary_type binary_type; /* 204 4 */ enum dso_load_errno load_errno; /* 208 4 */ u8 adjust_symbols:1; /* 212: 0 1 */ u8 has_build_id:1; /* 212: 1 1 */ u8 header_build_id:1; /* 212: 2 1 */ u8 has_srcline:1; /* 212: 3 1 */ u8 hit:1; /* 212: 4 1 */ u8 annotate_warned:1; /* 212: 5 1 */ u8 auxtrace_warned:1; /* 212: 6 1 */ u8 short_name_allocated:1; /* 212: 7 1 */ u8 long_name_allocated:1; /* 213: 0 1 */ u8 is_64_bit:1; /* 213: 1 1 */ /* XXX 6 bits hole, try to pack */ _Bool sorted_by_name; /* 214 1 */ _Bool loaded; /* 215 1 */ u8 rel; /* 216 1 */ /* XXX 7 bytes hole, try to pack */ struct build_id bid; /* 224 32 */ /* --- cacheline 4 boundary (256 bytes) --- */ u64 text_offset; /* 256 8 */ u64 text_end; /* 264 8 */ const char * short_name; /* 272 8 */ const char * long_name; /* 280 8 */ u16 long_name_len; /* 288 2 */ u16 short_name_len; /* 290 2 */ /* XXX 4 bytes hole, try to pack */ void * dwfl; /* 296 8 */ struct auxtrace_cache * auxtrace_cache; /* 304 8 */ int comp; /* 312 4 */ /* XXX 4 bytes hole, try to pack */ /* --- cacheline 5 boundary (320 bytes) --- */ struct { struct rb_root cache; /* 320 8 */ int fd; /* 328 4 */ int status; /* 332 4 */ u32 status_seen; /* 336 4 */ /* XXX 4 bytes hole, try to pack */ u64 file_size; /* 344 8 */ struct list_head open_entry; /* 352 16 */ u64 elf_base_addr; /* 368 8 */ u64 debug_frame_offset; /* 376 8 */ /* --- cacheline 6 boundary (384 bytes) --- */ u64 eh_frame_hdr_addr; /* 384 8 */ u64 eh_frame_hdr_offset; /* 392 8 */ } data; /* 320 80 */ struct { u32 id; /* 400 4 */ u32 sub_id; /* 404 4 */ struct perf_env * env; /* 408 8 */ } bpf_prog; /* 400 16 */ union { void * priv; /* 416 8 */ u64 db_id; /* 416 8 */ }; /* 416 8 */ struct nsinfo * nsinfo; /* 424 8 */ struct dso_id id; /* 432 24 */ /* --- cacheline 7 boundary (448 bytes) was 8 bytes ago --- */ refcount_t refcnt; /* 456 4 */ char name[]; /* 460 0 */ /* size: 464, cachelines: 8, members: 49 */ /* sum members: 440, holes: 4, sum holes: 18 */ /* sum bitfield members: 10 bits, bit holes: 1, sum bit holes: 6 bi= ts */ /* padding: 4 */ /* forced alignments: 1 */ /* last cacheline: 16 bytes */ } __attribute__((__aligned__(8))); ``` After: ``` struct dso { struct mutex lock; /* 0 40 */ struct list_head node; /* 40 16 */ struct rb_node rb_node __attribute__((__aligned__(8)));= /* 56 24 */ /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */ struct rb_root * root; /* 80 8 */ struct rb_root_cached symbols; /* 88 16 */ struct symbol * * symbol_names; /* 104 8 */ size_t symbol_names_len; /* 112 8 */ struct rb_root_cached inlined_nodes; /* 120 16 */ /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */ struct rb_root_cached srclines; /* 136 16 */ struct { u64 addr; /* 152 8 */ struct symbol * symbol; /* 160 8 */ } last_find_result; /* 152 16 */ struct build_id bid; /* 168 32 */ /* --- cacheline 3 boundary (192 bytes) was 8 bytes ago --- */ u64 text_offset; /* 200 8 */ u64 text_end; /* 208 8 */ const char * short_name; /* 216 8 */ const char * long_name; /* 224 8 */ void * a2l; /* 232 8 */ char * symsrc_filename; /* 240 8 */ struct nsinfo * nsinfo; /* 248 8 */ /* --- cacheline 4 boundary (256 bytes) --- */ struct auxtrace_cache * auxtrace_cache; /* 256 8 */ union { void * priv; /* 264 8 */ u64 db_id; /* 264 8 */ }; /* 264 8 */ struct { struct perf_env * env; /* 272 8 */ u32 id; /* 280 4 */ u32 sub_id; /* 284 4 */ } bpf_prog; /* 272 16 */ struct { struct rb_root cache; /* 288 8 */ struct list_head open_entry; /* 296 16 */ u64 file_size; /* 312 8 */ /* --- cacheline 5 boundary (320 bytes) --- */ u64 elf_base_addr; /* 320 8 */ u64 debug_frame_offset; /* 328 8 */ u64 eh_frame_hdr_addr; /* 336 8 */ u64 eh_frame_hdr_offset; /* 344 8 */ int fd; /* 352 4 */ int status; /* 356 4 */ u32 status_seen; /* 360 4 */ } data; /* 288 80 */ /* XXX last struct has 4 bytes of padding */ struct dso_id id; /* 368 24 */ /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */ unsigned int a2l_fails; /* 392 4 */ int comp; /* 396 4 */ refcount_t refcnt; /* 400 4 */ enum dso_load_errno load_errno; /* 404 4 */ u16 long_name_len; /* 408 2 */ u16 short_name_len; /* 410 2 */ enum dso_binary_type symtab_type:8; /* 412: 0 4 */ enum dso_binary_type binary_type:8; /* 412: 8 4 */ enum dso_space_type kernel:2; /* 412:16 4 */ enum dso_swap_type needs_swap:2; /* 412:18 4 */ /* Bitfield combined with next fields */ _Bool is_kmod:1; /* 414: 4 1 */ u8 adjust_symbols:1; /* 414: 5 1 */ u8 has_build_id:1; /* 414: 6 1 */ u8 header_build_id:1; /* 414: 7 1 */ u8 has_srcline:1; /* 415: 0 1 */ u8 hit:1; /* 415: 1 1 */ u8 annotate_warned:1; /* 415: 2 1 */ u8 auxtrace_warned:1; /* 415: 3 1 */ u8 short_name_allocated:1; /* 415: 4 1 */ u8 long_name_allocated:1; /* 415: 5 1 */ u8 is_64_bit:1; /* 415: 6 1 */ /* XXX 1 bit hole, try to pack */ _Bool sorted_by_name; /* 416 1 */ _Bool loaded; /* 417 1 */ u8 rel; /* 418 1 */ char name[]; /* 419 0 */ /* size: 424, cachelines: 7, members: 48 */ /* sum members: 415 */ /* sum bitfield members: 31 bits, bit holes: 1, sum bit holes: 1 bi= ts */ /* padding: 5 */ /* paddings: 1, sum paddings: 4 */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); ``` Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dso.h | 84 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 2cdcd1e2ef8b..17dab230a2ca 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -161,66 +161,66 @@ struct dso { u64 addr; struct symbol *symbol; } last_find_result; - void *a2l; - char *symsrc_filename; - unsigned int a2l_fails; - enum dso_space_type kernel; - bool is_kmod; - enum dso_swap_type needs_swap; - enum dso_binary_type symtab_type; - enum dso_binary_type binary_type; - enum dso_load_errno load_errno; - u8 adjust_symbols:1; - u8 has_build_id:1; - u8 header_build_id:1; - u8 has_srcline:1; - u8 hit:1; - u8 annotate_warned:1; - u8 auxtrace_warned:1; - u8 short_name_allocated:1; - u8 long_name_allocated:1; - u8 is_64_bit:1; - bool sorted_by_name; - bool loaded; - u8 rel; struct build_id bid; u64 text_offset; u64 text_end; const char *short_name; const char *long_name; - u16 long_name_len; - u16 short_name_len; + void *a2l; + char *symsrc_filename; +#if defined(__powerpc__) void *dwfl; /* DWARF debug info */ +#endif + struct nsinfo *nsinfo; struct auxtrace_cache *auxtrace_cache; - int comp; - + union { /* Tool specific area */ + void *priv; + u64 db_id; + }; + /* bpf prog information */ + struct { + struct perf_env *env; + u32 id; + u32 sub_id; + } bpf_prog; /* dso data file */ struct { struct rb_root cache; - int fd; - int status; - u32 status_seen; - u64 file_size; struct list_head open_entry; + u64 file_size; u64 elf_base_addr; u64 debug_frame_offset; u64 eh_frame_hdr_addr; u64 eh_frame_hdr_offset; + int fd; + int status; + u32 status_seen; } data; - /* bpf prog information */ - struct { - u32 id; - u32 sub_id; - struct perf_env *env; - } bpf_prog; - - union { /* Tool specific area */ - void *priv; - u64 db_id; - }; - struct nsinfo *nsinfo; struct dso_id id; + unsigned int a2l_fails; + int comp; refcount_t refcnt; + enum dso_load_errno load_errno; + u16 long_name_len; + u16 short_name_len; + enum dso_binary_type symtab_type:8; + enum dso_binary_type binary_type:8; + enum dso_space_type kernel:2; + enum dso_swap_type needs_swap:2; + bool is_kmod:1; + u8 adjust_symbols:1; + u8 has_build_id:1; + u8 header_build_id:1; + u8 has_srcline:1; + u8 hit:1; + u8 annotate_warned:1; + u8 auxtrace_warned:1; + u8 short_name_allocated:1; + u8 long_name_allocated:1; + u8 is_64_bit:1; + bool sorted_by_name; + bool loaded; + u8 rel; char name[]; }; =20 --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 C737612C527 for ; Thu, 21 Mar 2024 16:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036995; cv=none; b=Ii2Ttv/Okhfo0wcQq7odXkg7vsH8CxxXyKpRDxdJvmbuPFPDsITqpMPVXPbW/8jhJ8uWqvAgp+UPIvsbuq3W7fB9rJ3x00Ngnb61vXqwr571Yv4wgvwuByM0vNJrUOkQJ4hEoVUc+IQb1BY1kR4nVkPVZ/n5uPzAYVYbjHfbEyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036995; c=relaxed/simple; bh=RvGrSieMg01puLorEFd1YvPlUCbeQQy+EOZcf0PNNg4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=e7PAD37POSmA/MGPkW+u4T5P0dv6gD/oUC8RT3RbhUMLpqn77NPLkr5+NhJ66hABA0j5dYe2Eej/ESWqlqcNJLIAAMgv4Ep0R9Msx1ThQtFLxmaTyUYhlKe8BGGWID9H/7MoVsZtwgu6FKhaMszs9MoCaJiJXCHIbBvn+1H534w= 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=tsJ+KahJ; arc=none smtp.client-ip=209.85.128.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="tsJ+KahJ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cd62fa1f9so18766817b3.0 for ; Thu, 21 Mar 2024 09:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036992; x=1711641792; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=A6mwx89e884iOWF0zBTZijYWplNkTQNApk2ZPN2RuwQ=; b=tsJ+KahJ0qXEvNc8iy3xgnYPGh3KybapLbi8R/V+CT32o1U1UuluOpbpmQWe5geEnM xGbz2hj10hbOoWKdNmTuhMNS0dmYpBluQlX1SZlYnLqcfPunH9sRCmeJ5Pr66IXydjp/ ByWJEWRXANLzHv2bHTTDoYcjTcyPI/RLaYl0P2pmEsMZCl9qbBTdGjr+p60rjXXqldUE bpEGCypy52kTs4w3B1ZwNQfrmazd5HHPxXhq3lSrZk6yEcOt9mAw8JJrYXyQL3RKkyoI eZ1XkpJFdIuKVc2OHV2IO0lLfkUrWZ0Ju7/8v5GGt9bCl2dPQpgOEUJ5ugEtA6R+2f9g 81jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036992; x=1711641792; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A6mwx89e884iOWF0zBTZijYWplNkTQNApk2ZPN2RuwQ=; b=gdqueL3ICX6GqCVqF9NcIDm9+jlcofQNoDcN1BRg2xkdV9jtCQbU4XYTS4OgzmahpB LbpcXI7Hrm+24TCcKpDnFdNfZA8DOifX7G5wYCjWBcsSsub78KuMXk1Z9jaFe4HS421C Wni+N1l5Wgj+eKEQ5VVuQVSYmIwuyjtvbtD0F6NtlUOd8D1hrBuSQUhdjn3zhcQR/YUC tYQDI7bNetsUxhElGZJyZwxTGSHaZdH2h22ynOnQ3i9iSAFLVhrZsOAtCzNnn4CchymM oHm/VUCcx/KP3ZEo+/NHYhLvflCQYAPzFVkTd/Rq4y2mTYCw5kcOxr2CXD8Af4e0UQt+ ZsKw== X-Forwarded-Encrypted: i=1; AJvYcCVSHOdd1JDaTUIw9/O9t64EDtw6dyhT0GjBUnx/0lUy8wyqq5cJ+d0tIt1R09+EoiyfmVtp5/tZrJ8oXQk1nOxH/S/t9Vzq7MQ94/Er X-Gm-Message-State: AOJu0YxgePtJ4f3IkXoMh6AguyczDw7tQvOtUmP/S8XflvCznM0ztfRm lD7SuyTWjaPQCPE7Ct9ELKosCR37m/HtSxp2wVdw0hSiHan4IUTUq8HRvbu8PXY4NiDfThQYIB7 /H+GdIQ== X-Google-Smtp-Source: AGHT+IHQxhdOJM9f3J7sPloBw38dOD7P0pBnJ4xHDNNUfsOPJgaFwpLWerNNimUxZh/oUtIkZ28Kqb5EP8bS X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a81:9bcb:0:b0:610:3b7a:c179 with SMTP id s194-20020a819bcb000000b006103b7ac179mr3686397ywg.8.1711036991810; Thu, 21 Mar 2024 09:03:11 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:49 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 02/13] perf dsos: Attempt to better abstract dsos internals From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move functions from machine and build-id to dsos. Pass dsos struct rather than internal state. Rename some functions to better represent which data structure they operate on. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/util/build-id.c | 38 +--------------------------- tools/perf/util/build-id.h | 2 -- tools/perf/util/dso.h | 6 ----- tools/perf/util/dsos.c | 49 ++++++++++++++++++++++++++++++++++--- tools/perf/util/dsos.h | 19 +++++++++++--- tools/perf/util/machine.c | 40 ++++++------------------------ tools/perf/util/machine.h | 2 ++ tools/perf/util/session.c | 21 ++++++++++++++++ tools/perf/util/session.h | 2 ++ 11 files changed, 97 insertions(+), 86 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index eb3ef5c24b66..ef73317e6ae7 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2122,7 +2122,7 @@ static int __cmd_inject(struct perf_inject *inject) */ if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) && inject->have_auxtrace && !inject->itrace_synth_opts.set) - dsos__hit_all(session); + perf_session__dsos_hit_all(session); /* * The AUX areas have been removed and replaced with * synthesized hardware events, so clear the feature flag. diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40d2c1c48666..32df34dda9cd 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1790,7 +1790,7 @@ record__finish_output(struct record *rec) process_buildids(rec); =20 if (rec->buildid_all) - dsos__hit_all(rec->session); + perf_session__dsos_hit_all(rec->session); } perf_session__write_header(rec->session, rec->evlist, fd, true); =20 diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 03c64b85383b..a617b1917e6b 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -390,42 +390,6 @@ int perf_session__write_buildid_table(struct perf_sess= ion *session, return err; } =20 -static int __dsos__hit_all(struct list_head *head) -{ - struct dso *pos; - - list_for_each_entry(pos, head, node) - pos->hit =3D true; - - return 0; -} - -static int machine__hit_all_dsos(struct machine *machine) -{ - return __dsos__hit_all(&machine->dsos.head); -} - -int dsos__hit_all(struct perf_session *session) -{ - struct rb_node *nd; - int err; - - err =3D machine__hit_all_dsos(&session->machines.host); - if (err) - return err; - - for (nd =3D rb_first_cached(&session->machines.guests); nd; - nd =3D rb_next(nd)) { - struct machine *pos =3D rb_entry(nd, struct machine, rb_node); - - err =3D machine__hit_all_dsos(pos); - if (err) - return err; - } - - return 0; -} - void disable_buildid_cache(void) { no_buildid_cache =3D true; @@ -992,7 +956,7 @@ int perf_session__cache_build_ids(struct perf_session *= session) =20 static bool machine__read_build_ids(struct machine *machine, bool with_hit= s) { - return __dsos__read_build_ids(&machine->dsos.head, with_hits); + return __dsos__read_build_ids(&machine->dsos, with_hits); } =20 bool perf_session__read_build_ids(struct perf_session *session, bool with_= hits) diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 4e3a1169379b..3fa8bffb07ca 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -39,8 +39,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool, union = perf_event *event, struct perf_sample *sample, struct evsel *evsel, struct machine *machine); =20 -int dsos__hit_all(struct perf_session *session); - int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *e= vent, struct perf_sample *sample, struct evsel *evsel, struct machine *machine); diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 17dab230a2ca..3d4faad8d5dc 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -233,12 +233,6 @@ struct dso { #define dso__for_each_symbol(dso, pos, n) \ symbols__for_each_entry(&(dso)->symbols, pos, n) =20 -#define dsos__for_each_with_build_id(pos, head) \ - list_for_each_entry(pos, head, node) \ - if (!pos->has_build_id) \ - continue; \ - else - static inline void dso__set_loaded(struct dso *dso) { dso->loaded =3D true; diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index cf80aa42dd07..e65ef6762bed 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -12,6 +12,35 @@ #include // filename__read_build_id #include =20 +void dsos__init(struct dsos *dsos) +{ + INIT_LIST_HEAD(&dsos->head); + dsos->root =3D RB_ROOT; + init_rwsem(&dsos->lock); +} + +static void dsos__purge(struct dsos *dsos) +{ + struct dso *pos, *n; + + down_write(&dsos->lock); + + list_for_each_entry_safe(pos, n, &dsos->head, node) { + RB_CLEAR_NODE(&pos->rb_node); + pos->root =3D NULL; + list_del_init(&pos->node); + dso__put(pos); + } + + up_write(&dsos->lock); +} + +void dsos__exit(struct dsos *dsos) +{ + dsos__purge(dsos); + exit_rwsem(&dsos->lock); +} + static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) { if (a->maj > b->maj) return -1; @@ -73,8 +102,9 @@ int dso__cmp_id(struct dso *a, struct dso *b) return __dso_id__cmp(&a->id, &b->id); } =20 -bool __dsos__read_build_ids(struct list_head *head, bool with_hits) +bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) { + struct list_head *head =3D &dsos->head; bool have_build_id =3D false; struct dso *pos; struct nscookie nsc; @@ -303,9 +333,10 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const = char *name, struct dso_id return dso; } =20 -size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, +size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm) { + struct list_head *head =3D &dsos->head; struct dso *pos; size_t ret =3D 0; =20 @@ -320,8 +351,9 @@ size_t __dsos__fprintf_buildid(struct list_head *head, = FILE *fp, return ret; } =20 -size_t __dsos__fprintf(struct list_head *head, FILE *fp) +size_t __dsos__fprintf(struct dsos *dsos, FILE *fp) { + struct list_head *head =3D &dsos->head; struct dso *pos; size_t ret =3D 0; =20 @@ -331,3 +363,14 @@ size_t __dsos__fprintf(struct list_head *head, FILE *f= p) =20 return ret; } + +int __dsos__hit_all(struct dsos *dsos) +{ + struct list_head *head =3D &dsos->head; + struct dso *pos; + + list_for_each_entry(pos, head, node) + pos->hit =3D true; + + return 0; +} diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index 5dbec2bc6966..1c81ddf07f8f 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -21,6 +21,15 @@ struct dsos { struct rw_semaphore lock; }; =20 +#define dsos__for_each_with_build_id(pos, head) \ + list_for_each_entry(pos, head, node) \ + if (!pos->has_build_id) \ + continue; \ + else + +void dsos__init(struct dsos *dsos); +void dsos__exit(struct dsos *dsos); + void __dsos__add(struct dsos *dsos, struct dso *dso); void dsos__add(struct dsos *dsos, struct dso *dso); struct dso *__dsos__addnew(struct dsos *dsos, const char *name); @@ -28,13 +37,15 @@ struct dso *__dsos__find(struct dsos *dsos, const char = *name, bool cmp_short); =20 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id); =20 +bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits); + struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, stru= ct dso *dso, const char *name, struct dso_id *id); =20 -bool __dsos__read_build_ids(struct list_head *head, bool with_hits); - -size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, +size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm); -size_t __dsos__fprintf(struct list_head *head, FILE *fp); +size_t __dsos__fprintf(struct dsos *dsos, FILE *fp); + +int __dsos__hit_all(struct dsos *dsos); =20 #endif /* __PERF_DSOS */ diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 527517db3182..acd22b589f18 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -48,13 +48,6 @@ static struct dso *machine__kernel_dso(struct machine *m= achine) return map__dso(machine->vmlinux_map); } =20 -static void dsos__init(struct dsos *dsos) -{ - INIT_LIST_HEAD(&dsos->head); - dsos->root =3D RB_ROOT; - init_rwsem(&dsos->lock); -} - static int machine__set_mmap_name(struct machine *machine) { if (machine__is_host(machine)) @@ -165,28 +158,6 @@ struct machine *machine__new_kallsyms(void) return machine; } =20 -static void dsos__purge(struct dsos *dsos) -{ - struct dso *pos, *n; - - down_write(&dsos->lock); - - list_for_each_entry_safe(pos, n, &dsos->head, node) { - RB_CLEAR_NODE(&pos->rb_node); - pos->root =3D NULL; - list_del_init(&pos->node); - dso__put(pos); - } - - up_write(&dsos->lock); -} - -static void dsos__exit(struct dsos *dsos) -{ - dsos__purge(dsos); - exit_rwsem(&dsos->lock); -} - void machine__delete_threads(struct machine *machine) { threads__remove_all_threads(&machine->threads); @@ -907,11 +878,11 @@ static struct map *machine__addnew_module_map(struct = machine *machine, u64 start size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) { struct rb_node *nd; - size_t ret =3D __dsos__fprintf(&machines->host.dsos.head, fp); + size_t ret =3D __dsos__fprintf(&machines->host.dsos, fp); =20 for (nd =3D rb_first_cached(&machines->guests); nd; nd =3D rb_next(nd)) { struct machine *pos =3D rb_entry(nd, struct machine, rb_node); - ret +=3D __dsos__fprintf(&pos->dsos.head, fp); + ret +=3D __dsos__fprintf(&pos->dsos, fp); } =20 return ret; @@ -920,7 +891,7 @@ size_t machines__fprintf_dsos(struct machines *machines= , FILE *fp) size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm) { - return __dsos__fprintf_buildid(&m->dsos.head, fp, skip, parm); + return __dsos__fprintf_buildid(&m->dsos, fp, skip, parm); } =20 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, @@ -3282,3 +3253,8 @@ bool machine__is_lock_function(struct machine *machin= e, u64 addr) =20 return false; } + +int machine__hit_all_dsos(struct machine *machine) +{ + return __dsos__hit_all(&machine->dsos); +} diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index e28c787616fe..05927aa3e813 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -306,4 +306,6 @@ int machine__map_x86_64_entry_trampolines(struct machin= e *machine, int machine__resolve(struct machine *machine, struct addr_location *al, struct perf_sample *sample); =20 +int machine__hit_all_dsos(struct machine *machine); + #endif /* __PERF_MACHINE_H */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 02a932a83c51..a10343b9dcd4 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2916,3 +2916,24 @@ int perf_event__process_id_index(struct perf_session= *session, } return 0; } + +int perf_session__dsos_hit_all(struct perf_session *session) +{ + struct rb_node *nd; + int err; + + err =3D machine__hit_all_dsos(&session->machines.host); + if (err) + return err; + + for (nd =3D rb_first_cached(&session->machines.guests); nd; + nd =3D rb_next(nd)) { + struct machine *pos =3D rb_entry(nd, struct machine, rb_node); + + err =3D machine__hit_all_dsos(pos); + if (err) + return err; + } + + return 0; +} diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 5064c6ec11e7..3b0256e977a6 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -156,6 +156,8 @@ int perf_session__deliver_synth_event(struct perf_sessi= on *session, union perf_event *event, struct perf_sample *sample); =20 +int perf_session__dsos_hit_all(struct perf_session *session); + int perf_event__process_id_index(struct perf_session *session, union perf_event *event); =20 --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 0CF8812C542 for ; Thu, 21 Mar 2024 16:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036997; cv=none; b=rrpWfv6MqEXYgdzvIKIJdwZCY+OUG44pQdrLnvL1Wwca5MMh+de9qvpdO3CNNZtpnibyhrnBi4mMDEWr94Kz+oLkNrkzTbi19gmrgrhLSnw+ZurUyM04vhxZLPOIBkGsiUOEFVuB7aJcKXr3+qQtYnqi9JhtR0N9lZd0TKejmMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711036997; c=relaxed/simple; bh=DpS1VYOXN5R6vCzbh7A9b/ATmIa0NxRmy7mO95P/5gE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BsrCodadAsiOpu2PK3qK2zu4woS90kG4Wb6mkksfLfrow8C0WPZSdpavNjm7b3t/D+RGTDGx89mECW370s6B0JR22G9/WgJlw5HKrOa+tOPT76l5QsUal190yX4esO2I4WFL42OAPPDPdnO6m5/BYM5ArEoSqGdMrQ0sRdaPzBg= 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=mnu3dn8i; arc=none smtp.client-ip=209.85.219.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="mnu3dn8i" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dce775fa8adso1958667276.1 for ; Thu, 21 Mar 2024 09:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036994; x=1711641794; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=VooEq/3ZWxySAoyPE/sY5Ob6zVTJRR27KRBnDEyS5a0=; b=mnu3dn8iYvsunh+8Uwd1mP5OQ2KePh18KxUkywvc53JrOJb5i8J/tpQ06psFik1Vdn N9DQasClBRv2Z+In44AagKlZdIWIKOGQJqwHl34JAyv1cUbAnpSBCf8LmXaNyjXpUORC 07HDXpNZ1bRtm8C0d/tfGqOm3mqIT9fBB4R9Ud/QCeNvJ1Okis99Ls/PxSf4ZcQbb95j PK+3dmcDPiozYNuUjtiGlUhtC69TuHLm7cmxk5NUAXzo6Wai6w6i33H1KkaoomTDiEh/ wYiFPudMKzYA0A7wJ5Ox0VL3kLDnAU1LJAs9OR8wqEjjzgGjZRWuw1AEEQDWPI+wW5cQ R48Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036994; x=1711641794; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VooEq/3ZWxySAoyPE/sY5Ob6zVTJRR27KRBnDEyS5a0=; b=c924RMISftHcB9vSCs7Xkv+eKVJH1KlUTiYNuSghtotflu0HpRhcfJG0R6I5ze+E7P agTKEKlinF8UBs0Kwyw0OEC+L2Y6Ycy3NtUhoi5FaqkIkBU498HHroz8O4J69trA0q1i bbD3XAAXZ1mNVB4/5yAQfZ04YBq26xi2qzam0fBnTOPikfyX6fJ42CxkGPJGEd0S75vj x0DGrbEkZ8zXyI6G0uemlV8teFzJ79rN8tg8BFnJ2iPfe1jeMSUYFhPfCr+1Y7x2Fp0z +xQRMUEunmtBCp9k4/83YF5wgdC07uJVdwSBBrC2HXqZOhNNRRszWHkkyk6a/R2Y1Rc0 xMUg== X-Forwarded-Encrypted: i=1; AJvYcCX2fVFGVRuj4MgsHk32pPrUt/k7l9f+NztrPxl51n0F21L9ssfN7R/h+fnsPXDQW17SXIPqsrj1jiHUZ872un02zJw8uzz7sruUsgSg X-Gm-Message-State: AOJu0YzA4vm5W6cqBRxZqQJRAzT1HYgEwjUPiq4YBSCCHyxAIrKUyg0q AVsZtz5yZwAsWXwDYbBGe1krT/+s8qWcKzPSzAGy6lEr5XayuL77TFi77l/JVw6nwEkiHA7RScg 0CKknNA== X-Google-Smtp-Source: AGHT+IGbdRb9vjmmi5x1gzszUx04jmtwyR/JuH15fUTVCklv9QmM7FC7guO5yk2/GuQfVuvztRHQlIh383Dw X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:240e:b0:dcc:5a91:aee9 with SMTP id dr14-20020a056902240e00b00dcc5a91aee9mr5424305ybb.7.1711036994055; Thu, 21 Mar 2024 09:03:14 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:50 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 03/13] perf dsos: Tidy reference counting and locking From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move more functionality into dsos.c generally from machine, renaming functions to match their new usage. The find function is made to always "get" before returning a dso. Reduce the scope of locks in vdso to match the locking paradigm. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dsos.c | 73 +++++++++++++++++++++++++++++++++++---- tools/perf/util/dsos.h | 9 ++++- tools/perf/util/machine.c | 62 ++------------------------------- tools/perf/util/map.c | 4 +-- tools/perf/util/vdso.c | 48 +++++++++++-------------- 5 files changed, 97 insertions(+), 99 deletions(-) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index e65ef6762bed..d269e09005a7 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -181,7 +181,7 @@ struct dso *__dsos__findnew_link_by_longname_id(struct = rb_root *root, struct dso * at the end of the list of duplicates. */ if (!dso || (dso =3D=3D this)) - return this; /* Find matching dso */ + return dso__get(this); /* Find matching dso */ /* * The core kernel DSOs may have duplicated long name. * In this case, the short name should be different. @@ -253,15 +253,20 @@ static struct dso *__dsos__find_id(struct dsos *dsos,= const char *name, struct d if (cmp_short) { list_for_each_entry(pos, &dsos->head, node) if (__dso__cmp_short_name(name, id, pos) =3D=3D 0) - return pos; + return dso__get(pos); return NULL; } return __dsos__findnew_by_longname_id(&dsos->root, name, id); } =20 -struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_sho= rt) +struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short) { - return __dsos__find_id(dsos, name, NULL, cmp_short); + struct dso *res; + + down_read(&dsos->lock); + res =3D __dsos__find_id(dsos, name, NULL, cmp_short); + up_read(&dsos->lock); + return res; } =20 static void dso__set_basename(struct dso *dso) @@ -303,8 +308,6 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos,= const char *name, struct if (dso !=3D NULL) { __dsos__add(dsos, dso); dso__set_basename(dso); - /* Put dso here because __dsos_add already got it */ - dso__put(dso); } return dso; } @@ -328,7 +331,7 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const c= har *name, struct dso_id { struct dso *dso; down_write(&dsos->lock); - dso =3D dso__get(__dsos__findnew_id(dsos, name, id)); + dso =3D __dsos__findnew_id(dsos, name, id); up_write(&dsos->lock); return dso; } @@ -374,3 +377,59 @@ int __dsos__hit_all(struct dsos *dsos) =20 return 0; } + +struct dso *dsos__findnew_module_dso(struct dsos *dsos, + struct machine *machine, + struct kmod_path *m, + const char *filename) +{ + struct dso *dso; + + down_write(&dsos->lock); + + dso =3D __dsos__find_id(dsos, m->name, NULL, /*cmp_short=3D*/true); + if (!dso) { + dso =3D __dsos__addnew(dsos, m->name); + if (dso =3D=3D NULL) + goto out_unlock; + + dso__set_module_info(dso, m, machine); + dso__set_long_name(dso, strdup(filename), true); + dso->kernel =3D DSO_SPACE__KERNEL; + } + +out_unlock: + up_write(&dsos->lock); + return dso; +} + +struct dso *dsos__find_kernel_dso(struct dsos *dsos) +{ + struct dso *dso, *res =3D NULL; + + down_read(&dsos->lock); + list_for_each_entry(dso, &dsos->head, node) { + /* + * The cpumode passed to is_kernel_module is not the cpumode of + * *this* event. If we insist on passing correct cpumode to + * is_kernel_module, we should record the cpumode when we adding + * this dso to the linked list. + * + * However we don't really need passing correct cpumode. We + * know the correct cpumode must be kernel mode (if not, we + * should not link it onto kernel_dsos list). + * + * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. + * is_kernel_module() treats it as a kernel cpumode. + */ + if (!dso->kernel || + is_kernel_module(dso->long_name, + PERF_RECORD_MISC_CPUMODE_UNKNOWN)) + continue; + + res =3D dso__get(dso); + break; + } + up_read(&dsos->lock); + return res; +} diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index 1c81ddf07f8f..a7c7f723c5ff 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -10,6 +10,8 @@ =20 struct dso; struct dso_id; +struct kmod_path; +struct machine; =20 /* * DSOs are put into both a list for fast iteration and rbtree for fast @@ -33,7 +35,7 @@ void dsos__exit(struct dsos *dsos); void __dsos__add(struct dsos *dsos, struct dso *dso); void dsos__add(struct dsos *dsos, struct dso *dso); struct dso *__dsos__addnew(struct dsos *dsos, const char *name); -struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_sho= rt); +struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short= ); =20 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id); =20 @@ -48,4 +50,9 @@ size_t __dsos__fprintf(struct dsos *dsos, FILE *fp); =20 int __dsos__hit_all(struct dsos *dsos); =20 +struct dso *dsos__findnew_module_dso(struct dsos *dsos, struct machine *ma= chine, + struct kmod_path *m, const char *filename); + +struct dso *dsos__find_kernel_dso(struct dsos *dsos); + #endif /* __PERF_DSOS */ diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index acd22b589f18..a06b030fba54 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -646,31 +646,6 @@ int machine__process_lost_samples_event(struct machine= *machine __maybe_unused, return 0; } =20 -static struct dso *machine__findnew_module_dso(struct machine *machine, - struct kmod_path *m, - const char *filename) -{ - struct dso *dso; - - down_write(&machine->dsos.lock); - - dso =3D __dsos__find(&machine->dsos, m->name, true); - if (!dso) { - dso =3D __dsos__addnew(&machine->dsos, m->name); - if (dso =3D=3D NULL) - goto out_unlock; - - dso__set_module_info(dso, m, machine); - dso__set_long_name(dso, strdup(filename), true); - dso->kernel =3D DSO_SPACE__KERNEL; - } - - dso__get(dso); -out_unlock: - up_write(&machine->dsos.lock); - return dso; -} - int machine__process_aux_event(struct machine *machine __maybe_unused, union perf_event *event) { @@ -854,7 +829,7 @@ static struct map *machine__addnew_module_map(struct ma= chine *machine, u64 start if (kmod_path__parse_name(&m, filename)) return NULL; =20 - dso =3D machine__findnew_module_dso(machine, &m, filename); + dso =3D dsos__findnew_module_dso(&machine->dsos, machine, &m, filename); if (dso =3D=3D NULL) goto out; =20 @@ -1663,40 +1638,7 @@ static int machine__process_kernel_mmap_event(struct= machine *machine, * Should be there already, from the build-id table in * the header. */ - struct dso *kernel =3D NULL; - struct dso *dso; - - down_read(&machine->dsos.lock); - - list_for_each_entry(dso, &machine->dsos.head, node) { - - /* - * The cpumode passed to is_kernel_module is not the - * cpumode of *this* event. If we insist on passing - * correct cpumode to is_kernel_module, we should - * record the cpumode when we adding this dso to the - * linked list. - * - * However we don't really need passing correct - * cpumode. We know the correct cpumode must be kernel - * mode (if not, we should not link it onto kernel_dsos - * list). - * - * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. - * is_kernel_module() treats it as a kernel cpumode. - */ - - if (!dso->kernel || - is_kernel_module(dso->long_name, - PERF_RECORD_MISC_CPUMODE_UNKNOWN)) - continue; - - - kernel =3D dso__get(dso); - break; - } - - up_read(&machine->dsos.lock); + struct dso *kernel =3D dsos__find_kernel_dso(&machine->dsos); =20 if (kernel =3D=3D NULL) kernel =3D machine__findnew_dso(machine, machine->mmap_name); diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index a5d57c201a30..cca871959f87 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -196,9 +196,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, * reading the header will have the build ID set and all future mmaps w= ill * have it missing. */ - down_read(&machine->dsos.lock); - header_bid_dso =3D __dsos__find(&machine->dsos, filename, false); - up_read(&machine->dsos.lock); + header_bid_dso =3D dsos__find(&machine->dsos, filename, false); if (header_bid_dso && header_bid_dso->header_build_id) { dso__set_build_id(dso, &header_bid_dso->bid); dso->header_build_id =3D 1; diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index df8963796187..35532dcbff74 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c @@ -133,8 +133,6 @@ static struct dso *__machine__addnew_vdso(struct machin= e *machine, const char *s if (dso !=3D NULL) { __dsos__add(&machine->dsos, dso); dso__set_long_name(dso, long_name, false); - /* Put dso here because __dsos_add already got it */ - dso__put(dso); } =20 return dso; @@ -252,17 +250,15 @@ static struct dso *__machine__findnew_compat(struct m= achine *machine, const char *file_name; struct dso *dso; =20 - dso =3D __dsos__find(&machine->dsos, vdso_file->dso_name, true); + dso =3D dsos__find(&machine->dsos, vdso_file->dso_name, true); if (dso) - goto out; + return dso; =20 file_name =3D vdso__get_compat_file(vdso_file); if (!file_name) - goto out; + return NULL; =20 - dso =3D __machine__addnew_vdso(machine, vdso_file->dso_name, file_name); -out: - return dso; + return __machine__addnew_vdso(machine, vdso_file->dso_name, file_name); } =20 static int __machine__findnew_vdso_compat(struct machine *machine, @@ -308,21 +304,21 @@ static struct dso *machine__find_vdso(struct machine = *machine, dso_type =3D machine__thread_dso_type(machine, thread); switch (dso_type) { case DSO__TYPE_32BIT: - dso =3D __dsos__find(&machine->dsos, DSO__NAME_VDSO32, true); + dso =3D dsos__find(&machine->dsos, DSO__NAME_VDSO32, true); if (!dso) { - dso =3D __dsos__find(&machine->dsos, DSO__NAME_VDSO, - true); + dso =3D dsos__find(&machine->dsos, DSO__NAME_VDSO, + true); if (dso && dso_type !=3D dso__type(dso, machine)) dso =3D NULL; } break; case DSO__TYPE_X32BIT: - dso =3D __dsos__find(&machine->dsos, DSO__NAME_VDSOX32, true); + dso =3D dsos__find(&machine->dsos, DSO__NAME_VDSOX32, true); break; case DSO__TYPE_64BIT: case DSO__TYPE_UNKNOWN: default: - dso =3D __dsos__find(&machine->dsos, DSO__NAME_VDSO, true); + dso =3D dsos__find(&machine->dsos, DSO__NAME_VDSO, true); break; } =20 @@ -334,37 +330,33 @@ struct dso *machine__findnew_vdso(struct machine *mac= hine, { struct vdso_info *vdso_info; struct dso *dso =3D NULL; + char *file; =20 - down_write(&machine->dsos.lock); if (!machine->vdso_info) machine->vdso_info =3D vdso_info__new(); =20 vdso_info =3D machine->vdso_info; if (!vdso_info) - goto out_unlock; + return NULL; =20 dso =3D machine__find_vdso(machine, thread); if (dso) - goto out_unlock; + return dso; =20 #if BITS_PER_LONG =3D=3D 64 if (__machine__findnew_vdso_compat(machine, thread, vdso_info, &dso)) - goto out_unlock; + return dso; #endif =20 - dso =3D __dsos__find(&machine->dsos, DSO__NAME_VDSO, true); - if (!dso) { - char *file; + dso =3D dsos__find(&machine->dsos, DSO__NAME_VDSO, true); + if (dso) + return dso; =20 - file =3D get_file(&vdso_info->vdso); - if (file) - dso =3D __machine__addnew_vdso(machine, DSO__NAME_VDSO, file); - } + file =3D get_file(&vdso_info->vdso); + if (!file) + return NULL; =20 -out_unlock: - dso__get(dso); - up_write(&machine->dsos.lock); - return dso; + return __machine__addnew_vdso(machine, DSO__NAME_VDSO, file); } =20 bool dso__is_vdso(struct dso *dso) --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 4CB9212C55F for ; Thu, 21 Mar 2024 16:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037000; cv=none; b=uDYJ7MWKNcbUfT+dR6+HEbPTjSonwg6sxjvTVB9B0yPvnZXD+awW2edWPZQivKBUR870ZpFJn7GDOfK/WlDazDKeaYpMROilYMwwM3C0o77XzYWbTob25wVxADYbAR5p3Y1kxGgFxTFBy9PenBL6zWpzpRyvvAXi4B/8ykeHmBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037000; c=relaxed/simple; bh=QP0PbL5rLghFLJ//+TLNVGLCNfruBUXZgQsXaCRy2/8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LtbIx3sJgKKz+z8GST/cSHXKWNft8SIJyBVZchMecoVzahVeAL/UsGN9TFm2h23/ZRe5H//pBmygTyBLjf9wmvm89GD0jX9ihxbUZANSPU2CJqNEtW2h/r4BkOrlAVfSi7v8cqMJHXJjr5sgyB5ABD7D2xhBezBuCMKWHNn8is4= 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=fvpbhedJ; arc=none smtp.client-ip=209.85.128.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="fvpbhedJ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-610fe0406e9so18137927b3.2 for ; Thu, 21 Mar 2024 09:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036996; x=1711641796; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=h4Lbk6+ewHbBcUKKBVnEnKnqA+Oj4kfXooBC1ERcwlI=; b=fvpbhedJ3ostsIWDVr0+plwZyH0ltVpwqpfw2iI23Pqvl8oJq1NvbnqgGEBfxlimNM 2ic8ezsuNp5x7EAk5VD8gS3Pwwi9h5/ew3f3RFwbGRyKLTlDvut85/eG50f93ma1N6Ro AyVZrwlCtlGeNQQ1rBlG2JXh0aoHR6O41ti6i6bnnF0DsMvbN5RefKfnffsuVBqxsSTb ZjdPbn5FL+/vnB5W9T+QwPzC2Zej4M6J4btcZ+ozzTYDy5BzysMVGiPibPwkOU7SUE89 K+P9Oy3ejreJaeIvelu0ztCLx/mOtIxceX0AUcmxbwFctnkKCR+jubYZEYBZchlyWG6J 14Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036996; x=1711641796; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h4Lbk6+ewHbBcUKKBVnEnKnqA+Oj4kfXooBC1ERcwlI=; b=LS5M91ggB2nsDa+LUZG4t2fk3/0/X6hYhOzWnKTp1MCRbJzyG8Z8GI1G0Auic+Rzc+ WTVHEg+Xkbx1BtAvbDPwEMKFvj0rgyt/Qn33WgRQFXGsB7DA5Xa+sAUpwyMYQlADs4g5 D8AoKp1yE5rScQVJ0tCipJT4z3k5tfY82xB295X2S6gC9yqiRovU6YUoBgvQQY1VCSa1 8ybDRtN5x9sDzbAeLDwgcOfqckUFlAkFFPODa6NazQnu/l/uMTHvWIgEiR/xBsmKvc6/ D57oe8aeUxRqLGwnL4ivBqyAafA6eAhhTPiGs5hLI9niA+ofyL8oWMLHgZVW4+DwGUb/ kxXw== X-Forwarded-Encrypted: i=1; AJvYcCVHLJJPsk6ar520pjYTyMmrUDkTCz6AQdAHL/DrsVUGUisKLvSDjPRlIXPptO/mVcYLM1IKsIfxV5J3ATrfNL6RP4eV1ITu71HhSmeX X-Gm-Message-State: AOJu0YwNWyJ0gu8FCeaevuP1P6oz/j87Pk5led4zMKQikZnAhHFSGqTP tVXq7llEoKYVCUPR6xRQ78LjxMuSBlVRF/Nlz4Hgzwch4Mh6HHhVPYOA5ybbL+DJqKRESrs33eu hw2ST5g== X-Google-Smtp-Source: AGHT+IFngUIcQyUkSV+lDyA6uYRYCWeFxyIyvFvF0RBuKGP5TZQi67/EnGPw/vg+0RUL9Ac4OvnP2/r6Rczh X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a0d:e64e:0:b0:609:1253:bfd with SMTP id p75-20020a0de64e000000b0060912530bfdmr3974752ywe.10.1711036996192; Thu, 21 Mar 2024 09:03:16 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:51 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 04/13] perf dsos: Add dsos__for_each_dso From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To better abstract the dsos internals, add dsos__for_each_dso that does a callback on each dso. This also means the read lock can be correctly held. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-inject.c | 25 +++++++----- tools/perf/util/build-id.c | 76 ++++++++++++++++++++----------------- tools/perf/util/dsos.c | 16 ++++++++ tools/perf/util/dsos.h | 8 +--- tools/perf/util/machine.c | 40 +++++++++++-------- 5 files changed, 100 insertions(+), 65 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index ef73317e6ae7..ce5e28eaad90 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -1187,23 +1187,28 @@ static int synthesize_build_id(struct perf_inject *= inject, struct dso *dso, pid_ process_build_id, machine); } =20 +static int guest_session__add_build_ids_cb(struct dso *dso, void *data) +{ + struct guest_session *gs =3D data; + struct perf_inject *inject =3D container_of(gs, struct perf_inject, guest= _session); + + if (!dso->has_build_id) + return 0; + + return synthesize_build_id(inject, dso, gs->machine_pid); + +} + static int guest_session__add_build_ids(struct guest_session *gs) { struct perf_inject *inject =3D container_of(gs, struct perf_inject, guest= _session); - struct machine *machine =3D &gs->session->machines.host; - struct dso *dso; - int ret; =20 /* Build IDs will be put in the Build ID feature section */ perf_header__set_feat(&inject->session->header, HEADER_BUILD_ID); =20 - dsos__for_each_with_build_id(dso, &machine->dsos.head) { - ret =3D synthesize_build_id(inject, dso, gs->machine_pid); - if (ret) - return ret; - } - - return 0; + return dsos__for_each_dso(&gs->session->machines.host.dsos, + guest_session__add_build_ids_cb, + gs); } =20 static int guest_session__ksymbol_event(struct perf_tool *tool, diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index a617b1917e6b..a6d3c253f19f 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -327,48 +327,56 @@ static int write_buildid(const char *name, size_t nam= e_len, struct build_id *bid return write_padded(fd, name, name_len + 1, len); } =20 -static int machine__write_buildid_table(struct machine *machine, - struct feat_fd *fd) +struct machine__write_buildid_table_cb_args { + struct machine *machine; + struct feat_fd *fd; + u16 kmisc, umisc; +}; + +static int machine__write_buildid_table_cb(struct dso *dso, void *data) { - int err =3D 0; - struct dso *pos; - u16 kmisc =3D PERF_RECORD_MISC_KERNEL, - umisc =3D PERF_RECORD_MISC_USER; + struct machine__write_buildid_table_cb_args *args =3D data; + const char *name; + size_t name_len; + bool in_kernel =3D false; =20 - if (!machine__is_host(machine)) { - kmisc =3D PERF_RECORD_MISC_GUEST_KERNEL; - umisc =3D PERF_RECORD_MISC_GUEST_USER; - } + if (!dso->has_build_id) + return 0; =20 - dsos__for_each_with_build_id(pos, &machine->dsos.head) { - const char *name; - size_t name_len; - bool in_kernel =3D false; + if (!dso->hit && !dso__is_vdso(dso)) + return 0; =20 - if (!pos->hit && !dso__is_vdso(pos)) - continue; + if (dso__is_vdso(dso)) { + name =3D dso->short_name; + name_len =3D dso->short_name_len; + } else if (dso__is_kcore(dso)) { + name =3D args->machine->mmap_name; + name_len =3D strlen(name); + } else { + name =3D dso->long_name; + name_len =3D dso->long_name_len; + } =20 - if (dso__is_vdso(pos)) { - name =3D pos->short_name; - name_len =3D pos->short_name_len; - } else if (dso__is_kcore(pos)) { - name =3D machine->mmap_name; - name_len =3D strlen(name); - } else { - name =3D pos->long_name; - name_len =3D pos->long_name_len; - } + in_kernel =3D dso->kernel || is_kernel_module(name, PERF_RECORD_MISC_CPUM= ODE_UNKNOWN); + return write_buildid(name, name_len, &dso->bid, args->machine->pid, + in_kernel ? args->kmisc : args->umisc, args->fd); +} =20 - in_kernel =3D pos->kernel || - is_kernel_module(name, - PERF_RECORD_MISC_CPUMODE_UNKNOWN); - err =3D write_buildid(name, name_len, &pos->bid, machine->pid, - in_kernel ? kmisc : umisc, fd); - if (err) - break; +static int machine__write_buildid_table(struct machine *machine, struct fe= at_fd *fd) +{ + struct machine__write_buildid_table_cb_args args =3D { + .machine =3D machine, + .fd =3D fd, + .kmisc =3D PERF_RECORD_MISC_KERNEL, + .umisc =3D PERF_RECORD_MISC_USER, + }; + + if (!machine__is_host(machine)) { + args.kmisc =3D PERF_RECORD_MISC_GUEST_KERNEL; + args.umisc =3D PERF_RECORD_MISC_GUEST_USER; } =20 - return err; + return dsos__for_each_dso(&machine->dsos, machine__write_buildid_table_cb= , &args); } =20 int perf_session__write_buildid_table(struct perf_session *session, diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index d269e09005a7..d43f64939b12 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -433,3 +433,19 @@ struct dso *dsos__find_kernel_dso(struct dsos *dsos) up_read(&dsos->lock); return res; } + +int dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void = *data), void *data) +{ + struct dso *dso; + + down_read(&dsos->lock); + list_for_each_entry(dso, &dsos->head, node) { + int err; + + err =3D cb(dso, data); + if (err) + return err; + } + up_read(&dsos->lock); + return 0; +} diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index a7c7f723c5ff..317a263f0e37 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -23,12 +23,6 @@ struct dsos { struct rw_semaphore lock; }; =20 -#define dsos__for_each_with_build_id(pos, head) \ - list_for_each_entry(pos, head, node) \ - if (!pos->has_build_id) \ - continue; \ - else - void dsos__init(struct dsos *dsos); void dsos__exit(struct dsos *dsos); =20 @@ -55,4 +49,6 @@ struct dso *dsos__findnew_module_dso(struct dsos *dsos, s= truct machine *machine, =20 struct dso *dsos__find_kernel_dso(struct dsos *dsos); =20 +int dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void = *data), void *data); + #endif /* __PERF_DSOS */ diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index a06b030fba54..bd153bc2c8da 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1562,16 +1562,14 @@ int machine__create_kernel_maps(struct machine *mac= hine) return ret; } =20 -static bool machine__uses_kcore(struct machine *machine) +static int machine__uses_kcore_cb(struct dso *dso, void *data __maybe_unus= ed) { - struct dso *dso; - - list_for_each_entry(dso, &machine->dsos.head, node) { - if (dso__is_kcore(dso)) - return true; - } + return dso__is_kcore(dso) ? 1 : 0; +} =20 - return false; +static bool machine__uses_kcore(struct machine *machine) +{ + return dsos__for_each_dso(&machine->dsos, machine__uses_kcore_cb, NULL) != =3D 0 ? true : false; } =20 static bool perf_event__is_extra_kernel_mmap(struct machine *machine, @@ -3137,16 +3135,28 @@ char *machine__resolve_kernel_addr(void *vmachine, = unsigned long long *addrp, ch return sym->name; } =20 +struct machine__for_each_dso_cb_args { + struct machine *machine; + machine__dso_t fn; + void *priv; +}; + +static int machine__for_each_dso_cb(struct dso *dso, void *data) +{ + struct machine__for_each_dso_cb_args *args =3D data; + + return args->fn(dso, args->machine, args->priv); +} + int machine__for_each_dso(struct machine *machine, machine__dso_t fn, void= *priv) { - struct dso *pos; - int err =3D 0; + struct machine__for_each_dso_cb_args args =3D { + .machine =3D machine, + .fn =3D fn, + .priv =3D priv, + }; =20 - list_for_each_entry(pos, &machine->dsos.head, node) { - if (fn(pos, machine, priv)) - err =3D -1; - } - return err; + return dsos__for_each_dso(&machine->dsos, machine__for_each_dso_cb, &args= ); } =20 int machine__for_each_kernel_map(struct machine *machine, machine__map_t f= n, void *priv) --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 A0A6712BF23 for ; Thu, 21 Mar 2024 16:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037001; cv=none; b=EnIsenZJnO4SUSgamAaKKBSKtW5f3XJNBBMlAQykbP3lURQpQUeAsPBAl2+Zi/nafJVXawMohBNXHAeieUNsD5//LcCLLZ+yGrJa4XDQMfeL/j7MteWjbuzfhPALY+/WTnu1Ltxl2g2XBWh3MMP3tV0Z9iIEuzCGfPS7AmY20Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037001; c=relaxed/simple; bh=9LrrlqsVcKRB6YFnDGI9TYjo4HpRppL0r92IM1Tgoh4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SaWWpXPPj+99gKBe4PPgW5PqvYKQI+sDZlcpLwwaoRCZ46FU70Cn2UXtiobKpUREsMFdAnh4SdzPp+BeXU5S3EfCWxWDN+zc2Xp4QXdGctO9WA5cl+t13Z6vuEZTTB9EA9rA5lDljI+en9acdP0B5QbfCWZWEE5gW92MxlTr808= 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=Mdb7spP3; arc=none smtp.client-ip=209.85.219.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="Mdb7spP3" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd944567b6cso1494676276.2 for ; Thu, 21 Mar 2024 09:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036999; x=1711641799; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=G9mbEbN1xeqzONkxcGNMMjxISnrWiZEkSSQzXGtcTD4=; b=Mdb7spP32sGQEDm0u4BJmuQ50CiiR95D5hOAsmq/iCi7OoJ9z/PgZ1jrDduIWvcnEq LzRn2L+Ebl0pEsVYiDeKbRBAr2fXSgS6JKwEya501VjjDNbHnnR7akVowIJ4FwMGjFXK hbKiaDwC1/iMznYYWQFGYFmD72sF8Qx8Kbd170XdHHt6pfssaud2oDGlimZ2+wWlPhua 8s0D2DLmJTNwQZcU3YuHc97CU1Y6AJcaKfw0OYcMh1odkbIx5pOf8gw1wPqnk40ttePL AGH22U7ixF7dpWifcrknw6ylwxXI3oMzaz3jClY3C+msJJ6SP4hhzobQ+kWMcj4acE5U pwqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036999; x=1711641799; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G9mbEbN1xeqzONkxcGNMMjxISnrWiZEkSSQzXGtcTD4=; b=lyzEaiE0AF3i7YYgb92FOsbPDGY7oc58rmbMIra95bCLQ2GItmghM4ai4R0e3NSHou Fo/NZavk/65mvtflfivbiBXDp2H3UhpwT0666WY904drCt1uEUiVkKG4LofVw83rqsw6 m+8fkoaKjGZnJhRV8d45ufA3KlafP0FSikdIaNjkz1LPL3sJcJg1bjDd9Kl2+HsEYyon 5oReu8BmzXTayoRcuGjL6+BF7/WfbYfDe9fWLFKhmSvGYVFm2Gr+Hj/2LMXkPr9SGKzE EIQ+J8VyEtvq1Cmdc14sSIoYpC+zihC5WSmqyIPRAHkUfXU9SknOtebwi7x+Gqby9QKk hUZw== X-Forwarded-Encrypted: i=1; AJvYcCVNeWvQ3ZprNIorjjgnCK1EbuM5ATgky03QUmEXPBDn0YtXeb54cI8lKLowlXJY2zwqeBhUdnHhQQa7vQM1PXn9g9lybD/QpKNVpAno X-Gm-Message-State: AOJu0Yw28sT9Ng5IfKTYsOfzxQmjcjKIRJpgNJRypMLCLsKACnIAfDdu OIehG07CkYKiAuVNIa7EVPX3UFdviApU+844Tch0WAbouL4+sxBtOrTQZiuFVKIyBZGPq9t/Cdm khm8dwQ== X-Google-Smtp-Source: AGHT+IFBX1i5W9iuhZeU/Z7RRN7eMO4Lx043+kbxsvY/o3kqCbqP8YT6t16ykoQnFPFDSBxq5mrS0mombbJY X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:218c:b0:dcc:4785:b51e with SMTP id dl12-20020a056902218c00b00dcc4785b51emr969569ybb.12.1711036998640; Thu, 21 Mar 2024 09:03:18 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:52 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 05/13] perf dso: Move dso functions out of dsos From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move dso and dso_id functions to dso.c to match the struct declarations. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dso.c | 61 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 4 +++ tools/perf/util/dsos.c | 61 ------------------------------------------ 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 6e2a7198b382..ad562743d769 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1269,6 +1269,67 @@ static void dso__set_long_name_id(struct dso *dso, c= onst char *name, struct dso_ __dsos__findnew_link_by_longname_id(root, dso, NULL, id); } =20 +static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) +{ + if (a->maj > b->maj) return -1; + if (a->maj < b->maj) return 1; + + if (a->min > b->min) return -1; + if (a->min < b->min) return 1; + + if (a->ino > b->ino) return -1; + if (a->ino < b->ino) return 1; + + /* + * Synthesized MMAP events have zero ino_generation, avoid comparing + * them with MMAP events with actual ino_generation. + * + * I found it harmful because the mismatch resulted in a new + * dso that did not have a build ID whereas the original dso did have a + * build ID. The build ID was essential because the object was not found + * otherwise. - Adrian + */ + if (a->ino_generation && b->ino_generation) { + if (a->ino_generation > b->ino_generation) return -1; + if (a->ino_generation < b->ino_generation) return 1; + } + + return 0; +} + +bool dso_id__empty(struct dso_id *id) +{ + if (!id) + return true; + + return !id->maj && !id->min && !id->ino && !id->ino_generation; +} + +void dso__inject_id(struct dso *dso, struct dso_id *id) +{ + dso->id.maj =3D id->maj; + dso->id.min =3D id->min; + dso->id.ino =3D id->ino; + dso->id.ino_generation =3D id->ino_generation; +} + +int dso_id__cmp(struct dso_id *a, struct dso_id *b) +{ + /* + * The second is always dso->id, so zeroes if not set, assume passing + * NULL for a means a zeroed id + */ + if (dso_id__empty(a) || dso_id__empty(b)) + return 0; + + return __dso_id__cmp(a, b); +} + +int dso__cmp_id(struct dso *a, struct dso *b) +{ + return __dso_id__cmp(&a->id, &b->id); +} + void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated) { dso__set_long_name_id(dso, name, NULL, name_allocated); diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 3d4faad8d5dc..2c295438226d 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -238,6 +238,9 @@ static inline void dso__set_loaded(struct dso *dso) dso->loaded =3D true; } =20 +int dso_id__cmp(struct dso_id *a, struct dso_id *b); +bool dso_id__empty(struct dso_id *id); + struct dso *dso__new_id(const char *name, struct dso_id *id); struct dso *dso__new(const char *name); void dso__delete(struct dso *dso); @@ -245,6 +248,7 @@ void dso__delete(struct dso *dso); int dso__cmp_id(struct dso *a, struct dso *b); void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated); void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated); +void dso__inject_id(struct dso *dso, struct dso_id *id); =20 int dso__name_len(const struct dso *dso); =20 diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index d43f64939b12..f816927a21ff 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -41,67 +41,6 @@ void dsos__exit(struct dsos *dsos) exit_rwsem(&dsos->lock); } =20 -static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) -{ - if (a->maj > b->maj) return -1; - if (a->maj < b->maj) return 1; - - if (a->min > b->min) return -1; - if (a->min < b->min) return 1; - - if (a->ino > b->ino) return -1; - if (a->ino < b->ino) return 1; - - /* - * Synthesized MMAP events have zero ino_generation, avoid comparing - * them with MMAP events with actual ino_generation. - * - * I found it harmful because the mismatch resulted in a new - * dso that did not have a build ID whereas the original dso did have a - * build ID. The build ID was essential because the object was not found - * otherwise. - Adrian - */ - if (a->ino_generation && b->ino_generation) { - if (a->ino_generation > b->ino_generation) return -1; - if (a->ino_generation < b->ino_generation) return 1; - } - - return 0; -} - -static bool dso_id__empty(struct dso_id *id) -{ - if (!id) - return true; - - return !id->maj && !id->min && !id->ino && !id->ino_generation; -} - -static void dso__inject_id(struct dso *dso, struct dso_id *id) -{ - dso->id.maj =3D id->maj; - dso->id.min =3D id->min; - dso->id.ino =3D id->ino; - dso->id.ino_generation =3D id->ino_generation; -} - -static int dso_id__cmp(struct dso_id *a, struct dso_id *b) -{ - /* - * The second is always dso->id, so zeroes if not set, assume passing - * NULL for a means a zeroed id - */ - if (dso_id__empty(a) || dso_id__empty(b)) - return 0; - - return __dso_id__cmp(a, b); -} - -int dso__cmp_id(struct dso *a, struct dso *b) -{ - return __dso_id__cmp(&a->id, &b->id); -} - bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) { struct list_head *head =3D &dsos->head; --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 6EC0612CDA9 for ; Thu, 21 Mar 2024 16:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037007; cv=none; b=Hq8uLJHmROJ2lWb23U97OepFtPosxjusiFtwqqXTYt7VIGANC6Bs8KNJJi4GZg+OYhR0yB5BGmD0+GVWKiUL/7POYJKp1SF9DWlnKULoiyCECMslCudqf+XFumwFqLQwNOhFup3k/1gSE3pG7Gae/IkFfaZeKxQYKT/f/T6FHKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037007; c=relaxed/simple; bh=pcKEp/t7NibPWWwI0c25kFKRAInJPDRXwVb8ImvA4bw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Qi3MK3FLsZ65t7lXd8D1Mws90Iz1Ynid5duSJo02iJGFisTzySmblNzdAyjOIz/+wzfa12OuZaDGz3P167zMQ0PhisRVRuymiDMw6jEQUDztJh/kHPeEhh3z5vJ42/K5Dy3usJsRVXu18nAw2OixdZJZ0Vf8D7OyRERZlzTxsIg= 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=VHaa81mj; arc=none smtp.client-ip=209.85.128.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="VHaa81mj" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60ab69a9e6fso28372827b3.0 for ; Thu, 21 Mar 2024 09:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037003; x=1711641803; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=bVLF+UKKSSneQDn6qHputn9QFsbRV8FfQmrWOHTFem8=; b=VHaa81mjeWm7jeTO9GoOfIlgMNGAgry38glFr7EJ9akANzSwdltxFHYb1ffgE8pY6E 2nWkwG3eBOr5kbJNNgGapv77vh9QfSOt1SNAfmK62eVVWQUtPjUo5ELxt9DotrLL23av eS+p+tgSnVY3rwkEpiidk/uhp3klLrM437YO2n47KiCR1ex5oXCw48E7FbnQ+WBiBveK J11mNUA5Pv5M8YoeY6f1qlL4WOo+ZczANigBQgWwI2iadjnwVHbbN5hw9Qhhg2siH3vE ryyJS+6LIIaq466hXrGnXkClDcQ5ni+szwnRzymFvzwRj/39YnogbaIUK6ufGLYHoVm3 hMEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037003; x=1711641803; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bVLF+UKKSSneQDn6qHputn9QFsbRV8FfQmrWOHTFem8=; b=ia9MDP2JBlFU8d2zX9DWUvWpYeMKNKbEs//+NP0j3zp+bHT0cz/JFQvV3XcTerTXTE 3p6PsPz+y7f4ucQrnEHEt6JwmtLf1bEiC3PVoC86vpUjfEmAO1VlWFnmjZDKRPtaR9uH IXJzjUrIZzkPq7icsX7fAFeam084oYBtJde37tpiOO5C9pJuGL5DymKEflRFmxcdlWOp FOxfchEwmI/+5d+FTC+BdVHSzxOJy/taRINWrnRFZ0fAJvqhwS64mzEGPp8f178VoH+p L9WJPppcHU/FDg6+fZAQlmxl7T/8V2kOLRPEv5UJrM/1JR7k4NHjH/3VFwGEzWgs9qh4 99gg== X-Forwarded-Encrypted: i=1; AJvYcCUph5Z7wiDYzMWogqK8WWTOX9oDt+mWjcwiuCLvDboZqkFqj2tuoSVkeRFNHXEbqcr9y6fRcgdGZdzTQJf55aCgKJ+o42Mu5sdA1HHC X-Gm-Message-State: AOJu0Yw4ROIk2HYD63UDwGVlqyyueVxIvcv4jwWg3QXW2OsX7P4L9Krf gtsl+d8lfauOlF5aIKgkyf2K0/aM7J3Mh46a1mffhEc6NUJxAoNzYvAiZNFuxGOI0Qs9gVNG1Wk P+fCkSA== X-Google-Smtp-Source: AGHT+IFXqgieHzdBR1PeQbVrNq2Ez/JXfq1sVXzLHKGI5bHOXdEHN+ok9zB6M8NysufvWDRFFOmYjUqbxTgv X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a0d:cc41:0:b0:610:dc1b:8e57 with SMTP id o62-20020a0dcc41000000b00610dc1b8e57mr835290ywd.3.1711037003534; Thu, 21 Mar 2024 09:03:23 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:53 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 06/13] perf dsos: Switch more loops to dsos__for_each_dso From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch loops within dsos.c, add a version that isn't locked. Switch some unlocked loops to hold the read lock. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/build-id.c | 2 +- tools/perf/util/dsos.c | 258 ++++++++++++++++++++++++------------- tools/perf/util/dsos.h | 8 +- tools/perf/util/machine.c | 8 +- 4 files changed, 174 insertions(+), 102 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index a6d3c253f19f..864bc26b6b46 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -964,7 +964,7 @@ int perf_session__cache_build_ids(struct perf_session *= session) =20 static bool machine__read_build_ids(struct machine *machine, bool with_hit= s) { - return __dsos__read_build_ids(&machine->dsos, with_hits); + return dsos__read_build_ids(&machine->dsos, with_hits); } =20 bool perf_session__read_build_ids(struct perf_session *session, bool with_= hits) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index f816927a21ff..b7fbfb877ae3 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -41,38 +41,65 @@ void dsos__exit(struct dsos *dsos) exit_rwsem(&dsos->lock); } =20 -bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) + +static int __dsos__for_each_dso(struct dsos *dsos, + int (*cb)(struct dso *dso, void *data), + void *data) +{ + struct dso *dso; + + list_for_each_entry(dso, &dsos->head, node) { + int err; + + err =3D cb(dso, data); + if (err) + return err; + } + return 0; +} + +struct dsos__read_build_ids_cb_args { + bool with_hits; + bool have_build_id; +}; + +static int dsos__read_build_ids_cb(struct dso *dso, void *data) { - struct list_head *head =3D &dsos->head; - bool have_build_id =3D false; - struct dso *pos; + struct dsos__read_build_ids_cb_args *args =3D data; struct nscookie nsc; =20 - list_for_each_entry(pos, head, node) { - if (with_hits && !pos->hit && !dso__is_vdso(pos)) - continue; - if (pos->has_build_id) { - have_build_id =3D true; - continue; - } - nsinfo__mountns_enter(pos->nsinfo, &nsc); - if (filename__read_build_id(pos->long_name, &pos->bid) > 0) { - have_build_id =3D true; - pos->has_build_id =3D true; - } else if (errno =3D=3D ENOENT && pos->nsinfo) { - char *new_name =3D dso__filename_with_chroot(pos, pos->long_name); - - if (new_name && filename__read_build_id(new_name, - &pos->bid) > 0) { - have_build_id =3D true; - pos->has_build_id =3D true; - } - free(new_name); + if (args->with_hits && !dso->hit && !dso__is_vdso(dso)) + return 0; + if (dso->has_build_id) { + args->have_build_id =3D true; + return 0; + } + nsinfo__mountns_enter(dso->nsinfo, &nsc); + if (filename__read_build_id(dso->long_name, &dso->bid) > 0) { + args->have_build_id =3D true; + dso->has_build_id =3D true; + } else if (errno =3D=3D ENOENT && dso->nsinfo) { + char *new_name =3D dso__filename_with_chroot(dso, dso->long_name); + + if (new_name && filename__read_build_id(new_name, &dso->bid) > 0) { + args->have_build_id =3D true; + dso->has_build_id =3D true; } - nsinfo__mountns_exit(&nsc); + free(new_name); } + nsinfo__mountns_exit(&nsc); + return 0; +} =20 - return have_build_id; +bool dsos__read_build_ids(struct dsos *dsos, bool with_hits) +{ + struct dsos__read_build_ids_cb_args args =3D { + .with_hits =3D with_hits, + .have_build_id =3D false, + }; + + dsos__for_each_dso(dsos, dsos__read_build_ids_cb, &args); + return args.have_build_id; } =20 static int __dso__cmp_long_name(const char *long_name, struct dso_id *id, = struct dso *b) @@ -105,6 +132,7 @@ struct dso *__dsos__findnew_link_by_longname_id(struct = rb_root *root, struct dso =20 if (!name) name =3D dso->long_name; + /* * Find node with the matching name */ @@ -185,17 +213,40 @@ static struct dso *__dsos__findnew_by_longname_id(str= uct rb_root *root, const ch return __dsos__findnew_link_by_longname_id(root, NULL, name, id); } =20 +struct dsos__find_id_cb_args { + const char *name; + struct dso_id *id; + struct dso *res; +}; + +static int dsos__find_id_cb(struct dso *dso, void *data) +{ + struct dsos__find_id_cb_args *args =3D data; + + if (__dso__cmp_short_name(args->name, args->id, dso) =3D=3D 0) { + args->res =3D dso__get(dso); + return 1; + } + return 0; + +} + static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, st= ruct dso_id *id, bool cmp_short) { - struct dso *pos; + struct dso *res; =20 if (cmp_short) { - list_for_each_entry(pos, &dsos->head, node) - if (__dso__cmp_short_name(name, id, pos) =3D=3D 0) - return dso__get(pos); - return NULL; + struct dsos__find_id_cb_args args =3D { + .name =3D name, + .id =3D id, + .res =3D NULL, + }; + + __dsos__for_each_dso(dsos, dsos__find_id_cb, &args); + return args.res; } - return __dsos__findnew_by_longname_id(&dsos->root, name, id); + res =3D __dsos__findnew_by_longname_id(&dsos->root, name, id); + return res; } =20 struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short) @@ -275,48 +326,74 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const= char *name, struct dso_id return dso; } =20 -size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, - bool (skip)(struct dso *dso, int parm), int parm) -{ - struct list_head *head =3D &dsos->head; - struct dso *pos; - size_t ret =3D 0; +struct dsos__fprintf_buildid_cb_args { + FILE *fp; + bool (*skip)(struct dso *dso, int parm); + int parm; + size_t ret; +}; =20 - list_for_each_entry(pos, head, node) { - char sbuild_id[SBUILD_ID_SIZE]; +static int dsos__fprintf_buildid_cb(struct dso *dso, void *data) +{ + struct dsos__fprintf_buildid_cb_args *args =3D data; + char sbuild_id[SBUILD_ID_SIZE]; =20 - if (skip && skip(pos, parm)) - continue; - build_id__sprintf(&pos->bid, sbuild_id); - ret +=3D fprintf(fp, "%-40s %s\n", sbuild_id, pos->long_name); - } - return ret; + if (args->skip && args->skip(dso, args->parm)) + return 0; + build_id__sprintf(&dso->bid, sbuild_id); + args->ret +=3D fprintf(args->fp, "%-40s %s\n", sbuild_id, dso->long_name); + return 0; } =20 -size_t __dsos__fprintf(struct dsos *dsos, FILE *fp) +size_t dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, + bool (*skip)(struct dso *dso, int parm), int parm) { - struct list_head *head =3D &dsos->head; - struct dso *pos; - size_t ret =3D 0; + struct dsos__fprintf_buildid_cb_args args =3D { + .fp =3D fp, + .skip =3D skip, + .parm =3D parm, + .ret =3D 0, + }; + + dsos__for_each_dso(dsos, dsos__fprintf_buildid_cb, &args); + return args.ret; +} =20 - list_for_each_entry(pos, head, node) { - ret +=3D dso__fprintf(pos, fp); - } +struct dsos__fprintf_cb_args { + FILE *fp; + size_t ret; +}; =20 - return ret; +static int dsos__fprintf_cb(struct dso *dso, void *data) +{ + struct dsos__fprintf_cb_args *args =3D data; + + args->ret +=3D dso__fprintf(dso, args->fp); + return 0; } =20 -int __dsos__hit_all(struct dsos *dsos) +size_t dsos__fprintf(struct dsos *dsos, FILE *fp) { - struct list_head *head =3D &dsos->head; - struct dso *pos; + struct dsos__fprintf_cb_args args =3D { + .fp =3D fp, + .ret =3D 0, + }; =20 - list_for_each_entry(pos, head, node) - pos->hit =3D true; + dsos__for_each_dso(dsos, dsos__fprintf_cb, &args); + return args.ret; +} =20 +static int dsos__hit_all_cb(struct dso *dso, void *data __maybe_unused) +{ + dso->hit =3D true; return 0; } =20 +int dsos__hit_all(struct dsos *dsos) +{ + return dsos__for_each_dso(dsos, dsos__hit_all_cb, NULL); +} + struct dso *dsos__findnew_module_dso(struct dsos *dsos, struct machine *machine, struct kmod_path *m, @@ -342,49 +419,44 @@ struct dso *dsos__findnew_module_dso(struct dsos *dso= s, return dso; } =20 -struct dso *dsos__find_kernel_dso(struct dsos *dsos) +static int dsos__find_kernel_dso_cb(struct dso *dso, void *data) { - struct dso *dso, *res =3D NULL; + struct dso **res =3D data; + /* + * The cpumode passed to is_kernel_module is not the cpumode of *this* + * event. If we insist on passing correct cpumode to is_kernel_module, + * we should record the cpumode when we adding this dso to the linked + * list. + * + * However we don't really need passing correct cpumode. We know the + * correct cpumode must be kernel mode (if not, we should not link it + * onto kernel_dsos list). + * + * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. + * is_kernel_module() treats it as a kernel cpumode. + */ + if (!dso->kernel || + is_kernel_module(dso->long_name, PERF_RECORD_MISC_CPUMODE_UNKNOWN)) + return 0; =20 - down_read(&dsos->lock); - list_for_each_entry(dso, &dsos->head, node) { - /* - * The cpumode passed to is_kernel_module is not the cpumode of - * *this* event. If we insist on passing correct cpumode to - * is_kernel_module, we should record the cpumode when we adding - * this dso to the linked list. - * - * However we don't really need passing correct cpumode. We - * know the correct cpumode must be kernel mode (if not, we - * should not link it onto kernel_dsos list). - * - * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. - * is_kernel_module() treats it as a kernel cpumode. - */ - if (!dso->kernel || - is_kernel_module(dso->long_name, - PERF_RECORD_MISC_CPUMODE_UNKNOWN)) - continue; + *res =3D dso__get(dso); + return 1; +} =20 - res =3D dso__get(dso); - break; - } - up_read(&dsos->lock); +struct dso *dsos__find_kernel_dso(struct dsos *dsos) +{ + struct dso *res =3D NULL; + + dsos__for_each_dso(dsos, dsos__find_kernel_dso_cb, &res); return res; } =20 int dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void = *data), void *data) { - struct dso *dso; + int err; =20 down_read(&dsos->lock); - list_for_each_entry(dso, &dsos->head, node) { - int err; - - err =3D cb(dso, data); - if (err) - return err; - } + err =3D __dsos__for_each_dso(dsos, cb, data); up_read(&dsos->lock); - return 0; + return err; } diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index 317a263f0e37..50bd51523475 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -33,16 +33,16 @@ struct dso *dsos__find(struct dsos *dsos, const char *n= ame, bool cmp_short); =20 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id); =20 -bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits); +bool dsos__read_build_ids(struct dsos *dsos, bool with_hits); =20 struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, stru= ct dso *dso, const char *name, struct dso_id *id); =20 -size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, +size_t dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm); -size_t __dsos__fprintf(struct dsos *dsos, FILE *fp); +size_t dsos__fprintf(struct dsos *dsos, FILE *fp); =20 -int __dsos__hit_all(struct dsos *dsos); +int dsos__hit_all(struct dsos *dsos); =20 struct dso *dsos__findnew_module_dso(struct dsos *dsos, struct machine *ma= chine, struct kmod_path *m, const char *filename); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index bd153bc2c8da..97a0c21ba2a5 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -853,11 +853,11 @@ static struct map *machine__addnew_module_map(struct = machine *machine, u64 start size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) { struct rb_node *nd; - size_t ret =3D __dsos__fprintf(&machines->host.dsos, fp); + size_t ret =3D dsos__fprintf(&machines->host.dsos, fp); =20 for (nd =3D rb_first_cached(&machines->guests); nd; nd =3D rb_next(nd)) { struct machine *pos =3D rb_entry(nd, struct machine, rb_node); - ret +=3D __dsos__fprintf(&pos->dsos, fp); + ret +=3D dsos__fprintf(&pos->dsos, fp); } =20 return ret; @@ -866,7 +866,7 @@ size_t machines__fprintf_dsos(struct machines *machines= , FILE *fp) size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm) { - return __dsos__fprintf_buildid(&m->dsos, fp, skip, parm); + return dsos__fprintf_buildid(&m->dsos, fp, skip, parm); } =20 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, @@ -3208,5 +3208,5 @@ bool machine__is_lock_function(struct machine *machin= e, u64 addr) =20 int machine__hit_all_dsos(struct machine *machine) { - return __dsos__hit_all(&machine->dsos); + return dsos__hit_all(&machine->dsos); } --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 ACAC912CDBF for ; Thu, 21 Mar 2024 16:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037008; cv=none; b=c/fAHvNOVdhluw6bxi8T/U8IA2JrGMkjuS8/Mmt42gQ+UZHAqn2t+j/38P4ffnmn2g5PVJ0QfkUuwcfyi2WvCtEdnyGx/T2sS7+4Y4ii63UwPsnr2d2r5jR33vuAlccJaOOWCOAxfMumkjKdSz00S2lQt9Z3NACWxC3ssfaVWPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037008; c=relaxed/simple; bh=VwH2EESOD7uIXnGIQeEXhXN0yZm21mEFJikuHXNpphs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OfpZmuyWrw2iSeXfZmCJuzmZUBSZtH1i4YMrvs54lLkUofU6GhZEIyMbqgM0Wj4mtrE5dIge6K4rdlVCNgNzkn2vFBw9rrIakM6KL7yq7lgZoV2L/2i6xMXGQ0CLIjxbK/EF07GQX2h+vK1Kkv/mDXRa+WJ1pj9g9qy4GyYxBTk= 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=IXmkeLd0; arc=none smtp.client-ip=209.85.128.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="IXmkeLd0" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60cd041665bso20532427b3.0 for ; Thu, 21 Mar 2024 09:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037005; x=1711641805; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7M6dlbdCtX29YjQIUfEZskpYw45aSUTFvIbbT68nc+E=; b=IXmkeLd0DaGJ5OiNcdTWhF0Rq2i+sFl1vJUXG0iu9Esb1mKPVv50BI3NwRQDQjY2hN 52sN+wc1r/jRYHguYxaBiFEsI9UDbbcd3Wovp9ukpvsnEblpwM20pZHvTQT7RXU9R8A2 lnHx911opnpjNFeXcKxxM7iSmfNGIVsphYwkt86hMFghGIRDYXQ90BgTH99W8In9UlvQ Dr7Cp/3wH39WeHppvZjk05FRBGygDhzedwiop0uKpIwIgdqxFfrgnnFjlB9PUuKjx0gm D0phSHPA+Rtx43dqzN1i3ksPK6YNGbcLObaelpDiYWrfLlijUf8/AWKZ+BEOUvC1/d2T wPEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037005; x=1711641805; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7M6dlbdCtX29YjQIUfEZskpYw45aSUTFvIbbT68nc+E=; b=QSbfJ3xg5QtZjo2g5K+I/oVIvCooPCvmWZ91dC6JRfimTMX3U5k0vuXF/NG1+QLf+p 7nqz79bivulmW95+c5q/u4gZDh5bZpWODYvru4h4GD3Iax4dyy2VTLUNYpIYOscIWwB8 V83WIPYDE/E7kgF7O/7fNw9ZJ88aXBdDpQkVEAQx2y2kKbouNly53jjCYzbiNYqebAVT 1bGpN+0RRQnx1vH9VIcqyuvLNc9SKv1Bc76IdO6rgqubxcQ4oZJIFojMaBbVoDUB5F+8 fMyycYpsREDFr4j+pbW9K5TlUP9Hj3/fkCVi153/PYmtqnC+45Ye9ELTH2/1TJaoppqD yVcQ== X-Forwarded-Encrypted: i=1; AJvYcCXvVE0g+2OUhJd6khpp+1JsaC18FYZV97UhclFZ8URRXCTbuOvW98EuCNwUgg21t778Xo5OXUOv8nvv9J7xzz95Lxpr/5yBegZtsBti X-Gm-Message-State: AOJu0YymDKXBiFaBg9JGxDWaRXVI7AqKDy+yVAqiqjJCc75igoDVRYKP jUzIS1pMYNXYwg3gsj59Zl4L+8deXOkg9rOAgHUyAlzStM32C5sO/yDlZarYWSRCuch4cBTc02A MBAk87A== X-Google-Smtp-Source: AGHT+IFvVlOYy0rzJBztwM2owLWlaYQ1sufMDDiwhu1yaDG2mBjURJcddRT+4O6dxQREuvnjHo7UYqfZuwU4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:2408:b0:dc2:1f34:fac4 with SMTP id dr8-20020a056902240800b00dc21f34fac4mr5759911ybb.2.1711037005642; Thu, 21 Mar 2024 09:03:25 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:54 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 07/13] perf dsos: Switch backing storage to array from rbtree/list From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DSOs were held on a list for fast iteration and in an rbtree for fast finds. Switch to using a lazily sorted array where iteration is just iterating through the array and binary searches are the same complexity as searching the rbtree. The find may need to sort the array first which does increase the complexity, but add operations have lower complexity and overall the complexity should remain about the same. The set name operations on the dso just records that the array is no longer sorted, avoiding complexity in rebalancing the rbtree. Tighter locking discipline is enforced to avoid the array being resorted while long and short names or ids are changed. The array is smaller in size, replacing 6 pointers with 2, and so even with extra allocated space in the array, the array may be 50% unoccupied, the memory saving should be at least 2x. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dso.c | 67 +++++++++------ tools/perf/util/dso.h | 10 +-- tools/perf/util/dsos.c | 188 ++++++++++++++++++++++++++--------------- tools/perf/util/dsos.h | 21 +++-- 4 files changed, 177 insertions(+), 109 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index ad562743d769..3caca60a6ce3 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1241,35 +1241,35 @@ struct dso *machine__findnew_kernel(struct machine = *machine, const char *name, return dso; } =20 -static void dso__set_long_name_id(struct dso *dso, const char *name, struc= t dso_id *id, bool name_allocated) +static void dso__set_long_name_id(struct dso *dso, const char *name, bool = name_allocated) { - struct rb_root *root =3D dso->root; + struct dsos *dsos =3D dso->dsos; =20 if (name =3D=3D NULL) return; =20 - if (dso->long_name_allocated) - free((char *)dso->long_name); - - if (root) { - rb_erase(&dso->rb_node, root); + if (dsos) { /* - * __dsos__findnew_link_by_longname_id() isn't guaranteed to - * add it back, so a clean removal is required here. + * Need to avoid re-sorting the dsos breaking by non-atomically + * renaming the dso. */ - RB_CLEAR_NODE(&dso->rb_node); - dso->root =3D NULL; + down_write(&dsos->lock); } =20 + if (dso->long_name_allocated) + free((char *)dso->long_name); + dso->long_name =3D name; dso->long_name_len =3D strlen(name); dso->long_name_allocated =3D name_allocated; =20 - if (root) - __dsos__findnew_link_by_longname_id(root, dso, NULL, id); + if (dsos) { + dsos->sorted =3D false; + up_write(&dsos->lock); + } } =20 -static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) +static int __dso_id__cmp(const struct dso_id *a, const struct dso_id *b) { if (a->maj > b->maj) return -1; if (a->maj < b->maj) return 1; @@ -1297,7 +1297,7 @@ static int __dso_id__cmp(struct dso_id *a, struct dso= _id *b) return 0; } =20 -bool dso_id__empty(struct dso_id *id) +bool dso_id__empty(const struct dso_id *id) { if (!id) return true; @@ -1305,15 +1305,22 @@ bool dso_id__empty(struct dso_id *id) return !id->maj && !id->min && !id->ino && !id->ino_generation; } =20 -void dso__inject_id(struct dso *dso, struct dso_id *id) +void __dso__inject_id(struct dso *dso, struct dso_id *id) { + struct dsos *dsos =3D dso->dsos; + + /* dsos write lock held by caller. */ + dso->id.maj =3D id->maj; dso->id.min =3D id->min; dso->id.ino =3D id->ino; dso->id.ino_generation =3D id->ino_generation; + + if (dsos) + dsos->sorted =3D false; } =20 -int dso_id__cmp(struct dso_id *a, struct dso_id *b) +int dso_id__cmp(const struct dso_id *a, const struct dso_id *b) { /* * The second is always dso->id, so zeroes if not set, assume passing @@ -1332,20 +1339,34 @@ int dso__cmp_id(struct dso *a, struct dso *b) =20 void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated) { - dso__set_long_name_id(dso, name, NULL, name_allocated); + dso__set_long_name_id(dso, name, name_allocated); } =20 void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated) { + struct dsos *dsos =3D dso->dsos; + if (name =3D=3D NULL) return; =20 + if (dsos) { + /* + * Need to avoid re-sorting the dsos breaking by non-atomically + * renaming the dso. + */ + down_write(&dsos->lock); + } if (dso->short_name_allocated) free((char *)dso->short_name); =20 dso->short_name =3D name; dso->short_name_len =3D strlen(name); dso->short_name_allocated =3D name_allocated; + + if (dsos) { + dsos->sorted =3D false; + up_write(&dsos->lock); + } } =20 int dso__name_len(const struct dso *dso) @@ -1381,7 +1402,7 @@ struct dso *dso__new_id(const char *name, struct dso_= id *id) strcpy(dso->name, name); if (id) dso->id =3D *id; - dso__set_long_name_id(dso, dso->name, id, false); + dso__set_long_name_id(dso, dso->name, false); dso__set_short_name(dso, dso->name, false); dso->symbols =3D RB_ROOT_CACHED; dso->symbol_names =3D NULL; @@ -1406,9 +1427,6 @@ struct dso *dso__new_id(const char *name, struct dso_= id *id) dso->is_kmod =3D 0; dso->needs_swap =3D DSO_SWAP__UNSET; dso->comp =3D COMP_ID__NONE; - RB_CLEAR_NODE(&dso->rb_node); - dso->root =3D NULL; - INIT_LIST_HEAD(&dso->node); INIT_LIST_HEAD(&dso->data.open_entry); mutex_init(&dso->lock); refcount_set(&dso->refcnt, 1); @@ -1424,9 +1442,8 @@ struct dso *dso__new(const char *name) =20 void dso__delete(struct dso *dso) { - if (!RB_EMPTY_NODE(&dso->rb_node)) - pr_err("DSO %s is still in rbtree when being deleted!\n", - dso->long_name); + if (dso->dsos) + pr_err("DSO %s is still in rbtree when being deleted!\n", dso->long_name= ); =20 /* free inlines first, as they reference symbols */ inlines__tree_delete(&dso->inlined_nodes); diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 2c295438226d..b22dec8b3f3a 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -146,9 +146,7 @@ struct auxtrace_cache; =20 struct dso { struct mutex lock; - struct list_head node; - struct rb_node rb_node; /* rbtree node sorted by long name */ - struct rb_root *root; /* root of rbtree that rb_node is in */ + struct dsos *dsos; struct rb_root_cached symbols; struct symbol **symbol_names; size_t symbol_names_len; @@ -238,8 +236,8 @@ static inline void dso__set_loaded(struct dso *dso) dso->loaded =3D true; } =20 -int dso_id__cmp(struct dso_id *a, struct dso_id *b); -bool dso_id__empty(struct dso_id *id); +int dso_id__cmp(const struct dso_id *a, const struct dso_id *b); +bool dso_id__empty(const struct dso_id *id); =20 struct dso *dso__new_id(const char *name, struct dso_id *id); struct dso *dso__new(const char *name); @@ -248,7 +246,7 @@ void dso__delete(struct dso *dso); int dso__cmp_id(struct dso *a, struct dso *b); void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated); void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated); -void dso__inject_id(struct dso *dso, struct dso_id *id); +void __dso__inject_id(struct dso *dso, struct dso_id *id); =20 int dso__name_len(const struct dso *dso); =20 diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index b7fbfb877ae3..cfc10e1a6802 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -14,24 +14,30 @@ =20 void dsos__init(struct dsos *dsos) { - INIT_LIST_HEAD(&dsos->head); - dsos->root =3D RB_ROOT; init_rwsem(&dsos->lock); + + dsos->cnt =3D 0; + dsos->allocated =3D 0; + dsos->dsos =3D NULL; + dsos->sorted =3D true; } =20 static void dsos__purge(struct dsos *dsos) { - struct dso *pos, *n; - down_write(&dsos->lock); =20 - list_for_each_entry_safe(pos, n, &dsos->head, node) { - RB_CLEAR_NODE(&pos->rb_node); - pos->root =3D NULL; - list_del_init(&pos->node); - dso__put(pos); + for (unsigned int i =3D 0; i < dsos->cnt; i++) { + struct dso *dso =3D dsos->dsos[i]; + + dso__put(dso); + dso->dsos =3D NULL; } =20 + zfree(&dsos->dsos); + dsos->cnt =3D 0; + dsos->allocated =3D 0; + dsos->sorted =3D true; + up_write(&dsos->lock); } =20 @@ -46,9 +52,8 @@ static int __dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void *data), void *data) { - struct dso *dso; - - list_for_each_entry(dso, &dsos->head, node) { + for (unsigned int i =3D 0; i < dsos->cnt; i++) { + struct dso *dso =3D dsos->dsos[i]; int err; =20 err =3D cb(dso, data); @@ -119,16 +124,47 @@ static int dso__cmp_short_name(struct dso *a, struct = dso *b) return __dso__cmp_short_name(a->short_name, &a->id, b); } =20 +static int dsos__cmp_long_name_id_short_name(const void *va, const void *v= b) +{ + const struct dso *a =3D *((const struct dso **)va); + const struct dso *b =3D *((const struct dso **)vb); + int rc =3D strcmp(a->long_name, b->long_name); + + if (!rc) { + rc =3D dso_id__cmp(&a->id, &b->id); + if (!rc) + rc =3D strcmp(a->short_name, b->short_name); + } + return rc; +} + /* * Find a matching entry and/or link current entry to RB tree. * Either one of the dso or name parameter must be non-NULL or the * function will not work. */ -struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, stru= ct dso *dso, - const char *name, struct dso_id *id) +struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos, + struct dso *dso, + const char *name, + struct dso_id *id, + bool write_locked) { - struct rb_node **p =3D &root->rb_node; - struct rb_node *parent =3D NULL; + int low =3D 0, high =3D dsos->cnt - 1; + + if (!dsos->sorted) { + if (!write_locked) { + up_read(&dsos->lock); + down_write(&dsos->lock); + dso =3D __dsos__findnew_link_by_longname_id(dsos, dso, name, id, + /*write_locked=3D*/true); + up_write(&dsos->lock); + down_read(&dsos->lock); + return dso; + } + qsort(dsos->dsos, dsos->cnt, sizeof(struct dso *), + dsos__cmp_long_name_id_short_name); + dsos->sorted =3D true; + } =20 if (!name) name =3D dso->long_name; @@ -136,11 +172,11 @@ struct dso *__dsos__findnew_link_by_longname_id(struc= t rb_root *root, struct dso /* * Find node with the matching name */ - while (*p) { - struct dso *this =3D rb_entry(*p, struct dso, rb_node); + while (low <=3D high) { + int mid =3D (low + high) / 2; + struct dso *this =3D dsos->dsos[mid]; int rc =3D __dso__cmp_long_name(name, id, this); =20 - parent =3D *p; if (rc =3D=3D 0) { /* * In case the new DSO is a duplicate of an existing @@ -161,56 +197,53 @@ struct dso *__dsos__findnew_link_by_longname_id(struc= t rb_root *root, struct dso } } if (rc < 0) - p =3D &parent->rb_left; + high =3D mid - 1; else - p =3D &parent->rb_right; - } - if (dso) { - /* Add new node and rebalance tree */ - rb_link_node(&dso->rb_node, parent, p); - rb_insert_color(&dso->rb_node, root); - dso->root =3D root; + low =3D mid + 1; } + if (dso) + __dsos__add(dsos, dso); return NULL; } =20 -void __dsos__add(struct dsos *dsos, struct dso *dso) +int __dsos__add(struct dsos *dsos, struct dso *dso) { - list_add_tail(&dso->node, &dsos->head); - __dsos__findnew_link_by_longname_id(&dsos->root, dso, NULL, &dso->id); - /* - * It is now in the linked list, grab a reference, then garbage collect - * this when needing memory, by looking at LRU dso instances in the - * list with atomic_read(&dso->refcnt) =3D=3D 1, i.e. no references - * anywhere besides the one for the list, do, under a lock for the - * list: remove it from the list, then a dso__put(), that probably will - * be the last and will then call dso__delete(), end of life. - * - * That, or at the end of the 'struct machine' lifetime, when all - * 'struct dso' instances will be removed from the list, in - * dsos__exit(), if they have no other reference from some other data - * structure. - * - * E.g.: after processing a 'perf.data' file and storing references - * to objects instantiated while processing events, we will have - * references to the 'thread', 'map', 'dso' structs all from 'struct - * hist_entry' instances, but we may not need anything not referenced, - * so we might as well call machines__exit()/machines__delete() and - * garbage collect it. - */ - dso__get(dso); + if (dsos->cnt =3D=3D dsos->allocated) { + unsigned int to_allocate =3D 2; + struct dso **temp; + + if (dsos->allocated > 0) + to_allocate =3D dsos->allocated * 2; + temp =3D realloc(dsos->dsos, sizeof(struct dso *) * to_allocate); + if (!temp) + return -ENOMEM; + dsos->dsos =3D temp; + dsos->allocated =3D to_allocate; + } + dsos->dsos[dsos->cnt++] =3D dso__get(dso); + if (dsos->cnt >=3D 2 && dsos->sorted) { + dsos->sorted =3D dsos__cmp_long_name_id_short_name(&dsos->dsos[dsos->cnt= - 2], + &dsos->dsos[dsos->cnt - 1]) + <=3D 0; + } + dso->dsos =3D dsos; + return 0; } =20 -void dsos__add(struct dsos *dsos, struct dso *dso) +int dsos__add(struct dsos *dsos, struct dso *dso) { + int ret; + down_write(&dsos->lock); - __dsos__add(dsos, dso); + ret =3D __dsos__add(dsos, dso); up_write(&dsos->lock); + return ret; } =20 -static struct dso *__dsos__findnew_by_longname_id(struct rb_root *root, co= nst char *name, struct dso_id *id) +static struct dso *__dsos__findnew_by_longname_id(struct dsos *dsos, const= char *name, + struct dso_id *id, bool write_locked) { - return __dsos__findnew_link_by_longname_id(root, NULL, name, id); + return __dsos__findnew_link_by_longname_id(dsos, NULL, name, id, write_lo= cked); } =20 struct dsos__find_id_cb_args { @@ -231,7 +264,8 @@ static int dsos__find_id_cb(struct dso *dso, void *data) =20 } =20 -static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, st= ruct dso_id *id, bool cmp_short) +static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, st= ruct dso_id *id, + bool cmp_short, bool write_locked) { struct dso *res; =20 @@ -245,7 +279,7 @@ static struct dso *__dsos__find_id(struct dsos *dsos, c= onst char *name, struct d __dsos__for_each_dso(dsos, dsos__find_id_cb, &args); return args.res; } - res =3D __dsos__findnew_by_longname_id(&dsos->root, name, id); + res =3D __dsos__findnew_by_longname_id(dsos, name, id, write_locked); return res; } =20 @@ -254,7 +288,7 @@ struct dso *dsos__find(struct dsos *dsos, const char *n= ame, bool cmp_short) struct dso *res; =20 down_read(&dsos->lock); - res =3D __dsos__find_id(dsos, name, NULL, cmp_short); + res =3D __dsos__find_id(dsos, name, NULL, cmp_short, /*write_locked=3D*/f= alse); up_read(&dsos->lock); return res; } @@ -296,8 +330,13 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos= , const char *name, struct struct dso *dso =3D dso__new_id(name, id); =20 if (dso !=3D NULL) { - __dsos__add(dsos, dso); + /* + * The dsos lock is held on entry, so rename the dso before + * adding it to avoid needing to take the dsos lock again to say + * the array isn't sorted. + */ dso__set_basename(dso); + __dsos__add(dsos, dso); } return dso; } @@ -309,10 +348,10 @@ struct dso *__dsos__addnew(struct dsos *dsos, const c= har *name) =20 static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name,= struct dso_id *id) { - struct dso *dso =3D __dsos__find_id(dsos, name, id, false); + struct dso *dso =3D __dsos__find_id(dsos, name, id, false, /*write_locked= =3D*/true); =20 if (dso && dso_id__empty(&dso->id) && !dso_id__empty(id)) - dso__inject_id(dso, id); + __dso__inject_id(dso, id); =20 return dso ? dso : __dsos__addnew_id(dsos, name, id); } @@ -403,18 +442,27 @@ struct dso *dsos__findnew_module_dso(struct dsos *dso= s, =20 down_write(&dsos->lock); =20 - dso =3D __dsos__find_id(dsos, m->name, NULL, /*cmp_short=3D*/true); + dso =3D __dsos__find_id(dsos, m->name, NULL, /*cmp_short=3D*/true, /*writ= e_locked=3D*/true); + if (dso) { + up_write(&dsos->lock); + return dso; + } + /* + * Failed to find the dso so create it. Change the name before adding it + * to the array, to avoid unnecessary sorts and potential locking + * issues. + */ + dso =3D dso__new_id(m->name, /*id=3D*/NULL); if (!dso) { - dso =3D __dsos__addnew(dsos, m->name); - if (dso =3D=3D NULL) - goto out_unlock; - - dso__set_module_info(dso, m, machine); - dso__set_long_name(dso, strdup(filename), true); - dso->kernel =3D DSO_SPACE__KERNEL; + up_write(&dsos->lock); + return NULL; } + dso__set_basename(dso); + dso__set_module_info(dso, m, machine); + dso__set_long_name(dso, strdup(filename), true); + dso->kernel =3D DSO_SPACE__KERNEL; + __dsos__add(dsos, dso); =20 -out_unlock: up_write(&dsos->lock); return dso; } diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index 50bd51523475..c1b3979ad4bd 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -14,20 +14,22 @@ struct kmod_path; struct machine; =20 /* - * DSOs are put into both a list for fast iteration and rbtree for fast - * long name lookup. + * Collection of DSOs as an array for iteration speed, but sorted for O(n) + * lookup. */ struct dsos { - struct list_head head; - struct rb_root root; /* rbtree root sorted by long name */ struct rw_semaphore lock; + struct dso **dsos; + unsigned int cnt; + unsigned int allocated; + bool sorted; }; =20 void dsos__init(struct dsos *dsos); void dsos__exit(struct dsos *dsos); =20 -void __dsos__add(struct dsos *dsos, struct dso *dso); -void dsos__add(struct dsos *dsos, struct dso *dso); +int __dsos__add(struct dsos *dsos, struct dso *dso); +int dsos__add(struct dsos *dsos, struct dso *dso); struct dso *__dsos__addnew(struct dsos *dsos, const char *name); struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short= ); =20 @@ -35,8 +37,11 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const ch= ar *name, struct dso_id =20 bool dsos__read_build_ids(struct dsos *dsos, bool with_hits); =20 -struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, stru= ct dso *dso, - const char *name, struct dso_id *id); +struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos, + struct dso *dso, + const char *name, + struct dso_id *id, + bool write_locked); =20 size_t dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm); --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 E07E612D1E4 for ; Thu, 21 Mar 2024 16:03:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037010; cv=none; b=M+0238LDXZkDzQjEnvD6oOyIDLHwCHdHE2rv65nK+GUvOXQyRM0SnGeMFZZDYAnePAdkqXyU0308ejqgv/dT7cHCTHDIhEZQzoRttBMyQz4FS8BH2dhu0tc/I+psMEOu3U40H2y+JDNCofz8z2KT0G+newJCrtiuEEvYpLs81TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037010; c=relaxed/simple; bh=9dGUST8fNArFOG69zr0ELlXx+wbNrZRxfaYe9UCGBtM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QLqv21bj5Dv27YgrV/PCzWDKOmJJE353j1lPVqU+0n0oxMT/lI4kyxpHUCH0KoVZVitErfsnP/2CI+5iQBdpJ8CFw+Bko7L7BoHXIamRQzFbjcL+5Lr8MRiuej9s27SjrdgAHiCxExzvE/l+bGTb0xJq63VWji5lyVQOQRF0lrk= 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=37KVxsTy; arc=none smtp.client-ip=209.85.128.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="37KVxsTy" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-608ad239f8fso18208777b3.0 for ; Thu, 21 Mar 2024 09:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037008; x=1711641808; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=vEQ5BBsljQyJP/Rmf1XGwbxQw69MXA9Ie8L3tI9K1qI=; b=37KVxsTyeUADNFUJc/sDeUnAdhtdG3vJ7XadfPwphfMCGwwzkBqjfXmdZ9fGFAvypT UzEejvbTZRgMncyzEFGze3mJLEfluNABvvJjZzmas1EntJrY/eixgixf1H97qvRU4BzY 2FTRjYB+dvns4/nVmnQzcStngFyKh8EaRRvI+T0MNbj5tbuDAPIM5C7pRcRsJWxYtEIv hvpAhoxB5VJucOHf/9P+gwk6QgQf+IXDOtE772edQlSPYken9PFrrZoDh2BwUL+Zg1NS ytTM5H3Iqt0qUXmKMbXmtXmcRebBNlJDU6bqyfsYmSSudQEt4cI0bp0gHSUUEx2/24sp iabQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037008; x=1711641808; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vEQ5BBsljQyJP/Rmf1XGwbxQw69MXA9Ie8L3tI9K1qI=; b=k4xXROkB+krNovAb+SURQk2CDvAiQEMzec9mNfS+NtDOMshraQwmdoNCvil3WiR3lA JlRLPdaloPkDdmDjvVS1ziLOHwoboNbJ7E6gN43nHwzRK7HsJjk/j+A8EXQe9CDVCB0w ZdNrIiZrvRhrQ0pwDIo9tYrjWP23q/iLOT/YTghM2vPW80etVUwuuRmyuOAlRaWvT04L urnshBpDjF2eawYBCP1/hL5kCGtczYgENm9oXjqD6sGC35mhtujeefObAO4dnX6HCgEH cXqtYfa1iZkpLcej5pYfxdkhL8wsbe+VDaCj4QTrih8khIoBsxicCmNQMwULhb4Q6NwE BTGw== X-Forwarded-Encrypted: i=1; AJvYcCWxMha7y+b67x/rcKsqZmYVn/C7HFjDEnff3x9RAVmUOxd906X7szlk5KlbK+7VJaZEWxcKBgmRpET9lZrAcjqQDAuvdsqSXNzGN8OI X-Gm-Message-State: AOJu0YyadQnPcjRfmf59Uy4wFpcwS9uD++g4F5DyJOGPA+NS37EI4OTC 2qxk0jr+Dm/zPglyflrws08OlC6CuErUvaucP1kWhCHwF8MgH7cjYPwdo0Z5qF16VKDENwKOwUW SmVMBEg== X-Google-Smtp-Source: AGHT+IHHuNe2YarMJ2QH01M6jUApwN+PIyvS2BuY1tpPY0Gq4YDWkdVdOSojL0Cyst7T6UGGvz2eBpWLHrfP X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:100e:b0:dc9:5ef8:2b2d with SMTP id w14-20020a056902100e00b00dc95ef82b2dmr5505080ybt.4.1711037007909; Thu, 21 Mar 2024 09:03:27 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:55 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 08/13] perf dsos: Remove __dsos__addnew From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Function no longer used so remove. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dsos.c | 5 ----- tools/perf/util/dsos.h | 1 - 2 files changed, 6 deletions(-) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index cfc10e1a6802..1495ab1cd7a0 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -341,11 +341,6 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos= , const char *name, struct return dso; } =20 -struct dso *__dsos__addnew(struct dsos *dsos, const char *name) -{ - return __dsos__addnew_id(dsos, name, NULL); -} - static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name,= struct dso_id *id) { struct dso *dso =3D __dsos__find_id(dsos, name, id, false, /*write_locked= =3D*/true); diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index c1b3979ad4bd..d1497b11d64c 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -30,7 +30,6 @@ void dsos__exit(struct dsos *dsos); =20 int __dsos__add(struct dsos *dsos, struct dso *dso); int dsos__add(struct dsos *dsos, struct dso *dso); -struct dso *__dsos__addnew(struct dsos *dsos, const char *name); struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short= ); =20 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct d= so_id *id); --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 5546712D20A for ; Thu, 21 Mar 2024 16:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037013; cv=none; b=MWiyHtLik20NvGv9kzFtdK+X+cP7sMMH3K+WZ9JYKmrbH3onDaSgPOCXeBUtSJkRBfr9sFaP/t+sWhU/Zds+9A046ez3BdwtlBL0MAMxvqUKH6kjEU9mwgJl3l1bj9RiBXeBEmhwNHUNARKbhefg0pX2N7E8c0OaGN3qfq9IdSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037013; c=relaxed/simple; bh=3gSnYwZVx0I+sEaou2QDUcUWPJPDhp1y08jtX5P7qHA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Wrf0Bb9nbikiOKlF7RlomhwXTHwlEznyFSldTo0BzOjuL+aDIzI8lFTCKUiKkOh6GzMsax7OQ/VvjBC7uN2kxdq2QOQ7VGaUR3Sk9/OiFElfmZYMm1EWvL4Pd//qhE0frUiAWqHLOvDMR3iPP1vK5TyWkdRd0PzE1EcU5fs/w5M= 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=hi37OlOr; arc=none smtp.client-ip=209.85.219.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="hi37OlOr" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so1317728276.0 for ; Thu, 21 Mar 2024 09:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037010; x=1711641810; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Qb34hunpitkV9KyM24uyeOBHfw4J/ByrLgEYhlQl+E4=; b=hi37OlOrl3pwBswv/NM+alweu+eGceTtlKwTgINUuqSvFwrcMtJrDj5KbycTKVBH+o gacAD3ENeRTurryyutEb7B8PMDEj6P4BFPr96yqn41YWf758PgVujNCI5yw45BTcP+rB 9Be+0ZdNvWbGbJYG8dc+ttpEispqkpj9L0dMEywj6pL2t9LVTn9d4wKqjqgeQc5ALKtv JSmLCCAloaIMw/Ao2X5wqvVuJXg6Hk93TNswKBUThgFSfPDI/ifvoKNBXOdveuFU8Zcx CwY1dybm4PGnSAVjDcLddJ8VQsMxWdqCGqf6LO/JQ0OWiHvRdONsM0KYbtvzAFuUxp4z vGiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037010; x=1711641810; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qb34hunpitkV9KyM24uyeOBHfw4J/ByrLgEYhlQl+E4=; b=hWFpx+8p4QG+sAZF/zqCGcVpLgU5DboThIX9akRn23w1ZAj9PbZfxHZ1ALqUlSiLm7 uRDi/+tMahrn6qdkb6XjRP2vXE/1uMxJyQNkaoYjSgxQ1GUvc+0gsgBY0Rh3Cm39WbY8 Rlwrh9GXqaNNyDY8hRQ1LH8dLPcwT1lv6s7Koe5kOnaIb8WIANO0uTG2oDazBBLouIz3 HlIfsRTMwBwVm1xXoNNbx37DgdiBbVzwmVzblQDmXzx9QZmOs5q5Fu5K0w7ZbubYrk3n DYSfEvXCy/P8RnH/GoeAVFcnFjz85NjUrmnLBQixIcwS9vSwinRFxGa4YCP8VLgU2Czh 1itg== X-Forwarded-Encrypted: i=1; AJvYcCUz7t+Y7NpetN3fKVUli/Yltt9K1naSaj3AJrKKPE7/y5yERNtVq40nuBDmQpu8kei6qF4q8XLYWmcMUpXkECENUrqye9hoisZASTkt X-Gm-Message-State: AOJu0YzLcohQKCAYVsoCCRsmykinAioLnr2g/NuJuKLj4M8iuTLt1GyT YbwF7IqKVxVlndXlwpiIYxn2yT0S0++cWAoApihM4yfbqziQDmVKbFaL+Q87FacZcXQXaB1oOCi eXw30hw== X-Google-Smtp-Source: AGHT+IF1MrvJcngaV2dN8KblCVa0Hc2pz9DnItF9pL5PjnsfTGKaICOkqEoOARvjno1M2zvM00mA2+7MfK2m X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:983:b0:dd9:489d:da74 with SMTP id bv3-20020a056902098300b00dd9489dda74mr335436ybb.13.1711037010253; Thu, 21 Mar 2024 09:03:30 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:56 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 09/13] perf dsos: Remove __dsos__findnew_link_by_longname_id From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Function was only called in dsos.c with the dso parameter as NULL. Remove the function and specialize for the dso being NULL case removing other unused functions along the way. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dsos.c | 51 +++++++++--------------------------------- tools/perf/util/dsos.h | 6 ----- 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index 1495ab1cd7a0..e4110438841b 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -119,11 +119,6 @@ static int __dso__cmp_short_name(const char *short_nam= e, struct dso_id *id, stru return rc ?: dso_id__cmp(id, &b->id); } =20 -static int dso__cmp_short_name(struct dso *a, struct dso *b) -{ - return __dso__cmp_short_name(a->short_name, &a->id, b); -} - static int dsos__cmp_long_name_id_short_name(const void *va, const void *v= b) { const struct dso *a =3D *((const struct dso **)va); @@ -143,20 +138,21 @@ static int dsos__cmp_long_name_id_short_name(const vo= id *va, const void *vb) * Either one of the dso or name parameter must be non-NULL or the * function will not work. */ -struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos, - struct dso *dso, - const char *name, - struct dso_id *id, - bool write_locked) +static struct dso *__dsos__find_by_longname_id(struct dsos *dsos, + const char *name, + struct dso_id *id, + bool write_locked) { int low =3D 0, high =3D dsos->cnt - 1; =20 if (!dsos->sorted) { if (!write_locked) { + struct dso *dso; + up_read(&dsos->lock); down_write(&dsos->lock); - dso =3D __dsos__findnew_link_by_longname_id(dsos, dso, name, id, - /*write_locked=3D*/true); + dso =3D __dsos__find_by_longname_id(dsos, name, id, + /*write_locked=3D*/true); up_write(&dsos->lock); down_read(&dsos->lock); return dso; @@ -166,9 +162,6 @@ struct dso *__dsos__findnew_link_by_longname_id(struct = dsos *dsos, dsos->sorted =3D true; } =20 - if (!name) - name =3D dso->long_name; - /* * Find node with the matching name */ @@ -178,31 +171,13 @@ struct dso *__dsos__findnew_link_by_longname_id(struc= t dsos *dsos, int rc =3D __dso__cmp_long_name(name, id, this); =20 if (rc =3D=3D 0) { - /* - * In case the new DSO is a duplicate of an existing - * one, print a one-time warning & put the new entry - * at the end of the list of duplicates. - */ - if (!dso || (dso =3D=3D this)) - return dso__get(this); /* Find matching dso */ - /* - * The core kernel DSOs may have duplicated long name. - * In this case, the short name should be different. - * Comparing the short names to differentiate the DSOs. - */ - rc =3D dso__cmp_short_name(dso, this); - if (rc =3D=3D 0) { - pr_err("Duplicated dso name: %s\n", name); - return NULL; - } + return dso__get(this); /* Find matching dso */ } if (rc < 0) high =3D mid - 1; else low =3D mid + 1; } - if (dso) - __dsos__add(dsos, dso); return NULL; } =20 @@ -240,12 +215,6 @@ int dsos__add(struct dsos *dsos, struct dso *dso) return ret; } =20 -static struct dso *__dsos__findnew_by_longname_id(struct dsos *dsos, const= char *name, - struct dso_id *id, bool write_locked) -{ - return __dsos__findnew_link_by_longname_id(dsos, NULL, name, id, write_lo= cked); -} - struct dsos__find_id_cb_args { const char *name; struct dso_id *id; @@ -279,7 +248,7 @@ static struct dso *__dsos__find_id(struct dsos *dsos, c= onst char *name, struct d __dsos__for_each_dso(dsos, dsos__find_id_cb, &args); return args.res; } - res =3D __dsos__findnew_by_longname_id(dsos, name, id, write_locked); + res =3D __dsos__find_by_longname_id(dsos, name, id, write_locked); return res; } =20 diff --git a/tools/perf/util/dsos.h b/tools/perf/util/dsos.h index d1497b11d64c..6c13b65648bc 100644 --- a/tools/perf/util/dsos.h +++ b/tools/perf/util/dsos.h @@ -36,12 +36,6 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const ch= ar *name, struct dso_id =20 bool dsos__read_build_ids(struct dsos *dsos, bool with_hits); =20 -struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos, - struct dso *dso, - const char *name, - struct dso_id *id, - bool write_locked); - size_t dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, bool (skip)(struct dso *dso, int parm), int parm); size_t dsos__fprintf(struct dsos *dsos, FILE *fp); --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 D608D12D752 for ; Thu, 21 Mar 2024 16:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037015; cv=none; b=rqdf2R5azPeqEx9c5Gqu6mJaFJE+BZTwsQsw6SrL+oRHvG6U8kgcjVrVQlKMam28O7B2XRjEvof5aEN8jlkqStNLDmgnaiMTeiTMlxAWiQdsryK/NL8aNL30YEuuRfNeU/q42RCGDHOW0GEWgkS9CvzaOIJeEupoIPfXDdwHs98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037015; c=relaxed/simple; bh=FdcVwa6jh1vhtevvSVIZ1eIHhvgiOynPZiHgwCY919Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XIKWXh2qcOCp2RwJcuc0py7OUvBkgoJdDmDXdB+Wk92lP1Jh4C9ykxyRMA8IjA7ccKRn13g/2CiEjm9GHbjheNeZgXezxzZs76+ZdGr45YWRZ8C1yPYb184rOirdGtZAdMcPbn9NOE7IWyYNqKzxBu+vVsJC7LkYT91vXCVZU+k= 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=HeYmSESZ; arc=none smtp.client-ip=209.85.219.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="HeYmSESZ" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc58cddb50so1692207276.0 for ; Thu, 21 Mar 2024 09:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037013; x=1711641813; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=o76ugCV3An0K5fdYO1n9nYRvHF1/7Rh4K9YTwb1u+VI=; b=HeYmSESZn5x3DIPRLeBucraWCq/bgEFJHR0q2EN4n4ZyOefkgs+t67EjNci57gdvc5 VunoEHR/CK5PWNDJP0UknfcdcqJBZ19QaDhtOe1IBzhYHAa/ta2Dp9wVUgeVmbFAEGQB LGfmDzG7ODXQfpYF/GiAPreieJtOAfwGHfHyJDAGXqyxeR3Sbc3bm8IhzZ+/tzKRQrht yqxVqcPYtcElRljCpa0Svli9eee4H+pyU4ayjq317O2krAa1FlwaNhfZTpuIed60Cstn N6TlQS5e3Quw4AiPaV7pCxBt5Ptigynp1zHdi1i5DxmmdxibNNKbLBubULfy7CTFEYBC friQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037013; x=1711641813; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o76ugCV3An0K5fdYO1n9nYRvHF1/7Rh4K9YTwb1u+VI=; b=wvSMfhKLfPqFPSI856m+g1M1rlZqxBtjJYNzCQwnrrKXXhvyJLWACzhcTkPVFQBxTT okr7HpSQ+yTgLdHR9T704//j8s0x2JHMqynTGK+edrQP4U2P6R5kp6magDiwEVjTgH+U UJBgCfQwxxLv/fieb0axoz87j3q0bY1Zr4JsGC4fLn+5xbbs/hqsJSk6H4rYZHO9IDJd Vew9Aj/vxb7H8geevNI8Ee5lJMi6tpr1i5RlOara5KafWQdzCpfTTOb0ll3lylN9N5Kr /R/JHPqQBExXnAZPP4jwkQxlvRIFfmeLdbCsr4zTGK4pHgAkj2LYcjqL3ihlsQ6LmkC8 hHPg== X-Forwarded-Encrypted: i=1; AJvYcCUE521fMS0tl6ixgDXTg/aS2hyx3ZVdQHvRrCaNYZNRBIAlR3i0jRgLGKJji80TlCkbjCo6d2JNB3RjYqDLIHbrBiz6bwUtBhvDGshI X-Gm-Message-State: AOJu0YzaVw8zPh20lAfo/wVqV+ABHQS3F1KLGnGmJ1RpTzT2PJopX2M0 CMSNa2tjDAbsy1o0qKESCd03SeRg6WtHBNOcu3hBKNkauVMokuopOPd3VVRaovRJ2tH33MciSH/ PASe63A== X-Google-Smtp-Source: AGHT+IHcmf0pKTCFxGvZtBxL4QRYeWkGCOD1HrG1KWjoNaorGeWkBU+4FeO4sIGsphZtJGzlmt3DLmDqL+/H X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:18c3:b0:dc6:cafd:dce5 with SMTP id ck3-20020a05690218c300b00dc6cafddce5mr5443997ybb.12.1711037012790; Thu, 21 Mar 2024 09:03:32 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:57 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 10/13] perf dsos: Switch hand code to bsearch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using the bsearch library function rather than having a hand written binary search. Const-ify some static functions to avoid compiler warnings. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/dsos.c | 46 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index e4110438841b..23c3fe4f2abb 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -107,13 +107,15 @@ bool dsos__read_build_ids(struct dsos *dsos, bool wit= h_hits) return args.have_build_id; } =20 -static int __dso__cmp_long_name(const char *long_name, struct dso_id *id, = struct dso *b) +static int __dso__cmp_long_name(const char *long_name, const struct dso_id= *id, + const struct dso *b) { int rc =3D strcmp(long_name, b->long_name); return rc ?: dso_id__cmp(id, &b->id); } =20 -static int __dso__cmp_short_name(const char *short_name, struct dso_id *id= , struct dso *b) +static int __dso__cmp_short_name(const char *short_name, const struct dso_= id *id, + const struct dso *b) { int rc =3D strcmp(short_name, b->short_name); return rc ?: dso_id__cmp(id, &b->id); @@ -133,6 +135,19 @@ static int dsos__cmp_long_name_id_short_name(const voi= d *va, const void *vb) return rc; } =20 +struct dsos__key { + const char *long_name; + const struct dso_id *id; +}; + +static int dsos__cmp_key_long_name_id(const void *vkey, const void *vdso) +{ + const struct dsos__key *key =3D vkey; + const struct dso *dso =3D *((const struct dso **)vdso); + + return __dso__cmp_long_name(key->long_name, key->id, dso); +} + /* * Find a matching entry and/or link current entry to RB tree. * Either one of the dso or name parameter must be non-NULL or the @@ -143,7 +158,11 @@ static struct dso *__dsos__find_by_longname_id(struct = dsos *dsos, struct dso_id *id, bool write_locked) { - int low =3D 0, high =3D dsos->cnt - 1; + struct dsos__key key =3D { + .long_name =3D name, + .id =3D id, + }; + struct dso **res; =20 if (!dsos->sorted) { if (!write_locked) { @@ -162,23 +181,12 @@ static struct dso *__dsos__find_by_longname_id(struct= dsos *dsos, dsos->sorted =3D true; } =20 - /* - * Find node with the matching name - */ - while (low <=3D high) { - int mid =3D (low + high) / 2; - struct dso *this =3D dsos->dsos[mid]; - int rc =3D __dso__cmp_long_name(name, id, this); + res =3D bsearch(&key, dsos->dsos, dsos->cnt, sizeof(struct dso *), + dsos__cmp_key_long_name_id); + if (!res) + return NULL; =20 - if (rc =3D=3D 0) { - return dso__get(this); /* Find matching dso */ - } - if (rc < 0) - high =3D mid - 1; - else - low =3D mid + 1; - } - return NULL; + return dso__get(*res); } =20 int __dsos__add(struct dsos *dsos, struct dso *dso) --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 3439312DD84 for ; Thu, 21 Mar 2024 16:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037024; cv=none; b=hGxm/a7PSnT3H/CzgpiuCHwrCYAxj0nYTDyx/leTyBeIwRGQDEyVtwrqnqu7uwQUST9biY/bcNQ6Ib1cVBXCod+OqzL7aXMvioZQmLR1LLdIhV5YmKpO2/A01Z5vrffTQPWRD6K42GwUsrLE/2ionX26azlg69Qc1ho+LPViiLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037024; c=relaxed/simple; bh=V5OekrwV/HGB+yzq0ntCLGCuYe+yTGZcQhxCahuMbWU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jHhta9tCGfBMdNoIWXtTj3yoiNJtTiLPoRr9XkGIqAfkqkam5oLDIIG/Sw+xnYlu/iF2OV2A3oUDMXLlajSMLdO8p5EF9gnXX8gwX9zdKNfiXUoc8QH8oloLgIttqBqGApU/RVqaYRVLpeCyzD9keJQhubBvHDJdw1TqBGeyy9k= 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=OJtyg/0k; arc=none smtp.client-ip=209.85.128.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="OJtyg/0k" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609f2920b53so17683847b3.0 for ; Thu, 21 Mar 2024 09:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037015; x=1711641815; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fXANvNORShfrlDLwBjLCo0v80u1xy+lyJmjV1yEVQO4=; b=OJtyg/0kx0BFYehUlnc9BTCqOWr4+GwFA6t302nnKgsmmdQhpQu8zQesDKixjWctuC YIbmDSdrUJVlRIFugi7krufoFiVmD0K0IEf5eoqsLGYsriwSWfcXn8MH1RCtI0vcymNL PrFbDMZ2ZA69P6K5Gj0LiZFjmrmLmE/wRybQj+KganKrP/wAmhjeBHUJD/RCszxktpLA RN8ytp5MuiH31gMG/hYCSoCG4X7euwkvT/PJTIVhlrY4aVMQt2Na+t85Ht9L/ysJEsUs Y6ed9zAlwBO9abOYJ+lp/xbId8lAfkb1Vr940D4XAZaBHnF9RRt27zoIyGbvZGU2wPfG qIAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037015; x=1711641815; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fXANvNORShfrlDLwBjLCo0v80u1xy+lyJmjV1yEVQO4=; b=OlWKDa+u7DMeybUUKEzKbCfQeHnyT4KAsxbO4GOoQsx/NNg4eqjOUWyK/F9TNBIPfV H6IniTslUCHzfp1+AkWTVlDp6AyuAi+Z3C3UZGE/H9JD3jcLPFkc88OVVJSka0wx72Le ASAGMNfARxntqOlS1PGDNZx803HJVYCLGNh4hZPmI+8CgdeslV7uNJ5N+BIXvuj+YbED VQFj1uMjybU6/BQmkClP0LfWBz2Rg4aLHt31DxqRIseiht6DH1yBBUhKFHPqGLBmdLC+ jvubt1MX7oTomtGTI8gi//4j+PX1ft2/Aj8ou6xfYbywY7Mxk9LfptmMETTmgkq47vHT 96mA== X-Forwarded-Encrypted: i=1; AJvYcCW4XMbfOFMwM6/UQpzLh9ElFZXnazEulUCD9M4H3m0cAfQ1whNKndw+uq4Enw1e0kySA3cU1DmxIn7dGVjU4Nfp58Qc10UyWgNlGtB0 X-Gm-Message-State: AOJu0YwKLSPbjBNR7SWqQBRBXmJQkRRje1pFRBAKIlUorOGVSoRmknHI zYgNA1BqAdXbI2iWzK9oVvQNBlQEICDzeuKzck+Ty6EqpqMW9BuVht0+azwGwisIOYhPxwkfno9 rrpJQ/g== X-Google-Smtp-Source: AGHT+IFIR2HLaYw9/9Q5jGkTvs7qA1/tkvNJRMqcuZXUoO0N2RpMaVdds0fPVXqF1M1HaH+51QNTPtGWZ7qA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a0d:d9d7:0:b0:60c:9475:f4c6 with SMTP id b206-20020a0dd9d7000000b0060c9475f4c6mr3998309ywe.10.1711037015238; Thu, 21 Mar 2024 09:03:35 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:58 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 11/13] perf dso: Add reference count checking and accessor functions From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add reference count checking to struct dso, this can help with implementing correct reference counting discipline. To avoid RC_CHK_ACCESS everywhere, add accessor functions for the variables in struct dso. The majority of the change is mechanical in nature and not easy to split up. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 8 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 18 +- tools/perf/builtin-inject.c | 71 ++- tools/perf/builtin-kallsyms.c | 2 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 8 +- tools/perf/builtin-top.c | 4 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 8 +- tools/perf/tests/dso-data.c | 11 +- tools/perf/tests/hists_common.c | 6 +- tools/perf/tests/hists_cumulate.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/maps.c | 4 +- tools/perf/tests/symbols.c | 8 +- tools/perf/tests/vmlinux-kallsyms.c | 6 +- tools/perf/ui/browsers/annotate.c | 6 +- tools/perf/ui/browsers/hists.c | 8 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate-data.c | 14 +- tools/perf/util/annotate.c | 47 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/block-info.c | 2 +- tools/perf/util/bpf-event.c | 8 +- tools/perf/util/build-id.c | 38 +- tools/perf/util/callchain.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/db-export.c | 6 +- tools/perf/util/dlfilter.c | 12 +- tools/perf/util/dso.c | 368 +++++++------ tools/perf/util/dso.h | 488 ++++++++++++++++-- tools/perf/util/dsos.c | 54 +- tools/perf/util/event.c | 8 +- tools/perf/util/header.c | 8 +- tools/perf/util/hist.c | 4 +- tools/perf/util/intel-pt.c | 22 +- tools/perf/util/machine.c | 46 +- tools/perf/util/map.c | 77 ++- tools/perf/util/maps.c | 14 +- tools/perf/util/probe-event.c | 25 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 21 +- tools/perf/util/sort.c | 19 +- tools/perf/util/srcline.c | 65 +-- tools/perf/util/symbol-elf.c | 94 ++-- tools/perf/util/symbol-minimal.c | 4 +- tools/perf/util/symbol.c | 186 +++---- tools/perf/util/symbol_fprintf.c | 4 +- tools/perf/util/synthetic-events.c | 24 +- tools/perf/util/thread.c | 4 +- tools/perf/util/unwind-libunwind-local.c | 18 +- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/vdso.c | 8 +- 55 files changed, 1162 insertions(+), 732 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index f677671409b1..889d8172e29f 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -217,7 +217,7 @@ static int process_branch_callback(struct evsel *evsel, } =20 if (a.map !=3D NULL) - map__dso(a.map)->hit =3D 1; + dso__set_hit(map__dso(a.map)); =20 hist__account_cycles(sample->branch_stack, al, sample, false, NULL); =20 @@ -252,7 +252,7 @@ static int evsel__add_sample(struct evsel *evsel, struc= t perf_sample *sample, if (al->sym !=3D NULL) { struct dso *dso =3D map__dso(al->map); =20 - rb_erase_cached(&al->sym->rb_node, &dso->symbols); + rb_erase_cached(&al->sym->rb_node, dso__symbols(dso)); symbol__delete(al->sym); dso__reset_find_symbol_cache(dso); } @@ -341,7 +341,7 @@ static void print_annotated_data_header(struct hist_ent= ry *he, struct evsel *evs } =20 printf("Annotate type: '%s' in %s (%d samples):\n", - he->mem_type->self.type_name, dso->name, nr_samples); + he->mem_type->self.type_name, dso__name(dso), nr_samples); =20 if (evsel__is_group_event(evsel)) { struct evsel *pos; @@ -488,7 +488,7 @@ static void hists__find_annotations(struct hists *hists, struct hist_entry *he =3D rb_entry(nd, struct hist_entry, rb_node); struct annotation *notes; =20 - if (he->ms.sym =3D=3D NULL || map__dso(he->ms.map)->annotate_warned) + if (he->ms.sym =3D=3D NULL || dso__annotate_warned(map__dso(he->ms.map))) goto find_next; =20 if (ann->sym_hist_filter && diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index e2a40f1d9225..b0511d16aeb6 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -286,7 +286,7 @@ static bool dso__missing_buildid_cache(struct dso *dso,= int parm __maybe_unused) =20 pr_warning("Problems with %s file, consider removing it from the cache\n= ", filename); - } else if (memcmp(dso->bid.data, bid.data, bid.size)) { + } else if (memcmp(dso__bid(dso)->data, bid.data, bid.size)) { pr_warning("Problems with %s file, consider removing it from the cache\n= ", filename); } diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid= -list.c index c9037477865a..383d5de36ce4 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c @@ -26,16 +26,18 @@ static int buildid__map_cb(struct map *map, void *arg _= _maybe_unused) { const struct dso *dso =3D map__dso(map); char bid_buf[SBUILD_ID_SIZE]; + const char *dso_long_name =3D dso__long_name(dso); + const char *dso_short_name =3D dso__short_name(dso); =20 memset(bid_buf, 0, sizeof(bid_buf)); - if (dso->has_build_id) - build_id__sprintf(&dso->bid, bid_buf); + if (dso__has_build_id(dso)) + build_id__sprintf(dso__bid_const(dso), bid_buf); printf("%s %16" PRIx64 " %16" PRIx64, bid_buf, map__start(map), map__end(= map)); - if (dso->long_name !=3D NULL) { - printf(" %s", dso->long_name); - } else if (dso->short_name !=3D NULL) { - printf(" %s", dso->short_name); - } + if (dso_long_name !=3D NULL) + printf(" %s", dso_long_name); + else if (dso_short_name !=3D NULL) + printf(" %s", dso_short_name); + printf("\n"); =20 return 0; @@ -76,7 +78,7 @@ static int filename__fprintf_build_id(const char *name, F= ILE *fp) =20 static bool dso__skip_buildid(struct dso *dso, int with_hits) { - return with_hits && !dso->hit; + return with_hits && !dso__hit(dso); } =20 static int perf_session__list_build_ids(bool force, bool with_hits) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index ce5e28eaad90..a212678d47be 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -445,10 +445,9 @@ static struct dso *findnew_dso(int pid, int tid, const= char *filename, } =20 if (dso) { - mutex_lock(&dso->lock); - nsinfo__put(dso->nsinfo); - dso->nsinfo =3D nsi; - mutex_unlock(&dso->lock); + mutex_lock(dso__lock(dso)); + dso__set_nsinfo(dso, nsi); + mutex_unlock(dso__lock(dso)); } else nsinfo__put(nsi); =20 @@ -466,8 +465,8 @@ static int perf_event__repipe_buildid_mmap(struct perf_= tool *tool, dso =3D findnew_dso(event->mmap.pid, event->mmap.tid, event->mmap.filename, NULL, machine); =20 - if (dso && !dso->hit) { - dso->hit =3D 1; + if (dso && !dso__hit(dso)) { + dso__set_hit(dso); dso__inject_build_id(dso, tool, machine, sample->cpumode, 0); } dso__put(dso); @@ -492,7 +491,7 @@ static int perf_event__repipe_mmap2(struct perf_tool *t= ool, event->mmap2.filename, NULL, machine); if (dso) { /* mark it not to inject build-id */ - dso->hit =3D 1; + dso__set_hit(dso); } dso__put(dso); } @@ -544,7 +543,7 @@ static int perf_event__repipe_buildid_mmap2(struct perf= _tool *tool, event->mmap2.filename, NULL, machine); if (dso) { /* mark it not to inject build-id */ - dso->hit =3D 1; + dso__set_hit(dso); } dso__put(dso); perf_event__repipe(tool, event, sample, machine); @@ -554,8 +553,8 @@ static int perf_event__repipe_buildid_mmap2(struct perf= _tool *tool, dso =3D findnew_dso(event->mmap2.pid, event->mmap2.tid, event->mmap2.filename, &dso_id, machine); =20 - if (dso && !dso->hit) { - dso->hit =3D 1; + if (dso && !dso__hit(dso)) { + dso__set_hit(dso); dso__inject_build_id(dso, tool, machine, sample->cpumode, event->mmap2.flags); } @@ -631,24 +630,24 @@ static int dso__read_build_id(struct dso *dso) { struct nscookie nsc; =20 - if (dso->has_build_id) + if (dso__has_build_id(dso)) return 0; =20 - mutex_lock(&dso->lock); - nsinfo__mountns_enter(dso->nsinfo, &nsc); - if (filename__read_build_id(dso->long_name, &dso->bid) > 0) - dso->has_build_id =3D true; - else if (dso->nsinfo) { - char *new_name =3D dso__filename_with_chroot(dso, dso->long_name); + mutex_lock(dso__lock(dso)); + nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); + if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0) + dso__set_has_build_id(dso); + else if (dso__nsinfo(dso)) { + char *new_name =3D dso__filename_with_chroot(dso, dso__long_name(dso)); =20 - if (new_name && filename__read_build_id(new_name, &dso->bid) > 0) - dso->has_build_id =3D true; + if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0) + dso__set_has_build_id(dso); free(new_name); } nsinfo__mountns_exit(&nsc); - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); =20 - return dso->has_build_id ? 0 : -1; + return dso__has_build_id(dso) ? 0 : -1; } =20 static struct strlist *perf_inject__parse_known_build_ids( @@ -700,14 +699,14 @@ static bool perf_inject__lookup_known_build_id(struct= perf_inject *inject, dso_name =3D strchr(build_id, ' '); bid_len =3D dso_name - pos->s; dso_name =3D skip_spaces(dso_name); - if (strcmp(dso->long_name, dso_name)) + if (strcmp(dso__long_name(dso), dso_name)) continue; for (int ix =3D 0; 2 * ix + 1 < bid_len; ++ix) { - dso->bid.data[ix] =3D (hex(build_id[2 * ix]) << 4 | - hex(build_id[2 * ix + 1])); + dso__bid(dso)->data[ix] =3D (hex(build_id[2 * ix]) << 4 | + hex(build_id[2 * ix + 1])); } - dso->bid.size =3D bid_len / 2; - dso->has_build_id =3D 1; + dso__bid(dso)->size =3D bid_len / 2; + dso__set_has_build_id(dso); return true; } return false; @@ -720,9 +719,9 @@ static int dso__inject_build_id(struct dso *dso, struct= perf_tool *tool, tool); int err; =20 - if (is_anon_memory(dso->long_name) || flags & MAP_HUGETLB) + if (is_anon_memory(dso__long_name(dso)) || flags & MAP_HUGETLB) return 0; - if (is_no_dso_memory(dso->long_name)) + if (is_no_dso_memory(dso__long_name(dso))) return 0; =20 if (inject->known_build_ids !=3D NULL && @@ -730,14 +729,14 @@ static int dso__inject_build_id(struct dso *dso, stru= ct perf_tool *tool, return 1; =20 if (dso__read_build_id(dso) < 0) { - pr_debug("no build_id found for %s\n", dso->long_name); + pr_debug("no build_id found for %s\n", dso__long_name(dso)); return -1; } =20 err =3D perf_event__synthesize_build_id(tool, dso, cpumode, perf_event__repipe, machine); if (err) { - pr_err("Can't synthesize build_id event for %s\n", dso->long_name); + pr_err("Can't synthesize build_id event for %s\n", dso__long_name(dso)); return -1; } =20 @@ -763,8 +762,8 @@ int perf_event__inject_buildid(struct perf_tool *tool, = union perf_event *event, if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { struct dso *dso =3D map__dso(al.map); =20 - if (!dso->hit) { - dso->hit =3D 1; + if (!dso__hit(dso)) { + dso__set_hit(dso); dso__inject_build_id(dso, tool, machine, sample->cpumode, map__flags(al.map)); } @@ -1146,8 +1145,8 @@ static bool dso__is_in_kernel_space(struct dso *dso) return false; =20 return dso__is_kcore(dso) || - dso->kernel || - is_kernel_module(dso->long_name, PERF_RECORD_MISC_CPUMODE_UNKNOWN); + dso__kernel(dso) || + is_kernel_module(dso__long_name(dso), PERF_RECORD_MISC_CPUMODE_UNK= NOWN); } =20 static u64 evlist__first_id(struct evlist *evlist) @@ -1181,7 +1180,7 @@ static int synthesize_build_id(struct perf_inject *in= ject, struct dso *dso, pid_ if (!machine) return -ENOMEM; =20 - dso->hit =3D 1; + dso__set_hit(dso); =20 return perf_event__synthesize_build_id(&inject->tool, dso, cpumode, process_build_id, machine); @@ -1192,7 +1191,7 @@ static int guest_session__add_build_ids_cb(struct dso= *dso, void *data) struct guest_session *gs =3D data; struct perf_inject *inject =3D container_of(gs, struct perf_inject, guest= _session); =20 - if (!dso->has_build_id) + if (!dso__has_build_id(dso)) return 0; =20 return synthesize_build_id(inject, dso, gs->machine_pid); diff --git a/tools/perf/builtin-kallsyms.c b/tools/perf/builtin-kallsyms.c index 7f75c5b73f26..a3c2ffdc1af8 100644 --- a/tools/perf/builtin-kallsyms.c +++ b/tools/perf/builtin-kallsyms.c @@ -38,7 +38,7 @@ static int __cmd_kallsyms(int argc, const char **argv) =20 dso =3D map__dso(map); printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n= ", - symbol->name, dso->short_name, dso->long_name, + symbol->name, dso__short_name(dso), dso__long_name(dso), map__unmap_ip(map, symbol->start), map__unmap_ip(map, symbol->end), symbol->start, symbol->end); } diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 5b851e64e4a1..863fcd735dae 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -213,7 +213,7 @@ dump_raw_samples(struct perf_tool *tool, if (al.map !=3D NULL) { dso =3D map__dso(al.map); if (dso) - dso->hit =3D 1; + dso__set_hit(dso); } =20 field_sep =3D symbol_conf.field_sep; @@ -255,7 +255,7 @@ dump_raw_samples(struct perf_tool *tool, symbol_conf.field_sep, sample->data_src, symbol_conf.field_sep, - dso ? dso->long_name : "???", + dso ? dso__long_name(dso) : "???", al.sym ? al.sym->name : "???"); out_put: addr_location__exit(&al); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index dcd93ee5fc24..16a925a3e2e7 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -322,7 +322,7 @@ static int process_sample_event(struct perf_tool *tool, } =20 if (al.map !=3D NULL) - map__dso(al.map)->hit =3D 1; + dso__set_hit(map__dso(al.map)); =20 if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample, @@ -609,7 +609,7 @@ static void report__warn_kptr_restrict(const struct rep= ort *rep) return; =20 if (kernel_map =3D=3D NULL || - (map__dso(kernel_map)->hit && + (dso__hit(map__dso(kernel_map)) && (kernel_kmap->ref_reloc_sym =3D=3D NULL || kernel_kmap->ref_reloc_sym->addr =3D=3D 0))) { const char *desc =3D @@ -850,7 +850,7 @@ static int maps__fprintf_task_cb(struct map *map, void = *data) prot & PROT_EXEC ? 'x' : '-', map__flags(map) ? 's' : 'p', map__pgoff(map), - dso->id.ino, dso->name); + dso__id_const(dso)->ino, dso__name(dso)); =20 if (ret < 0) return ret; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 2e7148d667bd..f60a7567da1e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1014,11 +1014,11 @@ static int perf_sample__fprintf_brstackoff(struct p= erf_sample *sample, to =3D entries[i].to; =20 if (thread__find_map_fb(thread, sample->cpumode, from, &alf) && - !map__dso(alf.map)->adjust_symbols) + !dso__adjust_symbols(map__dso(alf.map))) from =3D map__dso_map_ip(alf.map, from); =20 if (thread__find_map_fb(thread, sample->cpumode, to, &alt) && - !map__dso(alt.map)->adjust_symbols) + !dso__adjust_symbols(map__dso(alt.map))) to =3D map__dso_map_ip(alt.map, to); =20 printed +=3D fprintf(fp, " 0x%"PRIx64, from); @@ -1079,7 +1079,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end, pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); goto out; } - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR) { + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR) { pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); goto out; } @@ -1091,7 +1091,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end, len =3D dso__data_read_offset(dso, machine, offset, (u8 *)buffer, end - start + MAXINSN); =20 - *is64bit =3D dso->is_64_bit; + *is64bit =3D dso__is_64_bit(dso); if (len <=3D 0) pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n", start, end); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 5ac6dcc64cef..1d6aef51c122 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -129,7 +129,7 @@ static int perf_top__parse_source(struct perf_top *top,= struct hist_entry *he) /* * We can't annotate with just /proc/kallsyms */ - if (dso->symtab_type =3D=3D DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(d= so)) { + if (dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__KALLSYMS && !dso__is_kc= ore(dso)) { pr_err("Can't annotate %s: No vmlinux file was found in the " "path\n", sym->name); sleep(1); @@ -182,7 +182,7 @@ static void ui__warn_map_erange(struct map *map, struct= symbol *sym, u64 ip) "Tools: %s\n\n" "Not all samples will be on the annotation output.\n\n" "Please report to linux-kernel@vger.kernel.org\n", - ip, dso->long_name, dso__symtab_origin(dso), + ip, dso__long_name(dso), dso__symtab_origin(dso), map__start(map), map__end(map), sym->start, sym->end, sym->binding =3D=3D STB_GLOBAL ? 'g' : sym->binding =3D=3D STB_LOCAL ? 'l' : 'w', sym->name, diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index d3ec244e692a..70cbe153b9dc 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2917,7 +2917,7 @@ static void print_location(FILE *f, struct perf_sampl= e *sample, { =20 if ((verbose > 0 || print_dso) && al->map) - fprintf(f, "%s@", map__dso(al->map)->long_name); + fprintf(f, "%s@", dso__long_name(map__dso(al->map))); =20 if ((verbose > 0 || print_sym) && al->sym) fprintf(f, "%s+0x%" PRIx64, al->sym->name, diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-readin= g.c index 7a3a7bbbec71..6208f58622d1 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -253,9 +253,9 @@ static int read_object_code(u64 addr, size_t len, u8 cp= umode, goto out; } dso =3D map__dso(al.map); - pr_debug("File is: %s\n", dso->long_name); + pr_debug("File is: %s\n", dso__long_name(dso)); =20 - if (dso->symtab_type =3D=3D DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(d= so)) { + if (dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__KALLSYMS && !dso__is_kc= ore(dso)) { pr_debug("Unexpected kernel address - skipping\n"); goto out; } @@ -274,7 +274,7 @@ static int read_object_code(u64 addr, size_t len, u8 cp= umode, * modules to manage long jumps. Check if the ip offset falls in stubs * sections for kernel modules. And skip module address after text end */ - if (dso->is_kmod && al.addr > dso->text_end) { + if (dso__is_kmod(dso) && al.addr > dso__text_end(dso)) { pr_debug("skipping the module address %#"PRIx64" after text end\n", al.a= ddr); goto out; } @@ -315,7 +315,7 @@ static int read_object_code(u64 addr, size_t len, u8 cp= umode, state->done[state->done_cnt++] =3D map__start(al.map); } =20 - objdump_name =3D dso->long_name; + objdump_name =3D dso__long_name(dso); if (dso__needs_decompress(dso)) { if (dso__decompress_kmodule_path(dso, objdump_name, decomp_name, diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index 2d67422c1222..fde4eca84b6f 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c @@ -228,7 +228,8 @@ static void dsos__delete(int cnt) for (i =3D 0; i < cnt; i++) { struct dso *dso =3D dsos[i]; =20 - unlink(dso->name); + dso__data_close(dso); + unlink(dso__name(dso)); dso__put(dso); } =20 @@ -289,14 +290,14 @@ static int test__dso_data_cache(struct test_suite *te= st __maybe_unused, int subt } =20 /* verify the first one is already open */ - TEST_ASSERT_VAL("dsos[0] is not open", dsos[0]->data.fd !=3D -1); + TEST_ASSERT_VAL("dsos[0] is not open", dso__data(dsos[0])->fd !=3D -1); =20 /* open +1 dso to reach the allowed limit */ fd =3D dso__data_fd(dsos[i], &machine); TEST_ASSERT_VAL("failed to get fd", fd > 0); =20 /* should force the first one to be closed */ - TEST_ASSERT_VAL("failed to close dsos[0]", dsos[0]->data.fd =3D=3D -1); + TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(dsos[0])->fd =3D=3D = -1); =20 /* cleanup everything */ dsos__delete(dso_cnt); @@ -371,7 +372,7 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub * dso_0 should get closed, because we reached * the file descriptor limit */ - TEST_ASSERT_VAL("failed to close dso_0", dso_0->data.fd =3D=3D -1); + TEST_ASSERT_VAL("failed to close dso_0", dso__data(dso_0)->fd =3D=3D -1); =20 /* open dso_0 */ fd =3D dso__data_fd(dso_0, &machine); @@ -381,7 +382,7 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub * dso_1 should get closed, because we reached * the file descriptor limit */ - TEST_ASSERT_VAL("failed to close dso_1", dso_1->data.fd =3D=3D -1); + TEST_ASSERT_VAL("failed to close dso_1", dso__data(dso_1)->fd =3D=3D -1); =20 /* cleanup everything */ close(fd_extra); diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_commo= n.c index d08add0f4da6..187f12f5bc21 100644 --- a/tools/perf/tests/hists_common.c +++ b/tools/perf/tests/hists_common.c @@ -146,7 +146,7 @@ struct machine *setup_fake_machine(struct machines *mac= hines) goto out; } =20 - symbols__insert(&dso->symbols, sym); + symbols__insert(dso__symbols(dso), sym); } =20 dso__put(dso); @@ -183,7 +183,7 @@ void print_hists_in(struct hists *hists) =20 pr_info("%2d: entry: %-8s [%-8s] %20s: period =3D %"PRIu64"\n", i, thread__comm_str(he->thread), - dso->short_name, + dso__short_name(dso), he->ms.sym->name, he->stat.period); } =20 @@ -212,7 +212,7 @@ void print_hists_out(struct hists *hists) =20 pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period =3D %"PRIu64"/%"PRIu64= "\n", i, thread__comm_str(he->thread), thread__tid(he->thread), - dso->short_name, + dso__short_name(dso), he->ms.sym->name, he->stat.period, he->stat_acc ? he->stat_acc->period : 0); } diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cum= ulate.c index 71dacb0fec4d..1e0f5a310fd5 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -164,11 +164,11 @@ static void put_fake_samples(void) typedef int (*test_fn_t)(struct evsel *, struct machine *); =20 #define COMM(he) (thread__comm_str(he->thread)) -#define DSO(he) (map__dso(he->ms.map)->short_name) +#define DSO(he) (dso__short_name(map__dso(he->ms.map))) #define SYM(he) (he->ms.sym->name) #define CPU(he) (he->cpu) #define DEPTH(he) (he->callchain->max_depth) -#define CDSO(cl) (map__dso(cl->ms.map)->short_name) +#define CDSO(cl) (dso__short_name(map__dso(cl->ms.map))) #define CSYM(cl) (cl->ms.sym->name) =20 struct result { diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_outpu= t.c index ba1cccf57049..33b5cc8352a7 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -129,7 +129,7 @@ static void put_fake_samples(void) typedef int (*test_fn_t)(struct evsel *, struct machine *); =20 #define COMM(he) (thread__comm_str(he->thread)) -#define DSO(he) (map__dso(he->ms.map)->short_name) +#define DSO(he) (dso__short_name(map__dso(he->ms.map))) #define SYM(he) (he->ms.sym->name) #define CPU(he) (he->cpu) #define PID(he) (thread__tid(he->thread)) diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c index b15417a0d617..4f1f9385ea9c 100644 --- a/tools/perf/tests/maps.c +++ b/tools/perf/tests/maps.c @@ -26,7 +26,7 @@ static int check_maps_cb(struct map *map, void *data) =20 if (map__start(map) !=3D merged->start || map__end(map) !=3D merged->end || - strcmp(map__dso(map)->name, merged->name) || + strcmp(dso__name(map__dso(map)), merged->name) || refcount_read(map__refcnt(map)) !=3D 1) { return 1; } @@ -39,7 +39,7 @@ static int failed_cb(struct map *map, void *data __maybe_= unused) pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n", map__start(map), map__end(map), - map__dso(map)->name, + dso__name(map__dso(map)), refcount_read(map__refcnt(map))); =20 return 0; diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c index d208105919ed..ee20a366f32f 100644 --- a/tools/perf/tests/symbols.c +++ b/tools/perf/tests/symbols.c @@ -81,7 +81,7 @@ static int create_map(struct test_info *ti, char *filenam= e, struct map **map_p) * If 'filename' matches a current kernel module, must use a kernel * map. Find the one that already exists. */ - if (dso && dso->kernel) { + if (dso && dso__kernel(dso) !=3D DSO_SPACE__USER) { *map_p =3D find_module_map(ti->machine, dso); dso__put(dso); if (!*map_p) { @@ -116,7 +116,7 @@ static int test_dso(struct dso *dso) if (verbose > 1) dso__fprintf(dso, stderr); =20 - for (nd =3D rb_first_cached(&dso->symbols); nd; nd =3D rb_next(nd)) { + for (nd =3D rb_first_cached(dso__symbols(dso)); nd; nd =3D rb_next(nd)) { struct symbol *sym =3D rb_entry(nd, struct symbol, rb_node); =20 if (sym->type !=3D STT_FUNC && sym->type !=3D STT_GNU_IFUNC) @@ -145,7 +145,7 @@ static int subdivided_dso_cb(struct dso *dso, struct ma= chine *machine __maybe_un { struct dso *text_dso =3D d; =20 - if (dso !=3D text_dso && strstarts(dso->short_name, text_dso->short_name)) + if (dso !=3D text_dso && strstarts(dso__short_name(dso), dso__short_name(= text_dso))) if (test_dso(dso) !=3D TEST_OK) return -1; =20 @@ -190,7 +190,7 @@ static int test_file(struct test_info *ti, char *filena= me) ret =3D test_dso(dso); =20 /* Module dso is split into many dsos by section */ - if (ret =3D=3D TEST_OK && dso->kernel) + if (ret =3D=3D TEST_OK && dso__kernel(dso) !=3D DSO_SPACE__USER) ret =3D process_subdivided_dso(ti->machine, dso); out_put: map__put(map); diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux= -kallsyms.c index fecbf851bb2e..e30fd55f8e51 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -129,7 +129,7 @@ static int test__vmlinux_matches_kallsyms_cb1(struct ma= p *map, void *data) * cases. */ struct map *pair =3D maps__find_by_name(args->kallsyms.kmaps, - (dso->kernel ? dso->short_name : dso->name)); + (dso__kernel(dso) ? dso__short_name(dso) : dso__name(dso))); =20 if (pair) { map__set_priv(pair, 1); @@ -162,11 +162,11 @@ static int test__vmlinux_matches_kallsyms_cb2(struct = map *map, void *data) } =20 pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as", - map__start(map), map__end(map), map__pgoff(map), dso->name); + map__start(map), map__end(map), map__pgoff(map), dso__name(dso)); if (mem_end !=3D map__end(pair)) pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64, map__start(pair), map__end(pair), map__pgoff(pair)); - pr_info(" %s\n", dso->name); + pr_info(" %s\n", dso__name(dso)); map__set_priv(pair, 1); } map__put(pair); diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index ec5e21932876..c0fb4888f092 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -438,7 +438,7 @@ static int sym_title(struct symbol *sym, struct map *ma= p, char *title, size_t sz, int percent_type) { return snprintf(title, sz, "%s %s [Percent: %s]", sym->name, - map__dso(map)->long_name, + dso__long_name(map__dso(map)), percent_type_str(percent_type)); } =20 @@ -967,14 +967,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struc= t evsel *evsel, return -1; =20 dso =3D map__dso(ms->map); - if (dso->annotate_warned) + if (dso__annotate_warned(dso)) return -1; =20 if (not_annotated) { err =3D symbol__annotate2(ms, evsel, &browser.arch); if (err) { char msg[BUFSIZ]; - dso->annotate_warned =3D true; + dso__set_annotate_warned(dso); symbol__strerror_disassemble(ms, err, msg, sizeof(msg)); ui__error("Couldn't annotate %s:\n%s", sym->name, msg); goto out_free_offsets; diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 0c02b3a8e121..2b32c5da47c9 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2488,7 +2488,7 @@ add_annotate_opt(struct hist_browser *browser __maybe= _unused, { struct dso *dso; =20 - if (!ms->map || (dso =3D map__dso(ms->map)) =3D=3D NULL || dso->annotate_= warned) + if (!ms->map || (dso =3D map__dso(ms->map)) =3D=3D NULL || dso__annotate_= warned(dso)) return 0; =20 if (!ms->sym) @@ -2581,7 +2581,7 @@ static int hists_browser__zoom_map(struct hist_browse= r *browser, struct map *map } else { struct dso *dso =3D map__dso(map); ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DS= O\"", - __map__is_kernel(map) ? "the Kernel" : dso->short_name); + __map__is_kernel(map) ? "the Kernel" : dso__short_name(dso)); browser->hists->dso_filter =3D dso; perf_hpp__set_elide(HISTC_DSO, true); pstack__push(browser->pstack, &browser->hists->dso_filter); @@ -2607,7 +2607,7 @@ add_dso_opt(struct hist_browser *browser, struct popu= p_action *act, =20 if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly= into the kernel)", browser->hists->dso_filter ? "out of" : "into", - __map__is_kernel(map) ? "the Kernel" : map__dso(map)->short_name) <= 0) + __map__is_kernel(map) ? "the Kernel" : dso__short_name(map__dso(map= ))) < 0) return 0; =20 act->ms.map =3D map; @@ -3083,7 +3083,7 @@ static int evsel__hists_browse(struct evsel *evsel, i= nt nr_events, const char *h if (!browser->selection || !browser->selection->map || !map__dso(browser->selection->map) || - map__dso(browser->selection->map)->annotate_warned) { + dso__annotate_warned(map__dso(browser->selection->map))) { continue; } =20 diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c index 3d1b958d8832..fba55175a935 100644 --- a/tools/perf/ui/browsers/map.c +++ b/tools/perf/ui/browsers/map.c @@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser) { int key; =20 - if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name, + if (ui_browser__show(&browser->b, dso__long_name(map__dso(browser->map)), "Press ESC to exit, %s / to search", verbose > 0 ? "" : "restart with -v to use") < 0) return -1; @@ -106,7 +106,7 @@ int map__browse(struct map *map) { struct map_browser mb =3D { .b =3D { - .entries =3D &map__dso(map)->symbols, + .entries =3D dso__symbols(map__dso(map)), .refresh =3D ui_browser__rb_tree_refresh, .seek =3D ui_browser__rb_tree_seek, .write =3D map_browser__write, diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 043d80791bd0..bb21947f38c7 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -275,7 +275,7 @@ static struct annotated_data_type *dso__findnew_data_ty= pe(struct dso *dso, /* Check existing nodes in dso->data_types tree */ key.self.type_name =3D type_name; key.self.size =3D size; - node =3D rb_find(&key, &dso->data_types, data_type_cmp); + node =3D rb_find(&key, dso__data_types(dso), data_type_cmp); if (node) { result =3D rb_entry(node, struct annotated_data_type, node); free(type_name); @@ -296,7 +296,7 @@ static struct annotated_data_type *dso__findnew_data_ty= pe(struct dso *dso, if (symbol_conf.annotate_data_member) add_member_types(result, type_die); =20 - rb_add(&result->node, &dso->data_types, data_type_less); + rb_add(&result->node, dso__data_types(dso), data_type_less); return result; } =20 @@ -469,7 +469,7 @@ static struct global_var_entry *global_var__find(struct= data_loc_info *dloc, u64 struct dso *dso =3D map__dso(dloc->ms->map); struct rb_node *node; =20 - node =3D rb_find((void *)(uintptr_t)addr, &dso->global_vars, global_var_c= mp); + node =3D rb_find((void *)(uintptr_t)addr, dso__global_vars(dso), global_v= ar_cmp); if (node =3D=3D NULL) return NULL; =20 @@ -500,7 +500,7 @@ static bool global_var__add(struct data_loc_info *dloc,= u64 addr, gvar->end =3D addr + size; gvar->die_offset =3D dwarf_dieoffset(type_die); =20 - rb_add(&gvar->node, &dso->global_vars, global_var_less); + rb_add(&gvar->node, dso__global_vars(dso), global_var_less); return true; } =20 @@ -768,7 +768,7 @@ static void update_insn_state_x86(struct type_state *st= ate, return; =20 tsr =3D &state->regs[dst->reg1]; - if (map__dso(dloc->ms->map)->kernel && + if (dso__kernel(map__dso(dloc->ms->map)) && src->segment =3D=3D INSN_SEG_X86_GS && src->imm) { u64 ip =3D dloc->ms->sym->start + dl->al.offset; u64 var_addr; @@ -1255,7 +1255,7 @@ static int check_matching_type(struct type_state *sta= te, return -1; } =20 - if (map__dso(dloc->ms->map)->kernel && arch__is(dloc->arch, "x86")) { + if (dso__kernel(map__dso(dloc->ms->map)) && arch__is(dloc->arch, "x86")) { u64 addr; int offset; =20 @@ -1585,7 +1585,7 @@ struct annotated_data_type *find_data_type(struct dat= a_loc_info *dloc) struct dso *dso =3D map__dso(dloc->ms->map); Dwarf_Die type_die; =20 - dloc->di =3D debuginfo__new(dso->long_name); + dloc->di =3D debuginfo__new(dso__long_name(dso)); if (dloc->di =3D=3D NULL) { pr_debug_dtp("cannot get the debug info\n"); return NULL; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 64e54ff1aa1d..dff346f95a40 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1815,8 +1815,8 @@ int symbol__strerror_disassemble(struct map_symbol *m= s, int errnum, char *buf, s char bf[SBUILD_ID_SIZE + 15] =3D " with build id "; char *build_id_msg =3D NULL; =20 - if (dso->has_build_id) { - build_id__sprintf(&dso->bid, bf + 15); + if (dso__has_build_id(dso)) { + build_id__sprintf(dso__bid(dso), bf + 15); build_id_msg =3D bf; } scnprintf(buf, buflen, @@ -1838,11 +1838,11 @@ int symbol__strerror_disassemble(struct map_symbol = *ms, int errnum, char *buf, s scnprintf(buf, buflen, "Problems while parsing the CPUID in the arch spe= cific initialization."); break; case SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE: - scnprintf(buf, buflen, "Invalid BPF file: %s.", dso->long_name); + scnprintf(buf, buflen, "Invalid BPF file: %s.", dso__long_name(dso)); break; case SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF: scnprintf(buf, buflen, "The %s BPF file has no BTF section, compile with= -g or use pahole -J.", - dso->long_name); + dso__long_name(dso)); break; default: scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum= ); @@ -1860,7 +1860,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil char *pos; int len; =20 - if (dso->symtab_type =3D=3D DSO_BINARY_TYPE__KALLSYMS && + if (dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; =20 @@ -1869,7 +1869,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil __symbol__join_symfs(filename, filename_size, build_id_filename); free(build_id_filename); } else { - if (dso->has_build_id) + if (dso__has_build_id(dso)) return ENOMEM; goto fallback; } @@ -1903,20 +1903,20 @@ static int dso__disassemble_filename(struct dso *ds= o, char *filename, size_t fil * cache, or is just a kallsyms file, well, lets hope that this * DSO is the same as when 'perf record' ran. */ - if (dso->kernel && dso->long_name[0] =3D=3D '/') - snprintf(filename, filename_size, "%s", dso->long_name); + if (dso__kernel(dso) && dso__long_name(dso)[0] =3D=3D '/') + snprintf(filename, filename_size, "%s", dso__long_name(dso)); else - __symbol__join_symfs(filename, filename_size, dso->long_name); + __symbol__join_symfs(filename, filename_size, dso__long_name(dso)); =20 - mutex_lock(&dso->lock); - if (access(filename, R_OK) && errno =3D=3D ENOENT && dso->nsinfo) { + mutex_lock(dso__lock(dso)); + if (access(filename, R_OK) && errno =3D=3D ENOENT && dso__nsinfo(dso)) { char *new_name =3D dso__filename_with_chroot(dso, filename); if (new_name) { strlcpy(filename, new_name, filename_size); free(new_name); } } - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); } =20 free(build_id_path); @@ -2202,11 +2202,11 @@ static int symbol__disassemble(struct symbol *sym, = struct annotate_args *args) map__unmap_ip(map, sym->end)); =20 pr_debug("annotating [%p] %30s : [%p] %30s\n", - dso, dso->long_name, sym, sym->name); + dso, dso__long_name(dso), sym, sym->name); =20 - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) { + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) { return symbol__disassemble_bpf(sym, args); - } else if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_IMAGE) { + } else if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_IMAGE) { return symbol__disassemble_bpf_image(sym, args); } else if (dso__is_kcore(dso)) { kce.kcore_filename =3D symfs_filename; @@ -2657,7 +2657,7 @@ int symbol__annotate_printf(struct map_symbol *ms, st= ruct evsel *evsel) int graph_dotted_len; char buf[512]; =20 - filename =3D strdup(dso->long_name); + filename =3D strdup(dso__long_name(dso)); if (!filename) return -ENOMEM; =20 @@ -2822,7 +2822,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms= , struct evsel *evsel) } =20 fprintf(fp, "%s() %s\nEvent: %s\n\n", - ms->sym->name, map__dso(ms->map)->long_name, ev_name); + ms->sym->name, dso__long_name(map__dso(ms->map)), ev_name); symbol__annotate_fprintf2(ms->sym, fp); =20 fclose(fp); @@ -3082,7 +3082,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, stru= ct evsel *evsel) if (err) { char msg[BUFSIZ]; =20 - dso->annotate_warned =3D true; + dso__set_annotate_warned(dso); symbol__strerror_disassemble(ms, err, msg, sizeof(msg)); ui__error("Couldn't annotate %s:\n%s", sym->name, msg); return -1; @@ -3091,13 +3091,12 @@ int symbol__tty_annotate2(struct map_symbol *ms, st= ruct evsel *evsel) if (annotate_opts.print_lines) { srcline_full_filename =3D annotate_opts.full_path; symbol__calc_lines(ms, &source_line); - print_summary(&source_line, dso->long_name); + print_summary(&source_line, dso__long_name(dso)); } =20 hists__scnprintf_title(hists, buf, sizeof(buf)); fprintf(stdout, "%s, [percent: %s]\n%s() %s\n", - buf, percent_type_str(annotate_opts.percent_type), sym->name, - dso->long_name); + buf, percent_type_str(annotate_opts.percent_type), sym->name, dso__long_= name(dso)); symbol__annotate_fprintf2(sym, stdout); =20 annotated_source__purge(symbol__annotation(sym)->src); @@ -3116,7 +3115,7 @@ int symbol__tty_annotate(struct map_symbol *ms, struc= t evsel *evsel) if (err) { char msg[BUFSIZ]; =20 - dso->annotate_warned =3D true; + dso__set_annotate_warned(dso); symbol__strerror_disassemble(ms, err, msg, sizeof(msg)); ui__error("Couldn't annotate %s:\n%s", sym->name, msg); return -1; @@ -3127,7 +3126,7 @@ int symbol__tty_annotate(struct map_symbol *ms, struc= t evsel *evsel) if (annotate_opts.print_lines) { srcline_full_filename =3D annotate_opts.full_path; symbol__calc_lines(ms, &source_line); - print_summary(&source_line, dso->long_name); + print_summary(&source_line, dso__long_name(dso)); } =20 symbol__annotate_printf(ms, evsel); @@ -3941,7 +3940,7 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) } =20 /* This CPU access in kernel - pretend PC-relative addressing */ - if (map__dso(ms->map)->kernel && arch__is(arch, "x86") && + if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") && op_loc->segment =3D=3D INSN_SEG_X86_GS && op_loc->imm) { dloc.var_addr =3D op_loc->offset; op_loc->reg1 =3D DWARF_REG_PC; diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index cfa2153d4611..3fd350de0051 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2654,7 +2654,7 @@ static int addr_filter__entire_dso(struct addr_filter= *filt, struct dso *dso) } =20 filt->addr =3D 0; - filt->size =3D dso->data.file_size; + filt->size =3D dso__data(dso)->file_size; =20 return 0; } diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c index dec910989701..895ee8adf3b3 100644 --- a/tools/perf/util/block-info.c +++ b/tools/perf/util/block-info.c @@ -319,7 +319,7 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, st= ruct perf_hpp *hpp, =20 if (map && map__dso(map)) { return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width, - map__dso(map)->short_name); + dso__short_name(map__dso(map))); } =20 return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width, diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index 83709146a48a..827695cd0408 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -59,10 +59,10 @@ static int machine__process_bpf_event_load(struct machi= ne *machine, if (map) { struct dso *dso =3D map__dso(map); =20 - dso->binary_type =3D DSO_BINARY_TYPE__BPF_PROG_INFO; - dso->bpf_prog.id =3D id; - dso->bpf_prog.sub_id =3D i; - dso->bpf_prog.env =3D env; + dso__set_binary_type(dso, DSO_BINARY_TYPE__BPF_PROG_INFO); + dso__bpf_prog(dso)->id =3D id; + dso__bpf_prog(dso)->sub_id =3D i; + dso__bpf_prog(dso)->env =3D env; map__put(map); } } diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 864bc26b6b46..83a1581e8cf1 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -60,7 +60,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe= _unused, =20 addr_location__init(&al); if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) - map__dso(al.map)->hit =3D 1; + dso__set_hit(map__dso(al.map)); =20 addr_location__exit(&al); thread__put(thread); @@ -272,10 +272,10 @@ char *__dso__build_id_filename(const struct dso *dso,= char *bf, size_t size, bool alloc =3D (bf =3D=3D NULL); int ret; =20 - if (!dso->has_build_id) + if (!dso__has_build_id(dso)) return NULL; =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid_const(dso), sbuild_id); linkname =3D build_id_cache__linkname(sbuild_id, NULL, 0); if (!linkname) return NULL; @@ -340,25 +340,25 @@ static int machine__write_buildid_table_cb(struct dso= *dso, void *data) size_t name_len; bool in_kernel =3D false; =20 - if (!dso->has_build_id) + if (!dso__has_build_id(dso)) return 0; =20 - if (!dso->hit && !dso__is_vdso(dso)) + if (!dso__hit(dso) && !dso__is_vdso(dso)) return 0; =20 if (dso__is_vdso(dso)) { - name =3D dso->short_name; - name_len =3D dso->short_name_len; + name =3D dso__short_name(dso); + name_len =3D dso__short_name_len(dso); } else if (dso__is_kcore(dso)) { name =3D args->machine->mmap_name; name_len =3D strlen(name); } else { - name =3D dso->long_name; - name_len =3D dso->long_name_len; + name =3D dso__long_name(dso); + name_len =3D dso__long_name_len(dso); } =20 - in_kernel =3D dso->kernel || is_kernel_module(name, PERF_RECORD_MISC_CPUM= ODE_UNKNOWN); - return write_buildid(name, name_len, &dso->bid, args->machine->pid, + in_kernel =3D dso__kernel(dso) || is_kernel_module(name, PERF_RECORD_MISC= _CPUMODE_UNKNOWN); + return write_buildid(name, name_len, dso__bid(dso), args->machine->pid, in_kernel ? args->kmisc : args->umisc, args->fd); } =20 @@ -876,11 +876,11 @@ static bool dso__build_id_mismatch(struct dso *dso, c= onst char *name) struct build_id bid; bool ret =3D false; =20 - mutex_lock(&dso->lock); - if (filename__read_build_id_ns(name, &bid, dso->nsinfo) >=3D 0) + mutex_lock(dso__lock(dso)); + if (filename__read_build_id_ns(name, &bid, dso__nsinfo(dso)) >=3D 0) ret =3D !dso__build_id_equal(dso, &bid); =20 - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); =20 return ret; } @@ -890,13 +890,13 @@ static int dso__cache_build_id(struct dso *dso, struc= t machine *machine, { bool is_kallsyms =3D dso__is_kallsyms(dso); bool is_vdso =3D dso__is_vdso(dso); - const char *name =3D dso->long_name; + const char *name =3D dso__long_name(dso); const char *proper_name =3D NULL; const char *root_dir =3D NULL; char *allocated_name =3D NULL; int ret =3D 0; =20 - if (!dso->has_build_id) + if (!dso__has_build_id(dso)) return 0; =20 if (dso__is_kcore(dso)) { @@ -921,10 +921,10 @@ static int dso__cache_build_id(struct dso *dso, struc= t machine *machine, if (!is_kallsyms && dso__build_id_mismatch(dso, name)) goto out_free; =20 - mutex_lock(&dso->lock); - ret =3D build_id_cache__add_b(&dso->bid, name, dso->nsinfo, + mutex_lock(dso__lock(dso)); + ret =3D build_id_cache__add_b(dso__bid(dso), name, dso__nsinfo(dso), is_kallsyms, is_vdso, proper_name, root_dir); - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); out_free: free(allocated_name); return ret; diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 7517d16c02ec..68feed871809 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1205,7 +1205,7 @@ char *callchain_list__sym_name(struct callchain_list = *cl, if (show_dso) scnprintf(bf + printed, bfsize - printed, " %s", cl->ms.map ? - map__dso(cl->ms.map)->short_name : + dso__short_name(map__dso(cl->ms.map)) : "unknown"); =20 return bf; diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-con= vert-json.c index 09d57efd2d9d..3cf64f5b23ee 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -134,7 +134,7 @@ static void output_sample_callchain_entry(struct perf_t= ool *tool, output_json_key_string(out, false, 5, "symbol", al->sym->name); =20 if (dso) { - const char *dso_name =3D dso->short_name; + const char *dso_name =3D dso__short_name(dso); =20 if (dso_name && strlen(dso_name) > 0) { fputc(',', out); diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index 106429155c2e..50f916374d87 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -146,10 +146,10 @@ int db_export__comm_thread(struct db_export *dbe, str= uct comm *comm, int db_export__dso(struct db_export *dbe, struct dso *dso, struct machine *machine) { - if (dso->db_id) + if (dso__db_id(dso)) return 0; =20 - dso->db_id =3D ++dbe->dso_last_db_id; + dso__set_db_id(dso, ++dbe->dso_last_db_id); =20 if (dbe->export_dso) return dbe->export_dso(dbe, dso, machine); @@ -184,7 +184,7 @@ static int db_ids_from_al(struct db_export *dbe, struct= addr_location *al, err =3D db_export__dso(dbe, dso, maps__machine(al->maps)); if (err) return err; - *dso_db_id =3D dso->db_id; + *dso_db_id =3D dso__db_id(dso); =20 if (!al->sym) { al->sym =3D symbol__new(al->addr, 0, 0, 0, "unknown"); diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 908e16813722..7d180bdaedbc 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -33,13 +33,13 @@ static void al_to_d_al(struct addr_location *al, struct= perf_dlfilter_al *d_al) if (al->map) { struct dso *dso =3D map__dso(al->map); =20 - if (symbol_conf.show_kernel_path && dso->long_name) - d_al->dso =3D dso->long_name; + if (symbol_conf.show_kernel_path && dso__long_name(dso)) + d_al->dso =3D dso__long_name(dso); else - d_al->dso =3D dso->name; - d_al->is_64_bit =3D dso->is_64_bit; - d_al->buildid_size =3D dso->bid.size; - d_al->buildid =3D dso->bid.data; + d_al->dso =3D dso__name(dso); + d_al->is_64_bit =3D dso__is_64_bit(dso); + d_al->buildid_size =3D dso__bid(dso)->size; + d_al->buildid =3D dso__bid(dso)->data; } else { d_al->dso =3D NULL; d_al->is_64_bit =3D 0; diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 3caca60a6ce3..27db65e96e04 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -40,6 +40,12 @@ static const char * const debuglink_paths[] =3D { "/usr/lib/debug%s/%s" }; =20 +void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi) +{ + nsinfo__put(RC_CHK_ACCESS(dso)->nsinfo); + RC_CHK_ACCESS(dso)->nsinfo =3D nsi; +} + char dso__symtab_origin(const struct dso *dso) { static const char origin[] =3D { @@ -63,14 +69,14 @@ char dso__symtab_origin(const struct dso *dso) [DSO_BINARY_TYPE__GUEST_VMLINUX] =3D 'V', }; =20 - if (dso =3D=3D NULL || dso->symtab_type =3D=3D DSO_BINARY_TYPE__NOT_FOUND) + if (dso =3D=3D NULL || dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__NOT_= FOUND) return '!'; - return origin[dso->symtab_type]; + return origin[dso__symtab_type(dso)]; } =20 bool dso__is_object_file(const struct dso *dso) { - switch (dso->binary_type) { + switch (dso__binary_type(dso)) { case DSO_BINARY_TYPE__KALLSYMS: case DSO_BINARY_TYPE__GUEST_KALLSYMS: case DSO_BINARY_TYPE__JAVA_JIT: @@ -117,7 +123,7 @@ int dso__read_binary_type_filename(const struct dso *ds= o, char symfile[PATH_MAX]; unsigned int i; =20 - len =3D __symbol__join_symfs(filename, size, dso->long_name); + len =3D __symbol__join_symfs(filename, size, dso__long_name(dso)); last_slash =3D filename + len; while (last_slash !=3D filename && *last_slash !=3D '/') last_slash--; @@ -159,12 +165,12 @@ int dso__read_binary_type_filename(const struct dso *= dso, =20 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s.debug", dso->long_name); + snprintf(filename + len, size - len, "%s.debug", dso__long_name(dso)); break; =20 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s", dso->long_name); + snprintf(filename + len, size - len, "%s", dso__long_name(dso)); break; =20 case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: @@ -173,13 +179,13 @@ int dso__read_binary_type_filename(const struct dso *= dso, * /usr/lib/debug/lib when it is expected to be in * /usr/lib/debug/usr/lib */ - if (strlen(dso->long_name) < 9 || - strncmp(dso->long_name, "/usr/lib/", 9)) { + if (strlen(dso__long_name(dso)) < 9 || + strncmp(dso__long_name(dso), "/usr/lib/", 9)) { ret =3D -1; break; } len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s", dso->long_name + 4); + snprintf(filename + len, size - len, "%s", dso__long_name(dso) + 4); break; =20 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: @@ -187,29 +193,29 @@ int dso__read_binary_type_filename(const struct dso *= dso, const char *last_slash; size_t dir_size; =20 - last_slash =3D dso->long_name + dso->long_name_len; - while (last_slash !=3D dso->long_name && *last_slash !=3D '/') + last_slash =3D dso__long_name(dso) + dso__long_name_len(dso); + while (last_slash !=3D dso__long_name(dso) && *last_slash !=3D '/') last_slash--; =20 len =3D __symbol__join_symfs(filename, size, ""); - dir_size =3D last_slash - dso->long_name + 2; + dir_size =3D last_slash - dso__long_name(dso) + 2; if (dir_size > (size - len)) { ret =3D -1; break; } - len +=3D scnprintf(filename + len, dir_size, "%s", dso->long_name); + len +=3D scnprintf(filename + len, dir_size, "%s", dso__long_name(dso)); len +=3D scnprintf(filename + len , size - len, ".debug%s", last_slash); break; } =20 case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: - if (!dso->has_build_id) { + if (!dso__has_build_id(dso)) { ret =3D -1; break; } =20 - build_id__sprintf(&dso->bid, build_id_hex); + build_id__sprintf(dso__bid_const(dso), build_id_hex); len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/"= ); snprintf(filename + len, size - len, "%.2s/%s.debug", build_id_hex, build_id_hex + 2); @@ -218,23 +224,23 @@ int dso__read_binary_type_filename(const struct dso *= dso, case DSO_BINARY_TYPE__VMLINUX: case DSO_BINARY_TYPE__GUEST_VMLINUX: case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: - __symbol__join_symfs(filename, size, dso->long_name); + __symbol__join_symfs(filename, size, dso__long_name(dso)); break; =20 case DSO_BINARY_TYPE__GUEST_KMODULE: case DSO_BINARY_TYPE__GUEST_KMODULE_COMP: path__join3(filename, size, symbol_conf.symfs, - root_dir, dso->long_name); + root_dir, dso__long_name(dso)); break; =20 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP: - __symbol__join_symfs(filename, size, dso->long_name); + __symbol__join_symfs(filename, size, dso__long_name(dso)); break; =20 case DSO_BINARY_TYPE__KCORE: case DSO_BINARY_TYPE__GUEST_KCORE: - snprintf(filename, size, "%s", dso->long_name); + snprintf(filename, size, "%s", dso__long_name(dso)); break; =20 default: @@ -310,8 +316,8 @@ bool is_kernel_module(const char *pathname, int cpumode) =20 bool dso__needs_decompress(struct dso *dso) { - return dso->symtab_type =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP = || - dso->symtab_type =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE_COMP; + return dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_= COMP || + dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE_COMP; } =20 int filename__decompress(const char *name, char *pathname, @@ -363,11 +369,10 @@ static int decompress_kmodule(struct dso *dso, const = char *name, if (!dso__needs_decompress(dso)) return -1; =20 - if (dso->comp =3D=3D COMP_ID__NONE) + if (dso__comp(dso) =3D=3D COMP_ID__NONE) return -1; =20 - return filename__decompress(name, pathname, len, dso->comp, - &dso->load_errno); + return filename__decompress(name, pathname, len, dso__comp(dso), dso__loa= d_errno(dso)); } =20 int dso__decompress_kmodule_fd(struct dso *dso, const char *name) @@ -468,17 +473,17 @@ void dso__set_module_info(struct dso *dso, struct kmo= d_path *m, struct machine *machine) { if (machine__is_host(machine)) - dso->symtab_type =3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE; + dso__set_symtab_type(dso, DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE); else - dso->symtab_type =3D DSO_BINARY_TYPE__GUEST_KMODULE; + dso__set_symtab_type(dso, DSO_BINARY_TYPE__GUEST_KMODULE); =20 /* _KMODULE_COMP should be next to _KMODULE */ if (m->kmod && m->comp) { - dso->symtab_type++; - dso->comp =3D m->comp; + dso__set_symtab_type(dso, dso__symtab_type(dso) + 1); + dso__set_comp(dso, m->comp); } =20 - dso->is_kmod =3D 1; + dso__set_is_kmod(dso); dso__set_short_name(dso, strdup(m->name), true); } =20 @@ -491,13 +496,15 @@ static pthread_mutex_t dso__data_open_lock =3D PTHREA= D_MUTEX_INITIALIZER; =20 static void dso__list_add(struct dso *dso) { - list_add_tail(&dso->data.open_entry, &dso__data_open); + list_add_tail(&dso__data(dso)->open_entry, &dso__data_open); + dso__data(dso)->dso =3D dso__get(dso); dso__data_open_cnt++; } =20 static void dso__list_del(struct dso *dso) { - list_del_init(&dso->data.open_entry); + list_del_init(&dso__data(dso)->open_entry); + dso__put(dso__data(dso)->dso); WARN_ONCE(dso__data_open_cnt <=3D 0, "DSO data fd counter out of bounds."); dso__data_open_cnt--; @@ -528,7 +535,7 @@ static int do_open(char *name) =20 char *dso__filename_with_chroot(const struct dso *dso, const char *filenam= e) { - return filename_with_chroot(nsinfo__pid(dso->nsinfo), filename); + return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename= ); } =20 static int __open_dso(struct dso *dso, struct machine *machine) @@ -541,18 +548,18 @@ static int __open_dso(struct dso *dso, struct machine= *machine) if (!name) return -ENOMEM; =20 - mutex_lock(&dso->lock); + mutex_lock(dso__lock(dso)); if (machine) root_dir =3D machine->root_dir; =20 - if (dso__read_binary_type_filename(dso, dso->binary_type, + if (dso__read_binary_type_filename(dso, dso__binary_type(dso), root_dir, name, PATH_MAX)) goto out; =20 if (!is_regular_file(name)) { char *new_name; =20 - if (errno !=3D ENOENT || dso->nsinfo =3D=3D NULL) + if (errno !=3D ENOENT || dso__nsinfo(dso) =3D=3D NULL) goto out; =20 new_name =3D dso__filename_with_chroot(dso, name); @@ -568,7 +575,7 @@ static int __open_dso(struct dso *dso, struct machine *= machine) size_t len =3D sizeof(newpath); =20 if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) { - fd =3D -dso->load_errno; + fd =3D -(*dso__load_errno(dso)); goto out; } =20 @@ -582,7 +589,7 @@ static int __open_dso(struct dso *dso, struct machine *= machine) unlink(name); =20 out: - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); free(name); return fd; } @@ -601,13 +608,13 @@ static int open_dso(struct dso *dso, struct machine *= machine) int fd; struct nscookie nsc; =20 - if (dso->binary_type !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) { - mutex_lock(&dso->lock); - nsinfo__mountns_enter(dso->nsinfo, &nsc); - mutex_unlock(&dso->lock); + if (dso__binary_type(dso) !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) { + mutex_lock(dso__lock(dso)); + nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); + mutex_unlock(dso__lock(dso)); } fd =3D __open_dso(dso, machine); - if (dso->binary_type !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) + if (dso__binary_type(dso) !=3D DSO_BINARY_TYPE__BUILD_ID_CACHE) nsinfo__mountns_exit(&nsc); =20 if (fd >=3D 0) { @@ -624,10 +631,10 @@ static int open_dso(struct dso *dso, struct machine *= machine) =20 static void close_data_fd(struct dso *dso) { - if (dso->data.fd >=3D 0) { - close(dso->data.fd); - dso->data.fd =3D -1; - dso->data.file_size =3D 0; + if (dso__data(dso)->fd >=3D 0) { + close(dso__data(dso)->fd); + dso__data(dso)->fd =3D -1; + dso__data(dso)->file_size =3D 0; dso__list_del(dso); } } @@ -646,10 +653,10 @@ static void close_dso(struct dso *dso) =20 static void close_first_dso(void) { - struct dso *dso; + struct dso_data *dso_data; =20 - dso =3D list_first_entry(&dso__data_open, struct dso, data.open_entry); - close_dso(dso); + dso_data =3D list_first_entry(&dso__data_open, struct dso_data, open_entr= y); + close_dso(dso_data->dso); } =20 static rlim_t get_fd_limit(void) @@ -728,28 +735,29 @@ static void try_to_open_dso(struct dso *dso, struct m= achine *machine) DSO_BINARY_TYPE__NOT_FOUND, }; int i =3D 0; + struct dso_data *dso_data =3D dso__data(dso); =20 - if (dso->data.fd >=3D 0) + if (dso_data->fd >=3D 0) return; =20 - if (dso->binary_type !=3D DSO_BINARY_TYPE__NOT_FOUND) { - dso->data.fd =3D open_dso(dso, machine); + if (dso__binary_type(dso) !=3D DSO_BINARY_TYPE__NOT_FOUND) { + dso_data->fd =3D open_dso(dso, machine); goto out; } =20 do { - dso->binary_type =3D binary_type_data[i++]; + dso__set_binary_type(dso, binary_type_data[i++]); =20 - dso->data.fd =3D open_dso(dso, machine); - if (dso->data.fd >=3D 0) + dso_data->fd =3D open_dso(dso, machine); + if (dso_data->fd >=3D 0) goto out; =20 - } while (dso->binary_type !=3D DSO_BINARY_TYPE__NOT_FOUND); + } while (dso__binary_type(dso) !=3D DSO_BINARY_TYPE__NOT_FOUND); out: - if (dso->data.fd >=3D 0) - dso->data.status =3D DSO_DATA_STATUS_OK; + if (dso_data->fd >=3D 0) + dso_data->status =3D DSO_DATA_STATUS_OK; else - dso->data.status =3D DSO_DATA_STATUS_ERROR; + dso_data->status =3D DSO_DATA_STATUS_ERROR; } =20 /** @@ -763,7 +771,7 @@ static void try_to_open_dso(struct dso *dso, struct mac= hine *machine) */ int dso__data_get_fd(struct dso *dso, struct machine *machine) { - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR) + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR) return -1; =20 if (pthread_mutex_lock(&dso__data_open_lock) < 0) @@ -771,10 +779,10 @@ int dso__data_get_fd(struct dso *dso, struct machine = *machine) =20 try_to_open_dso(dso, machine); =20 - if (dso->data.fd < 0) + if (dso__data(dso)->fd < 0) pthread_mutex_unlock(&dso__data_open_lock); =20 - return dso->data.fd; + return dso__data(dso)->fd; } =20 void dso__data_put_fd(struct dso *dso __maybe_unused) @@ -786,10 +794,10 @@ bool dso__data_status_seen(struct dso *dso, enum dso_= data_status_seen by) { u32 flag =3D 1 << by; =20 - if (dso->data.status_seen & flag) + if (dso__data(dso)->status_seen & flag) return true; =20 - dso->data.status_seen |=3D flag; + dso__data(dso)->status_seen |=3D flag; =20 return false; } @@ -799,12 +807,13 @@ static ssize_t bpf_read(struct dso *dso, u64 offset, = char *data) { struct bpf_prog_info_node *node; ssize_t size =3D DSO__DATA_CACHE_SIZE; + struct dso_bpf_prog *dso_bpf_prog =3D dso__bpf_prog(dso); u64 len; u8 *buf; =20 - node =3D perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id= ); + node =3D perf_env__find_bpf_prog_info(dso_bpf_prog->env, dso_bpf_prog->id= ); if (!node || !node->info_linear) { - dso->data.status =3D DSO_DATA_STATUS_ERROR; + dso__data(dso)->status =3D DSO_DATA_STATUS_ERROR; return -1; } =20 @@ -822,14 +831,15 @@ static ssize_t bpf_read(struct dso *dso, u64 offset, = char *data) static int bpf_size(struct dso *dso) { struct bpf_prog_info_node *node; + struct dso_bpf_prog *dso_bpf_prog =3D dso__bpf_prog(dso); =20 - node =3D perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id= ); + node =3D perf_env__find_bpf_prog_info(dso_bpf_prog->env, dso_bpf_prog->id= ); if (!node || !node->info_linear) { - dso->data.status =3D DSO_DATA_STATUS_ERROR; + dso__data(dso)->status =3D DSO_DATA_STATUS_ERROR; return -1; } =20 - dso->data.file_size =3D node->info_linear->info.jited_prog_len; + dso__data(dso)->file_size =3D node->info_linear->info.jited_prog_len; return 0; } #endif // HAVE_LIBBPF_SUPPORT @@ -837,10 +847,10 @@ static int bpf_size(struct dso *dso) static void dso_cache__free(struct dso *dso) { - struct rb_root *root =3D &dso->data.cache; + struct rb_root *root =3D &dso__data(dso)->cache; struct rb_node *next =3D rb_first(root); =20 - mutex_lock(&dso->lock); + mutex_lock(dso__lock(dso)); while (next) { struct dso_cache *cache; =20 @@ -849,12 +859,12 @@ dso_cache__free(struct dso *dso) rb_erase(&cache->rb_node, root); free(cache); } - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); } =20 static struct dso_cache *__dso_cache__find(struct dso *dso, u64 offset) { - const struct rb_root *root =3D &dso->data.cache; + const struct rb_root *root =3D &dso__data(dso)->cache; struct rb_node * const *p =3D &root->rb_node; const struct rb_node *parent =3D NULL; struct dso_cache *cache; @@ -880,13 +890,13 @@ static struct dso_cache *__dso_cache__find(struct dso= *dso, u64 offset) static struct dso_cache * dso_cache__insert(struct dso *dso, struct dso_cache *new) { - struct rb_root *root =3D &dso->data.cache; + struct rb_root *root =3D &dso__data(dso)->cache; struct rb_node **p =3D &root->rb_node; struct rb_node *parent =3D NULL; struct dso_cache *cache; u64 offset =3D new->offset; =20 - mutex_lock(&dso->lock); + mutex_lock(dso__lock(dso)); while (*p !=3D NULL) { u64 end; =20 @@ -907,7 +917,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *ne= w) =20 cache =3D NULL; out: - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); return cache; } =20 @@ -932,18 +942,18 @@ static ssize_t file_read(struct dso *dso, struct mach= ine *machine, pthread_mutex_lock(&dso__data_open_lock); =20 /* - * dso->data.fd might be closed if other thread opened another + * dso__data(dso)->fd might be closed if other thread opened another * file (dso) due to open file limit (RLIMIT_NOFILE). */ try_to_open_dso(dso, machine); =20 - if (dso->data.fd < 0) { - dso->data.status =3D DSO_DATA_STATUS_ERROR; + if (dso__data(dso)->fd < 0) { + dso__data(dso)->status =3D DSO_DATA_STATUS_ERROR; ret =3D -errno; goto out; } =20 - ret =3D pread(dso->data.fd, data, DSO__DATA_CACHE_SIZE, offset); + ret =3D pread(dso__data(dso)->fd, data, DSO__DATA_CACHE_SIZE, offset); out: pthread_mutex_unlock(&dso__data_open_lock); return ret; @@ -963,11 +973,11 @@ static struct dso_cache *dso_cache__populate(struct d= so *dso, return NULL; } #ifdef HAVE_LIBBPF_SUPPORT - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) *ret =3D bpf_read(dso, cache_offset, cache->data); else #endif - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__OOL) + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__OOL) *ret =3D DSO__DATA_CACHE_SIZE; else *ret =3D file_read(dso, machine, cache_offset, cache->data); @@ -1056,25 +1066,25 @@ static int file_size(struct dso *dso, struct machin= e *machine) pthread_mutex_lock(&dso__data_open_lock); =20 /* - * dso->data.fd might be closed if other thread opened another + * dso__data(dso)->fd might be closed if other thread opened another * file (dso) due to open file limit (RLIMIT_NOFILE). */ try_to_open_dso(dso, machine); =20 - if (dso->data.fd < 0) { + if (dso__data(dso)->fd < 0) { ret =3D -errno; - dso->data.status =3D DSO_DATA_STATUS_ERROR; + dso__data(dso)->status =3D DSO_DATA_STATUS_ERROR; goto out; } =20 - if (fstat(dso->data.fd, &st) < 0) { + if (fstat(dso__data(dso)->fd, &st) < 0) { ret =3D -errno; pr_err("dso cache fstat failed: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); - dso->data.status =3D DSO_DATA_STATUS_ERROR; + dso__data(dso)->status =3D DSO_DATA_STATUS_ERROR; goto out; } - dso->data.file_size =3D st.st_size; + dso__data(dso)->file_size =3D st.st_size; =20 out: pthread_mutex_unlock(&dso__data_open_lock); @@ -1083,13 +1093,13 @@ static int file_size(struct dso *dso, struct machin= e *machine) =20 int dso__data_file_size(struct dso *dso, struct machine *machine) { - if (dso->data.file_size) + if (dso__data(dso)->file_size) return 0; =20 - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR) + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR) return -1; #ifdef HAVE_LIBBPF_SUPPORT - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) return bpf_size(dso); #endif return file_size(dso, machine); @@ -1108,7 +1118,7 @@ off_t dso__data_size(struct dso *dso, struct machine = *machine) return -1; =20 /* For now just estimate dso data size is close to file size */ - return dso->data.file_size; + return dso__data(dso)->file_size; } =20 static ssize_t data_read_write_offset(struct dso *dso, struct machine *mac= hine, @@ -1119,7 +1129,7 @@ static ssize_t data_read_write_offset(struct dso *dso= , struct machine *machine, return -1; =20 /* Check the offset sanity. */ - if (offset > dso->data.file_size) + if (offset > dso__data(dso)->file_size) return -1; =20 if (offset + size < offset) @@ -1142,7 +1152,7 @@ static ssize_t data_read_write_offset(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) { - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR) + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR) return -1; =20 return data_read_write_offset(dso, machine, offset, data, size, true); @@ -1182,7 +1192,7 @@ ssize_t dso__data_write_cache_offs(struct dso *dso, s= truct machine *machine, { u8 *data =3D (u8 *)data_in; /* cast away const to use same fns for r/w */ =20 - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR) + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR) return -1; =20 return data_read_write_offset(dso, machine, offset, data, size, false); @@ -1235,7 +1245,7 @@ struct dso *machine__findnew_kernel(struct machine *m= achine, const char *name, */ if (dso !=3D NULL) { dso__set_short_name(dso, short_name, false); - dso->kernel =3D dso_type; + dso__set_kernel(dso, dso_type); } =20 return dso; @@ -1243,7 +1253,7 @@ struct dso *machine__findnew_kernel(struct machine *m= achine, const char *name, =20 static void dso__set_long_name_id(struct dso *dso, const char *name, bool = name_allocated) { - struct dsos *dsos =3D dso->dsos; + struct dsos *dsos =3D dso__dsos(dso); =20 if (name =3D=3D NULL) return; @@ -1256,12 +1266,12 @@ static void dso__set_long_name_id(struct dso *dso, = const char *name, bool name_a down_write(&dsos->lock); } =20 - if (dso->long_name_allocated) - free((char *)dso->long_name); + if (dso__long_name_allocated(dso)) + free((char *)dso__long_name(dso)); =20 - dso->long_name =3D name; - dso->long_name_len =3D strlen(name); - dso->long_name_allocated =3D name_allocated; + RC_CHK_ACCESS(dso)->long_name =3D name; + RC_CHK_ACCESS(dso)->long_name_len =3D strlen(name); + dso__set_long_name_allocated(dso, name_allocated); =20 if (dsos) { dsos->sorted =3D false; @@ -1307,14 +1317,15 @@ bool dso_id__empty(const struct dso_id *id) =20 void __dso__inject_id(struct dso *dso, struct dso_id *id) { - struct dsos *dsos =3D dso->dsos; + struct dsos *dsos =3D dso__dsos(dso); + struct dso_id *dso_id =3D dso__id(dso); =20 /* dsos write lock held by caller. */ =20 - dso->id.maj =3D id->maj; - dso->id.min =3D id->min; - dso->id.ino =3D id->ino; - dso->id.ino_generation =3D id->ino_generation; + dso_id->maj =3D id->maj; + dso_id->min =3D id->min; + dso_id->ino =3D id->ino; + dso_id->ino_generation =3D id->ino_generation; =20 if (dsos) dsos->sorted =3D false; @@ -1334,7 +1345,7 @@ int dso_id__cmp(const struct dso_id *a, const struct = dso_id *b) =20 int dso__cmp_id(struct dso *a, struct dso *b) { - return __dso_id__cmp(&a->id, &b->id); + return __dso_id__cmp(dso__id(a), dso__id(b)); } =20 void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated) @@ -1344,7 +1355,7 @@ void dso__set_long_name(struct dso *dso, const char *= name, bool name_allocated) =20 void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated) { - struct dsos *dsos =3D dso->dsos; + struct dsos *dsos =3D dso__dsos(dso); =20 if (name =3D=3D NULL) return; @@ -1356,12 +1367,12 @@ void dso__set_short_name(struct dso *dso, const cha= r *name, bool name_allocated) */ down_write(&dsos->lock); } - if (dso->short_name_allocated) - free((char *)dso->short_name); + if (dso__short_name_allocated(dso)) + free((char *)dso__short_name(dso)); =20 - dso->short_name =3D name; - dso->short_name_len =3D strlen(name); - dso->short_name_allocated =3D name_allocated; + RC_CHK_ACCESS(dso)->short_name =3D name; + RC_CHK_ACCESS(dso)->short_name_len =3D strlen(name); + dso__set_short_name_allocated(dso, name_allocated); =20 if (dsos) { dsos->sorted =3D false; @@ -1374,40 +1385,44 @@ int dso__name_len(const struct dso *dso) if (!dso) return strlen("[unknown]"); if (verbose > 0) - return dso->long_name_len; + return dso__long_name_len(dso); =20 - return dso->short_name_len; + return dso__short_name_len(dso); } =20 bool dso__loaded(const struct dso *dso) { - return dso->loaded; + return RC_CHK_ACCESS(dso)->loaded; } =20 bool dso__sorted_by_name(const struct dso *dso) { - return dso->sorted_by_name; + return RC_CHK_ACCESS(dso)->sorted_by_name; } =20 void dso__set_sorted_by_name(struct dso *dso) { - dso->sorted_by_name =3D true; + RC_CHK_ACCESS(dso)->sorted_by_name =3D true; } =20 struct dso *dso__new_id(const char *name, struct dso_id *id) { - struct dso *dso =3D calloc(1, sizeof(*dso) + strlen(name) + 1); + RC_STRUCT(dso) *dso =3D zalloc(sizeof(*dso) + strlen(name) + 1); + struct dso *res; + struct dso_data *data; =20 - if (dso !=3D NULL) { + if (!dso) + return NULL; + + if (ADD_RC_CHK(res, dso)) { strcpy(dso->name, name); if (id) dso->id =3D *id; - dso__set_long_name_id(dso, dso->name, false); - dso__set_short_name(dso, dso->name, false); + dso__set_long_name_id(res, dso->name, false); + dso__set_short_name(res, dso->name, false); dso->symbols =3D RB_ROOT_CACHED; dso->symbol_names =3D NULL; dso->symbol_names_len =3D 0; - dso->data.cache =3D RB_ROOT; dso->inlined_nodes =3D RB_ROOT_CACHED; dso->srclines =3D RB_ROOT_CACHED; dso->data_types =3D RB_ROOT; @@ -1427,12 +1442,16 @@ struct dso *dso__new_id(const char *name, struct ds= o_id *id) dso->is_kmod =3D 0; dso->needs_swap =3D DSO_SWAP__UNSET; dso->comp =3D COMP_ID__NONE; - INIT_LIST_HEAD(&dso->data.open_entry); mutex_init(&dso->lock); refcount_set(&dso->refcnt, 1); + data =3D &dso->data; + data->cache =3D RB_ROOT; + data->fd =3D -1; + data->status =3D DSO_DATA_STATUS_UNKNOWN; + INIT_LIST_HEAD(&data->open_entry); + data->dso =3D NULL; /* Set when on the open_entry list. */ } - - return dso; + return res; } =20 struct dso *dso__new(const char *name) @@ -1442,71 +1461,78 @@ struct dso *dso__new(const char *name) =20 void dso__delete(struct dso *dso) { - if (dso->dsos) - pr_err("DSO %s is still in rbtree when being deleted!\n", dso->long_name= ); + if (dso__dsos(dso)) + pr_err("DSO %s is still in rbtree when being deleted!\n", dso__long_name= (dso)); =20 /* free inlines first, as they reference symbols */ - inlines__tree_delete(&dso->inlined_nodes); - srcline__tree_delete(&dso->srclines); - symbols__delete(&dso->symbols); - dso->symbol_names_len =3D 0; - zfree(&dso->symbol_names); - annotated_data_type__tree_delete(&dso->data_types); - global_var_type__tree_delete(&dso->global_vars); - - if (dso->short_name_allocated) { - zfree((char **)&dso->short_name); - dso->short_name_allocated =3D false; + inlines__tree_delete(&RC_CHK_ACCESS(dso)->inlined_nodes); + srcline__tree_delete(&RC_CHK_ACCESS(dso)->srclines); + symbols__delete(&RC_CHK_ACCESS(dso)->symbols); + RC_CHK_ACCESS(dso)->symbol_names_len =3D 0; + zfree(&RC_CHK_ACCESS(dso)->symbol_names); + annotated_data_type__tree_delete(dso__data_types(dso)); + global_var_type__tree_delete(dso__global_vars(dso)); + + if (RC_CHK_ACCESS(dso)->short_name_allocated) { + zfree((char **)&RC_CHK_ACCESS(dso)->short_name); + RC_CHK_ACCESS(dso)->short_name_allocated =3D false; } =20 - if (dso->long_name_allocated) { - zfree((char **)&dso->long_name); - dso->long_name_allocated =3D false; + if (RC_CHK_ACCESS(dso)->long_name_allocated) { + zfree((char **)&RC_CHK_ACCESS(dso)->long_name); + RC_CHK_ACCESS(dso)->long_name_allocated =3D false; } =20 dso__data_close(dso); - auxtrace_cache__free(dso->auxtrace_cache); + auxtrace_cache__free(RC_CHK_ACCESS(dso)->auxtrace_cache); dso_cache__free(dso); dso__free_a2l(dso); - zfree(&dso->symsrc_filename); - nsinfo__zput(dso->nsinfo); - mutex_destroy(&dso->lock); - free(dso); + zfree(&RC_CHK_ACCESS(dso)->symsrc_filename); + nsinfo__zput(RC_CHK_ACCESS(dso)->nsinfo); + mutex_destroy(dso__lock(dso)); + RC_CHK_FREE(dso); } =20 struct dso *dso__get(struct dso *dso) { - if (dso) - refcount_inc(&dso->refcnt); - return dso; + struct dso *result; + + if (RC_CHK_GET(result, dso)) + refcount_inc(&RC_CHK_ACCESS(dso)->refcnt); + + return result; } =20 void dso__put(struct dso *dso) { - if (dso && refcount_dec_and_test(&dso->refcnt)) + if (dso && refcount_dec_and_test(&RC_CHK_ACCESS(dso)->refcnt)) dso__delete(dso); + else + RC_CHK_PUT(dso); } =20 void dso__set_build_id(struct dso *dso, struct build_id *bid) { - dso->bid =3D *bid; - dso->has_build_id =3D 1; + RC_CHK_ACCESS(dso)->bid =3D *bid; + RC_CHK_ACCESS(dso)->has_build_id =3D 1; } =20 bool dso__build_id_equal(const struct dso *dso, struct build_id *bid) { - if (dso->bid.size > bid->size && dso->bid.size =3D=3D BUILD_ID_SIZE) { + const struct build_id *dso_bid =3D dso__bid_const(dso); + + if (dso_bid->size > bid->size && dso_bid->size =3D=3D BUILD_ID_SIZE) { /* * For the backward compatibility, it allows a build-id has * trailing zeros. */ - return !memcmp(dso->bid.data, bid->data, bid->size) && - !memchr_inv(&dso->bid.data[bid->size], 0, - dso->bid.size - bid->size); + return !memcmp(dso_bid->data, bid->data, bid->size) && + !memchr_inv(&dso_bid->data[bid->size], 0, + dso_bid->size - bid->size); } =20 - return dso->bid.size =3D=3D bid->size && - memcmp(dso->bid.data, bid->data, dso->bid.size) =3D=3D 0; + return dso_bid->size =3D=3D bid->size && + memcmp(dso_bid->data, bid->data, dso_bid->size) =3D=3D 0; } =20 void dso__read_running_kernel_build_id(struct dso *dso, struct machine *ma= chine) @@ -1516,8 +1542,8 @@ void dso__read_running_kernel_build_id(struct dso *ds= o, struct machine *machine) if (machine__is_default_guest(machine)) return; sprintf(path, "%s/sys/kernel/notes", machine->root_dir); - if (sysfs__read_build_id(path, &dso->bid) =3D=3D 0) - dso->has_build_id =3D true; + if (sysfs__read_build_id(path, dso__bid(dso)) =3D=3D 0) + dso__set_has_build_id(dso); } =20 int dso__kernel_module_get_build_id(struct dso *dso, @@ -1528,14 +1554,14 @@ int dso__kernel_module_get_build_id(struct dso *dso, * kernel module short names are of the form "[module]" and * we need just "module" here. */ - const char *name =3D dso->short_name + 1; + const char *name =3D dso__short_name(dso) + 1; =20 snprintf(filename, sizeof(filename), "%s/sys/module/%.*s/notes/.note.gnu.build-id", root_dir, (int)strlen(name) - 1, name); =20 - if (sysfs__read_build_id(filename, &dso->bid) =3D=3D 0) - dso->has_build_id =3D true; + if (sysfs__read_build_id(filename, dso__bid(dso)) =3D=3D 0) + dso__set_has_build_id(dso); =20 return 0; } @@ -1544,21 +1570,21 @@ static size_t dso__fprintf_buildid(struct dso *dso,= FILE *fp) { char sbuild_id[SBUILD_ID_SIZE]; =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); return fprintf(fp, "%s", sbuild_id); } =20 size_t dso__fprintf(struct dso *dso, FILE *fp) { struct rb_node *nd; - size_t ret =3D fprintf(fp, "dso: %s (", dso->short_name); + size_t ret =3D fprintf(fp, "dso: %s (", dso__short_name(dso)); =20 - if (dso->short_name !=3D dso->long_name) - ret +=3D fprintf(fp, "%s, ", dso->long_name); + if (dso__short_name(dso) !=3D dso__long_name(dso)) + ret +=3D fprintf(fp, "%s, ", dso__long_name(dso)); ret +=3D fprintf(fp, "%sloaded, ", dso__loaded(dso) ? "" : "NOT "); ret +=3D dso__fprintf_buildid(dso, fp); ret +=3D fprintf(fp, ")\n"); - for (nd =3D rb_first_cached(&dso->symbols); nd; nd =3D rb_next(nd)) { + for (nd =3D rb_first_cached(dso__symbols(dso)); nd; nd =3D rb_next(nd)) { struct symbol *pos =3D rb_entry(nd, struct symbol, rb_node); ret +=3D symbol__fprintf(pos, fp); } @@ -1582,7 +1608,7 @@ enum dso_type dso__type(struct dso *dso, struct machi= ne *machine) =20 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen) { - int idx, errnum =3D dso->load_errno; + int idx, errnum =3D *dso__load_errno(dso); /* * This must have a same ordering as the enum dso_load_errno. */ diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index b22dec8b3f3a..f9689dd60de3 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -11,6 +11,7 @@ #include #include "build-id.h" #include "mutex.h" +#include =20 struct machine; struct map; @@ -100,26 +101,27 @@ enum dso_load_errno { __DSO_LOAD_ERRNO__END, }; =20 -#define DSO__SWAP(dso, type, val) \ -({ \ - type ____r =3D val; \ - BUG_ON(dso->needs_swap =3D=3D DSO_SWAP__UNSET); \ - if (dso->needs_swap =3D=3D DSO_SWAP__YES) { \ - switch (sizeof(____r)) { \ - case 2: \ - ____r =3D bswap_16(val); \ - break; \ - case 4: \ - ____r =3D bswap_32(val); \ - break; \ - case 8: \ - ____r =3D bswap_64(val); \ - break; \ - default: \ - BUG_ON(1); \ - } \ - } \ - ____r; \ +#define DSO__SWAP(dso, 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) { \ + switch (sizeof(____r)) { \ + case 2: \ + ____r =3D bswap_16(val); \ + break; \ + case 4: \ + ____r =3D bswap_32(val); \ + break; \ + case 8: \ + ____r =3D bswap_64(val); \ + break; \ + default: \ + BUG_ON(1); \ + } \ + } \ + ____r; \ }) =20 #define DSO__DATA_CACHE_SIZE 4096 @@ -142,9 +144,29 @@ struct dso_cache { char data[]; }; =20 +struct dso_data { + struct rb_root cache; + struct list_head open_entry; + struct dso *dso; + int fd; + int status; + u32 status_seen; + u64 file_size; + u64 elf_base_addr; + u64 debug_frame_offset; + u64 eh_frame_hdr_addr; + u64 eh_frame_hdr_offset; +}; + +struct dso_bpf_prog { + u32 id; + u32 sub_id; + struct perf_env *env; +}; + struct auxtrace_cache; =20 -struct dso { +DECLARE_RC_STRUCT(dso) { struct mutex lock; struct dsos *dsos; struct rb_root_cached symbols; @@ -176,24 +198,9 @@ struct dso { u64 db_id; }; /* bpf prog information */ - struct { - struct perf_env *env; - u32 id; - u32 sub_id; - } bpf_prog; + struct dso_bpf_prog bpf_prog; /* dso data file */ - struct { - struct rb_root cache; - struct list_head open_entry; - u64 file_size; - u64 elf_base_addr; - u64 debug_frame_offset; - u64 eh_frame_hdr_addr; - u64 eh_frame_hdr_offset; - int fd; - int status; - u32 status_seen; - } data; + struct dso_data data; struct dso_id id; unsigned int a2l_fails; int comp; @@ -229,11 +236,388 @@ struct dso { * @n: the 'struct rb_node *' to use as a temporary storage */ #define dso__for_each_symbol(dso, pos, n) \ - symbols__for_each_entry(&(dso)->symbols, pos, n) + symbols__for_each_entry(dso__symbols(dso), pos, n) + +static inline void *dso__a2l(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->a2l; +} + +static inline void dso__set_a2l(struct dso *dso, void *val) +{ + RC_CHK_ACCESS(dso)->a2l =3D val; +} + +static inline unsigned int dso__a2l_fails(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->a2l_fails; +} + +static inline void dso__set_a2l_fails(struct dso *dso, unsigned int val) +{ + RC_CHK_ACCESS(dso)->a2l_fails =3D val; +} + +static inline bool dso__adjust_symbols(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->adjust_symbols; +} + +static inline void dso__set_adjust_symbols(struct dso *dso, bool val) +{ + RC_CHK_ACCESS(dso)->adjust_symbols =3D val; +} + +static inline bool dso__annotate_warned(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->annotate_warned; +} + +static inline void dso__set_annotate_warned(struct dso *dso) +{ + RC_CHK_ACCESS(dso)->annotate_warned =3D 1; +} + +static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->auxtrace_cache; +} + +static inline void dso__set_auxtrace_cache(struct dso *dso, struct auxtrac= e_cache *cache) +{ + RC_CHK_ACCESS(dso)->auxtrace_cache =3D cache; +} + +static inline struct build_id *dso__bid(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->bid; +} + +static inline const struct build_id *dso__bid_const(const struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->bid; +} + +static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->bpf_prog; +} + +static inline bool dso__has_build_id(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->has_build_id; +} + +static inline void dso__set_has_build_id(struct dso *dso) +{ + RC_CHK_ACCESS(dso)->has_build_id =3D true; +} + +static inline bool dso__has_srcline(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->has_srcline; +} + +static inline void dso__set_has_srcline(struct dso *dso, bool val) +{ + RC_CHK_ACCESS(dso)->has_srcline =3D val; +} + +static inline int dso__comp(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->comp; +} + +static inline void dso__set_comp(struct dso *dso, int comp) +{ + RC_CHK_ACCESS(dso)->comp =3D comp; +} + +static inline struct dso_data *dso__data(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->data; +} + +static inline u64 dso__db_id(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->db_id; +} + +static inline void dso__set_db_id(struct dso *dso, u64 db_id) +{ + RC_CHK_ACCESS(dso)->db_id =3D db_id; +} + +static inline struct dsos *dso__dsos(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->dsos; +} + +static inline void dso__set_dsos(struct dso *dso, struct dsos *dsos) +{ + RC_CHK_ACCESS(dso)->dsos =3D dsos; +} + +static inline bool dso__header_build_id(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->header_build_id; +} + +static inline void dso__set_header_build_id(struct dso *dso, bool val) +{ + RC_CHK_ACCESS(dso)->header_build_id =3D val; +} + +static inline bool dso__hit(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->hit; +} + +static inline void dso__set_hit(struct dso *dso) +{ + RC_CHK_ACCESS(dso)->hit =3D 1; +} + +static inline struct dso_id *dso__id(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->id; +} + +static inline const struct dso_id *dso__id_const(const struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->id; +} + +static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->inlined_nodes; +} + +static inline bool dso__is_64_bit(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->is_64_bit; +} + +static inline void dso__set_is_64_bit(struct dso *dso, bool is) +{ + RC_CHK_ACCESS(dso)->is_64_bit =3D is; +} + +static inline bool dso__is_kmod(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->is_kmod; +} + +static inline void dso__set_is_kmod(struct dso *dso) +{ + RC_CHK_ACCESS(dso)->is_kmod =3D 1; +} + +static inline enum dso_space_type dso__kernel(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->kernel; +} + +static inline void dso__set_kernel(struct dso *dso, enum dso_space_type ke= rnel) +{ + RC_CHK_ACCESS(dso)->kernel =3D kernel; +} + +static inline u64 dso__last_find_result_addr(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->last_find_result.addr; +} + +static inline void dso__set_last_find_result_addr(struct dso *dso, u64 add= r) +{ + RC_CHK_ACCESS(dso)->last_find_result.addr =3D addr; +} + +static inline struct symbol *dso__last_find_result_symbol(const struct dso= *dso) +{ + return RC_CHK_ACCESS(dso)->last_find_result.symbol; +} + +static inline void dso__set_last_find_result_symbol(struct dso *dso, struc= t symbol *symbol) +{ + RC_CHK_ACCESS(dso)->last_find_result.symbol =3D symbol; +} + +static inline enum dso_load_errno *dso__load_errno(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->load_errno; +} =20 static inline void dso__set_loaded(struct dso *dso) { - dso->loaded =3D true; + RC_CHK_ACCESS(dso)->loaded =3D true; +} + +static inline struct mutex *dso__lock(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->lock; +} + +static inline const char *dso__long_name(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->long_name; +} + +static inline bool dso__long_name_allocated(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->long_name_allocated; +} + +static inline void dso__set_long_name_allocated(struct dso *dso, bool allo= cated) +{ + RC_CHK_ACCESS(dso)->long_name_allocated =3D allocated; +} + +static inline u16 dso__long_name_len(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->long_name_len; +} + +static inline const char *dso__name(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->name; +} + +static inline enum dso_swap_type dso__needs_swap(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->needs_swap; +} + +static inline void dso__set_needs_swap(struct dso *dso, enum dso_swap_type= type) +{ + RC_CHK_ACCESS(dso)->needs_swap =3D type; +} + +static inline struct nsinfo *dso__nsinfo(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->nsinfo; +} + +static inline const struct nsinfo *dso__nsinfo_const(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->nsinfo; +} + +static inline struct nsinfo **dso__nsinfo_ptr(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->nsinfo; +} + +void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi); + +static inline u8 dso__rel(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->rel; +} + +static inline void dso__set_rel(struct dso *dso, u8 rel) +{ + RC_CHK_ACCESS(dso)->rel =3D rel; +} + +static inline const char *dso__short_name(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->short_name; +} + +static inline bool dso__short_name_allocated(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->short_name_allocated; +} + +static inline void dso__set_short_name_allocated(struct dso *dso, bool all= ocated) +{ + RC_CHK_ACCESS(dso)->short_name_allocated =3D allocated; +} + +static inline u16 dso__short_name_len(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->short_name_len; +} + +static inline struct rb_root_cached *dso__srclines(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->srclines; +} + +static inline struct rb_root *dso__data_types(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->data_types; +} + +static inline struct rb_root *dso__global_vars(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->global_vars; +} + +static inline struct rb_root_cached *dso__symbols(struct dso *dso) +{ + return &RC_CHK_ACCESS(dso)->symbols; +} + +static inline struct symbol **dso__symbol_names(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->symbol_names; +} + +static inline void dso__set_symbol_names(struct dso *dso, struct symbol **= names) +{ + RC_CHK_ACCESS(dso)->symbol_names =3D names; +} + +static inline size_t dso__symbol_names_len(struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->symbol_names_len; +} + +static inline void dso__set_symbol_names_len(struct dso *dso, size_t len) +{ + RC_CHK_ACCESS(dso)->symbol_names_len =3D len; +} + +static inline const char *dso__symsrc_filename(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->symsrc_filename; +} + +static inline void dso__set_symsrc_filename(struct dso *dso, char *val) +{ + RC_CHK_ACCESS(dso)->symsrc_filename =3D val; +} + +static inline enum dso_binary_type dso__symtab_type(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->symtab_type; +} + +static inline void dso__set_symtab_type(struct dso *dso, enum dso_binary_t= ype bt) +{ + RC_CHK_ACCESS(dso)->symtab_type =3D bt; +} + +static inline u64 dso__text_end(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->text_end; +} + +static inline void dso__set_text_end(struct dso *dso, u64 val) +{ + RC_CHK_ACCESS(dso)->text_end =3D val; +} + +static inline u64 dso__text_offset(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->text_offset; +} + +static inline void dso__set_text_offset(struct dso *dso, u64 val) +{ + RC_CHK_ACCESS(dso)->text_offset =3D val; } =20 int dso_id__cmp(const struct dso_id *a, const struct dso_id *b); @@ -265,7 +649,7 @@ bool dso__loaded(const struct dso *dso); =20 static inline bool dso__has_symbols(const struct dso *dso) { - return !RB_EMPTY_ROOT(&dso->symbols.rb_root); + return !RB_EMPTY_ROOT(&RC_CHK_ACCESS(dso)->symbols.rb_root); } =20 char *dso__filename_with_chroot(const struct dso *dso, const char *filenam= e); @@ -381,21 +765,33 @@ void dso__reset_find_symbol_cache(struct dso *dso); size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp); size_t dso__fprintf(struct dso *dso, FILE *fp); =20 +static inline enum dso_binary_type dso__binary_type(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->binary_type; +} + +static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_t= ype bt) +{ + RC_CHK_ACCESS(dso)->binary_type =3D bt; +} + static inline bool dso__is_vmlinux(const struct dso *dso) { - return dso->binary_type =3D=3D DSO_BINARY_TYPE__VMLINUX || - dso->binary_type =3D=3D DSO_BINARY_TYPE__GUEST_VMLINUX; + enum dso_binary_type bt =3D dso__binary_type(dso); + + return bt =3D=3D DSO_BINARY_TYPE__VMLINUX || bt =3D=3D DSO_BINARY_TYPE__G= UEST_VMLINUX; } =20 static inline bool dso__is_kcore(const struct dso *dso) { - return dso->binary_type =3D=3D DSO_BINARY_TYPE__KCORE || - dso->binary_type =3D=3D DSO_BINARY_TYPE__GUEST_KCORE; + enum dso_binary_type bt =3D dso__binary_type(dso); + + return bt =3D=3D DSO_BINARY_TYPE__KCORE || bt =3D=3D DSO_BINARY_TYPE__GUE= ST_KCORE; } =20 static inline bool dso__is_kallsyms(const struct dso *dso) { - return dso->kernel && dso->long_name[0] !=3D '/'; + return RC_CHK_ACCESS(dso)->kernel && RC_CHK_ACCESS(dso)->long_name[0] != =3D '/'; } =20 bool dso__is_object_file(const struct dso *dso); diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index 23c3fe4f2abb..ab3d0c01dd63 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -29,8 +29,8 @@ static void dsos__purge(struct dsos *dsos) for (unsigned int i =3D 0; i < dsos->cnt; i++) { struct dso *dso =3D dsos->dsos[i]; =20 + dso__set_dsos(dso, NULL); dso__put(dso); - dso->dsos =3D NULL; } =20 zfree(&dsos->dsos); @@ -73,22 +73,22 @@ static int dsos__read_build_ids_cb(struct dso *dso, voi= d *data) struct dsos__read_build_ids_cb_args *args =3D data; struct nscookie nsc; =20 - if (args->with_hits && !dso->hit && !dso__is_vdso(dso)) + if (args->with_hits && !dso__hit(dso) && !dso__is_vdso(dso)) return 0; - if (dso->has_build_id) { + if (dso__has_build_id(dso)) { args->have_build_id =3D true; return 0; } - nsinfo__mountns_enter(dso->nsinfo, &nsc); - if (filename__read_build_id(dso->long_name, &dso->bid) > 0) { + nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); + if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0) { args->have_build_id =3D true; - dso->has_build_id =3D true; - } else if (errno =3D=3D ENOENT && dso->nsinfo) { - char *new_name =3D dso__filename_with_chroot(dso, dso->long_name); + dso__set_has_build_id(dso); + } else if (errno =3D=3D ENOENT && dso__nsinfo(dso)) { + char *new_name =3D dso__filename_with_chroot(dso, dso__long_name(dso)); =20 - if (new_name && filename__read_build_id(new_name, &dso->bid) > 0) { + if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0) { args->have_build_id =3D true; - dso->has_build_id =3D true; + dso__set_has_build_id(dso); } free(new_name); } @@ -110,27 +110,27 @@ bool dsos__read_build_ids(struct dsos *dsos, bool wit= h_hits) static int __dso__cmp_long_name(const char *long_name, const struct dso_id= *id, const struct dso *b) { - int rc =3D strcmp(long_name, b->long_name); - return rc ?: dso_id__cmp(id, &b->id); + int rc =3D strcmp(long_name, dso__long_name(b)); + return rc ?: dso_id__cmp(id, dso__id_const(b)); } =20 static int __dso__cmp_short_name(const char *short_name, const struct dso_= id *id, const struct dso *b) { - int rc =3D strcmp(short_name, b->short_name); - return rc ?: dso_id__cmp(id, &b->id); + int rc =3D strcmp(short_name, dso__short_name(b)); + return rc ?: dso_id__cmp(id, dso__id_const(b)); } =20 static int dsos__cmp_long_name_id_short_name(const void *va, const void *v= b) { const struct dso *a =3D *((const struct dso **)va); const struct dso *b =3D *((const struct dso **)vb); - int rc =3D strcmp(a->long_name, b->long_name); + int rc =3D strcmp(dso__long_name(a), dso__long_name(b)); =20 if (!rc) { - rc =3D dso_id__cmp(&a->id, &b->id); + rc =3D dso_id__cmp(dso__id_const(a), dso__id_const(b)); if (!rc) - rc =3D strcmp(a->short_name, b->short_name); + rc =3D strcmp(dso__short_name(a), dso__short_name(b)); } return rc; } @@ -209,7 +209,7 @@ int __dsos__add(struct dsos *dsos, struct dso *dso) &dsos->dsos[dsos->cnt - 1]) <=3D 0; } - dso->dsos =3D dsos; + dso__set_dsos(dso, dsos); return 0; } =20 @@ -275,7 +275,7 @@ static void dso__set_basename(struct dso *dso) char *base, *lname; int tid; =20 - if (sscanf(dso->long_name, "/tmp/perf-%d.map", &tid) =3D=3D 1) { + if (sscanf(dso__long_name(dso), "/tmp/perf-%d.map", &tid) =3D=3D 1) { if (asprintf(&base, "[JIT] tid %d", tid) < 0) return; } else { @@ -283,7 +283,7 @@ static void dso__set_basename(struct dso *dso) * basename() may modify path buffer, so we must pass * a copy. */ - lname =3D strdup(dso->long_name); + lname =3D strdup(dso__long_name(dso)); if (!lname) return; =20 @@ -322,7 +322,7 @@ static struct dso *__dsos__findnew_id(struct dsos *dsos= , const char *name, struc { struct dso *dso =3D __dsos__find_id(dsos, name, id, false, /*write_locked= =3D*/true); =20 - if (dso && dso_id__empty(&dso->id) && !dso_id__empty(id)) + if (dso && dso_id__empty(dso__id(dso)) && !dso_id__empty(id)) __dso__inject_id(dso, id); =20 return dso ? dso : __dsos__addnew_id(dsos, name, id); @@ -351,8 +351,8 @@ static int dsos__fprintf_buildid_cb(struct dso *dso, vo= id *data) =20 if (args->skip && args->skip(dso, args->parm)) return 0; - build_id__sprintf(&dso->bid, sbuild_id); - args->ret +=3D fprintf(args->fp, "%-40s %s\n", sbuild_id, dso->long_name); + build_id__sprintf(dso__bid(dso), sbuild_id); + args->ret +=3D fprintf(args->fp, "%-40s %s\n", sbuild_id, dso__long_name(= dso)); return 0; } =20 @@ -396,7 +396,7 @@ size_t dsos__fprintf(struct dsos *dsos, FILE *fp) =20 static int dsos__hit_all_cb(struct dso *dso, void *data __maybe_unused) { - dso->hit =3D true; + dso__set_hit(dso); return 0; } =20 @@ -432,7 +432,7 @@ struct dso *dsos__findnew_module_dso(struct dsos *dsos, dso__set_basename(dso); dso__set_module_info(dso, m, machine); dso__set_long_name(dso, strdup(filename), true); - dso->kernel =3D DSO_SPACE__KERNEL; + dso__set_kernel(dso, DSO_SPACE__KERNEL); __dsos__add(dsos, dso); =20 up_write(&dsos->lock); @@ -455,8 +455,8 @@ static int dsos__find_kernel_dso_cb(struct dso *dso, vo= id *data) * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. * is_kernel_module() treats it as a kernel cpumode. */ - if (!dso->kernel || - is_kernel_module(dso->long_name, PERF_RECORD_MISC_CPUMODE_UNKNOWN)) + if (!dso__kernel(dso) || + is_kernel_module(dso__long_name(dso), PERF_RECORD_MISC_CPUMODE_UNKNOW= N)) return 0; =20 *res =3D dso__get(dso); diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 198903157f9e..f32f9abf6344 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -726,7 +726,7 @@ int machine__resolve(struct machine *machine, struct ad= dr_location *al, dso =3D al->map ? map__dso(al->map) : NULL; dump_printf(" ...... dso: %s\n", dso - ? dso->long_name + ? dso__long_name(dso) : (al->level =3D=3D 'H' ? "[hypervisor]" : "")); =20 if (thread__is_filtered(thread)) @@ -750,10 +750,10 @@ int machine__resolve(struct machine *machine, struct = addr_location *al, if (al->map) { if (symbol_conf.dso_list && (!dso || !(strlist__has_entry(symbol_conf.dso_list, - dso->short_name) || - (dso->short_name !=3D dso->long_name && + dso__short_name(dso)) || + (dso__short_name(dso) !=3D dso__long_name(dso) && strlist__has_entry(symbol_conf.dso_list, - dso->long_name))))) { + dso__long_name(dso)))))) { al->filtered |=3D (1 << HIST_FILTER__DSO); } =20 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 3fe28edc3d01..55e9553861d0 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2308,7 +2308,7 @@ static int __event_process_build_id(struct perf_recor= d_header_build_id *bev, =20 build_id__init(&bid, bev->data, size); dso__set_build_id(dso, &bid); - dso->header_build_id =3D 1; + dso__set_header_build_id(dso, true); =20 if (dso_space !=3D DSO_SPACE__USER) { struct kmod_path m =3D { .name =3D NULL, }; @@ -2316,13 +2316,13 @@ static int __event_process_build_id(struct perf_rec= ord_header_build_id *bev, if (!kmod_path__parse_name(&m, filename) && m.kmod) dso__set_module_info(dso, &m, machine); =20 - dso->kernel =3D dso_space; + dso__set_kernel(dso, dso_space); free(m.name); } =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); pr_debug("build id event received for %s: %s [%zu]\n", - dso->long_name, sbuild_id, size); + dso__long_name(dso), sbuild_id, size); dso__put(dso); } =20 diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index fa359180ebf8..4ffa06b96338 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2128,7 +2128,7 @@ static bool hists__filter_entry_by_dso(struct hists *= hists, struct hist_entry *he) { if (hists->dso_filter !=3D NULL && - (he->ms.map =3D=3D NULL || map__dso(he->ms.map) !=3D hists->dso_filte= r)) { + (he->ms.map =3D=3D NULL || !RC_CHK_EQUAL(map__dso(he->ms.map), hists-= >dso_filter))) { he->filtered |=3D (1 << HIST_FILTER__DSO); return true; } @@ -2808,7 +2808,7 @@ int __hists__scnprintf_title(struct hists *hists, cha= r *bf, size_t size, bool sh } if (dso) printed +=3D scnprintf(bf + printed, size - printed, - ", DSO: %s", dso->short_name); + ", DSO: %s", dso__short_name(dso)); if (socket_id > -1) printed +=3D scnprintf(bf + printed, size - printed, ", Processor Socket: %d", socket_id); diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index f38893e0b036..04a291562b14 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -598,15 +598,15 @@ static struct auxtrace_cache *intel_pt_cache(struct d= so *dso, struct auxtrace_cache *c; unsigned int bits; =20 - if (dso->auxtrace_cache) - return dso->auxtrace_cache; + if (dso__auxtrace_cache(dso)) + return dso__auxtrace_cache(dso); =20 bits =3D intel_pt_cache_size(dso, machine); =20 /* Ignoring cache creation failure */ c =3D auxtrace_cache__new(bits, sizeof(struct intel_pt_cache_entry), 200); =20 - dso->auxtrace_cache =3D c; + dso__set_auxtrace_cache(dso, c); =20 return c; } @@ -650,7 +650,7 @@ intel_pt_cache_lookup(struct dso *dso, struct machine *= machine, u64 offset) if (!c) return NULL; =20 - return auxtrace_cache__lookup(dso->auxtrace_cache, offset); + return auxtrace_cache__lookup(dso__auxtrace_cache(dso), offset); } =20 static void intel_pt_cache_invalidate(struct dso *dso, struct machine *mac= hine, @@ -661,7 +661,7 @@ static void intel_pt_cache_invalidate(struct dso *dso, = struct machine *machine, if (!c) return; =20 - auxtrace_cache__remove(dso->auxtrace_cache, offset); + auxtrace_cache__remove(dso__auxtrace_cache(dso), offset); } =20 static inline bool intel_pt_guest_kernel_ip(uint64_t ip) @@ -820,8 +820,8 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn= *intel_pt_insn, } dso =3D map__dso(al.map); =20 - if (dso->data.status =3D=3D DSO_DATA_STATUS_ERROR && - dso__data_status_seen(dso, DSO_DATA_STATUS_SEEN_ITRACE)) { + if (dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR && + dso__data_status_seen(dso, DSO_DATA_STATUS_SEEN_ITRACE)) { ret =3D -ENOENT; goto out_ret; } @@ -854,7 +854,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn= *intel_pt_insn, /* Load maps to ensure dso->is_64_bit has been updated */ map__load(al.map); =20 - x86_64 =3D dso->is_64_bit; + x86_64 =3D dso__is_64_bit(dso); =20 while (1) { len =3D dso__data_read_offset(dso, machine, @@ -1008,7 +1008,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data) =20 offset =3D map__map_ip(al.map, ip); =20 - res =3D intel_pt_match_pgd_ip(ptq->pt, ip, offset, map__dso(al.map)->long= _name); + res =3D intel_pt_match_pgd_ip(ptq->pt, ip, offset, dso__long_name(map__ds= o(al.map))); addr_location__exit(&al); return res; } @@ -3416,7 +3416,7 @@ static int intel_pt_text_poke(struct intel_pt *pt, un= ion perf_event *event) } =20 dso =3D map__dso(al.map); - if (!dso || !dso->auxtrace_cache) + if (!dso || !dso__auxtrace_cache(dso)) continue; =20 offset =3D map__map_ip(al.map, addr); @@ -3436,7 +3436,7 @@ static int intel_pt_text_poke(struct intel_pt *pt, un= ion perf_event *event) } else { intel_pt_cache_invalidate(dso, machine, offset); intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n", - dso->long_name, addr); + dso__long_name(dso), addr); } } out: diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 97a0c21ba2a5..4153dc92154d 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -694,7 +694,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, err =3D -ENOMEM; goto out; } - dso->kernel =3D DSO_SPACE__KERNEL; + dso__set_kernel(dso, DSO_SPACE__KERNEL); map =3D map__new2(0, dso); dso__put(dso); if (!map) { @@ -702,8 +702,8 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, goto out; } if (event->ksymbol.ksym_type =3D=3D PERF_RECORD_KSYMBOL_TYPE_OOL) { - dso->binary_type =3D DSO_BINARY_TYPE__OOL; - dso->data.file_size =3D event->ksymbol.len; + dso__set_binary_type(dso, DSO_BINARY_TYPE__OOL); + dso__data(dso)->file_size =3D event->ksymbol.len; dso__set_loaded(dso); } =20 @@ -718,7 +718,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, dso__set_loaded(dso); =20 if (is_bpf_image(event->ksymbol.name)) { - dso->binary_type =3D DSO_BINARY_TYPE__BPF_IMAGE; + dso__set_binary_type(dso, DSO_BINARY_TYPE__BPF_IMAGE); dso__set_long_name(dso, "", false); } } else { @@ -888,17 +888,17 @@ size_t machine__fprintf_vmlinux_path(struct machine *= machine, FILE *fp) size_t printed =3D 0; struct dso *kdso =3D machine__kernel_dso(machine); =20 - if (kdso->has_build_id) { + if (dso__has_build_id(kdso)) { char filename[PATH_MAX]; - if (dso__build_id_filename(kdso, filename, sizeof(filename), - false)) + + if (dso__build_id_filename(kdso, filename, sizeof(filename), false)) printed +=3D fprintf(fp, "[0] %s\n", filename); } =20 - for (i =3D 0; i < vmlinux_path__nr_entries; ++i) - printed +=3D fprintf(fp, "[%d] %s\n", - i + kdso->has_build_id, vmlinux_path[i]); - + for (i =3D 0; i < vmlinux_path__nr_entries; ++i) { + printed +=3D fprintf(fp, "[%d] %s\n", i + dso__has_build_id(kdso), + vmlinux_path[i]); + } return printed; } =20 @@ -948,7 +948,7 @@ static struct dso *machine__get_kernel(struct machine *= machine) DSO_SPACE__KERNEL_GUEST); } =20 - if (kernel !=3D NULL && (!kernel->has_build_id)) + if (kernel !=3D NULL && (!dso__has_build_id(kernel))) dso__read_running_kernel_build_id(kernel, machine); =20 return kernel; @@ -1313,8 +1313,8 @@ static char *get_kernel_version(const char *root_dir) =20 static bool is_kmod_dso(struct dso *dso) { - return dso->symtab_type =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || - dso->symtab_type =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE; + return dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE = || + dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE; } =20 static int maps__set_module_path(struct maps *maps, const char *path, stru= ct kmod_path *m) @@ -1341,8 +1341,8 @@ static int maps__set_module_path(struct maps *maps, c= onst char *path, struct kmo * we need to update the symtab_type if needed. */ if (m->comp && is_kmod_dso(dso)) { - dso->symtab_type++; - dso->comp =3D m->comp; + dso__set_symtab_type(dso, dso__symtab_type(dso)); + dso__set_comp(dso, m->comp); } map__put(map); return 0; @@ -1643,13 +1643,13 @@ static int machine__process_kernel_mmap_event(struc= t machine *machine, if (kernel =3D=3D NULL) goto out_problem; =20 - kernel->kernel =3D dso_space; + dso__set_kernel(kernel, dso_space); if (__machine__create_kernel_maps(machine, kernel) < 0) { dso__put(kernel); goto out_problem; } =20 - if (strstr(kernel->long_name, "vmlinux")) + if (strstr(dso__long_name(kernel), "vmlinux")) dso__set_short_name(kernel, "[kernel.vmlinux]", false); =20 if (machine__update_kernel_mmap(machine, xm->start, xm->end) < 0) { @@ -2031,14 +2031,14 @@ static char *callchain_srcline(struct map_symbol *m= s, u64 ip) return srcline; =20 dso =3D map__dso(map); - srcline =3D srcline__tree_find(&dso->srclines, ip); + srcline =3D srcline__tree_find(dso__srclines(dso), ip); if (!srcline) { bool show_sym =3D false; bool show_addr =3D callchain_param.key =3D=3D CCKEY_ADDRESS; =20 srcline =3D get_srcline(dso, map__rip_2objdump(map, ip), ms->sym, show_sym, show_addr, ip); - srcline__tree_insert(&dso->srclines, ip, srcline); + srcline__tree_insert(dso__srclines(dso), ip, srcline); } =20 return srcline; @@ -2836,12 +2836,12 @@ static int append_inlines(struct callchain_cursor *= cursor, struct map_symbol *ms addr =3D map__rip_2objdump(map, addr); dso =3D map__dso(map); =20 - inline_node =3D inlines__tree_find(&dso->inlined_nodes, addr); + inline_node =3D inlines__tree_find(dso__inlined_nodes(dso), addr); if (!inline_node) { inline_node =3D dso__parse_addr_inlines(dso, addr, sym); if (!inline_node) return ret; - inlines__tree_insert(&dso->inlined_nodes, inline_node); + inlines__tree_insert(dso__inlined_nodes(dso), inline_node); } =20 ilist_ms =3D (struct map_symbol) { @@ -3130,7 +3130,7 @@ char *machine__resolve_kernel_addr(void *vmachine, un= signed long long *addrp, ch if (sym =3D=3D NULL) return NULL; =20 - *modp =3D __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NU= LL; + *modp =3D __map__is_kmodule(map) ? (char *)dso__short_name(map__dso(map))= : NULL; *addrp =3D map__unmap_ip(map, sym->start); return sym->name; } diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index cca871959f87..117c4bb78b35 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -168,7 +168,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, if (dso =3D=3D NULL) goto out_delete; =20 - assert(!dso->kernel); + assert(!dso__kernel(dso)); map__init(result, start, start + len, pgoff, dso); =20 if (anon || no_dso) { @@ -182,10 +182,9 @@ struct map *map__new(struct machine *machine, u64 star= t, u64 len, if (!(prot & PROT_EXEC)) dso__set_loaded(dso); } - mutex_lock(&dso->lock); - nsinfo__put(dso->nsinfo); - dso->nsinfo =3D nsi; - mutex_unlock(&dso->lock); + mutex_lock(dso__lock(dso)); + dso__set_nsinfo(dso, nsi); + mutex_unlock(dso__lock(dso)); =20 if (build_id__is_defined(bid)) { dso__set_build_id(dso, bid); @@ -197,9 +196,9 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, * have it missing. */ header_bid_dso =3D dsos__find(&machine->dsos, filename, false); - if (header_bid_dso && header_bid_dso->header_build_id) { - dso__set_build_id(dso, &header_bid_dso->bid); - dso->header_build_id =3D 1; + if (header_bid_dso && dso__header_build_id(header_bid_dso)) { + dso__set_build_id(dso, dso__bid(header_bid_dso)); + dso__set_header_build_id(dso, 1); } } dso__put(dso); @@ -221,7 +220,7 @@ struct map *map__new2(u64 start, struct dso *dso) struct map *result; RC_STRUCT(map) *map; =20 - map =3D calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0)); + map =3D calloc(1, sizeof(*map) + (dso__kernel(dso) ? sizeof(struct kmap) = : 0)); if (ADD_RC_CHK(result, map)) { /* * ->end will be filled after we load all the symbols @@ -234,7 +233,7 @@ struct map *map__new2(u64 start, struct dso *dso) =20 bool __map__is_kernel(const struct map *map) { - if (!map__dso(map)->kernel) + if (!dso__kernel(map__dso(map))) return false; return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) = =3D=3D map; } @@ -251,7 +250,7 @@ bool __map__is_bpf_prog(const struct map *map) const char *name; struct dso *dso =3D map__dso(map); =20 - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_PROG_INFO) return true; =20 /* @@ -259,7 +258,7 @@ bool __map__is_bpf_prog(const struct map *map) * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can * guess the type based on name. */ - name =3D dso->short_name; + name =3D dso__short_name(dso); return name && (strstr(name, "bpf_prog_") =3D=3D name); } =20 @@ -268,7 +267,7 @@ bool __map__is_bpf_image(const struct map *map) const char *name; struct dso *dso =3D map__dso(map); =20 - if (dso->binary_type =3D=3D DSO_BINARY_TYPE__BPF_IMAGE) + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__BPF_IMAGE) return true; =20 /* @@ -276,7 +275,7 @@ bool __map__is_bpf_image(const struct map *map) * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can * guess the type based on name. */ - name =3D dso->short_name; + name =3D dso__short_name(dso); return name && is_bpf_image(name); } =20 @@ -284,7 +283,7 @@ bool __map__is_ool(const struct map *map) { const struct dso *dso =3D map__dso(map); =20 - return dso && dso->binary_type =3D=3D DSO_BINARY_TYPE__OOL; + return dso && dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__OOL; } =20 bool map__has_symbols(const struct map *map) @@ -315,7 +314,7 @@ void map__put(struct map *map) void map__fixup_start(struct map *map) { struct dso *dso =3D map__dso(map); - struct rb_root_cached *symbols =3D &dso->symbols; + struct rb_root_cached *symbols =3D dso__symbols(dso); struct rb_node *nd =3D rb_first_cached(symbols); =20 if (nd !=3D NULL) { @@ -328,7 +327,7 @@ void map__fixup_start(struct map *map) void map__fixup_end(struct map *map) { struct dso *dso =3D map__dso(map); - struct rb_root_cached *symbols =3D &dso->symbols; + struct rb_root_cached *symbols =3D dso__symbols(dso); struct rb_node *nd =3D rb_last(&symbols->rb_root); =20 if (nd !=3D NULL) { @@ -342,7 +341,7 @@ void map__fixup_end(struct map *map) int map__load(struct map *map) { struct dso *dso =3D map__dso(map); - const char *name =3D dso->long_name; + const char *name =3D dso__long_name(dso); int nr; =20 if (dso__loaded(dso)) @@ -350,10 +349,10 @@ int map__load(struct map *map) =20 nr =3D dso__load(dso, map); if (nr < 0) { - if (dso->has_build_id) { + if (dso__has_build_id(dso)) { char sbuild_id[SBUILD_ID_SIZE]; =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); pr_debug("%s with build id %s not found", name, sbuild_id); } else pr_debug("Failed to open %s", name); @@ -415,7 +414,7 @@ struct map *map__clone(struct map *from) size_t size =3D sizeof(RC_STRUCT(map)); struct dso *dso =3D map__dso(from); =20 - if (dso && dso->kernel) + if (dso && dso__kernel(dso)) size +=3D sizeof(struct kmap); =20 map =3D memdup(RC_CHK_ACCESS(from), size); @@ -432,14 +431,14 @@ size_t map__fprintf(struct map *map, FILE *fp) const struct dso *dso =3D map__dso(map); =20 return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n", - map__start(map), map__end(map), map__pgoff(map), dso->name); + map__start(map), map__end(map), map__pgoff(map), dso__name(dso)); } =20 static bool prefer_dso_long_name(const struct dso *dso, bool print_off) { - return dso->long_name && + return dso__long_name(dso) && (symbol_conf.show_kernel_path || - (print_off && (dso->name[0] =3D=3D '[' || dso__is_kcore(dso)))); + (print_off && (dso__name(dso)[0] =3D=3D '[' || dso__is_kcore(dso)))); } =20 static size_t __map__fprintf_dsoname(struct map *map, bool print_off, FILE= *fp) @@ -450,9 +449,9 @@ static size_t __map__fprintf_dsoname(struct map *map, b= ool print_off, FILE *fp) =20 if (dso) { if (prefer_dso_long_name(dso, print_off)) - dsoname =3D dso->long_name; + dsoname =3D dso__long_name(dso); else - dsoname =3D dso->name; + dsoname =3D dso__name(dso); } =20 if (symbol_conf.pad_output_len_dso) { @@ -545,14 +544,14 @@ u64 map__rip_2objdump(struct map *map, u64 rip) } } =20 - if (!dso->adjust_symbols) + if (!dso__adjust_symbols(dso)) return rip; =20 - if (dso->rel) + if (dso__rel(dso)) return rip - map__pgoff(map); =20 - if (dso->kernel =3D=3D DSO_SPACE__USER) - return rip + dso->text_offset; + if (dso__kernel(dso) =3D=3D DSO_SPACE__USER) + return rip + dso__text_offset(dso); =20 return map__unmap_ip(map, rip) - map__reloc(map); } @@ -573,14 +572,14 @@ u64 map__objdump_2mem(struct map *map, u64 ip) { const struct dso *dso =3D map__dso(map); =20 - if (!dso->adjust_symbols) + if (!dso__adjust_symbols(dso)) return map__unmap_ip(map, ip); =20 - if (dso->rel) + if (dso__rel(dso)) return map__unmap_ip(map, ip + map__pgoff(map)); =20 - if (dso->kernel =3D=3D DSO_SPACE__USER) - return map__unmap_ip(map, ip - dso->text_offset); + if (dso__kernel(dso) =3D=3D DSO_SPACE__USER) + return map__unmap_ip(map, ip - dso__text_offset(dso)); =20 return ip + map__reloc(map); } @@ -590,14 +589,14 @@ u64 map__objdump_2rip(struct map *map, u64 ip) { const struct dso *dso =3D map__dso(map); =20 - if (!dso->adjust_symbols) + if (!dso__adjust_symbols(dso)) return ip; =20 - if (dso->rel) + if (dso__rel(dso)) return ip + map__pgoff(map); =20 - if (dso->kernel =3D=3D DSO_SPACE__USER) - return ip - dso->text_offset; + if (dso__kernel(dso) =3D=3D DSO_SPACE__USER) + return ip - dso__text_offset(dso); =20 return map__map_ip(map, ip + map__reloc(map)); } @@ -613,7 +612,7 @@ struct kmap *__map__kmap(struct map *map) { const struct dso *dso =3D map__dso(map); =20 - if (!dso || !dso->kernel) + if (!dso || !dso__kernel(dso)) return NULL; return (struct kmap *)(&RC_CHK_ACCESS(map)[1]); } diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index ce13145a9f8e..725300896f38 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -76,7 +76,7 @@ static void check_invariants(const struct maps *maps __ma= ybe_unused) /* Expect at least 1 reference count. */ assert(refcount_read(map__refcnt(map)) > 0); =20 - if (map__dso(map) && map__dso(map)->kernel) + if (map__dso(map) && dso__kernel(map__dso(map))) assert(RC_CHK_EQUAL(map__kmap(map)->kmaps, maps)); =20 if (i > 0) { @@ -346,7 +346,7 @@ static int map__strcmp(const void *a, const void *b) const struct map *map_b =3D *(const struct map * const *)b; const struct dso *dso_a =3D map__dso(map_a); const struct dso *dso_b =3D map__dso(map_b); - int ret =3D strcmp(dso_a->short_name, dso_b->short_name); + int ret =3D strcmp(dso__short_name(dso_a), dso__short_name(dso_b)); =20 if (ret =3D=3D 0 && RC_CHK_ACCESS(map_a) !=3D RC_CHK_ACCESS(map_b)) { /* Ensure distinct but name equal maps have an order. */ @@ -485,7 +485,7 @@ static int __maps__insert(struct maps *maps, struct map= *new) } if (map__end(new) < map__start(new)) RC_CHK_ACCESS(maps)->ends_broken =3D true; - if (dso && dso->kernel) { + if (dso && dso__kernel(dso)) { struct kmap *kmap =3D map__kmap(new); =20 if (kmap) @@ -766,7 +766,7 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) =20 if (use_browser) { pr_debug("overlapping maps in %s (disable tui for more info)\n", - map__dso(new)->name); + dso__name(map__dso(new))); } else if (verbose >=3D 2) { pr_debug("overlapping maps:\n"); map__fprintf(new, fp); @@ -987,7 +987,7 @@ static int map__strcmp_name(const void *name, const voi= d *b) { const struct dso *dso =3D map__dso(*(const struct map **)b); =20 - return strcmp(name, dso->short_name); + return strcmp(name, dso__short_name(dso)); } =20 struct map *maps__find_by_name(struct maps *maps, const char *name) @@ -1006,7 +1006,7 @@ struct map *maps__find_by_name(struct maps *maps, con= st char *name) if (i < maps__nr_maps(maps) && maps__maps_by_name(maps)) { struct dso *dso =3D map__dso(maps__maps_by_name(maps)[i]); =20 - if (dso && strcmp(dso->short_name, name) =3D=3D 0) { + if (dso && strcmp(dso__short_name(dso), name) =3D=3D 0) { result =3D map__get(maps__maps_by_name(maps)[i]); done =3D true; } @@ -1043,7 +1043,7 @@ struct map *maps__find_by_name(struct maps *maps, con= st char *name) struct map *pos =3D maps_by_address[i]; struct dso *dso =3D map__dso(pos); =20 - if (dso && strcmp(dso->short_name, name) =3D=3D 0) { + if (dso && strcmp(dso__short_name(dso), name) =3D=3D 0) { result =3D map__get(pos); break; } diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 2a0ad9ecf0a2..adf58a655f9b 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -158,8 +158,8 @@ static int kernel_get_module_map_cb(struct map *map, vo= id *data) { struct kernel_get_module_map_cb_args *args =3D data; struct dso *dso =3D map__dso(map); - const char *short_name =3D dso->short_name; /* short_name is "[module]" */ - u16 short_name_len =3D dso->short_name_len; + const char *short_name =3D dso__short_name(dso); + u16 short_name_len =3D dso__short_name_len(dso); =20 if (strncmp(short_name + 1, args->module, short_name_len - 2) =3D=3D 0 && args->module[short_name_len - 2] =3D=3D '\0') { @@ -201,10 +201,9 @@ struct map *get_target_map(const char *target, struct = nsinfo *nsi, bool user) map =3D dso__new_map(target); dso =3D map ? map__dso(map) : NULL; if (dso) { - mutex_lock(&dso->lock); - nsinfo__put(dso->nsinfo); - dso->nsinfo =3D nsinfo__get(nsi); - mutex_unlock(&dso->lock); + mutex_lock(dso__lock(dso)); + dso__set_nsinfo(dso, nsinfo__get(nsi)); + mutex_unlock(dso__lock(dso)); } return map; } else { @@ -367,11 +366,11 @@ static int kernel_get_module_dso(const char *module, = struct dso **pdso) =20 map =3D machine__kernel_map(host_machine); dso =3D map__dso(map); - if (!dso->has_build_id) + if (!dso__has_build_id(dso)) dso__read_running_kernel_build_id(dso, host_machine); =20 vmlinux_name =3D symbol_conf.vmlinux_name; - dso->load_errno =3D 0; + *dso__load_errno(dso) =3D 0; if (vmlinux_name) ret =3D dso__load_vmlinux(dso, map, vmlinux_name, false); else @@ -498,7 +497,7 @@ static struct debuginfo *open_from_debuginfod(struct ds= o *dso, struct nsinfo *ns if (!c) return NULL; =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); fd =3D debuginfod_find_debuginfo(c, (const unsigned char *)sbuild_id, 0, &path); if (fd >=3D 0) @@ -541,7 +540,7 @@ static struct debuginfo *open_debuginfo(const char *mod= ule, struct nsinfo *nsi, if (!module || !strchr(module, '/')) { err =3D kernel_get_module_dso(module, &dso); if (err < 0) { - if (!dso || dso->load_errno =3D=3D 0) { + if (!dso || *dso__load_errno(dso) =3D=3D 0) { if (!str_error_r(-err, reason, STRERR_BUFSIZE)) strcpy(reason, "(unknown)"); } else @@ -558,7 +557,7 @@ static struct debuginfo *open_debuginfo(const char *mod= ule, struct nsinfo *nsi, } return NULL; } - path =3D dso->long_name; + path =3D dso__long_name(dso); } nsinfo__mountns_enter(nsi, &nsc); ret =3D debuginfo__new(path); @@ -3794,8 +3793,8 @@ int show_available_funcs(const char *target, struct n= sinfo *nsi, /* Show all (filtered) symbols */ setup_pager(); =20 - for (size_t i =3D 0; i < dso->symbol_names_len; i++) { - struct symbol *pos =3D dso->symbol_names[i]; + for (size_t i =3D 0; i < dso__symbol_names_len(dso); i++) { + struct symbol *pos =3D dso__symbol_names(dso)[i]; =20 if (strfilter__compare(_filter, pos->name)) printf("%s\n", pos->name); diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index b072ac5d3bc2..e16257d5ab2c 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -320,10 +320,10 @@ static SV *perl_process_callchain(struct perf_sample = *sample, const char *dsoname =3D "[unknown]"; =20 if (dso) { - if (symbol_conf.show_kernel_path && dso->long_name) - dsoname =3D dso->long_name; + if (symbol_conf.show_kernel_path && dso__long_name(dso)) + dsoname =3D dso__long_name(dso); else - dsoname =3D dso->name; + dsoname =3D dso__name(dso); } if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) { hv_undef(elem); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 8aa301948de5..c2caa5720299 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -393,10 +393,10 @@ static const char *get_dsoname(struct map *map) struct dso *dso =3D map ? map__dso(map) : NULL; =20 if (dso) { - if (symbol_conf.show_kernel_path && dso->long_name) - dsoname =3D dso->long_name; + if (symbol_conf.show_kernel_path && dso__long_name(dso)) + dsoname =3D dso__long_name(dso); else - dsoname =3D dso->name; + dsoname =3D dso__name(dso); } =20 return dsoname; @@ -799,8 +799,9 @@ static void set_sym_in_dict(PyObject *dict, struct addr= _location *al, if (al->map) { struct dso *dso =3D map__dso(al->map); =20 - pydict_set_item_string_decref(dict, dso_field, _PyUnicode_FromString(dso= ->name)); - build_id__sprintf(&dso->bid, sbuild_id); + pydict_set_item_string_decref(dict, dso_field, + _PyUnicode_FromString(dso__name(dso))); + build_id__sprintf(dso__bid(dso), sbuild_id); pydict_set_item_string_decref(dict, dso_bid_field, _PyUnicode_FromString(sbuild_id)); pydict_set_item_string_decref(dict, dso_map_start, @@ -1246,14 +1247,14 @@ static int python_export_dso(struct db_export *dbe,= struct dso *dso, char sbuild_id[SBUILD_ID_SIZE]; PyObject *t; =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); =20 t =3D tuple_new(5); =20 - tuple_set_d64(t, 0, dso->db_id); + tuple_set_d64(t, 0, dso__db_id(dso)); tuple_set_d64(t, 1, machine->db_id); - tuple_set_string(t, 2, dso->short_name); - tuple_set_string(t, 3, dso->long_name); + tuple_set_string(t, 2, dso__short_name(dso)); + tuple_set_string(t, 3, dso__long_name(dso)); tuple_set_string(t, 4, sbuild_id); =20 call_object(tables->dso_handler, t, "dso_table"); @@ -1273,7 +1274,7 @@ static int python_export_symbol(struct db_export *dbe= , struct symbol *sym, t =3D tuple_new(6); =20 tuple_set_d64(t, 0, *sym_db_id); - tuple_set_d64(t, 1, dso->db_id); + tuple_set_d64(t, 1, dso__db_id(dso)); tuple_set_d64(t, 2, sym->start); tuple_set_d64(t, 3, sym->end); tuple_set_s32(t, 4, sym->binding); diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 92a1bd695e8a..944e67e4f84e 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -239,11 +239,11 @@ static int64_t _sort__dso_cmp(struct map *map_l, stru= ct map *map_r) return cmp_null(dso_r, dso_l); =20 if (verbose > 0) { - dso_name_l =3D dso_l->long_name; - dso_name_r =3D dso_r->long_name; + dso_name_l =3D dso__long_name(dso_l); + dso_name_r =3D dso__long_name(dso_r); } else { - dso_name_l =3D dso_l->short_name; - dso_name_r =3D dso_r->short_name; + dso_name_l =3D dso__short_name(dso_l); + dso_name_r =3D dso__short_name(dso_r); } =20 return strcmp(dso_name_l, dso_name_r); @@ -262,7 +262,7 @@ static int _hist_entry__dso_snprintf(struct map *map, c= har *bf, const char *dso_name =3D "[unknown]"; =20 if (dso) - dso_name =3D verbose > 0 ? dso->long_name : dso->short_name; + dso_name =3D verbose > 0 ? dso__long_name(dso) : dso__short_name(dso); =20 return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); } @@ -364,7 +364,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol = *ms, char o =3D dso ? dso__symtab_origin(dso) : '!'; u64 rip =3D ip; =20 - if (dso && dso->kernel && dso->adjust_symbols) + if (dso && dso__kernel(dso) && dso__adjust_symbols(dso)) rip =3D map__unmap_ip(map, ip); =20 ret +=3D repsep_snprintf(bf, size, "%-#*llx %c ", @@ -1586,8 +1586,8 @@ sort__dcacheline_cmp(struct hist_entry *left, struct = hist_entry *right) */ =20 if ((left->cpumode !=3D PERF_RECORD_MISC_KERNEL) && - (!(map__flags(l_map) & MAP_SHARED)) && !l_dso->id.maj && !l_dso->id.m= in && - !l_dso->id.ino && !l_dso->id.ino_generation) { + (!(map__flags(l_map) & MAP_SHARED)) && !dso__id(l_dso)->maj && !dso__= id(l_dso)->min && + !dso__id(l_dso)->ino && !dso__id(l_dso)->ino_generation) { /* userspace anonymous */ =20 if (thread__pid(left->thread) > thread__pid(right->thread)) @@ -1626,7 +1626,8 @@ static int hist_entry__dcacheline_snprintf(struct his= t_entry *he, char *bf, if ((he->cpumode !=3D PERF_RECORD_MISC_KERNEL) && map && !(map__prot(map) & PROT_EXEC) && (map__flags(map) & MAP_SHARED) && - (dso->id.maj || dso->id.min || dso->id.ino || dso->id.ino_generation= )) + (dso__id(dso)->maj || dso__id(dso)->min || dso__id(dso)->ino || + dso__id(dso)->ino_generation)) level =3D 's'; else if (!map) level =3D 'X'; diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index 7addc34afcf5..9d670d8c1c08 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -27,14 +27,14 @@ bool srcline_full_filename; =20 char *srcline__unknown =3D (char *)"??:0"; =20 -static const char *dso__name(struct dso *dso) +static const char *srcline_dso_name(struct dso *dso) { const char *dso_name; =20 - if (dso->symsrc_filename) - dso_name =3D dso->symsrc_filename; + if (dso__symsrc_filename(dso)) + dso_name =3D dso__symsrc_filename(dso); else - dso_name =3D dso->long_name; + dso_name =3D dso__long_name(dso); =20 if (dso_name[0] =3D=3D '[') return NULL; @@ -638,7 +638,7 @@ static int addr2line(const char *dso_name, u64 addr, struct inline_node *node, struct symbol *sym __maybe_unused) { - struct child_process *a2l =3D dso->a2l; + struct child_process *a2l =3D dso__a2l(dso); char *record_function =3D NULL; char *record_filename =3D NULL; unsigned int record_line_nr =3D 0; @@ -655,8 +655,9 @@ static int addr2line(const char *dso_name, u64 addr, if (!filename__has_section(dso_name, ".debug_line")) goto out; =20 - dso->a2l =3D addr2line_subprocess_init(symbol_conf.addr2line_path, dso_n= ame); - a2l =3D dso->a2l; + dso__set_a2l(dso, + addr2line_subprocess_init(symbol_conf.addr2line_path, dso_name)); + a2l =3D dso__a2l(dso); } =20 if (a2l =3D=3D NULL) { @@ -770,7 +771,7 @@ static int addr2line(const char *dso_name, u64 addr, free(record_function); free(record_filename); if (io.eof) { - dso->a2l =3D NULL; + dso__set_a2l(dso, NULL); addr2line_subprocess_cleanup(a2l); } return ret; @@ -778,14 +779,14 @@ static int addr2line(const char *dso_name, u64 addr, =20 void dso__free_a2l(struct dso *dso) { - struct child_process *a2l =3D dso->a2l; + struct child_process *a2l =3D dso__a2l(dso); =20 if (!a2l) return; =20 addr2line_subprocess_cleanup(a2l); =20 - dso->a2l =3D NULL; + dso__set_a2l(dso, NULL); } =20 #endif /* HAVE_LIBBFD_SUPPORT */ @@ -823,33 +824,34 @@ char *__get_srcline(struct dso *dso, u64 addr, struct= symbol *sym, char *srcline; const char *dso_name; =20 - if (!dso->has_srcline) + if (!dso__has_srcline(dso)) goto out; =20 - dso_name =3D dso__name(dso); + dso_name =3D srcline_dso_name(dso); if (dso_name =3D=3D NULL) - goto out; + goto out_err; =20 if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines, NULL, sym)) - goto out; + goto out_err; =20 srcline =3D srcline_from_fileline(file, line); free(file); =20 if (!srcline) - goto out; + goto out_err; =20 - dso->a2l_fails =3D 0; + dso__set_a2l_fails(dso, 0); =20 return srcline; =20 -out: - if (dso->a2l_fails && ++dso->a2l_fails > A2L_FAIL_LIMIT) { - dso->has_srcline =3D 0; +out_err: + dso__set_a2l_fails(dso, dso__a2l_fails(dso) + 1); + if (dso__a2l_fails(dso) > A2L_FAIL_LIMIT) { + dso__set_has_srcline(dso, false); dso__free_a2l(dso); } - +out: if (!show_addr) return (show_sym && sym) ? strndup(sym->name, sym->namelen) : SRCLINE_UNKNOWN; @@ -858,7 +860,7 @@ char *__get_srcline(struct dso *dso, u64 addr, struct s= ymbol *sym, if (asprintf(&srcline, "%s+%" PRIu64, show_sym ? sym->name : "", ip - sym->start) < 0) return SRCLINE_UNKNOWN; - } else if (asprintf(&srcline, "%s[%" PRIx64 "]", dso->short_name, addr) <= 0) + } else if (asprintf(&srcline, "%s[%" PRIx64 "]", dso__short_name(dso), ad= dr) < 0) return SRCLINE_UNKNOWN; return srcline; } @@ -869,22 +871,23 @@ char *get_srcline_split(struct dso *dso, u64 addr, un= signed *line) char *file =3D NULL; const char *dso_name; =20 - if (!dso->has_srcline) - goto out; + if (!dso__has_srcline(dso)) + return NULL; =20 - dso_name =3D dso__name(dso); + dso_name =3D srcline_dso_name(dso); if (dso_name =3D=3D NULL) - goto out; + goto out_err; =20 if (!addr2line(dso_name, addr, &file, line, dso, true, NULL, NULL)) - goto out; + goto out_err; =20 - dso->a2l_fails =3D 0; + dso__set_a2l_fails(dso, 0); return file; =20 -out: - if (dso->a2l_fails && ++dso->a2l_fails > A2L_FAIL_LIMIT) { - dso->has_srcline =3D 0; +out_err: + dso__set_a2l_fails(dso, dso__a2l_fails(dso) + 1); + if (dso__a2l_fails(dso) > A2L_FAIL_LIMIT) { + dso__set_has_srcline(dso, false); dso__free_a2l(dso); } =20 @@ -982,7 +985,7 @@ struct inline_node *dso__parse_addr_inlines(struct dso = *dso, u64 addr, { const char *dso_name; =20 - dso_name =3D dso__name(dso); + dso_name =3D srcline_dso_name(dso); if (dso_name =3D=3D NULL) return NULL; =20 diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 0b91f813c4fa..3be5e8d1e278 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -174,7 +174,7 @@ static inline bool elf_sec__is_data(const GElf_Shdr *sh= dr, =20 static bool elf_sec__filter(GElf_Shdr *shdr, Elf_Data *secstrs) { - return elf_sec__is_text(shdr, secstrs) ||=20 + return elf_sec__is_text(shdr, secstrs) || elf_sec__is_data(shdr, secstrs); } =20 @@ -312,8 +312,8 @@ static char *demangle_sym(struct dso *dso, int kmodule,= const char *elf_name) * DWARF DW_compile_unit has this, but we don't always have access * to it... */ - if (!want_demangle(dso->kernel || kmodule)) - return demangled; + if (!want_demangle(dso__kernel(dso) || kmodule)) + return demangled; =20 demangled =3D cxx_demangle_sym(elf_name, verbose > 0, verbose > 0); if (demangled =3D=3D NULL) { @@ -470,7 +470,7 @@ static bool get_plt_sizes(struct dso *dso, GElf_Ehdr *e= hdr, GElf_Shdr *shdr_plt, } if (*plt_entry_size) return true; - pr_debug("Missing PLT entry size for %s\n", dso->long_name); + pr_debug("Missing PLT entry size for %s\n", dso__long_name(dso)); return false; } =20 @@ -654,7 +654,7 @@ static int dso__synthesize_plt_got_symbols(struct dso *= dso, Elf *elf, sym =3D symbol__new(shdr.sh_offset + i, shdr.sh_entsize, STB_GLOBAL, STT= _FUNC, buf); if (!sym) goto out; - symbols__insert(&dso->symbols, sym); + symbols__insert(dso__symbols(dso), sym); } err =3D 0; out: @@ -708,7 +708,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct= symsrc *ss) plt_sym =3D symbol__new(shdr_plt.sh_offset, plt_header_size, STB_GLOBAL, = STT_FUNC, ".plt"); if (!plt_sym) goto out_elf_end; - symbols__insert(&dso->symbols, plt_sym); + symbols__insert(dso__symbols(dso), plt_sym); =20 /* Only x86 has .plt.got */ if (machine_is_x86(ehdr.e_machine) && @@ -830,7 +830,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct= symsrc *ss) goto out_elf_end; =20 plt_offset +=3D plt_entry_size; - symbols__insert(&dso->symbols, f); + symbols__insert(dso__symbols(dso), f); ++nr; } =20 @@ -840,7 +840,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct= symsrc *ss) if (err =3D=3D 0) return nr; pr_debug("%s: problems reading %s PLT info.\n", - __func__, dso->long_name); + __func__, dso__long_name(dso)); return 0; } =20 @@ -1175,19 +1175,19 @@ static int dso__swap_init(struct dso *dso, unsigned= char eidata) { static unsigned int const endian =3D 1; =20 - dso->needs_swap =3D DSO_SWAP__NO; + dso__set_needs_swap(dso, DSO_SWAP__NO); =20 switch (eidata) { case ELFDATA2LSB: /* We are big endian, DSO is little endian. */ if (*(unsigned char const *)&endian !=3D 1) - dso->needs_swap =3D DSO_SWAP__YES; + dso__set_needs_swap(dso, DSO_SWAP__YES); break; =20 case ELFDATA2MSB: /* We are little endian, DSO is big endian. */ if (*(unsigned char const *)&endian !=3D 0) - dso->needs_swap =3D DSO_SWAP__YES; + dso__set_needs_swap(dso, DSO_SWAP__YES); break; =20 default: @@ -1238,11 +1238,11 @@ int symsrc__init(struct symsrc *ss, struct dso *dso= , const char *name, if (fd < 0) return -1; =20 - type =3D dso->symtab_type; + type =3D dso__symtab_type(dso); } else { fd =3D open(name, O_RDONLY); if (fd < 0) { - dso->load_errno =3D errno; + *dso__load_errno(dso) =3D errno; return -1; } } @@ -1250,37 +1250,37 @@ int symsrc__init(struct symsrc *ss, struct dso *dso= , const char *name, elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); if (elf =3D=3D NULL) { pr_debug("%s: cannot read %s ELF file.\n", __func__, name); - dso->load_errno =3D DSO_LOAD_ERRNO__INVALID_ELF; + *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__INVALID_ELF; goto out_close; } =20 if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) { - dso->load_errno =3D DSO_LOAD_ERRNO__INVALID_ELF; + *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__INVALID_ELF; pr_debug("%s: cannot get elf header.\n", __func__); goto out_elf_end; } =20 if (dso__swap_init(dso, ehdr.e_ident[EI_DATA])) { - dso->load_errno =3D DSO_LOAD_ERRNO__INTERNAL_ERROR; + *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__INTERNAL_ERROR; goto out_elf_end; } =20 /* Always reject images with a mismatched build-id: */ - if (dso->has_build_id && !symbol_conf.ignore_vmlinux_buildid) { + if (dso__has_build_id(dso) && !symbol_conf.ignore_vmlinux_buildid) { u8 build_id[BUILD_ID_SIZE]; struct build_id bid; int size; =20 size =3D elf_read_build_id(elf, build_id, BUILD_ID_SIZE); if (size <=3D 0) { - dso->load_errno =3D DSO_LOAD_ERRNO__CANNOT_READ_BUILDID; + *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__CANNOT_READ_BUILDID; goto out_elf_end; } =20 build_id__init(&bid, build_id, size); if (!dso__build_id_equal(dso, &bid)) { pr_debug("%s: build id mismatch for %s.\n", __func__, name); - dso->load_errno =3D DSO_LOAD_ERRNO__MISMATCHING_BUILDID; + *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__MISMATCHING_BUILDID; goto out_elf_end; } } @@ -1305,14 +1305,14 @@ int symsrc__init(struct symsrc *ss, struct dso *dso= , const char *name, if (ss->opdshdr.sh_type !=3D SHT_PROGBITS) ss->opdsec =3D NULL; =20 - if (dso->kernel =3D=3D DSO_SPACE__USER) + if (dso__kernel(dso) =3D=3D DSO_SPACE__USER) ss->adjust_symbols =3D true; else ss->adjust_symbols =3D elf__needs_adjust_symbols(ehdr); =20 ss->name =3D strdup(name); if (!ss->name) { - dso->load_errno =3D errno; + *dso__load_errno(dso) =3D errno; goto out_elf_end; } =20 @@ -1432,7 +1432,7 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, if (adjust_kernel_syms) sym->st_value -=3D shdr->sh_addr - shdr->sh_offset; =20 - if (strcmp(section_name, (curr_dso->short_name + dso->short_name_len)) = =3D=3D 0) + if (strcmp(section_name, (dso__short_name(curr_dso) + dso__short_name_len= (dso))) =3D=3D 0) return 0; =20 if (strcmp(section_name, ".text") =3D=3D 0) { @@ -1441,7 +1441,7 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, * kallsyms and identity maps. Overwrite it to * map to the kernel dso. */ - if (*remap_kernel && dso->kernel && !kmodule) { + if (*remap_kernel && dso__kernel(dso) && !kmodule) { *remap_kernel =3D false; map__set_start(map, shdr->sh_addr + ref_reloc(kmap)); map__set_end(map, map__start(map) + shdr->sh_size); @@ -1489,7 +1489,7 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, return 0; } =20 - snprintf(dso_name, sizeof(dso_name), "%s%s", dso->short_name, section_nam= e); + snprintf(dso_name, sizeof(dso_name), "%s%s", dso__short_name(dso), sectio= n_name); =20 curr_map =3D maps__find_by_name(kmaps, dso_name); if (curr_map =3D=3D NULL) { @@ -1501,17 +1501,17 @@ static int dso__process_kernel_symbol(struct dso *d= so, struct map *map, curr_dso =3D dso__new(dso_name); if (curr_dso =3D=3D NULL) return -1; - curr_dso->kernel =3D dso->kernel; - curr_dso->long_name =3D dso->long_name; - curr_dso->long_name_len =3D dso->long_name_len; - curr_dso->binary_type =3D dso->binary_type; - curr_dso->adjust_symbols =3D dso->adjust_symbols; + dso__set_kernel(curr_dso, dso__kernel(dso)); + RC_CHK_ACCESS(curr_dso)->long_name =3D dso__long_name(dso); + RC_CHK_ACCESS(curr_dso)->long_name_len =3D dso__long_name_len(dso); + dso__set_binary_type(curr_dso, dso__binary_type(dso)); + dso__set_adjust_symbols(curr_dso, dso__adjust_symbols(dso)); curr_map =3D map__new2(start, curr_dso); dso__put(curr_dso); if (curr_map =3D=3D NULL) return -1; =20 - if (curr_dso->kernel) + if (dso__kernel(curr_dso)) map__kmap(curr_map)->kmaps =3D kmaps; =20 if (adjust_kernel_syms) { @@ -1521,7 +1521,7 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, } else { map__set_mapping_type(curr_map, MAPPING_TYPE__IDENTITY); } - curr_dso->symtab_type =3D dso->symtab_type; + dso__set_symtab_type(curr_dso, dso__symtab_type(dso)); if (maps__insert(kmaps, curr_map)) return -1; /* @@ -1547,7 +1547,7 @@ static int dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *sy= ms_ss, struct symsrc *runtime_ss, int kmodule, int dynsym) { - struct kmap *kmap =3D dso->kernel ? map__kmap(map) : NULL; + struct kmap *kmap =3D dso__kernel(dso) ? map__kmap(map) : NULL; struct maps *kmaps =3D kmap ? map__kmaps(map) : NULL; struct map *curr_map =3D map; struct dso *curr_dso =3D dso; @@ -1581,8 +1581,8 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, =20 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, ".text", NULL)) { - dso->text_offset =3D tshdr.sh_addr - tshdr.sh_offset; - dso->text_end =3D tshdr.sh_offset + tshdr.sh_size; + dso__set_text_offset(dso, tshdr.sh_addr - tshdr.sh_offset); + dso__set_text_end(dso, tshdr.sh_offset + tshdr.sh_size); } =20 if (runtime_ss->opdsec) @@ -1641,16 +1641,16 @@ dso__load_sym_internal(struct dso *dso, struct map = *map, struct symsrc *syms_ss, * attempted to prelink vdso to its virtual address. */ if (dso__is_vdso(dso)) - map__set_reloc(map, map__start(map) - dso->text_offset); + map__set_reloc(map, map__start(map) - dso__text_offset(dso)); =20 - dso->adjust_symbols =3D runtime_ss->adjust_symbols || ref_reloc(kmap); + dso__set_adjust_symbols(dso, runtime_ss->adjust_symbols || ref_reloc(kmap= )); /* * Initial kernel and module mappings do not map to the dso. * Flag the fixups. */ - if (dso->kernel) { + if (dso__kernel(dso)) { remap_kernel =3D true; - adjust_kernel_syms =3D dso->adjust_symbols; + adjust_kernel_syms =3D dso__adjust_symbols(dso); } =20 if (kmodule && adjust_kernel_syms) @@ -1743,7 +1743,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, (sym.st_value & 1)) --sym.st_value; =20 - if (dso->kernel) { + if (dso__kernel(dso)) { if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &cur= r_dso, &curr_map, section_name, adjust_kernel_syms, kmodule, &remap_kernel, max_text_sh_offset)) @@ -1792,7 +1792,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, =20 arch__sym_update(f, &sym); =20 - __symbols__insert(&curr_dso->symbols, f, dso->kernel); + __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); nr++; } =20 @@ -1800,8 +1800,8 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, * For misannotated, zeroed, ASM function sizes. */ if (nr > 0) { - symbols__fixup_end(&dso->symbols, false); - symbols__fixup_duplicate(&dso->symbols); + symbols__fixup_end(dso__symbols(dso), false); + symbols__fixup_duplicate(dso__symbols(dso)); if (kmap) { /* * We need to fixup this here too because we create new @@ -1821,16 +1821,16 @@ int dso__load_sym(struct dso *dso, struct map *map,= struct symsrc *syms_ss, int nr =3D 0; int err =3D -1; =20 - dso->symtab_type =3D syms_ss->type; - dso->is_64_bit =3D syms_ss->is_64_bit; - dso->rel =3D syms_ss->ehdr.e_type =3D=3D ET_REL; + dso__set_symtab_type(dso, syms_ss->type); + dso__set_is_64_bit(dso, syms_ss->is_64_bit); + dso__set_rel(dso, syms_ss->ehdr.e_type =3D=3D ET_REL); =20 /* * Modules may already have symbols from kallsyms, but those symbols * have the wrong values for the dso maps, so remove them. */ if (kmodule && syms_ss->symtab) - symbols__delete(&dso->symbols); + symbols__delete(dso__symbols(dso)); =20 if (!syms_ss->symtab) { /* @@ -1838,7 +1838,7 @@ int dso__load_sym(struct dso *dso, struct map *map, s= truct symsrc *syms_ss, * to using kallsyms. The vmlinux runtime symbols aren't * of much use. */ - if (dso->kernel) + if (dso__kernel(dso)) return err; } else { err =3D dso__load_sym_internal(dso, map, syms_ss, runtime_ss, diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index 1da8b713509c..c6f369b5d893 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -273,7 +273,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, co= nst char *name, out_close: close(fd); out_errno: - dso->load_errno =3D errno; + RC_CHK_ACCESS(dso)->load_errno =3D errno; return -1; } =20 @@ -348,7 +348,7 @@ int dso__load_sym(struct dso *dso, struct map *map __ma= ybe_unused, =20 ret =3D fd__is_64_bit(ss->fd); if (ret >=3D 0) - dso->is_64_bit =3D ret; + RC_CHK_ACCESS(dso)->is_64_bit =3D ret; =20 if (filename__read_build_id(ss->name, &bid) > 0) dso__set_build_id(dso, &bid); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 9ebdb8e13c0b..c95fb69de096 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -532,52 +532,52 @@ static struct symbol *symbols__find_by_name(struct sy= mbol *symbols[], =20 void dso__reset_find_symbol_cache(struct dso *dso) { - dso->last_find_result.addr =3D 0; - dso->last_find_result.symbol =3D NULL; + dso__set_last_find_result_addr(dso, 0); + dso__set_last_find_result_symbol(dso, NULL); } =20 void dso__insert_symbol(struct dso *dso, struct symbol *sym) { - __symbols__insert(&dso->symbols, sym, dso->kernel); + __symbols__insert(dso__symbols(dso), sym, dso__kernel(dso)); =20 /* update the symbol cache if necessary */ - if (dso->last_find_result.addr >=3D sym->start && - (dso->last_find_result.addr < sym->end || + if (dso__last_find_result_addr(dso) >=3D sym->start && + (dso__last_find_result_addr(dso) < sym->end || sym->start =3D=3D sym->end)) { - dso->last_find_result.symbol =3D sym; + dso__set_last_find_result_symbol(dso, sym); } } =20 void dso__delete_symbol(struct dso *dso, struct symbol *sym) { - rb_erase_cached(&sym->rb_node, &dso->symbols); + rb_erase_cached(&sym->rb_node, dso__symbols(dso)); symbol__delete(sym); dso__reset_find_symbol_cache(dso); } =20 struct symbol *dso__find_symbol(struct dso *dso, u64 addr) { - if (dso->last_find_result.addr !=3D addr || dso->last_find_result.symbol = =3D=3D NULL) { - dso->last_find_result.addr =3D addr; - dso->last_find_result.symbol =3D symbols__find(&dso->symbols, addr); + if (dso__last_find_result_addr(dso) !=3D addr || dso__last_find_result_sy= mbol(dso) =3D=3D NULL) { + dso__set_last_find_result_addr(dso, addr); + dso__set_last_find_result_symbol(dso, symbols__find(dso__symbols(dso), a= ddr)); } =20 - return dso->last_find_result.symbol; + return dso__last_find_result_symbol(dso); } =20 struct symbol *dso__find_symbol_nocache(struct dso *dso, u64 addr) { - return symbols__find(&dso->symbols, addr); + return symbols__find(dso__symbols(dso), addr); } =20 struct symbol *dso__first_symbol(struct dso *dso) { - return symbols__first(&dso->symbols); + return symbols__first(dso__symbols(dso)); } =20 struct symbol *dso__last_symbol(struct dso *dso) { - return symbols__last(&dso->symbols); + return symbols__last(dso__symbols(dso)); } =20 struct symbol *dso__next_symbol(struct symbol *sym) @@ -587,11 +587,11 @@ struct symbol *dso__next_symbol(struct symbol *sym) =20 struct symbol *dso__next_symbol_by_name(struct dso *dso, size_t *idx) { - if (*idx + 1 >=3D dso->symbol_names_len) + if (*idx + 1 >=3D dso__symbol_names_len(dso)) return NULL; =20 ++*idx; - return dso->symbol_names[*idx]; + return dso__symbol_names(dso)[*idx]; } =20 /* @@ -599,27 +599,29 @@ struct symbol *dso__next_symbol_by_name(struct dso *d= so, size_t *idx) */ struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name,= size_t *idx) { - struct symbol *s =3D symbols__find_by_name(dso->symbol_names, dso->symbol= _names_len, - name, SYMBOL_TAG_INCLUDE__NONE, idx); - if (!s) - s =3D symbols__find_by_name(dso->symbol_names, dso->symbol_names_len, - name, SYMBOL_TAG_INCLUDE__DEFAULT_ONLY, idx); + struct symbol *s =3D symbols__find_by_name(dso__symbol_names(dso), + dso__symbol_names_len(dso), + name, SYMBOL_TAG_INCLUDE__NONE, idx); + if (!s) { + s =3D symbols__find_by_name(dso__symbol_names(dso), dso__symbol_names_le= n(dso), + name, SYMBOL_TAG_INCLUDE__DEFAULT_ONLY, idx); + } return s; } =20 void dso__sort_by_name(struct dso *dso) { - mutex_lock(&dso->lock); + mutex_lock(dso__lock(dso)); if (!dso__sorted_by_name(dso)) { size_t len; =20 - dso->symbol_names =3D symbols__sort_by_name(&dso->symbols, &len); - if (dso->symbol_names) { - dso->symbol_names_len =3D len; + dso__set_symbol_names(dso, symbols__sort_by_name(dso__symbols(dso), &len= )); + if (dso__symbol_names(dso)) { + dso__set_symbol_names_len(dso, len); dso__set_sorted_by_name(dso); } } - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); } =20 /* @@ -746,7 +748,7 @@ static int map__process_kallsym_symbol(void *arg, const= char *name, { struct symbol *sym; struct dso *dso =3D arg; - struct rb_root_cached *root =3D &dso->symbols; + struct rb_root_cached *root =3D dso__symbols(dso); =20 if (!symbol_type__filter(type)) return 0; @@ -786,8 +788,8 @@ static int maps__split_kallsyms_for_kcore(struct maps *= kmaps, struct dso *dso) { struct symbol *pos; int count =3D 0; - struct rb_root_cached old_root =3D dso->symbols; - struct rb_root_cached *root =3D &dso->symbols; + struct rb_root_cached *root =3D dso__symbols(dso); + struct rb_root_cached old_root =3D *root; struct rb_node *next =3D rb_first_cached(root); =20 if (!kmaps) @@ -821,13 +823,13 @@ static int maps__split_kallsyms_for_kcore(struct maps= *kmaps, struct dso *dso) pos->end =3D map__end(curr_map); if (pos->end) pos->end -=3D map__start(curr_map) - map__pgoff(curr_map); - symbols__insert(&curr_map_dso->symbols, pos); + symbols__insert(dso__symbols(curr_map_dso), pos); ++count; map__put(curr_map); } =20 /* Symbols have been adjusted */ - dso->adjust_symbols =3D 1; + dso__set_adjust_symbols(dso, true); =20 return count; } @@ -844,7 +846,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, struct map *curr_map =3D map__get(initial_map); struct symbol *pos; int count =3D 0, moved =3D 0; - struct rb_root_cached *root =3D &dso->symbols; + struct rb_root_cached *root =3D dso__symbols(dso); struct rb_node *next =3D rb_first_cached(root); int kernel_range =3D 0; bool x86_64; @@ -871,9 +873,9 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, =20 *module++ =3D '\0'; curr_map_dso =3D map__dso(curr_map); - if (strcmp(curr_map_dso->short_name, module)) { + if (strcmp(dso__short_name(curr_map_dso), module)) { if (!RC_CHK_EQUAL(curr_map, initial_map) && - dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST && + dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST && machine__is_default_guest(machine)) { /* * We assume all symbols of a module are @@ -896,7 +898,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, goto discard_symbol; } curr_map_dso =3D map__dso(curr_map); - if (curr_map_dso->loaded && + if (dso__loaded(curr_map_dso) && !machine__is_default_guest(machine)) goto discard_symbol; } @@ -932,7 +934,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, goto add_symbol; } =20 - if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) snprintf(dso_name, sizeof(dso_name), "[guest.kernel].%d", kernel_range++); @@ -946,7 +948,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, if (ndso =3D=3D NULL) return -1; =20 - ndso->kernel =3D dso->kernel; + dso__set_kernel(ndso, dso__kernel(dso)); =20 curr_map =3D map__new2(pos->start, ndso); if (curr_map =3D=3D NULL) { @@ -971,7 +973,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, struct dso *curr_map_dso =3D map__dso(curr_map); =20 rb_erase_cached(&pos->rb_node, root); - symbols__insert(&curr_map_dso->symbols, pos); + symbols__insert(dso__symbols(curr_map_dso), pos); ++moved; } else ++count; @@ -983,7 +985,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, } =20 if (!RC_CHK_EQUAL(curr_map, initial_map) && - dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST && + dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST && machine__is_default_guest(maps__machine(kmaps))) { dso__set_loaded(map__dso(curr_map)); } @@ -1157,7 +1159,7 @@ static int do_validate_kcore_modules_cb(struct map *o= ld_map, void *data) =20 dso =3D map__dso(old_map); /* Module must be in memory at the same address */ - mi =3D find_module(dso->short_name, modules); + mi =3D find_module(dso__short_name(dso), modules); if (!mi || mi->start !=3D map__start(old_map)) return -EINVAL; =20 @@ -1326,7 +1328,7 @@ static int dso__load_kcore(struct dso *dso, struct ma= p *map, &is_64_bit); if (err) goto out_err; - dso->is_64_bit =3D is_64_bit; + dso__set_is_64_bit(dso, is_64_bit); =20 if (list_empty(&md.maps)) { err =3D -EINVAL; @@ -1418,10 +1420,10 @@ static int dso__load_kcore(struct dso *dso, struct = map *map, * Set the data type and long name so that kcore can be read via * dso__data_read_addr(). */ - if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) - dso->binary_type =3D DSO_BINARY_TYPE__GUEST_KCORE; + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) + dso__set_binary_type(dso, DSO_BINARY_TYPE__GUEST_KCORE); else - dso->binary_type =3D DSO_BINARY_TYPE__KCORE; + dso__set_binary_type(dso, DSO_BINARY_TYPE__KCORE); dso__set_long_name(dso, strdup(kcore_filename), true); =20 close(fd); @@ -1482,13 +1484,13 @@ int __dso__load_kallsyms(struct dso *dso, const cha= r *filename, if (kallsyms__delta(kmap, filename, &delta)) return -1; =20 - symbols__fixup_end(&dso->symbols, true); - symbols__fixup_duplicate(&dso->symbols); + symbols__fixup_end(dso__symbols(dso), true); + symbols__fixup_duplicate(dso__symbols(dso)); =20 - if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) - dso->symtab_type =3D DSO_BINARY_TYPE__GUEST_KALLSYMS; + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) + dso__set_symtab_type(dso, DSO_BINARY_TYPE__GUEST_KALLSYMS); else - dso->symtab_type =3D DSO_BINARY_TYPE__KALLSYMS; + dso__set_symtab_type(dso, DSO_BINARY_TYPE__KALLSYMS); =20 if (!no_kcore && !dso__load_kcore(dso, map, filename)) return maps__split_kallsyms_for_kcore(kmap->kmaps, dso); @@ -1544,7 +1546,7 @@ static int dso__load_perf_map(const char *map_path, s= truct dso *dso) if (sym =3D=3D NULL) goto out_delete_line; =20 - symbols__insert(&dso->symbols, sym); + symbols__insert(dso__symbols(dso), sym); nr_syms++; } =20 @@ -1670,15 +1672,15 @@ int dso__load_bfd_symbols(struct dso *dso, const ch= ar *debugfile) if (!symbol) goto out_free; =20 - symbols__insert(&dso->symbols, symbol); + symbols__insert(dso__symbols(dso), symbol); } #ifdef bfd_get_section #undef bfd_asymbol_section #endif =20 - symbols__fixup_end(&dso->symbols, false); - symbols__fixup_duplicate(&dso->symbols); - dso->adjust_symbols =3D 1; + symbols__fixup_end(dso__symbols(dso), false); + symbols__fixup_duplicate(dso__symbols(dso)); + dso__set_adjust_symbols(dso); =20 err =3D 0; out_free: @@ -1701,17 +1703,17 @@ static bool dso__is_compatible_symtab_type(struct d= so *dso, bool kmod, case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: - return !kmod && dso->kernel =3D=3D DSO_SPACE__USER; + return !kmod && dso__kernel(dso) =3D=3D DSO_SPACE__USER; =20 case DSO_BINARY_TYPE__KALLSYMS: case DSO_BINARY_TYPE__VMLINUX: case DSO_BINARY_TYPE__KCORE: - return dso->kernel =3D=3D DSO_SPACE__KERNEL; + return dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL; =20 case DSO_BINARY_TYPE__GUEST_KALLSYMS: case DSO_BINARY_TYPE__GUEST_VMLINUX: case DSO_BINARY_TYPE__GUEST_KCORE: - return dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST; + return dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST; =20 case DSO_BINARY_TYPE__GUEST_KMODULE: case DSO_BINARY_TYPE__GUEST_KMODULE_COMP: @@ -1721,7 +1723,7 @@ static bool dso__is_compatible_symtab_type(struct dso= *dso, bool kmod, * kernel modules know their symtab type - it's set when * creating a module dso in machine__addnew_module_map(). */ - return kmod && dso->symtab_type =3D=3D type; + return kmod && dso__symtab_type(dso) =3D=3D type; =20 case DSO_BINARY_TYPE__BUILD_ID_CACHE: case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: @@ -1789,18 +1791,19 @@ int dso__load(struct dso *dso, struct map *map) struct build_id bid; struct nscookie nsc; char newmapname[PATH_MAX]; - const char *map_path =3D dso->long_name; + const char *map_path =3D dso__long_name(dso); =20 - mutex_lock(&dso->lock); - perfmap =3D strncmp(dso->name, "/tmp/perf-", 10) =3D=3D 0; + mutex_lock(dso__lock(dso)); + perfmap =3D strncmp(dso__name(dso), "/tmp/perf-", 10) =3D=3D 0; if (perfmap) { - if (dso->nsinfo && (dso__find_perf_map(newmapname, - sizeof(newmapname), &dso->nsinfo) =3D=3D 0)) { + if (dso__nsinfo(dso) && + (dso__find_perf_map(newmapname, sizeof(newmapname), + dso__nsinfo_ptr(dso)) =3D=3D 0)) { map_path =3D newmapname; } } =20 - nsinfo__mountns_enter(dso->nsinfo, &nsc); + nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); =20 /* check again under the dso->lock */ if (dso__loaded(dso)) { @@ -1808,15 +1811,15 @@ int dso__load(struct dso *dso, struct map *map) goto out; } =20 - kmod =3D dso->symtab_type =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || - dso->symtab_type =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || - dso->symtab_type =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE || - dso->symtab_type =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE_COMP; + kmod =3D dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODUL= E || + dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || + dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE || + dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__GUEST_KMODULE_COMP; =20 - if (dso->kernel && !kmod) { - if (dso->kernel =3D=3D DSO_SPACE__KERNEL) + if (dso__kernel(dso) && !kmod) { + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL) ret =3D dso__load_kernel_sym(dso, map); - else if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) + else if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) ret =3D dso__load_guest_kernel_sym(dso, map); =20 machine =3D maps__machine(map__kmaps(map)); @@ -1825,12 +1828,13 @@ int dso__load(struct dso *dso, struct map *map) goto out; } =20 - dso->adjust_symbols =3D 0; + dso__set_adjust_symbols(dso, false); =20 if (perfmap) { ret =3D dso__load_perf_map(map_path, dso); - dso->symtab_type =3D ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT : - DSO_BINARY_TYPE__NOT_FOUND; + dso__set_symtab_type(dso, ret > 0 + ? DSO_BINARY_TYPE__JAVA_JIT + : DSO_BINARY_TYPE__NOT_FOUND); goto out; } =20 @@ -1845,9 +1849,9 @@ int dso__load(struct dso *dso, struct map *map) * Read the build id if possible. This is required for * DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work */ - if (!dso->has_build_id && - is_regular_file(dso->long_name)) { - __symbol__join_symfs(name, PATH_MAX, dso->long_name); + if (!dso__has_build_id(dso) && + is_regular_file(dso__long_name(dso))) { + __symbol__join_symfs(name, PATH_MAX, dso__long_name(dso)); if (filename__read_build_id(name, &bid) > 0) dso__set_build_id(dso, &bid); } @@ -1881,7 +1885,7 @@ int dso__load(struct dso *dso, struct map *map) nsinfo__mountns_exit(&nsc); =20 is_reg =3D is_regular_file(name); - if (!is_reg && errno =3D=3D ENOENT && dso->nsinfo) { + if (!is_reg && errno =3D=3D ENOENT && dso__nsinfo(dso)) { char *new_name =3D dso__filename_with_chroot(dso, name); if (new_name) { is_reg =3D is_regular_file(new_name); @@ -1898,7 +1902,7 @@ int dso__load(struct dso *dso, struct map *map) sirc =3D symsrc__init(ss, dso, name, symtab_type); =20 if (nsexit) - nsinfo__mountns_enter(dso->nsinfo, &nsc); + nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); =20 if (bfdrc =3D=3D 0) { ret =3D 0; @@ -1911,8 +1915,8 @@ int dso__load(struct dso *dso, struct map *map) if (!syms_ss && symsrc__has_symtab(ss)) { syms_ss =3D ss; next_slot =3D true; - if (!dso->symsrc_filename) - dso->symsrc_filename =3D strdup(name); + if (!dso__symsrc_filename(dso)) + dso__set_symsrc_filename(dso, strdup(name)); } =20 if (!runtime_ss && symsrc__possibly_runtime(ss)) { @@ -1959,11 +1963,11 @@ int dso__load(struct dso *dso, struct map *map) symsrc__destroy(&ss_[ss_pos - 1]); out_free: free(name); - if (ret < 0 && strstr(dso->name, " (deleted)") !=3D NULL) + if (ret < 0 && strstr(dso__name(dso), " (deleted)") !=3D NULL) ret =3D 0; out: dso__set_loaded(dso); - mutex_unlock(&dso->lock); + mutex_unlock(dso__lock(dso)); nsinfo__mountns_exit(&nsc); =20 return ret; @@ -1982,7 +1986,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *ma= p, else symbol__join_symfs(symfs_vmlinux, vmlinux); =20 - if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) symtab_type =3D DSO_BINARY_TYPE__GUEST_VMLINUX; else symtab_type =3D DSO_BINARY_TYPE__VMLINUX; @@ -1995,10 +1999,10 @@ int dso__load_vmlinux(struct dso *dso, struct map *= map, * an incorrect long name unless we set it here first. */ dso__set_long_name(dso, vmlinux, vmlinux_allocated); - if (dso->kernel =3D=3D DSO_SPACE__KERNEL_GUEST) - dso->binary_type =3D DSO_BINARY_TYPE__GUEST_VMLINUX; + if (dso__kernel(dso) =3D=3D DSO_SPACE__KERNEL_GUEST) + dso__set_binary_type(dso, DSO_BINARY_TYPE__GUEST_VMLINUX); else - dso->binary_type =3D DSO_BINARY_TYPE__VMLINUX; + dso__set_binary_type(dso, DSO_BINARY_TYPE__VMLINUX); =20 err =3D dso__load_sym(dso, map, &ss, &ss, 0); symsrc__destroy(&ss); @@ -2091,7 +2095,7 @@ static char *dso__find_kallsyms(struct dso *dso, stru= ct map *map) bool is_host =3D false; char path[PATH_MAX]; =20 - if (!dso->has_build_id) { + if (!dso__has_build_id(dso)) { /* * Last resort, if we don't have a build-id and couldn't find * any vmlinux file, try the running kernel kallsyms table. @@ -2116,7 +2120,7 @@ static char *dso__find_kallsyms(struct dso *dso, stru= ct map *map) goto proc_kallsyms; } =20 - build_id__sprintf(&dso->bid, sbuild_id); + build_id__sprintf(dso__bid(dso), sbuild_id); =20 /* Find kallsyms in build-id cache with kcore */ scnprintf(path, sizeof(path), "%s/%s/%s", @@ -2209,7 +2213,7 @@ static int dso__load_kernel_sym(struct dso *dso, stru= ct map *map) free(kallsyms_allocated_filename); =20 if (err > 0 && !dso__is_kcore(dso)) { - dso->binary_type =3D DSO_BINARY_TYPE__KALLSYMS; + dso__set_binary_type(dso, DSO_BINARY_TYPE__KALLSYMS); dso__set_long_name(dso, DSO__NAME_KALLSYMS, false); map__fixup_start(map); map__fixup_end(map); @@ -2252,7 +2256,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso= , struct map *map) if (err > 0) pr_debug("Using %s for symbols\n", kallsyms_filename); if (err > 0 && !dso__is_kcore(dso)) { - dso->binary_type =3D DSO_BINARY_TYPE__GUEST_KALLSYMS; + dso__set_binary_type(dso, DSO_BINARY_TYPE__GUEST_KALLSYMS); dso__set_long_name(dso, machine->mmap_name, false); map__fixup_start(map); map__fixup_end(map); diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fpri= ntf.c index 088f4abf230f..53e1af4ed9ac 100644 --- a/tools/perf/util/symbol_fprintf.c +++ b/tools/perf/util/symbol_fprintf.c @@ -64,8 +64,8 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso, { size_t ret =3D 0; =20 - for (size_t i =3D 0; i < dso->symbol_names_len; i++) { - struct symbol *pos =3D dso->symbol_names[i]; + for (size_t i =3D 0; i < dso__symbol_names_len(dso); i++) { + struct symbol *pos =3D dso__symbol_names(dso)[i]; =20 ret +=3D fprintf(fp, "%s\n", pos->name); } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 2a0289c14959..5498048f56ea 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -385,8 +385,8 @@ static void perf_record_mmap2__read_build_id(struct per= f_record_mmap2 *event, id.ino_generation =3D event->ino_generation; =20 dso =3D dsos__findnew_id(&machine->dsos, event->filename, &id); - if (dso && dso->has_build_id) { - bid =3D dso->bid; + if (dso && dso__has_build_id(dso)) { + bid =3D *dso__bid(dso); rc =3D 0; goto out; } @@ -407,7 +407,7 @@ static void perf_record_mmap2__read_build_id(struct per= f_record_mmap2 *event, event->__reserved_1 =3D 0; event->__reserved_2 =3D 0; =20 - if (dso && !dso->has_build_id) + if (dso && !dso__has_build_id(dso)) dso__set_build_id(dso, &bid); } else { if (event->filename[0] =3D=3D '/') { @@ -684,7 +684,7 @@ static int perf_event__synthesize_modules_maps_cb(struc= t map *map, void *data) =20 dso =3D map__dso(map); if (symbol_conf.buildid_mmap2) { - size =3D PERF_ALIGN(dso->long_name_len + 1, sizeof(u64)); + size =3D PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64)); event->mmap2.header.type =3D PERF_RECORD_MMAP2; event->mmap2.header.size =3D (sizeof(event->mmap2) - (sizeof(event->mmap2.filename) - size)); @@ -694,11 +694,11 @@ static int perf_event__synthesize_modules_maps_cb(str= uct map *map, void *data) event->mmap2.len =3D map__size(map); event->mmap2.pid =3D args->machine->pid; =20 - memcpy(event->mmap2.filename, dso->long_name, dso->long_name_len + 1); + memcpy(event->mmap2.filename, dso__long_name(dso), dso__long_name_len(ds= o) + 1); =20 perf_record_mmap2__read_build_id(&event->mmap2, args->machine, false); } else { - size =3D PERF_ALIGN(dso->long_name_len + 1, sizeof(u64)); + size =3D PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64)); event->mmap.header.type =3D PERF_RECORD_MMAP; event->mmap.header.size =3D (sizeof(event->mmap) - (sizeof(event->mmap.filename) - size)); @@ -708,7 +708,7 @@ static int perf_event__synthesize_modules_maps_cb(struc= t map *map, void *data) event->mmap.len =3D map__size(map); event->mmap.pid =3D args->machine->pid; =20 - memcpy(event->mmap.filename, dso->long_name, dso->long_name_len + 1); + memcpy(event->mmap.filename, dso__long_name(dso), dso__long_name_len(dso= ) + 1); } =20 if (perf_tool__process_synth_event(args->tool, event, args->machine, args= ->process) !=3D 0) @@ -2231,20 +2231,20 @@ int perf_event__synthesize_build_id(struct perf_too= l *tool, struct dso *pos, u16 union perf_event ev; size_t len; =20 - if (!pos->hit) + if (!dso__hit(pos)) return 0; =20 memset(&ev, 0, sizeof(ev)); =20 - len =3D pos->long_name_len + 1; + len =3D dso__long_name_len(pos) + 1; len =3D PERF_ALIGN(len, NAME_ALIGN); - ev.build_id.size =3D min(pos->bid.size, sizeof(pos->bid.data)); - memcpy(&ev.build_id.build_id, pos->bid.data, ev.build_id.size); + ev.build_id.size =3D min(dso__bid(pos)->size, sizeof(dso__bid(pos)->data)= ); + memcpy(&ev.build_id.build_id, dso__bid(pos)->data, ev.build_id.size); ev.build_id.header.type =3D PERF_RECORD_HEADER_BUILD_ID; ev.build_id.header.misc =3D misc | PERF_RECORD_MISC_BUILD_ID_SIZE; ev.build_id.pid =3D machine->pid; ev.build_id.header.size =3D sizeof(ev.build_id) + len; - memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); + memcpy(&ev.build_id.filename, dso__long_name(pos), dso__long_name_len(pos= )); =20 return process(tool, &ev, NULL, machine); } diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1aa8962dcf52..0a473112f881 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -457,14 +457,14 @@ int thread__memcpy(struct thread *thread, struct mach= ine *machine, =20 dso =3D map__dso(al.map); =20 - if (!dso || dso->data.status =3D=3D DSO_DATA_STATUS_ERROR || map__load(al= .map) < 0) { + if (!dso || dso__data(dso)->status =3D=3D DSO_DATA_STATUS_ERROR || map__l= oad(al.map) < 0) { addr_location__exit(&al); return -1; } =20 offset =3D map__map_ip(al.map, ip); if (is64bit) - *is64bit =3D dso->is_64_bit; + *is64bit =3D dso__is_64_bit(dso); =20 addr_location__exit(&al); =20 diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unw= ind-libunwind-local.c index 6a5ac0faa6f4..cde267ea3e99 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -329,27 +329,27 @@ static int read_unwind_spec_eh_frame(struct dso *dso,= struct unwind_info *ui, }; int ret, fd; =20 - if (dso->data.eh_frame_hdr_offset =3D=3D 0) { + if (dso__data(dso)->eh_frame_hdr_offset =3D=3D 0) { fd =3D dso__data_get_fd(dso, ui->machine); if (fd < 0) return -EINVAL; =20 /* Check the .eh_frame section for unwinding info */ ret =3D elf_section_address_and_offset(fd, ".eh_frame_hdr", - &dso->data.eh_frame_hdr_addr, - &dso->data.eh_frame_hdr_offset); - dso->data.elf_base_addr =3D elf_base_address(fd); + &dso__data(dso)->eh_frame_hdr_addr, + &dso__data(dso)->eh_frame_hdr_offset); + dso__data(dso)->elf_base_addr =3D elf_base_address(fd); dso__data_put_fd(dso); - if (ret || dso->data.eh_frame_hdr_offset =3D=3D 0) + if (ret || dso__data(dso)->eh_frame_hdr_offset =3D=3D 0) return -EINVAL; } =20 maps__for_each_map(thread__maps(ui->thread), read_unwind_spec_eh_frame_ma= ps_cb, &args); =20 - args.base_addr -=3D dso->data.elf_base_addr; + args.base_addr -=3D dso__data(dso)->elf_base_addr; /* Address of .eh_frame_hdr */ - *segbase =3D args.base_addr + dso->data.eh_frame_hdr_addr; - ret =3D unwind_spec_ehframe(dso, ui->machine, dso->data.eh_frame_hdr_offs= et, + *segbase =3D args.base_addr + dso__data(dso)->eh_frame_hdr_addr; + ret =3D unwind_spec_ehframe(dso, ui->machine, dso__data(dso)->eh_frame_hd= r_offset, table_data, fde_count); if (ret) return ret; @@ -460,7 +460,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_= proc_info_t *pi, return -EINVAL; } =20 - pr_debug("unwind: find_proc_info dso %s\n", dso->name); + pr_debug("unwind: find_proc_info dso %s\n", dso__name(dso)); =20 /* Check the .eh_frame section for unwinding info */ if (!read_unwind_spec_eh_frame(dso, ui, &table_data, &segbase, &fde_count= )) { diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-li= bunwind.c index 2728eb4f13ea..cb8be6acfb6f 100644 --- a/tools/perf/util/unwind-libunwind.c +++ b/tools/perf/util/unwind-libunwind.c @@ -25,7 +25,7 @@ int unwind__prepare_access(struct maps *maps, struct map = *map, bool *initialized return 0; =20 if (maps__addr_space(maps)) { - pr_debug("unwind: thread map already set, dso=3D%s\n", dso->name); + pr_debug("unwind: thread map already set, dso=3D%s\n", dso__name(dso)); if (initialized) *initialized =3D true; return 0; diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index 35532dcbff74..1b6f8f6db7aa 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c @@ -148,7 +148,7 @@ static int machine__thread_dso_type_maps_cb(struct map = *map, void *data) struct machine__thread_dso_type_maps_cb_args *args =3D data; struct dso *dso =3D map__dso(map); =20 - if (!dso || dso->long_name[0] !=3D '/') + if (!dso || dso__long_name(dso)[0] !=3D '/') return 0; =20 args->dso_type =3D dso__type(dso, args->machine); @@ -361,7 +361,7 @@ struct dso *machine__findnew_vdso(struct machine *machi= ne, =20 bool dso__is_vdso(struct dso *dso) { - return !strcmp(dso->short_name, DSO__NAME_VDSO) || - !strcmp(dso->short_name, DSO__NAME_VDSO32) || - !strcmp(dso->short_name, DSO__NAME_VDSOX32); + return !strcmp(dso__short_name(dso), DSO__NAME_VDSO) || + !strcmp(dso__short_name(dso), DSO__NAME_VDSO32) || + !strcmp(dso__short_name(dso), DSO__NAME_VDSOX32); } --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 7A3AC12C540 for ; Thu, 21 Mar 2024 16:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037020; cv=none; b=YmL4vSq9Ol+wBH4ZPq+kg+9w+A/u7zcepL/luFbf4bqDy7r5mrTxpTrOwMu4BJLCuNXr3SCC0qYkQlCcgWn9g7jCtVm8pNDVgZ2UYxDbtOApdjkzp2gEYnAoqbVFwhyK6sc+2rubwZuThg3jvhzoKU2Utwg+5+K98FxtdC0LXuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037020; c=relaxed/simple; bh=ajfSGUSK6Jil7GSQtwCQravAQoMFTLhTKffJm6L2W5M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SfmebcO3IdfIUxHDK16H/TRBVXJR/9AWQYHWUsJerzhXDxcuA2/t/tldAe86+D8Lha9BiX6STAl0CIBcJNGGKH9zKwt8OH4fcBdJpfGtTAzsCZFkhdeEh1rEgZGpZMVILvyqKuQKci/1rollKFpyd2AjyGrGg0KNCYWoC+1o+ns= 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=bTbHfMCF; arc=none smtp.client-ip=209.85.128.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="bTbHfMCF" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60ccc3cfa39so16175027b3.2 for ; Thu, 21 Mar 2024 09:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037017; x=1711641817; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=QSWFRUv0PmSjQhtJM1Pggtzo9mpMbnZ+euPjjZfflDg=; b=bTbHfMCFfb2XhbYsJtaS2OLd7sB9Ai+3LjOQwzrN6gjgQ8EVsQBGG7S79C0LcwAMDE GZTZZnaSf1HrzfkBRBYHruqgHCEjsNav1i4Yu11kxRp0IE3aozDnU8n5FK8ItQGc9LXy /FWrC5iD9TuRgD4ow97vUSIV9z3hOi61uXVKFKp0TDdycqGY6V0PiNq5vdk9jKzzXD+T A5AJxkzN+0J4LUQXBPQbUdxYRjuYgz6NNEj25T2h1x19gnF2Kb2CWJSBR6WLkmMk/cCp pXAGyNS1Li/AwZ026fqsuQ7+fiqrShAF/ROn6Oit6jzhlb80uhg9uRUXvAS+ZzAaeAd3 AZwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037017; x=1711641817; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QSWFRUv0PmSjQhtJM1Pggtzo9mpMbnZ+euPjjZfflDg=; b=Q7CiyvAelvMaZd76jGnrOqq0fl6ulZQeX8ZP4CPXW9ymTsJLAPaJ22re+lXCqbr+cm 7BqjnpEc2DYppQbCJ5j4xZdnLCoOUDEPM9oM2EWIFcrxv0Ehebj2sWipsvtv+uXRR+ME 43HVgPPXp25JpsF+BQm1NwvZnTz6tIKIZ0YkW+pioeqvWocnL8vnLZ5gMNHl0AeI5DVn 4VTHgnuRMpL2KTEEMpxXZr92tPotqDO24vOIOyIa7PS8d+V3S2/1ol4GxvPtL8nAsyve O52jwUAtEorweyPdYv0SQEJRlRgaUmiOGVmdAtdwWI6TYFxyBVamySst8bG0PhBiz/NA tzGw== X-Forwarded-Encrypted: i=1; AJvYcCXjY43aQN3IfjHAEV5JRpi6hD/epnT8BdLaIQnwxid9vwO5I5/hSqjx7CsOK7s9FF5L13odVlKcIPh4fScsSs1Y6rGbQWgHiFWUOTIG X-Gm-Message-State: AOJu0YxS9wBNA6F9a0rJDFdXW9+ZgFuMg7TDRD1Fy0dxu4H4HIzcY+eo yx4WD1tjM83p/8JTSEaDGp+HUYz80aXRbXlRgoMKGJIiLEZVloBU+6mYKSrGg1PzQ+N5TeJGmKG C2/PKNA== X-Google-Smtp-Source: AGHT+IFWpf0oTVgMx1wxX0LndU4NIISvXBSxOofnmLhO+OeoGjed2VRi2fUiXdWGXlj6VLqCmuuiopvMmoji X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:690c:f88:b0:610:f11e:9d24 with SMTP id df8-20020a05690c0f8800b00610f11e9d24mr1661598ywb.4.1711037017498; Thu, 21 Mar 2024 09:03:37 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:59 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 12/13] perf dso: Reference counting related fixes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure gets and puts are better aligned fixing reference couting checking problems. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/machine.c | 4 +-- tools/perf/util/map.c | 1 + tools/perf/util/symbol-elf.c | 51 ++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 4153dc92154d..ca8b1d7e4028 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -683,7 +683,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, struct perf_sample *sample __maybe_unused) { struct symbol *sym; - struct dso *dso; + struct dso *dso =3D NULL; struct map *map =3D maps__find(machine__kernel_maps(machine), event->ksym= bol.addr); int err =3D 0; =20 @@ -696,7 +696,6 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, } dso__set_kernel(dso, DSO_SPACE__KERNEL); map =3D map__new2(0, dso); - dso__put(dso); if (!map) { err =3D -ENOMEM; goto out; @@ -735,6 +734,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, dso__insert_symbol(dso, sym); out: map__put(map); + dso__put(dso); return err; } =20 diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 117c4bb78b35..e1d14936a60d 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -200,6 +200,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, dso__set_build_id(dso, dso__bid(header_bid_dso)); dso__set_header_build_id(dso, 1); } + dso__put(header_bid_dso); } dso__put(dso); } diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 3be5e8d1e278..e398abfd13a0 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1419,7 +1419,7 @@ void __weak arch__sym_update(struct symbol *s __maybe= _unused, static int dso__process_kernel_symbol(struct dso *dso, struct map *map, GElf_Sym *sym, GElf_Shdr *shdr, struct maps *kmaps, struct kmap *kmap, - struct dso **curr_dsop, struct map **curr_mapp, + struct dso **curr_dsop, const char *section_name, bool adjust_kernel_syms, bool kmodule, bool *remap_kernel, u64 max_text_sh_offset) @@ -1470,8 +1470,8 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, map__set_pgoff(map, shdr->sh_offset); } =20 - *curr_mapp =3D map; - *curr_dsop =3D dso; + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(dso); return 0; } =20 @@ -1484,8 +1484,8 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, */ if (kmodule && adjust_kernel_syms && is_exe_text(shdr->sh_flags) && shdr->sh_offset <=3D max_text_sh_offset) { - *curr_mapp =3D map; - *curr_dsop =3D dso; + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(dso); return 0; } =20 @@ -1507,10 +1507,10 @@ static int dso__process_kernel_symbol(struct dso *d= so, struct map *map, dso__set_binary_type(curr_dso, dso__binary_type(dso)); dso__set_adjust_symbols(curr_dso, dso__adjust_symbols(dso)); curr_map =3D map__new2(start, curr_dso); - dso__put(curr_dso); - if (curr_map =3D=3D NULL) + if (curr_map =3D=3D NULL) { + dso__put(curr_dso); return -1; - + } if (dso__kernel(curr_dso)) map__kmap(curr_map)->kmaps =3D kmaps; =20 @@ -1524,21 +1524,15 @@ static int dso__process_kernel_symbol(struct dso *d= so, struct map *map, dso__set_symtab_type(curr_dso, dso__symtab_type(dso)); if (maps__insert(kmaps, curr_map)) return -1; - /* - * Add it before we drop the reference to curr_map, i.e. while - * we still are sure to have a reference to this DSO via - * *curr_map->dso. - */ dsos__add(&maps__machine(kmaps)->dsos, curr_dso); - /* kmaps already got it */ - map__put(curr_map); dso__set_loaded(curr_dso); - *curr_mapp =3D curr_map; + dso__put(*curr_dsop); *curr_dsop =3D curr_dso; } else { - *curr_dsop =3D map__dso(curr_map); - map__put(curr_map); + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(map__dso(curr_map)); } + map__put(curr_map); =20 return 0; } @@ -1549,11 +1543,9 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, { struct kmap *kmap =3D dso__kernel(dso) ? map__kmap(map) : NULL; struct maps *kmaps =3D kmap ? map__kmaps(map) : NULL; - struct map *curr_map =3D map; - struct dso *curr_dso =3D dso; + struct dso *curr_dso =3D NULL; Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym; uint32_t nr_syms; - int err =3D -1; uint32_t idx; GElf_Ehdr ehdr; GElf_Shdr shdr; @@ -1656,6 +1648,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, if (kmodule && adjust_kernel_syms) max_text_sh_offset =3D max_text_section(runtime_ss->elf, &runtime_ss->eh= dr); =20 + curr_dso =3D dso__get(dso); elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) { struct symbol *f; const char *elf_name =3D elf_sym__name(&sym, symstrs); @@ -1744,9 +1737,13 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, --sym.st_value; =20 if (dso__kernel(dso)) { - if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &cur= r_dso, &curr_map, - section_name, adjust_kernel_syms, kmodule, - &remap_kernel, max_text_sh_offset)) + if (dso__process_kernel_symbol(dso, map, &sym, &shdr, + kmaps, kmap, &curr_dso, + section_name, + adjust_kernel_syms, + kmodule, + &remap_kernel, + max_text_sh_offset)) goto out_elf_end; } else if ((used_opd && runtime_ss->adjust_symbols) || (!used_opd && syms_ss->adjust_symbols)) { @@ -1795,6 +1792,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); nr++; } + dso__put(curr_dso); =20 /* * For misannotated, zeroed, ASM function sizes. @@ -1810,9 +1808,10 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, maps__fixup_end(kmaps); } } - err =3D nr; + return nr; out_elf_end: - return err; + dso__put(curr_dso); + return -1; } =20 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, --=20 2.44.0.396.g6e790dbe36-goog From nobody Sat Feb 7 17:09:50 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 E750B12DD9B for ; Thu, 21 Mar 2024 16:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037024; cv=none; b=Vk88t8b0h3NQZUKKjcBYDekom/efuNFUXw8UgZCYplVaGpRRe2uCEWK7J5A9I6M6o3yyWQCU7Xs4Tj5sZ9XWDuseJ077lHC4S+EP0d8BcPX7kiGKm/Nfy5Sd2CSrm6qc69U6wL1M3j2R42tHwfVRgUgbOJclZws+9tR6MFGDWEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037024; c=relaxed/simple; bh=hSMuUa1ZbCYjg1HblkWJi89sX+KRofSvSmdTL9QiRM4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Wex5WBo0OmnbJwvOpW+tFiM+b1dvwmvcmaXQucUcrCZ2Kr5NJGAoWKS69/pGzAb4M1HJCIYZs5WH8e5Zwgwu5lEDil0Wlt/1O4VLrC/ULUpboMcSKjGfjXA62ymhd//wWjudXZwuDUkngCRPDeZyRX2JfO2VF/+vGsnCV/KU0rw= 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=Qx1O0F+b; arc=none smtp.client-ip=209.85.219.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="Qx1O0F+b" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbee93a3e1so1794359276.3 for ; Thu, 21 Mar 2024 09:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711037020; x=1711641820; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3Gaj42JKJGpbBMXevo1XN/rsx9c1VGwA8xTiPugnM4A=; b=Qx1O0F+bFc65A6y+UoQN7tTSy5W2CwqZwvtVGOLE454j84ZrwV/t9wLMxQnUI9vpPC g+9vqRHPr+vq8CaIDJCqbaBOL1zm7pn/VTiNcN13ntQDXMGMzxdV7rSbnTL9oHM9Z9nG 17BDb/kTDenVTvLZBwkoJP8XcXOYUPKOe9NqkIjvIPR6qjqmI9ED8cQLcnl2viPim6K/ gZRFfLkC0zU5kjo6C1IzkdvbE/nvjt1sXFcufYmiBharm0LITvSzE5HTPD6pYTfZcL+l 4zoq2aQSCdnA94Xr2p+Sxd/nbeFtwzgno/Df+kw9sSFrqfGgMzPG5DPcJ1jadN2xhIGn +vqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037020; x=1711641820; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3Gaj42JKJGpbBMXevo1XN/rsx9c1VGwA8xTiPugnM4A=; b=AoM1LFD2lxdMOUCqE9XMolKkB2/yCz4sgIPOu+LaT7/6FPgUsaK4TJASXpV3qWCoIf LZcvqw0bjVLUW/4f4hcEd552xVJOIX48hQCq+9Sw0gtMugvOA0oKmRQBab/M7vlUY91/ TlE+9kXK8BNrmNz8u4p6z9cEyYRfzsg/EUPxctC3k+IUzDAE6/bcMWGQzpJ7fU3LyELc 7c/1TtWCZt2ft9Afu0O/wLyzgL9s5sAaV7ZvIxttOOW+Wjb7HFFIyEO4uFmWv2XF0vV3 KGL4H6el/CnURImibkiIdm9hoHOB3aH3TFkwKmAxNb2k8SIJmIrZV/fp2UWEswHxqkyY bD9A== X-Forwarded-Encrypted: i=1; AJvYcCWSLAzitAUgcemwkmWUlLxTTao+0E7MskbMSdyFdRnaHbFOlyGhcZPXCVBNYulroIsNCIdcFER3URIMLvZ1NYeF6n/kYd1wKVpyCV6X X-Gm-Message-State: AOJu0Yy1fZdxEePGhQUuGUoheipapjB6nt8g+FxgEzW0WcetGnkuQ/+g ZHYFg38fJyC1HEzULeY8FzmXeAfqIOf92ATZl5ZFTviIRAk8IkOJqbot/+i7ZJqhTmFFNL2jInQ thlDCfA== X-Google-Smtp-Source: AGHT+IEbE5WUFq8xfNUCKbDt50IXF5QiEpV7O81PoZcFnvlQr5NC0Zjv2R2VhftEmgI0GRlf2HbQHqPrmHFb X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:188f:b0:dcf:f526:4cc6 with SMTP id cj15-20020a056902188f00b00dcff5264cc6mr1128689ybb.11.1711037019952; Thu, 21 Mar 2024 09:03:39 -0700 (PDT) Date: Thu, 21 Mar 2024 09:03:00 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 13/13] perf dso: Use container_of to avoid a pointer in dso_data From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The dso pointer in dso_data is necessary for reference count checking to account for the dso_data forming a global list of open dso's with references to the dso. The dso pointer also allows for the indirection that reference count checking needs. Outside of reference count checking the indirection isn't needed and container_of is more efficient and saves space. The reference count won't be increased by placing items onto the global list, matching how things were before the reference count checking change, but we assert the dso is in dsos holding it live (and that the set of open dsos is a subset of all dsos for the machine). Update the DSO data tests so that they use a dsos struct to make the invariant true. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/dso-data.c | 60 ++++++++++++++++++------------------- tools/perf/util/dso.c | 16 +++++++++- tools/perf/util/dso.h | 2 ++ 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index fde4eca84b6f..5286ae8bd2d7 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c @@ -10,6 +10,7 @@ #include #include #include "dso.h" +#include "dsos.h" #include "machine.h" #include "symbol.h" #include "tests.h" @@ -123,9 +124,10 @@ static int test__dso_data(struct test_suite *test __ma= ybe_unused, int subtest __ TEST_ASSERT_VAL("No test file", file); =20 memset(&machine, 0, sizeof(machine)); + dsos__init(&machine.dsos); =20 - dso =3D dso__new((const char *)file); - + dso =3D dso__new(file); + TEST_ASSERT_VAL("Failed to add dso", !dsos__add(&machine.dsos, dso)); TEST_ASSERT_VAL("Failed to access to dso", dso__data_fd(dso, &machine) >=3D 0); =20 @@ -170,6 +172,7 @@ static int test__dso_data(struct test_suite *test __may= be_unused, int subtest __ } =20 dso__put(dso); + dsos__exit(&machine.dsos); unlink(file); return 0; } @@ -199,41 +202,35 @@ static long open_files_cnt(void) return nr - 1; } =20 -static struct dso **dsos; - -static int dsos__create(int cnt, int size) +static int dsos__create(int cnt, int size, struct dsos *dsos) { int i; =20 - dsos =3D malloc(sizeof(*dsos) * cnt); - TEST_ASSERT_VAL("failed to alloc dsos array", dsos); + dsos__init(dsos); =20 for (i =3D 0; i < cnt; i++) { - char *file; + struct dso *dso; + char *file =3D test_file(size); =20 - file =3D test_file(size); TEST_ASSERT_VAL("failed to get dso file", file); - - dsos[i] =3D dso__new(file); - TEST_ASSERT_VAL("failed to get dso", dsos[i]); + dso =3D dso__new(file); + TEST_ASSERT_VAL("failed to get dso", dso); + TEST_ASSERT_VAL("failed to add dso", !dsos__add(dsos, dso)); + dso__put(dso); } =20 return 0; } =20 -static void dsos__delete(int cnt) +static void dsos__delete(struct dsos *dsos) { - int i; - - for (i =3D 0; i < cnt; i++) { - struct dso *dso =3D dsos[i]; + for (unsigned int i =3D 0; i < dsos->cnt; i++) { + struct dso *dso =3D dsos->dsos[i]; =20 dso__data_close(dso); unlink(dso__name(dso)); - dso__put(dso); } - - free(dsos); + dsos__exit(dsos); } =20 static int set_fd_limit(int n) @@ -267,10 +264,10 @@ static int test__dso_data_cache(struct test_suite *te= st __maybe_unused, int subt /* and this is now our dso open FDs limit */ dso_cnt =3D limit / 2; TEST_ASSERT_VAL("failed to create dsos\n", - !dsos__create(dso_cnt, TEST_FILE_SIZE)); + !dsos__create(dso_cnt, TEST_FILE_SIZE, &machine.dsos)); =20 for (i =3D 0; i < (dso_cnt - 1); i++) { - struct dso *dso =3D dsos[i]; + struct dso *dso =3D machine.dsos.dsos[i]; =20 /* * Open dsos via dso__data_fd(), it opens the data @@ -290,17 +287,17 @@ static int test__dso_data_cache(struct test_suite *te= st __maybe_unused, int subt } =20 /* verify the first one is already open */ - TEST_ASSERT_VAL("dsos[0] is not open", dso__data(dsos[0])->fd !=3D -1); + TEST_ASSERT_VAL("dsos[0] is not open", dso__data(machine.dsos.dsos[0])->f= d !=3D -1); =20 /* open +1 dso to reach the allowed limit */ - fd =3D dso__data_fd(dsos[i], &machine); + fd =3D dso__data_fd(machine.dsos.dsos[i], &machine); TEST_ASSERT_VAL("failed to get fd", fd > 0); =20 /* should force the first one to be closed */ - TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(dsos[0])->fd =3D=3D = -1); + TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(machine.dsos.dsos[0]= )->fd =3D=3D -1); =20 /* cleanup everything */ - dsos__delete(dso_cnt); + dsos__delete(&machine.dsos); =20 /* Make sure we did not leak any file descriptor. */ nr_end =3D open_files_cnt(); @@ -325,9 +322,9 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub long nr_end, nr =3D open_files_cnt(), lim =3D new_limit(3); int fd, fd_extra; =20 -#define dso_0 (dsos[0]) -#define dso_1 (dsos[1]) -#define dso_2 (dsos[2]) +#define dso_0 (machine.dsos.dsos[0]) +#define dso_1 (machine.dsos.dsos[1]) +#define dso_2 (machine.dsos.dsos[2]) =20 /* Rest the internal dso open counter limit. */ reset_fd_limit(); @@ -347,7 +344,8 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit((lim))); =20 - TEST_ASSERT_VAL("failed to create dsos\n", !dsos__create(3, TEST_FILE_SIZ= E)); + TEST_ASSERT_VAL("failed to create dsos\n", + !dsos__create(3, TEST_FILE_SIZE, &machine.dsos)); =20 /* open dso_0 */ fd =3D dso__data_fd(dso_0, &machine); @@ -386,7 +384,7 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub =20 /* cleanup everything */ close(fd_extra); - dsos__delete(3); + dsos__delete(&machine.dsos); =20 /* Make sure we did not leak any file descriptor. */ nr_end =3D open_files_cnt(); diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 27db65e96e04..dde706b71da7 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -497,14 +497,20 @@ static pthread_mutex_t dso__data_open_lock =3D PTHREA= D_MUTEX_INITIALIZER; static void dso__list_add(struct dso *dso) { list_add_tail(&dso__data(dso)->open_entry, &dso__data_open); +#ifdef REFCNT_CHECKING dso__data(dso)->dso =3D dso__get(dso); +#endif + /* Assume the dso is part of dsos, hence the optional reference count abo= ve. */ + assert(dso__dsos(dso)); dso__data_open_cnt++; } =20 static void dso__list_del(struct dso *dso) { list_del_init(&dso__data(dso)->open_entry); +#ifdef REFCNT_CHECKING dso__put(dso__data(dso)->dso); +#endif WARN_ONCE(dso__data_open_cnt <=3D 0, "DSO data fd counter out of bounds."); dso__data_open_cnt--; @@ -654,9 +660,15 @@ static void close_dso(struct dso *dso) static void close_first_dso(void) { struct dso_data *dso_data; + struct dso *dso; =20 dso_data =3D list_first_entry(&dso__data_open, struct dso_data, open_entr= y); - close_dso(dso_data->dso); +#ifdef REFCNT_CHECKING + dso =3D dso_data->dso; +#else + dso =3D container_of(dso_data, struct dso, data); +#endif + close_dso(dso); } =20 static rlim_t get_fd_limit(void) @@ -1449,7 +1461,9 @@ struct dso *dso__new_id(const char *name, struct dso_= id *id) data->fd =3D -1; data->status =3D DSO_DATA_STATUS_UNKNOWN; INIT_LIST_HEAD(&data->open_entry); +#ifdef REFCNT_CHECKING data->dso =3D NULL; /* Set when on the open_entry list. */ +#endif } return res; } diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index f9689dd60de3..df2c98402af3 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -147,7 +147,9 @@ struct dso_cache { struct dso_data { struct rb_root cache; struct list_head open_entry; +#ifdef REFCNT_CHECKING struct dso *dso; +#endif int fd; int status; u32 status_seen; --=20 2.44.0.396.g6e790dbe36-goog