From patchwork Tue Jan 31 02:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 50572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2516881wrn; Mon, 30 Jan 2023 18:35:48 -0800 (PST) X-Google-Smtp-Source: AK7set/uq6o9Uk9Hzah0n6TO4XRxBuvw3tSsCAmOVnkSvigTKcbeqAF14ITcewmPKoDg3A6BpvSK X-Received: by 2002:a17:906:3789:b0:87d:eff1:acc8 with SMTP id n9-20020a170906378900b0087deff1acc8mr14166887ejc.48.1675132547971; Mon, 30 Jan 2023 18:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675132547; cv=none; d=google.com; s=arc-20160816; b=BliqQKx7DXoIWJuligmsFQEI9En9L0LpCJBoCulB0vVXwPK1DmKgnwhS4SP3dgDLA1 eAssSvhVVoOU4ETDPg9WiMg3ARvHg/LLwJzt/n+R9Ky3Qg3jWW6jar4gFbMJWFJRdifV oBgp5eNHTzJX/5DDPJpoWuXrNQC0DdPjgBACGdvyBhyXLu7zCZraE9pMAA8WUWYqP3el rhnS9gMQBiOtzPrhM0B0tD+IDFQAOMCOcd+Xk5YthFZjPgnvJxxHv0YBrdEH62fjpG3W ocAbD6MpmQqQDKJCqyKjUSP2nAhQUym8GXWLl1hXNHy4WVcYDwsU+Mu6+DpDD7Sl2RmI Hu5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=UYmg7u8BuMXGs5kfhUOaWTWsCts8KrLu3C1CWq/3WHM=; b=FjTCxNQiuB7v6UDTj94KgEwEHg7ou9tRRo37w6G1E6AMk8rKnvmR5uGwLsqdDQV57E d8icxPlDgZAHTQxK99XGXEWSXy8rCj8PD2MZAviBarqu0fD0MJYgPOUI6YHY/iiaElrm dEYIYkEmTaTQb5e2KT9lws8QPROSbNVNmcjSCDK7+L+DDFCVbFYhP7wckJ5ylzt6lKEI DDLTR1Va67IilEsk79o1ys8OSA1AngsY1neCnVwTpldj+G1SA6lw0WPdiFsaoMAzdPPf kRGPGJNnorujk8L9c96OgQPAwGov4Ikgt/xsfH/91vrmbMjKK1NkUxB3OZxH4dpS1pQ9 4Czg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RTGJbkgf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a170906018d00b0087f1daeb101si11697147ejb.312.2023.01.30.18.35.24; Mon, 30 Jan 2023 18:35:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RTGJbkgf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229895AbjAaCeB (ORCPT + 99 others); Mon, 30 Jan 2023 21:34:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbjAaCd4 (ORCPT ); Mon, 30 Jan 2023 21:33:56 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DC6233E6; Mon, 30 Jan 2023 18:33:54 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so13073141pjl.0; Mon, 30 Jan 2023 18:33:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=UYmg7u8BuMXGs5kfhUOaWTWsCts8KrLu3C1CWq/3WHM=; b=RTGJbkgf23Vqp0k6oNVwNP/dnObdTu5cDug2Sy9PX/05iTauQBtYdWbumFoFberAEJ Dva/GD2vHJSRgljKfENSIfM8h0Ht4NDON0CbdHpojXxjASUdBbH8G1JGVovp0BSRYmPW Yr+BvfOk6WX3zHhFlUx9pkeOOFBkxXKQ9nOApt0hL05Gzmt/CqWiiHxjteRVQiwaxr2U WVwoXYqQ7T7sSE48/nnBgEbR4pyV7v9ff8ms15oT1XiwLrot3c08/jkj4+tLVVKEq+gx Mg92A4LsBW3tNhq+9a3vyV9le0NI8aYz9ysgY+ih8B4c3QUJejnIweno94hxpruKYWge v0wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UYmg7u8BuMXGs5kfhUOaWTWsCts8KrLu3C1CWq/3WHM=; b=JHABnFZ6DsiSfDmqPP6AU+ztYdG2QzoOiDGIoX4K91eiSpe10QaSdf0cNWdIhrYnRX sqqzeZllDo8MNj4e8gObHZNEgpQAhZT3gmCmyGCxHRaAnEih6HWY48xplcVuLDRCEXHU HBUDvlKQrfeIgGgxHCUK3v+iYsW8PgP06+Q74ijhxH9+zUHtUwtsqY9xvQwQGGRjXMwB ebU+hb7qQNdjifWUcBy3zflsTuJt8llSExJ7vXuOwtKaqzDovDOcfxx7I4d1Q8PoORS2 j038aLYYbG28sUXjOt93gnDQ7Mxv8IYQ7NxVauI5lwXRb5UkYgxk6fcBDPeKrluL1cJ1 MO4g== X-Gm-Message-State: AO0yUKVHq26QGaHmAfW9T3tqqpR9gT1j/cmmv+LOhUdbcJx2JYD/acYT ogriZxqF7tq9URZdDK6MTd4= X-Received: by 2002:a17:90a:1952:b0:22c:3edd:7e48 with SMTP id 18-20020a17090a195200b0022c3edd7e48mr16423999pjh.32.1675132434199; Mon, 30 Jan 2023 18:33:54 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:3f41:4035:c56c:92cc]) by smtp.gmail.com with ESMTPSA id u13-20020a17090a6a8d00b00228f45d589fsm7640582pjj.29.2023.01.30.18.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 18:33:53 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, James Clark , Leo Yan , Stephane Eranian Subject: [PATCH 1/4] perf inject: Use perf_data__read() for auxtrace Date: Mon, 30 Jan 2023 18:33:47 -0800 Message-Id: <20230131023350.1903992-2-namhyung@kernel.org> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog In-Reply-To: <20230131023350.1903992-1-namhyung@kernel.org> References: <20230131023350.1903992-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756503786700566443?= X-GMAIL-MSGID: =?utf-8?q?1756503786700566443?= In copy_bytes(), it reads the data from the (input) fd and writes it to the output file. But it does with the read(2) unconditionally which caused a problem of mixing buffered vs unbuffered I/O together. You can see the problem when using pipes. $ perf record -e intel_pt// -o- true | perf inject -b > /dev/null [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] 0x45c0 [0x30]: failed to process type: 71 It should use perf_data__read() to honor the 'use_stdio' setting. Fixes: 601366678c93 ("perf data: Allow to use stdio functions for pipe mode") Reviewed-by: James Clark Signed-off-by: Namhyung Kim --- tools/perf/builtin-inject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 3f4e4dd5abf3..f8182417b734 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -215,14 +215,14 @@ static int perf_event__repipe_event_update(struct perf_tool *tool, #ifdef HAVE_AUXTRACE_SUPPORT -static int copy_bytes(struct perf_inject *inject, int fd, off_t size) +static int copy_bytes(struct perf_inject *inject, struct perf_data *data, off_t size) { char buf[4096]; ssize_t ssz; int ret; while (size > 0) { - ssz = read(fd, buf, min(size, (off_t)sizeof(buf))); + ssz = perf_data__read(data, buf, min(size, (off_t)sizeof(buf))); if (ssz < 0) return -errno; ret = output_bytes(inject, buf, ssz); @@ -260,7 +260,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_session *session, ret = output_bytes(inject, event, event->header.size); if (ret < 0) return ret; - ret = copy_bytes(inject, perf_data__fd(session->data), + ret = copy_bytes(inject, session->data, event->auxtrace.size); } else { ret = output_bytes(inject, event,