Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2185351rda; Tue, 24 Oct 2023 15:25:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwyVx1mjGyLerMM+8OlPxOQ8NinTtU4NoPqDrbgEUkCSazDAK7FRT+OHb2HhcEx9C1U0xu X-Received: by 2002:a05:6a20:7f95:b0:16b:a5fb:eee5 with SMTP id d21-20020a056a207f9500b0016ba5fbeee5mr5443101pzj.28.1698186345731; Tue, 24 Oct 2023 15:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186345; cv=none; d=google.com; s=arc-20160816; b=MWf1gmfeaMUr7jQIFugT5qPBrBfIdNUPBzGqR/BQRIdrF6wOoRGuMwmqQoMmwoz0TC eAv2JrStojb+sgo2r5n3QoCMz7pFoo+G4QR9l27LsL5hvNXyAgCRrqPgaVeNTtrq4kpZ tLwUHHW2wvQNVzNraegxWy/VvWta68wDa67zYRmcTnc0QlGLfKkM5DJ8DOI708I1LfMN bFHspNWJOnPvFyJpQUhnqnNp8KFerjM/AafdQZnj0bC0mWxD0SdrqIYDW9HKJPYOvz8F hXKRHLa7htURdo3Ki+uC57BxP7UHH+qGVT522tNroKbYsCwfFPAkMcvZOyxzrcpmz2AH 0vYg== 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=a57oV/e0Ni3jLZTf3mm6h3wI1Kphc9bMaGQTthj78GI=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=YlDeLFwZ4F+CFW8S11gUynjx5nY6HgnN1mKGoeRRsu5O2oIMCyT+OBtWME6OeMPg99 CcUC2XDTfDu0enMVSsK87qYyE+Q3OMdFq09yVgAWAbtL3MePorXhhsVbGaonSb3Q3XON T268RW2nDnzuZH0LjrIjrCVxiggdBcJ7i3mXmXl8owIop0gA1xjCadtn9zAMSeYNey3M xdt/3xnMi79quzWVCjpiOu/RMxeWr/NycPrdXh98lyUDU8Boq3R8WzPvBe99cZT1uzgL VfA6mrBZdWu3gSzvgp9AfjGtIXi/bPqO5Nyg1ydiu33055uvVbeRTX0HSt8hDuw53EtA HCZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lAtV+NBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j12-20020a170902da8c00b001cadc96944fsi5931038plx.495.2023.10.24.15.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:25:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lAtV+NBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 910678020375; Tue, 24 Oct 2023 15:25:42 -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 S1344501AbjJXWZb (ORCPT + 99 others); Tue, 24 Oct 2023 18:25:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344525AbjJXWZN (ORCPT ); Tue, 24 Oct 2023 18:25: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 7163410E2 for ; Tue, 24 Oct 2023 15:24:45 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a3a38b96cso5573853276.0 for ; Tue, 24 Oct 2023 15:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186282; x=1698791082; 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=a57oV/e0Ni3jLZTf3mm6h3wI1Kphc9bMaGQTthj78GI=; b=lAtV+NBSe+UpA5Rr+Qd3pgNNsrTd3pDBkC2VnSTgUeHV+/WWSNMzgqe+hFljO5X3Xe OW+vvhGQnJNm4LaVzIjI7Mlg1SDO/g6gUfX4HKCffk2z6HJ+26ZvARpkL3E+8ZHfEiRQ p4rx+J3d+OOBZnyPb4c6C1dmCCQInCcRR5niZhlW3zmENUqwYtFwfHrtPghdVmE5ViZD /OYXinPQu9CTdOApQBa9RBJx97eEE4TJiizBdQRj7eIwZO2UHpilM+OauJBRMUvxVxYt oeej7fuVOb+dKVoIcE/v1jPDbO8BUU2XBfNY5t1J5vouR/+WumYlOvgYAyAYc4ztMILH 0YUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186282; x=1698791082; 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=a57oV/e0Ni3jLZTf3mm6h3wI1Kphc9bMaGQTthj78GI=; b=Sm/ze2VOKNreCitf6wm1C8M8YpRpE7m3vhjxNN9qUbMASVbVCFo8wAj76kfUlNbHQE RGH0oWqA08IykJXnqv5Ji2teZeyTYdcLEVpy74rABjxJCd+4K+W9ZeLJwJDJodznh3fh SmVDNbKP86ZIUwOTWuYaWI5lqnkLHtSr7UF8LDFiWX4DqfNuoKjiUkz+zusA2T/h4dO8 SKk4bWhCw88SM6jfyQ4D5JKG5jSzqaVO/iTDDnj/pR8u1t+cKM7+1RUN5xgBSS91ZsNw IKsN+MgBzvX2c2Rt+Ik6h2JVA1s3Z0tEsJ1krKlgpjlsPVzMgLGHhXb3wD8jSbowoiaB mYZQ== X-Gm-Message-State: AOJu0YyHCm3FHO+ELtflow5uCYGShwaP9IHntBJO2EEOLm5w1hX++GwP qEEJxPFJ/YkuIWVgLLkxH+iyhMzZRrKU X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a05:6902:1083:b0:d9a:4f4c:961b with SMTP id v3-20020a056902108300b00d9a4f4c961bmr353600ybu.1.1698186282072; Tue, 24 Oct 2023 15:24:42 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:16 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-14-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 13/50] 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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , 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,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]); Tue, 24 Oct 2023 15:25:42 -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.758.gaed0368e0e-goog