From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932965AbcBITSD (ORCPT ); Tue, 9 Feb 2016 14:18:03 -0500 Received: from mga04.intel.com ([192.55.52.120]:48517 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932435AbcBITR7 (ORCPT ); Tue, 9 Feb 2016 14:17:59 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,422,1449561600"; d="scan'208";a="649692926" Date: Tue, 9 Feb 2016 11:17:59 -0800 From: "Luck, Tony" To: Borislav Petkov Cc: Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andy Lutomirski , Peter Zijlstra , Steven Rostedt , Brian Gerst , lkml Subject: Re: [PATCH -v2] x86: Add an archinfo dumper module Message-ID: <20160209191758.GA21766@agluck-desk.sc.intel.com> References: <20160201115601.GD6438@pd.tnic> <3908561D78D1C84285E8C5FCA982C28F39FCE0E4@ORSMSX114.amr.corp.intel.com> <20160202094147.GA3778@pd.tnic> <20160203104823.GA21257@gmail.com> <20160203110052.GA20682@pd.tnic> <20160204152235.GB5343@pd.tnic> <20160204190757.GA4249@agluck-desk.sc.intel.com> <20160207105103.GC5862@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160207105103.GC5862@pd.tnic> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > What I was going to propose, though, was to simplify the parsing by > doing this: > > struct reg_range { > const char * const names; > unsigned flags; > unsigned len; > }; > > which describes a bit slice of the register and then do this: > > const struct reg_range reg_descriptor[] = { > { TYPE_FLAG, 1, { "VAL" } }, > { TYPE_RSVD, 62 - 11 + 1, {"rsvd" } }, > { TYPE_ALTERNATE, 2, { "nope", "low", "mid", high" } }, > { TYPE_HEX, 3, { "BAR" } }, > { TYPE_DEC, 2, { "FOO" } }, > }; > > Then, the parsing code would simply do: > > for (i = ARRAY_SIZE(reg_descriptor) - 1; i >= 0; i--) > dump_range(reg_descriptor[i]); > > > with all the logic in dump_range(). > > The advantage is that you don't have to do any string parsing which > might be problematic in some cases and when typing the register > descriptor, you can be very easy exact on bit length and which bits by > typing the values directly from the manuals. And you can do lazy stuff > like "62-11+1" above in case you don't want to count reserved bits, > especially if they're trailing nybbles and such fun... There is a lot of bit counting and typing either way. My string format is visually compact, and looks quite similar to the eventual output. Your reg_range does allow you to pass counting to the compiler in the case that the documentation gives you highbit/lowbit ranges. But most fields are small enough that yuo don't even need to take your socks off to count ... so I don't see it as a huge deal. Both formats allow for a sanity check that all the bitfields add up to 64 ... which will detect single errors (which your code for my example would fail because you missed the second reserved field) and only have 60 bits described). -Tony