From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54C60C433EF for ; Thu, 27 Jan 2022 00:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233018AbiA0ABA (ORCPT ); Wed, 26 Jan 2022 19:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbiA0AAz (ORCPT ); Wed, 26 Jan 2022 19:00:55 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C049AC06173B for ; Wed, 26 Jan 2022 16:00:55 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id f8so735961pgf.8 for ; Wed, 26 Jan 2022 16:00:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mBsnkhj9xj5fvZLZ8FdKBQCV6h1H9nMcr2W+mM1cviE=; b=Zu2AALlDUvbJFxm8rVmcaLkLx7IsmzL2b1DfrJ7q1GurSjUMj+aV0F2DmgXjCwV5xO hBu84csBIHM54lI4UzcZZAnP7Pg6FvQAHcZQI8+MpA80cOCNLj7eNiJidnBTlGDiJO3m AyvgHmR9wzCBYDkFCjWh7KFoL5PHd37f3ybHHjWQNgETApCKLagp0BNp9pJL1vzNfu6C yvFi0o1yw+wBPHAb0QvSHMi6oyp1n+WxzFJxcZjsezPHMeFikI8mNkEQIxXr3/BAzBKx ERft4kY9F9tRKZi25iccq5xjJGjfYgEGD9HSqbFYmoMdfkrgydKhtBpfqNNZUxqZVFeQ raPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mBsnkhj9xj5fvZLZ8FdKBQCV6h1H9nMcr2W+mM1cviE=; b=3O+sRKSjuYSVZK3mQNJePMc+nbWfGP0pRTW+rfRfqITtAnrZEvpqZ0NElCKk5HMWpY ruOA6Xa00uR7/XHbF/kK9KVjwVZV5/5eIkHtPLz3ed3rwI/cSNsXgJRnBv0NbNtX484R ieTjp2dvdrcWAbObaam7VmMwz38uTuy6M0oZjpB2iEja56HsRoCHMt5ButIC/o9yomqI QKnNFVhgtQs8KxM2xwlPzu25+4mV1kLEBhNInd7Ik+u2x/ciI7SguUlzQJqPP/+1RzMZ KclRdOfr22ok5TIEeEZREr5BsYlxavwMhAze5+qINduPhmeXQdgg32Ef4nJwfuFRHHRb R/Vw== X-Gm-Message-State: AOAM530+yfwTtYzB5IWR3IKWlta0VQ7J28MhZ3M0EVSddZMTxIBTIc8Q dIDn15nVSb7Ce6CmVHZWTGM= X-Google-Smtp-Source: ABdhPJwZEzj/Qr9LwWIIzdOx5TyIJwOnvQi3nqmx7OkVnNYTDhZydiJQg6RJcXGwQjVbGNX4cjJX5A== X-Received: by 2002:a63:34b:: with SMTP id 72mr888870pgd.50.1643241655255; Wed, 26 Jan 2022 16:00:55 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:00:54 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 1/6] perf lock: Convert lockhash_table to use hlist Date: Wed, 26 Jan 2022 16:00:45 -0800 Message-Id: <20220127000050.3011493-2-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The hlist_head has a single entry so we can save some memory. Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index d70131b7b1b1..43139166f02e 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -38,13 +38,13 @@ static struct perf_session *session; #define LOCKHASH_BITS 12 #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) =20 -static struct list_head lockhash_table[LOCKHASH_SIZE]; +static struct hlist_head lockhash_table[LOCKHASH_SIZE]; =20 #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) =20 struct lock_stat { - struct list_head hash_entry; + struct hlist_node hash_entry; struct rb_node rb; /* used for sorting */ =20 /* @@ -317,10 +317,10 @@ static struct lock_stat *pop_from_result(void) =20 static struct lock_stat *lock_stat_findnew(void *addr, const char *name) { - struct list_head *entry =3D lockhashentry(addr); + struct hlist_head *entry =3D lockhashentry(addr); struct lock_stat *ret, *new; =20 - list_for_each_entry(ret, entry, hash_entry) { + hlist_for_each_entry(ret, entry, hash_entry) { if (ret->addr =3D=3D addr) return ret; } @@ -339,7 +339,7 @@ static struct lock_stat *lock_stat_findnew(void *addr, = const char *name) strcpy(new->name, name); new->wait_time_min =3D ULLONG_MAX; =20 - list_add(&new->hash_entry, entry); + hlist_add_head(&new->hash_entry, entry); return new; =20 alloc_failed: @@ -781,7 +781,7 @@ static void dump_map(void) =20 pr_info("Address of instance: name of class\n"); for (i =3D 0; i < LOCKHASH_SIZE; i++) { - list_for_each_entry(st, &lockhash_table[i], hash_entry) { + hlist_for_each_entry(st, &lockhash_table[i], hash_entry) { pr_info(" %p: %s\n", st->addr, st->name); } } @@ -838,7 +838,7 @@ static void sort_result(void) struct lock_stat *st; =20 for (i =3D 0; i < LOCKHASH_SIZE; i++) { - list_for_each_entry(st, &lockhash_table[i], hash_entry) { + hlist_for_each_entry(st, &lockhash_table[i], hash_entry) { insert_to_result(st, compare); } } @@ -990,7 +990,7 @@ int cmd_lock(int argc, const char **argv) int rc =3D 0; =20 for (i =3D 0; i < LOCKHASH_SIZE; i++) - INIT_LIST_HEAD(lockhash_table + i); + INIT_HLIST_HEAD(lockhash_table + i); =20 argc =3D parse_options_subcommand(argc, argv, lock_options, lock_subcomma= nds, lock_usage, PARSE_OPT_STOP_AT_NON_OPTION); --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E0ABC433F5 for ; Thu, 27 Jan 2022 00:01:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233251AbiA0ABD (ORCPT ); Wed, 26 Jan 2022 19:01:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232500AbiA0AA5 (ORCPT ); Wed, 26 Jan 2022 19:00:57 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7943C06161C for ; Wed, 26 Jan 2022 16:00:57 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id q75so746486pgq.5 for ; Wed, 26 Jan 2022 16:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iF12oDk33SC89FmUfUCUurczF3RBfapGcpp1SGxX/Hk=; b=a0ZX2Rb3/IavQpCZKwTz9ZIRWiMM8EG9Ysfo1NpkLOEH3UeXigGX184ypCwQgD/I3t hWNA92Mn5T8zus2U4ZYsrVVSr882V4FMC54i8w0B2Q5RAaczdi7AK5hOYiHeQqEl7GhI e+dVmJImbnE5Mb394Kg8ujyuPl2Osq2jFHQ2Vpj8wlOy5HQGzQ1CiQFHjvZokzAXpbeS 147mEakUnyLptcZ0205EeOIfWauMbIa08GSUc2P+4FHdh6hAPaGlzOCFK1NmYPv1EKNc rEiym+889tB3aoS60F4YGHdZ/8ToY5BBTV+uROfhefEqmMnfUM0TY/k40/4Mj499Rf4s ZI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=iF12oDk33SC89FmUfUCUurczF3RBfapGcpp1SGxX/Hk=; b=LuI3FbnTRibNxdbK3rFFE9pHVi24VM3QAEtH4jaO8sNRxwW+SJlJR3PVgTMPnzgFsv TEX2hcJL+hDgD3/8zsTfHkBaKZ2p4UFHif3296iQDTMRcUo272BB9VUkyuMswG+3PBLw U4OlX9fTsVopDXboAHLszPdZJ2zU17fdWRmeoecUR/7Klhw9ob8xIl0DlTEQHSwhz62r 4yk+u1fnE27Ns4iC9E3hqLmbpy3KrpjIOemPZR6ochnxMnzwUzIaYL/FcNtNWQJiqIwb QZtdNDHK5YafzBAVEuPS3LdM/Otk3nIaN72Z23m8dGvwIi3gyF/Tl3EKXE+zFGLAaQtq l4sA== X-Gm-Message-State: AOAM532vTCDMqi+q/UX6N3y+GzRrfcFEaDll/UMfpiwgCkTohj7Nm4Zj DQf2XrNCB4a3h3odiOa0kQk= X-Google-Smtp-Source: ABdhPJyI9TKIB3V/1va1WsxgTtlH0KVNXn6avGS7oC/Wc6dGTnBlrHISvM/u6P4dnqMW4u1VkHYK0g== X-Received: by 2002:a05:6a02:20c:: with SMTP id bh12mr924892pgb.308.1643241657043; Wed, 26 Jan 2022 16:00:57 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:00:56 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 2/6] perf lock: Change type of lock_stat->addr to u64 Date: Wed, 26 Jan 2022 16:00:46 -0800 Message-Id: <20220127000050.3011493-3-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As evsel__intval() returns u64, we can just use it as is. Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 43139166f02e..c4b5c3d71ae3 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -47,12 +47,7 @@ struct lock_stat { struct hlist_node hash_entry; struct rb_node rb; /* used for sorting */ =20 - /* - * FIXME: evsel__intval() returns u64, - * so address of lockdep_map should be treated as 64bit. - * Is there more better solution? - */ - void *addr; /* address of lockdep_map, used as ID */ + u64 addr; /* address of lockdep_map, used as ID */ char *name; /* for strcpy(), we cannot use const */ =20 unsigned int nr_acquire; @@ -106,7 +101,7 @@ struct lock_seq_stat { struct list_head list; int state; u64 prev_event_time; - void *addr; + u64 addr; =20 int read_count; }; @@ -315,7 +310,7 @@ static struct lock_stat *pop_from_result(void) return container_of(node, struct lock_stat, rb); } =20 -static struct lock_stat *lock_stat_findnew(void *addr, const char *name) +static struct lock_stat *lock_stat_findnew(u64 addr, const char *name) { struct hlist_head *entry =3D lockhashentry(addr); struct lock_stat *ret, *new; @@ -361,7 +356,7 @@ struct trace_lock_handler { struct perf_sample *sample); }; =20 -static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr) +static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr) { struct lock_seq_stat *seq; =20 @@ -400,16 +395,13 @@ enum acquire_flags { static int report_lock_acquire_event(struct evsel *evsel, struct perf_sample *sample) { - void *addr; struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; const char *name =3D evsel__strval(evsel, sample, "name"); - u64 tmp =3D evsel__intval(evsel, sample, "lockdep_addr"); + u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); int flag =3D evsel__intval(evsel, sample, "flags"); =20 - memcpy(&addr, &tmp, sizeof(void *)); - ls =3D lock_stat_findnew(addr, name); if (!ls) return -ENOMEM; @@ -472,15 +464,12 @@ static int report_lock_acquire_event(struct evsel *ev= sel, static int report_lock_acquired_event(struct evsel *evsel, struct perf_sample *sample) { - void *addr; struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; u64 contended_term; const char *name =3D evsel__strval(evsel, sample, "name"); - u64 tmp =3D evsel__intval(evsel, sample, "lockdep_addr"); - - memcpy(&addr, &tmp, sizeof(void *)); + u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); =20 ls =3D lock_stat_findnew(addr, name); if (!ls) @@ -535,14 +524,11 @@ static int report_lock_acquired_event(struct evsel *e= vsel, static int report_lock_contended_event(struct evsel *evsel, struct perf_sample *sample) { - void *addr; struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; const char *name =3D evsel__strval(evsel, sample, "name"); - u64 tmp =3D evsel__intval(evsel, sample, "lockdep_addr"); - - memcpy(&addr, &tmp, sizeof(void *)); + u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); =20 ls =3D lock_stat_findnew(addr, name); if (!ls) @@ -590,14 +576,11 @@ static int report_lock_contended_event(struct evsel *= evsel, static int report_lock_release_event(struct evsel *evsel, struct perf_sample *sample) { - void *addr; struct lock_stat *ls; struct thread_stat *ts; struct lock_seq_stat *seq; const char *name =3D evsel__strval(evsel, sample, "name"); - u64 tmp =3D evsel__intval(evsel, sample, "lockdep_addr"); - - memcpy(&addr, &tmp, sizeof(void *)); + u64 addr =3D evsel__intval(evsel, sample, "lockdep_addr"); =20 ls =3D lock_stat_findnew(addr, name); if (!ls) @@ -782,7 +765,7 @@ static void dump_map(void) pr_info("Address of instance: name of class\n"); for (i =3D 0; i < LOCKHASH_SIZE; i++) { hlist_for_each_entry(st, &lockhash_table[i], hash_entry) { - pr_info(" %p: %s\n", st->addr, st->name); + pr_info(" %#llx: %s\n", (unsigned long long)st->addr, st->name); } } } --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 147B8C433EF for ; Thu, 27 Jan 2022 00:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233090AbiA0ABF (ORCPT ); Wed, 26 Jan 2022 19:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiA0AA7 (ORCPT ); Wed, 26 Jan 2022 19:00:59 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56871C06161C for ; Wed, 26 Jan 2022 16:00:59 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id 192so1119962pfz.3 for ; Wed, 26 Jan 2022 16:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gr6OHamf/KamqCZ0WcYTNgpdivEzEDFg4GOvJ7a+I8I=; b=gL7JYhNBzJb70oZUYlf+Qfy35k1mAZNUtFoVEJTwmebK/bfmg/s+uZmZyBbrlbMchk b3I2e4niUg4yWKw52WQPRC9dB4MgruhFzRPG+2XLhuVAKstSAFr20v7HL3LOrZW27eeA D5DaajTNBxtmCBBwgF+4m+Bs/Sfae4u/kcx3AY7ZJQlTvvIfxIgtoJDdEbOYfdKiLHb2 yNoMLwwYo2VZvQwdZhbnUEKZjDaxw1U4BB+pONR6joWqERT7zJHdvcrqRXKzoUN7uHrF AqgkZtYe6UA7HHTm4xOurXY5vANekPvSc93VN7roCtBZX4BO7NdwYofrqmkG+Hotud8Y hbFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gr6OHamf/KamqCZ0WcYTNgpdivEzEDFg4GOvJ7a+I8I=; b=5nJF70BlVNUd1xF7pCcjzO1j1NXXGmmvfTmo48oxiFYu/JYBGAZg+6ux2jgnYwxNLo L39Mjz/qUbcdFJwUqj/TjlNNiO3qIY+pePMOIWTYiBENKF8LPrmyZ3tYzZ/GmOzBJwBY HQkTTEsCcKXXeeyEEYZpPDknoCZvxgzH499H9z0a2KbdL0Gz+NpeHe2SZDICJhO2NPtB puKI0QLuOgW5jLdB6FScoG7cqo8UEEDw1m0GuKdZ1Ggmqv5+Q7uvVdCVu9PfODAH0ayj oWl+5UDgwcWUNmPX+sgkoDQx3Bn+wv72f+JlqJ4odS66piFyH+f0tJsKYuS2Af2ijtA3 gyDA== X-Gm-Message-State: AOAM5339BN8rGMT/+SaVfXePIyUte2tthic5U0VjimdQwGaGVyyjJOPX 4sTwP5ERtkTwwaMPoAj2lkrmnnfPi2c= X-Google-Smtp-Source: ABdhPJxbTbnJb4QIeAL2LvYGnmZkVCVDSQeiObHyQVaKu7//+kWTTzOLPnxMcLE1+vb1sLc96mo/dg== X-Received: by 2002:aa7:9989:: with SMTP id k9mr848884pfh.23.1643241658834; Wed, 26 Jan 2022 16:00:58 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:00:58 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 3/6] perf lock: Sort map info based on class name Date: Wed, 26 Jan 2022 16:00:47 -0800 Message-Id: <20220127000050.3011493-4-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of the random order, sort it by lock class name. Before: # perf lock info -m Address of instance: name of class 0xffffa0d940ac5310: &dentry->d_lockref.lock 0xffffa0c20b0e1cb0: &dentry->d_lockref.lock 0xffffa0d8e051cc48: &base->lock 0xffffa0d94f992110: &anon_vma->rwsem 0xffffa0d947a4f278: (null) 0xffffa0c208f6e108: &map->lock 0xffffa0c213ad32c8: &cfs_rq->removed.lock 0xffffa0c20d695888: &parent->list_lock 0xffffa0c278775278: (null) 0xffffa0c212ad4690: &dentry->d_lockref.lock After: # perf lock info -m Address of instance: name of class 0xffffa0c20d538800: &(&sig->stats_lock)->lock 0xffffa0c216d4ec40: &(&sig->stats_lock)->lock 0xffffa1fe4cb04610: &(__futex_data.queues)[i].lock 0xffffa1fe4cb07750: &(__futex_data.queues)[i].lock 0xffffa1fe4cb07b50: &(__futex_data.queues)[i].lock 0xffffa1fe4cb0b850: &(__futex_data.queues)[i].lock 0xffffa1fe4cb0bcd0: &(__futex_data.queues)[i].lock 0xffffa1fe4cb0e5d0: &(__futex_data.queues)[i].lock 0xffffa1fe4cb11ad0: &(__futex_data.queues)[i].lock Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index c4b5c3d71ae3..8078f7ca826d 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -757,6 +757,21 @@ static void dump_threads(void) } } =20 +static int compare_maps(struct lock_stat *a, struct lock_stat *b) +{ + int ret; + + if (a->name && b->name) + ret =3D strcmp(a->name, b->name); + else + ret =3D !!a->name - !!b->name; + + if (!ret) + return a->addr < b->addr; + else + return ret < 0; +} + static void dump_map(void) { unsigned int i; @@ -765,9 +780,12 @@ static void dump_map(void) pr_info("Address of instance: name of class\n"); for (i =3D 0; i < LOCKHASH_SIZE; i++) { hlist_for_each_entry(st, &lockhash_table[i], hash_entry) { - pr_info(" %#llx: %s\n", (unsigned long long)st->addr, st->name); + insert_to_result(st, compare_maps); } } + + while ((st =3D pop_from_result())) + pr_info(" %#llx: %s\n", (unsigned long long)st->addr, st->name); } =20 static int dump_info(void) --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBE43C433FE for ; Thu, 27 Jan 2022 00:01:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233521AbiA0ABH (ORCPT ); Wed, 26 Jan 2022 19:01:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233079AbiA0ABB (ORCPT ); Wed, 26 Jan 2022 19:01:01 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBECDC06161C for ; Wed, 26 Jan 2022 16:01:00 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id u130so1122992pfc.2 for ; Wed, 26 Jan 2022 16:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ihUPCTAjmv8P3pRhjuXxq0KY3Z6v+ZT6Zl7bAgi/+Ls=; b=Mw9tCO6BYAzlms3ZjyXrajFiphRfPOuUVktHDlu48wEcrzEYMa8t404luPWZqkF9DC /hO2owv0DAC6h7FNdBDgFauEk20t+R3G4U+JUzl4N6ioaa4Peji5m36thFreGjB3QPpQ Mjdua3bts6bvHj/X5g7LLMBZFIJ4/BEjN2UOg9sZu6LUk/Y1oeOz6pReTuPTwOpt4Ney qZiJvFf8xUjtFfpid24F1PIC92on0YkeFt8o4C7tPPmDMHp+8/0xDdf1APw5c0sx74hq 0mxKDKWEFmZ3+qhTwkkdVD0DJYOOqEaPd8i4axAaClo1CzeqhP3Q9xD9Nz0gcAYxnmaT E/JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ihUPCTAjmv8P3pRhjuXxq0KY3Z6v+ZT6Zl7bAgi/+Ls=; b=WiPh3zgViH//t8Kgg/zgowsDgpV/VsQVaghIUWlzTKTc+3nvY885BK60x2UN1nCAEt /8wJj4SIcy7aE0rfGVmJYG+jYJkLStAwLXo3z1Bxg7VKeV6ivrgfrDC9f1IHhzrRfpqG XcaChFLpzxK3XwQik4OEkEI1K5TreNlvSRbv0rQV1n3pwllZr0WqVquTFU9ngI7HGcYh W2QCE8aARSRDeglRSKMqjgVfIAjGTztrzXZa1gyTS+xI2uM+opQb0wUWMZhlM9lO5JcF sZvZ1so4l8gyjz75hHuiCTtbNW2qtmv6VodtFKe/6JCBkyO2tGJvxJyXWv1QYaCU7VhW hYsQ== X-Gm-Message-State: AOAM530mfugufCT+vwsV5mmau1zZIRVF6cjLcF9ELFG3FvGpx5gBLdOv VtZEofPnlcWFUFdrUJUS++o= X-Google-Smtp-Source: ABdhPJzOSTVzfmJcWjxj4ZYlmZs3Cv157LVSfKNAu1iAOfxLxaz7fee3OMRQtC4rvuwln4uFDxBiDA== X-Received: by 2002:a05:6a00:1709:: with SMTP id h9mr755145pfc.23.1643241660446; Wed, 26 Jan 2022 16:01:00 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:00:59 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 4/6] perf lock: Fix lock name length check for printing Date: Wed, 26 Jan 2022 16:00:48 -0800 Message-Id: <20220127000050.3011493-5-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It has 20 character spaces for name so lock names shorter than 20 should be printed without ellipsis. Before: # perf lock report Name acquired contended avg wait (ns) total wait (ns) = max wait (ns) min wait (ns) rcu_read_lock 251225 0 0 0 = 0 0 &(ei->i_block_re... 8731 0 0 0 = 0 0 &sb->s_type->i_l... 8731 0 0 0 = 0 0 hrtimer_bases.lo... 5261 0 0 0 = 0 0 hrtimer_bases.lo... 2626 0 0 0 = 0 0 hrtimer_bases.lo... 1953 0 0 0 = 0 0 hrtimer_bases.lo... 1382 0 0 0 = 0 0 cpu_hotplug_lock... 1350 0 0 0 = 0 0 After: # perf lock report Name acquired contended avg wait (ns) total wait (ns) = max wait (ns) min wait (ns) rcu_read_lock 251225 0 0 0 = 0 0 &(ei->i_block_re... 8731 0 0 0 = 0 0 &sb->s_type->i_l... 8731 0 0 0 = 0 0 hrtimer_bases.lock 5261 0 0 0 = 0 0 hrtimer_bases.lock 2626 0 0 0 = 0 0 hrtimer_bases.lock 1953 0 0 0 = 0 0 hrtimer_bases.lock 1382 0 0 0 = 0 0 cpu_hotplug_lock 1350 0 0 0 = 0 0 Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 8078f7ca826d..f6adf3cdd1e2 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -710,7 +710,7 @@ static void print_result(void) } bzero(cut_name, 20); =20 - if (strlen(st->name) < 16) { + if (strlen(st->name) < 20) { /* output raw name */ pr_info("%20s ", st->name); } else { --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C95C433F5 for ; Thu, 27 Jan 2022 00:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233525AbiA0ABJ (ORCPT ); Wed, 26 Jan 2022 19:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233274AbiA0ABD (ORCPT ); Wed, 26 Jan 2022 19:01:03 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD89C06173B for ; Wed, 26 Jan 2022 16:01:03 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id e16so754696pgn.4 for ; Wed, 26 Jan 2022 16:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4bDlE2QWvzROS/x4MoT8MwkxZD4NwyUX21PPI5rsM0c=; b=pdanNWyifAAf4OgnVpHijgYbyAJwh3mzlt3SmK8HZF4HhKAJ0P4RmVfYVtKHocwYnX OJG4tZr46SaGRNschqIOHutPxEdEToSHVnomWzSVjxuK72SNNRrkHtYkg20Anqg9nL3N za1jfzCT52cDtHQP4iQ2uTvBooBdgr1Gl6RXjexrkshPL+bRJpB/CXCH34V212dXs8Ct qj6ybkrpD0RtUKw1Qm+A2qcYY7PCr+91OX2N3L44WWr5Ow05Sd20qVxNkYeS5ERYYBJD F9ChCSHA+qU4DztW5doTjl4Y6Iy3kOE1qsJbNMjMeut8UU2crnFIa9x6n/ezVCzTI2Vk StbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=4bDlE2QWvzROS/x4MoT8MwkxZD4NwyUX21PPI5rsM0c=; b=hy4h8oXpW7ltupKG4f/88l+8nKGSCLxClNYoNdSvDAC/P6VMiWgIR8d0R+vkGENqiZ +NeSlyVPx7sw5V0NsTO8XZJ+1QRFsJwsQEBk4JN8ZWADdPY7lZH0XesnesvTlsfB6MHc Xy1ZKCnh5yawoXBgn1PZ9ERxEZTt2Dh3i4GM8QwLfhq3VR2Np/9WmiVTYkuxBm6bwPd9 oISeHDMIonjXiXijQ4vOOMryTF0UksWPbtkGhuUEVjT/igx7aIuQiKbgs8LsMDW77xri 8g2epUZ0etNsVXWPfO8OjmrtlsEQ/NBxkehOTck857k+nlHcM4DoaKVYHMZ35cyT3wgg pnxA== X-Gm-Message-State: AOAM530HRbBB1Z2qOcRAp/1EayBWc3z93KY5oU4teV1iwdPjN+k7T4iq X5OpGRQq8NAytaRrWVW8rTk= X-Google-Smtp-Source: ABdhPJxSyN7O6Uy1h4qme9btAqAPREF+EJwoUXjT3VueVuwvPIavh+fd3iekicIt3PO0kZP7BO+ogQ== X-Received: by 2002:a05:6a00:b54:: with SMTP id p20mr827707pfo.49.1643241662711; Wed, 26 Jan 2022 16:01:02 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:01:02 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 5/6] perf lock: Add -c/--combine-locks option Date: Wed, 26 Jan 2022 16:00:49 -0800 Message-Id: <20220127000050.3011493-6-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The -c or --combine-locks option is to merge lock instances in the same class into a single entry. It compares the name of the locks and marks duplicated entries using lock_stat->combined. # perf lock report Name acquired contended avg wait (ns) total wait (ns) = max wait (ns) min wait (ns) rcu_read_lock 251225 0 0 0 = 0 0 &(ei->i_block_re... 8731 0 0 0 = 0 0 &sb->s_type->i_l... 8731 0 0 0 = 0 0 hrtimer_bases.lock 5261 0 0 0 = 0 0 hrtimer_bases.lock 2626 0 0 0 = 0 0 hrtimer_bases.lock 1953 0 0 0 = 0 0 hrtimer_bases.lock 1382 0 0 0 = 0 0 cpu_hotplug_lock 1350 0 0 0 = 0 0 hrtimer_bases.lock 1273 0 0 0 = 0 0 hrtimer_bases.lock 1269 0 0 0 = 0 0 # perf lock report -c Name acquired contended avg wait (ns) total wait (ns) = max wait (ns) min wait (ns) rcu_read_lock 251225 0 0 0 = 0 0 hrtimer_bases.lock 39450 0 0 0 = 0 0 &sb->s_type->i_l... 10301 1 662 662 = 662 662 ptlock_ptr(page) 10173 2 701 1402 = 760 642 &(ei->i_block_re... 8732 0 0 0 = 0 0 &xa->xa_lock 8088 0 0 0 = 0 0 &base->lock 6705 0 0 0 = 0 0 &p->pi_lock 5549 0 0 0 = 0 0 &dentry->d_lockr... 5010 4 1274 5097 = 1844 789 &ep->lock 3958 0 0 0 = 0 0 Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-lock.txt | 4 ++ tools/perf/builtin-lock.c | 68 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentat= ion/perf-lock.txt index 1b4d452923d7..f5eb95788969 100644 --- a/tools/perf/Documentation/perf-lock.txt +++ b/tools/perf/Documentation/perf-lock.txt @@ -54,6 +54,10 @@ REPORT OPTIONS Sorting key. Possible values: acquired (default), contended, avg_wait, wait_total, wait_max, wait_min. =20 +-c:: +--combine-locks:: + Merge lock instances in the same class (based on name). + INFO OPTIONS ------------ =20 diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index f6adf3cdd1e2..bbfeba79426a 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -65,6 +65,7 @@ struct lock_stat { u64 wait_time_max; =20 int discard; /* flag of blacklist */ + int combined; }; =20 /* @@ -115,6 +116,8 @@ struct thread_stat { =20 static struct rb_root thread_stats; =20 +static bool combine_locks; + static struct thread_stat *thread_stat_find(u32 tid) { struct rb_node *node; @@ -241,6 +244,7 @@ static const char *sort_key =3D "acquired"; =20 static int (*compare)(struct lock_stat *, struct lock_stat *); =20 +static struct rb_root sorted; /* place to store intermediate data */ static struct rb_root result; /* place to store sorted data */ =20 #define DEF_KEY_LOCK(name, fn_suffix) \ @@ -274,6 +278,49 @@ static int select_key(void) return -1; } =20 +static void combine_lock_stats(struct lock_stat *st) +{ + struct rb_node **rb =3D &sorted.rb_node; + struct rb_node *parent =3D NULL; + struct lock_stat *p; + int ret; + + while (*rb) { + p =3D container_of(*rb, struct lock_stat, rb); + parent =3D *rb; + + if (st->name && p->name) + ret =3D strcmp(st->name, p->name); + else + ret =3D !!st->name - !!p->name; + + if (ret =3D=3D 0) { + p->nr_acquired +=3D st->nr_acquired; + p->nr_contended +=3D st->nr_contended; + p->wait_time_total +=3D st->wait_time_total; + + if (p->nr_contended) + p->avg_wait_time =3D p->wait_time_total / p->nr_contended; + + if (p->wait_time_min > st->wait_time_min) + p->wait_time_min =3D st->wait_time_min; + if (p->wait_time_max < st->wait_time_max) + p->wait_time_max =3D st->wait_time_max; + + st->combined =3D 1; + return; + } + + if (ret < 0) + rb =3D &(*rb)->rb_left; + else + rb =3D &(*rb)->rb_right; + } + + rb_link_node(&st->rb, parent, rb); + rb_insert_color(&st->rb, &sorted); +} + static void insert_to_result(struct lock_stat *st, int (*bigger)(struct lock_stat *, struct lock_stat *)) { @@ -281,6 +328,9 @@ static void insert_to_result(struct lock_stat *st, struct rb_node *parent =3D NULL; struct lock_stat *p; =20 + if (combine_locks && st->combined) + return; + while (*rb) { p =3D container_of(*rb, struct lock_stat, rb); parent =3D *rb; @@ -833,6 +883,21 @@ static int process_sample_event(struct perf_tool *tool= __maybe_unused, return err; } =20 +static void combine_result(void) +{ + unsigned int i; + struct lock_stat *st; + + if (!combine_locks) + return; + + for (i =3D 0; i < LOCKHASH_SIZE; i++) { + hlist_for_each_entry(st, &lockhash_table[i], hash_entry) { + combine_lock_stats(st); + } + } +} + static void sort_result(void) { unsigned int i; @@ -896,6 +961,7 @@ static int __cmd_report(bool display_info) if (display_info) /* used for info subcommand */ err =3D dump_info(); else { + combine_result(); sort_result(); print_result(); } @@ -970,6 +1036,8 @@ int cmd_lock(int argc, const char **argv) OPT_STRING('k', "key", &sort_key, "acquired", "key for sorting (acquired / contended / avg_wait / wait_total / wai= t_max / wait_min)"), /* TODO: type */ + OPT_BOOLEAN('c', "combine-locks", &combine_locks, + "combine locks in the same class"), OPT_PARENT(lock_options) }; =20 --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue Jun 30 02:39:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 806DBC433F5 for ; Thu, 27 Jan 2022 00:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233726AbiA0ABM (ORCPT ); Wed, 26 Jan 2022 19:01:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiA0ABF (ORCPT ); Wed, 26 Jan 2022 19:01:05 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A3B7C06161C for ; Wed, 26 Jan 2022 16:01:05 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id e16so754755pgn.4 for ; Wed, 26 Jan 2022 16:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=unP+2twZA3OrVPx6WNOyb6deG2PSgw9+yCmy5oJ8xpI=; b=eQ+L5Z9MjBgl9fcq2aI541HzzDd54dfAmQydkM9kd67azeHklB6Kv+aNlVhuljfgI1 pvqgsePHr21yuCsdkInOOxn++Wk3e9mxySrnVV5CR4aV7/5aX3ctMREqXv/FqFvj7N1c bMy/3rhaZdKZb0L9TFeq26yCj7M9UNMjrUlq7BaSFbrCcZ9ZNyIfz9H1jtVWPb6UYnqk ap7j6od/GwHBGQgx4V2qNf8Wl4qEIKRzic6vID2EQNaOwHDfQb7msqyPeL8kmYMeLvpy spoN7+X7S2eG+LeDFkHdL+Y9dDbHILe6UJnCXD7Hfb6MfE2Lj87UKzsYwmWnKt4rf4GC tOig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=unP+2twZA3OrVPx6WNOyb6deG2PSgw9+yCmy5oJ8xpI=; b=qMpjjlsIvKxR6HfX0OjoXhCEsqY+fNGxuiVz1f6JkY9Aa052J+k/fbrOkXaT/3wWG8 bvc3avGeMTPxuOAw2sAYDT9aqAezOeWzNgggzFXpSt0wbdfsYZ260UX27VQ1WMfSi3PA OL6hh7b57nLrNYBPSUJbrvwQcuE7HBWDy9pwT8DUYJ2XUs0n4YVINBTGOe86llMcnxD+ PxWhnqG6P0jV9cHXDa1xUzurRM/xWCV8Obpn3siAwdrAniiB1plamBuib8aW6szd4duc fuTiLplxKmnENwAGMbEfp1ullxsCV24F4uVb/gxqrfTdsAtCNoJI8rlFVPzQleIpZzbv pzow== X-Gm-Message-State: AOAM531pxRDHhoTlIJsAeY/3WPodRa8BcbxA1FuRJRaxIiHtXgwhiyi+ mBmuclwu0Tt4lkOjxfP1JFE= X-Google-Smtp-Source: ABdhPJz72cD96I4xpifE84yjtY7n9KXt/vhDJ0z0byTrV7S3r5Jd4tbNJZAfnnnZ+sGJQMqDN5h9/A== X-Received: by 2002:a63:844a:: with SMTP id k71mr836232pgd.559.1643241664703; Wed, 26 Jan 2022 16:01:04 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:e94:fba2:6768:ac75]) by smtp.gmail.com with ESMTPSA id t24sm3545546pfg.92.2022.01.26.16.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:01:04 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers Subject: [PATCH 6/6] perf lock: Carefully combine lock stats for discarded entries Date: Wed, 26 Jan 2022 16:00:50 -0800 Message-Id: <20220127000050.3011493-7-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220127000050.3011493-1-namhyung@kernel.org> References: <20220127000050.3011493-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Stats from discarded entries should be omitted. But a lock class may have both good and bad entries. If the first entry was bad, we can zero-fill the stats and only add good stats if any. The entry can remove the discard state if it finds a good entry later. Acked-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index bbfeba79426a..57b9ebd7118a 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -295,6 +295,9 @@ static void combine_lock_stats(struct lock_stat *st) ret =3D !!st->name - !!p->name; =20 if (ret =3D=3D 0) { + if (st->discard) + goto out; + p->nr_acquired +=3D st->nr_acquired; p->nr_contended +=3D st->nr_contended; p->wait_time_total +=3D st->wait_time_total; @@ -307,6 +310,10 @@ static void combine_lock_stats(struct lock_stat *st) if (p->wait_time_max < st->wait_time_max) p->wait_time_max =3D st->wait_time_max; =20 + /* now it got a new !discard record */ + p->discard =3D 0; + +out: st->combined =3D 1; return; } @@ -319,6 +326,15 @@ static void combine_lock_stats(struct lock_stat *st) =20 rb_link_node(&st->rb, parent, rb); rb_insert_color(&st->rb, &sorted); + + if (st->discard) { + st->nr_acquired =3D 0; + st->nr_contended =3D 0; + st->wait_time_total =3D 0; + st->avg_wait_time =3D 0; + st->wait_time_min =3D ULLONG_MAX; + st->wait_time_max =3D 0; + } } =20 static void insert_to_result(struct lock_stat *st, --=20 2.35.0.rc0.227.g00780c9af4-goog