Received: by 10.223.164.202 with SMTP id h10csp1039700wrb; Sun, 26 Nov 2017 18:36:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMaCJhSXG1wZZe0s1N9N5QSvF8UTttVZUPV0sVSK5fqqZrSwgFskbOrt06bVbD995sz9vPse X-Received: by 10.159.255.75 with SMTP id u11mr36208894pls.79.1511750203425; Sun, 26 Nov 2017 18:36:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511750203; cv=none; d=google.com; s=arc-20160816; b=qa36QOUf2YespuDzwjImLtuw/F6WuY+qMx09e1ALEgIx4lODMnXZ3xv/C+SZW+VEbX JumPEafRU3LieLRuirQhZ6a85ZCr3ydkDSFMXE0rlZBqWJla14TnmCESDQQK9jP7VdOx Lo4Aj7tLGUJBfq16CVt6Ttg11HyvW7E4wiZdkRxhrort7x4d+7O4bdUyqoHM3i3ygmMe Y6MwvP0bOHu2po2R3WhTXBuWgwRN6tD0T7eG74S2iODDFpgQrjvPInAFxZcV0fxVQ9Hj XkEe0B/Pjl7zlOCsFqYSRKhAvjzTQAgIqyIvwYqw1nKUdihtdNl8k7u4FZZUu570dHYE NZxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=S0al/VwgKwFag6L0WQeG6kET374oaM/1SC2xSXd9hGo=; b=pytfqUrvva0GS0r7NFhj7gNx+2mI5UCWtqdgT3uklDDbpRFRUFrztlPTGt0CmxO2av 1IRjHVD7dYE3qOG69Vgtlyj0YgiJAbO+cSFbc9YvlXKLAV0XyMDicLK/rRv/dvxmFsLz 5lOLXRWdLif8BCNzZuvb3GxqWrjrRyB4KcIaIY/BT7/QuVCZqIWGQrUaUaFnI5emSk4U B9x88YzYlOkcVWnqnn0zqL6GVhFnp1qeKOBvZcDi/P4uWDEwHe4w8lt+N881Dvh/ZHhH r79Y56kid6vlBkXDuNHjtdBiuB4j/IYo0/4vssHp2kqtudghNkY2EFriN6woT/w3wpBt 9Kfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si19969747pfa.111.2017.11.26.18.36.32; Sun, 26 Nov 2017 18:36:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751395AbdK0CeR (ORCPT + 77 others); Sun, 26 Nov 2017 21:34:17 -0500 Received: from smtp2.provo.novell.com ([137.65.250.81]:58854 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751350AbdK0CeQ (ORCPT ); Sun, 26 Nov 2017 21:34:16 -0500 Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Sun, 26 Nov 2017 19:34:10 -0700 From: Davidlohr Bueso To: acme@kernel.org Cc: jolsa@redhat.com, ak@linux.intel.com, mingo@redhat.com, dave@stgolabs.net, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 4/7] perf util: Use cached rbtree for rblists Date: Sun, 26 Nov 2017 18:30:43 -0800 Message-Id: <20171127023046.19139-5-dave@stgolabs.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171127023046.19139-1-dave@stgolabs.net> References: <20171127023046.19139-1-dave@stgolabs.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something required for any of the strlist or intlist traversals (XXX_for_each_entry()). There are a number of users in perf of these (particularly strlists), including probes, and buildid. Signed-off-by: Davidlohr Bueso --- tools/perf/util/intlist.h | 2 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/rblist.c | 30 ++++++++++++++++++------------ tools/perf/util/rblist.h | 2 +- tools/perf/util/stat-shadow.c | 2 +- tools/perf/util/strlist.h | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/intlist.h b/tools/perf/util/intlist.h index 85bab8735fa9..5c19ee001299 100644 --- a/tools/perf/util/intlist.h +++ b/tools/perf/util/intlist.h @@ -45,7 +45,7 @@ static inline unsigned int intlist__nr_entries(const struct intlist *ilist) /* For intlist iteration */ static inline struct int_node *intlist__first(struct intlist *ilist) { - struct rb_node *rn = rb_first(&ilist->rblist.entries); + struct rb_node *rn = rb_first_cached(&ilist->rblist.entries); return rn ? rb_entry(rn, struct int_node, rb_node) : NULL; } static inline struct int_node *intlist__next(struct int_node *in) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 0ddd9c199227..59a08a9eebb9 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -350,7 +350,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, else if (metrics && !raw) printf("\nMetrics:\n\n"); - for (node = rb_first(&groups.entries); node; node = next) { + for (node = rb_first_cached(&groups.entries); node; node = next) { struct mep *me = container_of(node, struct mep, nd); if (metricgroups) diff --git a/tools/perf/util/rblist.c b/tools/perf/util/rblist.c index 0dfe27d99458..8256545344ed 100644 --- a/tools/perf/util/rblist.c +++ b/tools/perf/util/rblist.c @@ -13,8 +13,9 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry) { - struct rb_node **p = &rblist->entries.rb_node; + struct rb_node **p = &rblist->entries.rb_root.rb_node; struct rb_node *parent = NULL, *new_node; + bool leftmost = true; while (*p != NULL) { int rc; @@ -24,9 +25,10 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry) rc = rblist->node_cmp(parent, new_entry); if (rc > 0) p = &(*p)->rb_left; - else if (rc < 0) + else if (rc < 0) { p = &(*p)->rb_right; - else + leftmost = false; + } else return -EEXIST; } @@ -35,7 +37,7 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry) return -ENOMEM; rb_link_node(new_node, parent, p); - rb_insert_color(new_node, &rblist->entries); + rb_insert_color_cached(new_node, &rblist->entries, leftmost); ++rblist->nr_entries; return 0; @@ -43,7 +45,7 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry) void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node) { - rb_erase(rb_node, &rblist->entries); + rb_erase_cached(rb_node, &rblist->entries); --rblist->nr_entries; rblist->node_delete(rblist, rb_node); } @@ -52,8 +54,9 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, const void *entry, bool create) { - struct rb_node **p = &rblist->entries.rb_node; + struct rb_node **p = &rblist->entries.rb_root.rb_node; struct rb_node *parent = NULL, *new_node = NULL; + bool leftmost = true; while (*p != NULL) { int rc; @@ -63,9 +66,10 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, rc = rblist->node_cmp(parent, entry); if (rc > 0) p = &(*p)->rb_left; - else if (rc < 0) + else if (rc < 0) { p = &(*p)->rb_right; - else + leftmost = false; + } else return parent; } @@ -73,7 +77,8 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, new_node = rblist->node_new(rblist, entry); if (new_node) { rb_link_node(new_node, parent, p); - rb_insert_color(new_node, &rblist->entries); + rb_insert_color_cached(new_node, + &rblist->entries, leftmost); ++rblist->nr_entries; } } @@ -94,7 +99,7 @@ struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry) void rblist__init(struct rblist *rblist) { if (rblist != NULL) { - rblist->entries = RB_ROOT; + rblist->entries = RB_ROOT_CACHED; rblist->nr_entries = 0; } @@ -104,7 +109,7 @@ void rblist__init(struct rblist *rblist) void rblist__delete(struct rblist *rblist) { if (rblist != NULL) { - struct rb_node *pos, *next = rb_first(&rblist->entries); + struct rb_node *pos, *next = rb_first_cached(&rblist->entries); while (next) { pos = next; @@ -119,7 +124,8 @@ struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx) { struct rb_node *node; - for (node = rb_first(&rblist->entries); node; node = rb_next(node)) { + for (node = rb_first_cached(&rblist->entries); + node; node = rb_next(node)) { if (!idx--) return node; } diff --git a/tools/perf/util/rblist.h b/tools/perf/util/rblist.h index 4c8638a22571..4b16fc48a46d 100644 --- a/tools/perf/util/rblist.h +++ b/tools/perf/util/rblist.h @@ -20,7 +20,7 @@ */ struct rblist { - struct rb_root entries; + struct rb_root_cached entries; unsigned int nr_entries; int (*node_cmp)(struct rb_node *rbn, const void *entry); diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 855e35cbb1dc..a7ed1180d878 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -164,7 +164,7 @@ void perf_stat__reset_shadow_stats(void) memset(runtime_smi_num_stats, 0, sizeof(runtime_smi_num_stats)); memset(runtime_aperf_stats, 0, sizeof(runtime_aperf_stats)); - next = rb_first(&runtime_saved_values.entries); + next = rb_first_cached(&runtime_saved_values.entries); while (next) { pos = next; next = rb_next(pos); diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h index d58f1e08b170..7e82c71dcc42 100644 --- a/tools/perf/util/strlist.h +++ b/tools/perf/util/strlist.h @@ -57,7 +57,7 @@ static inline unsigned int strlist__nr_entries(const struct strlist *slist) /* For strlist iteration */ static inline struct str_node *strlist__first(struct strlist *slist) { - struct rb_node *rn = rb_first(&slist->rblist.entries); + struct rb_node *rn = rb_first_cached(&slist->rblist.entries); return rn ? rb_entry(rn, struct str_node, rb_node) : NULL; } static inline struct str_node *strlist__next(struct str_node *sn) -- 2.13.6 From 1585209158749219835@xxx Mon Nov 27 09:01:00 +0000 2017 X-GM-THRID: 1585209158749219835 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread