intel / intel-cmt-cat

User space software for Intel(R) Resource Director Technology
http://www.intel.com/content/www/us/en/architecture-and-technology/resource-director-technology.html
Other
685 stars 180 forks source link

Why setting COS through code APIs is invalid? #245

Closed K1ngRay closed 1 year ago

K1ngRay commented 1 year ago

Firstly, call the API in the code to set COS and print it out, and the displayed result is correct.

`int main(){

struct pqos_config cfg;
const struct pqos_cpuinfo *p_cpu = NULL;
const struct pqos_cap *p_cap = NULL;
unsigned int l3cat_id_count, *p_l3cat_ids = NULL;
int ret, exit_val = EXIT_SUCCESS;
memset(&cfg, 0, sizeof(cfg));
cfg.fd_log = STDOUT_FILENO;
cfg.verbose = 0;
//  init
ret = pqos_init(&cfg);
if (ret != PQOS_RETVAL_OK)
{
    printf("Error initializing PQoS library!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

//  get pointers of cap and cpu
ret = pqos_cap_get(&p_cap, &p_cpu);
if (ret != PQOS_RETVAL_OK)
{
    printf("Error retrieving PQoS capabilities!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

// get ids and count of l3 cache
p_l3cat_ids = pqos_cpu_get_l3cat_ids(p_cpu, &l3cat_id_count);
if (p_l3cat_ids == NULL)
{
    printf("Error retrieving CPU socket information!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

// set cos table
struct pqos_l3ca sel_l3ca_cos_tab[PQOS_MAX_L3CA_COS];
memset(sel_l3ca_cos_tab, 0, sizeof(pqos_l3ca) * PQOS_MAX_L3CA_COS);
// E5 v4 has 20 ways of cache, with the first first 0 to 14 cos configured to share access to 19 ways 
// and the 16th cos configured to access 1 way separately
for (int i = 0; i < PQOS_MAX_L3CA_COS; i++)
{
    sel_l3ca_cos_tab[i].class_id = i; 
    if (i < PQOS_MAX_L3CA_COS - 1)
        sel_l3ca_cos_tab[i].u.ways_mask = 0xffffe;
    else sel_l3ca_cos_tab[i].u.ways_mask = 0x1;
}

// set cos
for (int i = 0; i < l3cat_id_count; i++)
{
    ret = pqos_l3ca_set(p_l3cat_ids[i], PQOS_MAX_L3CA_COS, sel_l3ca_cos_tab);
    if (ret != PQOS_RETVAL_OK)
    {
        printf("Allocation configuration error!\n");
        goto error_exit;
    }
    printf("Allocation configuration altered.\n");
}

// print result
ret = print_allocation_config(l3cat_id_count, p_l3cat_ids);
if (ret != PQOS_RETVAL_OK)
{
    printf("Allocation capability not detected!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}
error_exit:
// reset and deallocate all the resources
ret = pqos_fini();
if (ret != PQOS_RETVAL_OK)
    printf("Error shutting down PQoS library!\n");
if (p_l3cat_ids != NULL)
    free(p_l3cat_ids);
return exit_val;

}`

`int print_allocation_config(const unsigned l3cat_id_count, const unsigned *l3cat_ids){

int ret = PQOS_RETVAL_OK;
unsigned i;
for (i = 0; i < l3cat_id_count; i++)
{
    struct pqos_l3ca tab[PQOS_MAX_L3CA_COS];
    unsigned num = 0;

    ret = pqos_l3ca_get(l3cat_ids[i], PQOS_MAX_L3CA_COS, &num, tab);
    if (ret == PQOS_RETVAL_OK)
    {
        unsigned n = 0;

        printf("L3CA COS definitions for Socket %u:\n",
               l3cat_ids[i]);
        for (n = 0; n < num; n++)
        {
            printf("    L3CA COS%u => MASK 0x%llx\n",
                   tab[n].class_id,
                   (unsigned long long)tab[n].u.ways_mask);
        }
    }
    else
    {
        printf("Error:%d", ret);
        return ret;
    }
}
return ret;

}` image

But when I used pqos - s, the result of displaying cos did not change, and all cos masks were default 0xfffff. Why is this? image

Interestingly, when I modify code to only print cos later, the result was indeed the one I set last time. `int main(){

struct pqos_config cfg;
const struct pqos_cpuinfo *p_cpu = NULL;
const struct pqos_cap *p_cap = NULL;
unsigned int l3cat_id_count, *p_l3cat_ids = NULL;
int ret, exit_val = EXIT_SUCCESS;
memset(&cfg, 0, sizeof(cfg));
cfg.fd_log = STDOUT_FILENO;
cfg.verbose = 0;
//  init
ret = pqos_init(&cfg);
if (ret != PQOS_RETVAL_OK)
{
    printf("Error initializing PQoS library!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

//  get pointers of cap and cpu
ret = pqos_cap_get(&p_cap, &p_cpu);
if (ret != PQOS_RETVAL_OK)
{
    printf("Error retrieving PQoS capabilities!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

// get ids and count of l3 cache
p_l3cat_ids = pqos_cpu_get_l3cat_ids(p_cpu, &l3cat_id_count);
if (p_l3cat_ids == NULL)
{
    printf("Error retrieving CPU socket information!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}

// print result
ret = print_allocation_config(l3cat_id_count, p_l3cat_ids);
if (ret != PQOS_RETVAL_OK)
{
    printf("Allocation capability not detected!\n");
    exit_val = EXIT_FAILURE;
    goto error_exit;
}
error_exit:
// reset and deallocate all the resources
ret = pqos_fini();
if (ret != PQOS_RETVAL_OK)
    printf("Error shutting down PQoS library!\n");
if (p_l3cat_ids != NULL)
    free(p_l3cat_ids);
return exit_val;

}` image

So did I successfully modify it?

aleksinx commented 1 year ago

You should not mix interfaces

  1. In the code you initialize library using MSR interface
  2. pqos -s uses OS interface is avaialble. To use msr interface with pqos command please use --iface=msr parameter

Regards Michał

K1ngRay commented 1 year ago

You should not mix interfaces

  1. In the code you initialize library using MSR interface
  2. pqos -s uses OS interface is avaialble. To use msr interface with pqos command please use --iface=msr parameter

Regards Michał

Thank you!