From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F344C433F5 for ; Mon, 28 Mar 2022 20:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345755AbiC1UaI (ORCPT ); Mon, 28 Mar 2022 16:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243163AbiC1UaD (ORCPT ); Mon, 28 Mar 2022 16:30:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B77F63CB; Mon, 28 Mar 2022 13:28:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 24206614AF; Mon, 28 Mar 2022 20:28:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5558CC34100; Mon, 28 Mar 2022 20:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648499301; bh=L9F9sed3I6zVMFBhDzt/us35ixJsSrs2mjG6DDuTy54=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HQMEO/8UzHEDmCqZYmz0LJD6GbzO1mLlKbjG3+mnvBT+qw8CkKnSLmeiLNBh0BY4K 0JxZ6sz1CNpFofH/2Ob2AMowYYw25Sa2VzOLz29PIpasDORj6pWNpS+k/PnS54/qCb vHNsEHJdSUfqUzUSh6+07Bdmn7G97d7zCE3I1XpGexHN6uA24H2exV4avMfJO52G/e dfXXWnQl+I+qGa68FnFUPaY4zojrvARdDYK5XSJ82+Nn4FWxj1W51+mnqR7nDbztuT PYW8hTw4f+vVVYPTbMvrLaNOSvkdSR54FsWJl/4A1AfdJAZZWj17Ta6265HfJ4O5yb yAuE8FFR+VQRg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 9A21340407; Mon, 28 Mar 2022 17:28:18 -0300 (-03) Date: Mon, 28 Mar 2022 17:28:18 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Stephane Eranian Subject: Re: [PATCH 3/5] perf cpumap: Add intersect function. Message-ID: References: <20220328062414.1893550-1-irogers@google.com> <20220328062414.1893550-4-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220328062414.1893550-4-irogers@google.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sun, Mar 27, 2022 at 11:24:12PM -0700, Ian Rogers escreveu: > The merge function gives the union of two cpu maps. Add an intersect > function which will be used in the next change. > > Signed-off-by: Ian Rogers > --- > tools/lib/perf/cpumap.c | 38 ++++++++++++++++++++++++++++ > tools/lib/perf/include/perf/cpumap.h | 2 ++ > 2 files changed, 40 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index 953bc50b0e41..56b4d213039f 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -393,3 +393,41 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, > perf_cpu_map__put(orig); > return merged; > } > + > +struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, > + struct perf_cpu_map *other) > +{ > + struct perf_cpu *tmp_cpus; > + int tmp_len; > + int i, j, k; > + struct perf_cpu_map *merged = NULL; > + > + if (perf_cpu_map__is_subset(other, orig)) > + return orig; > + if (perf_cpu_map__is_subset(orig, other)) { > + perf_cpu_map__put(orig); Why this put(orig)? > + return perf_cpu_map__get(other); And why the get here and not on the first if? > + } > + > + tmp_len = max(orig->nr, other->nr); > + tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu)); > + if (!tmp_cpus) > + return NULL; > + > + i = j = k = 0; > + while (i < orig->nr && j < other->nr) { > + if (orig->map[i].cpu < other->map[j].cpu) > + i++; > + else if (orig->map[i].cpu > other->map[j].cpu) > + j++; > + else { > + j++; > + tmp_cpus[k++] = orig->map[i++]; > + } > + } > + if (k) > + merged = cpu_map__trim_new(k, tmp_cpus); > + free(tmp_cpus); > + perf_cpu_map__put(orig); > + return merged; > +} > diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h > index 4a2edbdb5e2b..a2a7216c0b78 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -19,6 +19,8 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); > LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); > LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, > struct perf_cpu_map *other); > +LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, > + struct perf_cpu_map *other); > LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); > LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); > LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > -- > 2.35.1.1021.g381101b075-goog -- - Arnaldo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91048C433FE for ; Mon, 28 Mar 2022 20:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=h073S/l7MDIGg/CQ1npskJRWDkA+IYoKA5nZSxF5dX8=; b=qAie6jqT5Bye0C WWLAh1dDs9iRp+dz7susqv8+kF2DZ9kSMrjh/yvhpL8DsS2BZ0OC79LyOMpBuagV573DwwRR4yxXP hJNAHK6pwXjbweSf7HfFIhTGaYSwsHTh+eiK7tg20IJYfV+xiGwtu/nr2muN29pO4Mufp8iDIkkmK mdnLQpK2tnI/n8d83Z0l3CzQh1rWKMtflbFONEkPtcmMastThtvXvk6fcFsPYhXzRr/N7uYaS5Rid kD0Fe7jYzAuVOaZ3vkhx6Jl+hOQZq5uuVITix+JUGHeCycuENimZ2HHDFcY7uZi3xHNqPO1FCyopZ IK8Rrlsx0DbqsEXHskYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYvyT-00A4HO-1a; Mon, 28 Mar 2022 20:28:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYvyR-00A4Gz-Da for linux-arm-kernel@bombadil.infradead.org; Mon, 28 Mar 2022 20:28:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SDtks43Rgj8mIMjCkowhuAtV3UZVQekyKf0i7Iickww=; b=LjCyq2bavNY35JJcrSJuPGynw0 Y+LIbWPQCWnPgAyHtihAr27AVPQ9QUW4ZuMk8Ux+SrvA8VVGlV8xl2U6hLVY74vqplrhJmjCrq1GV 0LyIhVDEAbzxOwGZZepksZ5s+EDVm7M1bdcAcC1gczB+sPVUxBvmVy3zFAWYNHbu482/PbFGzDxHR 3bOSs3ZucCrKKgYD+XCtV2nNxDYjXqBDuw0TneclGko5oHtnElWDfboP0DBeE+/Adhv+CZA80+pBG KqL56Qj+l2v7TdZztJpX8Qa8tFEfpyFQcOwa3TbkNxJackJ0SdqMgkscJz9lXxMqDZltdAI+MdXqI 7jmBSySw==; Received: from [187.19.239.165] (helo=quaco.ghostprotocols.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYvyP-00HF0T-Rp; Mon, 28 Mar 2022 20:28:22 +0000 Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 9A21340407; Mon, 28 Mar 2022 17:28:18 -0300 (-03) Date: Mon, 28 Mar 2022 17:28:18 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Stephane Eranian Subject: Re: [PATCH 3/5] perf cpumap: Add intersect function. Message-ID: References: <20220328062414.1893550-1-irogers@google.com> <20220328062414.1893550-4-irogers@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220328062414.1893550-4-irogers@google.com> X-Url: http://acmel.wordpress.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Em Sun, Mar 27, 2022 at 11:24:12PM -0700, Ian Rogers escreveu: > The merge function gives the union of two cpu maps. Add an intersect > function which will be used in the next change. > > Signed-off-by: Ian Rogers > --- > tools/lib/perf/cpumap.c | 38 ++++++++++++++++++++++++++++ > tools/lib/perf/include/perf/cpumap.h | 2 ++ > 2 files changed, 40 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index 953bc50b0e41..56b4d213039f 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -393,3 +393,41 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, > perf_cpu_map__put(orig); > return merged; > } > + > +struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, > + struct perf_cpu_map *other) > +{ > + struct perf_cpu *tmp_cpus; > + int tmp_len; > + int i, j, k; > + struct perf_cpu_map *merged = NULL; > + > + if (perf_cpu_map__is_subset(other, orig)) > + return orig; > + if (perf_cpu_map__is_subset(orig, other)) { > + perf_cpu_map__put(orig); Why this put(orig)? > + return perf_cpu_map__get(other); And why the get here and not on the first if? > + } > + > + tmp_len = max(orig->nr, other->nr); > + tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu)); > + if (!tmp_cpus) > + return NULL; > + > + i = j = k = 0; > + while (i < orig->nr && j < other->nr) { > + if (orig->map[i].cpu < other->map[j].cpu) > + i++; > + else if (orig->map[i].cpu > other->map[j].cpu) > + j++; > + else { > + j++; > + tmp_cpus[k++] = orig->map[i++]; > + } > + } > + if (k) > + merged = cpu_map__trim_new(k, tmp_cpus); > + free(tmp_cpus); > + perf_cpu_map__put(orig); > + return merged; > +} > diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h > index 4a2edbdb5e2b..a2a7216c0b78 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -19,6 +19,8 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); > LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); > LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, > struct perf_cpu_map *other); > +LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, > + struct perf_cpu_map *other); > LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); > LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); > LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > -- > 2.35.1.1021.g381101b075-goog -- - Arnaldo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel