How do I keep a function in cache all the time in CPP?

at present, there is a function in a high-performance module in the project, which needs to be saved in cache all the time. A large number of other non-high-performance operations may be called during the execution of this function. The test result with rdtscp instruction shows that the performance of calling main_task for 10 times in a row is 10 times faster than that of executing some_task+main_task function, which should be the problem of cache miss.

remarks: linux system (centos)

the test sample code is as follows:

-sharpinclude <cmath>
-sharpinclude <ctime>
-sharpinclude <cstdlib>
-sharpinclude <iostream>
using namespace std;

static int datas[2 * 60 * 80 * 40];
static const int data_size = sizeof(datas) / sizeof(int);

void some_task()
{
        for (size_t i = 0; i < data_size * 60; PPi)
        {
            const int index = abs(rand()) % data_size;
            datas[index] = static_cast<int>(log(static_cast<double>(abs(rand()) + 1)));
        }
}

void main_task()
{
    /* ...do something... */
}

int main()
{
    for (size_t i = 0; i < 10; PPi)
    {
        some_task();
                /* start_time rdtscp */
        main_task();
                /* end_time rdtscp */
    }
}
Menu