All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kevin D. Kissell" <kevink@mips.com>
To: "Matthew Dharm" <mdharm@momenco.com>,
	"Linux-MIPS" <linux-mips@linux-mips.org>
Subject: Re: When to #ifdef on CPUs?
Date: Fri, 13 Sep 2002 12:51:41 +0200	[thread overview]
Message-ID: <00ca01c25b13$92c7f780$10eca8c0@grendel> (raw)
In-Reply-To: NEBBLJGMNKKEEMNLHGAIMEPBCIAA.mdharm@momenco.com

From: "Matthew Dharm" <mdharm@momenco.com>
> I'm basically done with my task of porting linux to our SR71000-based
> board.  I'm getting ready to start feeding patches to Ralf, and
> something occured to me....
> 
> Sometimes, in some places, we use CONFIG_ options to select the
> apropriate CPU.  Other places, we probe for the CPU based on the PRID
> register.
> 
> In some places, the reason for the choice is clear -- it's just much
> easier to select the cache library based on a CONFIG_ option in a
> Makefile than trying to do run-time assignment of many function
> pointers.
> 
> However, is some places, the choice is not clear.  In cpu-probe.c, for
> example, several of the CPU identification routines are wrapped in
> #ifdef's -- odd, since the wrong 'case' of the switch statements
> should never get executed, even if compiled in....

There is a big discontinuity between the R3000 privileged resource 
model and that of the R4000 and later CPUs. So it would not surprise 
me if the MIPS/Linux kernel retained some R3000/non-R3000 
conditional code for a while longer.  Much of rest of what you're 
seeing, particularly in cpu-probe.c, is just slop - expedient hacks 
that somehow became permanent.  

But the ambivalence between run-time and build-time binding
to CPUs probably also reflects the two poles of use of
MIPS/Linux.  The folks who use it on old SGI and DEC
workstations have platforms like the SGI Indy where the
same relatively RAM-rich platform configuration can support 
a number of different CPUs .  That tends to lead to run-time
binding of the CPU-specific routines and parameters.
The folks who use it for embedded apps tend to have
system and peripheral setups that are anyway pretty 
application-specific, and since memory isn't entirely free,
there's no advantage, and some slight disadvantage, 
in including code to support other CPUs in the OS image.
So we have an environment where boot-time CPU
binding works OK across the set of CPUs used in
Indys, and not necessarily for others.

And there are, alas, cases where the designers failed 
to  provide a correctly unique PrID register value, such 
as is apparently the case with the NEC Vr4111 and VR4181.  
I'd be willing to bet that there is *some* way to distinguish 
those two parts at run-time if one really wanted to, though.

> So, what's the rule here?  When do I used #ifdef and when do I just
> let the PRID stuff work it's magic?

I don't know that there's a rule as such, but I would strongly
recommend using the PrID and Config registers to generate a 
kernel CPU ID and a set of mips_cpu.options bits, and that
information abstracted into the mips_cpu structure should be
used in preference to comparing against CPU ID's.  It may
require a little more thought up-front, but it leaves the rest
of the code a lot easier to maintain.  You should have seen
what the kernel looked like before we introduced the
mips_cpu structure!

Fortunately, the standardization of the privileged resource 
architecture in the MIPS32 and MIPS64 specs means that
the problem shouldn't get much worse - newer parts should
just work with a MIPS32 kernel.

> I mean, heck... it might be nice to put a check to see if the detected
> CPU matches what the kernel was compiled for...

If it doesn't, that's a bug.

            Kevin K.

      parent reply	other threads:[~2002-09-13 10:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-13  1:58 When to #ifdef on CPUs? Matthew Dharm
2002-09-13  7:22 ` Maciej W. Rozycki
2002-09-13  9:08 ` Kevin D. Kissell
2002-09-13 10:34   ` Maciej W. Rozycki
2002-09-13 10:51 ` Kevin D. Kissell [this message]

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='00ca01c25b13$92c7f780$10eca8c0@grendel' \
    --to=kevink@mips.com \
    --cc=linux-mips@linux-mips.org \
    --cc=mdharm@momenco.com \
    /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.