/* Common sysfs tunables */ /* * sampling_rate_store - update sampling rate effective immediately if needed. * * If new rate is smaller than the old, simply updating * dbs.sampling_rate might not be appropriate. For example, if the * original sampling_rate was 1 second and the requested new sampling rate is 10 * ms because the user needs immediate reaction from ondemand governor, but not * sure if higher frequency will be required or not, then, the governor may * change the sampling rate too late; up to 1 second later. Thus, if we are * reducing the sampling rate, we need to make the new value effective * immediately. * * This must be called with dbs_data->mutex held, otherwise traversing * policy_dbs_list isn't safe.
*/
ssize_t sampling_rate_store(struct gov_attr_set *attr_set, constchar *buf,
size_t count)
{ struct dbs_data *dbs_data = to_dbs_data(attr_set); struct policy_dbs_info *policy_dbs; unsignedint sampling_interval; int ret;
ret = sscanf(buf, "%u", &sampling_interval); if (ret != 1 || sampling_interval < CPUFREQ_DBS_MIN_SAMPLING_INTERVAL) return -EINVAL;
dbs_data->sampling_rate = sampling_interval;
/* * We are operating under dbs_data->mutex and so the list and its * entries can't be freed concurrently.
*/
list_for_each_entry(policy_dbs, &attr_set->policy_list, list) {
mutex_lock(&policy_dbs->update_mutex); /* * On 32-bit architectures this may race with the * sample_delay_ns read in dbs_update_util_handler(), but that * really doesn't matter. If the read returns a value that's * too big, the sample will be skipped, but the next invocation * of dbs_update_util_handler() (when the update has been * completed) will take a sample. * * If this runs in parallel with dbs_work_handler(), we may end * up overwriting the sample_delay_ns value that it has just * written, but it will be corrected next time a sample is * taken, so it shouldn't be significant.
*/
gov_update_sample_delay(policy_dbs, 0);
mutex_unlock(&policy_dbs->update_mutex);
}
/** * gov_update_cpu_data - Update CPU load data. * @dbs_data: Top-level governor data pointer. * * Update CPU load data for all CPUs in the domain governed by @dbs_data * (that may be a single policy or a bunch of them if governor tunables are * system-wide). * * Call under the @dbs_data mutex.
*/ void gov_update_cpu_data(struct dbs_data *dbs_data)
{ struct policy_dbs_info *policy_dbs;
/* * Sometimes governors may use an additional multiplier to increase * sample delays temporarily. Apply that multiplier to sampling_rate * so as to keep the wake-up-from-idle detection logic a bit * conservative.
*/
sampling_rate = dbs_data->sampling_rate * policy_dbs->rate_mult; /* * For the purpose of ondemand, waiting for disk IO is an indication * that you're performance critical, and not that the system is actually * idle, so do not add the iowait time to the CPU idle time then.
*/
io_busy = dbs_data->io_is_busy;
/* * cur_idle_time could be smaller than j_cdbs->prev_cpu_idle if * it's obtained from get_cpu_idle_time_jiffy() when NOHZ is * off, where idle_time is calculated by the difference between * time elapsed in jiffies and "busy time" obtained from CPU * statistics. If a CPU is 100% busy, the time elapsed and busy * time should grow with the same amount in two consecutive * samples, but in practice there could be a tiny difference, * making the accumulated idle time decrease sometimes. Hence, * in this case, idle_time should be regarded as 0 in order to * make the further process correct.
*/ if (cur_idle_time > j_cdbs->prev_cpu_idle)
idle_time = cur_idle_time - j_cdbs->prev_cpu_idle; else
idle_time = 0;
j_cdbs->prev_cpu_idle = cur_idle_time;
if (ignore_nice) {
u64 cur_nice = kcpustat_field(&kcpustat_cpu(j), CPUTIME_NICE, j);
if (unlikely(!time_elapsed)) { /* * That can only happen when this function is called * twice in a row with a very short interval between the * calls, so the previous load value can be used then.
*/
load = j_cdbs->prev_load;
} elseif (unlikely(idle_time > 2 * sampling_rate &&
j_cdbs->prev_load)) { /* * If the CPU had gone completely idle and a task has * just woken up on this CPU now, it would be unfair to * calculate 'load' the usual way for this elapsed * time-window, because it would show near-zero load, * irrespective of how CPU intensive that task actually * was. This is undesirable for latency-sensitive bursty * workloads. * * To avoid this, reuse the 'load' from the previous * time-window and give this task a chance to start with * a reasonably high CPU frequency. However, that * shouldn't be over-done, lest we get stuck at a high * load (high frequency) for too long, even when the * current system load has actually dropped down, so * clear prev_load to guarantee that the load will be * computed again next time. * * Detecting this situation is easy: an unusually large * 'idle_time' (as compared to the sampling rate) * indicates this scenario.
*/
load = j_cdbs->prev_load;
j_cdbs->prev_load = 0;
} else { if (time_elapsed > idle_time)
load = 100 * (time_elapsed - idle_time) / time_elapsed; else
load = 0;
j_cdbs->prev_load = load;
}
if (unlikely(idle_time > 2 * sampling_rate)) { unsignedint periods = idle_time / sampling_rate;
if (periods < idle_periods)
idle_periods = periods;
}
/* * Make sure cpufreq_governor_limits() isn't evaluating load or the * ondemand governor isn't updating the sampling rate in parallel.
*/
mutex_lock(&policy_dbs->update_mutex);
gov_update_sample_delay(policy_dbs, gov->gov_dbs_update(policy));
mutex_unlock(&policy_dbs->update_mutex);
/* Allow the utilization update handler to queue up more work. */
atomic_set(&policy_dbs->work_count, 0); /* * If the update below is reordered with respect to the sample delay * modification, the utilization update handler may end up using a stale * sample delay value.
*/
smp_wmb();
policy_dbs->work_in_progress = false;
}
if (!cpufreq_this_cpu_can_update(policy_dbs->policy)) return;
/* * The work may not be allowed to be queued up right now. * Possible reasons: * - Work has already been queued up or is in progress. * - It is too early (too little time from the previous sample).
*/ if (policy_dbs->work_in_progress) return;
/* * If the reads below are reordered before the check above, the value * of sample_delay_ns used in the computation may be stale.
*/
smp_rmb();
lst = READ_ONCE(policy_dbs->last_sample_time);
delta_ns = time - lst; if ((s64)delta_ns < policy_dbs->sample_delay_ns) return;
/* * If the policy is not shared, the irq_work may be queued up right away * at this point. Otherwise, we need to ensure that only one of the * CPUs sharing the policy will do that.
*/ if (policy_dbs->is_shared) { if (!atomic_add_unless(&policy_dbs->work_count, 1, 1)) return;
/* * If another CPU updated last_sample_time in the meantime, we * shouldn't be here, so clear the work counter and bail out.
*/ if (unlikely(lst != READ_ONCE(policy_dbs->last_sample_time))) {
atomic_set(&policy_dbs->work_count, 0); return;
}
}
ret = gov->init(dbs_data); if (ret) goto free_dbs_data;
/* * The sampling interval should not be less than the transition latency * of the CPU and it also cannot be too small for dbs_update() to work * correctly.
*/
dbs_data->sampling_rate = max_t(unsignedint,
CPUFREQ_DBS_MIN_SAMPLING_INTERVAL,
cpufreq_policy_transition_delay_us(policy));
if (!have_governor_per_policy())
gov->gdbs_data = dbs_data;
j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time, io_busy); /* * Make the first invocation of dbs_update() compute the load.
*/
j_cdbs->prev_load = 0;
if (ignore_nice)
j_cdbs->prev_cpu_nice = kcpustat_field(&kcpustat_cpu(j), CPUTIME_NICE, j);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.