Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 187051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:45:18+00:00 2026-05-11T15:45:18+00:00

I am trying to understand how the linux syscall sched_setaffinity() works. This is a

  • 0

I am trying to understand how the linux syscall sched_setaffinity() works. This is a follow-on from my question here.

I have this guide, which explains how to use the syscall and has a pretty neat (working!) example.

So I downloaded the Linux 2.6.27.19 kernel sources.

I did a ‘grep’ for lines containing that syscall, and I got 91 results. Not promising.

Ultimately, I’m trying to understand how the kernel is able to set the instruction pointer for a specific core (or processor.)

I am familiar with how single-core-single-thread programs work. One might issue a ‘jmp foo’ instruction, and this basically sets the IP to the memory address of the ‘foo’ label. But when one has multiple cores, one has to say ‘fetch the next instruction at memory address foo, and set the instruction pointer for core number 2 to begin execution there.’

Where, in the assembly code, are we specifying which core performs that operation?

Back to the kernel code: what is important here? The file ‘kernel/sched.c’ has a function called sched_setaffinity(), but returns type ‘long’ – which is inconsistent with its manual page. So what is important here? Which of these modules shows the assembly instructions issued? What module is reading the ‘task_struct’, looking at the ‘cpus_allowed’ member, and then translating that into an instruction? (I’ve also thumbed through the glibc source – but I think it just makes a call to the kernel code to accomplish this task.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:45:19+00:00Added an answer on May 11, 2026 at 3:45 pm

    sched_setaffinity() simply tells the scheduler which CPUs is that process/thread allowed to run on, then calls for a re-schedule.

    The scheduler actually runs on each one of the CPUs, so it gets a chance to decide what task to execute next on that particular CPU.

    If you’re interested in how you can actually call some code on other CPUs, I suggest you take a look at smp_call_function_single(). In case we want to call something on another CPU, this calls generic_exec_single(). The latter simply adds the function to the target CPU’s call queue and forces a reschedule through some IPI stuff (if the queue was empty).

    Bottom line is: there no actual SMP variant of the _jmp_ instruction. Instead, code running on other CPUs cooperates in order to accomplish the task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems the simplest solution I could use was to add… May 11, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer I am using the WPF Localization Extension. It is a… May 11, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer Javascript: var today = new Date(); alert( today.getTimezoneOffset() ); This… May 11, 2026 at 5:06 pm

Related Questions

I am trying to understand if I really have any case for using git/mercurial.
In the installation documentation to RoR it mentions that there are many limitations to
I can understand how one can write a program that uses multiple processes or
I am trying to install a Java application on my Linux machine (Slackware). I
I need to run Perl applications I develop on cygwin Windows on HP unix

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.