Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp795299ybe; Fri, 13 Sep 2019 06:30:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOZtG1rmNaK1cChrPdpKpK9Fil+lLxj5/YHWi+wZHcvAnmMonRFa/iOGqhz6Y+Y5qvUV2X X-Received: by 2002:a50:9384:: with SMTP id o4mr2437395eda.8.1568381454039; Fri, 13 Sep 2019 06:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381454; cv=none; d=google.com; s=arc-20160816; b=atUUH6+s7iLyc47cXWtTx9ylhu6U0LVcVwCGRfFklidySHUNT1FHF87My8WSB7H4F8 11cI6D9C7qHRf6JqEYgnB92kdiJEruJRlXYIN1gTEMKFbFpOPy/0Vd3Wzp79O5rEmnb6 0oKOjsbIOk6mA2Ka2vfYBiDTIuFrSLKUQJol971nqfB6xrZgCNHckDT4QGVnVMjZW5hJ 8mjnWo55lo5XQkPVyertbhjWbYnDiSCL31UsvBcHDxCl4JAnE+L+oX1E7oB6o/o183lG hqiGI83lv1emNYkvOhCFvivVjYA09qFUqhTd0W8G4+9CG0rb58JMl2h+IJi0GjWAiqxe XHcw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QGMAKEZb2eCdXInxnl1MilaT1jJFb/OWImpWJVDyTro=; b=WGjOvSlOwbzJGRwV0wtp7I91K3XiR+2mFVDqk0217DDTPTe5m5zbViuxTq4uoSIba0 n68tuQyqm/1OZTHz44pt7aB5KvnxkhQ+eXBPmqv1dQJiE0WDQen1/MlobFpLNUDr4WtC BEHnBkHrdVrs7B8DLGeZgPgpcfmjFamAIWEZ3ME1qsA+24wwJwhHYNapapGLxJCB/Twv z/MXPEsyow7lIYZZg7GY7AXwx7IoIBzwUaA87d9eEtjSprIAM0JdHJfjQN2Bclx7Gk0n bDsgzBlS+BZRk91nqh23zWJxZmlSNcgu/GB4hYE55Acc4y3oPHkV4aHgy7M7gQydk2qp IVYQ== 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 y24si11103780ejb.344.2019.09.13.06.30.18; Fri, 13 Sep 2019 06:30:54 -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 S2391542AbfIMN0Q (ORCPT + 99 others); Fri, 13 Sep 2019 09:26:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39066 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391526AbfIMN0N (ORCPT ); Fri, 13 Sep 2019 09:26:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D89C308FBA9; Fri, 13 Sep 2019 13:26:13 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00C255C1D4; Fri, 13 Sep 2019 13:26:10 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH 55/73] libperf: Add perf_evlist_mmap_ops::new callback Date: Fri, 13 Sep 2019 15:23:37 +0200 Message-Id: <20190913132355.21634-56-jolsa@kernel.org> In-Reply-To: <20190913132355.21634-1-jolsa@kernel.org> References: <20190913132355.21634-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Sep 2019 13:26:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding perf_evlist_mmap_ops::new callback to be called in mmap_per_evsel to get/allocate the new 'struct perf_mmap' object. Adding libperf's perf_evlist__mmap_cb_new function as libperf's new callback. Link: http://lkml.kernel.org/n/tip-smr1w2e6j37ncbmsd1eet228@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/evlist.c | 32 +++++++++++++++++------- tools/perf/lib/include/internal/evlist.h | 3 +++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 67b5f14f738f..8caced7d489a 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -327,9 +327,23 @@ static void perf_evlist__set_sid_idx(struct perf_evlist *evlist, #define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y)) +static struct perf_mmap* +perf_evlist__mmap_cb_new(struct perf_evlist *evlist, bool overwrite, int idx) +{ + struct perf_mmap **maps, *map; + + map = perf_mmap__new(overwrite, NULL); + if (map == NULL) + return NULL; + + maps = overwrite ? evlist->mmap_ovw : evlist->mmap; + maps[idx] = map; + return map; +} + static int -mmap_per_evsel(struct perf_evlist *evlist, int idx, - struct perf_mmap_param *mp, int cpu_idx, +mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, + int idx, struct perf_mmap_param *mp, int cpu_idx, int thread, int *_output, int *_output_overwrite) { int evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx); @@ -348,18 +362,16 @@ mmap_per_evsel(struct perf_evlist *evlist, int idx, if (cpu == -1) continue; - map = perf_mmap__new(overwrite, NULL); + map = ops->new(evlist, overwrite, idx); if (map == NULL) return -ENOMEM; if (overwrite) { mp->prot = PROT_READ; output = _output_overwrite; - evlist->mmap_ovw[idx] = map; } else { mp->prot = PROT_READ | PROT_WRITE; output = _output; - evlist->mmap[idx] = map; } fd = FD(evsel, cpu, thread); @@ -410,7 +422,7 @@ mmap_per_thread(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, if (ops->idx) ops->idx(evlist, mp, thread, false); - if (mmap_per_evsel(evlist, thread, mp, 0, thread, + if (mmap_per_evsel(evlist, ops, thread, mp, 0, thread, &output, &output_overwrite)) goto out_unmap; } @@ -438,7 +450,7 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, ops->idx(evlist, mp, cpu, true); for (thread = 0; thread < nr_threads; thread++) { - if (mmap_per_evsel(evlist, cpu, mp, cpu, + if (mmap_per_evsel(evlist, ops, cpu, mp, cpu, thread, &output, &output_overwrite)) goto out_unmap; } @@ -459,7 +471,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist, const struct perf_cpu_map *cpus = evlist->cpus; const struct perf_thread_map *threads = evlist->threads; - if (!ops) + if (!ops || !ops->new) return -EINVAL; perf_evlist__for_each_entry(evlist, evsel) { @@ -478,7 +490,9 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist, int perf_evlist__mmap(struct perf_evlist *evlist, int pages) { struct perf_mmap_param mp; - struct perf_evlist_mmap_ops ops = { 0 }; + struct perf_evlist_mmap_ops ops = { + .new = perf_evlist__mmap_cb_new, + }; if (!evlist->mmap && perf_evlist__alloc_maps(evlist)) return -ENOMEM; diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h index 64522b8237be..3cb836912ee6 100644 --- a/tools/perf/lib/include/internal/evlist.h +++ b/tools/perf/lib/include/internal/evlist.h @@ -29,9 +29,12 @@ struct perf_evlist { typedef void (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool); +typedef struct perf_mmap* +(*perf_evlist_mmap__cb_new_t)(struct perf_evlist*, bool, int); struct perf_evlist_mmap_ops { perf_evlist_mmap__cb_idx_t idx; + perf_evlist_mmap__cb_new_t new; }; int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); -- 2.21.0