3 Replies - 848 Views - Last Post: 03 July 2013 - 11:10 AM Rate Topic: -----

#1 IneptCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-June 13

Using a function (sched_getcpu) with glibc-2.5

Posted 28 June 2013 - 05:22 AM

Hello,

So this software I am working with was coded using a computer with the glibc 2.12 library, but I have to make it run with glibc-2.5. So far the only problem I have found when compiling is that the software uses the sched_getcpu() function. But, I looked it up and apparently sched_getcpu() has only been available since glibc-2.6. So, I need an alternate function/solution that does the same thing as sched_getcpu(). Is there an alternate pre-glibc-2.6 equivalent function I could use? I was also thinking of trying to find the code for the function online and trying to write an equivalent...but I am fairly new to coding/programming(is there a diff?) and the stuff I am finding is making little sense(I am finding stuff on macros which I have no exp. with)...I am still searching but any help would be much appreciated.

On a side note, I think I understand static vs. dynamic libraries and why they would be useful, but I do not know what these libraries are when coding. How can I tell if the library I am using is static or dynamic? and are the glibc libraries static or dynamic? This is important because another option I was thinking about would be to upgrade to a recent glibc library, but if I do that and it turns out glibc is dynamic then I would have to uprgrade evry system this software is supposed to run on (they are all glibc 2.5) because using dynamic libraries would make the software dependent on the local system libraries (right?).

Again, I am new to this so sorry if my questions don't make much sense.

Is This A Good Question/Topic? 0
  • +

Replies To: Using a function (sched_getcpu) with glibc-2.5

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,461
  • Joined: 05-May 12

Re: Using a function (sched_getcpu) with glibc-2.5

Posted 28 June 2013 - 05:34 AM

From the sched_getcpu() manual page at: http://man7.org/linu...d_getcpu.3.html

Quote

NOTES

The call
           cpu = sched_getcpu();


is equivalent to the following getcpu(2) call:
           int c, s;
           s = getcpu(&c, NULL, NULL);
           cpu = (s == -1) ? s : c;


Was This Post Helpful? 1
  • +
  • -

#3 IneptCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-June 13

Re: Using a function (sched_getcpu) with glibc-2.5

Posted 03 July 2013 - 10:44 AM

Sorry I took so long to reply, I've looked at that avenue and it doesn't look like an option because the man pages also say:
"getcpu() was added in kernel 2.6.19 for x86_64 and i386." The kernel on these computers are version 2.6.18. Also,
I am not exactly sure what get_cpu(or sched_getcpu) does so I don't know how I would go about hard coding it into my
program. It looks like it is supposed to return the processor that the current task is running on but I am not %100
sure and if that is the case then it is a call to the system and I don't know how to prgram system calls or if thats
even a realistic solution.
Was This Post Helpful? 0
  • +
  • -

#4 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 687
  • View blog
  • Posts: 2,376
  • Joined: 31-December 10

Re: Using a function (sched_getcpu) with glibc-2.5

Posted 03 July 2013 - 11:10 AM

View PostIneptCoder, on 28 June 2013 - 08:22 AM, said:

Hello,

So this software I am working with was coded using a computer with the glibc 2.12 library, but I have to make it run with glibc-2.5. So far the only problem I have found when compiling is that the software uses the sched_getcpu() function. But, I looked it up and apparently sched_getcpu() has only been available since glibc-2.6.

How is it that the codebase uses glibc 2.12 and sched_getcpu() but somehow it wasn't introduced until glibc 2.6?

*EDIT*: From what I read, you need to use the feature test macro to get the functionality you desire. All you need to do is define a certain macro before you include the header file. http://man7.org/linu...d_getcpu.3.html

#define _GNU_SOURCE
#include <sched.h>


This post has been edited by vividexstance: 03 July 2013 - 11:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1