Lines Matching +full:- +full:affinity

1 // SPDX-License-Identifier: GPL-2.0
2 /* Manage affinity to optimize IPIs inside the kernel perf API. */
10 #include "affinity.h"
14 int sz = cpu__max_cpu().cpu + 8 - 1; in get_cpu_set_size()
24 int affinity__setup(struct affinity *a) in affinity__setup()
28 a->orig_cpus = bitmap_zalloc(cpu_set_size * 8); in affinity__setup()
29 if (!a->orig_cpus) in affinity__setup()
30 return -1; in affinity__setup()
31 sched_getaffinity(0, cpu_set_size, (cpu_set_t *)a->orig_cpus); in affinity__setup()
32 a->sched_cpus = bitmap_zalloc(cpu_set_size * 8); in affinity__setup()
33 if (!a->sched_cpus) { in affinity__setup()
34 zfree(&a->orig_cpus); in affinity__setup()
35 return -1; in affinity__setup()
37 bitmap_zero((unsigned long *)a->sched_cpus, cpu_set_size); in affinity__setup()
38 a->changed = false; in affinity__setup()
44 * It is more efficient to change perf's affinity to the target
48 void affinity__set(struct affinity *a, int cpu) in affinity__set()
54 * - if cpu is -1 in affinity__set()
55 * - restrict out of bound access to sched_cpus in affinity__set()
57 if (cpu == -1 || ((cpu >= (cpu_set_size * 8)))) in affinity__set()
60 a->changed = true; in affinity__set()
61 __set_bit(cpu, a->sched_cpus); in affinity__set()
63 * We ignore errors because affinity is just an optimization. in affinity__set()
67 sched_setaffinity(0, cpu_set_size, (cpu_set_t *)a->sched_cpus); in affinity__set()
68 __clear_bit(cpu, a->sched_cpus); in affinity__set()
71 static void __affinity__cleanup(struct affinity *a) in __affinity__cleanup()
75 if (a->changed) in __affinity__cleanup()
76 sched_setaffinity(0, cpu_set_size, (cpu_set_t *)a->orig_cpus); in __affinity__cleanup()
77 zfree(&a->sched_cpus); in __affinity__cleanup()
78 zfree(&a->orig_cpus); in __affinity__cleanup()
81 void affinity__cleanup(struct affinity *a) in affinity__cleanup()