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 C8F47C77B61 for ; Sun, 26 Mar 2023 13:42:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 695CF6B0074; Sun, 26 Mar 2023 09:42:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64CBB6B0078; Sun, 26 Mar 2023 09:42:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E0B96B007D; Sun, 26 Mar 2023 09:42:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 313126B0074 for ; Sun, 26 Mar 2023 09:42:56 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0FE4F14044D for ; Sun, 26 Mar 2023 13:42:56 +0000 (UTC) X-FDA: 80611165152.04.1CE04D0 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf30.hostedemail.com (Postfix) with ESMTP id A7E2780017 for ; Sun, 26 Mar 2023 13:42:53 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eZ02xYuA; spf=pass (imf30.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679838174; 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: references:dkim-signature; bh=VVVe+YaBXys2N1iteOdjrgthFiNKC3pd27y/5E84gco=; b=DwfUXhHvz8fPXB7jnzMDpW12SS54o/00GeuyNaIBjq+eHicgd+KKZZ9JMRvG9Cj/hoWBxF WwqzUBJ3PGdz+RDYh5q20SlUgee1vx/SvSJJ5wRErMDGsYk//JnDjunXHPbXYYoBWOlpC3 B6owVPyUd1hckfPPRf6IvGAU+XYQRgs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eZ02xYuA; spf=pass (imf30.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679838174; a=rsa-sha256; cv=none; b=m2D66HvXZC6yQZCSpAwU1URvuqs4Z47cizgGRVjOybN6KcwEQVMgD+dc9Egy0rkgzvu0+T Q7hklvAjOj1zC7SCYt1vwnkEFt3A0i3oqC4KTi4l6q6jwfb33GhmZ5vS6GazwwHPYBrEMj nIPgl9YFkVIOYT505esxyrGhYU+Njh4= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 6F136CE0EA2; Sun, 26 Mar 2023 13:42:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91B79C433D2; Sun, 26 Mar 2023 13:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679838168; bh=x+elaEjNBGrw81mnE6F3RWtDHADRa8KpDJx2MLvF+68=; h=From:Subject:Date:To:Cc:From; b=eZ02xYuAFO8BHQcq5wBrsTWOROoC1psdx7Zlo1qBJVADy7vf5K7sYEsQ7Dl+Ue8xa MKLLFyQ5k98pIJTv0a2dkzeLBPrKsjxaB8+7FubDbH5VIwZkQpLPWwHTzHIgn0WO10 pid06sLruwUrROAet5ObBbcpOd/4V5ndquDDyXUQ0ydFsCHnsFNDnMekNCGF/bNv6A KO/ZXBsORenk1JDdSR4fIjVKuUiI/HmusKVoG1dqZzm/y2Mpy0TPZoyUXCeqOW+3N5 1oBQ1pmGthZxrS0WucIdlG6ymWvg30I9H6b9Y5Nr9CPiZBayr8E0qtngf+XczpoxVw jeYx4F0NDs2PA== From: Mark Brown Subject: [PATCH v2 0/2] regmap: Add basic maple tree register cache Date: Sun, 26 Mar 2023 14:42:37 +0100 Message-Id: <20230325-regcache-maple-v2-0-799dcab3ecb1@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAM1LIGQC/3WNyw6CMBAAf4X07Jo+BNST/2E4lHWhDdiSrUEN4 d8t3D3OJJNZRCL2lMS1WATT7JOPIYM+FAKdDT2Bf2QWWmojjS6BqUeLjuBpp5HAVCeqy7PCTqL IUWsTQcs2oNuyd+Rh0xNT5z/7595kdj69In/37aw2+/cwK5CgsK4uqjLlpWtvA3Gg8Ri5F826r j+fcv0FxAAAAA== To: "Liam R. Howlett" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-2eb1a X-Developer-Signature: v=1; a=openpgp-sha256; l=2618; i=broonie@kernel.org; h=from:subject:message-id; bh=x+elaEjNBGrw81mnE6F3RWtDHADRa8KpDJx2MLvF+68=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkIEvUrRLjFjSATPOgbSsaPDGv7FcK/Sg2c2iZ0au8 8y5yp/WJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZCBL1AAKCRAk1otyXVSH0IK1B/ 4wMIlkYEA7C04mN1cu+A3y5NLYTDyyBtkoN3pWcqGjgYC7pq0jM+RRY/OanBCEOZomJ3Ulwk7JmYPe xC2BZI2Gi4HpQGod24jXNlbxlLlNba1wGZq7EJNVzDmsxSDlrhYpNG9Fmx4J7+6E/zKmtPrtTIhnOP A2Ns0W61a6tUwnqLaXLxLdwIplVflOxVATdugvUlNBr/7YHoUX8YEM7iLeLwk7YGdOC3BrySbdXQyb ctI1c5KeAzBf5lVMLLnKnWmnqfKZCP8a+LxyRICTVWC8Y6AKrSi6iclmMVfGQtYtSokFJs6y1LnXHD 76szIVvDvCHf1GS3fQ3cbxWTgEmoBA X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A7E2780017 X-Stat-Signature: c9u6brr9ymrxpio6b781ery9aw7gz7wu X-HE-Tag: 1679838173-782840 X-HE-Meta: U2FsdGVkX1/+DD4llLLIbwOaCK6I6+FCQcUPGRwqOYeRsVbLIE/vDBRJgj12cGveozyo4y7scazaPx6gxMRXVSkCT0pG/Q3K9mE8ExBIrsisDvCIMz0tLdE1WBN+RTXyN69J7Jt/LLLTGqkgUYsNJzfOVyKoJfBqogqMqNFMDkSB0QKUE2Njd1m6egTGw6Q9L7qV/qvUdVXqL0DPo5SyKGHISsXhhckWahwFqmA7ganYNAkLZMZLoqab+Vev02oqBzs2GdJ29ZFCmIknj6cGZtpIeCYk6A+l0jB7qOZEkPQ++DJi0NSrpyupM1UoYr7/5SRVubE022zpac2B3hOXBmIGpRmn3ZjTtDbHTEhtoX0sRRYky8HB3os0J3X5fY0Tf2XpLBu1WYOwWtYH6PB11/+lqkBZgFff1gfoQPYNsqN65w1I8jc8eB083G17GbRlZXMpgYDqJl33/dixUozLGfdpvQOVDtxoR53+RIaywJ3VgtcWd2d1qcsutD9ns7E+Zc5Z27fmA7j5fj4towSVziBGS2YwKJTsckrYa1qVMUKuKbszaDpIDLldCFtwHV+zFOBsqAOD4OwR5ar2rAAFpuSLSrz7gSDfo8mZgpPXs1sjRro6B/YT0zh6h6PZo23e4w7Q8NnvAA205VtUfVdqnPi3bRPrmyB7Vwa+zq29WD793wtLx1+g2Tb5D/QGmsbvhGyUSTzK00TmrXot9rE6x6E98r7WK+Ic2SWqV6ovNP6VdUUuRLBr7y30EzdFJr7zZvuHOiqgQF/bEL7W7m+K/wjuwwCQQu9qo2z/kZFx6Y2Wpw9goqFLJgrvrsCkBlpUfKLbHf0AMHgitkahCgo8NEY66dp+5AEK/h4FihOZnoRMsoLVeLcv+EahPph5e/SHaWE8H83xlyunz11mw7KSU3HU0nVuOzWZpwbJnbRzrlxr2KSWtsisqMq7TnMlt4gOMuzu3lJLQAXfSlIKVmb 70/CUrYX CP2S7+h6U373//Rl06WZIN6YtsrG6lVSOx+e5m+FEXsK5bMLAalB29AdHoD1RyMM8MHKdfhsAXEgTXWkPGlpwGuT0RZf310caxUfqhn8z/0iV/xy9HRVUT7TaAwwQaP56PmtsIBiVel2TW0Ajl/4QThrqejKQQfU/dM7GKGwsIl9CMdnEKPIDSPvzj0v5aR1uveiEu80ZXR7DbtKYOLRWPsYGRYO8DOGEd7mu4rH+CWw1tqI2R7kgFA+ZnIsrZrQpfcsn/RJhWPob5/J4M9g3rMYM7bmDKdDq5o7hJFkW9vWPcybxwoKBMxGVK25cSuiNk1Bz6FY+R66cIpR15JvJcT5Fim9L9jz18scY08CVgfR11ac= 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: The current state of the art for sparse register maps is the rbtree cache. This works well for most applications but isn't always ideal for sparser register maps since the rbtree can get deep, requiring a lot of walking. Fortunately the kernel has a data structure intended to address this very problem, the maple tree. Provide an initial implementation of a register cache based on the maple tree to start taking advantage of it. The entries stored in the maple tree are arrays of register values, with the maple tree keys holding the register addresses. We store data in host native format rather than device native format as we do for rbtree, this will be a benefit for devices where we don't marshal data within regmap and simplifies the code but will result in additional CPU overhead when syncing the cache on devices where we do marshal data in regmap. This should work well for a lot of devices, though there's some additional areas that could be looked at such as caching the last accessed entry like we do for rbtree and trying to minimise the maple tree level locking. We should also use bulk writes rather than single register writes when syncing the cache where possible, even if we don't store in device native format, and there is room for improvement in how we load register defaults into the cache. Very small register maps may continue to to better with rbtree longer term, though the difference should become marginal especially in the context of the cost of register I/O. Changes in v2: - Rework to store multiple values per maple tree node with coalescing, bringing us much closer to the state of the art with rbtree. - Add locking required for maple tree usage. - Use more efficent code suggested by Liam to free the register map. - Link to v1: https://lore.kernel.org/r/20230325-regcache-maple-v1-0-1c76916359fb@kernel.org Signed-off-by: Mark Brown --- Mark Brown (2): regmap: Factor out single value register syncing regmap: Add maple tree based register cache drivers/base/regmap/Makefile | 2 +- drivers/base/regmap/internal.h | 2 + drivers/base/regmap/regcache-maple.c | 265 +++++++++++++++++++++++++++++++++++ drivers/base/regmap/regcache.c | 41 ++++-- drivers/base/regmap/regmap-kunit.c | 3 + include/linux/regmap.h | 1 + 6 files changed, 299 insertions(+), 15 deletions(-) --- base-commit: c20bc1c03695287bd19922a32052f2bc7d4a462d change-id: 20230325-regcache-maple-364e7581cf0c Best regards, -- Mark Brown