Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp934645pxb; Wed, 29 Sep 2021 12:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtKJVWqGFg1+HjFj1UhgQdqBgfVfSY+/UiuQL24x+/T0s4KJoC5UPuQS3OtdFCPGD4BZMK X-Received: by 2002:a05:6402:1598:: with SMTP id c24mr2095146edv.253.1632945285143; Wed, 29 Sep 2021 12:54:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1632945285; cv=pass; d=google.com; s=arc-20160816; b=TQaEcJicVnH3nMEbKedXTjYT3iiwA/n8IvIhmBJ0/xYb24BlKTwLgJ1rZGvsLenFBg mZY24L79BVbQGW2i+ROlf1+ixPBp+neXspFo1JfroxA+qTa2OCTJStsBrFq2Y2uOApyd pXL9+9GOceuI2aYJ7B+GtSPCsHamSNthyrOAm0bROU3kS5VPiK1UER3T8cUCMfoHewW5 VZ4ktXqkx1w7uTt+e/m2KHMStDS4NDtwUWeDVzSwCaQfY7SA+UZGrqFeEKAs5H+4SymC iwy6fEdf8geKC1v1G8KGAJlLCaLT1IJRxs/ROIWSCH/4PwAFiTx7EgqC5igF4zJPL3Hm MJ5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-id:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=kRho7jvlBA3v3mfuo2/5Zv3vqQCIR1aesPbevXnMkXA=; b=rKVoOFmfyI3wn4fCKXgUqA2M31TQe1xlOZMwuY/9AyzIUxrezszc4z8tCl3HSJl/Gh I1w4wzEjNTzYIKLL4eOf9j6Zebl4kYHrPU+xxjqt2P9DZZ74zvfCPoEa2D2325FL3+y8 Jst/7Uoh5upDeB6Lg8HFKWUruw3HUeOAvIe55Xr2BKdcrU6TgpqaR5ML2Y7tQXC3k+s8 brSa3f7h9yPByxwQvHKwOw3dcZVURLjIBWB+dj36xXPBexpIpfzPrXENFX7EUKVmNTJ+ DtVc0ZdnghyX1vrWIbRtyGV/ORhf+09L1JTcdji9a2tlCt3tiWGiMpV/Fz55//BIA1I7 j+8g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=hGFcOJMV; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.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=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si1140710ejy.260.2021.09.29.12.54.19; Wed, 29 Sep 2021 12:54:45 -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=@fb.com header.s=facebook header.b=hGFcOJMV; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.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=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245067AbhI2Tj6 (ORCPT + 99 others); Wed, 29 Sep 2021 15:39:58 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:46978 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbhI2Tj5 (ORCPT ); Wed, 29 Sep 2021 15:39:57 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18TDFdjA015804 for ; Wed, 29 Sep 2021 12:38:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : mime-version; s=facebook; bh=kRho7jvlBA3v3mfuo2/5Zv3vqQCIR1aesPbevXnMkXA=; b=hGFcOJMVOpTm8dGwLElR437/Pi986JbzRALPN4MwFR59FspxMTZVbz2OYO3hKKTqxbOf rnkB9Anb7pA0GImwzuwtAoiPctplawtVNF4IvNA+u+PZ23sIwsuR5pQUzAeanTxzLi28 hhgGzFdPYbVSCIwfkNbY8NuPDUjllfY5+rE= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 3bcrv634eu-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 29 Sep 2021 12:38:15 -0700 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (100.104.98.9) by o365-in.thefacebook.com (100.104.94.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Wed, 29 Sep 2021 12:38:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K9RG/2djZfqMzzCmJv749jHwwaq15kFX8EUvPfyaADfOURek8FUS+20w1cajbthkGP7B/VqWvmOXn6PATPzf5qr6eSg8Ukyp2+7J+dxADgPBryxczDOhUppn6vq0AJwjnKJHIls05OGJ5yQMpJrXuMh3WDX2RBtIAeUcyo578j0NY3gAylimGsmyUQQla3gWDw4rKh4L9tPSFfmh3fUtJ22Bp2vQO6IJXKTbqDs8X8uy3QZhpRHVpUVs6+FHIS/rZElCO0fRRjqhLM3/F3s1dlTt33vxk3DmiHozC9hkchFSFaX6VOvR0gnmBjW1irE9urxisUkmCVTIyiVKCkkbjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kRho7jvlBA3v3mfuo2/5Zv3vqQCIR1aesPbevXnMkXA=; b=D2FUZWkF7OtfVyeyelGkhBlQySh6sFCExyXC3b3h2AtVcHqwWHEjZPFGRoekJSfg6Vh2IhM/TOVLQ4Bd9lfyT/oHNQ8Uegiuv1OH4+iAOHhS9MvOrrzSOj70hE5fQqwSrnQiv26mQgJfqYrH3gMHDhSZP4D+QMkoAcivK9P0M6aD97oQESrGF72+gy9yhGIcLsmPiOJZjACnRsBKsyKlQ858KnGjMKnjUHTiWss0uCstCoJ/uS1Pvyz6sRokmzBa+/ZAONnpYR0sIoYnRXZG++ci9RKoSWyPipnKgVw+ZrNYiW5PqFYFq6iC/ikUwlXO6xQfXE9EIJ0Gl4g6AieGmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SA1PR15MB5109.namprd15.prod.outlook.com (2603:10b6:806:1dc::10) by SA1PR15MB5078.namprd15.prod.outlook.com (2603:10b6:806:1dd::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Wed, 29 Sep 2021 19:38:12 +0000 Received: from SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::7d66:9b36:b482:af0f]) by SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::7d66:9b36:b482:af0f%8]) with mapi id 15.20.4566.015; Wed, 29 Sep 2021 19:38:12 +0000 From: Song Liu To: Peter Zijlstra CC: linux-kernel , Arnaldo Carvalho de Melo , Ingo Molnar , Kernel Team , Stephane Eranian , Lucian Grijincu Subject: Re: [PATCH v2] perf/core: fix userpage->time_enabled of inactive events Thread-Topic: [PATCH v2] perf/core: fix userpage->time_enabled of inactive events Thread-Index: AQHXsON8cxUzcBLit0S7boefzLsslKu6xCKAgACtKYA= Date: Wed, 29 Sep 2021 19:38:12 +0000 Message-ID: <59D2F040-D16F-4ECE-9977-C5187127FB84@fb.com> References: <20210924012800.2461781-1-songliubraving@fb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3654.120.0.1.13) authentication-results: infradead.org; dkim=none (message not signed) header.d=none;infradead.org; dmarc=none action=none header.from=fb.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 310be829-f9f0-4a12-3c5a-08d98380acc8 x-ms-traffictypediagnostic: SA1PR15MB5078: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: E/fWdkA/jAvuMLlFzpPY673F9HYFMFl1+3s71M7mqtx4GW7WhbOoEfu/EQigpP0LPgH9M1kON/lFe3HkiMSb9lk7DTJitsMxq2uMjQ+2oMLSfDTxba5KNj70HTm/DwpqK+T9rPnFLStDeLVepf4ehoEmg15jHCCYVML3N6zUXMItRm8MSBlOFriPvMQwQcS+mtrTwU4enD0M7PNGuBWCEr6+twcRBs9tIzWe8GGgwvXXTmGowiFgTxPiipE/HWoWGHv0YFuGE/f/D7oSZMa3s1YTP9Zh3DMaS8Ma3sqaM1w/5QxonT4lntgNkBgQiOduzIUE8Tv6TxLDmOvQS6h2KOB3lbpm2YG6Jz9BlrOQRVPDMlIXkrjO2g/oJMiK7KB9r+e1JcXDP7oe06p8Us0mqI3IXvCuoO78iqy1VULlFFlT8YpmddwNlkDT9A6btWWbz+mOEYKwZkeKEnBqXvikBhg6rlPpqcj0ErrWLEs/r5hQhO86SNg8/zfK3kipx5ZTKM13+7nly2d/wznFuRAPIkckkx2inWCi0lejy3MYyjz1hFnPxD5RXhPXHfPaR1QSWMvWQXN32zPSj3j34eCNCbr0QO9AC3Vyv3gXmZAT6NdE2l/v/HWBWaLe/QrJVVRt42SImOY0JkKIe54BeR5yTCRIplXYdah/lm3c2ktD5bHlb7NFEdnTT85P9Ue+tFAmssU98EpHxr/i1eQWXaQqhRjRBCH6eIvVXRYnK9FHhcVr7xicg3NrEAGBLnAkl1CB x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR15MB5109.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(66446008)(6486002)(54906003)(6506007)(122000001)(83380400001)(8936002)(8676002)(64756008)(2616005)(38100700002)(71200400001)(66946007)(316002)(53546011)(66476007)(66556008)(76116006)(91956017)(6916009)(186003)(6512007)(86362001)(2906002)(508600001)(33656002)(38070700005)(5660300002)(36756003)(4326008)(45980500001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?oU04qz3mIhnbmnozH4EE5rCbu238dGO6wcrtdGmShquVUXvU38Yw5YPAbMI6?= =?us-ascii?Q?UX0WNchMdC+Hwt6uQBRwpYi5LyOaXJMrrUedIhMnWp0eY0z1ODXmCH/cC3Pc?= =?us-ascii?Q?0y+WVXMRUDjnP9brSHFElIFdO1lLIQZvhr8TLaDOgmuWVDyMUHG1I4GyaW7l?= =?us-ascii?Q?lmIwZd3e8lXfLo4hKeHf4qukSYjF+YBJ8zRIghAcWiWtw+f0betfLfxGEweQ?= =?us-ascii?Q?VNQdYs9qa55SKC7RdiEnC9bU+rryPw485xb7z0TdzVsTHLOstkAJfSJjDoVk?= =?us-ascii?Q?B/M/JX0d9RdB+f8DI+I2aKD3+3fxEiFnn4WKHbcSJ1cppQKsFOCChJq9Gcij?= =?us-ascii?Q?EnN8QmqOwoCIFdCpBJ7rPXf8iDxPpXomImNc1UVSi6OaKB3xiNFJmJ9QZ6PA?= =?us-ascii?Q?eju+CtZmgUp2rZ0ukRqXu9WqaaxUjKcxQ81TGur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Nq06MqHsMIi+nrNNtyMWfS8ETZBu1b40VR3tLfcKda+1FI5MLGQ?= =?us-ascii?Q?mE5jco8=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <639094499385C646B9549B1EC9278B43@namprd15.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR15MB5109.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 310be829-f9f0-4a12-3c5a-08d98380acc8 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Sep 2021 19:38:12.6068 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: RVBbP3hclVe+audoAn6s1+xUbr749KPp4Vqha5aFcT9bvX6bj5qYDtMzkTOEN6Z9DtAk9FpKWiTvLqcjdRZcow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR15MB5078 X-OriginatorOrg: fb.com X-Proofpoint-GUID: nAxkosqRgAwo8db4OKP4yDz-wcKSIvdi X-Proofpoint-ORIG-GUID: nAxkosqRgAwo8db4OKP4yDz-wcKSIvdi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-29_08,2021-09-29_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2109290114 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Sep 29, 2021, at 2:18 AM, Peter Zijlstra wrote: > > On Thu, Sep 23, 2021 at 06:28:00PM -0700, Song Liu wrote: > >> diff --git a/kernel/events/core.c b/kernel/events/core.c >> index 1cb1f9b8392e2..d73f986eef7b3 100644 >> --- a/kernel/events/core.c >> +++ b/kernel/events/core.c >> @@ -3707,6 +3707,46 @@ static noinline int visit_groups_merge(struct perf_cpu_context *cpuctx, >> return 0; >> } >> >> +static inline bool event_update_userpage(struct perf_event *event) >> +{ >> + /* >> + * Checking mmap_count to avoid unnecessary work. This does leave a >> + * corner case: if the event is enabled before mmap(), the first >> + * time the event gets scheduled is via: >> + * >> + * __perf_event_enable (or __perf_install_in_context) >> + * -> ctx_resched >> + * -> perf_event_sched_in >> + * -> ctx_sched_in >> + * >> + * with mmap_count of 0, so we will skip here. As a result, >> + * userpage->offset is not accurate after mmap and before the >> + * first rotation. >> + * >> + * To avoid the discrepancy of this window, the user space should >> + * mmap the event before enabling it. >> + */ > > It seems to me that writing that comment was more work than actually > fixing perf_mmap() to DTRT, no? AFAICT all we need is something like: > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index fd2ae70fa6c4..1e33c2e6b0dc 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -6324,6 +6324,8 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) > > ring_buffer_attach(event, rb); > > + perf_event_update_time(event); > + perf_set_shadow_time(event, event->ctx); > perf_event_init_userpage(event); > perf_event_update_userpage(event); > } else { Yeah, this does work. I will fold this in v3. Thanks, Song