76 #if !defined( MBG_TGT_WIN32 ) 82 #if !defined( MBGDEVIO_USE_THREAD_API ) 83 #error Symbol MBGDEVIO_USE_THREAD_API needs to be defined, see the Makefile. 86 #if !defined( USE_PROCESS_AFFINITY ) 87 #define USE_PROCESS_AFFINITY 1 91 #define MBG_FIRST_COPYRIGHT_YEAR 2008 92 #define MBG_LAST_COPYRIGHT_YEAR 0 // use default 94 static const char *
pname =
"mbgxhrtime";
101 #if USE_PROCESS_AFFINITY 122 printf(
"%s: CPU%i", info, min_cpu );
124 if ( max_cpu == min_cpu )
127 printf(
"...CPU%i", max_cpu );
144 perror(
"Failed to get process affinity mask" );
157 perror(
"Failed to set process affinity mask" );
161 printf(
"Process affinity mask set for CPU%i only\n", cpu_num );
174 int this_loops =
loops;
180 printf(
"High resolution time not supported by this device.\n" );
194 static int has_printed_msg = 0;
209 if ( !has_printed_msg )
211 printf(
"Waiting until PC cycles frequency has been computed ... " );
219 if ( has_printed_msg )
223 printf(
"PC cycles freq: %.6f MHz", ( (
double) (
int64_t) freq_hz ) / 1E6 );
225 if ( default_freq_hz )
226 printf(
", default: %.6f MHz", ( (
double) (
int64_t) default_freq_hz ) / 1E6 );
243 latency = ( (double) cyc_2 - (
double) cyc_1 ) / (
double) (
int64_t) freq_hz * 1E6;
247 printf(
"t: %s (%.3f us)\n", ws, latency );
249 if ( this_loops > 0 )
252 if ( this_loops == 0 )
261 fprintf( stderr,
"** Aborting: xhrt function returned %i\n", rc );
278 "This example program reads fast extrapolated high resolution time stamps.\n" 280 "The program starts an extra polling thread which reads a high resolution\n" 281 "time stamp plus associated PC cycles counter at regular intervals.\n" 282 "The returned time stamps are extrapolated using the current PC cycles\n" 283 "count value plus the last time stamp/cycles pair read by the polling thread.\n" 285 "This is very much faster than accessing the card every time a time stamp\n" 286 "needs to be retrieved.\n" 287 "This works only for devices which support high resolution time (HR time)." 299 int main(
int argc,
char *argv[] )
307 while ( ( c = getopt( argc, argv,
"cn:h?" ) ) != -1 )
316 loops = atoi( optarg );
332 #if USE_PROCESS_AFFINITY
#define _pcps_has_hr_time(_d)
void check_set_process_affinity_mask(MBG_PROCESS_ID pid, int cpu_num)
Requested action completed successfully.
#define _mbg_cpu_clear(_ps)
A structure used to control a poll thread function.
static __mbg_inline void mbg_get_pc_cycles(MBG_PC_CYCLES *p)
static MBG_DEV_HANDLER_FNC do_mbgxhrtime
int main(int argc, char *argv[])
Unable to handle requested action, usage printed.
#define mbg_rc_is_success(_rc)
int mbg_get_xhrt_cycles_frequency(MBG_XHRT_INFO *p, MBG_PC_CYCLES_FREQUENCY *p_freq_hz)
Retrieve the frequency of the system's cycles counter.
_MBG_API_ATTR int _MBG_API mbg_set_process_affinity(MBG_PROCESS_ID pid, MBG_CPU_SET *p)
Set the CPU affinity of a process.
_MBG_API_ATTR int _MBG_API mbg_get_default_cycles_frequency_from_dev(MBG_DEV_HANDLE dh, MBG_PC_CYCLES_FREQUENCY *p)
Retrieve the system's default cycles counter frequency from the kernel driver.
_MBG_API_ATTR int _MBG_API mbg_get_process_affinity(MBG_PROCESS_ID pid, MBG_CPU_SET *p)
Read the CPU affinity of a process.
#define MBG_FIRST_COPYRIGHT_YEAR
static const char * pname
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
#define _mbg_cpu_set(_i, _ps)
#define MBG_LAST_COPYRIGHT_YEAR
Action failed for specified device.
uint64_t MBG_PC_CYCLES_FREQUENCY
#define _mbg_cpu_isset(_i, _ps)
High resolution time including status and local time offset.
int mbg_get_xhrt_time_as_pcps_hr_time(MBG_XHRT_INFO *p, PCPS_HR_TIME *p_hrt)
Retrieve an extrapolated time stamp in PCPS_HR_TIME format.
#define _mbg_get_current_process()
static void print_cpu_set(const char *info, MBG_CPU_SET *p_cpu_set)
int mbg_xhrt_poll_thread_stop(MBG_POLL_THREAD_INFO *p_pti)
Stop a polling thread started by mbg_xhrt_poll_thread_create.
int mbg_xhrt_poll_thread_create(MBG_POLL_THREAD_INFO *p_pti, MBG_DEV_HANDLE dh, MBG_PC_CYCLES_FREQUENCY freq_hz, int sleep_ms)
Set up a MBG_POLL_THREAD_INFO structure and start a new thread.
int64_t MBG_PC_CYCLES
Generic types to hold PC cycle counter values.