From patchwork Mon Mar 28 23:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12794329 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 1FAF2C433EF for ; Mon, 28 Mar 2022 23:29:05 +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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=RezBf7KQ7bM83CKZtGDs/6OnH3zQHMpheKl2NkQ8f78=; b=W1JNJK0RyCRsUqWJUzxVY6RohC ICBzejnCZbcTvIO0helIqA5jG16KeTFiyso3QUZgDsaWNs8QYDGnXGJfgFQfy4lW+Mn6TNAWhjmlT 3g+Hur2a/1F033D6I+Ji+a1RVyFctVvmokh4lnRvIuNsTiLqI24bxHMDMj9vfNDGFMcwfqxOaJtK/ 7SAwGGkvu7R7L/iIJWwxxVL5Sc4ON+cmMh/OHQMgD6HtwynesUvrl5DOFAx73JHXpO8mAxwObljeI 47YJ/zLUSzVwypRSoW28LPa2FNAwkKt+CxdWKZx0DlfSGRM6MBuI9ajGFKcv8GoUr8uder+zSPpnp O6tXj8vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYym5-00ARbl-4B; Mon, 28 Mar 2022 23:27:49 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYylL-00ARGl-N0 for linux-arm-kernel@lists.infradead.org; Mon, 28 Mar 2022 23:27:05 +0000 Received: by mail-yb1-xb49.google.com with SMTP id y193-20020a25dcca000000b00636d788e549so10997134ybe.5 for ; Mon, 28 Mar 2022 16:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wTKe8RpF21rMt2kcDMmTht0LJEvhd7SCLcprAeqvk0k=; b=T+4CDrUc5B8KgUxLdGAYIFFTV/O9bYCD2ejWPkf6qr6F1udOCh/a2NQLPEB+f3E/NX 4TWmJqbMg2E9di4NS0w6fgrYVbAYscM4TtPW15WASNVFdWbW4eNnH2cHi0Ld3Mk1u6l+ aRkS3ldnET20rnCamLxmrQuXIDBXQDi9UG/NdvJ1h1itQe2WvqFiz/QGC1DXWyZjF8eh PZJ43qGpWsndy7U8UxNZkEd4PrX+UBILlb0wU9QU2Qgeh99PvTxAh3LRjkaZxeFHT7GX wMFm3Im+nIYQIFbJdUfT4UE0Y7ZyLX7I9IdOPOEvOjJFyVb+ArG5Ui/FgzgqWPqc0er1 IhyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wTKe8RpF21rMt2kcDMmTht0LJEvhd7SCLcprAeqvk0k=; b=JPv31M+YDyLiiqufenmS4YCYfj30uZRDWPF7/4ZkGHYmABtODRsAlTFFMJb3dj/RgJ 3bCG9j/VdNfDAC4OYkJPrV7YMFYUERo0l1s/EAiQAauogVkkfhE5FTn2+ixAHLtaF8Lq QlLI6gqP5BlklMRiadRTkFWh+wMgTVG82wF6EnTcFzi3iEXFVMm1XOfAPWpFlqZToHRf RrBMvrd5mdAOQ2+aZGSka8f61O6pzC+CHQTK7vKAt6rtdebh8PuBBLSd3//8VGOgdWzd gd0+HHMmPyj/mPvPkY8DyOIG625la4u8klRTb+vzq6bXjLNhCdL6zKoJOmyrJKlWdRg6 17PA== X-Gm-Message-State: AOAM533xu6Kdkbby1Chj0cweakc8mWBy7wglq023FJC1fqC5Lc/Dafrc /XMH66M2V96oLDEWilZZdUuvVSpQfeTe X-Google-Smtp-Source: ABdhPJz0C9b/wpARXJ780K4O2sn/803EfldbYME8HRYxuiKm0vuJpVEupKAKTIMkx4gfX2bF+RArPAe9TLyO X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a25:5f06:0:b0:633:80e1:6336 with SMTP id t6-20020a255f06000000b0063380e16336mr25503992ybb.100.1648510022185; Mon, 28 Mar 2022 16:27:02 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:46 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-5-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 4/6] perf cpumap: More cpu map reuse by merge. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , 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 Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220328_162703_781024_6E24F9C8 X-CRM114-Status: GOOD ( 15.33 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org perf_cpu_map__merge will reuse one of its arguments if they are equal or the other argument is NULL. The arguments could be reused if it is known one set of values is a subset of the other. For example, a map of 0-1 and a map of just 0 when merged yields the map of 0-1. Currently a new map is created rather than adding a reference count to the original 0-1 map. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 23701024e0c0..384d5e076ee4 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -355,17 +355,12 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, int i, j, k; struct perf_cpu_map *merged; - if (!orig && !other) - return NULL; - if (!orig) { - perf_cpu_map__get(other); - return other; - } - if (!other) - return orig; - if (orig->nr == other->nr && - !memcmp(orig->map, other->map, orig->nr * sizeof(struct perf_cpu))) + if (perf_cpu_map__is_subset(orig, other)) return orig; + if (perf_cpu_map__is_subset(other, orig)) { + perf_cpu_map__put(orig); + return perf_cpu_map__get(other); + } tmp_len = orig->nr + other->nr; tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu));