Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1023847imm; Wed, 17 Oct 2018 12:01:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV60VLbagK7d2QMvxUvbFIWzmweop80dscRPv5EP6L+HPsM292533vscfz9kxiLWiS5vWwfG6 X-Received: by 2002:a65:5b07:: with SMTP id y7-v6mr25649147pgq.125.1539802918111; Wed, 17 Oct 2018 12:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539802918; cv=none; d=google.com; s=arc-20160816; b=gZ6zzpNGYaZvqgs+V07OjX2UIp66Gl12WIuCmr81MVRV8k9tNc62EtiMD9kXZ8eQfT krVAgUZ6z39HjlCIcdqyhlIK11T11DcyRBMMC4fPObsI4jfM5DihMs5PHtKnKEg2aGqy jGNGuiHxSS9HPR3RXQUqpROMvqN8FDrlKfPMjeHzoboIyvt4s5c+xMt9qwf+5kPZfR49 sOyNSSkOtCQlOkwReZm439Zn6/HZL64qhhMpKftUd9qOIVg5g+y/STamsgy5fxQC1y2w LJRKVbaZQlHwsM+XU9nJXExvqQn0EjejiDLgUGfC52KQ1e10tH2VCF+pHBGu3Kdxjm35 Iqig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature; bh=HXhRIXiQzjyF/7lvK56Fv8lMPfW0tQHjKedBOgO2iJA=; b=D5HjEs4MqWx1Smop63bb+UheoACWF1br0HlVe+KHxcau0dLQT3JdVPlxf5FQ4CAG/D u/LzTchryE5lIj6qoqp4FF38EFKJr/RavyLFj/tVBgIYEr1BlpmxdXRfFMCFGcPgDvXP Sa6DxbE9Cy+Q6XtJHQE88E6VL2wbs32/B/8ZKWEZ+PWySRmDkLuODsw3uHWm7Zoq5YG8 GmH88h3gn06oaG0QSqKjskujCQNvLwCCniuCZKRvI1PTtExI0EFP8sz2kV5Lnkg+M1De HCE7JYGQr9oC9XEPJpUq0cyKHypPRbIpl9YaZPN9t9/e7luDhIa3pxQEFqmr0c2gEnJO +qTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=ZqjgepPs; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b="Xgzi/kYZ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17-v6si3163675pgo.294.2018.10.17.12.01.41; Wed, 17 Oct 2018 12:01:58 -0700 (PDT) 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=pass header.i=@fb.com header.s=facebook header.b=ZqjgepPs; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b="Xgzi/kYZ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbeJRCzB (ORCPT + 99 others); Wed, 17 Oct 2018 22:55:01 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:54360 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbeJRCzB (ORCPT ); Wed, 17 Oct 2018 22:55:01 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9HIoor1006374; Wed, 17 Oct 2018 11:57:29 -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 : content-transfer-encoding : mime-version; s=facebook; bh=HXhRIXiQzjyF/7lvK56Fv8lMPfW0tQHjKedBOgO2iJA=; b=ZqjgepPsqTjMcyCBX0LA9mdSY+Cpc4YYSDlbibUSq+S9T/dTM5+GvVKlKk4+VDKIgWkS eAXrY1xfPsTRTUjCQPOVZtyCjnZIdPwQoRrVtJEaY1JDOgNtgvEX/FjcmYmRsLZb0Iw+ 8zfCltUibMdVxTf2LWAhT7+F9Jmp7QY/O4g= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2n67yfgr0b-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 17 Oct 2018 11:57:29 -0700 Received: from frc-hub02.TheFacebook.com (2620:10d:c021:18::172) by frc-hub02.TheFacebook.com (2620:10d:c021:18::172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3; Wed, 17 Oct 2018 11:57:27 -0700 Received: from FRC-CHUB05.TheFacebook.com (2620:10d:c021:18::24) by frc-hub02.TheFacebook.com (2620:10d:c021:18::172) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1531.3 via Frontend Transport; Wed, 17 Oct 2018 11:57:27 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.25) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 17 Oct 2018 14:57:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HXhRIXiQzjyF/7lvK56Fv8lMPfW0tQHjKedBOgO2iJA=; b=Xgzi/kYZIKwfkcz76xz+Y68+1hNYfrSJuuMSC6m797sJjdf5Dq/JMLq2v5FXJGIDJIivsdD4A05pXRuJp7YiDQJiCmAnwFW4YiOM/9kAaysQZNqNLlAG6GxHw9FfCGHBXMOzk48yxdmXw+AcJC0J1Jj0d+IRIi2WW/0DVfhibpk= Received: from MWHPR15MB1165.namprd15.prod.outlook.com (10.175.2.19) by MWHPR15MB1198.namprd15.prod.outlook.com (10.175.2.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.25; Wed, 17 Oct 2018 18:57:25 +0000 Received: from MWHPR15MB1165.namprd15.prod.outlook.com ([fe80::f809:2e0d:6e1c:924a]) by MWHPR15MB1165.namprd15.prod.outlook.com ([fe80::f809:2e0d:6e1c:924a%8]) with mapi id 15.20.1228.027; Wed, 17 Oct 2018 18:57:25 +0000 From: Song Liu To: Peter Zijlstra CC: Alexey Budankov , Ingo Molnar , lkml , "acme@kernel.org" , Alexander Shishkin , Jiri Olsa , Stephane Eranian , "Thomas Gleixner" , "mark.rutland@arm.com" , "megha.dey@intel.com" , "frederic@kernel.org" Subject: Re: [RFC][PATCH] perf: Rewrite core context handling Thread-Topic: [RFC][PATCH] perf: Rewrite core context handling Thread-Index: AQHUYIaFJ/VvvMmSxkC06uIJGGK3pKUf754AgAATMgCAAOOBAIABVJuAgAEXCYCAAF4KAIAACjKAgAAUdwCAAAbFAA== Date: Wed, 17 Oct 2018 18:57:25 +0000 Message-ID: <26D16201-2CEE-4D4A-B2FD-8F472B48A273@fb.com> References: <20181010104559.GO5728@hirez.programming.kicks-ass.net> <3a738a08-2295-a4e9-dce7-a3e2b2ad794e@linux.intel.com> <20181015083448.GN9867@hirez.programming.kicks-ass.net> <20181017110651.GI3121@hirez.programming.kicks-ass.net> <82000D4A-0A1B-4A8B-904C-24640215D2BD@fb.com> <20181017171955.GQ3121@hirez.programming.kicks-ass.net> <20181017183310.GB2603@hirez.programming.kicks-ass.net> In-Reply-To: <20181017183310.GB2603@hirez.programming.kicks-ass.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3445.9.1) x-originating-ip: [2620:10d:c090:200::5:7715] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR15MB1198;20:klJCxZ9GIxSrgCtOIAn+qTQP86u1YY2k8V570VAOxezYMKfagEbuAGu2RvS5cIM1iI9epQXptYSV2XpyA/0xfVSVV6CLF38vw9QubJbysyc760vwqWCuBUHwevfjp9WeROy7+xMxAOz3nrZw/pi1Eco6om56tiC6+jG4iY0dJr0= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 8c639f59-03ff-4e3d-cf3d-08d6346260cc x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1198; x-ms-traffictypediagnostic: MWHPR15MB1198: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(209352067349851); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231355)(11241501184)(944501410)(52105095)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051)(76991095);SRVR:MWHPR15MB1198;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1198; x-forefront-prvs: 08286A0BE2 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(346002)(376002)(366004)(136003)(39860400002)(199004)(189003)(6916009)(46003)(82746002)(2900100001)(186003)(50226002)(6346003)(36756003)(76176011)(446003)(11346002)(33656002)(476003)(7416002)(81156014)(2616005)(102836004)(5660300001)(81166006)(8676002)(6506007)(53546011)(486006)(6116002)(6486002)(8936002)(229853002)(99286004)(6436002)(305945005)(105586002)(106356001)(7736002)(54906003)(53936002)(57306001)(83716004)(71200400001)(68736007)(71190400001)(6512007)(14454004)(316002)(93886005)(256004)(478600001)(97736004)(6246003)(86362001)(2906002)(5250100002)(25786009)(14444005)(5024004)(4326008);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1198;H:MWHPR15MB1165.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HTFBms2xSBZx5hK3EakzApnF+tgcOMVlwLdaL3aXyJKA9Ff74UNJIjkrmsVFdfjAy0ZMtirEWBt4qRF9UxgCuN2I9QZaG4emHr3Pw+6u4Eq9tcxZT5PWGMnXp5yjynAvDR6D4PedAekbYXMAh764WtEqFWVOAaEAtqf1P0XBmhCRpbmvd4o0W3LZtb2ldbW0vI5ChOPkkU4mh/xl/ObEBKs5q260AsxKwphyTd8JoxznKbQdhwG2bSw32IsC64PO8dHZq3I8cKShf9nbD7Z1kfwO4sppKnCVZVLRkeIG6C5dmzDg/e7QU1rkxSwaaH2diswjszDdXtY/EB7+nbLtOW/mA28FCSRp4BUD07Vk59g= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 8c639f59-03ff-4e3d-cf3d-08d6346260cc X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Oct 2018 18:57:25.2316 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1198 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-16_14:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Oct 17, 2018, at 11:33 AM, Peter Zijlstra wrote= : >=20 > On Wed, Oct 17, 2018 at 07:19:55PM +0200, Peter Zijlstra wrote: >> On Wed, Oct 17, 2018 at 04:43:27PM +0000, Song Liu wrote: >>=20 >>>> That makes task and cpu contexts wildly different, which will complica= te >>>> matters I feel. >>>>=20 >>>=20 >>> I think we only need different logic when adding events to the task/cpu= =20 >>> contexts. The ctx_sched_in() and ctx_sched_out() will need some extra >>> logic to filter out events that are not being scheduled (don't schedule >>> events on PMU-a when rotating PMU-b). This logic will be the same for=20 >>> task and cpu context. The difference is, the CPU context will not have >>> such events, because we never added such event to CPU context.=20 >>>=20 >>> Does this make sense? I could try draft a RFC to see how difficult it i= s.=20 >>=20 >> I'm not sure it saves much, if we have multiple per-cpu contexts we get >> to re-introduce the active_ctx_list and loose the simplification for the >> online status. >>=20 >> Plus that fundamental assymetry -- which would bother my OCD forever >> more :-) >=20 > Worse, the whole syscall that installs the events will come apart. The > locking for the two cases is different :/ I agree... I didn't get into details of locking. I just consider these all as part of "adding event to context".=20 I believe this patch should give close to the optimal performance. However,= =20 I do feel it makes the logic more complicate. Before this patch, perf_cpu_c= ontext and perf_event_context don't need to know much about multiple PMUs. With this patch, the two extra *_pmu_context are necessary for performance (and maybe also for correctness).=20 If we take first a baby step, how about adding more perf_event_ctx to=20 task_struct->perf_event_ctxp? We need one sw perf_event_ctx and a few hw=20 perf_event_ctx (one for each hw PMU). (I haven't checked whether it is OK to allocate these when attaching events). (And I guess you don't really=20 like this..) On the other hand, this patch makes it possible to create groups of events from different hw PMUs. I guess that will be useful.=20 Thanks, Song=