Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755418AbaBRNER (ORCPT ); Tue, 18 Feb 2014 08:04:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20362 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754887AbaBRNEP (ORCPT ); Tue, 18 Feb 2014 08:04:15 -0500 Date: Tue, 18 Feb 2014 14:04:05 +0100 From: Jiri Olsa To: Don Zickus Cc: acme@ghostprotocols.net, LKML , jmario@redhat.com, fowles@inreach.com, eranian@google.com Subject: Re: [PATCH 09/21] perf, c2c: Add rbtree sorted on mmap2 data Message-ID: <20140218130405.GI4343@krava.brq.redhat.com> References: <1392053356-23024-1-git-send-email-dzickus@redhat.com> <1392053356-23024-10-git-send-email-dzickus@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1392053356-23024-10-git-send-email-dzickus@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 10, 2014 at 12:29:04PM -0500, Don Zickus wrote: > In order for the c2c tool to work correctly, it needs to properly > sort all the records on uniquely identifiable data addresses. These > unique addresses are converted from virtual addresses provided by the > hardware into a kernel address using an mmap2 record as the decoder. > SNIP > +static int physid_cmp(struct c2c_entry *left, struct c2c_entry *right) > +{ > + u64 l, r; > + struct map *l_map = left->mi->daddr.map; > + struct map *r_map = right->mi->daddr.map; > + > + /* group event types together */ > + if (left->cpumode > right->cpumode) return 1; > + if (left->cpumode < right->cpumode) return -1; > + > + if (l_map->maj > r_map->maj) return 1; > + if (l_map->maj < r_map->maj) return -1; > + > + if (l_map->min > r_map->min) return 1; > + if (l_map->min < r_map->min) return -1; > + > + if (l_map->ino > r_map->ino) return 1; > + if (l_map->ino < r_map->ino) return -1; > + > + if (l_map->ino_generation > r_map->ino_generation) return 1; > + if (l_map->ino_generation < r_map->ino_generation) return -1; > + > + /* > + * Addresses with no major/minor numbers are assumed to be > + * anonymous in userspace. Sort those on pid then address. > + * > + * The kernel and non-zero major/minor mapped areas are > + * assumed to be unity mapped. Sort those on address then pid. > + */ > + > + /* al_addr does all the right addr - start + offset calculations */ > + l = left->mi->daddr.al_addr; > + r = right->mi->daddr.al_addr; > + > + if (l_map->maj || l_map->min) { > + /* mmapped areas */ > + > + /* hack to mark similar regions, 'right' is new entry */ > + /* entries with same maj/min/ino/inogen are in same address space */ > + right->color = REGION_SAME; > + > + if (l > r) return 1; > + if (l < r) return -1; > + > + /* sorting by iaddr makes calculations easier later */ > + if (left->mi->iaddr.al_addr > right->mi->iaddr.al_addr) return 1; > + if (left->mi->iaddr.al_addr < right->mi->iaddr.al_addr) return -1; > + > + if (left->thread->pid_ > right->thread->pid_) return 1; > + if (left->thread->pid_ < right->thread->pid_) return -1; > + > + if (left->thread->tid > right->thread->tid) return 1; > + if (left->thread->tid < right->thread->tid) return -1; > + } else if (left->cpumode == PERF_RECORD_MISC_KERNEL) { > + /* kernel mapped areas where 'start' doesn't matter */ > + > + /* hack to mark similar regions, 'right' is new entry */ > + /* whole kernel region is in the same address space */ > + right->color = REGION_SAME; > + > + if (l > r) return 1; > + if (l < r) return -1; > + > + /* sorting by iaddr makes calculations easier later */ > + if (left->mi->iaddr.al_addr > right->mi->iaddr.al_addr) return 1; > + if (left->mi->iaddr.al_addr < right->mi->iaddr.al_addr) return -1; > + > + if (left->thread->pid_ > right->thread->pid_) return 1; > + if (left->thread->pid_ < right->thread->pid_) return -1; > + > + if (left->thread->tid > right->thread->tid) return 1; > + if (left->thread->tid < right->thread->tid) return -1; > + } else { > + /* userspace anonymous */ > + if (left->thread->pid_ > right->thread->pid_) return 1; > + if (left->thread->pid_ < right->thread->pid_) return -1; > + > + if (left->thread->tid > right->thread->tid) return 1; > + if (left->thread->tid < right->thread->tid) return -1; > + > + /* hack to mark similar regions, 'right' is new entry */ > + /* userspace anonymous address space is contained within pid */ > + right->color = REGION_SAME; > + > + if (l > r) return 1; > + if (l < r) return -1; > + > + /* sorting by iaddr makes calculations easier later */ > + if (left->mi->iaddr.al_addr > right->mi->iaddr.al_addr) return 1; > + if (left->mi->iaddr.al_addr < right->mi->iaddr.al_addr) return -1; > + } > + > + return 0; > +} there's sort object doing exatly this over hist_entry's Is there any reason not to use hist_entries? jirka -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/