LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2012, 12:36 AM   #1
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Rep: Reputation: 17
how can program determine: # of cores, execution core, core cps


My application needs to determine the following information at runtime. Except for item #1 (which should not change during execution), my application needs to determine these values regularly (not just once).

#1: number of CPU cores.
#2: current speed of core #n.
#3: which core #n is executing this code.

My application is C and assembly-language, so a solution available in either C or assembly-language is fine. The code to determine #2 and #3 must be fast and efficient, because it executes during crucial routines. To read /proc/cpuinfo and parse the contents is much too slow (and I'm not sure the contents are always accurate and up-to-date at any given instant).

NOTE: My application already executes and saves the machine instruction that contains the current clock-cycle, and computes elapsed times in clock cycles based on these counts. This information is also useful, but does not let my application compute elapsed time in nanoseconds (or picoseconds) without a way to determine the frequency (in cps) each core (or at least the current core) is running at each instant.

Thanks!

PS: Do questions like this belong in this forum, or in "software"?
 
Old 12-13-2012, 04:47 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
cat /proc/cpuinfo --- #1.
 
Old 12-14-2012, 02:05 AM   #3
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Original Poster
Rep: Reputation: 17
no workie

Thanks, but that approach is too slow for my purposes. I guess you only read the title of my post, as my original message states /proc/cpuinfo is not fast enough (and may not always produce current information for variable information like cpu frequency).

Quote:
Originally Posted by jv2112 View Post
cat /proc/cpuinfo --- #1.
 
Old 12-14-2012, 05:18 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
That's the only option that you've got, and no, it might not produce up-to-the-bleeem info for real-time situations.

I frankly don't think that your program's "needs" are realistically obtainable. I think you're going to have to find a different algorithm ... not "to obtain the data you're asking for," but rather, "to do without it."
 
Old 12-14-2012, 04:32 PM   #5
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by sundialsvcs View Post
That's the only option that you've got, and no, it might not produce up-to-the-bleeem info for real-time situations.

I frankly don't think that your program's "needs" are realistically obtainable. I think you're going to have to find a different algorithm ... not "to obtain the data you're asking for," but rather, "to do without it."
You are certain? So you are saying there is no programmatic way to access each item of information in /proc/cpuinfo separately? I suppose I can capture and save the cpu-clock-counter AND a time-of-day value each time the function is called, then compute it myself. That would at least get more-and-more accurate as long as the core frequency didn't change recently, and if the core frequency did change since last time, that should at least be detectable (though the core frequency would be a blend of "before the change" and "current frequency".

As far as you know, does your comment also apply to item #3? Is there no way for code to determine which core it is currently executing on?

Also, is #-of-cores stated within the cpuid info somewhere? Otherwise, how is this determined?

Last edited by maxreason; 12-14-2012 at 07:02 PM.
 
Old 12-14-2012, 06:40 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
The data are all available in kernel-space. It is exposed in various ways - /proc/ being one of them. Some of it is not exposed at all.
If the current (user-space) data are insufficient for your needs, you'll need to write your own kernel module - then you can present however you want.
 
  


Reply

Tags
cpu core cps frequency



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
OpenCL : re targeting execution instances from Device Queue to particular Core. barunparichha Linux - Software 4 07-24-2012 04:55 AM
Six-Core AMD Opteron(tm) Processor 8435 only show 2 cores in cpuinfo eltonsky Linux - Hardware 2 03-08-2012 03:12 PM
[SOLVED] SMP kernel not seeing multiple cores/threads for Intel Core i7 870 processor honnefinger Linux - Kernel 10 04-18-2011 11:55 PM
Core dump issues. Program crashes but does not generate core dump file sabeel_ansari Programming 1 10-07-2009 04:23 PM
How to compile a C program in Fedora Core 4 SeniorSE Programming 3 09-13-2005 09:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 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