static uns32 avnd_sg_oper_req(AVND_CB *cb, AVSV_PARAM_INFO *param)
{
	uns32 rc = NCSCC_RC_FAILURE;

	TRACE_ENTER2("'%s'", param->name.value);

	switch (param->act) {
	case AVSV_OBJ_OPR_MOD:	{
		AVND_SU *su;

		su = m_AVND_SUDB_REC_GET(cb->sudb, param->name);
		if (!su) {
			LOG_ER("%s: failed to get %s", __FUNCTION__, param->name.value);
			goto done;
		}

		switch (param->attr_id) {
		case saAmfSGCompRestartProb_ID:
			assert(sizeof(SaTimeT) == param->value_len);
			su->comp_restart_prob = m_NCS_OS_NTOHLL_P(param->value);
			m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su,
				AVND_CKPT_SU_COMP_RESTART_PROB);
			break;
		case saAmfSGCompRestartMax_ID:
			assert(sizeof(uns32) == param->value_len);
			su->comp_restart_max = m_NCS_OS_NTOHL(*(uns32 *)(param->value));
			m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, AVND_CKPT_SU_COMP_RESTART_MAX);
			break;
		case saAmfSGSuRestartProb_ID:
			assert(sizeof(SaTimeT) == param->value_len);
			su->su_restart_prob = m_NCS_OS_NTOHLL_P(param->value);
			m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, AVND_CKPT_SU_RESTART_PROB);
			break;
		case saAmfSGSuRestartMax_ID:
			assert(sizeof(uns32) == param->value_len);
			su->su_restart_max = m_NCS_OS_NTOHL(*(uns32 *)(param->value));
			m_AVND_SEND_CKPT_UPDT_ASYNC_UPDT(cb, su, AVND_CKPT_SU_RESTART_MAX);
			break;
		default:
			LOG_NO("%s: Unsupported attribute %u", __FUNCTION__, param->attr_id);
			goto done;
		}
		break;
	}

	default:
		LOG_NO("%s: Unsupported action %u", __FUNCTION__, param->act);
		goto done;
	}

	rc = NCSCC_RC_SUCCESS;

done:
	TRACE_LEAVE();
	return rc;
}
/****************************************************************************
 * Function Name: ncs_tmr_remaining
 *
 * Purpose:   This function calculates how much time is remaining for a
 *            particular timer.
 *
 ****************************************************************************/
uint32_t ncs_tmr_remaining(tmr_t tmrID, uint32_t *p_tleft)
{
	SYSF_TMR *tmr;
	uint32_t total_ticks_left;
	uint32_t ticks_elapsed;
	uint32_t ticks_to_expiry;

	if (((tmr = (SYSF_TMR *)tmrID) == NULL) || (tmr_destroying == true) || (p_tleft == NULL))
		return NCSCC_RC_FAILURE;

	*p_tleft = 0;
	TMR_DBG_ASSERT_ISA(tmr->dbg);	/* confirm that its timer memory */

	if (ncslpg_take(&gl_tcb.persist) == false)	/* guarentee persistence */
		return NCSCC_RC_FAILURE;

	m_NCS_LOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);	/* critical region START */
	if (!TMR_TEST_STATE(tmr, TMR_STATE_START)) {
		m_NCS_UNLOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);	/* critical region START */
		return NCSCC_RC_FAILURE;
	}
	m_NCS_UNLOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);	/* critical region START */
	ticks_elapsed = get_time_elapsed_in_ticks(&ts_start);
	ticks_to_expiry = m_NCS_OS_NTOHLL_P(&tmr->key);
	total_ticks_left = (ticks_to_expiry - ticks_elapsed);

	*p_tleft = total_ticks_left * NCS_MILLISECONDS_PER_TICK;

	return ncslpg_give(&gl_tcb.persist, NCSCC_RC_SUCCESS);
}
static uns32 avnd_node_oper_req(AVND_CB *cb, AVSV_PARAM_INFO *param)
{
	uns32 rc = NCSCC_RC_FAILURE;

	TRACE_ENTER2("'%s'", param->name.value);

	switch (param->act) {
	case AVSV_OBJ_OPR_MOD:
		switch (param->attr_id) {
		case saAmfNodeSuFailoverProb_ID:
			assert(sizeof(SaTimeT) == param->value_len);
			cb->su_failover_prob = m_NCS_OS_NTOHLL_P(param->value);
			break;
		case saAmfNodeSuFailoverMax_ID:
			assert(sizeof(uns32) == param->value_len);
			cb->su_failover_max = m_NCS_OS_NTOHL(*(uns32 *)(param->value));
			break;
		default:
			LOG_NO("%s: Unsupported attribute %u", __FUNCTION__, param->attr_id);
			goto done;
		}
		break;
		
	default:
		LOG_NO("%s: Unsupported action %u", __FUNCTION__, param->act);
		goto done;
	}

	rc = NCSCC_RC_SUCCESS;

done:
	TRACE_LEAVE();
	return rc;
}
Exemple #4
0
/*****************************************************************************

  PROCEDURE NAME:    ncs_decode_64bit

  DESCRIPTION:

  Decode a 8-octet *NON-0/1-EXT-ENCODED* field.

  ARGUMENTS:

 stream:  Address of a pointer to streamed data.

  RETURNS:

  NOTES:

  "stream" points to the start of 8-octet unsigned value in the network order.
  Network-order is the same as "big-endian" order (MSB first).
  This function has a built-in network-to-host order effect.

*****************************************************************************/
uns64 ncs_decode_64bit(uns8 **stream)
{
	uns64 val;

	val = m_NCS_OS_NTOHLL_P((*stream));
	(*stream) += 8;

	return val;
}
static uint32_t ncs_tmr_engine(struct timeval *tv, uint64_t *next_delay)
{
	uint64_t next_expiry = 0;
	uint64_t ticks_elapsed = 0;
	SYSF_TMR_PAT_NODE *tmp = NULL;

#if ENABLE_SYSLOG_TMR_STATS
	/* To measure avg. timer expiry gap */
	struct timespec tmr_exp_prev_finish = { 0, 0 };
	struct timespec tmr_exp_curr_start = { 0, 0 };
	uint32_t tot_tmr_exp = 0;
	uint64_t sum_of_tmr_exp_gaps = 0;	/* Avg = sum_of_tmr_exp_gaps/tot_tmr_exp */
#endif

	while (true) {
		tmp = (SYSF_TMR_PAT_NODE *)ncs_patricia_tree_getnext(&gl_tcb.tmr_pat_tree, (uint8_t *)NULL);
		ticks_elapsed = get_time_elapsed_in_ticks(&ts_start);
		if (tmp != NULL) {
			next_expiry = m_NCS_OS_NTOHLL_P(&tmp->key);
		} else {
			tv->tv_sec = 0xffffff;
			tv->tv_usec = 0;
			*next_delay = 0;
			return NCSCC_RC_SUCCESS;
		}

		if (ticks_elapsed >= next_expiry) {
#if ENABLE_SYSLOG_TMR_STATS
			if (tot_tmr_exp != 0) {
				tmr_exp_curr_start.tv_sec = tmr_exp_curr_start.tv_nsec = 0;
				if (clock_gettime(CLOCK_MONOTONIC, &tmr_exp_curr_start)) {
					perror("clock_gettime with MONOTONIC Failed \n");
				}
				sum_of_tmr_exp_gaps += TIMESPEC_DIFF_IN_NS(tmr_exp_curr_start, tmr_exp_prev_finish);
				if (tot_tmr_exp >= 100) {
					printf("\nTotal active timers: %d\n", gl_tcb.stats.cnt);
					printf("Average timer-expiry gap (last %d expiries) = %lld\n",
					       tot_tmr_exp, sum_of_tmr_exp_gaps / tot_tmr_exp);
					tot_tmr_exp = 0;
					sum_of_tmr_exp_gaps = 0;
				}
			}
#endif

			if (true == sysfTmrExpiry(tmp)) {	/* call expiry routine          */
				return NCSCC_RC_FAILURE;
			}
#if ENABLE_SYSLOG_TMR_STATS
			tot_tmr_exp++;
			tmr_exp_prev_finish.tv_sec = tmr_exp_prev_finish.tv_nsec = 0;
			if (clock_gettime(CLOCK_MONOTONIC, &tmr_exp_prev_finish)) {
				perror("clock_gettime with MONOTONIC Failed \n");
				return NCSCC_RC_FAILURE;
			}
#endif
		} else {
			break;
		}
	}			/* while loop end */

	(*next_delay) = next_expiry - ticks_elapsed;

	/* Convert the next_dealy intto the below structure */
	tv->tv_sec = ((*next_delay) * NCS_MILLISECONDS_PER_TICK) / 1000;
	tv->tv_usec = (((*next_delay) % (1000 / NCS_MILLISECONDS_PER_TICK)) * (1000 * NCS_MILLISECONDS_PER_TICK));

	return NCSCC_RC_SUCCESS;
}