Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753996AbdH2Nv6 (ORCPT ); Tue, 29 Aug 2017 09:51:58 -0400 Received: from mga06.intel.com ([134.134.136.31]:24483 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237AbdH2Nv5 (ORCPT ); Tue, 29 Aug 2017 09:51:57 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,445,1498546800"; d="scan'208";a="129463909" From: Alexander Shishkin To: Alexey Budankov , Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Andi Kleen , Kan Liang , Dmitri Prokhorov , Valery Cherepennikov , Mark Rutland , Stephane Eranian , David Carrillo-Cisneros , linux-kernel Subject: Re: [PATCH v6 1/3] perf/core: use rb trees for pinned/flexible groups In-Reply-To: References: <96c7776f-1f17-a39e-23e9-658596216d6b@linux.intel.com> <20170803130002.oatczvnaalplrsep@hirez.programming.kicks-ass.net> <86cbe0b0-a1ec-4d5f-addc-87bccf2e97d7@linux.intel.com> <20170804143628.34c2xqxl2e6k2arj@hirez.programming.kicks-ass.net> <9d2e25c9-209c-f28a-d601-d3f1a71f032f@linux.intel.com> User-Agent: Notmuch/0.23.7 (http://notmuchmail.org) Emacs/25.1.1 (x86_64-pc-linux-gnu) Date: Tue, 29 Aug 2017 16:51:53 +0300 Message-ID: <87lgm2xz0m.fsf@ashishki-desk.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1206 Lines: 36 Alexey Budankov writes: > Now I figured that not all indexed events are always located under > the root with the same cpu, and it depends on the order of insertion > e.g. with insertion order 01,02,03,14,15,16 we get this: > > 02 > / \ > 01 14 > / \ > 03 15 > \ > 16 > > and it is unclear how to iterate cpu==0 part of tree in this case. Using this example, rb_next() should take you through the nodes in this order (assuming you start with 01): 01, 02, 03, 14, etc. So you iterate while event->cpu==cpu using rb_next() and you should be fine. > Iterating cpu specific subtree like this: > > #define for_each_group_event(event, group, cpu, pmu, field) \ > for (event = rb_entry_safe(group_first(group, cpu, pmu), \ > typeof(*event), field); \ > event && event->cpu == cpu && event->pmu == pmu; \ > event = rb_entry_safe(rb_next(&event->field), \ > typeof(*event), field)) Afaict, this assumes that you are also ordering on event->pmu, which should be reflected in your _less function. And also assuming that group_first() is doing the right thing. Can we see the code? Regards, -- Alex