LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-14-2011, 01:42 AM   #1
pillisrikanth
LQ Newbie
 
Registered: May 2011
Location: india,andhrapradesh,guntur
Posts: 29
Blog Entries: 3

Rep: Reputation: 0
Question how to find cpu id usinf linux c?


hi this is srikanthpilli, i am using arm9-cortex A9 processor. i wanna find arm9 processor cpu id by using linux 'C'. how i will write C code? and how i will check code in arm9-cortex-A9 processor? please help this problem


sorry about my english

Thanks in Advance

srikanthpilli
 
Old 12-14-2011, 07:07 AM   #2
cnxsoft
Member
 
Registered: Nov 2010
Location: Thailand
Distribution: Fedora 12, Ubuntu 10.10
Posts: 166

Rep: Reputation: 29
You should be able to get the info you need by checking the content of /proc/cpuinfo
 
Old 12-16-2011, 01:05 AM   #3
pillisrikanth
LQ Newbie
 
Registered: May 2011
Location: india,andhrapradesh,guntur
Posts: 29

Original Poster
Blog Entries: 3

Rep: Reputation: 0
Question cpuid problem

Thanks for your suggestion, this was done successfully in my console. but i wanna store getting data after type cat /proc/cpuinfu in some other location. so that's why i am asking you how to write code in linux C and how i will store that data in file.


thanks
srikanthpilli
 
Old 12-16-2011, 08:36 AM   #4
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hello srikanth,

Here is the solution of your problem, maybe this code can help you:

#include <stdio.h>

int main(int argc, char **argv)
{
unsigned eax, ebx, ecx, edx;

eax = 1; /* processor info and feature bits */
native_cpuid(&eax, &ebx, &ecx, &edx);

printf("stepping %d\n", eax & 0xF);
printf("model %d\n", (eax >> 4) & 0xF);
printf("family %d\n", (eax >> 8) & 0xF);
printf("processor type %d\n", (eax >> 12) & 0x3);
printf("extended model %d\n", (eax >> 16) & 0xF);
printf("extended family %d\n", (eax >> 20) & 0xFF);
}



And let us know if this code works for you.
 
Old 12-16-2011, 08:47 AM   #5
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
And this command will tell you Api usage:

/usr/bin/lsb_release -a
 
Old 12-17-2011, 02:38 AM   #6
cnxsoft
Member
 
Registered: Nov 2010
Location: Thailand
Distribution: Fedora 12, Ubuntu 10.10
Posts: 166

Rep: Reputation: 29
Quote:
Originally Posted by pillisrikanth View Post
Thanks for your suggestion, this was done successfully in my console. but i wanna store getting data after type cat /proc/cpuinfu in some other location. so that's why i am asking you how to write code in linux C and how i will store that data in file.


thanks
srikanthpilli
I meant you can open /proc/cpuinfo inside your C program to get and store the data.
But if Satyaveer Arya code works, it looks much better.
 
Old 12-17-2011, 10:34 PM   #7
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Yes ofcourse you can open /proc/cpuinfo file inside C program to get and store data in some other file.

---------- Post added 18th Dec 2011 at 10:05 AM ----------

Try the above code given by me and please share the results with us.
 
Old 12-26-2011, 02:46 AM   #8
pillisrikanth
LQ Newbie
 
Registered: May 2011
Location: india,andhrapradesh,guntur
Posts: 29

Original Poster
Blog Entries: 3

Rep: Reputation: 0
Question unable to compile this code?

after save the above program with cpuid.c, i tried with gcc cpuid.c, it shows the following error.

i.e
/tmp/cc2NybTs.o: In function `main':
cpuid.c.text+0x31): undefined reference to `native_cpuid'
collect2: ld returned 1 exit status
 
Old 12-26-2011, 03:23 AM   #9
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Satyaveer Arya's code seems to have been brought from this page:
Stack Overflow: Getting Machine Serial number and CPU Id using c/c++ in Linux

That page provides the definition for native_cpuid() that should be included as part of the C source file.

In addition, the solution on the page links to a wikipedia article (Wikipedia: CPUID) that describes bit ranges and their meanings for the various processor registers that are read by native_cpuid().
 
Old 12-26-2011, 07:00 AM   #10
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
As far as I can tell, the above examples are specific to x86 architecture, and will not work on ARM A9.

Obviously, A9 does have a mechanism for obtaining processor and architecture information; you might be able to use inline assembly to do that. However, it seems to me there are a lot of details to worry about (looking at some of the kernel sources), enough so that it makes more sense to let the kernel people worry about detecting the features, and just read /proc/cpuinfo in userspace programs instead.

If you are worried about memory usage or similar issues, you can use low-level I/O (unistd.h) to read /proc/cpuinfo to a small buffer, splitting each line into name : value pairs for parsing. Parse each pair, perhaps using a helper function for each different name, populating a structure describing the current CPU architecture with the results. This may sound a bit complicated, but it is not at all difficult to do. If you are only interested in specific capabilities (as in whether certain features are available or not), it is even easier.

If you'd like to see some example code, please show the /proc/cpuinfo file from your ARM Cortex A9 first.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find how many CPU's are active in 8 CPU Linux machine sumit_sinha Linux - General 11 03-29-2011 10:53 AM
How to find out the CPU and OS information on linux? yupeng Linux - General 3 05-25-2008 11:39 PM
LXer: How do I find out Linux CPU utilization? LXer Syndicated Linux News 0 01-14-2007 09:03 AM
Network traffic Grapher usinf RRDTool shipon_97 Linux - Networking 4 11-19-2006 05:27 AM
How to find CPU Cache ? (apart from dmesg|grep CPU) Dark Carnival Linux - Hardware 3 12-22-2005 07:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration