![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0 0002 /* 0003 * Scheduler code and data structures related to cpufreq. 0004 * 0005 * Copyright (C) 2016, Intel Corporation 0006 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 0007 */ 0008 0009 DEFINE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data); 0010 0011 /** 0012 * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer. 0013 * @cpu: The CPU to set the pointer for. 0014 * @data: New pointer value. 0015 * @func: Callback function to set for the CPU. 0016 * 0017 * Set and publish the update_util_data pointer for the given CPU. 0018 * 0019 * The update_util_data pointer of @cpu is set to @data and the callback 0020 * function pointer in the target struct update_util_data is set to @func. 0021 * That function will be called by cpufreq_update_util() from RCU-sched 0022 * read-side critical sections, so it must not sleep. @data will always be 0023 * passed to it as the first argument which allows the function to get to the 0024 * target update_util_data structure and its container. 0025 * 0026 * The update_util_data pointer of @cpu must be NULL when this function is 0027 * called or it will WARN() and return with no effect. 0028 */ 0029 void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, 0030 void (*func)(struct update_util_data *data, u64 time, 0031 unsigned int flags)) 0032 { 0033 if (WARN_ON(!data || !func)) 0034 return; 0035 0036 if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu))) 0037 return; 0038 0039 data->func = func; 0040 rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data); 0041 } 0042 EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook); 0043 0044 /** 0045 * cpufreq_remove_update_util_hook - Clear the CPU's update_util_data pointer. 0046 * @cpu: The CPU to clear the pointer for. 0047 * 0048 * Clear the update_util_data pointer for the given CPU. 0049 * 0050 * Callers must use RCU callbacks to free any memory that might be 0051 * accessed via the old update_util_data pointer or invoke synchronize_rcu() 0052 * right after this function to avoid use-after-free. 0053 */ 0054 void cpufreq_remove_update_util_hook(int cpu) 0055 { 0056 rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), NULL); 0057 } 0058 EXPORT_SYMBOL_GPL(cpufreq_remove_update_util_hook); 0059 0060 /** 0061 * cpufreq_this_cpu_can_update - Check if cpufreq policy can be updated. 0062 * @policy: cpufreq policy to check. 0063 * 0064 * Return 'true' if: 0065 * - the local and remote CPUs share @policy, 0066 * - dvfs_possible_from_any_cpu is set in @policy and the local CPU is not going 0067 * offline (in which case it is not expected to run cpufreq updates any more). 0068 */ 0069 bool cpufreq_this_cpu_can_update(struct cpufreq_policy *policy) 0070 { 0071 return cpumask_test_cpu(smp_processor_id(), policy->cpus) || 0072 (policy->dvfs_possible_from_any_cpu && 0073 rcu_dereference_sched(*this_cpu_ptr(&cpufreq_update_util_data))); 0074 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |