aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/affinity.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2011-06-21 01:29:34 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2011-08-27 11:58:39 -0400
commit592eaca1409e55407e980f71b2ec604ca3610ba5 (patch)
tree43cadd8d3f9cc150a7b108696bfabcddcff55650 /litmus/affinity.c
parentfb8d6602af1cbc09115544056b872b976c6349c3 (diff)
Avoid needlessly costly migrations. CONFIG_SCHED_CPU_AFFINITY
Given a choice between several available CPUs (unlinked) on which to schedule a task, let the scheduler select the CPU closest to where that task was previously scheduled. Hopefully, this will reduce cache migration penalties. Notes: SCHED_CPU_AFFINITY is dependent upon x86 (only x86 is supported at this time). Also PFair/PD^2 does not make use of this feature. Signed-off-by: Andrea Bastoni <bastoni@cs.unc.edu>
Diffstat (limited to 'litmus/affinity.c')
-rw-r--r--litmus/affinity.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/litmus/affinity.c b/litmus/affinity.c
new file mode 100644
index 000000000000..9adab7a3bcd7
--- /dev/null
+++ b/litmus/affinity.c
@@ -0,0 +1,44 @@
1#include <linux/cpu.h>
2
3#include <litmus/affinity.h>
4
5struct neighborhood neigh_info[NR_CPUS];
6
7/* called by _init_litmus() */
8void init_topology(void) {
9 int cpu;
10 int i;
11 int chk;
12 int depth = num_cache_leaves;
13
14 if (depth > NUM_CACHE_LEVELS)
15 depth = NUM_CACHE_LEVELS;
16
17 for_each_online_cpu(cpu) {
18 for (i = 0; i < depth; ++i) {
19 long unsigned int firstbits;
20
21 chk = get_shared_cpu_map((struct cpumask *)&neigh_info[cpu].neighbors[i], cpu, i);
22 if (chk) {
23 /* failed */
24 neigh_info[cpu].size[i] = 0;
25 } else {
26 /* size = num bits in mask */
27 neigh_info[cpu].size[i] =
28 cpumask_weight((struct cpumask *)&neigh_info[cpu].neighbors[i]);
29 }
30 firstbits = *neigh_info[cpu].neighbors[i]->bits;
31 printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
32 cpu, neigh_info[cpu].size[i], i, firstbits);
33 }
34
35 /* set data for non-existent levels */
36 for (; i < NUM_CACHE_LEVELS; ++i) {
37 neigh_info[cpu].size[i] = 0;
38
39 printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
40 cpu, neigh_info[cpu].size[i], i, 0lu);
41 }
42 }
43}
44