Sniper simulation of IDLE core state

46 views
Skip to first unread message

Paul Roșu

unread,
Jan 6, 2025, 8:27:53 AMJan 6
to Sniper simulator
Hello,

I am trying to write a core state predictor which should check the core state periodically (IDLE or RUNNING) and do a prediction, and adjust the core frequency such as to optimize the performance and power consumption.
(I have a fork with the core state exported in the Python api, also branch predictor Python hook, see on my github)

The problem is that I am not sure how Sniper is simulating the IDLE state, if it really waits for the thread while it is in idle and if it should mark the core as IDLE while waiting.

To check how it works, I added debug statements in the c++ code wherever I seen any core state updates, then I modified the sniper\test\api to stay idle for one second after doing a small loop:

#include "sim_api.h"

#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>

volatile long long value;

long long loop() {
    volatile int i;
    for (i = 0 ; i < 1000; i++) {
        value += i;
    }

    struct timespec ts;
    ts.tv_sec = 1;
    ts.tv_nsec = 0;
    nanosleep(&ts, NULL);
    asm volatile("mfence");
    return value;
}

int main() {
    SimRoiStart();
    value = 0;
    loop();
    if (SimInSimulator()) {
        printf("API Test: Running in the simulator\n"); fflush(stdout);
    } else {
        printf("API Test: Not running in the simulator\n"); fflush(stdout);
    }
    SimRoiEnd();
}

The run output is this:

../../run-sniper -n 2 -c gainestown --roi -g --api/simple/cores_per_socket=1 -- ./api
[SNIPER] Start
[CORE STATE DEBUG] Core 0 is in IDLE state due to Core constructor default
[CORE STATE DEBUG] Core 1 is in IDLE state due to Core constructor default
[CORE STATE DEBUG] Core 0 is in INITIALIZING state due to createThread
[SNIPER] --------------------------------------------------------------------------------
[SNIPER] Sniper using SIFT/trace-driven frontend
[SNIPER] Running pre-ROI region in  CACHE_ONLY mode
[SNIPER] Running application ROI in DETAILED mode
[SNIPER] Running post-ROI region in FAST_FORWARD mode
[SNIPER] --------------------------------------------------------------------------------
[CORE STATE DEBUG] Core 0 is in RUNNING state due to onThreadStart
[RECORD-TRACE] Using the SDE frontend (sift/recorder)
[SNIPER] Enabling performance models
[SNIPER] Setting instrumentation mode to DETAILED
API Test: Running in the simulator
[SNIPER] Disabling performance models
[SNIPER] Leaving ROI after 1.26 seconds
[SNIPER] Simulated 0.0M instructions, 0.3M cycles, 0.13 IPC
[SNIPER] Simulation speed 27.0 KIPS (13.5 KIPS / target core - 74124.3ns/instr)
[SNIPER] Sampling: executed 15.83% of simulated time in detailed mode
[SNIPER] Setting instrumentation mode to FAST_FORWARD
[TRACE:0] -- DONE --
[CORE STATE DEBUG] Core 0 is in IDLE state due to onThreadExit
[SNIPER] End
[SNIPER] Elapsed time: 4.13 seconds

and in the sim.out I see this:
                                     | Core 0     | Core 1    
  Instructions                       |      13754 |          0
  Cycles                             |     261157 |     261157
  IPC                                |       0.05 |       0.00
  Time (ns)                          |      98179 |      98179
  Idle time (ns)                     |      82628 |      98179
  Idle time (%)                      |      84.2% |     100.0%
Branch predictor stats               |            |          
  num correct                        |       1483 |          0
  num incorrect                      |         46 |          0
  misprediction rate                 |      3.01% |      0.00%
  mpki                               |       3.34 |       0.00
...

It seems the sniper stays in ROI for the expected time.
Also the idle time on core 0 (which executed the instructions) is as expected.

My questions are:
1. why in the sim.out the time is 981ms instead of 1.26s as expected?
2. why the core state is never marked as IDLE while it sleeps inside the ROI?
3. is there a way to achieve my goal with sniper ? (the core state predicting optimization)

I think I have a clue on question 3. as the only places where the core state is set to IDLE are at Core constructor default and in thread_manager createThread, moveThread and onThreadExit.
I cannot find any code path that sets core state to IDLE during thread sleep.

I would appreciate any insights on these behaviors, particularly regarding IDLE state handling during thread sleep.
Reply all
Reply to author
Forward
0 new messages