usr.sbin/powerd/powerd.c
static
void
acpi_setcpufreq(int nstate)
{
	int ncpus = 0;
	int increasing = (nstate > CpuLimit);
	int dom;
	int domBeg;
	int domEnd;
	int lowest;
	int highest;
	int desired;
	int v;
	char *sysid;
	char *ptr;
	char buf[256];
	size_t buflen;
	cpumask_t global_cpumask;

	/*
	 * Calculate the ending domain if the number of operating cpus
	 * has increased.
	 *
	 * Calculate the starting domain if the number of operating cpus
	 * has decreased.
	 */
	for (dom = DomBeg; dom < DomEnd; ++dom) {
		if (ncpus >= nstate)
			break;
		ncpus += CpuCount[dom];
	}

	syslog(LOG_INFO, "using %d cpus", nstate);

	/*
	 * Set the mask of cpus the userland scheduler is allowed to use.
	 */
	global_cpumask = (1L << nstate) - 1;
	sysctlbyname("kern.usched_global_cpumask", NULL, 0,
		     &global_cpumask, sizeof(global_cpumask));

	if (increasing) {
		domBeg = DomLimit;
		domEnd = dom;
	} else {
		domBeg = dom;
		domEnd = DomLimit;
	}
	DomLimit = dom;
	CpuLimit = nstate;

	/*
	 * Adjust the cpu frequency
	 */
	if (DebugOpt)
		printf("\n");
	for (dom = domBeg; dom < domEnd; ++dom) {
		/*
		 * Retrieve availability list
		 */
		asprintf(&sysid, "hw.acpi.cpu.px_dom%d.available", dom);
		buflen = sizeof(buf) - 1;
		v = sysctlbyname(sysid, buf, &buflen, NULL, 0);
		free(sysid);
		if (v < 0)
			continue;
		buf[buflen] = 0;

		/*
		 * Parse out the highest and lowest cpu frequencies
		 */
		ptr = buf;
		highest = lowest = 0;
		while (ptr && (v = strtol(ptr, &ptr, 10)) > 0) {
			if (lowest == 0 || lowest > v)
				lowest = v;
			if (highest == 0 || highest < v)
				highest = v;
		}

		/*
		 * Calculate the desired cpu frequency, test, and set.
		 */
		desired = increasing ? highest : lowest;

		asprintf(&sysid, "hw.acpi.cpu.px_dom%d.select", dom);
		buflen = sizeof(v);
		v = 0;
		sysctlbyname(sysid, &v, &buflen, NULL, 0);
		{
			if (DebugOpt) {
				printf("dom%d set frequency %d\n",
				       dom, desired);
			}
			sysctlbyname(sysid, NULL, NULL,
				     &desired, sizeof(desired));
		}
		free(sysid);
	}
}
/*
 * nstate is the requested number of cpus that we wish to run at full
 * frequency.  We calculate how many domains we have to adjust to reach
 * this goal.
 *
 * This function also sets the user scheduler global cpu mask.
 */
nstate is the requested number of cpus that we wish to run at full
frequency.  We calculate how many domains we have to adjust to reach
this goal.

This function also sets the user scheduler global cpu mask.
nstate is the requested number of cpus that we wish to run at full frequency . We calculate how many domains we have to adjust to reach this goal . This function also sets the user scheduler global cpu mask .
static
void
acpi_setcpufreq(int nstate)
{
	int ncpus = 0;
	int increasing = (nstate > CpuLimit);
	int dom;
	int domBeg;
	int domEnd;
	int lowest;
	int highest;
	int desired;
	int v;
	char *sysid;
	char *ptr;
	char buf[256];
	size_t buflen;
	cpumask_t global_cpumask;
	for (dom = DomBeg; dom < DomEnd; ++dom) {
		if (ncpus >= nstate)
			break;
		ncpus += CpuCount[dom];
	}
	syslog(LOG_INFO, "using %d cpus", nstate);
	global_cpumask = (1L << nstate) - 1;
	sysctlbyname("kern.usched_global_cpumask", NULL, 0,
		     &global_cpumask, sizeof(global_cpumask));
	if (increasing) {
		domBeg = DomLimit;
		domEnd = dom;
	} else {
		domBeg = dom;
		domEnd = DomLimit;
	}
	DomLimit = dom;
	CpuLimit = nstate;
	if (DebugOpt)
		printf("\n");
	for (dom = domBeg; dom < domEnd; ++dom) {
		asprintf(&sysid, "hw.acpi.cpu.px_dom%d.available", dom);
		buflen = sizeof(buf) - 1;
		v = sysctlbyname(sysid, buf, &buflen, NULL, 0);
		free(sysid);
		if (v < 0)
			continue;
		buf[buflen] = 0;
		ptr = buf;
		highest = lowest = 0;
		while (ptr && (v = strtol(ptr, &ptr, 10)) > 0) {
			if (lowest == 0 || lowest > v)
				lowest = v;
			if (highest == 0 || highest < v)
				highest = v;
		}
		desired = increasing ? highest : lowest;
		asprintf(&sysid, "hw.acpi.cpu.px_dom%d.select", dom);
		buflen = sizeof(v);
		v = 0;
		sysctlbyname(sysid, &v, &buflen, NULL, 0);
		{
			if (DebugOpt) {
				printf("dom%d set frequency %d\n",
				       dom, desired);
			}
			sysctlbyname(sysid, NULL, NULL,
				     &desired, sizeof(desired));
		}
		free(sysid);
	}
}
static void acpi_setcpufreq ( int nstate ) { int ncpus = 0 ; int increasing = ( nstate > CpuLimit ) ; int dom ; int domBeg ; int domEnd ; int lowest ; int highest ; int desired ; int v ; char * sysid ; char * ptr ; char buf [ 256 ] ; size_t buflen ; cpumask_t global_cpumask ; for ( dom = DomBeg ; dom < DomEnd ; ++ dom ) { if ( ncpus >= nstate ) break ; ncpus += CpuCount [ dom ] ; } syslog ( LOG_INFO , " " , nstate ) ; global_cpumask = ( 1L << nstate ) - 1 ; sysctlbyname ( " " , NULL , 0 , & global_cpumask , sizeof ( global_cpumask ) ) ; if ( increasing ) { domBeg = DomLimit ; domEnd = dom ; } else { domBeg = dom ; domEnd = DomLimit ; } DomLimit = dom ; CpuLimit = nstate ; if ( DebugOpt ) printf ( " \n " ) ; for ( dom = domBeg ; dom < domEnd ; ++ dom ) { asprintf ( & sysid , " " , dom ) ; buflen = sizeof ( buf ) - 1 ; v = sysctlbyname ( sysid , buf , & buflen , NULL , 0 ) ; free ( sysid ) ; if ( v < 0 ) continue ; buf [ buflen ] = 0 ; ptr = buf ; highest = lowest = 0 ; while ( ptr && ( v = strtol ( ptr , & ptr , 10 ) ) > 0 ) { if ( lowest == 0 || lowest > v ) lowest = v ; if ( highest == 0 || highest < v ) highest = v ; } desired = increasing ? highest : lowest ; asprintf ( & sysid , " " , dom ) ; buflen = sizeof ( v ) ; v = 0 ; sysctlbyname ( sysid , & v , & buflen , NULL , 0 ) ; { if ( DebugOpt ) { printf ( " \n " , dom , desired ) ; } sysctlbyname ( sysid , NULL , NULL , & desired , sizeof ( desired ) ) ; } free ( sysid ) ; } }
nstate is the requested number of cpus that we wish to run at full
 frequency.
nstate is the requested number of cpus that we wish to run at full frequency .
/*
	 * Calculate the ending domain if the number of operating cpus
	 * has increased.
	 *
	 * Calculate the starting domain if the number of operating cpus
	 * has decreased.
	 */ /*
	 * Set the mask of cpus the userland scheduler is allowed to use.
	 */ /*
	 * Adjust the cpu frequency
	 */ /*
		 * Retrieve availability list
		 */ /*
		 * Parse out the highest and lowest cpu frequencies
		 */ /*
		 * Calculate the desired cpu frequency, test, and set.
		 */