aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/affinity.c
blob: 9d5405cf05fd8bb54ea1bccbb9fc4ab3c8cb1294 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <linux/cpu.h>

#include <litmus/affinity.h>

struct neighborhood neigh_info[NR_CPUS];

/* called by _init_litmus() */
void init_topology(void)
{
	int cpu;
	int i;
	int chk;
	int depth = num_cache_leaves;

	if(depth > MAX_CACHE_DEPTH) /* L4 and greater?? */
		depth = MAX_CACHE_DEPTH;

	for_each_online_cpu(cpu)
	{
		for(i = 0; i < (int)depth; ++i)
		{
			long unsigned int firstbits;

			chk = get_shared_cpu_map((struct cpumask *)&neigh_info[cpu].neighbors[i], cpu, i);
			if(chk) /* failed */
			{
				neigh_info[cpu].size[i] = 0;
			}
			else
			{
				/* size = num bits in mask */
				neigh_info[cpu].size[i] = cpumask_weight((struct cpumask *)&neigh_info[cpu].neighbors[i]);
			}
			firstbits = *neigh_info[cpu].neighbors[i]->bits;
			printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
							cpu, neigh_info[cpu].size[i], i, firstbits);
		}

		/* set data for non-existent levels */
		for(; i < MAX_CACHE_DEPTH; ++i)
		{
			neigh_info[cpu].size[i] = 0;

			printk("CPU %d has %d neighbors at level %d. (mask = %lx)\n",
							cpu, neigh_info[cpu].size[i], i, 0lu);
		}
	}
}