Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3541922imu; Fri, 18 Jan 2019 12:13:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN7IBCOETZybRbuhxmgy5nS8yNf/hO1saSXl/qjL00VeALQ7huaw6iL3iOThKWvWMpit/5nJ X-Received: by 2002:a63:dc54:: with SMTP id f20mr19332285pgj.410.1547842403777; Fri, 18 Jan 2019 12:13:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547842403; cv=none; d=google.com; s=arc-20160816; b=dOyF6bjlntGfLWM3cCWNKBI3YwVmBC6Bwipw+kza8mh9yqT9Sss3DlY51hbrnqHrtE snVVHs7ogApfd4930JPJjv6NXx3mh9Y9EzHhbq7a8KmsrPx/2pQYAzo0Q7EG/hccbAn/ kHx8Vg9m2tas75rHPtPE8QKDoJKYUz2HKTWZc4/E5gf05aqZxys1pLLfSOm6pdtHPxZ8 BQwOlKwppKfZ9sS8cztBSRDBM1MysZb9J3CMRkKBzTRSHIb9dzhmX8GNVERo3ibijmjE o04tNDWY9AHCoatJWglOGNY0b3JelT9LgZzxcqD/Sq6xsucd0SpOJt/pnPh1nJ3G/zrx tJlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=U/QJ4CfI81kB0VE0e1usY7t5S5dPhqUGyBh/r+7td44=; b=ExS3w447SHn60d0eiuSqH2R7p+vBKyDUaH87tvpawy8vk3QTjjK4KyIEFaMmV3duTl Q7BxT7nXgApxFe9hFC3aQOREMxUFqSWnAfGG4SrnqK9ufEBHatmgppDOBUrT9aBD/xyt 6TY2EVLfDEzUDa7f01trDVAAc4vjdezYfui7ugLmGbob+GtO4MnVT4CV+ia/sWsFf3AJ nSLJREKHFc6D+ccEF1cFhojQBlnrwhjhSEXKNdBA4TVMgh2SyHZwgCsVTl+SF7fc2KC+ h49YwvrMLTVpWqv+JvBpVlTnAl9T5WH4JVYthpwN5b3kQk90cZS6147c+ZGIK87yaooF su3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=OzkO8bHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si5415677pgo.474.2019.01.18.12.13.08; Fri, 18 Jan 2019 12:13:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=OzkO8bHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729446AbfARULA (ORCPT + 99 others); Fri, 18 Jan 2019 15:11:00 -0500 Received: from merlin.infradead.org ([205.233.59.134]:37326 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729356AbfARULA (ORCPT ); Fri, 18 Jan 2019 15:11:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=U/QJ4CfI81kB0VE0e1usY7t5S5dPhqUGyBh/r+7td44=; b=OzkO8bHgYeoURMmtm+ykXf/ov qZJGBvb6xV/ExWUP8Xetm4EwoBbz5GGDPf10/FJqkqadqsC6kd46nmwmK7+M5k/XojrGwsODZojip aTmFMZVSU/leOh2NekEFTr90i9yhi2iOim6UHCSWy9mAg9NDIOqUw17K8et/knpftuGutA0bALdu4 Bi4bzJDRuRcdrhtQdhuCZQEpctubNB/qUdK6GSCvnl1BgzCMlIEFslciCac/x4EmI8+a3CfQybbe1 qVxpykR9qc4xjY4FGJh3UE30aNdaBmABycDUG4CgOiF6cUzwp3T4Q1VtqwAJsys3jO8N8/btSmtak K2ozcxXrQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkaTf-0005gu-8P; Fri, 18 Jan 2019 20:10:55 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DABC320289CC4; Fri, 18 Jan 2019 21:10:51 +0100 (CET) Date: Fri, 18 Jan 2019 21:10:51 +0100 From: Peter Zijlstra To: Vince Weaver , '@hirez.programming.kicks-ass.net Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo Subject: Re: perf: rdpmc bug when viewing all procs on remote cpu Message-ID: <20190118201051.GF27931@hirez.programming.kicks-ass.net> References: <20190118120149.GC27931@hirez.programming.kicks-ass.net> <20190118155814.GC14054@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 18, 2019 at 12:24:20PM -0500, Vince Weaver wrote: > On Fri, 18 Jan 2019, Peter Zijlstra wrote: > > > > You can actually use rdpmc when you attach to a CPU, but you have to > > ensure that the userspace component is guaranteed to run on that very > > CPU (sched_setaffinity(2) comes to mind). > > unfortunately the HPC people using PAPI would probably be annoyed if we > started binding their threads to cores out from under them. Quite.. :-) > > The best we could possibly do is put the (target, not current) cpu > > number in the mmap page; but userspace should already know this, for it > > created the event and therefore knows this already. > > one other thing the kernel would do is just disable rdpmc (setting index > to 0) in the case where the original perf_event_open() cpu paramater!=0 > > though that would stop the case where we were on the same CPU from > working. Indeed. > The issue is currently if you're not careful the rdpmc() interface will > sometimes return plausible (but wrong) results for a cross-CPU rdpmc() > call, even if you are properly falling back to read() on ->index being 0. > It's a bit surprising and it looks like it will take a decent amount of > userspace code to work around the issue, which cuts into the low-overhead > nature of rdpmc. > > If the answer is simply this is the way the kernel is going to do it, > that's fine, I just have to add workarounds to PAPI and then get the > perf_even_open() manpage updated to make sure people are aware of the > issue. I'm not sure there really is anything the kernel can do to help here... One thing you could look at is using rseq together with adding a CPU number to the userspace descriptor, and if rseq gives you a matching CPU number use rdpmc, otherwise, or on rseq abort, use read().