linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Luck, Tony" <tony.luck@intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andy Lutomirski <luto@amacapital.net>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Brian Gerst <brgerst@gmail.com>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -v2] x86: Add an archinfo dumper module
Date: Tue, 9 Feb 2016 11:17:59 -0800	[thread overview]
Message-ID: <20160209191758.GA21766@agluck-desk.sc.intel.com> (raw)
In-Reply-To: <20160207105103.GC5862@pd.tnic>

> 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

  reply	other threads:[~2016-02-09 19:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-01 11:56 [RFC] Dump interesting arch/platform info Borislav Petkov
2016-02-01 23:29 ` Luck, Tony
2016-02-02  9:41   ` Borislav Petkov
2016-02-03 10:48     ` Ingo Molnar
2016-02-03 11:00       ` Borislav Petkov
2016-02-04 15:22         ` [PATCH -v2] x86: Add an archinfo dumper module Borislav Petkov
2016-02-04 19:07           ` Luck, Tony
2016-02-07 10:51             ` Borislav Petkov
2016-02-09 19:17               ` Luck, Tony [this message]
2016-02-09 19:46                 ` Borislav Petkov
2016-02-05 19:51           ` Luck, Tony
2016-02-05 22:24             ` Luck, Tony
2016-02-08  0:01           ` H. Peter Anvin
2016-02-08  7:50             ` Boris Petkov
2016-02-09 12:23             ` Ingo Molnar
2016-02-09 14:01               ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160209191758.GA21766@agluck-desk.sc.intel.com \
    --to=tony.luck@intel.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).