FastFlow  SVN-r182-Aug-14-2014
A high-level, lock-less, parallel programming (shared-memory) and distributed programming (distributed-memory) framework for multi-cores and many-cores systems
 All Classes Namespaces Files Functions Variables Typedefs Groups Pages
Functions
mapping_utils.hpp File Reference

This file contains utilities for thread pinning to cores and thread mapping. More...

#include <iostream>
#include <errno.h>
#include <ff/config.hpp>
#include <stddef.h>
+ Include dependency graph for mapping_utils.hpp:
+ This graph shows which files directly or indirectly include this file:

Functions

static long ff_getThreadID ()
 Returns the ID of the calling thread. More...
 
static unsigned long ff_getCpuFreq ()
 Returnes the frequency of the CPU. More...
 
static int ff_numCores ()
 Returns the number of cores in the system. More...
 
static int ff_realNumCores ()
 Returns the real number of cores in the system without considering HT or HMT. More...
 
static int ff_numSockets ()
 Returns the number of CPUs (physical sockets) on the system. More...
 
static int ff_setPriority (int priority_level=0)
 Sets the scheduling priority. More...
 
static int ff_getMyCore ()
 Returns the ID of the core. More...
 
static int ff_mapThreadToCpu (int cpu_id, int priority_level=0)
 Maps the calling thread to the given CPU. More...
 

Detailed Description

This file contains utilities for thread pinning to cores and thread mapping.

This file provides support for thread pinning and mapping at linux and MacOS.

Function Documentation

static unsigned long ff_getCpuFreq ( )
inlinestatic

Returnes the frequency of the CPU.

It returns the frequency of the CPUs (On a shared memory system, all cores have the same frequency). It works on Linux OS and Apple OS.

Returns
An integer value showing the frequency of the core.
static int ff_getMyCore ( )
inlinestatic

Returns the ID of the core.

It returns the ID of the core where the calling thread is running. It works on Linux OS and Apple OS.

Returns
An integer value showing the ID of the core. If the ID of the core is not found, then -1 is returned.
static long ff_getThreadID ( )
inlinestatic

Returns the ID of the calling thread.

It returns the ID of the calling thread. It works on Linux OS, Apple OS, Windows.

Returns
if successful the identifier of the thread is returned. Otherwise a negative vlue is returned.
Examples:
parfor_basic.cpp.
static int ff_mapThreadToCpu ( int  cpu_id,
int  priority_level = 0 
)
inlinestatic

Maps the calling thread to the given CPU.

It maps the calling thread to the given core. It works on Linux OS, Apple OS, Windows.

Parameters
cpu_idthe ID of the CPU to which the thread will be attached.
priority_levelTODO
Returns
An integet value showing the priority level is returned if successful. Otherwise EINVAL is returned.
Examples:
perf_test_alloc1.cpp, and perf_test_alloc2.cpp.

References ff_numCores(), and ff_setPriority().

static int ff_numCores ( )
inlinestatic

Returns the number of cores in the system.

It returns the number of cores present in the system. (Note that it does take into account hyperthreading). It works on Linux OS, Apple OS and Windows.

Returns
An integer value showing the number of cores.
static int ff_numSockets ( )
inlinestatic

Returns the number of CPUs (physical sockets) on the system.

It returns the number physical sockets on the system. It works on Linux OS.

Returns
An integer value showing the number of sockets.
static int ff_realNumCores ( )
inlinestatic

Returns the real number of cores in the system without considering HT or HMT.

It returns the number of cores present in the system. It works on Linux OS

Returns
An integer value showing the number of cores.
static int ff_setPriority ( int  priority_level = 0)
inlinestatic

Sets the scheduling priority.

It sets the scheduling priority of the process (or thread). The priority_level is a value in the range -20 to 19. The default priority is 0, lower priorities cause more favorable scheduling.

MA: This should be redesigned since it might have different behaviours in different systems.

priority_level defines the level of the priority. Default is set to 0.

Returns
An integer value showing the priority of the scheduling policy.