-
Notifications
You must be signed in to change notification settings - Fork 139
/
placement.c
191 lines (159 loc) · 4.79 KB
/
placement.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright (C) 2006, Intel Corporation
* Copyright (C) 2012, Neil Horman <[email protected]>
*
* This file is part of irqbalance
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include "types.h"
#include "irqbalance.h"
GList *rebalance_irq_list;
struct obj_placement {
struct topo_obj *best;
uint64_t best_cost;
struct irq_info *info;
};
static void find_best_object(struct topo_obj *d, void *data)
{
struct obj_placement *best = (struct obj_placement *)data;
uint64_t newload;
/*
* Don't consider the unspecified numa node here
*/
if (numa_avail && (d->obj_type == OBJ_TYPE_NODE) && (d->number == NUMA_NO_NODE))
return;
/*
* also don't consider any node that doesn't have at least one cpu in
* the unbanned list
*/
if ((d->obj_type == OBJ_TYPE_NODE) &&
(!cpus_intersects(d->mask, unbanned_cpus)))
return;
if (d->powersave_mode)
return;
if (d->slots_left <= 0)
return;
newload = d->load;
if (newload < best->best_cost) {
best->best = d;
best->best_cost = newload;
} else if (newload == best->best_cost) {
if (g_list_length(d->interrupts) < g_list_length(best->best->interrupts)) {
best->best = d;
}
}
}
static void find_best_object_for_irq(struct irq_info *info, void *data)
{
struct obj_placement place;
struct topo_obj *d = data;
if (!info->moved)
return;
switch (d->obj_type) {
case OBJ_TYPE_NODE:
if (info->level == BALANCE_NONE)
return;
break;
case OBJ_TYPE_PACKAGE:
if (info->level == BALANCE_PACKAGE)
return;
break;
case OBJ_TYPE_CACHE:
if (info->level == BALANCE_CACHE)
return;
break;
case OBJ_TYPE_CPU:
if (info->level == BALANCE_CORE)
return;
break;
}
place.info = info;
place.best = NULL;
place.best_cost = ULLONG_MAX;
for_each_object(d->children, find_best_object, &place);
if (place.best)
migrate_irq_obj(d, place.best, info);
}
static void place_irq_in_object(struct topo_obj *d, void *data __attribute__((unused)))
{
if (g_list_length(d->interrupts) > 0)
for_each_irq(d->interrupts, find_best_object_for_irq, d);
}
static void place_irq_in_node(struct irq_info *info, void *data __attribute__((unused)))
{
struct obj_placement place;
if ((info->level == BALANCE_NONE) && cpus_empty(banned_cpus))
return;
if (irq_numa_node(info)->number != NUMA_NO_NODE || !numa_avail) {
/*
* Need to make sure this node is elligible for migration
* given the banned cpu list
*/
if (!cpus_intersects(irq_numa_node(info)->mask, unbanned_cpus)) {
log(TO_CONSOLE, LOG_WARNING, "There is no suitable CPU in node:%d.\n", irq_numa_node(info)->number);
log(TO_CONSOLE, LOG_WARNING, "Irqbalance dispatch irq:%d to other node.\n", info->irq);
goto find_placement;
}
/*
* This irq belongs to a device with a preferred numa node
* put it on that node
*/
migrate_irq_obj(NULL, irq_numa_node(info), info);
return;
}
find_placement:
place.best_cost = ULLONG_MAX;
place.best = NULL;
place.info = info;
for_each_object(numa_nodes, find_best_object, &place);
if (place.best)
migrate_irq_obj(NULL, place.best, info);
}
static void validate_irq(struct irq_info *info, void *data)
{
if (info->assigned_obj != data)
log(TO_CONSOLE, LOG_INFO, "object validation error: irq %d is wrong, points to %p, should be %p\n",
info->irq, (void*)info->assigned_obj, data);
}
static void validate_object(struct topo_obj *d, void *data __attribute__((unused)))
{
if (g_list_length(d->interrupts) > 0)
for_each_irq(d->interrupts, validate_irq, d);
}
static void validate_object_tree_placement(void)
{
for_each_object(packages, validate_object, NULL);
for_each_object(cache_domains, validate_object, NULL);
for_each_object(cpus, validate_object, NULL);
}
void calculate_placement(void)
{
sort_irq_list(&rebalance_irq_list);
if (g_list_length(rebalance_irq_list) > 0) {
for_each_irq(rebalance_irq_list, place_irq_in_node, NULL);
for_each_object(numa_nodes, place_irq_in_object, NULL);
for_each_object(packages, place_irq_in_object, NULL);
for_each_object(cache_domains, place_irq_in_object, NULL);
}
if (debug_mode)
validate_object_tree_placement();
}