src/dpdk/lib/librte_power/power_acpi_cpufreq.c
static int
power_set_governor_original(struct rte_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);

	/* Check if the governor to be set is the same as current */
	if (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {
		ret = 0;
		POWER_DEBUG_TRACE("Power management governor of lcore %u "
				"has already been set to %s\n",
				pi->lcore_id, pi->governor_ori);
		goto out;
	}

	/* Write back the original governor */
	val = fseek(f, 0, SEEK_SET);
	FOPS_OR_ERR_GOTO(val, out);

	val = fputs(pi->governor_ori, f);
	FOPS_OR_ERR_GOTO(val, out);

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

	return ret;
}
/**
 * It is to check the governor and then set the original governor back if
 * needed by writing the sys file.
 */
It is to check the governor and then set the original governor back if
needed by writing the sys file.
It is to check the governor and then set the original governor back if needed by writing the sys file .
static int
power_set_governor_original(struct rte_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);
	if (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {
		ret = 0;
		POWER_DEBUG_TRACE("Power management governor of lcore %u "
				"has already been set to %s\n",
				pi->lcore_id, pi->governor_ori);
		goto out;
	}
	val = fseek(f, 0, SEEK_SET);
	FOPS_OR_ERR_GOTO(val, out);
	val = fputs(pi->governor_ori, f);
	FOPS_OR_ERR_GOTO(val, out);
	ret = 0;
	RTE_LOG(INFO, POWER, "Power management governor of lcore %u "
			"has been set back to %s successfully\n",
			pi->lcore_id, pi->governor_ori);
out:
	fclose(f);
	return ret;
}
static int power_set_governor_original ( struct rte_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 ) ; if ( strncmp ( buf , pi -> governor_ori , sizeof ( pi -> governor_ori ) ) == 0 ) { ret = 0 ; POWER_DEBUG_TRACE ( " " " \n " , pi -> lcore_id , pi -> governor_ori ) ; goto out ; } val = fseek ( f , 0 , SEEK_SET ) ; FOPS_OR_ERR_GOTO ( val , out ) ; val = fputs ( pi -> governor_ori , f ) ; FOPS_OR_ERR_GOTO ( val , out ) ; ret = 0 ; RTE_LOG ( INFO , POWER , " " " \n " , pi -> lcore_id , pi -> governor_ori ) ; out : fclose ( f ) ; return ret ; }
It is to check the governor and then set the original governor back if
 needed by writing the sys file.
It is to check the governor and then set the original governor back if needed by writing the sys file .
/* Check if the governor to be set is the same as current */ /* Write back the original governor */