Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932080AbdHWOTS (ORCPT ); Wed, 23 Aug 2017 10:19:18 -0400 Received: from mga03.intel.com ([134.134.136.65]:6229 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754067AbdHWOTR (ORCPT ); Wed, 23 Aug 2017 10:19:17 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,417,1498546800"; d="scan'208";a="143698969" Subject: Re: [PATCH v6 1/3] perf/core: use rb trees for pinned/flexible groups To: Alexander Shishkin , 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 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> <87o9r6z9lt.fsf@ashishki-desk.ger.corp.intel.com> From: Alexey Budankov Organization: Intel Corp. Message-ID: <6e70f551-a9a3-deb9-67b1-a82251d69c36@linux.intel.com> Date: Wed, 23 Aug 2017 17:18:54 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <87o9r6z9lt.fsf@ashishki-desk.ger.corp.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1981 Lines: 80 On 23.08.2017 16:39, Alexander Shishkin wrote: > Alexey Budankov writes: > >>>>>> bool event_less(left, right) >>>>>> { >>>>>> if (left->cpu < right->cpu) >>>>>> return true; >>>>>> >>>>>> if (left->cpu > right_cpu) >>>>>> return false; >>>>>> >>>>>> if (left->vtime < right->vtime) >>>>>> return true; >>>>>> >>>>>> return false; >>>>>> } >>>>>> >>>>>> insert_group(group, event, tail) >>>>>> { >>>>>> if (tail) >>>>>> event->vtime = ++group->vtime; >>>>>> >>>>>> tree_insert(&group->root, event); >>>>>> } > > [ ... ] > >> 2. implementing special _less() function and rotation by re-inserting >> group with incremented index; >> > > [ ... ] > >> 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 > > How did you arrive at this? Seeing the actual code would help, because > this is not the ordering we're looking for. With Peter's earlier example > (quoted above) it shouldn't look like this. I implemented the solution Peter suggested. Then I was testing and noticed considerable difference in amount of collected samples when multiplexing event, in comparison to the version with tree of lists. I then looked for a fast way to emulate the idea with virtual index as a secondary key and found this RB tree emulator: https://www.cs.usfca.edu/~galles/visualization/RedBlack.html and it showed me the picture I mentioned above: 02 / \ 01 14 / \ 03 15 \ 16 I understand it is not 100% proof that index idea doesn't work however it means that in order to apply the idea to this patch some more changes are required additionally to what Peter shared earlier. > > Regards, > -- > Alex > > >