Lines Matching +full:switch +full:- +full:freq +full:- +full:select
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
98 static int set_freq(int freq);
135 static int apm_fd = -1;
137 static int devd_pipe = -1;
147 * threads are processing requests as a pipeline -- running one at
185 total += cp_times[cpu * CPUSTATES + i] - in read_usage_times()
190 excl = cp_times[cpu * CPUSTATES + CP_IDLE] - in read_usage_times()
193 excl += cp_times[cpu * CPUSTATES + CP_NICE] - in read_usage_times()
195 *load += 100 - excl * 100 / total; in read_usage_times()
212 return (-1); in read_freqs()
214 return (-1); in read_freqs()
217 return (-1); in read_freqs()
227 return (-1); in read_freqs()
232 return (-1); in read_freqs()
242 return (-1); in read_freqs()
244 if (((*freqs)[j] >= minfreq || minfreq == -1) && in read_freqs()
245 ((*freqs)[j] <= maxfreq || maxfreq == -1)) in read_freqs()
255 return (-1); in read_freqs()
278 set_freq(int freq) in set_freq() argument
281 if (sysctl(freq_mib, 4, NULL, NULL, &freq, sizeof(freq))) { in set_freq()
283 return (-1); in set_freq()
290 get_freq_id(int freq, int *freqs, int numfreqs) in get_freq_id() argument
295 if (freqs[i] < freq) in get_freq_id()
299 return (i - 1); in get_freq_id()
370 if (hdr != NULL && hdr->nlmsg_type != NLMSG_ERROR) {
422 apm_fd = -1;
481 if (strcmp(attrs.mcast_groups.groups[i]->mcast_grp_name,
485 &attrs.mcast_groups.groups[i]->mcast_grp_id,
486 sizeof(attrs.mcast_groups.groups[i]->mcast_grp_id))
487 == -1) {
505 return (-1);
511 sizeof(devd_addr)) == -1) {
515 devd_pipe = -1;
516 return (-1);
527 devd_pipe = -1;
543 errx(1, "bad option: -%c %s", (char)ch, optarg);
560 errx(1, "bad option: -%c %s", (char)ch, optarg);
575 "usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-N] [-n mode] [-p ival] [-r %%…
587 int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load; local
588 int minfreq = -1, maxfreq = -1;
608 while ((ch = getopt(argc, argv, "a:b:i:m:M:Nn:p:P:r:s:v")) != -1)
609 switch (ch) {
684 if (sysctlnametomib("dev.cpu.0.freq", freq_mib, &len))
685 err(EX_UNAVAILABLE, "no cpufreq(4) support -- aborting");
696 errx(1, "no CPU frequencies in user-specified range");
728 freq = initfreq = curfreq = get_freq();
730 if (freq < 1)
731 freq = 1;
735 * user-defined range, adjust it to be within the user-defined range.
752 if (curfreq < freqs[numfreqs - 1]) {
754 printf("CPU frequency is below user-defined "
756 "MHz\n", freqs[numfreqs - 1]);
758 if (set_freq(freqs[numfreqs - 1]) != 0) {
759 warn("error setting CPU freq %d",
760 freqs[numfreqs - 1]);
764 printf("CPU frequency is above user-defined "
769 warn("error setting CPU freq %d",
796 rfds = select(nfds, &fdset, NULL, &fdset, &timeout);
809 switch (acline_status) {
832 if (mwatts[i] != -1)
837 /* Always switch to the lowest frequency in min mode. */
839 freq = freqs[numfreqs - 1];
840 if (curfreq != freq) {
844 modes[acline_status], freq);
847 if (set_freq(freq) != 0) {
848 warn("error setting CPU freq %d",
849 freq);
856 /* Always switch to the highest frequency in max mode. */
858 freq = freqs[0];
859 if (curfreq != freq) {
863 modes[acline_status], freq);
866 if (set_freq(freq) != 0) {
867 warn("error setting CPU freq %d",
868 freq);
885 freq *= 2;
887 freq = freq * load / cpu_running_mark;
888 if (freq > freqs[0])
889 freq = freqs[0];
892 freq * 7 / 8, freqs, numfreqs)] *
894 freq = freq * 7 / 8;
895 if (freq < freqs[numfreqs - 1])
896 freq = freqs[numfreqs - 1];
901 freq *= 4;
903 freq = freq * load * 2 / cpu_running_mark;
904 if (freq > freqs[0] * 2)
905 freq = freqs[0] * 2;
908 freq * 31 / 32, freqs, numfreqs)] *
910 freq = freq * 31 / 32;
911 if (freq < freqs[numfreqs - 1])
912 freq = freqs[numfreqs - 1];
916 printf("load %3d%%, current freq %4d MHz (%2d), wanted freq %4d MHz\n",
917 load, curfreq, i, freq);
919 j = get_freq_id(freq, freqs, numfreqs);