From patchwork Thu Nov 2 17:56:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 161008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp533256vqu; Thu, 2 Nov 2023 10:58:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhx5rFcfF8kydHxnA1sBLLviHQa7mjLszaSymKtduEVYFOaM70eGQWo7cz5oCWwvlGVP/D X-Received: by 2002:a05:6a21:4841:b0:181:8e2:ba3c with SMTP id au1-20020a056a21484100b0018108e2ba3cmr8886364pzc.19.1698947939723; Thu, 02 Nov 2023 10:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698947939; cv=none; d=google.com; s=arc-20160816; b=ip2G4E7WSmJRZsm4GY1iHuYC9PYmubDlkPJ89V1sVEqXjQF1HrdFeYpku5rhdwT/3A XA9tSuHp1opakL0jpG5GgM5Mi3ozR0LwL4TkasTx4DTIeaKa/r1rs6cgP3k7XM01noZM FU6Du16PE0rgZhuawRAhg88LatPIW6v59h/IlHJus4UVvjmCqsmFnQUH5/lsNGuL65ll U8CNER14Xp6LaC4BgVH9vbxhubQkk3FQLt28CuxSPfhZ/y1Cg1OyX9ISU3KvKPKSSJRR J2Mm623FY8hKc06YTRctpnGTLbvAWEDEadKWZjzqm5jE9fZK+y4gxRxx+shYMsw6FBAo 6ufA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=45fiMNEp9HPngAxEFglGXsIL4df8TDdJeTxUUf03U6k=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=iCKBcKrSrCBWjJeiexJCJE77wMGG7gZlZ0alRhr1N+IQfmrKDK1alEP4FlrYXEw2rk hX+j1pd/IC7Y4PFRe7Gk2tNsPgvrYCs9QXp9M5Qlh/CLo+qXSzXvB0qOblwIFEIKLzDR xsX2HI3nCLwocKdebwr41jsY5FiYOLRKs82VN5X1Y6cnnQRoRJMyMRYuBvVIb1Imqs3R VYRZ2qBRfnnM/MBVihYMC6Uel4RxDnoy/R9+pMOfBOpF8bNm5fjnFdgNOXv8sx0253vC f3pVjHwgNqCmFlTWnew3zo2D91H5v93N9oqjsCz8U9J/VCVxQZJKC16Q4A8mWrl2NdVA rwvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZDeAbjg7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bs64-20020a632843000000b005b8eacb29c1si52414pgb.437.2023.11.02.10.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 10:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZDeAbjg7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4CFC7837EA4A; Thu, 2 Nov 2023 10:58:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345186AbjKBR6V (ORCPT + 35 others); Thu, 2 Nov 2023 13:58:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344990AbjKBR6N (ORCPT ); Thu, 2 Nov 2023 13:58:13 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED4341A6 for ; Thu, 2 Nov 2023 10:58:03 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da0cb98f66cso1414569276.2 for ; Thu, 02 Nov 2023 10:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947883; x=1699552683; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=45fiMNEp9HPngAxEFglGXsIL4df8TDdJeTxUUf03U6k=; b=ZDeAbjg7DorUI11gf20wny99hf5XbQfWunnSPi5m2R0HqVc8OL5uP07/PGLYd9Y90a f9teeab/1qgusnyL0LPb1etfZ5EWJ5vgf8AukOhCo4nC7hgC2jentTcDzalgx6PvTnEp vGt3ocDD6X2AecPEWf9gFIfcMuFiMPzsRLDkIRpZlO1bgeOi+M9bB8r0fqfALrwzzlIy jHs7MitmAzVeS9YCcFsnURV/w3ezT2H3wbu15KE0uaiZgY0p5kZ1+UPlBdJGQuBOWjOM oBBoK47cgaIC+gvIe9Mub1Q8gaDZIazLl6FnYNBLoxz7OEswjHCYi8xdepODCBzcWmcF hYIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947883; x=1699552683; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=45fiMNEp9HPngAxEFglGXsIL4df8TDdJeTxUUf03U6k=; b=m0bm5QWl3x7GAL0j8InzHUp27xoQty79er1GQqQ0ZMbMS3v6jc4Splc2VHBPMShCrG oCdB+uJFl9ve1yAydZV0n1+EGIAME++SPfhpSn/4BScGk9Z61V0qZZTlLem8kjakYkih pVAjpadCH9X7f6ol5506ZSlIEejR0L+VeKjL2K5k7tQZiSDpJZZgyKxmQcaeZA86dZj8 7e9J+dT3p1IQYkrzEJ2typHRjrHkcE/A40f78EvEHgeN10pik1w2HsWbX9qYxFtQvHmX Di+n9+IygGCxxZ2e0y9jEdoVRn7SpagUyvUXOg3pqs3NyvWprKs91zMvmkOKTgvPAviX 5M4w== X-Gm-Message-State: AOJu0YxpPdSY0hxaKJmhoSQ7/uhTstBvZF1GuzZA2trC7vtEWFmqeTeD Onq66fI7xEZoqnQvJza7q1Ek5xqX+3r0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a05:6902:168c:b0:da0:3e46:8ba5 with SMTP id bx12-20020a056902168c00b00da03e468ba5mr359884ybb.8.1698947882736; Thu, 02 Nov 2023 10:58:02 -0700 (PDT) Date: Thu, 2 Nov 2023 10:56:45 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-4-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 03/53] libperf: Lazily allocate mmap event copy From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 10:58:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781476034950982460 X-GMAIL-MSGID: 1781476034950982460 The event copy in the mmap is used to have storage to a read event. Not all users of mmaps read the events, such as perf record, so switch the allocation to being on first read rather than being embedded within the perf_mmap. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/lib/perf/include/internal/mmap.h | 2 +- tools/lib/perf/mmap.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/include/internal/mmap.h index 5a062af8e9d8..b11aaf5ed645 100644 --- a/tools/lib/perf/include/internal/mmap.h +++ b/tools/lib/perf/include/internal/mmap.h @@ -33,7 +33,7 @@ struct perf_mmap { bool overwrite; u64 flush; libperf_unmap_cb_t unmap_cb; - char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); + void *event_copy; struct perf_mmap *next; }; diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c index 2184814b37dd..91ae46aac378 100644 --- a/tools/lib/perf/mmap.c +++ b/tools/lib/perf/mmap.c @@ -51,6 +51,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, void perf_mmap__munmap(struct perf_mmap *map) { + free(map->event_copy); + map->event_copy = NULL; if (map && map->base != NULL) { munmap(map->base, perf_mmap__mmap_len(map)); map->base = NULL; @@ -226,6 +228,13 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map, unsigned int len = min(sizeof(*event), size), cpy; void *dst = map->event_copy; + if (!dst) { + dst = malloc(PERF_SAMPLE_MAX_SIZE); + if (!dst) + return NULL; + map->event_copy = dst; + } + do { cpy = min(map->mask + 1 - (offset & map->mask), len); memcpy(dst, &data[offset & map->mask], cpy);