Motr  M0
timer.c File Reference
#include "ut/ut.h"
#include "lib/time.h"
#include "lib/timer.h"
#include "lib/assert.h"
#include "lib/thread.h"
#include "lib/semaphore.h"
#include "lib/memory.h"
#include "lib/atomic.h"
#include "lib/ub.h"
#include "lib/trace.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
Include dependency graph for timer.c:

Go to the source code of this file.

Data Structures

struct  tg_worker
 
struct  tg_timer
 
struct  thread_group
 

Macros

#define TIMER_UB(name, init, round, fini)
 
#define TIMER_UB2(name, init, round, fini)
 

Enumerations

enum  { NR_TIMERS = 8, NR_TG = 8, NR_THREADS_TG = 8, NR_TIMERS_TG = 50 }
 
enum  { UB_TIMER_NR = 0x1 }
 

Functions

static pid_t _gettid ()
 
static m0_time_t make_time (int ms)
 
static m0_time_t make_time_abs (int ms)
 
static int time_rand_ms (int min_ms, int max_ms)
 
static void sem_init_zero (struct m0_semaphore *sem)
 
static unsigned long timer_callback (unsigned long data)
 
static void test_timers (enum m0_timer_type timer_type, int nr_timers, int interval_min_ms, int interval_max_ms, int wait_time_ms, int callbacks_min, int callbacks_max)
 
static unsigned long locality_default_callback (unsigned long data)
 
static void timer_locality_default_test ()
 
static unsigned long locality_test_callback (unsigned long data)
 
static void timer_locality_test (int nr_timers, int interval_min_ms, int interval_max_ms)
 
static unsigned long test_timer_callback_mt (unsigned long data)
 
static void test_timer_worker_mt (struct tg_worker *worker)
 
static void test_timer_controller_mt (struct thread_group *tg)
 
static void test_timer_many_timers_mt ()
 
void test_timer (void)
 
unsigned long timer_ub_callback_dummy (unsigned long unused)
 
static int timers_ub_init (const char *opts)
 
static void timers_ub_fini (void)
 
static void timer_ub__init (int index)
 
static void timer_ub__fini (int index)
 
static void timer_ub__start (int index)
 
static void timer_ub__stop (int index)
 
static void timer_ub_for_each (void(*func)(int index))
 
static void timer_ub_init_dummy (void)
 
static void timer_ub_soft_init_dummy (void)
 
static void timer_ub_hard_init_dummy (void)
 
static void timer_ub_soft_init_all (void)
 
static void timer_ub_hard_init_all (void)
 
static void timer_ub_soft_init_start_all (void)
 
static void timer_ub_hard_init_start_all (void)
 
static void timer_ub_fini_dummy (void)
 
static void timer_ub_fini_all (void)
 
static void timer_ub_stop_fini_all (void)
 
static void timer_ub_start_stop (int index)
 
static void timer_ub_init_start_stop (int index)
 
static void timer_ub_init_start_stop_fini (int index)
 
unsigned long timer_ub_callback (unsigned long index)
 
static void timer_ub__init_cb (int index)
 
static void timer_ub__fini_cb (int index)
 
static void timer_ub_init_cb_dummy (void)
 
static void timer_ub_soft_init_cb_all (void)
 
static void timer_ub_hard_init_cb_all (void)
 
static void timer_ub_soft_init_start_cb_all (void)
 
static void timer_ub_hard_init_start_cb_all (void)
 
static void timer_ub_start_callback (int index)
 
static void timer_ub_fini_cb_all (void)
 
static void timer_ub_stop_fini_cb_all (void)
 
static void timer_ub_callback_stop (int index)
 
static void timer_ub_init_start_callback_stop_fini (int index)
 

Variables

static pid_t loc_default_tid
 
static struct m0_semaphore loc_default_lock
 
static pid_t test_locality_tid
 
static struct m0_semaphoretest_locality_lock
 
static struct m0_atomic64 callbacks_executed
 
static struct m0_timer timer_ub_timers [UB_TIMER_NR]
 
static struct m0_semaphore timer_ub_semaphores [UB_TIMER_NR]
 
static enum m0_timer_type timer_ub_type
 
static m0_time_t timer_ub_expiration
 
static m0_timer_callback_t timer_ub_cb
 
struct m0_ub_set m0_timer_ub
 

Macro Definition Documentation

◆ TIMER_UB

#define TIMER_UB (   name,
  init,
  round,
  fini 
)
Value:
(struct m0_ub_bench) { \
.ub_name = name, \
.ub_iter = UB_TIMER_NR, \
.ub_init = timer_ub_##init, \
.ub_fini = timer_ub_##fini, \
.ub_round = timer_ub_##round, \
}
Definition: ub.h:42
const char * name
Definition: trace.c:110
int init(struct workload *w)
int fini(struct workload *w)

Definition at line 713 of file timer.c.

◆ TIMER_UB2

#define TIMER_UB2 (   name,
  init,
  round,
  fini 
)
Value:
TIMER_UB("S-"name, soft_##init, round, fini), \
TIMER_UB("H-"name, hard_##init, round, fini)
#define TIMER_UB(name, init, round, fini)
Definition: timer.c:713
const char * name
Definition: trace.c:110
int init(struct workload *w)
int fini(struct workload *w)

Definition at line 721 of file timer.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NR_TIMERS 
NR_TG 
NR_THREADS_TG 
NR_TIMERS_TG 

Definition at line 38 of file timer.c.

◆ anonymous enum

anonymous enum
Enumerator
UB_TIMER_NR 

Definition at line 496 of file timer.c.

Function Documentation

◆ _gettid()

static pid_t _gettid ( )
static

Definition at line 81 of file timer.c.

Here is the caller graph for this function:

◆ locality_default_callback()

static unsigned long locality_default_callback ( unsigned long  data)
static

Definition at line 176 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ locality_test_callback()

static unsigned long locality_test_callback ( unsigned long  data)
static

Definition at line 207 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_time()

static m0_time_t make_time ( int  ms)
static

Definition at line 86 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_time_abs()

static m0_time_t make_time_abs ( int  ms)
static

Definition at line 91 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sem_init_zero()

static void sem_init_zero ( struct m0_semaphore sem)
static

Definition at line 101 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_timer()

void test_timer ( void  )

Definition at line 471 of file timer.c.

Here is the call graph for this function:

◆ test_timer_callback_mt()

static unsigned long test_timer_callback_mt ( unsigned long  data)
static

Definition at line 276 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_timer_controller_mt()

static void test_timer_controller_mt ( struct thread_group tg)
static

Definition at line 315 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_timer_many_timers_mt()

static void test_timer_many_timers_mt ( )
static
this (main) thread              controller threads              worker threads
start all controllers
wait for controllers init
                        init workers
                        wait for all workers
                        barrier with workers    barrier with controller
                        sync with main
                        wait for all controllers
barrier with all controllers    barrier with main
                        init all timers
                        run all timers
                        fini() all timers
                        barrier with workers    barrier with controller
                                                detach from locality
                                                exit from thread
                        wait for workers
                                termination
barrier with all controllers    barrier with main
                        exit from thread
wait for controllers termination

Definition at line 422 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_timer_worker_mt()

static void test_timer_worker_mt ( struct tg_worker worker)
static

Definition at line 296 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_timers()

static void test_timers ( enum m0_timer_type  timer_type,
int  nr_timers,
int  interval_min_ms,
int  interval_max_ms,
int  wait_time_ms,
int  callbacks_min,
int  callbacks_max 
)
static

Test timers.

Parameters
timer_typetimer type
nr_timersnumber of timers in this test
interval_min_msminimum value for timer interval
interval_max_msmaximum value for timer interval for every timer it will be chosen with rand() in range [interval_min_ms, interval_max_ms]
wait_time_msfunction will wait this time and then m0_time_stop() for all timers
callbacks_min
See also
callbacks_max
Parameters
callbacks_maxnumber of executed callbacks should be in the interval [callbacks_min, callbacks_max] (this is checked with M0_UT_ASSERT())

Definition at line 129 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ time_rand_ms()

static int time_rand_ms ( int  min_ms,
int  max_ms 
)
static

Definition at line 96 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_callback()

static unsigned long timer_callback ( unsigned long  data)
static

Definition at line 107 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_locality_default_test()

static void timer_locality_default_test ( )
static

Definition at line 186 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_locality_test()

static void timer_locality_test ( int  nr_timers,
int  interval_min_ms,
int  interval_max_ms 
)
static

Definition at line 215 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__fini()

static void timer_ub__fini ( int  index)
static

Definition at line 525 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__fini_cb()

static void timer_ub__fini_cb ( int  index)
static

Definition at line 641 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__init()

static void timer_ub__init ( int  index)
static

Definition at line 518 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__init_cb()

static void timer_ub__init_cb ( int  index)
static

Definition at line 632 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__start()

static void timer_ub__start ( int  index)
static

Definition at line 530 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub__stop()

static void timer_ub__stop ( int  index)
static

Definition at line 535 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_callback()

unsigned long timer_ub_callback ( unsigned long  index)

Definition at line 626 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_callback_dummy()

unsigned long timer_ub_callback_dummy ( unsigned long  unused)

Definition at line 504 of file timer.c.

Here is the caller graph for this function:

◆ timer_ub_callback_stop()

static void timer_ub_callback_stop ( int  index)
static

Definition at line 696 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_fini_all()

static void timer_ub_fini_all ( void  )
static

Definition at line 594 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_fini_cb_all()

static void timer_ub_fini_cb_all ( void  )
static

Definition at line 685 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_fini_dummy()

static void timer_ub_fini_dummy ( void  )
static

Definition at line 590 of file timer.c.

◆ timer_ub_for_each()

static void timer_ub_for_each ( void(*)(int index func)
static

Definition at line 540 of file timer.c.

Here is the caller graph for this function:

◆ timer_ub_hard_init_all()

static void timer_ub_hard_init_all ( void  )
static

Definition at line 572 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_hard_init_cb_all()

static void timer_ub_hard_init_cb_all ( void  )
static

Definition at line 660 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_hard_init_dummy()

static void timer_ub_hard_init_dummy ( void  )
static

Definition at line 560 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_hard_init_start_all()

static void timer_ub_hard_init_start_all ( void  )
static

Definition at line 584 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_hard_init_start_cb_all()

static void timer_ub_hard_init_start_cb_all ( void  )
static

Definition at line 673 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_init_cb_dummy()

static void timer_ub_init_cb_dummy ( void  )
static

Definition at line 647 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_init_dummy()

static void timer_ub_init_dummy ( void  )
static

Definition at line 548 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_init_start_callback_stop_fini()

static void timer_ub_init_start_callback_stop_fini ( int  index)
static

Definition at line 702 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_init_start_stop()

static void timer_ub_init_start_stop ( int  index)
static

Definition at line 611 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_init_start_stop_fini()

static void timer_ub_init_start_stop_fini ( int  index)
static

Definition at line 618 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_soft_init_all()

static void timer_ub_soft_init_all ( void  )
static

Definition at line 566 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_soft_init_cb_all()

static void timer_ub_soft_init_cb_all ( void  )
static

Definition at line 653 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_soft_init_dummy()

static void timer_ub_soft_init_dummy ( void  )
static

Definition at line 554 of file timer.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ub_soft_init_start_all()

static void timer_ub_soft_init_start_all ( void  )
static

Definition at line 578 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_soft_init_start_cb_all()

static void timer_ub_soft_init_start_cb_all ( void  )
static

Definition at line 667 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_start_callback()

static void timer_ub_start_callback ( int  index)
static

Definition at line 679 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_start_stop()

static void timer_ub_start_stop ( int  index)
static

Definition at line 605 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_stop_fini_all()

static void timer_ub_stop_fini_all ( void  )
static

Definition at line 599 of file timer.c.

Here is the call graph for this function:

◆ timer_ub_stop_fini_cb_all()

static void timer_ub_stop_fini_cb_all ( void  )
static

Definition at line 690 of file timer.c.

Here is the call graph for this function:

◆ timers_ub_fini()

static void timers_ub_fini ( void  )
static

Definition at line 514 of file timer.c.

◆ timers_ub_init()

static int timers_ub_init ( const char *  opts)
static

Definition at line 509 of file timer.c.

Variable Documentation

◆ callbacks_executed

struct m0_atomic64 callbacks_executed
static

Definition at line 79 of file timer.c.

◆ loc_default_lock

struct m0_semaphore loc_default_lock
static

Definition at line 74 of file timer.c.

◆ loc_default_tid

pid_t loc_default_tid
static

Definition at line 73 of file timer.c.

◆ m0_timer_ub

struct m0_ub_set m0_timer_ub
Initial value:
= {
.us_name = "timer-ub",
.us_init = timers_ub_init,
.us_fini = timers_ub_fini,
.us_run = {
TIMER_UB2("<init>-fini", init_dummy, _init, fini_all),
TIMER_UB2("init-<fini>", init_all, _fini, fini_dummy),
TIMER_UB2("init-<start>-stop-fini",
init_all, _start, stop_fini_all),
TIMER_UB2("init-start-<stop>-fini",
init_start_all, _stop, fini_all),
TIMER_UB2("init-<start-stop>-fini",
init_all, start_stop, fini_all),
TIMER_UB2("<init-start-stop>-fini",
init_dummy, init_start_stop, fini_all),
TIMER_UB2("<init-start-stop-fini>",
init_dummy, init_start_stop_fini, fini_dummy),
TIMER_UB2("init-<start-callback>-stop-fini",
init_cb_all, start_callback, stop_fini_cb_all),
TIMER_UB2("init-start-<callback-stop>-fini",
init_start_cb_all, callback_stop, fini_cb_all),
TIMER_UB2("<init-start-callback-stop-fini>",
init_dummy, init_start_callback_stop_fini,
fini_dummy),
{ .ub_name = NULL }
}
}
#define NULL
Definition: misc.h:38
static void _fini(void)
Definition: ub.c:456
static void timers_ub_fini(void)
Definition: timer.c:514
static void _stop(void)
Definition: ub.c:264
static int _start(const char *opts)
Definition: ub.c:234
#define TIMER_UB2(name, init, round, fini)
Definition: timer.c:721
static int timers_ub_init(const char *opts)
Definition: timer.c:509
static void start_stop(void)
Definition: iter_ut.c:712
static void _init(bool mkfs, bool use_small_credits)
Definition: service_ut.c:137

Definition at line 737 of file timer.c.

◆ test_locality_lock

struct m0_semaphore* test_locality_lock
static

Definition at line 77 of file timer.c.

◆ test_locality_tid

pid_t test_locality_tid
static

Definition at line 76 of file timer.c.

◆ timer_ub_cb

m0_timer_callback_t timer_ub_cb
static

Definition at line 502 of file timer.c.

◆ timer_ub_expiration

m0_time_t timer_ub_expiration
static

Definition at line 501 of file timer.c.

◆ timer_ub_semaphores

struct m0_semaphore timer_ub_semaphores[UB_TIMER_NR]
static

Definition at line 499 of file timer.c.

◆ timer_ub_timers

struct m0_timer timer_ub_timers[UB_TIMER_NR]
static

Definition at line 498 of file timer.c.

◆ timer_ub_type

enum m0_timer_type timer_ub_type
static

Definition at line 500 of file timer.c.