Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3594746pxb; Fri, 5 Nov 2021 19:12:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLwKBNJ0kLdYB52KxgESyId72zQXv3e3IjGxn8MaeqngacowZcEd80hUAaujIWPc9ETBjd X-Received: by 2002:a5d:83c7:: with SMTP id u7mr2224760ior.80.1636164731151; Fri, 05 Nov 2021 19:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636164731; cv=none; d=google.com; s=arc-20160816; b=cbunUkDSHnk15ohkoBdvCW9tDA681BNsDQi4ObJMHFZ8Ofb69VvVof8Jay7qTGHBlG 6KIb+cg8TWwJ0bJhLRd3ozHjn+CFygbfQ1GNWpE65hUQrKfmm4Mdj1JbOjlCryjQ/zrt rMkWJhsNfUppFjy8s1G18QhMDgjxBL72FGPKResIp2IOsBwCAsVIkpSNYRBR6YqonUYX ajHCfFTFh69e9Wgwhv440pekBPn1flbGQRb1c8t/rdFDX9cJS/ELpJ2fPIifoBLagmz6 uDi2JqU7racjBnRJc8jyI43kDFzlKy6Ym2XedUt3zLSJbxrMKk5VZDEyeW7lic8c7Nhq lVmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8X0DdUNCAoyfQsZpIBtLXCHewJf/Ra0c7ujN9TKLlFw=; b=p6PGOQRpH9k11929I/7Qjuu9olNcmyeIy9ndqr2lkw+FrPXGFKZcKTK6LXAvgAbEf+ GPAQu7/mMk2G+4a8O0sjQEyCdffiVJpT0hEVeajatU03uLGd+jmmlN+Lwl5YOYmjkxrv 8LzsOTYV+BH/p/uIehTJGfYuCtr8/Poi/5q+bPUSICSMBd/fe7vkfpV+PGsQRxZwhbsA Lt+RW+e+XJ2jFI9cK/cj2yruMq7j2MWWZ94lz6Y1qbqBccg+496ESzL/diMHPEQAprOv zPke/agmCieVm0+gHwwDSYEL51MtD4RJxv+h1zrLVDIHIvDnjAgB/fR+hkzRGdkh2GKE L5dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k9WLnGRb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si12944913jac.29.2021.11.05.19.11.57; Fri, 05 Nov 2021 19:12:11 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k9WLnGRb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233310AbhKFBBZ (ORCPT + 99 others); Fri, 5 Nov 2021 21:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbhKFBBY (ORCPT ); Fri, 5 Nov 2021 21:01:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D905BC061570; Fri, 5 Nov 2021 17:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=8X0DdUNCAoyfQsZpIBtLXCHewJf/Ra0c7ujN9TKLlFw=; b=k9WLnGRbv/Pg5N/X5M+LkmDbgi AiB3Hg1m6ePDcjdTzkeKjhtqZYhz8/QGqZwxEd859Y63kFbArHTqCpoP+xcLq6F4VFRTxOoD+uDTL ZcZ9QUIbEEQWI0yfG1+JCR16BHbqYRARh7ZJjOBkBbXlDcg86ClCuJYBwp+cuVbQc2NOHMByDHcbt qoFEHf3g4YGRNhrU3fiW3QibCDB8Ynk/NFocnrAxb/Mo/fW0Krysh34Y0mv3/2e3ZEifVUvYe/KPm 9F2xunnqJGdibw2JPnHa02550Gd/A95YqP9fAV+ovAiG+HRCToEL3p4qjg0YST9hgcSqBhLrUYpDY Yk0tnskA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjA1L-006xtr-MN; Sat, 06 Nov 2021 00:57:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5519230031A; Sat, 6 Nov 2021 01:57:23 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3BF1A201C7B51; Sat, 6 Nov 2021 01:57:23 +0100 (CET) Date: Sat, 6 Nov 2021 01:57:23 +0100 From: Peter Zijlstra To: Nadav Amit Cc: kan.liang@linux.intel.com, LKML , linux-perf-users@vger.kernel.org Subject: Re: Using perf_event_open() to sample multiple events of a process Message-ID: References: <92645262-D319-4068-9C44-2409EF44888E@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 06, 2021 at 01:45:57AM +0100, Peter Zijlstra wrote: > On Thu, Nov 04, 2021 at 10:57:50PM -0700, Nadav Amit wrote: > > Hello Ken, Peter, > > > > I would appreciate some help regarding the use of perf_event_open() > > to have multiple samples getting into the same mmap’d memory when they > > are both attached to the same process. > > > > I am doing so (using both PERF_FLAG_FD_NO_GROUP and PERF_FLAG_FD_OUTPUT), > > but it results in -EINVAL. Debugging the code shows that > > perf_event_set_output() fails due to the following check: > > > > /* > > * If its not a per-cpu rb, it must be the same task. > > */ > > if (output_event->cpu == -1 && output_event->ctx != event->ctx) > > goto out; > > > > However, it appears that at this point, event->ctx is not initialized > > (it is null) so the test fails and the whole perf_event_open() syscall > > fails. > > > > Am I missing something? If not, I am unsure, unfortunately, what the > > proper way to fix it is… > > > > I include a small test that fails on my system. The second > > perf_event_open fails due to the check in perf_event_set_output(): > > > > Works when you use the SET_OUTPUT ioctl()... > > I think something went sideways in the syscall path and things went out > of order :/ I'll try and have a look. The problem seems to be that we call perf_event_set_output() before we set event->ctx, which is a bit of a problem. Now, afaict it's been broken since c3f00c70276d ("perf: Separate find_get_context() from event initialization"), which is ages ago :/ It's waaay too late to try and fix it; I'll be likely to make an even bigger mess if I tried. Perhaps tomorrow. Clearly FD_OUTPUT isn't much used :-(