All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andreas Herrmann <andreas.herrmann3@amd.com>
Cc: Jaswinder Singh Rajput <jaswinder@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86 maintainers <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [git-pull -tip] x86: msr architecture debug code
Date: Thu, 5 Mar 2009 15:08:09 +0100	[thread overview]
Message-ID: <20090305140809.GA27962@elte.hu> (raw)
In-Reply-To: <20090305135444.GB7347@alberich.amd.com>


* Andreas Herrmann <andreas.herrmann3@amd.com> wrote:

> On Mon, Mar 02, 2009 at 09:54:37PM +0100, Ingo Molnar wrote:
> > * Jaswinder Singh Rajput <jaswinder@kernel.org> wrote:
> 
> Oops, didn't read this mail till the end.
> Thus I missed this part.
> 
> > > +{
> > > +	struct cpuinfo_x86 *cpu = &cpu_data(0);
> > > +
> > > +	if (!cpu_has(cpu, X86_FEATURE_MSR))
> > > +		return -ENODEV;
> > > +
> > > +	msr_dir = debugfs_create_dir("msr", arch_debugfs_dir);
> > > +
> > > +	msr_file = debugfs_create_file("msr", S_IRUGO, msr_dir,
> > > +					NULL, &msr_fops);
> > > +	pmc_file = debugfs_create_file("pmc", S_IRUGO, msr_dir,
> > > +					NULL, &pmc_fops);
> > 
> > I think it would be possible to have a much more intuitive file 
> > layout under /debug/x86/msr/ than these two /debug/x86/msr/msr 
> > and /debug/x86/msr/pmc files.
> > 
> > Firstly, it should move one level deeper, to /debug/x86/cpu/msr/ 
> > - because the MSR is really a property of the CPU, and there are 
> > other properties of the CPU we might want to expose in the 
> > future.
> > 
> > Secondly, the picking of debugfs (as opposed to sysfs) is a good 
> > choice, because we probably want to tweak the layout a number of 
> > times and want to keep flexibility, without being limited by the 
> > sysfs ABI.
> > 
> > So i like the idea - but we really want to do even more and add 
> > more structure to this. If we just want dumb msr enumeration we 
> > already have /dev/msr.
> > 
> > Regarding the msr directory: one good approach would be to have 
> > have several "topic" directories under /debug/x86/cpu/msr/.
> > 
> > One such topic would be the 'pmu', with a structure like:
> > 
> >  /debug/x86/cpu/msr/pmu/
> >  /debug/x86/cpu/msr/pmu/pmc_0/
> >  /debug/x86/cpu/msr/pmu/pmc_0/counter
> >  /debug/x86/cpu/msr/pmu/pmc_0/eventsel
> > 
> > There would also be a /debug/x86/cpu/msr/raw/ directory with all 
> > MSR numbers we know about explicitly, for example:
> > 
> >  /debug/x86/cpu/msr/raw/0x372/value
> >  /debug/x86/cpu/msr/raw/0x372/width
> 
> Having this stuff in the kernel unnecessarily bloats up kernel code.

it should be a default-off Kconfig option and it is in debugfs 
so there's no real bloat issue here.

> What the kernel needs to provide is a reliable interface to 
> access MSRs -- to pass the data to userspace. This interface 
> is already there.
> 
> IMHO all kind of parsing and grouping of that data belongs in 
> user space.
> 
> One exception are MSRs that need to be checked early during 
> boot (e.g. MTRRs). For debugging purposes you might want to 
> dump certain MSRs early. But then you will use printk and not 
> debugfs.

Well it's really nice to know the _kernel's_ enumeration of MSRs 
and its knowledge about the structure of those MSRs.

Sure, we can and do export the flat MSR space to user-space, but 
the kernel also enumerates them internally, in various places. 
The debugfs interface shows them in one way - and as such also 
acts as a central force to keep these things tidy.

a VFS namespace is also pretty educative. You can see which MSRs 
matter to the lapic for example, you can see their symbolic 
names, their current state, etc. etc.

> > Maybe a symlink pointing it back to the topic directory 
> > would be useful as well. For example:
> > 
> >  /debug/x86/cpu/msr/raw/0x372/topic_dir -> /debug/x86/cpu/msr/pmu/pmc_0/
> > 
> > Other "topic directories" are possible too: a 
> > /debug/x86/cpu/msr/apic/ layout would be very useful and 
> > informative as well, and so are some of the other MSRs we 
> > tweak during bootup.
> 
> All nice suggestions but why in-kernel?
> 
> Just hack some script to do this. This is much more 
> maintainable. You don't need a kernel update to add support 
> for new CPUs or to fix bugs in this code itself -- you just 
> have to tweak your script.

the kernel tends to know a lot about these MSRs already so we 
just provide that information in a more structured form as well.

Such more structured form, beyond the debugging and 
education/development advantages, also acts as a counter-force 
back to the MSR enumeration code of the kernel and makes them 
more structured. It will no doubt also extend the kernel's 
knowledge of MSRs - read-only MSRs we dont normally read.

There's also a few other things like the IRR readout in the APIC 
code or the perfcounters status dump can also be done cleanly 
via /debug/x86/cpu/msr/.

Eventually i'd like /debug/x86/ to become a full CPU state dump: 
the kernel pagetable dumping code could go there, we could show 
control registers, we could show the GDT and IDT settings and 
contents, etc. etc.

	Ingo

  reply	other threads:[~2009-03-05 14:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-02 15:42 [git-pull -tip] x86: msr architecture debug code Jaswinder Singh Rajput
2009-03-02 17:25 ` Jaswinder Singh Rajput
2009-03-02 20:54 ` Ingo Molnar
2009-03-04 19:16   ` Jaswinder Singh Rajput
2009-03-04 20:49     ` [git-pull -tip V2] " Jaswinder Singh Rajput
2009-03-05 12:21       ` Andreas Herrmann
2009-03-05 13:10         ` Jaswinder Singh Rajput
2009-03-05 13:32         ` Ingo Molnar
2009-03-05 13:48           ` Jaswinder Singh Rajput
2009-03-05 14:11             ` Ingo Molnar
2009-03-05 14:31               ` Jaswinder Singh Rajput
2009-03-05 13:54   ` [git-pull -tip] " Andreas Herrmann
2009-03-05 14:08     ` Ingo Molnar [this message]
2009-03-05 17:01       ` Andreas Herrmann
2009-03-05 14:12     ` Jaswinder Singh Rajput
2009-03-05 14:37       ` Andreas Herrmann
2009-03-05 15:16         ` Jaswinder Singh Rajput
2009-03-05 15:47         ` Jaswinder Singh Rajput
2009-03-05 18:23           ` Andreas Herrmann
2009-03-05 18:40             ` Jaswinder Singh Rajput
2009-03-06 10:07               ` Andreas Herrmann

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=20090305140809.GA27962@elte.hu \
    --to=mingo@elte.hu \
    --cc=andreas.herrmann3@amd.com \
    --cc=hpa@zytor.com \
    --cc=jaswinder@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.