cpufreq.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Scheduler code and data structures related to cpufreq.
  3. *
  4. * Copyright (C) 2016, Intel Corporation
  5. * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include "sched.h"
  12. DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
  13. /**
  14. * cpufreq_set_update_util_data - Populate the CPU's update_util_data pointer.
  15. * @cpu: The CPU to set the pointer for.
  16. * @data: New pointer value.
  17. *
  18. * Set and publish the update_util_data pointer for the given CPU. That pointer
  19. * points to a struct update_util_data object containing a callback function
  20. * to call from cpufreq_update_util(). That function will be called from an RCU
  21. * read-side critical section, so it must not sleep.
  22. *
  23. * Callers must use RCU-sched callbacks to free any memory that might be
  24. * accessed via the old update_util_data pointer or invoke synchronize_sched()
  25. * right after this function to avoid use-after-free.
  26. */
  27. void cpufreq_set_update_util_data(int cpu, struct update_util_data *data)
  28. {
  29. if (WARN_ON(data && !data->func))
  30. return;
  31. rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);
  32. }
  33. EXPORT_SYMBOL_GPL(cpufreq_set_update_util_data);