Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp891144ybk; Wed, 20 May 2020 14:56:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXpoMgv3eeF6LgLn/bXm4RbbEDDg4eCc640Dae26+xdou35qWBAvQdAyZmxo9e4mutDS0j X-Received: by 2002:aa7:ca13:: with SMTP id y19mr5219868eds.30.1590011797146; Wed, 20 May 2020 14:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590011797; cv=none; d=google.com; s=arc-20160816; b=RZes5JjgHq1jcBLonNvwbFqc1B5RroNoDyg+YgtuwyMw15NMrpHNoN96NbPlKtn2aR 2dYRYgYHutZrzeZTllVk9XSmGejnaoiS00J7SRaIxY+IL7dQoSOJya5Sdnd8i7U9KIqT REtzUaETD7k03O2nUQDITMP0/KmyHsVn8VAcWCw20ho0QcdDWt1mzHuOR1HRtFr3JSn/ xIUH99Wce7/pxjIsWwPN7CvbyWbqNPeKZ1I8/N0pvI1Hia9RqEzSN0Pgxo6Fw3lxdxaS VNFTlai8+WfeYi0rp1siFIgdHtmEOP4Kq+ialPsKb+BHE3toFz3SjXM0AIlDyXqqH3k7 zj6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=K1eoD/CbeHmAwwQM5Kk034bbHXePj0f8t/9qXqJL1eo=; b=eT7x+4PdK8eUfasxxcXKXuLc/jej2nnsS96Pvb5l/4l9d+Ekzj7B1iVxYnT02/kYTZ 3aELMPHiWX3+17ywxDtPXOu4qz75+eUq43dx1TIlQLbysbPrgYEPSalL5hsF9oxNB91k AuHWMiYdrSd+Cgr1XNC3WEKPzi+Hq8Q0K/Q4o1sya1TTbD9YzZGzUYOdQgBr3vY18uvs OEPJrIEdqB4+1tbuQaHT6L7lqNG2dU1MHLorfB/JdD4W3m7XgWwb/J4kaFI3Qxxu6TRG O0MwHyp3adPsZ6LkU5JbV9SBX2XugmfKnOxzuaFkFMy4jt2CmDJsbl7RLiK0qNTBVIHZ n5lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VmcDX7Jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si2182620eji.141.2020.05.20.14.56.14; Wed, 20 May 2020 14:56:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VmcDX7Jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbgETVwn (ORCPT + 99 others); Wed, 20 May 2020 17:52:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33648 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728032AbgETVwm (ORCPT ); Wed, 20 May 2020 17:52:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590011560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=K1eoD/CbeHmAwwQM5Kk034bbHXePj0f8t/9qXqJL1eo=; b=VmcDX7JwTf5ihf5iii8uXNNaZvG3/HQRgQrgiB0lBEopLAiEir8ET0MLa0fEIWhBqPPn+Z 99nx67sMGwfnZlSrI7zZqRBIL7d6iue5UtqiEL2hCH3rGtlv9zRGmcU9DBcwR0h+LDhCox 6c/RzkEUDOP47ZK3u/xW/b8+2WRd01I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-JYwh_Y0HPJqVYzbY5uaHLg-1; Wed, 20 May 2020 17:52:37 -0400 X-MC-Unique: JYwh_Y0HPJqVYzbY5uaHLg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 629918015CF; Wed, 20 May 2020 21:52:36 +0000 (UTC) Received: from krava (unknown [10.40.193.10]) by smtp.corp.redhat.com (Postfix) with SMTP id 25AE960C05; Wed, 20 May 2020 21:52:34 +0000 (UTC) Date: Wed, 20 May 2020 23:52:34 +0200 From: Jiri Olsa To: Matt Fleming Cc: Jiri Olsa , Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf ordered_events: Optimise event object reuse Message-ID: <20200520215234.GO157452@krava> References: <20200515210151.2058-1-matt@codeblueprint.co.uk> <20200518120408.GD3726797@krava> <20200520130049.GC19431@codeblueprint.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200520130049.GC19431@codeblueprint.co.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 20, 2020 at 02:00:49PM +0100, Matt Fleming wrote: > On Mon, 18 May, at 02:04:08PM, Jiri Olsa wrote: > > On Fri, May 15, 2020 at 10:01:51PM +0100, Matt Fleming wrote: > > > ordered_event objects can be placed on the free object cache list in any > > > order which means future allocations may not return objects at > > > sequential locations in memory. Getting non-contiguous objects from the > > > free cache has bad consequences when later iterating over those objects > > > in ordered_events__queue(). > > > > > > For example, large perf.data files can contain trillions of events and > > > since objects that are next to each other in the free cache linked list > > > can point to pretty much anywhere in the object address space, lots of > > > cycles in ordered_events__queue() are spent servicing DTLB misses. > > > > > > Implement the free object cache using the in-kernel implementation of > > > interval trees so that objects can always be allocated from the free > > > object cache in sequential order, improving spatial locality and > > > reducing DTLB misses. > > > > > > Here are some numbers showing the speed up (reducing in execution time) > > > when running perf sched latency on sched events data and perf report on > > > HW_CPU_CYCLES. > > > > really nice, few questions below > > > > > > > > $ perf stat --null -r 10 -- bash -c \ > > > "export PAGER=cat ; perf sched latency -i $file --stdio &>/dev/null" > > > > > > Nr events File Size Before After Speed up > > > -------------- --------- -------- ------- ---------- > > > 123318457470 29MB 0.2149 0.2440 -13.5% > > > > should we be concerned about small data and the extra processing? > > I didn't look into this slowdown originally because it's ~2.9 ms, but > FYI it looks like this is caused by: > > - Longer code paths (more instructions) > - More branches > - More branch mispredicts > > > maybe we could add some option that disables this, at leat to be > > able to compare times in the future > > Sure. Do you mean a command-line option or build-time config? command line option would be great SNIP > > > diff --git a/tools/perf/tests/free-object-cache.c b/tools/perf/tests/free-object-cache.c > > > new file mode 100644 > > > index 000000000000..e4395ece7d2b > > > --- /dev/null > > > +++ b/tools/perf/tests/free-object-cache.c > > > @@ -0,0 +1,200 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +#include "tests.h" > > > +#include > > > + > > > +#define ordered_events__flush_time __test_ordered_events__flush_time > > > +#define ordered_events__first_time __test_ordered_events__first_time > > > +#define ordered_events__delete __test_ordered_events__delete > > > +#define ordered_events__init __test_ordered_events__init > > > +#define ordered_events__free __test_ordered_events__free > > > +#define ordered_events__queue __test_ordered_events__queue > > > +#define ordered_events__reinit __test_ordered_events__reinit > > > +#define ordered_events__flush __test_ordered_events__flush > > > > I'm excited to see these tests, but why is above needed? > > > > can't you use ordered-events interface as it is? you used only > > exported functions right? > > Nope, the tests in this file are unit tests so I'm testing > free_cache_{get,put} which are file-local functions by #include'ing > ordered-events.c. > > The above define are required to avoid duplicate symbol errors at > link-time, e.g. > > util/perf-in.o: In function `ordered_events__flush_time': > /home/matt/src/kernels/linux/tools/perf/util/ordered-events.c:461: multiple definition of `ordered_events__flush_time' > tests/perf-in.o:/home/matt/src/kernels/linux/tools/perf/tests/../util/ordered-events.c:461: first defined here > > There are other ways to resolve this (linker flags to change the > symbols) but I couldn't find any precedent with that, so this seemed > like the easiest and most obvious solution. I'm happy to fix this up any > other way if you have suggestions though. hum, could we just make free_cache_{get,put} public? thanks, jirka