Previous - Up - Next

4.1   Cycle Handler

The entry to the Micro Architectural Interface is a cycle handler. It is a call-back function that is called every clock cycle and is the location for the user code that models the micro architecture of the processor. The call-back should be placed in a module that can be loaded into Simics (see the Simics User Guide for a detailed description on how to write loadable modules).

The cycle handler can be configured to be called in different ways depending on the machine that will be modeled. If a single processor system or a SMP system is the target (where all the processors are independent) the cycle handler can be set up so that it is called once for each processor during a clock cycle, i.e. the whole first cycle is modeled for the first processor, then the whole first cycle is modeled for the second processor, etc. until all processors have modeled their first cycle, then the second cycle is modeled for the first processor and so on.

If a SMT system should be modeled each thread will be mapped on one Simics processor so that each physical processor will actually consists of a group of Simics processors. One cycle handler should then be used per group since the threads in one group will be dependent and may interact with each other during the same cycle.

An example of how to set up a cycle handler is presented below.


my_cycle_handler(conf_object_t *cpu, void *data)
    // All threads on one CPU is modeled here, cpu will 
    // point the the first thread on each physical CPU.

    // when we are finished we post ourself in the next cycle           
    SIM_time_post_cycle(cpu, 1, 0, my_cycle_handler, data);

static void
setup(void *data)
    /* We set up a multi-processor system with 3 CPUs. 
       Each CPU consists of 2 threads. We need a 6 processor 
       configuration for this to work where, 
       cpu0 and cpu1 are threads on the first physical processor,
       cpu2 and cpu3 are threads on the second physical processor,
       cpu4 and cpu5 are threads on the third physical processor.

                        0, 0, my_cycle_handler, data);
                        0, 0, my_cycle_handler, data);
                        0, 0, my_cycle_handler, data);

/* This code is called when the module is loaded into Simics */
    void *user_data = 0;

    /* We call the setup function as soon as we have a ready 
       configuration */
    if (SIM_initial_configuration_ok())
                                  setup, user_data);


Previous - Up - Next