From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760257AbcBYJIx (ORCPT ); Thu, 25 Feb 2016 04:08:53 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:36046 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759156AbcBYJIr (ORCPT ); Thu, 25 Feb 2016 04:08:47 -0500 Date: Thu, 25 Feb 2016 10:08:40 +0100 From: Peter Zijlstra To: "Rafael J. Wysocki" Cc: Linux PM list , Juri Lelli , Linux Kernel Mailing List , Viresh Kumar , Srinivas Pandruvada , Steve Muckle , Ingo Molnar Subject: Re: [RFC/RFT][PATCH v3 2/2] cpufreq: schedutil: Switching frequencies from interrupt context Message-ID: <20160225090840.GB6357@twins.programming.kicks-ass.net> References: <5059413.77KZsd2lep@vostro.rjw.lan> <1810564.h98CMnhalE@vostro.rjw.lan> <1597360.X9ARIiUr5r@vostro.rjw.lan> <1522086.TRnWVDkbTk@vostro.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522086.TRnWVDkbTk@vostro.rjw.lan> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 25, 2016 at 12:30:43AM +0100, Rafael J. Wysocki wrote: > +unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy, > + unsigned int target_freq) > +{ > + struct acpi_cpufreq_data *data = policy->driver_data; > + struct cpufreq_frequency_table *entry; > + struct acpi_processor_performance *perf; > + unsigned int uninitialized_var(next_perf_state); > + unsigned int uninitialized_var(next_freq); > + unsigned int best_diff; > + > + for (entry = data->freq_table, best_diff = UINT_MAX; > + entry->frequency != CPUFREQ_TABLE_END; entry++) { > + unsigned int diff, freq = entry->frequency; > + > + if (freq == CPUFREQ_ENTRY_INVALID) > + continue; > + > + diff = abs(freq - target_freq); Why would you consider frequencies that are below where you want to be? > + if (diff >= best_diff) > + continue; > + > + best_diff = diff; > + next_perf_state = entry->driver_data; > + next_freq = freq; > + if (best_diff == 0) > + goto found; > + } > + if (best_diff == UINT_MAX) > + return CPUFREQ_ENTRY_INVALID; > + > + found: > + perf = to_perf_data(data); > + if (perf->state == next_perf_state) { > + if (unlikely(data->resume)) > + data->resume = 0; > + else > + return next_freq; > + } > + > + data->cpu_freq_fast_write(perf->states[next_perf_state].control); > + perf->state = next_perf_state; > + return next_freq; > +}