LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   SMP configuration problems -- NR_CPUS undefined (https://www.linuxquestions.org/questions/linux-general-1/smp-configuration-problems-nr_cpus-undefined-310156/)

Alotau 04-05-2005 08:36 PM

SMP configuration problems -- NR_CPUS undefined
 
I am trying to create a RAM image of Linux to run on a fairly bare platform. The chip I am using has 2 PPC cores and I am working on getting the SMP capabilities of Linux working. I am using MontaVista Linux (if that matters). I am able to successfully create an image when I don't enable the SMP option in the menuconfig (I forget what the option is exactly, something like: "Enable SMP support"). Then when I do enable it I get errors on the build that seems to say that the constant NR_CPUS isn't defined. I tracked that constant down to linux/threads.h. Now I need to know how/where to include that file and maybe why wasn't it included already since it seems to be necessary?

I am very new to Linux, so if any other details are needed, I would be happy to supply them. Any advice apprecitated!

Thanks,
Joey

Alotau 04-06-2005 08:38 PM

<bump>

Nobody? Need more details? Help!

Alotau 04-07-2005 03:17 PM

<bump>

If no one knows what I might try, can anyone point me somewhere else to ask/look? Any help greatly appreciated!

Ben2210 04-07-2005 06:19 PM

You can try two things.

In the menuconfig, in the SMP option, it allows you to define the "maximum number of CPUS". Have you set a value here ?

Other thing you can try :
Try adding NR_CPUS=2 in the Makefile itself, at the beginning.

Alotau 04-07-2005 07:22 PM

Thanks for the response, Ben. I am very slow with this Linux stuff, but here are the results of your suggestions:

Quote:

Originally posted by Ben2210
You can try two things.

In the menuconfig, in the SMP option, it allows you to define the "maximum number of CPUS". Have you set a value here ?

I don't see that option anywhere. The only mention of SMP is when I do `make menuconfig' under `Platform support' there is an option `Symmetric multi-processing support'. I checked that option and a sub-option appeared `Distribute interrupts on all CPUs by default'. I left that unchecked because it is unimportant at the moment.

Quote:


Other thing you can try :
Try adding NR_CPUS=2 in the Makefile itself, at the beginning.

I really am no sort of Linux expert, but I tried to put that line first in the file called `Makefile' and got the same sort of errors. It seemed to blow up when it was processing smp.h, again with the error that NR_CPUS is undefined. Did I put the line in the correct Makefile? Any more advice? Thanks again...

Ben2210 04-07-2005 07:44 PM

OK, forget about editing the Makefile. That was silly. If you modified your makefile, revert your changes, and if you can't, re-extract your kernel sources.

Here we go :

in the menuconfig, go in "Processor type and features", then enable "Symmetric multi-processing support". It opens a new option "Maximum number of CPUs (2-255) (NEW)". Set that to 2. And you are done !

Note that the help for this option says "CONFIG_NR_CPUS", so that's exactly what we were looking for.

Important note :

As you're using a PPC architecture and I'm using a intel architecture, it might be that you have a different menu than I have. If this is the case, and you are not being proposed to change the NR_CPUS, either add a line to your .config :
Code:

CONFIG_NR_CPUS=2
then rerun make menuconfig, save your config, re-edit your .config and check that the line you added is still there.

Try compiling with that.
If it doesn't work, your last chance is to manually add the following line to the file include/linux/autoconf.h in your kernel sources directory :

Code:

#define NR_CPUS 2
Note that you have to do this *after* you run make menuconfig, but before the actual compilation.

Ben2210 04-07-2005 07:47 PM

Hey, what kernel version are you using ? The NR_CPUS option says it's new, so that may explain why you don't have it!

Alotau 04-07-2005 08:11 PM

Alright, Ben, you are awesome for helping me out. I am getting the feeling that some of these options have been disabled because the distro assumes a given platform (the platform they assume is the one I am trying to modify). There isn't a "Processor type and features" option. The "Symmetric multi-processing support" options lives under "Platform Support". So I couldn't try out that piece of advice. Your 2nd piece of advice concerning my .config file confused me a bit because I don't know where this file is (or what it is really). So I skipped that as well. So I went and modified that autoconfig.h file you suggested (last resort, I know).

When building based on this I got several warnings now that NR_CPUS gets redefined. Seems odd since it wasn't defined at all when I didn't have it in the autoconfig file. Anyway, finally I get an error form what looks like the entry.S file with an undefined reference to "hash_table_lock". Maybe this distro just didn't come complete and ready for this kind of modification? Is that possible? If that's the case, should I just look for some other distro? Would really like to get this one to work, though, so any further advice? If I am doing something silly please let me know! Thanks again...

Alotau 04-07-2005 08:13 PM

Quote:

Originally posted by Ben2210
Hey, what kernel version are you using ? The NR_CPUS option says it's new, so that may explain why you don't have it!
When I do "make menuconfig" it says "Linux Kernel v2.4.20_mvl31-ml300 Configuration".

So I guess v2.4.20?

Ben2210 04-08-2005 01:19 AM

Hi.

When I said .config, I meant the (hidden) .config file in your kernel sources directory. To see it, do "ls -a". This is the kernel config file ; make menuconfig reads it to know what config to start with.

You don't have the same options as me because your Architecture is different from mine. You have PPC, I have intel. You could change that in some config file, but you do not want to do that, as you would get an Intel kernel, and you need a PPC kernel. Your distro is not at fault!

Forget about trying to tweak the source files : the error about the undefined reference to "hash_table_lock" seems impossible to work around.

So you are trying to compile a 2.4.20 kernel. This is totally antique! It must date back to 2002 or so. If you want to stay with a 2.4 kernel, the latest is 2.4.30. You can also try a 2.6 kernel (latest is 2.6.11.6). I think that compiling a newer kernel has a lot of chances of solving your problem.

You are not doing anything silly!

Alotau 04-08-2005 05:32 AM

Alright Ben, thx again.

So here is a little more detail on my situation, to fish for a little more advice on where to proceed:

I have a fairly nice motherboard (lots of I/O built-in, 4 PCI slots, CompactFlash Reader, some RAM) with a Xilinx FPGA as the processor (Virtex II Pro, which has the 2 PPCs embedded within). As a demo of the board, it came with this MontaVista distro (which is why I have been trying to use that) and there are some tutorials on how to make a RAM image to run on a given configuration of the FPGA. This configuration only uses one of the PPCs. My goal is to get both going in an SMP fashion (I can get it going with both PPCs doing their own, independent thing, but that isn't as exciting). By the way, I am building the kernel on a separate PC and will ultimately be downloading Linux to the board's RAM. The FPGA gets configured and loaded with a simple bootloader program that starts Linux.

Given all of that, would it be possible to just download some newer version of Linux for PPC and configure it for 2 processors and make a RAM disk image of it? By now I think I understand how to go about configuring a kernel (given all the options are there!) as well as the process of making the image, the big thing is getting Linux to actually run on this board. If so, any advice on which one and where to get it? Ideally it would be easy to configure and free! But I think the "easy" is more important than the "free".

I just re-read this and it sounds a little muddled, but if it makes sense, can you offer any advice?

Thanks for the encouragement!

Ben2210 04-08-2005 06:08 AM

First, if you are looking for a completely free distro that is very configurable, that will allow you to compile a custom kernel, and that handles PPC processors, one name comes to mind : Gentoo.

The problem is that your processor (Xilinx) looks so unusual, I'm not so sure that Gentoo will handle it. Perhaps this is why your system came with such an unusual distro as Montavista.

There's one thing that I don't understand : why don't you directly compile on your Xilinx system ? Compiling on another system and then putting the kernel on your Xilinx system is more complicated...
Is your other system a PPC too ?

I don't know how special the kernel provided by Montavista was. Perhaps your hardware is so unusual, that you can't use a standard kernel and have to get your kernel from Montavista. Perhaps you can find newer kernel sources at Montavista. Also perhaps Montavista provides kernel patches to adapt a standard kernel for your hardware. You should probably use google or go directly to Montavista's site to check.

In case your hardware is standard enough to use a standard kernel (given the proper kernel configuration), download 2.4.30 from www.kernel.org. Then take the kernel "config" file provided by Montavista (you can probably find it in /boot or in the kernel sources directory, where it will probably be called ".config").

Untar the 2.4.30 kernel sources, put the Montavista kernel "config" file here, rename it to ".config" and you're ready to make menuconfig.

If that still does not work, you can try a 2.6 kernel. 2.6 has better support for modern hardware, and yours seems to fall in that category.

If you think you need a 2.6 kernel, there's only one problem : you won't be able to reuse your Montavista config file. But if you think you're ready and you've read a good 2.6 HOWTO, why not!

Ben2210 04-08-2005 06:12 AM

And by the way 2.6 will give you better performance, especially for a SMP processor.

EDIT:
I just realized that the difference between your kernel compile options and mine were probably caused by the fact that you use 2.4 , and I use 2.6.

Alotau 04-09-2005 06:34 PM

Quote:

Originally posted by Ben2210
First, if you are looking for a completely free distro that is very configurable, that will allow you to compile a custom kernel, and that handles PPC processors, one name comes to mind : Gentoo.
Thanks, I will look into it. Actually, that is the theme of this reply, I will have to do quite a bit more homework it seems to get to anything working.
Quote:


The problem is that your processor (Xilinx) looks so unusual, I'm not so sure that Gentoo will handle it. Perhaps this is why your system came with such an unusual distro as Montavista.

Ideally, my system will look like any other PPC405 system when it is working properly. At least that is the idea. The FPGA stuff around the PPC core is there to try new things. The only 'new' thing that I want to try is getting two PPCs on one chip working together.
Quote:


There's one thing that I don't understand : why don't you directly compile on your Xilinx system ? Compiling on another system and then putting the kernel on your Xilinx system is more complicated... Is your other system a PPC too ?

No, I was on an intel machine building the kernel. Another reason why I was trying to use the Montavista stuff provided. The target system (PPC) and host system (Intel (686?)) were assumed when the Montavista tools were provided. Thus saving me the worry of building a tool chain (I guess that is what I would have to do). Compiling directly on the Xilinx system is too hairy for me to think about, though maybe I should? There is a configuration provided that acts like a PPC 405 machine and can boot Linux. I got a HD connected once. There is 256M of RAM. If I went this route is Gentoo still a good choice?
Quote:

...find newer kernel sources at Montavista. Also perhaps Montavista provides kernel patches...
The Montavista stuff provided was a "preview" so you can work with it all you want, but if you want support or to sell something with Montavista in it, you need to register and stuff. So I am on my own in the Montavista realm!

As for the rest of your message, I think that I will go and figure out how to build myself the correct Linux for what I need. Now for some more questions to aid my understanding of SMP in Linux:

With linux configured perfectly and working on an SMP system, what steps does Linux go through to bring the system up? Is there a pointer to somewhere that I coiuld read about this?

Anyone know of PPC multiprocessors, architecturally speaking? Where I might find more info on that (I know it isn't a linux question, per se)?

Any other advice given everything you see on this thread?

Thanks again Ben, you helped quite a bit. And thanks in advance for any future advice (from Ben or anyone else!)...

Joey

Ben2210 04-10-2005 04:40 AM

First, look what I found for you (I just Googled for "gentoo xilinx") :
http://www.klingauf.com/v2p/index.phtml

I don't have the knowledge to answer your last questions about Linux bootup and PPC architecture.

That's just my opinion, but I recommend that you get rid of Montavista as soon as possible. Even if you could afford MontaVista support, you would then deprive you of a good learning experience and of a lot of fun. I'm sure there's a way of configuring your system by hand, and I'm more and more sure that your system is 'standard enough' for standard linux kernel sources. I think that your CPU itself should be no problem to detect, the problem will more be about your motherboard. In this regard, the first thing to do is
Code:

lspci
(or /sbin/lspci). Please post here the output of this command.

Then, you have a choice.

Either you stick with MontaVista for now and you try to compile a vanilla kernel. Use the link I have found. Maybe the day will soon come, where you will see not one, but two little penguins on your bootup screen...

Or you switch directly to Gentoo. Probably the first thing for this would be to go to the gentoo.org forum, to explain precisely what is your hardware (including the lspci output) and ask whether Gentoo will handle it. To get an answer on a gentoo forum, use the famous vanity of Gentoo users. Don't ask "here's my hardware, can you help?", ask "I'm not sure Gentoo is able to handle this - what's your opinion?" ;)


All times are GMT -5. The time now is 08:18 AM.