src/dpdk/lib/librte_timer/rte_timer.c
int
rte_timer_subsystem_init(void)
{
	const struct rte_memzone *mz;
	struct rte_timer_data *data;
	int i, lcore_id;
	static const char *mz_name = "rte_timer_mz";
	const size_t data_arr_size =
			RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);
	const size_t mem_size = data_arr_size + sizeof(*rte_timer_mz_refcnt);
	bool do_full_init = true;

	rte_mcfg_timer_lock();

	if (rte_timer_subsystem_initialized) {
		rte_mcfg_timer_unlock();
		return -EALREADY;
	}

	mz = rte_memzone_lookup(mz_name);
	if (mz == NULL) {
		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
				SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
		if (mz == NULL) {
			rte_mcfg_timer_unlock();
			return -ENOMEM;
		}
		do_full_init = true;
	} else
		do_full_init = false;

	rte_timer_data_mz = mz;
	rte_timer_data_arr = mz->addr;
	rte_timer_mz_refcnt = (void *)((char *)mz->addr + data_arr_size);

	if (do_full_init) {
		for (i = 0; i < RTE_MAX_DATA_ELS; i++) {
			data = &rte_timer_data_arr[i];

			for (lcore_id = 0; lcore_id < RTE_MAX_LCORE;
			     lcore_id++) {
				rte_spinlock_init(
					&data->priv_timer[lcore_id].list_lock);
				data->priv_timer[lcore_id].prev_lcore =
					lcore_id;
			}
		}
	}

	rte_timer_data_arr[default_data_id].internal_flags |= FL_ALLOCATED;
	(*rte_timer_mz_refcnt)++;

	rte_timer_subsystem_initialized = 1;

	rte_mcfg_timer_unlock();

	return 0;
}
/* Init the timer library. Allocate an array of timer data structs in shared
 * memory, and allocate the zeroth entry for use with original timer
 * APIs. Since the intersection of the sets of lcore ids in primary and
 * secondary processes should be empty, the zeroth entry can be shared by
 * multiple processes.
 */
Init the timer library. Allocate an array of timer data structs in shared
memory, and allocate the zeroth entry for use with original timer
APIs. Since the intersection of the sets of lcore ids in primary and
secondary processes should be empty, the zeroth entry can be shared by
multiple processes.
Init the timer library . Allocate an array of timer data structs in shared memory and allocate the zeroth entry for use with original timer APIs . Since the intersection of the sets of lcore ids in primary and secondary processes should be empty the zeroth entry can be shared by multiple processes .
int
rte_timer_subsystem_init(void)
{
	const struct rte_memzone *mz;
	struct rte_timer_data *data;
	int i, lcore_id;
	static const char *mz_name = "rte_timer_mz";
	const size_t data_arr_size =
			RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);
	const size_t mem_size = data_arr_size + sizeof(*rte_timer_mz_refcnt);
	bool do_full_init = true;
	rte_mcfg_timer_lock();
	if (rte_timer_subsystem_initialized) {
		rte_mcfg_timer_unlock();
		return -EALREADY;
	}
	mz = rte_memzone_lookup(mz_name);
	if (mz == NULL) {
		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
				SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
		if (mz == NULL) {
			rte_mcfg_timer_unlock();
			return -ENOMEM;
		}
		do_full_init = true;
	} else
		do_full_init = false;
	rte_timer_data_mz = mz;
	rte_timer_data_arr = mz->addr;
	rte_timer_mz_refcnt = (void *)((char *)mz->addr + data_arr_size);
	if (do_full_init) {
		for (i = 0; i < RTE_MAX_DATA_ELS; i++) {
			data = &rte_timer_data_arr[i];
			for (lcore_id = 0; lcore_id < RTE_MAX_LCORE;
			     lcore_id++) {
				rte_spinlock_init(
					&data->priv_timer[lcore_id].list_lock);
				data->priv_timer[lcore_id].prev_lcore =
					lcore_id;
			}
		}
	}
	rte_timer_data_arr[default_data_id].internal_flags |= FL_ALLOCATED;
	(*rte_timer_mz_refcnt)++;
	rte_timer_subsystem_initialized = 1;
	rte_mcfg_timer_unlock();
	return 0;
}
int rte_timer_subsystem_init ( void ) { const struct rte_memzone * mz ; struct rte_timer_data * data ; int i , lcore_id ; static const char * mz_name = " " ; const size_t data_arr_size = RTE_MAX_DATA_ELS * sizeof ( * rte_timer_data_arr ) ; const size_t mem_size = data_arr_size + sizeof ( * rte_timer_mz_refcnt ) ; bool do_full_init = true ; rte_mcfg_timer_lock ( ) ; if ( rte_timer_subsystem_initialized ) { rte_mcfg_timer_unlock ( ) ; return - EALREADY ; } mz = rte_memzone_lookup ( mz_name ) ; if ( mz == NULL ) { mz = rte_memzone_reserve_aligned ( mz_name , mem_size , SOCKET_ID_ANY , 0 , RTE_CACHE_LINE_SIZE ) ; if ( mz == NULL ) { rte_mcfg_timer_unlock ( ) ; return - ENOMEM ; } do_full_init = true ; } else do_full_init = false ; rte_timer_data_mz = mz ; rte_timer_data_arr = mz -> addr ; rte_timer_mz_refcnt = ( void * ) ( ( char * ) mz -> addr + data_arr_size ) ; if ( do_full_init ) { for ( i = 0 ; i < RTE_MAX_DATA_ELS ; i ++ ) { data = & rte_timer_data_arr [ i ] ; for ( lcore_id = 0 ; lcore_id < RTE_MAX_LCORE ; lcore_id ++ ) { rte_spinlock_init ( & data -> priv_timer [ lcore_id ] . list_lock ) ; data -> priv_timer [ lcore_id ] . prev_lcore = lcore_id ; } } } rte_timer_data_arr [ default_data_id ] . internal_flags |= FL_ALLOCATED ; ( * rte_timer_mz_refcnt ) ++ ; rte_timer_subsystem_initialized = 1 ; rte_mcfg_timer_unlock ( ) ; return 0 ; }
Init the timer library.
Init the timer library .