Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp553224rdb; Thu, 2 Nov 2023 10:58:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiHsge1ecAko5jMYNISN+PGgGWjiRke7hbIgsFFaDbx45QY7gjW4vwDWV0QU2kBAypiL8G X-Received: by 2002:a05:6358:70e:b0:168:e5e7:e652 with SMTP id e14-20020a056358070e00b00168e5e7e652mr18392049rwj.7.1698947925490; Thu, 02 Nov 2023 10:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698947925; cv=none; d=google.com; s=arc-20160816; b=Umnf2JRxmvIBscsT5zrFx1Vtshanjr2eWZ5z1qt5d6fdV09HNqSoZCPieapuGNzRhe n9rDBXS9ZIh0Nv8fczcYADdbQzh+/m0COso0Or0g9iVqxNLdFcj1wMhFdB/suy1yXQCL 0myvdRrAIUZxkUUYCUIb6t/sT2njdY2jfgrIcSXJVWCjpmm4/miC7ADDOOk0VGaWC7BP MGaursJtJ0QqRdAdYDUpr9mZC/CLL2Dz7rCMbb5ITnbK91r/UATDFqMjthhs51pkX2D2 YAFJDyZcadLsVdb1r7iHBglhdYDMTrm173/M0dsijwdm4nozGTdGDXca00FSE34tv1pi xs9w== 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 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id c124-20020a633582000000b005ae22729b09si49901pga.683.2023.11.02.10.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 10:58:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; 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 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id ED63A820D5CF; Thu, 2 Nov 2023 10:58:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343712AbjKBR6V (ORCPT + 99 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 Content-Type: text/plain; charset="UTF-8" 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 10:58:38 -0700 (PDT) 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 --- 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); -- 2.42.0.869.gea05f2083d-goog