From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80191D6ED3B for ; Thu, 21 Nov 2024 13:47:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE6D16B0089; Thu, 21 Nov 2024 08:47:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6EF06B008A; Thu, 21 Nov 2024 08:47:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE80E6B008C; Thu, 21 Nov 2024 08:47:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9D6EE6B0089 for ; Thu, 21 Nov 2024 08:47:58 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 509DDC11C0 for ; Thu, 21 Nov 2024 13:47:58 +0000 (UTC) X-FDA: 82810228998.23.46B32CC Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf02.hostedemail.com (Postfix) with ESMTP id 4285380004 for ; Thu, 21 Nov 2024 13:46:16 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732196740; a=rsa-sha256; cv=none; b=v+ysFlfcqxoWydu0VS/DUiS4RkgcDjITWNqZL7P7JRkGyrOsC8SItXcKlncUTKulfy0Ech ujHO6mT49oxnyd2qWTJR/5lum2t0NJihpWICOOu/HbDw9jpyXDXCLmf6gfHpId6mniaUd0 7mQumAs8fOkWssI0C8Uc458QGCjeK34= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732196740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HXztOsIw50EaNhbvzCeOoRzv24pwMij403UH/KqAc8U=; b=qv9+z7XMjae+aHNyS2dNtH40dY0R/oLHKsE8mMk+r3Z55MDQjUJLUEV+BQOnzPIKQuXcrY tppt7+Q98tOrDIUrB/Q+z5jI5r93xZg+qdxqKP1Br3bA9A4+aukeaHuPL6cIct9i3lxMCa soEZsHGwsvVW4htBjPR3AVPp2c9sD0g= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XvKKs6FsHz6K7JS; Thu, 21 Nov 2024 21:47:29 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E52A1140133; Thu, 21 Nov 2024 21:47:53 +0800 (CST) Received: from localhost (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 21 Nov 2024 14:47:52 +0100 Date: Thu, 21 Nov 2024 13:47:51 +0000 From: Jonathan Cameron To: , , , CC: , , Yicong Yang , Niyas Sait , , Vandana Salve , Davidlohr Bueso , Dave Jiang , Alison Schofield , Ira Weiny , Dan Williams , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , "Arnaldo Carvalho de Melo" , Mark Rutland , Gregory Price , Huang Ying Subject: Re: [RFC PATCH 0/4] CXL Hotness Monitoring Unit perf driver Message-ID: <20241121134751.00006e26@huawei.com> In-Reply-To: <20241121101845.1815660-1-Jonathan.Cameron@huawei.com> References: <20241121101845.1815660-1-Jonathan.Cameron@huawei.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100011.china.huawei.com (7.191.174.247) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspamd-Queue-Id: 4285380004 X-Stat-Signature: sx5rhbn6jqdj77munmyaedn3gybi4b84 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732196776-773838 X-HE-Meta: U2FsdGVkX1/P3eRxmyvG3dh6mZvIcLlkS1wVw1g7mAGjI4cCsVYLuPtm/3EDAgycUkBx6R8J3JayNkULXVedNYxCinxKVfvIHY1OJr+s2y3pACKSQAXkOuOPTwNgVIfM134C/ESxYUvHJstDU/tLKSjcgHfGGp5kOMSnIxJOMfSHaWA4Gyvj2S0YmHXcLlH1W0hakA7QwLRgMlfLqi+jXreZ8KEhKaVX8OYwLzM/dpDZpvZOw1TPivJv5G6qrGCmyli9UhQR53mkQEGc4nXerhMOQ24YSq8pIn5KcPdkSMbEr+veNH1F+B2lpI1WWGXj8de9byc1EBmyRO3DlHp+d1lQ5ooftsQPE16Wkj+Rkp9JVtIl2RsMKDDi1IkkV+QDAzuIadLvpCslJ9gHCl1Ugu+YyJA4YRMVgjUUFktnqy/dpTv/RSeEVXDs05FHbmXgQmVorWyIMl92PjvvNxOVGKal9V5n/MwcLQTNDxcWYttdvZiGnt4KfBfYlU4+onUvRxgLEwmXjo3JEUiPB17KlqZALqbsWfq05R/jtVCpsbtz8/rlZ+hLcYT7ODJobQ/+vZLUzJJjsfaXE0e1IJyFXI1UXR0jZPeJqQYHUFon6DSzDWda2mwRM76YhuvZP+HZCTXYbh/gUYVhbhw+uw5rhbYYPCThD6FtSQX1asv30+9zCiuUc9u9y1VF8AYf5lFcNYeYA4gv3idoVAd+n0tEqqwQ+2yD/yicxOU09mecrK+UDaOQj4bGYDCI1aOg57oSbU5UA6yck5GrMh5TozFhxrsxn4hc2oEfjifozZ7c5nojXUTDn33GrfdD+6iOcMS+h5Cp4yYPCBc04QLcnh4RBFGaN8ihYhGN0a0m98CL4sdr3kl+XYMLNRPIocWi4C/A+YJ9ZBPewsfxNPkFinYuejmyjLmj1zs5DMeiW4fTLn+81olzn+BuC3x5MosOBd9oBk9VvI2Dmq7cBaOfzUj IJ6QraXS lTkfK572fUKCurjZZYYuJ0ylyxl+IaSchYO3gjdPrwztIu26yAnn/gCX06ogXYWxTpVoc5LddyukqAYv6Qa1sfgX1SfN9SfXNFJz5QbGEUl85bKFWHcXlK81F9mB7IX3ZgBGEbOoRms5FhitRA9UlUUxTLNZ4dAd/DA+5xX77fSLiF9ay+BJR6lzh3Bci1KHBBYn0YrgXvtB9UxABNlVxG5rIEw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, 21 Nov 2024 10:18:41 +0000 Jonathan Cameron wrote: > The CXL specification release 3.2 is now available under a click through at > https://computeexpresslink.org/cxl-specification/ and it brings new > shiny toys. > > RFC reason > - Whilst trace capture with a particular configuration is potentially useful > the intent is that CXL HMU units will be used to drive various forms of > hotpage migration for memory tiering setups. This driver doesn't do this > (yet), but rather provides data capture etc for experimentation and > for working out how to mostly put the allocations in the right place to > start with by tuning applications. > > CXL r3.2 introduces a CXL Hotness Monitoring Unit definition. The intent > of this is to provide a way to establish which units of memory (typically > pages or larger) in CXL attached memory are hot. The implementation details > and algorithm are all implementation defined. The specification simply > describes the 'interface' which takes the form of ring buffer of hotness > records in a PCI BAR and defined capability, configuration and status > registers. > > The hardware may have constraints on what it can track, granularity etc > and on how accurately it tracks (e.g. counter exhaustion, inaccurate > trackers). Some of these constraints are discoverable from the hardware > registers, others such as loss of accuracy have no universally accepted > measures as they are typically access pattern dependent. Sadly it is > very unlikely any hardware will implement a truly precise tracker given > the large resource requirements for tracking at a useful granularity. > > There are two fundamental operation modes: > > * Epoch based. Counters are checked after a period of time (Epoch) and > if over a threshold added to the hotlist. > * Always on. Counters run until a threshold is reached, after that the > hot unit is added to the hotlist and the counter released. > > Counting can be filtered on: > > * Region of CXL DPA space (256MiB per bit in a bitmap). > * Type of access - Trusted and non trusted or non trusted only, R/W/RW > > Sampling can be modified by: > > * Downsampling including potentially randomized downsampling. > > The driver presented here is intended to be useful in its own right but > also to act as the first step of a possible path towards hotness monitoring > based hot page migration. Those steps might look like. > > 1. Gather data - drivers provide telemetry like solutions to get that > data. May be enhanced, for example in this driver by providing the > HPA address rather than DPA Unit Address. Userspace can access enough > information to do this so maybe not. > 2. Userspace algorithm development, possibly combined with userspace > triggered migration by PA. Working out how to use different levels > of constrained hardware resources will be challenging. > 3. Move those algorithms in kernel. Will require generalization across > different hotpage trackers etc. > > So far this driver just gives access to the raw data. I will probably kick > of a longer discussion on how to do adaptive sampling needed to actually > use these units for tiering etc, sometime soon (if no one one else beats > me too it). There is a follow up topic of how to virtualize this stuff > for memory stranding cases (VM gets a fixed mixture of fast and slow > memory and should do it's own tiering). > > More details in the Documentation patch but typical commands are: > > $perf record -a -e cxl_hmu_mem0.0.0/epoch_type=0,access_type=6,\ > hotness_threshold=1024,epoch_multiplier=4,epoch_scale=4,range_base=0,\ > range_size=1024,randomized_downsampling=0,downsampling_factor=32,\ > hotness_granual=12 > > $perf report --dump-raw-traces > > Example output. With a counter_width of 16 (0x10) the least significant > 4 bytes are the counter value and the unit index is bits 16-63. > Here all units are over the threshold and the indexes are 0,1,2 etc. > > . ... CXL_HMU data: size 33512 bytes > Header 0: units: 29c counter_width 10 > Header 1 : deadbeef > 0000000000000283 > 0000000000010364 > 0000000000020366 > 000000000003033c > 0000000000040343 > 00000000000502ff > 000000000006030d > 000000000007031a > > Which will produce a list of hotness entries. > Bits[N-1:0] counter value > Bits[63:N] Unit ID (combine with unit size and DPA base + HDM decoder > config to get to a Host Physical Address) > > Specific RFC questions. > - What should be in the header added to the aux buffer. > Currently just the minimum is provided. Number of records > and the counter width needed to decode them. > - Should we reset the counters when doing sampling "-F X" > If the frequency is higher than the epoch we never see any hot units. > If so, when should we reset them? > > Note testing has been light and on emulation only + as perf tool is > a pain to build on a striped back VM, build testing has all be on > arm64 so far. The driver loads though on both arm64 and x86 so > any problems are likely in the perf tool arch specific code > which is build tested (on wrong machine) FWIW, runs on x86. However, it triggers a lockdep warning in both start and stop due to the spin lock. Something to tidy up for RFCv2. J > > The QEMU emulation needs some cleanup, but I should be able to post > that shortly to let people actually play with this. There are lots > of open questions there on how 'right' we want the emulation to be > and what counting uarch to emulate. > > Jonathan Cameron (4): > cxl: Register devices for CXL Hotness Monitoring Units (CHMU) > cxl: Hotness Monitoring Unit via a Perf AUX Buffer. > perf: Add support for CXL Hotness Monitoring Units (CHMU) > hwtrace: Document CXL Hotness Monitoring Unit driver > > Documentation/trace/cxl-hmu.rst | 197 +++++++ > Documentation/trace/index.rst | 1 + > drivers/cxl/Kconfig | 6 + > drivers/cxl/Makefile | 3 + > drivers/cxl/core/Makefile | 1 + > drivers/cxl/core/core.h | 1 + > drivers/cxl/core/hmu.c | 64 ++ > drivers/cxl/core/port.c | 2 + > drivers/cxl/core/regs.c | 14 + > drivers/cxl/cxl.h | 5 + > drivers/cxl/cxlpci.h | 1 + > drivers/cxl/hmu.c | 880 ++++++++++++++++++++++++++++ > drivers/cxl/hmu.h | 23 + > drivers/cxl/pci.c | 26 +- > tools/perf/arch/arm/util/auxtrace.c | 58 ++ > tools/perf/arch/x86/util/auxtrace.c | 76 +++ > tools/perf/util/Build | 1 + > tools/perf/util/auxtrace.c | 4 + > tools/perf/util/auxtrace.h | 1 + > tools/perf/util/cxl-hmu.c | 367 ++++++++++++ > tools/perf/util/cxl-hmu.h | 18 + > 21 files changed, 1748 insertions(+), 1 deletion(-) > create mode 100644 Documentation/trace/cxl-hmu.rst > create mode 100644 drivers/cxl/core/hmu.c > create mode 100644 drivers/cxl/hmu.c > create mode 100644 drivers/cxl/hmu.h > create mode 100644 tools/perf/util/cxl-hmu.c > create mode 100644 tools/perf/util/cxl-hmu.h >