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 7748775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:52:11+00:00 2026-06-01T10:52:11+00:00

Normally we have to do like this to invoke a function from a function

  • 0

Normally we have to do like this to invoke a function from a function pointer:

int foo()
{
}

int main()
{
    int (*pFoo)() = foo; // pFoo points to function foo()
    foo();
    return 0;
}

In the Linux kernel code, sched_class has many function pointers:

struct sched_class {
        const struct sched_class *next;

        void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
        void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
        void (*yield_task) (struct rq *rq);
        bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
        .....
}

In pick_next_task function, it defines a local instance of sched_class named class, and directly invoke the function in it without assigning to external functions with the same signature (start from for_each_class):

static inline struct task_struct *
pick_next_task(struct rq *rq)
{
        const struct sched_class *class;
        struct task_struct *p;
    /*
     * Optimization: we know that if all tasks are in
     * the fair class we can call that function directly:
     */
    if (likely(rq->nr_running == rq->cfs.h_nr_running)) {
            p = fair_sched_class.pick_next_task(rq);
            if (likely(p))
                    return p;
    }

    for_each_class(class) {
            p = class->pick_next_task(rq);
            if (p)
                    return p;
    }

    BUG(); /* the idle class will always have a runnable task */
}

Is this because each function pointer in the sched_class has the same name as the actual implemented function, so every time a call is made via a function pointer of sched_class, it will automatically find the matching symbol in the kernel address space?

  • 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. Editorial Team
    Editorial Team
    2026-06-01T10:52:13+00:00Added an answer on June 1, 2026 at 10:52 am

    The definition of for_each_class should clear it up for you

     #define for_each_class(class) \
           for (class = sched_class_highest; class; class = class->next)
    

    If you go on tracing, sched_class_highest wil end up something like this

    #define sched_class_highest (&stop_sched_class)
    extern const struct sched_class stop_sched_class;
    
    /*
    * Simple, special scheduling class for the per-CPU stop tasks:
    */
    const struct sched_class stop_sched_class = {
          .next                   = &rt_sched_class,
    
          .enqueue_task           = enqueue_task_stop,
          .dequeue_task           = dequeue_task_stop,
          .yield_task             = yield_task_stop,
    
          .check_preempt_curr     = check_preempt_curr_stop,
    
          .pick_next_task         = pick_next_task_stop,
          .put_prev_task          = put_prev_task_stop,
    
    #ifdef CONFIG_SMP
          .select_task_rq         = select_task_rq_stop,
    #endif
    
         .set_curr_task          = set_curr_task_stop,
         .task_tick              = task_tick_stop,
    
         .get_rr_interval        = get_rr_interval_stop,
    
         .prio_changed           = prio_changed_stop,
         .switched_to            = switched_to_stop,
    };
    

    Now are you happy? 🙂

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

Sidebar

Related Questions

I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools
In WebForms, I would normally have code like this to let the browser present
Normally if I'd like to have an Erlang process timeout I would use the
I have lets say a WeeklyViewUserControl.xaml and a DailyViewUserControl.xaml. Normally I used stuff like
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I have created a BuildProcessTemplate that invokes a custom compiler. This compiler is normally
I have data like this: Task | Hours 1.1 | 40 2 | 40
I have a SQL*Loader control file that has a line something like this: FIELDS
If I have a piece of code that looks like this: - (void)testSomething {
This seems like it should be obvious, but the solution is eluding me. Normally

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.