コード例 #1
0
ファイル: ring_allocation_logic.cpp プロジェクト: olgk/libvma
/*
 * return true if ring migration is recommended.
 */
bool ring_allocation_logic::should_migrate_ring()
{
	if (!is_logic_support_migration()) {
		return false;
	}

	if (m_ring_migration_ratio < 0) {
		return false;
	}

	ral_logfuncall("currently accessed from thread=%lu, cpu=%d", pthread_self(), sched_getcpu());

	int count_max = m_ring_migration_ratio;
	if (m_migration_candidate) {
		count_max = CANDIDATE_STABILITY_ROUNDS;
		uint64_t new_id = calc_res_key_by_logic();
		if (m_migration_candidate != new_id) {
			m_migration_candidate = 0;
			m_migration_try_count = 0;
			return false;
		}
	}


	if (m_migration_try_count < count_max) {
		m_migration_try_count++;
		return false;
	} else {
		m_migration_try_count = 0;
	}

	if (!m_migration_candidate) {
		// save current used allocation key
		// no need to save profile, and allocation logic
		uint64_t curr_id = m_res_key.get_user_id_key();
		// calc new key
		uint64_t new_id = calc_res_key_by_logic();
		if (new_id == curr_id || g_n_internal_thread_id == curr_id) {
			return false;
		}
		m_migration_candidate = new_id;
		return false;
	}

	ral_logdbg("migrating from ring of id=%s to ring of id=%lu",
		   m_res_key.to_str(), m_migration_candidate);
	m_migration_candidate = 0;

	return true;
}
コード例 #2
0
ring_allocation_logic::ring_allocation_logic(ring_logic_t allocation_logic,
					     int ring_migration_ratio, source_t source,
					     resource_allocation_key &ring_profile):
	m_tostr("base"), m_ring_migration_ratio(ring_migration_ratio),
	m_source(source), m_migration_try_count(ring_migration_ratio)
{
	if (ring_profile.get_ring_alloc_logic() == RING_LOGIC_PER_INTERFACE &&
	    ring_profile.get_ring_profile_key() < START_RING_INDEX) {
		ring_profile.set_ring_alloc_logic(allocation_logic);
	}
	m_res_key = resource_allocation_key(ring_profile);
	m_migration_candidate = 0;
	m_res_key.set_user_id_key(calc_res_key_by_logic());
}
コード例 #3
0
resource_allocation_key* ring_allocation_logic::create_new_key(in_addr_t addr, int suggested_cpu /* = NO_CPU */)
{
	if (m_res_key.get_ring_alloc_logic() == RING_LOGIC_PER_CORE_ATTACH_THREADS) {
		pthread_t tid = pthread_self();
		int cpu = g_cpu_manager.reserve_cpu_for_thread(tid, suggested_cpu);
		if (cpu >= 0) {
			m_res_key.set_user_id_key(cpu);
			return &m_res_key;
		}
	}

	if (m_res_key.get_ring_alloc_logic() == RING_LOGIC_PER_IP) {
		m_source.m_ip = addr;
	}

	m_res_key.set_user_id_key(calc_res_key_by_logic());
	return &m_res_key;
}