src/dpdk/lib/librte_power/power_pstate_cpufreq.c
static int
power_get_available_freqs(struct pstate_power_info *pi)
{
	FILE *f_min, *f_max;
	int ret = -1;
	char *p_min, *p_max;
	char buf_min[BUFSIZ];
	char buf_max[BUFSIZ];
	char fullpath_min[PATH_MAX];
	char fullpath_max[PATH_MAX];
	char *s_min, *s_max;
	uint32_t sys_min_freq = 0, sys_max_freq = 0, base_max_freq = 0;
	uint32_t i, num_freqs = 0;

	snprintf(fullpath_max, sizeof(fullpath_max),
			POWER_SYSFILE_BASE_MAX_FREQ,
			pi->lcore_id);
	snprintf(fullpath_min, sizeof(fullpath_min),
			POWER_SYSFILE_BASE_MIN_FREQ,
			pi->lcore_id);

	f_min = fopen(fullpath_min, "r");
	FOPEN_OR_ERR_RET(f_min, ret);

	f_max = fopen(fullpath_max, "r");
	if (f_max == NULL)
		fclose(f_min);

	FOPEN_OR_ERR_RET(f_max, ret);

	s_min = fgets(buf_min, sizeof(buf_min), f_min);
	FOPS_OR_NULL_GOTO(s_min, out);

	s_max = fgets(buf_max, sizeof(buf_max), f_max);
	FOPS_OR_NULL_GOTO(s_max, out);


	/* Strip the line break if there is */
	p_min = strchr(buf_min, '\n');
	if (p_min != NULL)
		*p_min = 0;

	p_max = strchr(buf_max, '\n');
	if (p_max != NULL)
		*p_max = 0;

	sys_min_freq = strtoul(buf_min, &p_min, POWER_CONVERT_TO_DECIMAL);
	sys_max_freq = strtoul(buf_max, &p_max, POWER_CONVERT_TO_DECIMAL);

	if (sys_max_freq < sys_min_freq)
		goto out;

	pi->sys_max_freq = sys_max_freq;

	if (pi->priority_core == 1)
		base_max_freq = pi->core_base_freq;
	else
		base_max_freq = pi->non_turbo_max_ratio * BUS_FREQ;

	POWER_DEBUG_TRACE("sys min %u, sys max %u, base_max %u\n",
			sys_min_freq,
			sys_max_freq,
			base_max_freq);

	if (base_max_freq < sys_max_freq)
		pi->turbo_available = 1;
	else
		pi->turbo_available = 0;

	/* If turbo is available then there is one extra freq bucket
	 * to store the sys max freq which value is base_max +1
	 */
	num_freqs = (base_max_freq - sys_min_freq) / BUS_FREQ + 1 +
		pi->turbo_available;

	/* Generate the freq bucket array.
	 * If turbo is available the freq bucket[0] value is base_max +1
	 * the bucket[1] is base_max, bucket[2] is base_max - BUS_FREQ
	 * and so on.
	 * If turbo is not available bucket[0] is base_max and so on
	 */
	for (i = 0, pi->nb_freqs = 0; i < num_freqs; i++) {
		if ((i == 0) && pi->turbo_available)
			pi->freqs[pi->nb_freqs++] = base_max_freq + 1;
		else
			pi->freqs[pi->nb_freqs++] =
			base_max_freq - (i - pi->turbo_available) * BUS_FREQ;
	}

	ret = 0;

	POWER_DEBUG_TRACE("%d frequency(s) of lcore %u are available\n",
			num_freqs, pi->lcore_id);

out:
	fclose(f_min);
	fclose(f_max);

	return ret;
}
/**
 * It is to get the available frequencies of the specific lcore by reading the
 * sys file.
 */
It is to get the available frequencies of the specific lcore by reading the
sys file.
It is to get the available frequencies of the specific lcore by reading the sys file .
static int
power_get_available_freqs(struct pstate_power_info *pi)
{
	FILE *f_min, *f_max;
	int ret = -1;
	char *p_min, *p_max;
	char buf_min[BUFSIZ];
	char buf_max[BUFSIZ];
	char fullpath_min[PATH_MAX];
	char fullpath_max[PATH_MAX];
	char *s_min, *s_max;
	uint32_t sys_min_freq = 0, sys_max_freq = 0, base_max_freq = 0;
	uint32_t i, num_freqs = 0;
	snprintf(fullpath_max, sizeof(fullpath_max),
			POWER_SYSFILE_BASE_MAX_FREQ,
			pi->lcore_id);
	snprintf(fullpath_min, sizeof(fullpath_min),
			POWER_SYSFILE_BASE_MIN_FREQ,
			pi->lcore_id);
	f_min = fopen(fullpath_min, "r");
	FOPEN_OR_ERR_RET(f_min, ret);
	f_max = fopen(fullpath_max, "r");
	if (f_max == NULL)
		fclose(f_min);
	FOPEN_OR_ERR_RET(f_max, ret);
	s_min = fgets(buf_min, sizeof(buf_min), f_min);
	FOPS_OR_NULL_GOTO(s_min, out);
	s_max = fgets(buf_max, sizeof(buf_max), f_max);
	FOPS_OR_NULL_GOTO(s_max, out);
	p_min = strchr(buf_min, '\n');
	if (p_min != NULL)
		*p_min = 0;
	p_max = strchr(buf_max, '\n');
	if (p_max != NULL)
		*p_max = 0;
	sys_min_freq = strtoul(buf_min, &p_min, POWER_CONVERT_TO_DECIMAL);
	sys_max_freq = strtoul(buf_max, &p_max, POWER_CONVERT_TO_DECIMAL);
	if (sys_max_freq < sys_min_freq)
		goto out;
	pi->sys_max_freq = sys_max_freq;
	if (pi->priority_core == 1)
		base_max_freq = pi->core_base_freq;
	else
		base_max_freq = pi->non_turbo_max_ratio * BUS_FREQ;
	POWER_DEBUG_TRACE("sys min %u, sys max %u, base_max %u\n",
			sys_min_freq,
			sys_max_freq,
			base_max_freq);
	if (base_max_freq < sys_max_freq)
		pi->turbo_available = 1;
	else
		pi->turbo_available = 0;
	num_freqs = (base_max_freq - sys_min_freq) / BUS_FREQ + 1 +
		pi->turbo_available;
	for (i = 0, pi->nb_freqs = 0; i < num_freqs; i++) {
		if ((i == 0) && pi->turbo_available)
			pi->freqs[pi->nb_freqs++] = base_max_freq + 1;
		else
			pi->freqs[pi->nb_freqs++] =
			base_max_freq - (i - pi->turbo_available) * BUS_FREQ;
	}
	ret = 0;
	POWER_DEBUG_TRACE("%d frequency(s) of lcore %u are available\n",
			num_freqs, pi->lcore_id);
out:
	fclose(f_min);
	fclose(f_max);
	return ret;
}
static int power_get_available_freqs ( struct pstate_power_info * pi ) { FILE * f_min , * f_max ; int ret = -1 ; char * p_min , * p_max ; char buf_min [ BUFSIZ ] ; char buf_max [ BUFSIZ ] ; char fullpath_min [ PATH_MAX ] ; char fullpath_max [ PATH_MAX ] ; char * s_min , * s_max ; uint32_t sys_min_freq = 0 , sys_max_freq = 0 , base_max_freq = 0 ; uint32_t i , num_freqs = 0 ; snprintf ( fullpath_max , sizeof ( fullpath_max ) , POWER_SYSFILE_BASE_MAX_FREQ , pi -> lcore_id ) ; snprintf ( fullpath_min , sizeof ( fullpath_min ) , POWER_SYSFILE_BASE_MIN_FREQ , pi -> lcore_id ) ; f_min = fopen ( fullpath_min , " " ) ; FOPEN_OR_ERR_RET ( f_min , ret ) ; f_max = fopen ( fullpath_max , " " ) ; if ( f_max == NULL ) fclose ( f_min ) ; FOPEN_OR_ERR_RET ( f_max , ret ) ; s_min = fgets ( buf_min , sizeof ( buf_min ) , f_min ) ; FOPS_OR_NULL_GOTO ( s_min , out ) ; s_max = fgets ( buf_max , sizeof ( buf_max ) , f_max ) ; FOPS_OR_NULL_GOTO ( s_max , out ) ; p_min = strchr ( buf_min , ' \n ' ) ; if ( p_min != NULL ) * p_min = 0 ; p_max = strchr ( buf_max , ' \n ' ) ; if ( p_max != NULL ) * p_max = 0 ; sys_min_freq = strtoul ( buf_min , & p_min , POWER_CONVERT_TO_DECIMAL ) ; sys_max_freq = strtoul ( buf_max , & p_max , POWER_CONVERT_TO_DECIMAL ) ; if ( sys_max_freq < sys_min_freq ) goto out ; pi -> sys_max_freq = sys_max_freq ; if ( pi -> priority_core == 1 ) base_max_freq = pi -> core_base_freq ; else base_max_freq = pi -> non_turbo_max_ratio * BUS_FREQ ; POWER_DEBUG_TRACE ( " \n " , sys_min_freq , sys_max_freq , base_max_freq ) ; if ( base_max_freq < sys_max_freq ) pi -> turbo_available = 1 ; else pi -> turbo_available = 0 ; num_freqs = ( base_max_freq - sys_min_freq ) / BUS_FREQ + 1 + pi -> turbo_available ; for ( i = 0 , pi -> nb_freqs = 0 ; i < num_freqs ; i ++ ) { if ( ( i == 0 ) && pi -> turbo_available ) pi -> freqs [ pi -> nb_freqs ++ ] = base_max_freq + 1 ; else pi -> freqs [ pi -> nb_freqs ++ ] = base_max_freq - ( i - pi -> turbo_available ) * BUS_FREQ ; } ret = 0 ; POWER_DEBUG_TRACE ( " \n " , num_freqs , pi -> lcore_id ) ; out : fclose ( f_min ) ; fclose ( f_max ) ; return ret ; }
It is to get the available frequencies of the specific lcore by reading the
 sys file.
It is to get the available frequencies of the specific lcore by reading the sys file .
/* Strip the line break if there is */ /* If turbo is available then there is one extra freq bucket
	 * to store the sys max freq which value is base_max +1
	 */ /* Generate the freq bucket array.
	 * If turbo is available the freq bucket[0] value is base_max +1
	 * the bucket[1] is base_max, bucket[2] is base_max - BUS_FREQ
	 * and so on.
	 * If turbo is not available bucket[0] is base_max and so on
	 */