Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp871226ybg; Fri, 18 Oct 2019 08:35:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqym4QEKBnbPmkd8gAYbXCjQ+nqdWD4qMK3eqYkCpmS1I8niy1DCGQ5csFeufnlfNxIC3S00 X-Received: by 2002:a17:906:5c0a:: with SMTP id e10mr9220819ejq.285.1571412929828; Fri, 18 Oct 2019 08:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571412929; cv=none; d=google.com; s=arc-20160816; b=Us85JM7Dr/xPlzzMxlU8V3ELSZw71p7krU8I0TYMgeXeQ49tt6EgaUAp4nBE4VQRHR ArBCIQtikv4LKN+VdcZHsscpez1Afo3EVyWqBTy3vM7Ug8+nehixClryMLRBJtIA7RcP FR57F243sO97AaQrAz7lfD4+07dYhyjFGQjDGW8HOiO/kQuiqXSFSU8OYGsBFymtpjis J3MBrCIO7EtyEBJOufjulnMW999XS8y1/vJWJntFUZLblbx5HXvk4XXa+Xon+Il1yX3M xO2T60lq7GrVv9YU5XM7urN3bdkzmcf6jwj99rYaL9tWPsnAP7Apia8c6mjyWVwY+zeM 0YIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=fcirrAPokSx+9GV67avpVj31FqnXwNVPhr2MYBOPo9U=; b=ray3GhxxboGKebt4i2KgKYHO97MvABLue9bb6URMAsfD7eGbbSsyM4kkoha4Oq0UgH hIALnLLD080B96dcW7/ZqFEXJ417Mycwx1/Cu1KIjlneWJm6KnvNrLXVihjuT9hh5+yN 6Z1FPPkLQPk3YyVfdalqahYH7KOeRvf22mYf5XftTb1S40GuGimchpJYMlWlhqDujQb4 vkZwX89K3JZ46gwAu0V/Dk1WcoV6T6WH5W0Zek/bSylIRlZyHcjkODQapPyDhqfObtAG iKlSHUM0fvpARnVg3ASwDAaMgXNCBbFj/SjCF+RH6TJ0OcyO3e0eXymfadnEa9/4u2Ng jdtw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si244238eda.192.2019.10.18.08.35.06; Fri, 18 Oct 2019 08:35:29 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409081AbfJQK7X (ORCPT + 99 others); Thu, 17 Oct 2019 06:59:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60748 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729441AbfJQK7X (ORCPT ); Thu, 17 Oct 2019 06:59:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 135C6881363; Thu, 17 Oct 2019 10:59:22 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEC4A5D70D; Thu, 17 Oct 2019 10:59:18 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Kan Liang , Steven Rostedt , Adrian Hunter , Ian Rogers , Stephane Eranian , Song Liu , Alexey Budankov , Andi Kleen , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Jin Yao Subject: [PATCHv3 00/10] libperf: Add sampling interface (leftover) Date: Thu, 17 Oct 2019 12:59:08 +0200 Message-Id: <20191017105918.20873-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 17 Oct 2019 10:59:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hi, sending changes for exporting basic sampling interface in libperf. It's now possible to use following code in applications via libperf: --- (example is without error checks for simplicity) struct perf_event_attr attr = { .type = PERF_TYPE_TRACEPOINT, .sample_period = 1, .wakeup_watermark = 1, .disabled = 1, }; /* ... setup attr */ cpus = perf_cpu_map__new(NULL); evlist = perf_evlist__new(); evsel = perf_evsel__new(&attr); perf_evlist__add(evlist, evsel); perf_evlist__set_maps(evlist, cpus, NULL); err = perf_evlist__open(evlist); err = perf_evlist__mmap(evlist, 4); err = perf_evlist__enable(evlist); /* ... monitored area, plus all the other cpus */ err = perf_evlist__disable(evlist); perf_evlist__for_each_mmap(evlist, map) { if (perf_mmap__read_init(map) < 0) continue; while ((event = perf_mmap__read_event(map)) != NULL) { perf_mmap__consume(map); } perf_mmap__read_done(map); } perf_evlist__delete(evlist); perf_cpu_map__put(cpus); --- (end) Nothing is carved in stone so far, the interface is exported as is available in perf now and we can change it as we want. New tests are added in test-evlist.c to do thread and cpu based sampling. All the functionality should not change, however there's considerable mmap code rewrite. Now we have perf_evlist__mmap_ops called by both perf and libperf mmaps functions with specific 'struct perf_evlist_mmap_ops' callbacks: - get - to get mmap object, both libperf and perf use different objects, because perf needs to carry more data for aio, compression and auxtrace - mmap - to actually mmap the object, it's simple mmap for libperf, but more work for perf wrt aio, compression and auxtrace - idx - callback to get current IDs, used only in perf for auxtrace setup It would be great if guys could run your usual workloads to see if all is fine.. so far so good in my tests ;-) It's also available in here: git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git perf/lib v3 changes: - changed mmap0 and mmap_ovw0 to mmap_first and mmap_ovw_first - rebased to latest perf/core - portion of patches already taken v2 changes: - rebased to latest perf/core - portion of patches already taken - explained mmap refcnt management in following patch changelog: libperf: Centralize map refcnt setting thanks, jirka Cc: Kan Liang Cc: Steven Rostedt Cc: Adrian Hunter Cc: Ian Rogers Cc: Stephane Eranian Cc: Song Liu Cc: Alexey Budankov Cc: Andi Kleen --- Jiri Olsa (10): libperf: Add perf_evlist__for_each_mmap function libperf: Move mmap allocation to perf_evlist__mmap_ops::get libperf: Move mask setup to perf_evlist__mmap_ops function libperf: Link static tests with libapi.a libperf: Add _GNU_SOURCE define to compilation libperf: Add tests_mmap_thread test libperf: Add tests_mmap_cpus test libperf: Keep count of failed tests libperf: Do not export perf_evsel__init/perf_evlist__init libperf: Add pr_err macro tools/perf/lib/Makefile | 2 ++ tools/perf/lib/evlist.c | 71 ++++++++++++++++++++++++++++++++++++++--------------- tools/perf/lib/include/internal/evlist.h | 3 +++ tools/perf/lib/include/internal/evsel.h | 1 + tools/perf/lib/include/internal/mmap.h | 5 ++-- tools/perf/lib/include/internal/tests.h | 20 ++++++++++++--- tools/perf/lib/include/perf/core.h | 1 + tools/perf/lib/include/perf/evlist.h | 10 +++++++- tools/perf/lib/include/perf/evsel.h | 2 -- tools/perf/lib/internal.h | 3 +++ tools/perf/lib/libperf.map | 3 +-- tools/perf/lib/mmap.c | 6 +++-- tools/perf/lib/tests/Makefile | 8 +++--- tools/perf/lib/tests/test-cpumap.c | 2 +- tools/perf/lib/tests/test-evlist.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- tools/perf/lib/tests/test-evsel.c | 2 +- tools/perf/lib/tests/test-threadmap.c | 2 +- tools/perf/util/evlist.c | 29 +++++++++------------- 18 files changed, 333 insertions(+), 55 deletions(-)