<div dir="ltr">Hi,<div><br></div><div>I'm sorry, I did not! Thanks for the suggestions. I'll go through its calling functions, and the functions it calls.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 20, 2020 at 7:51 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, Jun 20, 2020 at 6:12 AM Richi Dubey <<a href="mailto:richidubey@gmail.com" target="_blank">richidubey@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I've been learning how SMP scheduler word in RTEMS and I came across the following function definition:<br>
> --------------------------------------------------------------------------------------------<br>
><br>
> /**<br>
>  * @brief Allocates the cpu for the scheduled thread.<br>
>  *<br>
>  * Attempts to prevent migrations but does not take into account affinity.<br>
>  *<br>
>  * @param context The scheduler context instance.<br>
>  * @param scheduled The scheduled node that should be executed next.<br>
>  * @param victim If the heir is this node's thread, no processor is allocated.<br>
>  * @param[in, out] victim_cpu The cpu to allocate.<br>
>  */<br>
><br>
>  static inline void _Scheduler_SMP_Allocate_processor_lazy(<br>
>   Scheduler_Context *context,<br>
>   Scheduler_Node    *scheduled,<br>
>   Scheduler_Node    *victim,<br>
>   Per_CPU_Control   *victim_cpu<br>
> )<br>
> {<br>
>   Thread_Control *scheduled_thread = _Scheduler_Node_get_user( scheduled );<br>
>   Thread_Control *victim_thread = _Scheduler_Node_get_user( victim );<br>
>   Per_CPU_Control *scheduled_cpu = _Thread_Get_CPU( scheduled_thread );<br>
>   Per_CPU_Control *cpu_self = _Per_CPU_Get();<br>
>   Thread_Control *heir;<br>
><br>
>   _Assert( _ISR_Get_level() != 0 );<br>
><br>
>   if ( _Thread_Is_executing_on_a_processor( scheduled_thread ) ) {<br>
>     if ( _Scheduler_SMP_Is_processor_owned_by_us( context, scheduled_cpu ) ) {<br>
>       heir = scheduled_cpu->heir;<br>
>       _Thread_Dispatch_update_heir(<br>
>         cpu_self,<br>
>         scheduled_cpu,<br>
>         scheduled_thread<br>
>       );<br>
>     } else {<br>
>       /* We have to force a migration to our processor set */<br>
>       heir = scheduled_thread;<br>
>     }<br>
>   } else {<br>
>     heir = scheduled_thread;<br>
>   }<br>
><br>
>   if ( heir != victim_thread ) {<br>
>     _Thread_Set_CPU( heir, victim_cpu );<br>
>     _Thread_Dispatch_update_heir( cpu_self, victim_cpu, heir );<br>
>   }<br>
> }<br>
><br>
><br>
> --------------------------------------------------------------------------------<br>
> 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?<br>
><br>
<br>
Have you looked at how the function gets called/used? Or more<br>
importantly, when it gets called?<br>
<br>
you see cpu_self = Per_CPU_Get();<br>
Have you looked at that function to see what it does yet? Does it need<br>
better documentation/doxygen?<br>
<br>
> Thanks,<br>
> Richi.<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>