'real-time content in L1 CPU cache

I am interested in memory bottleneck, and trying to figure out when variables are loaded into L1 data cache.

Is there any helpful tool to monitor the content in L1 cache? I want to know whether a varaible has been cached or not.

For example, here's simple funtion:

void fun(){
    char c1_loc='a';
    int i_loc=1;

    char c2_loc='b';
    double d_loc=2;

    char c3_loc='c';
    float f_loc=3;

    char c4_loc='d';
    short s_loc=4;
}

memory layout of this function:
memory layout of this function

I could get memory layout of the function with GDB, but how could I know which variables are in the same cache-line? In other words, I want to know from where cache-line start to load.

My machine is Intel-Core-I7-10710U, and the L1 data cache is 32KB, cacheline is 64B.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source