function test_pal_get_logical_core_ids

From liblfds.org
Jump to navigation Jump to search

Source Files

└───test
    └───src
        └───porting_abstraction_layer_get_logical_core_ids.c

Structures

struct test_pal_logical_processor
{
  lfds711_pal_uint_t
    logical_processor_number,
    windows_logical_processor_group_number;

  struct lfds711_list_asu_element
    lasue;
};

Prototype

void test_pal_get_logical_core_ids( struct lfds711_list_asu_state *lasus );

Parameters

struct lfds711_list_asu_state *lasus

A pointer to an allocated, initialized, but empty List (add-only, singly-linked, unordered).

Return Value

The return value is 1 if the thread has been successfully created, 0 otherwise.

Notes

The function iterates over the logical cores present in the system, where each logical core is expected to have a unique integer ID, and for each unique ID, allocates a list element, a struct test_pal_logical_processor, populates it and links it to the list. The ordering of elements in the list does not matter. The test programme when it finished and cleans up will pass each element in the list to free, so it is necessary one malloc is performed per element, or it'll all end in tears.

Example

void test_pal_get_logical_core_ids( struct lfds711_list_asu_state *lasus )
{
  char
    diskbuffer[BUFSIZ],
    string[1024];

  FILE
    *diskfile;

  int long long unsigned
    logical_processor_number;

  struct lfds711_misc_prng_state
    ps;

  struct test_pal_logical_processor
    *lp;

  assert( lasus != NULL );

  lfds711_misc_prng_init( &ps );

  lfds711_list_asu_init_valid_on_current_logical_core( lasus, NULL, NULL );

  *number_logical_processors = 0;

  diskfile = fopen( "/proc/cpuinfo", "r" );

  if( diskfile != NULL )
  {
    setbuf( diskfile, diskbuffer );

    while( NULL != fgets(string, 1024, diskfile) )
      if( 1 == sscanf(string, "processor : %llu", &logical_processor_number) )
      {
        lp = malloc( sizeof(struct test_pal_logical_processor) );

        lp->logical_processor_number = (lfds711_pal_uint_t) logical_processor_number;
        lp->windows_logical_processor_group_number = 0;

        LFDS711_LIST_ASU_SET_VALUE_IN_ELEMENT( lp->lasue, lp );
        lfds711_list_asu_link_start( lasus, &lp->lasue, &ps );
      }

    fclose( diskfile );
  }

  return;
}

See Also