<div dir="ltr">Great explanation. I feel stupid to miss this :p. Thanks!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 13, 2020 at 9:40 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 Thu, Aug 13, 2020 at 9:28 AM Richi Dubey <<a href="mailto:richidubey@gmail.com" target="_blank">richidubey@gmail.com</a>> wrote:<br>
><br>
> Thanks,<br>
><br>
> But I still can't find the code that links the 'Ready' in this<br>
><br>
> >>  #define RTEMS_SCHEDULER_EDF_SMP( name ) \<br>
> >>      static struct { \<br>
> >>        Scheduler_EDF_SMP_Context Base; \<br>
This 'Base' will be an instance of the struct<br>
Scheduler_EDF_SMP_Context. In memory, it will look like this:<br>
Scheduler_EDF_SMP_Context Base =<br>
the 0-valued array won't actually take any storage.<br>
<br>
> >>        Scheduler_EDF_SMP_Ready_queue Ready[ CONFIGURE_MAXIMUM_PROCESSORS<br>
This<br>
<br>
> >> + 1 ]; \<br>
><br>
In memory this structure will look like this:<br>
{ Scheduler_SMP_Context, int64_t, Chain_Control,<br>
Scheduler_EDF_SMP_Ready_queue[CONFIGURE_MAXIMUM_PROCESSORS + 1] }<br>
Because the Scheduler_EDF_SMP_Context type comes first and provides<br>
{ Scheduler_SMP_Context, int64_t, Chain_Control,<br>
Scheduler_EDF_SMP_Ready_queue[0] } where the last element is a 0-value<br>
array so it doesn't actually take up any memory storage, then the<br>
Scheduler_EDF_SMP_Ready_queue Ready[ CONFIGURE_MAXIMUM_PROCESSORS + 1]<br>
overlaps with the Scheduler_EDF_SMP_Ready_queue[0] because the end of<br>
Base aligns with the start of Ready.<br>
<br>
This is what I meant by you need to review how C struct layout works.<br>
<br>
<br>
<br>
> to the 'Ready' in scheduleredfsmp.h:<br>
><br>
> typedef struct {<br>
>   Scheduler_SMP_Context Base;<br>
><br>
>   /**<br>
>    * @brief Current generation for LIFO (index 0) and FIFO (index 1) ordering.<br>
>    */<br>
>   int64_t generations[ 2 ];<br>
><br>
>   /**<br>
>    * @brief Chain of ready queues with affine threads to determine the highest<br>
>    * priority ready thread.<br>
>    */<br>
>   Chain_Control Affine_queues;<br>
><br>
>   /**<br>
>    * @brief A table with ready queues.<br>
>    *<br>
>    * The index zero queue is used for threads with a one-to-all processor<br>
>    * affinity.  Index one corresponds to processor index zero, and so on.<br>
>    */<br>
>   Scheduler_EDF_SMP_Ready_queue Ready[ RTEMS_ZERO_LENGTH_ARRAY ];<br>
> } Scheduler_EDF_SMP_Context;<br>
><br>
> If I figure this out, everything else would make sense too. Please help me out.<br>
><br>
> On Thu, Aug 13, 2020 at 8:47 PM Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br>
>><br>
>> On Thu, Aug 13, 2020 at 8:34 AM Richi Dubey <<a href="mailto:richidubey@gmail.com" target="_blank">richidubey@gmail.com</a>> wrote:<br>
>> ><br>
>> > Thanks,<br>
>> >  I am assuming this is the code that allocates space:<br>
>> ><br>
>> >>  #define RTEMS_SCHEDULER_EDF_SMP( name ) \<br>
>> >>      static struct { \<br>
>> >>        Scheduler_EDF_SMP_Context Base; \<br>
>> >>        Scheduler_EDF_SMP_Ready_queue Ready[ CONFIGURE_MAXIMUM_PROCESSORS<br>
>> >> + 1 ]; \<br>
>> >>      } SCHEDULER_EDF_SMP_CONTEXT_NAME( name )<br>
>> ><br>
>> This is declaring a structure type that will have a particular format<br>
>> of the struct name.<br>
>><br>
>> ><br>
>> > How do we use or refer to this 'Base'? How do we link this 'Ready' to the 'Ready' inside the EDF_SMP_Context?<br>
>> ><br>
>><br>
>> This stuff gets set up during confdefs step. Eventually the scheduler<br>
>> contexts are instantiated in the scheduler table.<br>
>><br>
>> confdefs/scheduler.h:<br>
>>     #define CONFIGURE_SCHEDULER RTEMS_SCHEDULER_EDF_SMP( dflt )<br>
>><br>
>>     #define CONFIGURE_SCHEDULER_TABLE_ENTRIES \<br>
>>       RTEMS_SCHEDULER_TABLE_EDF_SMP( dflt, CONFIGURE_SCHEDULER_NAME )<br>
>> ....<br>
>> const Scheduler_Control _Scheduler_Table[] = {<br>
>>   CONFIGURE_SCHEDULER_TABLE_ENTRIES<br>
>> };<br>
>><br>
>> This is where the space actually gets allocated, based on how<br>
>> CONFIGURE_SCHEDULER_TABLE_ENTRIES gets defined up to here from the CPP<br>
>> macros.<br>
>><br>
>><br>
>><br>
>> > On Thu, Aug 13, 2020 at 6:17 PM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a>> wrote:<br>
>> > ><br>
>> > > On 13/08/2020 14:42, Richi Dubey wrote:<br>
>> > ><br>
>> > > > I want to use arrays with size _CONFIGURE_MAXIMUM_PROCESSORS. Is it<br>
>> > > > okay if I define the arrays with this size while writing the scheduler<br>
>> > > > strong APA header file? I am asking this because the value of this<br>
>> > > > header gets defined at the time the test case runs while the scheduler<br>
>> > > > gets linked to the test case at the time of linking. So how would it<br>
>> > > > work?<br>
>> > ><br>
>> > > Do NOT use _CONFIGURE_MAXIMUM_PROCESSORS.<br>
>> > ><br>
>> > > In <rtems/scheduler.h> please use something similar to the EDF scheduler<br>
>> > > instantiation:<br>
>> > ><br>
>> > > #ifdef CONFIGURE_SCHEDULER_EDF_SMP<br>
>> > >    #include <rtems/score/scheduleredfsmp.h><br>
>> > ><br>
>> > >    #ifndef CONFIGURE_MAXIMUM_PROCESSORS<br>
>> > >      #error "CONFIGURE_MAXIMUM_PROCESSORS must be defined to configure<br>
>> > > the EDF SMP scheduler"<br>
>> > >    #endif<br>
>> > ><br>
>> > >    #define SCHEDULER_EDF_SMP_CONTEXT_NAME( name ) \<br>
>> > >      SCHEDULER_CONTEXT_NAME( EDF_SMP_ ## name )<br>
>> > ><br>
>> > >    #define RTEMS_SCHEDULER_EDF_SMP( name ) \<br>
>> > >      static struct { \<br>
>> > >        Scheduler_EDF_SMP_Context Base; \<br>
>> > >        Scheduler_EDF_SMP_Ready_queue Ready[ CONFIGURE_MAXIMUM_PROCESSORS<br>
>> > > + 1 ]; \<br>
>> > >      } SCHEDULER_EDF_SMP_CONTEXT_NAME( name )<br>
>> > ><br>
>> > >    #define RTEMS_SCHEDULER_TABLE_EDF_SMP( name, obj_name ) \<br>
>> > >      { \<br>
>> > >        &SCHEDULER_EDF_SMP_CONTEXT_NAME( name ).Base.Base.Base, \<br>
>> > >        SCHEDULER_EDF_SMP_ENTRY_POINTS, \<br>
>> > >        SCHEDULER_EDF_MAXIMUM_PRIORITY, \<br>
>> > >        ( obj_name ) \<br>
>> > >        SCHEDULER_CONTROL_IS_NON_PREEMPT_MODE_SUPPORTED( false ) \<br>
>> > >      }<br>
>> > ><br>
>> > >    /* Provided for backward compatibility */<br>
>> > ><br>
>> > >    #define RTEMS_SCHEDULER_CONTEXT_EDF_SMP( name, max_cpu_count ) \<br>
>> > >      RTEMS_SCHEDULER_EDF_SMP( name )<br>
>> > ><br>
>> > >    #define RTEMS_SCHEDULER_CONTROL_EDF_SMP( name, obj_name ) \<br>
>> > >      RTEMS_SCHEDULER_TABLE_EDF_SMP( name, obj_name )<br>
>> > > #endif<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>