Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1330594 > unrolled thread

Re: [PATCH -v2] x86: Add an archinfo dumper module

Started by"Luck, Tony" <tony.luck@intel.com>
First post2016-02-09 20:20 +0100
Last post2016-02-09 20:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH -v2] x86: Add an archinfo dumper module "Luck, Tony" <tony.luck@intel.com> - 2016-02-09 20:20 +0100
    Re: [PATCH -v2] x86: Add an archinfo dumper module Borislav Petkov <bp@alien8.de> - 2016-02-09 20:50 +0100

#1330594 — Re: [PATCH -v2] x86: Add an archinfo dumper module

From"Luck, Tony" <tony.luck@intel.com>
Date2016-02-09 20:20 +0100
SubjectRe: [PATCH -v2] x86: Add an archinfo dumper module
Message-ID<r0lZo-8lW-3@gated-at.bofh.it>
> 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

[toc] | [next] | [standalone]


#1330612

FromBorislav Petkov <bp@alien8.de>
Date2016-02-09 20:50 +0100
Message-ID<r0msq-5p-15@gated-at.bofh.it>
In reply to#1330594
On Tue, Feb 09, 2016 at 11:17:59AM -0800, Luck, Tony wrote:
> 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.

Except if you have 64 all single bits and all defined. Then that thing:

+static char *cr4_format =
+"41r|PKE|SMAP|SMEP|1r|OSXSAVE|PCIDE|FSGSBASE|1r|SMXE|VMXE|2r|OSXMMEXCPT|OSFXSR|PCE|PGE|MCE|PAE|PSE|DE|TSD|PVI|VME";

triples. The array approach is going to be long too but in the
vertical and still visually parseable.

> 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).

The code iterating over reg_descriptor can check that, of course.

So the only thing I'm trying to avoid is string parsing - if you add all
the corner cases handling and more field syntax, then the whole parsing
game could become pretty complex and maybe even fragile.

Not with the range descriptors - that remains simple. And I like simple.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web