From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934932AbeAHQZe (ORCPT + 1 other); Mon, 8 Jan 2018 11:25:34 -0500 Received: from lelnx193.ext.ti.com ([198.47.27.77]:25779 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934820AbeAHQZb (ORCPT ); Mon, 8 Jan 2018 11:25:31 -0500 Subject: Re: [PATCH 3/3] regcache: flat: Add valid bit to this cache type To: Mark Brown CC: References: <20180107232234.11064-1-afd@ti.com> <20180107232234.11064-3-afd@ti.com> <20180108120801.GD11698@sirena.org.uk> From: "Andrew F. Davis" Message-ID: <4daf0acd-2d50-5873-212e-618e7b6d8123@ti.com> Date: Mon, 8 Jan 2018 10:25:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20180108120801.GD11698@sirena.org.uk> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/08/2018 06:08 AM, Mark Brown wrote: > On Sun, Jan 07, 2018 at 05:22:34PM -0600, Andrew F. Davis wrote: >> Other regmap cache types (LZO, RBtree) report back un-successful register >> lookups when a value has not been previously written into the cache. This >> allows regmap core to perform a real un-cached lookup to fetch the value. >> The Flat type cache does not and so all read succeed reporting zero for the >> registers value, even when the actual value is not known. > >> We fix this by changing the flat cache element type to a struct >> containing both the register's value and a bool signifying if this value >> is an actual cached value or not. This also opens up a path to implement >> additional regcache_ops such as "sync" and "drop" that rely on such >> validity information. > > The reason we don't do this for the flat cache is that its whole purpose > is to be as fast as possible in order to make it easier for MMIO devices. > Things that can take the hit of extra complexity should just use a rbtree > cache since if the registers are all bunched together it rapidly becomes > effectively the same data structure anyway. Unless you really know why > you're using a flat cache you probably shouldn't. > I can understand the need for a fast cache type, but without this change the implementation is simply wrong IMHO. Reading from a register that has not been read/written to should not just assume the default value is 0, it should first read and load the real initial value into the cache, just like other cache types do. Also, it looks like this cache type is used mostly in I2C devices (outside of sound/soc/, where in there, like you said MMIO devices are more common).