My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
OpenPgmCReferenceRunWithTheseCapabilities  
OpenPGM C Reference : Run With These Capabilities
Phase-Implementation
Updated Oct 6, 2011 by fnjo...@gmail.com

Capabilities

OpenPGM C programs require system capabilities from this list in order to function.

System Capability Description

Communications and Events

CAP_NET_RAW To create raw sockets required for the PGM protocol.
CAP_SYS_NICE To set real time thread scheduling and high thread priority for processing incoming messages and high resolution timing.

HPET*

access to /dev/hpet The High Performance Event Timer provides a system wide stable monotonic timer. Default access on Ubuntu is root only.

Real-time Clock*

access to /dev/rtc For TSC calibration with the hardware real-time clock access to the rtc device can be enabled by adding the user to the real-time Unix group, on Ubuntu this is called audio.

* Clock selection is specified by two system environment variables PGM_TIMER governing how to get the current time, and PGM_SLEEP governing how to wait for an interval of time.

Clock Selection

Kernel timer resolution is in a period of change, kernels can be found with standard resolutions of 1-4ms, with high resolution timers providing microsecond to nanosecond resolution. RDTSC is a very cheap mechanism for applications to get the current time in high resolution, however multiple core systems may suffer from drift between each core, some systems may vary frequency in power saving states. Particularly prone to error are Hyperthread based processors from Intel, it is highly recommended to disable hyperthreading on all processors wishing to run high speed PGM based messaging. The High Precision Event Timer, HPET, was created to provide a system wide stable timer in multi-core systems to resolve TSC irregularities.

An operating system calculates the current time of day based off various sources to provide an accurate, stable, and monotonic source to applications. On Linux the system time is generated from the APIC PM Timer or HPET with interpolation using TSC which can cause the time to become non-monotonic. Calculating a stable system time is not cheap and historically many applications have been re-engineered to minimise the calls to functions like gettimeofday() due to this overhead, using RDTSC has been a popular method to bypass this overhead, with multi-core systems either process affinity has to be used to keep using the same TSC source, or reading from the HPET device instead but at a ~500 nanosecond cost.

The RTC device /dev/rtc cannot be shared between multiple applications but offers a stable time source external to the TSC and is available on all systems, compared with limited availability of HPET.

On Linux TSC is calibrated using the details provided by the kernel in /proc/cpuinfo which is ratio calculated at boot time. By default TSC will be calibrated by the method defined by PGM_SLEEP, and either value can be overridden by defining RDTSC_FREQUENCY in kilohertz. It is recommended to set this frequency or use an alternative timing mechanism on Solaris.

Environment Setting Description

PGM_TIMER

CLOCK_GETTIME Use clock_gettime (CLOCK_MONOTONIC, tp), see CLOCK_GETRES(3) for further details.
FTIME Use ftime (tp), see ftime(3) for further details. Windows resolution is limited to 10-16ms.
RTC Read from /dev/rtc for current time, a 8192 Hz timer providing 122us resolution.
TSC* Call RDTSC and normalize with a RTC calibrated count of core ticks. On Windows uses the APIC PM timer or HPET timer via QueryPerformanceCounter.
HPET Read from the HPET device which handles femtosecond length pulses.
GETTIMEOFDAY* Use gettimeofday (tv, NULL), see gettimeofday(2) for further details.
MMTIME* Use Windows multi-media timers, lower resolution than other timers but offers greater stability and low cost for frequent usage.
QPC Use Windows Performance Counters, dependent upon accurate drivers and suitable "BIOS support" per the word of MSDN. Windows selects the "best" underlying hardware timing mechanism to use, can be a combination of APIC, HPET and TSC for interpolation.

PGM_SLEEP

CLOCK_NANOSLEEP Use clock_nanosleep (clk_id, TIMER_ABSTIME, tp, NULL), see clock_nanoslepe(2) for further details.
NANO_SLEEP Use nanosleep (tp, rem), see nanosleep(2) for further details.
RTC Read interrupts from /dev/rtc until requested time has elapsed.
TSC Repeatedly call RDTSC interleaving with g_thread_yield() to allow other threads to execute.
HPET Repeatedly read from the HPET interleaving with g_thread_yield() to allow other threads to execute.
PPOLL Use ppoll (usec), see ppoll(2) for further details.
USLEEP* or MICROSLEEP Use usleep (usec), see usleep(3) for further details.
MSLEEP* Use Sleep (msec), see Sleep for further details.
SELECT Use select (usec), see select(2) for further details.

* Default settings. Removed in OpenPGM version 3.0.

Examples

Use the PGM protocol via raw sockets using the CAP_NET_RAW capability,

$ sudo execcap 'cap_net_raw=ep' pgmsend moo

On a single core Intel system, use TSC and usleep.

$ PGM_TIMER=TSC PGM_SLEEP=USLEEP pgmsend moo

or,

$ pgmsend moo

On a multi-core Intel system with HPET device, use HPET and usleep.

$ sudo chmod a+r /dev/hpet
$ PGM_TIMER=HPET PGM_SLEEP=USLEEP pgmsend moo

or,

$ sudo chmod a+r /dev/hpet
$ PGM_TIMER=HPET pgmsend moo

On a hyper-threaded Intel system without HPET device, use the RTC device and usleep.

$ PGM_TIMER=RTC PGM_SLEEP=USLEEP pgmsend moo

or,

$ PGM_TIMER=RTC pgmsend moo

On a multi-core system without HPET and for multiple applications, use gettimeofday and usleep.

$ PGM_TIMER=GTOD PGM_SLEEP=USLEEP pgmsend moo

or,

$ PGM_TIMER=GTOD pgmsend moo

On a Windows system, use the system performance counter and Sleep.

C:\pgm\bin> set PGM_TIMER=TSC
C:\pgm\bin> set PGM_SLEEP=MSLEEP
C:\pgm\bin> pgmsend moo

or,

C:\pgm\bin> pgmsend moo

On a Solaris system with a 3.2Ghz core, set the TSC frequency first.

$ RDTSC_FREQUENCY=3200 PGM_TIMER=TSC PGM_SLEEP=USLEEP pgmsend moo

or,

$ RDTSC_FREQUENCY=3200 pgmsend moo

Sign in to add a comment
Powered by Google Project Hosting