Need help understanding the function Scheduler_SMP_Allocate_processor_lazy

Richi Dubey richidubey at gmail.com
Sun Jun 21 16:38:36 UTC 2020


Hi,

I'm sorry, I did not! Thanks for the suggestions. I'll go through its
calling functions, and the functions it calls.



On Sat, Jun 20, 2020 at 7:51 PM Gedare Bloom <gedare at rtems.org> wrote:

> On Sat, Jun 20, 2020 at 6:12 AM Richi Dubey <richidubey at gmail.com> wrote:
> >
> > Hi,
> >
> > I've been learning how SMP scheduler word in RTEMS and I came across the
> following function definition:
> >
> --------------------------------------------------------------------------------------------
> >
> > /**
> >  * @brief Allocates the cpu for the scheduled thread.
> >  *
> >  * Attempts to prevent migrations but does not take into account
> affinity.
> >  *
> >  * @param context The scheduler context instance.
> >  * @param scheduled The scheduled node that should be executed next.
> >  * @param victim If the heir is this node's thread, no processor is
> allocated.
> >  * @param[in, out] victim_cpu The cpu to allocate.
> >  */
> >
> >  static inline void _Scheduler_SMP_Allocate_processor_lazy(
> >   Scheduler_Context *context,
> >   Scheduler_Node    *scheduled,
> >   Scheduler_Node    *victim,
> >   Per_CPU_Control   *victim_cpu
> > )
> > {
> >   Thread_Control *scheduled_thread = _Scheduler_Node_get_user( scheduled
> );
> >   Thread_Control *victim_thread = _Scheduler_Node_get_user( victim );
> >   Per_CPU_Control *scheduled_cpu = _Thread_Get_CPU( scheduled_thread );
> >   Per_CPU_Control *cpu_self = _Per_CPU_Get();
> >   Thread_Control *heir;
> >
> >   _Assert( _ISR_Get_level() != 0 );
> >
> >   if ( _Thread_Is_executing_on_a_processor( scheduled_thread ) ) {
> >     if ( _Scheduler_SMP_Is_processor_owned_by_us( context, scheduled_cpu
> ) ) {
> >       heir = scheduled_cpu->heir;
> >       _Thread_Dispatch_update_heir(
> >         cpu_self,
> >         scheduled_cpu,
> >         scheduled_thread
> >       );
> >     } else {
> >       /* We have to force a migration to our processor set */
> >       heir = scheduled_thread;
> >     }
> >   } else {
> >     heir = scheduled_thread;
> >   }
> >
> >   if ( heir != victim_thread ) {
> >     _Thread_Set_CPU( heir, victim_cpu );
> >     _Thread_Dispatch_update_heir( cpu_self, victim_cpu, heir );
> >   }
> > }
> >
> >
> >
> --------------------------------------------------------------------------------
> > Can someone please help me understand what this function is trying to do
> and how exactly it is achieving that?  I am finding it hard to understand
> the meaning and use of the terms like cpu_self (why do we need cpu_self ?
> Is it the CPU for scheduled or for victim?),
> _Thread_Is_executing_on_a_processor( scheduled_thread ): Why would we have
> the thread already executing when we need to allocate a processor to it?
> Why are we allocating a processor then?
> >
>
> Have you looked at how the function gets called/used? Or more
> importantly, when it gets called?
>
> you see cpu_self = Per_CPU_Get();
> Have you looked at that function to see what it does yet? Does it need
> better documentation/doxygen?
>
> > Thanks,
> > Richi.
> >
> > _______________________________________________
> > devel mailing list
> > devel at rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20200621/22df5f92/attachment.html>


More information about the devel mailing list