From patchwork Fri Jan 10 05:11:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13933582 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 272F6205E26 for ; Fri, 10 Jan 2025 05:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486070; cv=none; b=a7Bqpqr4FVkd/6AaAWRfJvqqgnAobzfkuI+X/w5g1teoy+Nj4PVlgCXMcIBPCbdjSAmtC8m3+Oj6qVvx95+54drIg8Gki7hzc9KRFSdBQebWA+MjtWNo5LQaThrWyxgdOcNqOVW3aVpqi6ynwlsYmFlJV4Ki0WwbmR082lJnCQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486070; c=relaxed/simple; bh=PdTe3jFnoCLWzm3kmTMuOUCvtR+GmRocsG2mc9gfwJE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NaKMttshhezJq3YVt2Yj2t07KJNfg7u/Q7w/JPJPWp5MmLwsM2FTCY4MPRTF9kAfemtJnfJ44Cq2t/5H+q3aCYVAkwZ7ab2eIMAQWgrIkHpal4zslOk77M3o4fUMZYKlzDMWY18pQLOcdBh4tbYzUSGtsq39nfhsHz2rWjiZnSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LHFYvfl3; arc=none smtp.client-ip=209.85.216.73 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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LHFYvfl3" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so4842858a91.3 for ; Thu, 09 Jan 2025 21:14:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736486066; x=1737090866; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QOc+Zq7RKw8PAGfDRJz3cORnG4jrHFHNhA/YUYdk0Pc=; b=LHFYvfl3V1gDzJs4PIWHBPrlpESBCy1eCeHgBGDqVYxpsVR3+TJxomewZlexba9Ldg v6d3gasSmzMxDvRAeAcqnb59gLGJK7KflGP6oCCajLNpicBS3yeoOK5penqOawViWQg1 rS2GBD/gSZWXdEX7tyLTGZXm9NQSzYs5iU0q8TAvt8IFlHzERi4kH37+n3gkqxwaUk2B MBPKr4tiGu9sogeYZxHOeORoH2lpNT6l1qnF/pyL+cOeRW05foAEaTqgzwsO5EcL+9F/ 2k/3iFdPjUiI+V8S94KnsSRmM9h8ZXKwTDbFkErRR4WDjQtsb1CuCUE3lxRMQ9wYBk1z i0yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736486066; x=1737090866; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QOc+Zq7RKw8PAGfDRJz3cORnG4jrHFHNhA/YUYdk0Pc=; b=Pv4NFdkBu89wCdve0yuvo4PODEAPfzGWjJzV+fhTQa+1aHhbnZ62vh9qpmq4ZDSl/R wgzhLzC8hXoHsd4vNieVhbk24XA8TWKW8zERyHpmxSADTBqpaq79pd2vNBwM8pomDZGJ bBRScNCaf+tW1D9g0VcZ1EAWmrC0Mu+z6CSsBuAqrklFbpdl2279wQogr4bvr7Z76x9x Of2xxxqYlxPkbI27Ss+JivsZDWiocpejHUlMEdqvS7FXgLIYYZKdgedRZcaPtE7uOLKk bSd6J5/oVg4nT77DBKn3ntBun6eEjAgrNlBDk6tDf0gq0e3lz2rDyOLSCQgn4kRIIcNc SWPA== X-Forwarded-Encrypted: i=1; AJvYcCVaA+8D6jmCVCcgIF4D5ZAGnqnbt0MTqyTmCJ9Zzu+pljoh1s8muIi6LCtA1Hv5Am2Sjl8=@vger.kernel.org X-Gm-Message-State: AOJu0YxA2Ygfmd3vQgO1zY69ihOup9x/0CliH74Fh36Jmo8S52nY6uW8 /vKqM4zsfHlJ+hJKgIO3G0xYdED/iGMB9DZ9ueQKt7sle0VPomXgPcoYSZFiKFISvVR7XU4PJU3 q5Q== X-Google-Smtp-Source: AGHT+IE0+PBeuwxpnzTELFvbH/TuHAsee1m+fOwEkUQNielCR8eFWLWwsp0ClZTyWE2gxhBLCgqSGXk/TAw= X-Received: from pffk11.prod.google.com ([2002:aa7:88cb:0:b0:72b:2f6b:c0a3]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:170a:b0:725:d64c:f113 with SMTP id d2e1a72fcca58-72d21f18064mr14061211b3a.3.1736486066382; Thu, 09 Jan 2025 21:14:26 -0800 (PST) Date: Thu, 9 Jan 2025 21:11:41 -0800 In-Reply-To: <20250110051346.1507178-1-ctshao@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250110051346.1507178-1-ctshao@google.com> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250110051346.1507178-2-ctshao@google.com> Subject: [PATCH v1 1/4] perf lock: Add bpf maps for owner stack tracing From: Chun-Tse Shao To: linux-kernel@vger.kernel.org Cc: Chun-Tse Shao , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Add few bpf maps in order to tracing owner stack. Signed-off-by: Chun-Tse Shao --- tools/perf/util/bpf_lock_contention.c | 17 ++++++-- .../perf/util/bpf_skel/lock_contention.bpf.c | 40 +++++++++++++++++-- tools/perf/util/bpf_skel/lock_data.h | 6 +++ 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index 41a1ad087895..c9c58f243ceb 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -41,9 +41,20 @@ int lock_contention_prepare(struct lock_contention *con) else bpf_map__set_max_entries(skel->maps.task_data, 1); - if (con->save_callstack) - bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries); - else + if (con->save_callstack) { + bpf_map__set_max_entries(skel->maps.stacks, + con->map_nr_entries); + if (con->owner) { + bpf_map__set_value_size(skel->maps.owner_stacks_entries, + con->max_stack * sizeof(u64)); + bpf_map__set_value_size( + skel->maps.contention_owner_stacks, + con->max_stack * sizeof(u64)); + bpf_map__set_key_size(skel->maps.owner_lock_stat, + con->max_stack * sizeof(u64)); + skel->rodata->max_stack = con->max_stack; + } + } else bpf_map__set_max_entries(skel->maps.stacks, 1); if (target__has_cpu(target)) { diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index 1069bda5d733..05da19fdab23 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -19,13 +19,37 @@ #define LCB_F_PERCPU (1U << 4) #define LCB_F_MUTEX (1U << 5) -/* callstack storage */ + /* tmp buffer for owner callstack */ struct { - __uint(type, BPF_MAP_TYPE_STACK_TRACE); + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); __uint(key_size, sizeof(__u32)); __uint(value_size, sizeof(__u64)); + __uint(max_entries, 1); +} owner_stacks_entries SEC(".maps"); + +/* a map for tracing lock address to owner data */ +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(key_size, sizeof(__u64)); // lock address + __uint(value_size, sizeof(cotd)); __uint(max_entries, MAX_ENTRIES); -} stacks SEC(".maps"); +} contention_owner_tracing SEC(".maps"); + +/* a map for tracing lock address to owner stacktrace */ +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(key_size, sizeof(__u64)); // lock address + __uint(value_size, sizeof(__u64)); // straktrace + __uint(max_entries, MAX_ENTRIES); +} contention_owner_stacks SEC(".maps"); + +/* owner callstack to contention data storage */ +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(key_size, sizeof(__u64)); + __uint(value_size, sizeof(struct contention_data)); + __uint(max_entries, MAX_ENTRIES); +} owner_lock_stat SEC(".maps"); /* maintain timestamp at the beginning of contention */ struct { @@ -43,6 +67,14 @@ struct { __uint(max_entries, 1); } tstamp_cpu SEC(".maps"); +/* callstack storage */ +struct { + __uint(type, BPF_MAP_TYPE_STACK_TRACE); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(__u64)); + __uint(max_entries, MAX_ENTRIES); +} stacks SEC(".maps"); + /* actual lock contention statistics */ struct { __uint(type, BPF_MAP_TYPE_HASH); @@ -126,6 +158,7 @@ const volatile int needs_callstack; const volatile int stack_skip; const volatile int lock_owner; const volatile int use_cgroup_v2; +const volatile int max_stack; /* determine the key of lock stat */ const volatile int aggr_mode; @@ -436,7 +469,6 @@ int contention_end(u64 *ctx) return 0; need_delete = true; } - duration = bpf_ktime_get_ns() - pelem->timestamp; if ((__s64)duration < 0) { __sync_fetch_and_add(&time_fail, 1); diff --git a/tools/perf/util/bpf_skel/lock_data.h b/tools/perf/util/bpf_skel/lock_data.h index de12892f992f..1ef0bca9860e 100644 --- a/tools/perf/util/bpf_skel/lock_data.h +++ b/tools/perf/util/bpf_skel/lock_data.h @@ -3,6 +3,12 @@ #ifndef UTIL_BPF_SKEL_LOCK_DATA_H #define UTIL_BPF_SKEL_LOCK_DATA_H +typedef struct contention_owner_tracing_data { + u32 pid; // Who has the lock. + u64 timestamp; // The time while the owner acquires lock and contention is going on. + u32 count; // How many waiters for this lock. +} cotd; + struct tstamp_data { u64 timestamp; u64 lock; From patchwork Fri Jan 10 05:11:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13933583 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 453861E2602 for ; Fri, 10 Jan 2025 05:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486091; cv=none; b=s5o4jRvfqYVm2Bzmg+LEw1K47AEWRDoprJAuaX1/XD77izD8GMpECjtom6xQW4VyNCshwLyANwBkYA6Aa7tN7MNEh1R2TlS0+2C8avg3lPx029PqYvag6wNu8U218J+Nkbnxm8VMyuQiMTUh0J3yexp3G3H+3m5QoVBt5t1/eLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486091; c=relaxed/simple; bh=pL3UPttvwqAamdvk7y1fxiypCFAuCdmicaps6Vc/fw8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W98sUCD3++uRLNnvSoCsGkopsZRAyJbb6PmOa2lvukJl+oAxjxQOpIuZTB9ifCo1jUu+vUhzuMbvtmxfvbmGRVDCEbp7I+EctJhI89LarTopKY01QsQsLZi1lKbmlplLSYcFH+h4NKwqR0KvO9+QThCKEDlW32FlGiIcW3g+7P0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lUpduRdZ; arc=none smtp.client-ip=209.85.216.74 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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lUpduRdZ" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2f550d28f7dso3045480a91.3 for ; Thu, 09 Jan 2025 21:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736486088; x=1737090888; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I+QuW3qojkERBxFgAAtKpSC8lsmMZ0fs08nOqEMmXh4=; b=lUpduRdZC01LLs6qRXqCISmXHSlNARYKsTxmw2Zy/jKn17DBm++IaeBZRYIv0LpEuO HZjwNmwxQQ+kb9hafK/3RIut/C87GiptImMDdt1xGzLATGdFaNQ7E/kVEizm4mkUYCRm UnyE5KF0osJj1xpbh60oIRsTYtGgosC5SPz0CKafFmkFpESt4ck3/zlV380EIkz707YM TxJfrv6O915MEcfJkwKoXaCDQS8Zp16W5mKdqOKC1y5T2gZeY0BgU6hsbiP9HVRylVN8 Ul83Oq8Cy7S8l+b1qdLjAZt0kDKE3LHKWs5TUfQb9+43WUDyMwy/rlYnTJGnHtSk3qjD DNkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736486088; x=1737090888; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I+QuW3qojkERBxFgAAtKpSC8lsmMZ0fs08nOqEMmXh4=; b=HnKa8pUSznzt1q5J0ouXurJ46qMT5zfPMkhgXISLskiN6Vtr4xTuw3iaFMnDKnwGiw 1Virjna3jeyrMAoOLHCI3hR0YTzjZGSQS9wd2DPAGoQbgnvYYPh3ijqThEOTugtEk5a+ 9da3rR14stii7Eg2p6GOIAcKnYZutV41qptOJQ0eMNyt/a0nvO+T1xkP8CyajHYuX44e oDGCCDhHDEKWRDwRKuyEQL097OVBHs3UZwbxgIAAa4TaBx+jjeirIVBmaUUFfxNeKo6B xHl2o/G3RN15o7bfHgmxJboD7yfrWwpMP3B4LCZZ6lJwYN4RwmqfYsoaXTVYA5286E31 wQ9w== X-Forwarded-Encrypted: i=1; AJvYcCXYiRla3FFJOD6IUzjQYev6En3nmez91w/8IUc4I1vVMGs1wmg2Hku8+6zpNQlKB/vRwyY=@vger.kernel.org X-Gm-Message-State: AOJu0YxPSY67R3pE3DcQl78os/Dhj5kRDJVqpXCFkOEyRYIlNsPuKrwI SbM6+MvubLtsI7VcqJykKo8RP0b4y9/qdr8TQuo6x/r+3pInDPGamTFNTwne8kCXActVRX2Jymt mBw== X-Google-Smtp-Source: AGHT+IEeJFxjwEWWMJRT06FpUTerPuPKdSR7S9ijM2J6A/cHSAmNg4rsmvpRBsTzQBlTir1BIEVJZB+mAD0= X-Received: from pjbta14.prod.google.com ([2002:a17:90b:4ece:b0:2ef:79ee:65c0]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:540b:b0:2ee:d824:b559 with SMTP id 98e67ed59e1d1-2f548f44e6bmr13360936a91.28.1736486088638; Thu, 09 Jan 2025 21:14:48 -0800 (PST) Date: Thu, 9 Jan 2025 21:11:42 -0800 In-Reply-To: <20250110051346.1507178-1-ctshao@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250110051346.1507178-1-ctshao@google.com> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250110051346.1507178-3-ctshao@google.com> Subject: [PATCH v1 2/4] perf lock: Retrieve owner callstack in bpf program From: Chun-Tse Shao To: linux-kernel@vger.kernel.org Cc: Chun-Tse Shao , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Tracing owner callstack in `contention_begin()` and `contention_end()`, and storing in `owner_lock_stat` bpf map. Signed-off-by: Chun-Tse Shao --- .../perf/util/bpf_skel/lock_contention.bpf.c | 149 +++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index 05da19fdab23..79b641d7beb2 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -7,6 +7,7 @@ #include #include "lock_data.h" +#include /* for collect_lock_syms(). 4096 was rejected by the verifier */ #define MAX_CPUS 1024 @@ -178,6 +179,9 @@ int data_fail; int task_map_full; int data_map_full; +struct task_struct *bpf_task_from_pid(s32 pid) __ksym; +void bpf_task_release(struct task_struct *p) __ksym; + static inline __u64 get_current_cgroup_id(void) { struct task_struct *task; @@ -407,6 +411,60 @@ int contention_begin(u64 *ctx) pelem->flags = (__u32)ctx[1]; if (needs_callstack) { + u32 i = 0; + int owner_pid; + unsigned long *entries; + struct task_struct *task; + cotd *data; + + if (!lock_owner) + goto contention_begin_skip_owner_callstack; + + task = get_lock_owner(pelem->lock, pelem->flags); + if (!task) + goto contention_begin_skip_owner_callstack; + + owner_pid = BPF_CORE_READ(task, pid); + + entries = bpf_map_lookup_elem(&owner_stacks_entries, &i); + if (!entries) + goto contention_begin_skip_owner_callstack; + for (i = 0; i < max_stack; i++) + entries[i] = 0x0; + + task = bpf_task_from_pid(owner_pid); + if (task) { + bpf_get_task_stack(task, entries, + max_stack * sizeof(unsigned long), + 0); + bpf_task_release(task); + } + + data = bpf_map_lookup_elem(&contention_owner_tracing, + &(pelem->lock)); + + // Contention just happens, or corner case `lock` is owned by + // process not `owner_pid`. + if (!data || data->pid != owner_pid) { + cotd first = { + .pid = owner_pid, + .timestamp = pelem->timestamp, + .count = 1, + }; + bpf_map_update_elem(&contention_owner_tracing, + &(pelem->lock), &first, BPF_ANY); + bpf_map_update_elem(&contention_owner_stacks, + &(pelem->lock), entries, BPF_ANY); + } + // Contention is going on and new waiter joins. + else { + __sync_fetch_and_add(&data->count, 1); + // TODO: Since for owner the callstack would change at + // different time, We should check and report if the + // callstack is different with the recorded one in + // `contention_owner_stacks`. + } +contention_begin_skip_owner_callstack: pelem->stack_id = bpf_get_stackid(ctx, &stacks, BPF_F_FAST_STACK_CMP | stack_skip); if (pelem->stack_id < 0) @@ -443,6 +501,7 @@ int contention_end(u64 *ctx) struct tstamp_data *pelem; struct contention_key key = {}; struct contention_data *data; + __u64 timestamp; __u64 duration; bool need_delete = false; @@ -469,12 +528,100 @@ int contention_end(u64 *ctx) return 0; need_delete = true; } - duration = bpf_ktime_get_ns() - pelem->timestamp; + timestamp = bpf_ktime_get_ns(); + duration = timestamp - pelem->timestamp; if ((__s64)duration < 0) { __sync_fetch_and_add(&time_fail, 1); goto out; } + if (needs_callstack && lock_owner) { + u64 owner_contention_time; + unsigned long *owner_stack; + struct contention_data *cdata; + cotd *otdata; + + otdata = bpf_map_lookup_elem(&contention_owner_tracing, + &(pelem->lock)); + owner_stack = bpf_map_lookup_elem(&contention_owner_stacks, + &(pelem->lock)); + if (!otdata || !owner_stack) + goto contention_end_skip_owner_callstack; + + owner_contention_time = timestamp - otdata->timestamp; + + // Update `owner_lock_stat` if `owner_stack` is + // available. + if (owner_stack[0] != 0x0) { + cdata = bpf_map_lookup_elem(&owner_lock_stat, + owner_stack); + if (!cdata) { + struct contention_data first = { + .total_time = owner_contention_time, + .max_time = owner_contention_time, + .min_time = owner_contention_time, + .count = 1, + .flags = pelem->flags, + }; + bpf_map_update_elem(&owner_lock_stat, + owner_stack, &first, + BPF_ANY); + } else { + __sync_fetch_and_add(&cdata->total_time, + owner_contention_time); + __sync_fetch_and_add(&cdata->count, 1); + + /* FIXME: need atomic operations */ + if (cdata->max_time < owner_contention_time) + cdata->max_time = owner_contention_time; + if (cdata->min_time > owner_contention_time) + cdata->min_time = owner_contention_time; + } + } + + // `pid` in `otdata` is not lock owner anymore, delete + // this entry. + bpf_map_delete_elem(&contention_owner_stacks, &(otdata->pid)); + + // No contention is going on, delete `lock` in + // `contention_owner_tracing` and + // `contention_owner_stacks` + if (otdata->count <= 1) { + bpf_map_delete_elem(&contention_owner_tracing, + &(pelem->lock)); + bpf_map_delete_elem(&contention_owner_stacks, + &(pelem->lock)); + } + // Contention is still going on, with a new owner + // (current task). `otdata` should be updated accordingly. + // If ctx[1] is not 0, the current task terminate lock waiting + // without acquiring it. + else if (ctx[1] == 0) { + unsigned long *entries; + u32 i = 0; + + otdata->pid = pid; + otdata->timestamp = timestamp; + (otdata->count)--; + bpf_map_update_elem(&contention_owner_tracing, + &(pelem->lock), otdata, BPF_ANY); + + entries = + bpf_map_lookup_elem(&owner_stacks_entries, &i); + if (!entries) + goto contention_end_skip_owner_callstack; + for (i = 0; i < (u32)max_stack; i++) + entries[i] = 0x0; + + bpf_get_task_stack(bpf_get_current_task_btf(), entries, + max_stack * sizeof(unsigned long), + 0); + bpf_map_update_elem(&contention_owner_stacks, + &(pelem->lock), entries, BPF_ANY); + } + } +contention_end_skip_owner_callstack: + switch (aggr_mode) { case LOCK_AGGR_CALLER: key.stack_id = pelem->stack_id; From patchwork Fri Jan 10 05:11:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13933584 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 6C1262063FC for ; Fri, 10 Jan 2025 05:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486113; cv=none; b=F0pHzI/fX1WVW56cLl3pRbJV8i6eA5rDt+YcnqFXIWFKDMlrSBjWrUB1s/teIc9wR0JsUrMKdPUlTxztsul8tLiPjDKSNynJEWQXHQsQVMDtmK0NJrn+/EtmFzWALhJFNfJSxzAnuoD4jWk8Up+kBvj6XIvvCbEp579RETywsog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486113; c=relaxed/simple; bh=7r3spX1VTM6b7Ljhi+bgUnGyr89CaYIzvQ4zgRIgmY8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rpCULMjxrnBLiKn3593eSeMo+9j3YYyQTZ6nqctgJC/edugO+E9PBcJlCL7EU5Gpq4ZMOTA/F2QpdJB5tFXCpWACplr40uA4O0HQMtt61Xi39VS60prF3pvuzBAZUsL5mSxY78qASeJX9M2iIdAH1YQb+oOjz4XdLSACiq1Sgww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WWAF/PXb; arc=none smtp.client-ip=209.85.216.74 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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WWAF/PXb" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef79403c5eso4889653a91.0 for ; Thu, 09 Jan 2025 21:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736486111; x=1737090911; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nK90VQgfJdgs3XY2vlzkWlR2hkLCvAiNELZrM3w+SYE=; b=WWAF/PXb84Kp7d8v91buiy2xvNt2+fk2T7R5LUy9RelaEqmXGFuQA5awicLKdG2ekL SqaCw5AdypW8TF8QlfLp87c8O2ioJH6qgtK1o6nz3/AYWEM4GjVo2wL0a/rsnNn8eO13 EhrcD6a5ltIyvbXp7oC+QLbJKKy2l6+WfLQ5H2mJQ9p3lMkPf4D7cJzfr4oBRq2la+2q 2X32muXVMdPe7b1qoMKDeSECd62ic3AISkLV5j72g6ttYMF5ck+Kxf48Ofc+zpsjih2i vg+h3yP7A/UFGVkivLzEzwWxw3oXApIdjQwIVvhbUXDkkqfeC1USPb1yc/8ZFLtku19Y k9vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736486111; x=1737090911; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nK90VQgfJdgs3XY2vlzkWlR2hkLCvAiNELZrM3w+SYE=; b=OXGnzgvmJqce82Qd79D3igM4DsekKA5+WFJxyIGGuzTR6nrrCBKZ83fHwNBfQpnn6t eRJoP+kRaSJT/y2iMH/y2re503myuaxFf7B9dTWtFlUl5Vw3XpGxisCH54d7jp71BcYM ADRNRjWG1CoQvMuHoSbg3nbz8dDf0KSBrhRx+Yi1VnZxYKdKvX7saAYI6XSublbWPJlo fOS1LQtM4vxGau/WvSXGJbijp24N6fauTIZ51iNcc7szyr75xxuENtsJFxhCqvfrfbg7 HnB2zLkqiNF8JeOGD2djcj2i+V5cGRPXtk7+VPl8KZ6dvRlP3g6v6SXiZfTg8/SHLjRM HgMw== X-Forwarded-Encrypted: i=1; AJvYcCX4dgM57DuLCRx1dPjj7tJedHJgnvnzacgEbNpM7TD/LN47naE1hl8yM6yTzhW5hmtcQlU=@vger.kernel.org X-Gm-Message-State: AOJu0Yypj4E8qnOGJLej5Q5qmpoY9zorXig6UtYPnYQjzTiFHC0Mk34H /PPujgcHMrjMuCpzdv03/F4IO52jKnMbSRZGRJjOrVUZrV14hxqw26yN0NwAKuJm+4nc+W3+JIr Bnw== X-Google-Smtp-Source: AGHT+IGlBmwxlhdWhpyG89HKs3UpAFypEVCtO1wb10nPEF0fSyibZ1nDSSEdGPg5uIjNzFSctiSI+svOy0k= X-Received: from pjbsz8.prod.google.com ([2002:a17:90b:2d48:b0:2ee:3128:390f]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5241:b0:2ee:d18c:7d84 with SMTP id 98e67ed59e1d1-2f548f59de6mr13874596a91.20.1736486110811; Thu, 09 Jan 2025 21:15:10 -0800 (PST) Date: Thu, 9 Jan 2025 21:11:43 -0800 In-Reply-To: <20250110051346.1507178-1-ctshao@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250110051346.1507178-1-ctshao@google.com> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250110051346.1507178-4-ctshao@google.com> Subject: [PATCH v1 3/4] perf lock: Make rb_tree helper functions generic From: Chun-Tse Shao To: linux-kernel@vger.kernel.org Cc: Chun-Tse Shao , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org The rb_tree helper functions can be reused for parsing `owner_lock_stat` into rb tree for sorting. Signed-off-by: Chun-Tse Shao --- tools/perf/builtin-lock.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 062e2b56a2ab..f9b7620444c0 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -438,16 +438,13 @@ static void combine_lock_stats(struct lock_stat *st) rb_insert_color(&st->rb, &sorted); } -static void insert_to_result(struct lock_stat *st, - int (*bigger)(struct lock_stat *, struct lock_stat *)) +static void insert_to(struct rb_root *rr, struct lock_stat *st, + int (*bigger)(struct lock_stat *, struct lock_stat *)) { - struct rb_node **rb = &result.rb_node; + struct rb_node **rb = &rr->rb_node; struct rb_node *parent = NULL; struct lock_stat *p; - if (combine_locks && st->combined) - return; - while (*rb) { p = container_of(*rb, struct lock_stat, rb); parent = *rb; @@ -459,13 +456,21 @@ static void insert_to_result(struct lock_stat *st, } rb_link_node(&st->rb, parent, rb); - rb_insert_color(&st->rb, &result); + rb_insert_color(&st->rb, rr); } -/* returns left most element of result, and erase it */ -static struct lock_stat *pop_from_result(void) +static inline void insert_to_result(struct lock_stat *st, + int (*bigger)(struct lock_stat *, + struct lock_stat *)) +{ + if (combine_locks && st->combined) + return; + insert_to(&result, st, bigger); +} + +static inline struct lock_stat *pop_from(struct rb_root *rr) { - struct rb_node *node = result.rb_node; + struct rb_node *node = rr->rb_node; if (!node) return NULL; @@ -473,8 +478,15 @@ static struct lock_stat *pop_from_result(void) while (node->rb_left) node = node->rb_left; - rb_erase(node, &result); + rb_erase(node, rr); return container_of(node, struct lock_stat, rb); + +} + +/* returns left most element of result, and erase it */ +static struct lock_stat *pop_from_result(void) +{ + return pop_from(&result); } struct lock_stat *lock_stat_find(u64 addr) From patchwork Fri Jan 10 05:11:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13933585 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 9CFBA18C928 for ; Fri, 10 Jan 2025 05:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486135; cv=none; b=NQomOIeHx8zisPNanbOYfQwu/I8itbn5qQ0O8Q+kACfvIZHl/2RZCIoZG5/TrhYNOSa1EcIZ8juOulSL8zRRqc/cYGkVE0aPDvt3/V8ju4UZnHhvj0qEom8vvRd7uDSHgvIoBz1nzFJo+KpO5Ll6oZGnoKzRfZPMG/CVsLFRVas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736486135; c=relaxed/simple; bh=mxq8JbhUM61C/BdaOz17P9fYKKdIVBAz9OSawkUDkEU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RkohQC9AbGdjniHCv3vXvI+t6bw7/vxYS2cYEv9Vsvd+pKfzIMSWDxiS/dq7miWDq4XfQmyVRE5hgberwpJaYJSXQ+fAkEPwl4n3wlbF+iuaPPkV8tM4qJWOeioNiUWzDPulYjOtW7E+WP4js1zin2PbYZg7alHM3XHtPf0risY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NIXjhgMI; arc=none smtp.client-ip=209.85.216.73 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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NIXjhgMI" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so4845039a91.3 for ; Thu, 09 Jan 2025 21:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736486133; x=1737090933; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hE9EISDVTzVU1K+rlaaimzQWIvKlJ6sLk8tbkArb4CQ=; b=NIXjhgMIQ+OfNedIsSkypmaXak9pxlU7kuMjbLfHPMcO/RFXEp7bdb6SVZca9sUDbG OL2w0Ppkf9AkG+8YllMdQ6rxXmkpXSFtunBUyx6zl89qS4ty9KGNwgVTK6/1mTup2nIe ZvTsrSaPp/4nii4DIEbrSspN/p6WJERaLDQ9jJqffr/1EMfri2WIkG3a4gWChlPwTJ1U H3umhcoNVE+Fn8N5JBITADQPpXrHIHYabNPYcG8+DM6OztvUbqFgcJbJCQkZ7qgYrcw+ PrEoHFOSwUTdS6gh7BlL1tfPe0Z3bnVQFrwK/K6SJDNfPtK+Dej1oFnyunOEOAVI0Bjv CZ3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736486133; x=1737090933; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hE9EISDVTzVU1K+rlaaimzQWIvKlJ6sLk8tbkArb4CQ=; b=rJj7/CssLj2kU11jDs47eY0qAEB4lhVFmgyowM1v7wqMc1kLNOXCzZrZBm7ha2riQG kvf2HonF3yN2B3OY+hl2mMZbfSMTQK4dZFHqStlGE5wyvgdr7t1d/N8LYYLd3xnkzoga VE+PHPUEYIoz4M2O3MbfTHaxHnVz7mMtC2nHP7n0T+saqkgrX5I6gzA3mA+ei7lgvzjC VV/L6hcRwFPHM0k2jfhtt/jRUaLxdEmD1yBNf8pPj7f7DTVCkto0bRdwj4zqYdVLLAHQ iLeR8P5rBgd4Cn2Dh4x6rF/n0r8BhnXG6JING8d3ntD54Db9cW5dNWKLY6925f0/PXXe z+rg== X-Forwarded-Encrypted: i=1; AJvYcCVHEUU243JJq41XfXxG7oKbpXhPKiNQMBf+IW0w/nJcI/1QWbLoq/k2sx5yFxcDCqbbgMk=@vger.kernel.org X-Gm-Message-State: AOJu0Yzc2rcq3u4dyR1TmVMcakrX3OWqaMuTTbLa2x2WG2qIHeyZIBM8 DSD/qOzRn70+Qb+rs5oZOtbETuRemIg2lGpixXZaBh92+EESKBmRPtRvOLsZ5Cjq4WNlYPvtCZI K1Q== X-Google-Smtp-Source: AGHT+IHRqczsVQdVyjV3usT7mkM0Jd+4O54qlIoQebIseIGLadj0zMA2MHTCg5fOlfMt/wa+q4xdG6X0HYI= X-Received: from pjbpq5.prod.google.com ([2002:a17:90b:3d85:b0:2ef:8ef8:2701]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a50:b0:2ea:bf1c:1e3a with SMTP id 98e67ed59e1d1-2f548f2a154mr16873338a91.12.1736486132920; Thu, 09 Jan 2025 21:15:32 -0800 (PST) Date: Thu, 9 Jan 2025 21:11:44 -0800 In-Reply-To: <20250110051346.1507178-1-ctshao@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250110051346.1507178-1-ctshao@google.com> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250110051346.1507178-5-ctshao@google.com> Subject: [PATCH v1 4/4] perf lock: Report owner stack in usermode From: Chun-Tse Shao To: linux-kernel@vger.kernel.org Cc: Chun-Tse Shao , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Parse `owner_lock_stat` into a rb tree, and report owner lock stats with stack trace in order. Example output: $ sudo ~/linux/tools/perf/perf lock con -abvo -Y mutex-spin -E3 perf bench sched pipe ... contended total wait max wait avg wait type caller 171 1.55 ms 20.26 us 9.06 us mutex pipe_read+0x57 0xffffffffac6318e7 pipe_read+0x57 0xffffffffac623862 vfs_read+0x332 0xffffffffac62434b ksys_read+0xbb 0xfffffffface604b2 do_syscall_64+0x82 0xffffffffad00012f entry_SYSCALL_64_after_hwframe+0x76 36 193.71 us 15.27 us 5.38 us mutex pipe_write+0x50 0xffffffffac631ee0 pipe_write+0x50 0xffffffffac6241db vfs_write+0x3bb 0xffffffffac6244ab ksys_write+0xbb 0xfffffffface604b2 do_syscall_64+0x82 0xffffffffad00012f entry_SYSCALL_64_after_hwframe+0x76 4 51.22 us 16.47 us 12.80 us mutex do_epoll_wait+0x24d 0xffffffffac691f0d do_epoll_wait+0x24d 0xffffffffac69249b do_epoll_pwait.part.0+0xb 0xffffffffac693ba5 __x64_sys_epoll_pwait+0x95 0xfffffffface604b2 do_syscall_64+0x82 0xffffffffad00012f entry_SYSCALL_64_after_hwframe+0x76 === owner stack trace === 3 31.24 us 15.27 us 10.41 us mutex pipe_read+0x348 0xffffffffac631bd8 pipe_read+0x348 0xffffffffac623862 vfs_read+0x332 0xffffffffac62434b ksys_read+0xbb 0xfffffffface604b2 do_syscall_64+0x82 0xffffffffad00012f entry_SYSCALL_64_after_hwframe+0x76 ... Signed-off-by: Chun-Tse Shao --- tools/perf/builtin-lock.c | 21 +++++++++++++- tools/perf/util/bpf_lock_contention.c | 41 +++++++++++++++++++++++++++ tools/perf/util/lock-contention.h | 2 ++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index f9b7620444c0..b20687325d49 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -42,6 +42,7 @@ #include #include #include +#include static struct perf_session *session; static struct target target; @@ -1926,6 +1927,24 @@ static void print_contention_result(struct lock_contention *con) break; } + if (con->owner && con->save_callstack) { + struct rb_root root = RB_ROOT; + + + if (symbol_conf.field_sep) + fprintf(lock_output, "# owner stack trace:\n"); + else + fprintf(lock_output, "\n=== owner stack trace ===\n\n"); + while ((st = pop_owner_stack_trace(con))) { + insert_to(&root, st, compare); + } + + while ((st = pop_from(&root))) { + print_lock_stat(con, st); + zfree(st); + } + } + if (print_nr_entries) { /* update the total/bad stats */ while ((st = pop_from_result())) { @@ -2071,7 +2090,7 @@ static int check_lock_contention_options(const struct option *options, } } - if (show_lock_owner) + if (show_lock_owner && !verbose) show_thread_stats = true; return 0; diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index c9c58f243ceb..a63d5ffac386 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -414,6 +414,47 @@ static const char *lock_contention_get_name(struct lock_contention *con, return name_buf; } +struct lock_stat *pop_owner_stack_trace(struct lock_contention *con) +{ + int fd; + u64 *stack_trace; + struct contention_data data = {}; + size_t stack_size = con->max_stack * sizeof(*stack_trace); + struct lock_stat *st; + char name[KSYM_NAME_LEN]; + + fd = bpf_map__fd(skel->maps.owner_lock_stat); + + stack_trace = zalloc(stack_size); + if (stack_trace == NULL) + return NULL; + + if (bpf_map_get_next_key(fd, NULL, stack_trace)) + return NULL; + + bpf_map_lookup_elem(fd, stack_trace, &data); + st = zalloc(sizeof(struct lock_stat)); + + strcpy(name, stack_trace[0] ? lock_contention_get_name(con, NULL, + stack_trace, 0) : + "unknown"); + + st->name = strdup(name); + st->flags = data.flags; + st->nr_contended = data.count; + st->wait_time_total = data.total_time; + st->wait_time_max = data.max_time; + st->wait_time_min = data.min_time; + st->callstack = memdup(stack_trace, stack_size); + + if (data.count) + st->avg_wait_time = data.total_time / data.count; + + bpf_map_delete_elem(fd, stack_trace); + free(stack_trace); + + return st; +} int lock_contention_read(struct lock_contention *con) { int fd, stack, err = 0; diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-contention.h index 1a7248ff3889..83b400a36137 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -156,6 +156,8 @@ int lock_contention_stop(void); int lock_contention_read(struct lock_contention *con); int lock_contention_finish(struct lock_contention *con); +struct lock_stat *pop_owner_stack_trace(struct lock_contention *con); + #else /* !HAVE_BPF_SKEL */ static inline int lock_contention_prepare(struct lock_contention *con __maybe_unused)