aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/affinity.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2011-04-26 02:00:33 -0400
committerGlenn Elliott <gelliott@cs.unc.edu>2011-04-26 02:00:33 -0400
commit0640d8f6441b2c8865feccbbd50388acc7404510 (patch)
tree3a62d7f872f93cb44b705db653bef434363d551c /litmus/affinity.c
parent7d754596756240fa918b94cd0c3011c77a638987 (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. TODO: If a lower-priority task must be preempted and there are several scheduled tasks with the same low priority, then preempt the closest.
Diffstat (limited to 'litmus/affinity.c')
-rw-r--r--litmus/affinity.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/litmus/affinity.c b/litmus/affinity.c
new file mode 100644
index 000000000000..9d5405cf05fd
--- /dev/null
+++ b/litmus/affinity.c
@@ -0,0 +1,49 @@
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{
10 int cpu;
11 int i;
12 int chk;
13 int depth = num_cache_leaves;
14
15 if(depth > MAX_CACHE_DEPTH) /* L4 and greater?? */
16 depth = MAX_CACHE_DEPTH;
17
18 for_each_online_cpu(cpu)
19 {
20 for(i = 0; i < (int)depth; ++i)
21 {
22 long unsigned int firstbits;
23
24 chk = get_shared_cpu_map((struct cpumask *)&neigh_info[cpu].neighbors[i], cpu, i);
25 if(chk) /* failed */
26 {
27 neigh_info[cpu].size[i] = 0;
28 }
29 else
30 {
31 /* size = num bits in mask */
32 neigh_info[cpu].size[i] = cpumask_weight((struct cpumask *)&neigh_info[cpu].neighbors[i]);
33 }
34 firstbits = *neigh_info[cpu].neighbors[i]->bits;
35 printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
36 cpu, neigh_info[cpu].size[i], i, firstbits);
37 }
38
39 /* set data for non-existent levels */
40 for(; i < MAX_CACHE_DEPTH; ++i)
41 {
42 neigh_info[cpu].size[i] = 0;
43
44 printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
45 cpu, neigh_info[cpu].size[i], i, 0lu);
46 }
47 }
48}
49