Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp584305ybj; Thu, 7 May 2020 02:53:03 -0700 (PDT) X-Google-Smtp-Source: APiQypKY9gtUGvd9Gkd7BfIMIL1NR3b4MKZkk1a/SSSyZ7DMJp8S9LhRXOmUgHKBX0aLEGpE+S8c X-Received: by 2002:a17:906:31d7:: with SMTP id f23mr11559819ejf.59.1588845183705; Thu, 07 May 2020 02:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588845183; cv=none; d=google.com; s=arc-20160816; b=UWMceIGBycLbK3v/ky2t5OCJQeO2AyljH79qUHd6K+jTRrF8gmC8TvlWlLJ1HAQ4Un U0kgaVsd0sAYQKIye2UYw4g62tRBlqCOZg6gXuVNpqUqmo5H1G9Ja1tGnipwzLxHgAp0 ieRO2cu8IL0YgETD0kS/YTxAuCqyMh+AsUETYu8Wtwn23hiIrk+BqIcoilvw4Hvlte1h aYbD5n8AvWaqNLPVZ7eYoebx1D6rVvGcMY5OgzQCgQeXLk6V7MjoomwJopxD7azNtn8N dQxUnjoae0r8lYr2fvve/rs83Z4Xi77pNr2goY7fcSBaLdYtyrNL/BEYxXTfPV6+XmAo WRyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=g9PqgKpOVqvWE+cZc4PZgZ7y3BBYylynULTL/Xe0FFw=; b=uwJMK3Y9c544nOGqC4wDHkJ61AvJkO7qeluHvxw6VgJLihYTYL65k/drHmJGN22uMY 6gLHdYkluak1ZaUEyaL3jMqolMxEcSAIOWxJp4dS85hY4i6cqIv6Sy+AwVFHdhGilqHI So+fFdiBOUdYS0GNSvjd05f9EZjTRviOwYlItaNZ9BVuehp2Z0yAD24Wn2+BvsRS9XjM Q62ZdWh41bI/9cxBDxVy7xyKExYaDyywsOvtFkIfBSugozr394IgfPUjx07GYwlJZd7o rwL7RygzabPy8QkTU5Xn48ZtgdyhDN5HyeN/hH01zBDcCSzIf1qdbTS139yoSY88gGnF 6psw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p9si124268edt.570.2020.05.07.02.52.40; Thu, 07 May 2020 02:53:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726638AbgEGJun convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 May 2020 05:50:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25072 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726598AbgEGJum (ORCPT ); Thu, 7 May 2020 05:50:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-446-_3RZuUPaMVeWDcTaM-wNzw-1; Thu, 07 May 2020 05:50:34 -0400 X-MC-Unique: _3RZuUPaMVeWDcTaM-wNzw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C9DB80183C; Thu, 7 May 2020 09:50:33 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8079010013BD; Thu, 7 May 2020 09:50:30 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Paul Khuong Subject: [PATCH 2/5] perf tools: Do not seek in pipe fd during tracing data processing Date: Thu, 7 May 2020 11:50:21 +0200 Message-Id: <20200507095024.2789147-3-jolsa@kernel.org> In-Reply-To: <20200507095024.2789147-1-jolsa@kernel.org> References: <20200507095024.2789147-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's no need to set 'fd' position in pipe mode, the file descriptor is already in proper place. Moreover the lseek will fail on pipe descriptor and that's why it's been working properly. I was tempted to remove the lseek calls completely, because it seems that tracing data event was always synthesized only in pipe mode, so there's no need for 'file' mode handling. But I guess there was a reason behind this and there might (however unlikely) be a perf.data that we could break processing for. Signed-off-by: Jiri Olsa --- tools/perf/util/header.c | 18 ++++++++++++++---- tools/perf/util/session.c | 9 +++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 0ce47283a8a1..13a1fe4ac0c0 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3947,12 +3947,22 @@ int perf_event__process_tracing_data(struct perf_session *session, { ssize_t size_read, padding, size = event->tracing_data.size; int fd = perf_data__fd(session->data); - off_t offset = lseek(fd, 0, SEEK_CUR); char buf[BUFSIZ]; - /* setup for reading amidst mmap */ - lseek(fd, offset + sizeof(struct perf_record_header_tracing_data), - SEEK_SET); + /* + * The pipe fd is already in proper place and in any case + * we can't move it, and we'd screw the case where we read + * 'pipe' data from regular file. The trace_report reads + * data from 'fd' so we need to set it directly behind the + * event, where the tracing data starts. + */ + if (!perf_data__is_pipe(session->data)) { + off_t offset = lseek(fd, 0, SEEK_CUR); + + /* setup for reading amidst mmap */ + lseek(fd, offset + sizeof(struct perf_record_header_tracing_data), + SEEK_SET); + } size_read = trace_report(fd, &session->tevent, session->repipe); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c11d89e0ee55..b860f9f1b09e 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1542,8 +1542,13 @@ static s64 perf_session__process_user_event(struct perf_session *session, */ return 0; case PERF_RECORD_HEADER_TRACING_DATA: - /* setup for reading amidst mmap */ - lseek(fd, file_offset, SEEK_SET); + /* + * Setup for reading amidst mmap, but only when we + * are in 'file' mode. The 'pipe' fd is in proper + * place already. + */ + if (!perf_data__is_pipe(session->data)) + lseek(fd, file_offset, SEEK_SET); return tool->tracing_data(session, event); case PERF_RECORD_HEADER_BUILD_ID: return tool->build_id(session, event); -- 2.25.4