mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
ecae0bd517
included in this merge do the following: - Kemeng Shi has contributed some compation maintenance work in the series "Fixes and cleanups to compaction". - Joel Fernandes has a patchset ("Optimize mremap during mutual alignment within PMD") which fixes an obscure issue with mremap()'s pagetable handling during a subsequent exec(), based upon an implementation which Linus suggested. - More DAMON/DAMOS maintenance and feature work from SeongJae Park i the following patch series: mm/damon: misc fixups for documents, comments and its tracepoint mm/damon: add a tracepoint for damos apply target regions mm/damon: provide pseudo-moving sum based access rate mm/damon: implement DAMOS apply intervals mm/damon/core-test: Fix memory leaks in core-test mm/damon/sysfs-schemes: Do DAMOS tried regions update for only one apply interval - In the series "Do not try to access unaccepted memory" Adrian Hunter provides some fixups for the recently-added "unaccepted memory' feature. To increase the feature's checking coverage. "Plug a few gaps where RAM is exposed without checking if it is unaccepted memory". - In the series "cleanups for lockless slab shrink" Qi Zheng has done some maintenance work which is preparation for the lockless slab shrinking code. - Qi Zheng has redone the earlier (and reverted) attempt to make slab shrinking lockless in the series "use refcount+RCU method to implement lockless slab shrink". - David Hildenbrand contributes some maintenance work for the rmap code in the series "Anon rmap cleanups". - Kefeng Wang does more folio conversions and some maintenance work in the migration code. Series "mm: migrate: more folio conversion and unification". - Matthew Wilcox has fixed an issue in the buffer_head code which was causing long stalls under some heavy memory/IO loads. Some cleanups were added on the way. Series "Add and use bdev_getblk()". - In the series "Use nth_page() in place of direct struct page manipulation" Zi Yan has fixed a potential issue with the direct manipulation of hugetlb page frames. - In the series "mm: hugetlb: Skip initialization of gigantic tail struct pages if freed by HVO" has improved our handling of gigantic pages in the hugetlb vmmemmep optimizaton code. This provides significant boot time improvements when significant amounts of gigantic pages are in use. - Matthew Wilcox has sent the series "Small hugetlb cleanups" - code rationalization and folio conversions in the hugetlb code. - Yin Fengwei has improved mlock()'s handling of large folios in the series "support large folio for mlock" - In the series "Expose swapcache stat for memcg v1" Liu Shixin has added statistics for memcg v1 users which are available (and useful) under memcg v2. - Florent Revest has enhanced the MDWE (Memory-Deny-Write-Executable) prctl so that userspace may direct the kernel to not automatically propagate the denial to child processes. The series is named "MDWE without inheritance". - Kefeng Wang has provided the series "mm: convert numa balancing functions to use a folio" which does what it says. - In the series "mm/ksm: add fork-exec support for prctl" Stefan Roesch makes is possible for a process to propagate KSM treatment across exec(). - Huang Ying has enhanced memory tiering's calculation of memory distances. This is used to permit the dax/kmem driver to use "high bandwidth memory" in addition to Optane Data Center Persistent Memory Modules (DCPMM). The series is named "memory tiering: calculate abstract distance based on ACPI HMAT" - In the series "Smart scanning mode for KSM" Stefan Roesch has optimized KSM by teaching it to retain and use some historical information from previous scans. - Yosry Ahmed has fixed some inconsistencies in memcg statistics in the series "mm: memcg: fix tracking of pending stats updates values". - In the series "Implement IOCTL to get and optionally clear info about PTEs" Peter Xu has added an ioctl to /proc/<pid>/pagemap which permits us to atomically read-then-clear page softdirty state. This is mainly used by CRIU. - Hugh Dickins contributed the series "shmem,tmpfs: general maintenance" - a bunch of relatively minor maintenance tweaks to this code. - Matthew Wilcox has increased the use of the VMA lock over file-backed page faults in the series "Handle more faults under the VMA lock". Some rationalizations of the fault path became possible as a result. - In the series "mm/rmap: convert page_move_anon_rmap() to folio_move_anon_rmap()" David Hildenbrand has implemented some cleanups and folio conversions. - In the series "various improvements to the GUP interface" Lorenzo Stoakes has simplified and improved the GUP interface with an eye to providing groundwork for future improvements. - Andrey Konovalov has sent along the series "kasan: assorted fixes and improvements" which does those things. - Some page allocator maintenance work from Kemeng Shi in the series "Two minor cleanups to break_down_buddy_pages". - In thes series "New selftest for mm" Breno Leitao has developed another MM self test which tickles a race we had between madvise() and page faults. - In the series "Add folio_end_read" Matthew Wilcox provides cleanups and an optimization to the core pagecache code. - Nhat Pham has added memcg accounting for hugetlb memory in the series "hugetlb memcg accounting". - Cleanups and rationalizations to the pagemap code from Lorenzo Stoakes, in the series "Abstract vma_merge() and split_vma()". - Audra Mitchell has fixed issues in the procfs page_owner code's new timestamping feature which was causing some misbehaviours. In the series "Fix page_owner's use of free timestamps". - Lorenzo Stoakes has fixed the handling of new mappings of sealed files in the series "permit write-sealed memfd read-only shared mappings". - Mike Kravetz has optimized the hugetlb vmemmap optimization in the series "Batch hugetlb vmemmap modification operations". - Some buffer_head folio conversions and cleanups from Matthew Wilcox in the series "Finish the create_empty_buffers() transition". - As a page allocator performance optimization Huang Ying has added automatic tuning to the allocator's per-cpu-pages feature, in the series "mm: PCP high auto-tuning". - Roman Gushchin has contributed the patchset "mm: improve performance of accounted kernel memory allocations" which improves their performance by ~30% as measured by a micro-benchmark. - folio conversions from Kefeng Wang in the series "mm: convert page cpupid functions to folios". - Some kmemleak fixups in Liu Shixin's series "Some bugfix about kmemleak". - Qi Zheng has improved our handling of memoryless nodes by keeping them off the allocation fallback list. This is done in the series "handle memoryless nodes more appropriately". - khugepaged conversions from Vishal Moola in the series "Some khugepaged folio conversions". -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQTTMBEPP41GrTpTJgfdBJ7gKXxAjgUCZULEMwAKCRDdBJ7gKXxA jhQHAQCYpD3g849x69DmHnHWHm/EHQLvQmRMDeYZI+nx/sCJOwEAw4AKg0Oemv9y FgeUPAD1oasg6CP+INZvCj34waNxwAc= =E+Y4 -----END PGP SIGNATURE----- Merge tag 'mm-stable-2023-11-01-14-33' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull MM updates from Andrew Morton: "Many singleton patches against the MM code. The patch series which are included in this merge do the following: - Kemeng Shi has contributed some compation maintenance work in the series 'Fixes and cleanups to compaction' - Joel Fernandes has a patchset ('Optimize mremap during mutual alignment within PMD') which fixes an obscure issue with mremap()'s pagetable handling during a subsequent exec(), based upon an implementation which Linus suggested - More DAMON/DAMOS maintenance and feature work from SeongJae Park i the following patch series: mm/damon: misc fixups for documents, comments and its tracepoint mm/damon: add a tracepoint for damos apply target regions mm/damon: provide pseudo-moving sum based access rate mm/damon: implement DAMOS apply intervals mm/damon/core-test: Fix memory leaks in core-test mm/damon/sysfs-schemes: Do DAMOS tried regions update for only one apply interval - In the series 'Do not try to access unaccepted memory' Adrian Hunter provides some fixups for the recently-added 'unaccepted memory' feature. To increase the feature's checking coverage. 'Plug a few gaps where RAM is exposed without checking if it is unaccepted memory' - In the series 'cleanups for lockless slab shrink' Qi Zheng has done some maintenance work which is preparation for the lockless slab shrinking code - Qi Zheng has redone the earlier (and reverted) attempt to make slab shrinking lockless in the series 'use refcount+RCU method to implement lockless slab shrink' - David Hildenbrand contributes some maintenance work for the rmap code in the series 'Anon rmap cleanups' - Kefeng Wang does more folio conversions and some maintenance work in the migration code. Series 'mm: migrate: more folio conversion and unification' - Matthew Wilcox has fixed an issue in the buffer_head code which was causing long stalls under some heavy memory/IO loads. Some cleanups were added on the way. Series 'Add and use bdev_getblk()' - In the series 'Use nth_page() in place of direct struct page manipulation' Zi Yan has fixed a potential issue with the direct manipulation of hugetlb page frames - In the series 'mm: hugetlb: Skip initialization of gigantic tail struct pages if freed by HVO' has improved our handling of gigantic pages in the hugetlb vmmemmep optimizaton code. This provides significant boot time improvements when significant amounts of gigantic pages are in use - Matthew Wilcox has sent the series 'Small hugetlb cleanups' - code rationalization and folio conversions in the hugetlb code - Yin Fengwei has improved mlock()'s handling of large folios in the series 'support large folio for mlock' - In the series 'Expose swapcache stat for memcg v1' Liu Shixin has added statistics for memcg v1 users which are available (and useful) under memcg v2 - Florent Revest has enhanced the MDWE (Memory-Deny-Write-Executable) prctl so that userspace may direct the kernel to not automatically propagate the denial to child processes. The series is named 'MDWE without inheritance' - Kefeng Wang has provided the series 'mm: convert numa balancing functions to use a folio' which does what it says - In the series 'mm/ksm: add fork-exec support for prctl' Stefan Roesch makes is possible for a process to propagate KSM treatment across exec() - Huang Ying has enhanced memory tiering's calculation of memory distances. This is used to permit the dax/kmem driver to use 'high bandwidth memory' in addition to Optane Data Center Persistent Memory Modules (DCPMM). The series is named 'memory tiering: calculate abstract distance based on ACPI HMAT' - In the series 'Smart scanning mode for KSM' Stefan Roesch has optimized KSM by teaching it to retain and use some historical information from previous scans - Yosry Ahmed has fixed some inconsistencies in memcg statistics in the series 'mm: memcg: fix tracking of pending stats updates values' - In the series 'Implement IOCTL to get and optionally clear info about PTEs' Peter Xu has added an ioctl to /proc/<pid>/pagemap which permits us to atomically read-then-clear page softdirty state. This is mainly used by CRIU - Hugh Dickins contributed the series 'shmem,tmpfs: general maintenance', a bunch of relatively minor maintenance tweaks to this code - Matthew Wilcox has increased the use of the VMA lock over file-backed page faults in the series 'Handle more faults under the VMA lock'. Some rationalizations of the fault path became possible as a result - In the series 'mm/rmap: convert page_move_anon_rmap() to folio_move_anon_rmap()' David Hildenbrand has implemented some cleanups and folio conversions - In the series 'various improvements to the GUP interface' Lorenzo Stoakes has simplified and improved the GUP interface with an eye to providing groundwork for future improvements - Andrey Konovalov has sent along the series 'kasan: assorted fixes and improvements' which does those things - Some page allocator maintenance work from Kemeng Shi in the series 'Two minor cleanups to break_down_buddy_pages' - In thes series 'New selftest for mm' Breno Leitao has developed another MM self test which tickles a race we had between madvise() and page faults - In the series 'Add folio_end_read' Matthew Wilcox provides cleanups and an optimization to the core pagecache code - Nhat Pham has added memcg accounting for hugetlb memory in the series 'hugetlb memcg accounting' - Cleanups and rationalizations to the pagemap code from Lorenzo Stoakes, in the series 'Abstract vma_merge() and split_vma()' - Audra Mitchell has fixed issues in the procfs page_owner code's new timestamping feature which was causing some misbehaviours. In the series 'Fix page_owner's use of free timestamps' - Lorenzo Stoakes has fixed the handling of new mappings of sealed files in the series 'permit write-sealed memfd read-only shared mappings' - Mike Kravetz has optimized the hugetlb vmemmap optimization in the series 'Batch hugetlb vmemmap modification operations' - Some buffer_head folio conversions and cleanups from Matthew Wilcox in the series 'Finish the create_empty_buffers() transition' - As a page allocator performance optimization Huang Ying has added automatic tuning to the allocator's per-cpu-pages feature, in the series 'mm: PCP high auto-tuning' - Roman Gushchin has contributed the patchset 'mm: improve performance of accounted kernel memory allocations' which improves their performance by ~30% as measured by a micro-benchmark - folio conversions from Kefeng Wang in the series 'mm: convert page cpupid functions to folios' - Some kmemleak fixups in Liu Shixin's series 'Some bugfix about kmemleak' - Qi Zheng has improved our handling of memoryless nodes by keeping them off the allocation fallback list. This is done in the series 'handle memoryless nodes more appropriately' - khugepaged conversions from Vishal Moola in the series 'Some khugepaged folio conversions'" [ bcachefs conflicts with the dynamically allocated shrinkers have been resolved as per Stephen Rothwell in https://lore.kernel.org/all/20230913093553.4290421e@canb.auug.org.au/ with help from Qi Zheng. The clone3 test filtering conflict was half-arsed by yours truly ] * tag 'mm-stable-2023-11-01-14-33' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (406 commits) mm/damon/sysfs: update monitoring target regions for online input commit mm/damon/sysfs: remove requested targets when online-commit inputs selftests: add a sanity check for zswap Documentation: maple_tree: fix word spelling error mm/vmalloc: fix the unchecked dereference warning in vread_iter() zswap: export compression failure stats Documentation: ubsan: drop "the" from article title mempolicy: migration attempt to match interleave nodes mempolicy: mmap_lock is not needed while migrating folios mempolicy: alloc_pages_mpol() for NUMA policy without vma mm: add page_rmappable_folio() wrapper mempolicy: remove confusing MPOL_MF_LAZY dead code mempolicy: mpol_shared_policy_init() without pseudo-vma mempolicy trivia: use pgoff_t in shared mempolicy tree mempolicy trivia: slightly more consistent naming mempolicy trivia: delete those ancient pr_debug()s mempolicy: fix migrate_pages(2) syscall return nr_failed kernfs: drop shared NUMA mempolicy hooks hugetlbfs: drop shared NUMA mempolicy pretence mm/damon/sysfs-test: add a unit test for damon_sysfs_set_targets() ...
483 lines
11 KiB
C
483 lines
11 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* acpi_pad.c ACPI Processor Aggregator Driver
|
|
*
|
|
* Copyright (c) 2009, Intel Corporation.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/cpumask.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/types.h>
|
|
#include <linux/kthread.h>
|
|
#include <uapi/linux/sched/types.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/tick.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/perf_event.h>
|
|
#include <linux/platform_device.h>
|
|
#include <asm/mwait.h>
|
|
#include <xen/xen.h>
|
|
|
|
#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
|
|
#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
|
|
#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
|
|
static DEFINE_MUTEX(isolated_cpus_lock);
|
|
static DEFINE_MUTEX(round_robin_lock);
|
|
|
|
static unsigned long power_saving_mwait_eax;
|
|
|
|
static unsigned char tsc_detected_unstable;
|
|
static unsigned char tsc_marked_unstable;
|
|
|
|
static void power_saving_mwait_init(void)
|
|
{
|
|
unsigned int eax, ebx, ecx, edx;
|
|
unsigned int highest_cstate = 0;
|
|
unsigned int highest_subcstate = 0;
|
|
int i;
|
|
|
|
if (!boot_cpu_has(X86_FEATURE_MWAIT))
|
|
return;
|
|
if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
|
|
return;
|
|
|
|
cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
|
|
|
|
if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
|
|
!(ecx & CPUID5_ECX_INTERRUPT_BREAK))
|
|
return;
|
|
|
|
edx >>= MWAIT_SUBSTATE_SIZE;
|
|
for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) {
|
|
if (edx & MWAIT_SUBSTATE_MASK) {
|
|
highest_cstate = i;
|
|
highest_subcstate = edx & MWAIT_SUBSTATE_MASK;
|
|
}
|
|
}
|
|
power_saving_mwait_eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) |
|
|
(highest_subcstate - 1);
|
|
|
|
#if defined(CONFIG_X86)
|
|
switch (boot_cpu_data.x86_vendor) {
|
|
case X86_VENDOR_HYGON:
|
|
case X86_VENDOR_AMD:
|
|
case X86_VENDOR_INTEL:
|
|
case X86_VENDOR_ZHAOXIN:
|
|
case X86_VENDOR_CENTAUR:
|
|
/*
|
|
* AMD Fam10h TSC will tick in all
|
|
* C/P/S0/S1 states when this bit is set.
|
|
*/
|
|
if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
|
|
tsc_detected_unstable = 1;
|
|
break;
|
|
default:
|
|
/* TSC could halt in idle */
|
|
tsc_detected_unstable = 1;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
static unsigned long cpu_weight[NR_CPUS];
|
|
static int tsk_in_cpu[NR_CPUS] = {[0 ... NR_CPUS-1] = -1};
|
|
static DECLARE_BITMAP(pad_busy_cpus_bits, NR_CPUS);
|
|
static void round_robin_cpu(unsigned int tsk_index)
|
|
{
|
|
struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
|
|
cpumask_var_t tmp;
|
|
int cpu;
|
|
unsigned long min_weight = -1;
|
|
unsigned long preferred_cpu;
|
|
|
|
if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
|
|
return;
|
|
|
|
mutex_lock(&round_robin_lock);
|
|
cpumask_clear(tmp);
|
|
for_each_cpu(cpu, pad_busy_cpus)
|
|
cpumask_or(tmp, tmp, topology_sibling_cpumask(cpu));
|
|
cpumask_andnot(tmp, cpu_online_mask, tmp);
|
|
/* avoid HT siblings if possible */
|
|
if (cpumask_empty(tmp))
|
|
cpumask_andnot(tmp, cpu_online_mask, pad_busy_cpus);
|
|
if (cpumask_empty(tmp)) {
|
|
mutex_unlock(&round_robin_lock);
|
|
free_cpumask_var(tmp);
|
|
return;
|
|
}
|
|
for_each_cpu(cpu, tmp) {
|
|
if (cpu_weight[cpu] < min_weight) {
|
|
min_weight = cpu_weight[cpu];
|
|
preferred_cpu = cpu;
|
|
}
|
|
}
|
|
|
|
if (tsk_in_cpu[tsk_index] != -1)
|
|
cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
|
|
tsk_in_cpu[tsk_index] = preferred_cpu;
|
|
cpumask_set_cpu(preferred_cpu, pad_busy_cpus);
|
|
cpu_weight[preferred_cpu]++;
|
|
mutex_unlock(&round_robin_lock);
|
|
|
|
set_cpus_allowed_ptr(current, cpumask_of(preferred_cpu));
|
|
|
|
free_cpumask_var(tmp);
|
|
}
|
|
|
|
static void exit_round_robin(unsigned int tsk_index)
|
|
{
|
|
struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
|
|
|
|
cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
|
|
tsk_in_cpu[tsk_index] = -1;
|
|
}
|
|
|
|
static unsigned int idle_pct = 5; /* percentage */
|
|
static unsigned int round_robin_time = 1; /* second */
|
|
static int power_saving_thread(void *data)
|
|
{
|
|
int do_sleep;
|
|
unsigned int tsk_index = (unsigned long)data;
|
|
u64 last_jiffies = 0;
|
|
|
|
sched_set_fifo_low(current);
|
|
|
|
while (!kthread_should_stop()) {
|
|
unsigned long expire_time;
|
|
|
|
/* round robin to cpus */
|
|
expire_time = last_jiffies + round_robin_time * HZ;
|
|
if (time_before(expire_time, jiffies)) {
|
|
last_jiffies = jiffies;
|
|
round_robin_cpu(tsk_index);
|
|
}
|
|
|
|
do_sleep = 0;
|
|
|
|
expire_time = jiffies + HZ * (100 - idle_pct) / 100;
|
|
|
|
while (!need_resched()) {
|
|
if (tsc_detected_unstable && !tsc_marked_unstable) {
|
|
/* TSC could halt in idle, so notify users */
|
|
mark_tsc_unstable("TSC halts in idle");
|
|
tsc_marked_unstable = 1;
|
|
}
|
|
local_irq_disable();
|
|
|
|
perf_lopwr_cb(true);
|
|
|
|
tick_broadcast_enable();
|
|
tick_broadcast_enter();
|
|
stop_critical_timings();
|
|
|
|
mwait_idle_with_hints(power_saving_mwait_eax, 1);
|
|
|
|
start_critical_timings();
|
|
tick_broadcast_exit();
|
|
|
|
perf_lopwr_cb(false);
|
|
|
|
local_irq_enable();
|
|
|
|
if (time_before(expire_time, jiffies)) {
|
|
do_sleep = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* current sched_rt has threshold for rt task running time.
|
|
* When a rt task uses 95% CPU time, the rt thread will be
|
|
* scheduled out for 5% CPU time to not starve other tasks. But
|
|
* the mechanism only works when all CPUs have RT task running,
|
|
* as if one CPU hasn't RT task, RT task from other CPUs will
|
|
* borrow CPU time from this CPU and cause RT task use > 95%
|
|
* CPU time. To make 'avoid starvation' work, takes a nap here.
|
|
*/
|
|
if (unlikely(do_sleep))
|
|
schedule_timeout_killable(HZ * idle_pct / 100);
|
|
|
|
/* If an external event has set the need_resched flag, then
|
|
* we need to deal with it, or this loop will continue to
|
|
* spin without calling __mwait().
|
|
*/
|
|
if (unlikely(need_resched()))
|
|
schedule();
|
|
}
|
|
|
|
exit_round_robin(tsk_index);
|
|
return 0;
|
|
}
|
|
|
|
static struct task_struct *ps_tsks[NR_CPUS];
|
|
static unsigned int ps_tsk_num;
|
|
static int create_power_saving_task(void)
|
|
{
|
|
int rc;
|
|
|
|
ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
|
|
(void *)(unsigned long)ps_tsk_num,
|
|
"acpi_pad/%d", ps_tsk_num);
|
|
|
|
if (IS_ERR(ps_tsks[ps_tsk_num])) {
|
|
rc = PTR_ERR(ps_tsks[ps_tsk_num]);
|
|
ps_tsks[ps_tsk_num] = NULL;
|
|
} else {
|
|
rc = 0;
|
|
ps_tsk_num++;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static void destroy_power_saving_task(void)
|
|
{
|
|
if (ps_tsk_num > 0) {
|
|
ps_tsk_num--;
|
|
kthread_stop(ps_tsks[ps_tsk_num]);
|
|
ps_tsks[ps_tsk_num] = NULL;
|
|
}
|
|
}
|
|
|
|
static void set_power_saving_task_num(unsigned int num)
|
|
{
|
|
if (num > ps_tsk_num) {
|
|
while (ps_tsk_num < num) {
|
|
if (create_power_saving_task())
|
|
return;
|
|
}
|
|
} else if (num < ps_tsk_num) {
|
|
while (ps_tsk_num > num)
|
|
destroy_power_saving_task();
|
|
}
|
|
}
|
|
|
|
static void acpi_pad_idle_cpus(unsigned int num_cpus)
|
|
{
|
|
cpus_read_lock();
|
|
|
|
num_cpus = min_t(unsigned int, num_cpus, num_online_cpus());
|
|
set_power_saving_task_num(num_cpus);
|
|
|
|
cpus_read_unlock();
|
|
}
|
|
|
|
static uint32_t acpi_pad_idle_cpus_num(void)
|
|
{
|
|
return ps_tsk_num;
|
|
}
|
|
|
|
static ssize_t rrtime_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
unsigned long num;
|
|
|
|
if (kstrtoul(buf, 0, &num))
|
|
return -EINVAL;
|
|
if (num < 1 || num >= 100)
|
|
return -EINVAL;
|
|
mutex_lock(&isolated_cpus_lock);
|
|
round_robin_time = num;
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
return count;
|
|
}
|
|
|
|
static ssize_t rrtime_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return sysfs_emit(buf, "%d\n", round_robin_time);
|
|
}
|
|
static DEVICE_ATTR_RW(rrtime);
|
|
|
|
static ssize_t idlepct_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
unsigned long num;
|
|
|
|
if (kstrtoul(buf, 0, &num))
|
|
return -EINVAL;
|
|
if (num < 1 || num >= 100)
|
|
return -EINVAL;
|
|
mutex_lock(&isolated_cpus_lock);
|
|
idle_pct = num;
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
return count;
|
|
}
|
|
|
|
static ssize_t idlepct_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return sysfs_emit(buf, "%d\n", idle_pct);
|
|
}
|
|
static DEVICE_ATTR_RW(idlepct);
|
|
|
|
static ssize_t idlecpus_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
unsigned long num;
|
|
|
|
if (kstrtoul(buf, 0, &num))
|
|
return -EINVAL;
|
|
mutex_lock(&isolated_cpus_lock);
|
|
acpi_pad_idle_cpus(num);
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
return count;
|
|
}
|
|
|
|
static ssize_t idlecpus_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return cpumap_print_to_pagebuf(false, buf,
|
|
to_cpumask(pad_busy_cpus_bits));
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(idlecpus);
|
|
|
|
static struct attribute *acpi_pad_attrs[] = {
|
|
&dev_attr_idlecpus.attr,
|
|
&dev_attr_idlepct.attr,
|
|
&dev_attr_rrtime.attr,
|
|
NULL
|
|
};
|
|
|
|
ATTRIBUTE_GROUPS(acpi_pad);
|
|
|
|
/*
|
|
* Query firmware how many CPUs should be idle
|
|
* return -1 on failure
|
|
*/
|
|
static int acpi_pad_pur(acpi_handle handle)
|
|
{
|
|
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
|
|
union acpi_object *package;
|
|
int num = -1;
|
|
|
|
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
|
|
return num;
|
|
|
|
if (!buffer.length || !buffer.pointer)
|
|
return num;
|
|
|
|
package = buffer.pointer;
|
|
|
|
if (package->type == ACPI_TYPE_PACKAGE &&
|
|
package->package.count == 2 &&
|
|
package->package.elements[0].integer.value == 1) /* rev 1 */
|
|
|
|
num = package->package.elements[1].integer.value;
|
|
|
|
kfree(buffer.pointer);
|
|
return num;
|
|
}
|
|
|
|
static void acpi_pad_handle_notify(acpi_handle handle)
|
|
{
|
|
int num_cpus;
|
|
uint32_t idle_cpus;
|
|
struct acpi_buffer param = {
|
|
.length = 4,
|
|
.pointer = (void *)&idle_cpus,
|
|
};
|
|
|
|
mutex_lock(&isolated_cpus_lock);
|
|
num_cpus = acpi_pad_pur(handle);
|
|
if (num_cpus < 0) {
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
return;
|
|
}
|
|
acpi_pad_idle_cpus(num_cpus);
|
|
idle_cpus = acpi_pad_idle_cpus_num();
|
|
acpi_evaluate_ost(handle, ACPI_PROCESSOR_AGGREGATOR_NOTIFY, 0, ¶m);
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
}
|
|
|
|
static void acpi_pad_notify(acpi_handle handle, u32 event,
|
|
void *data)
|
|
{
|
|
struct acpi_device *adev = data;
|
|
|
|
switch (event) {
|
|
case ACPI_PROCESSOR_AGGREGATOR_NOTIFY:
|
|
acpi_pad_handle_notify(handle);
|
|
acpi_bus_generate_netlink_event(adev->pnp.device_class,
|
|
dev_name(&adev->dev), event, 0);
|
|
break;
|
|
default:
|
|
pr_warn("Unsupported event [0x%x]\n", event);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int acpi_pad_probe(struct platform_device *pdev)
|
|
{
|
|
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
|
|
acpi_status status;
|
|
|
|
strcpy(acpi_device_name(adev), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
|
|
strcpy(acpi_device_class(adev), ACPI_PROCESSOR_AGGREGATOR_CLASS);
|
|
|
|
status = acpi_install_notify_handler(adev->handle,
|
|
ACPI_DEVICE_NOTIFY, acpi_pad_notify, adev);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
return -ENODEV;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void acpi_pad_remove(struct platform_device *pdev)
|
|
{
|
|
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
|
|
|
|
mutex_lock(&isolated_cpus_lock);
|
|
acpi_pad_idle_cpus(0);
|
|
mutex_unlock(&isolated_cpus_lock);
|
|
|
|
acpi_remove_notify_handler(adev->handle,
|
|
ACPI_DEVICE_NOTIFY, acpi_pad_notify);
|
|
}
|
|
|
|
static const struct acpi_device_id pad_device_ids[] = {
|
|
{"ACPI000C", 0},
|
|
{"", 0},
|
|
};
|
|
MODULE_DEVICE_TABLE(acpi, pad_device_ids);
|
|
|
|
static struct platform_driver acpi_pad_driver = {
|
|
.probe = acpi_pad_probe,
|
|
.remove_new = acpi_pad_remove,
|
|
.driver = {
|
|
.dev_groups = acpi_pad_groups,
|
|
.name = "processor_aggregator",
|
|
.acpi_match_table = pad_device_ids,
|
|
},
|
|
};
|
|
|
|
static int __init acpi_pad_init(void)
|
|
{
|
|
/* Xen ACPI PAD is used when running as Xen Dom0. */
|
|
if (xen_initial_domain())
|
|
return -ENODEV;
|
|
|
|
power_saving_mwait_init();
|
|
if (power_saving_mwait_eax == 0)
|
|
return -EINVAL;
|
|
|
|
return platform_driver_register(&acpi_pad_driver);
|
|
}
|
|
|
|
static void __exit acpi_pad_exit(void)
|
|
{
|
|
platform_driver_unregister(&acpi_pad_driver);
|
|
}
|
|
|
|
module_init(acpi_pad_init);
|
|
module_exit(acpi_pad_exit);
|
|
MODULE_AUTHOR("Shaohua Li<shaohua.li@intel.com>");
|
|
MODULE_DESCRIPTION("ACPI Processor Aggregator Driver");
|
|
MODULE_LICENSE("GPL");
|