src/dpdk/lib/librte_power/power_pstate_cpufreq.c
static int
power_set_governor_performance(struct pstate_power_info *pi)
{
	FILE *f;
	int ret = -1;
	char buf[BUFSIZ];
	char fullpath[PATH_MAX];
	char *s;
	int val;

	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
			pi->lcore_id);
	f = fopen(fullpath, "rw+");
	FOPEN_OR_ERR_RET(f, ret);

	s = fgets(buf, sizeof(buf), f);
	FOPS_OR_NULL_GOTO(s, out);
	/* Strip off terminating '\n' */
	strtok(buf, "\n");

	/* Check if current governor is performance */
	if (strncmp(buf, POWER_GOVERNOR_PERF,
			sizeof(POWER_GOVERNOR_PERF)) == 0) {
		ret = 0;
		POWER_DEBUG_TRACE("Power management governor of lcore %u is "
				"already performance\n", pi->lcore_id);
		goto out;
	}
	/* Save the original governor */
	strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori));

	/* Write 'performance' to the governor */
	val = fseek(f, 0, SEEK_SET);
	FOPS_OR_ERR_GOTO(val, out);

	val = fputs(POWER_GOVERNOR_PERF, f);
	FOPS_OR_ERR_GOTO(val, out);

	/* We need to flush to see if the fputs succeeds */
	val = fflush(f);
	FOPS_OR_ERR_GOTO(val, out);

	ret = 0;
	RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
			"set to performance successfully\n", pi->lcore_id);
out:
	fclose(f);

	return ret;
}
/**
 * It is to check the current scaling governor by reading sys file, and then
 * set it into 'performance' if it is not by writing the sys file. The original
 * governor will be saved for rolling back.
 */
It is to check the current scaling governor by reading sys file, and then
set it into 'performance' if it is not by writing the sys file. The original
governor will be saved for rolling back.
It is to check the current scaling governor by reading sys file and then set it into ' performance ' if it is not by writing the sys file . The original governor will be saved for rolling back .
static int
power_set_governor_performance(struct pstate_power_info *pi)
{
	FILE *f;
	int ret = -1;
	char buf[BUFSIZ];
	char fullpath[PATH_MAX];
	char *s;
	int val;
	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
			pi->lcore_id);
	f = fopen(fullpath, "rw+");
	FOPEN_OR_ERR_RET(f, ret);
	s = fgets(buf, sizeof(buf), f);
	FOPS_OR_NULL_GOTO(s, out);
	strtok(buf, "\n");
	if (strncmp(buf, POWER_GOVERNOR_PERF,
			sizeof(POWER_GOVERNOR_PERF)) == 0) {
		ret = 0;
		POWER_DEBUG_TRACE("Power management governor of lcore %u is "
				"already performance\n", pi->lcore_id);
		goto out;
	}
	strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori));
	val = fseek(f, 0, SEEK_SET);
	FOPS_OR_ERR_GOTO(val, out);
	val = fputs(POWER_GOVERNOR_PERF, f);
	FOPS_OR_ERR_GOTO(val, out);
	val = fflush(f);
	FOPS_OR_ERR_GOTO(val, out);
	ret = 0;
	RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
			"set to performance successfully\n", pi->lcore_id);
out:
	fclose(f);
	return ret;
}
static int power_set_governor_performance ( struct pstate_power_info * pi ) { FILE * f ; int ret = -1 ; char buf [ BUFSIZ ] ; char fullpath [ PATH_MAX ] ; char * s ; int val ; snprintf ( fullpath , sizeof ( fullpath ) , POWER_SYSFILE_GOVERNOR , pi -> lcore_id ) ; f = fopen ( fullpath , " " ) ; FOPEN_OR_ERR_RET ( f , ret ) ; s = fgets ( buf , sizeof ( buf ) , f ) ; FOPS_OR_NULL_GOTO ( s , out ) ; strtok ( buf , " \n " ) ; if ( strncmp ( buf , POWER_GOVERNOR_PERF , sizeof ( POWER_GOVERNOR_PERF ) ) == 0 ) { ret = 0 ; POWER_DEBUG_TRACE ( " " " \n " , pi -> lcore_id ) ; goto out ; } strlcpy ( pi -> governor_ori , buf , sizeof ( pi -> governor_ori ) ) ; val = fseek ( f , 0 , SEEK_SET ) ; FOPS_OR_ERR_GOTO ( val , out ) ; val = fputs ( POWER_GOVERNOR_PERF , f ) ; FOPS_OR_ERR_GOTO ( val , out ) ; val = fflush ( f ) ; FOPS_OR_ERR_GOTO ( val , out ) ; ret = 0 ; RTE_LOG ( INFO , POWER , " " " \n " , pi -> lcore_id ) ; out : fclose ( f ) ; return ret ; }
It is to check the current scaling governor by reading sys file, and then
 set it into 'performance' if it is not by writing the sys file.
It is to check the current scaling governor by reading sys file and then set it into ' performance ' if it is not by writing the sys file .
/* Strip off terminating '\n' */ /* Check if current governor is performance */ /* Save the original governor */ /* Write 'performance' to the governor */ /* We need to flush to see if the fputs succeeds */