@@ -104,6 +104,10 @@ static int levels_mib[4]; static int acline_mib[4]; static size_t acline_mib_len; +/* GJ - hw.ncpu (only the first int is set?) */ +static int nsmt_mib[4]; +/* GJ - hw.ncpu from the mib */ +static int nsmt; /* Configuration */ static int cpu_running_mark; @@ -497,6 +501,8 @@ uint64_t mjoules_used; size_t len; int nonice; + /* GJ */ + int tload; /* Default mode for all AC states is adaptive. */ mode_ac = mode_none = MODE_HIADAPTIVE; @@ -594,6 +600,19 @@ if (sysctlnametomib("dev.cpu.0.freq_levels", levels_mib, &len)) err(1, "lookup freq_levels"); + /* GJ */ + len = 4; + /* sysctlnametomib() did not work */ + if (sysctlbyname("hw.ncpu", nsmt_mib, &len, NULL, 0)) + err(1, "lookup hw.ncpu"); + nsmt = nsmt_mib[0]; +#ifdef DEBUG + printf("hw.ncpu %d\n", nsmt); +#endif + /* prob no advantage to use scaling with so few SMTs */ + if (nsmt <= 4) + nsmt = 1; + /* Check if we can read the load and supported freqs. */ if (read_usage_times(NULL, nonice)) err(1, "read_usage_times"); @@ -777,12 +796,14 @@ } /* Adaptive mode; get the current CPU usage times. */ - if (read_usage_times(&load, nonice)) { + if (read_usage_times(&tload, nonice)) { if (vflag) warn("read_usage_times() failed"); continue; } + /* GJ - nsmt == hw.ncpu IFF > 4, else 1 */ + load = tload/nsmt; if (mode == MODE_ADAPTIVE) { if (load > cpu_running_mark) { if (load > 95 || load > cpu_running_mark * 2)