Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4751336pxb; Tue, 31 Aug 2021 12:22:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySIVR1FnX49X7MdwAV5vRvW0u97pyRkKa1udPU3aLySp2M3/SSv2oq5hnbo5ttWhJTz09N X-Received: by 2002:a05:6638:2493:: with SMTP id x19mr4233076jat.57.1630437744967; Tue, 31 Aug 2021 12:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630437744; cv=none; d=google.com; s=arc-20160816; b=eF9WuKjFRyt++wb51wD4B42soTkYEqkF8hFGH5IkvsunQni+TQgWRhBh2SEDXiDovj 2m2J6ijjfZ5xS/SDoqLjGb+I3GuLGwxEFXo0gENNb3nPfVWGyQikZ0X0j7oQGvQQwlFk MDHwc/13qggRNyyGTKC9c+aMS2XcP+WPA09IONYpCzcS4uKP/lu3wmywPQK47ZbrLPTq JujYIuxI8ZfTQ3pese7q2+JUTTqCYnCrTmvJxZsf1JYyOrMPmHO5NOjXt3Zqa1wfd2ji oPKyr/GtDhMX5OgawsU/8e6htXGPrm/C9VHiyAvUXrjMBS6VPYGzsmFnkCrpAzcaJpd0 myNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lWg+/hh2sFAaYG7mdbknVUqsujpwveU2gMhmyhWUKA8=; b=k+PkKKkPLdarCjKkTKUUDm1z9shGFuEDTr29tROqhA9COMwh/GfYNGwMAtcDBV4FVf MIeOuYjbarUffr4+Xj/mIzGSn+6E3QG6+zJ6KM4rgXfwJlOjSt27sBT2LBF4y1zLYCQF l0Zx+fm7dGFk/3L9o/tT4youvZZePhzkaJIwX3skQRp9ZviBDh//HzTmJC7OQ+TVBbda rFV0Jj678uG47dOTITTnoCUTwnzOPZS8IuWtcZba62hERNbeJ/sLwYjm99HjCGsdi4la GpOmKvTDUXsSqA0uwbTEtWtOEQwWa8n+sh2uVXqpRTjFSAFAv/03nQQ9RpwuBr0Tk48A d9GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DEtKVnss; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si19606640ilu.150.2021.08.31.12.22.12; Tue, 31 Aug 2021 12:22:24 -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=@kernel.org header.s=k20201202 header.b=DEtKVnss; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240607AbhHaTWC (ORCPT + 99 others); Tue, 31 Aug 2021 15:22:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:39960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbhHaTV7 (ORCPT ); Tue, 31 Aug 2021 15:21:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C885604AC; Tue, 31 Aug 2021 19:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630437663; bh=y8xsBEhjhKK04c0aoOkUN1HQirrD7nQfR2QpWd0Iw1E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DEtKVnssoyFoVRvb+4oy/vKxBHXxGxsQukxpGJJxJGCJJvCjDWeBYg3VVhivAtb/T L/vdns4/PYJv5Y/mTrUZ6FlU9VXyqgre2/XdkkpeLJQJibSepZvhDJ3kOHcpYfc+bc s6dlCc7BEsewjC8NaWi0XwZ6VCjnnB39j9/nIgxw+oEGh91Ovh3NsPb+zcsjJ5+3m0 u6Vnw3eN/u8nWfs/sHGMft9lJqxoI/egEa4ev+Z7udubihP/y8CD3edHeaIwrqu9dp 8GLV6WSR3gVqcSAJfzraYmXRixrpZb2HbmxVmOexoPPAo2b/WvdoJGLQWlD/7XbaZ6 2by0hFRJWPpQw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 0F23B4007E; Tue, 31 Aug 2021 16:21:01 -0300 (-03) Date: Tue, 31 Aug 2021 16:21:01 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [RFC PATCH v1 04/37] perf util: add mmap_cpu_mask__duplicate function Message-ID: References: <8943a548ef7a3dd3e015095afad7e9a8b2154c05.1629490974.git.rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8943a548ef7a3dd3e015095afad7e9a8b2154c05.1629490974.git.rickyman7@gmail.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Aug 21, 2021 at 11:19:10AM +0200, Riccardo Mancini escreveu: > This patch adds a new function in util/mmap.c to duplicate a mmap_cpu_mask. > > This new function will be used in the following patches. > > Signed-off-by: Riccardo Mancini > --- > tools/perf/util/mmap.c | 12 ++++++++++++ > tools/perf/util/mmap.h | 3 +++ > 2 files changed, 15 insertions(+) > > diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c > index ab7108d22428b527..9e9a447682cc962c 100644 > --- a/tools/perf/util/mmap.c > +++ b/tools/perf/util/mmap.c > @@ -350,3 +350,15 @@ int perf_mmap__push(struct mmap *md, void *to, > out: > return rc; > } > + > +int mmap_cpu_mask__duplicate(struct mmap_cpu_mask *original, > + struct mmap_cpu_mask *clone) > +{ > + clone->nbits = original->nbits; > + clone->bits = bitmap_alloc(original->nbits); > + if (!clone->bits) > + return -ENOMEM; > + > + memcpy(clone->bits, original->bits, MMAP_CPU_MASK_BYTES(original)); > + return 0; > +} > diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h > index 9d5f589f02ae70e1..b4923e587fd7749c 100644 > --- a/tools/perf/util/mmap.h > +++ b/tools/perf/util/mmap.h > @@ -63,4 +63,7 @@ size_t mmap__mmap_len(struct mmap *map); > > void mmap_cpu_mask__scnprintf(struct mmap_cpu_mask *mask, const char *tag); > > +int mmap_cpu_mask__duplicate(struct mmap_cpu_mask *original, > + struct mmap_cpu_mask *clone); > + > #endif /*__PERF_MMAP_H */ The jargon here is class__clone(): ⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep __clone tools/perf/util/bpf-loader.c:bpf_map_op__clone(struct bpf_map_op *op) tools/perf/util/bpf-loader.c:bpf_map_priv__clone(struct bpf_map_priv *priv) tools/perf/util/bpf-loader.c: newop = bpf_map_op__clone(pos); tools/perf/util/bpf-loader.c: priv = bpf_map_priv__clone(tmpl_priv); tools/perf/util/cgroup.c: evsel = evsel__clone(pos); tools/perf/util/evsel.c: * evsel__clone - create a new evsel copied from @orig tools/perf/util/evsel.c:struct evsel *evsel__clone(struct evsel *orig) tools/perf/util/evsel.h: * Please check evsel__clone() to copy them properly so that tools/perf/util/evsel.h:struct evsel *evsel__clone(struct evsel *orig); tools/perf/util/map.h:struct map *map__clone(struct map *map); tools/perf/util/maps.h:int maps__clone(struct thread *thread, struct maps *parent); tools/perf/util/parse-events.c:int parse_events_term__clone(struct parse_events_term **new, tools/perf/util/parse-events.c: ret = parse_events_term__clone(&n, term); tools/perf/util/parse-events.h:int parse_events_term__clone(struct parse_events_term **new, tools/perf/util/symbol.c: struct map *m = map__clone(new_map); tools/perf/util/thread.c:static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone) tools/perf/util/thread.c: return do_maps_clone ? maps__clone(thread, parent->maps) : 0; tools/perf/util/thread.c: return thread__clone_maps(thread, parent, do_maps_clone); tools/perf/util/map.c:struct map *map__clone(struct map *from) tools/perf/util/map.c: struct map *before = map__clone(pos); tools/perf/util/map.c: struct map *after = map__clone(pos); tools/perf/util/map.c:int maps__clone(struct thread *thread, struct maps *parent) tools/perf/util/map.c: struct map *new = map__clone(map); tools/perf/util/pmu.c: ret = parse_events_term__clone(&cloned, term); ⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep __duplicate ⬢[acme@toolbox perf]$