Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 1 | /* |
Jubin John | 05d6ac1 | 2016-02-14 20:22:17 -0800 | [diff] [blame] | 2 | * Copyright(c) 2015, 2016 Intel Corporation. |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | #include <linux/topology.h> |
| 48 | #include <linux/cpumask.h> |
| 49 | #include <linux/module.h> |
| 50 | |
| 51 | #include "hfi.h" |
| 52 | #include "affinity.h" |
| 53 | #include "sdma.h" |
| 54 | #include "trace.h" |
| 55 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 56 | struct hfi1_affinity_node_list node_affinity = { |
| 57 | .list = LIST_HEAD_INIT(node_affinity.list), |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 58 | .lock = __MUTEX_INITIALIZER(node_affinity.lock) |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 61 | /* Name of IRQ types, indexed by enum irq_type */ |
| 62 | static const char * const irq_type_names[] = { |
| 63 | "SDMA", |
| 64 | "RCVCTXT", |
| 65 | "GENERAL", |
| 66 | "OTHER", |
| 67 | }; |
| 68 | |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 69 | /* Per NUMA node count of HFI devices */ |
| 70 | static unsigned int *hfi1_per_node_cntr; |
| 71 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 72 | static inline void init_cpu_mask_set(struct cpu_mask_set *set) |
| 73 | { |
| 74 | cpumask_clear(&set->mask); |
| 75 | cpumask_clear(&set->used); |
| 76 | set->gen = 0; |
| 77 | } |
| 78 | |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 79 | /* Initialize non-HT cpu cores mask */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 80 | void init_real_cpu_mask(void) |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 81 | { |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 82 | int possible, curr_cpu, i, ht; |
| 83 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 84 | cpumask_clear(&node_affinity.real_cpu_mask); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 85 | |
| 86 | /* Start with cpu online mask as the real cpu mask */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 87 | cpumask_copy(&node_affinity.real_cpu_mask, cpu_online_mask); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * Remove HT cores from the real cpu mask. Do this in two steps below. |
| 91 | */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 92 | possible = cpumask_weight(&node_affinity.real_cpu_mask); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 93 | ht = cpumask_weight(topology_sibling_cpumask( |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 94 | cpumask_first(&node_affinity.real_cpu_mask))); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 95 | /* |
| 96 | * Step 1. Skip over the first N HT siblings and use them as the |
| 97 | * "real" cores. Assumes that HT cores are not enumerated in |
| 98 | * succession (except in the single core case). |
| 99 | */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 100 | curr_cpu = cpumask_first(&node_affinity.real_cpu_mask); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 101 | for (i = 0; i < possible / ht; i++) |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 102 | curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask); |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 103 | /* |
| 104 | * Step 2. Remove the remaining HT siblings. Use cpumask_next() to |
| 105 | * skip any gaps. |
| 106 | */ |
| 107 | for (; i < possible; i++) { |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 108 | cpumask_clear_cpu(curr_cpu, &node_affinity.real_cpu_mask); |
| 109 | curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask); |
| 110 | } |
| 111 | } |
| 112 | |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 113 | int node_affinity_init(void) |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 114 | { |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 115 | int node; |
| 116 | struct pci_dev *dev = NULL; |
| 117 | const struct pci_device_id *ids = hfi1_pci_tbl; |
| 118 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 119 | cpumask_clear(&node_affinity.proc.used); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 120 | cpumask_copy(&node_affinity.proc.mask, cpu_online_mask); |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 121 | |
| 122 | node_affinity.proc.gen = 0; |
| 123 | node_affinity.num_core_siblings = |
| 124 | cpumask_weight(topology_sibling_cpumask( |
| 125 | cpumask_first(&node_affinity.proc.mask) |
| 126 | )); |
| 127 | node_affinity.num_online_nodes = num_online_nodes(); |
| 128 | node_affinity.num_online_cpus = num_online_cpus(); |
| 129 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 130 | /* |
| 131 | * The real cpu mask is part of the affinity struct but it has to be |
| 132 | * initialized early. It is needed to calculate the number of user |
| 133 | * contexts in set_up_context_variables(). |
| 134 | */ |
| 135 | init_real_cpu_mask(); |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 136 | |
| 137 | hfi1_per_node_cntr = kcalloc(num_possible_nodes(), |
| 138 | sizeof(*hfi1_per_node_cntr), GFP_KERNEL); |
| 139 | if (!hfi1_per_node_cntr) |
| 140 | return -ENOMEM; |
| 141 | |
| 142 | while (ids->vendor) { |
| 143 | dev = NULL; |
| 144 | while ((dev = pci_get_device(ids->vendor, ids->device, dev))) { |
| 145 | node = pcibus_to_node(dev->bus); |
| 146 | if (node < 0) |
| 147 | node = numa_node_id(); |
| 148 | |
| 149 | hfi1_per_node_cntr[node]++; |
| 150 | } |
| 151 | ids++; |
| 152 | } |
| 153 | |
| 154 | return 0; |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void node_affinity_destroy(void) |
| 158 | { |
| 159 | struct list_head *pos, *q; |
| 160 | struct hfi1_affinity_node *entry; |
| 161 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 162 | mutex_lock(&node_affinity.lock); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 163 | list_for_each_safe(pos, q, &node_affinity.list) { |
| 164 | entry = list_entry(pos, struct hfi1_affinity_node, |
| 165 | list); |
| 166 | list_del(pos); |
| 167 | kfree(entry); |
| 168 | } |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 169 | mutex_unlock(&node_affinity.lock); |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 170 | kfree(hfi1_per_node_cntr); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static struct hfi1_affinity_node *node_affinity_allocate(int node) |
| 174 | { |
| 175 | struct hfi1_affinity_node *entry; |
| 176 | |
| 177 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 178 | if (!entry) |
| 179 | return NULL; |
| 180 | entry->node = node; |
| 181 | INIT_LIST_HEAD(&entry->list); |
| 182 | |
| 183 | return entry; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * It appends an entry to the list. |
| 188 | * It *must* be called with node_affinity.lock held. |
| 189 | */ |
| 190 | static void node_affinity_add_tail(struct hfi1_affinity_node *entry) |
| 191 | { |
| 192 | list_add_tail(&entry->list, &node_affinity.list); |
| 193 | } |
| 194 | |
| 195 | /* It must be called with node_affinity.lock held */ |
| 196 | static struct hfi1_affinity_node *node_affinity_lookup(int node) |
| 197 | { |
| 198 | struct list_head *pos; |
| 199 | struct hfi1_affinity_node *entry; |
| 200 | |
| 201 | list_for_each(pos, &node_affinity.list) { |
| 202 | entry = list_entry(pos, struct hfi1_affinity_node, list); |
| 203 | if (entry->node == node) |
| 204 | return entry; |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 207 | return NULL; |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 210 | /* |
| 211 | * Interrupt affinity. |
| 212 | * |
| 213 | * non-rcv avail gets a default mask that |
| 214 | * starts as possible cpus with threads reset |
| 215 | * and each rcv avail reset. |
| 216 | * |
| 217 | * rcv avail gets node relative 1 wrapping back |
| 218 | * to the node relative 1 as necessary. |
| 219 | * |
| 220 | */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 221 | int hfi1_dev_affinity_init(struct hfi1_devdata *dd) |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 222 | { |
| 223 | int node = pcibus_to_node(dd->pcidev->bus); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 224 | struct hfi1_affinity_node *entry; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 225 | const struct cpumask *local_mask; |
Jubin John | 0852d24 | 2016-04-12 11:30:08 -0700 | [diff] [blame] | 226 | int curr_cpu, possible, i; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 227 | |
| 228 | if (node < 0) |
| 229 | node = numa_node_id(); |
| 230 | dd->node = node; |
| 231 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 232 | local_mask = cpumask_of_node(dd->node); |
| 233 | if (cpumask_first(local_mask) >= nr_cpu_ids) |
| 234 | local_mask = topology_core_cpumask(0); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 235 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 236 | mutex_lock(&node_affinity.lock); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 237 | entry = node_affinity_lookup(dd->node); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | * If this is the first time this NUMA node's affinity is used, |
| 241 | * create an entry in the global affinity structure and initialize it. |
| 242 | */ |
| 243 | if (!entry) { |
| 244 | entry = node_affinity_allocate(node); |
| 245 | if (!entry) { |
| 246 | dd_dev_err(dd, |
| 247 | "Unable to allocate global affinity node\n"); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 248 | mutex_unlock(&node_affinity.lock); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 249 | return -ENOMEM; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 250 | } |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 251 | init_cpu_mask_set(&entry->def_intr); |
| 252 | init_cpu_mask_set(&entry->rcv_intr); |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 253 | cpumask_clear(&entry->general_intr_mask); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 254 | /* Use the "real" cpu mask of this node as the default */ |
| 255 | cpumask_and(&entry->def_intr.mask, &node_affinity.real_cpu_mask, |
| 256 | local_mask); |
| 257 | |
| 258 | /* fill in the receive list */ |
| 259 | possible = cpumask_weight(&entry->def_intr.mask); |
| 260 | curr_cpu = cpumask_first(&entry->def_intr.mask); |
| 261 | |
| 262 | if (possible == 1) { |
| 263 | /* only one CPU, everyone will use it */ |
| 264 | cpumask_set_cpu(curr_cpu, &entry->rcv_intr.mask); |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 265 | cpumask_set_cpu(curr_cpu, &entry->general_intr_mask); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 266 | } else { |
| 267 | /* |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 268 | * The general/control context will be the first CPU in |
| 269 | * the default list, so it is removed from the default |
| 270 | * list and added to the general interrupt list. |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 271 | */ |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 272 | cpumask_clear_cpu(curr_cpu, &entry->def_intr.mask); |
| 273 | cpumask_set_cpu(curr_cpu, &entry->general_intr_mask); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 274 | curr_cpu = cpumask_next(curr_cpu, |
| 275 | &entry->def_intr.mask); |
| 276 | |
| 277 | /* |
| 278 | * Remove the remaining kernel receive queues from |
| 279 | * the default list and add them to the receive list. |
| 280 | */ |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 281 | for (i = 0; |
| 282 | i < (dd->n_krcv_queues - 1) * |
| 283 | hfi1_per_node_cntr[dd->node]; |
| 284 | i++) { |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 285 | cpumask_clear_cpu(curr_cpu, |
| 286 | &entry->def_intr.mask); |
| 287 | cpumask_set_cpu(curr_cpu, |
| 288 | &entry->rcv_intr.mask); |
| 289 | curr_cpu = cpumask_next(curr_cpu, |
| 290 | &entry->def_intr.mask); |
| 291 | if (curr_cpu >= nr_cpu_ids) |
| 292 | break; |
| 293 | } |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * If there ends up being 0 CPU cores leftover for SDMA |
| 297 | * engines, use the same CPU cores as general/control |
| 298 | * context. |
| 299 | */ |
| 300 | if (cpumask_weight(&entry->def_intr.mask) == 0) |
| 301 | cpumask_copy(&entry->def_intr.mask, |
| 302 | &entry->general_intr_mask); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 305 | node_affinity_add_tail(entry); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 306 | } |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 307 | mutex_unlock(&node_affinity.lock); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 308 | return 0; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 311 | /* |
| 312 | * Function sets the irq affinity for msix. |
| 313 | * It *must* be called with node_affinity.lock held. |
| 314 | */ |
| 315 | static int get_irq_affinity(struct hfi1_devdata *dd, |
| 316 | struct hfi1_msix_entry *msix) |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 317 | { |
| 318 | int ret; |
| 319 | cpumask_var_t diff; |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 320 | struct hfi1_affinity_node *entry; |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 321 | struct cpu_mask_set *set = NULL; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 322 | struct sdma_engine *sde = NULL; |
| 323 | struct hfi1_ctxtdata *rcd = NULL; |
| 324 | char extra[64]; |
| 325 | int cpu = -1; |
| 326 | |
| 327 | extra[0] = '\0'; |
| 328 | cpumask_clear(&msix->mask); |
| 329 | |
| 330 | ret = zalloc_cpumask_var(&diff, GFP_KERNEL); |
| 331 | if (!ret) |
| 332 | return -ENOMEM; |
| 333 | |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 334 | entry = node_affinity_lookup(dd->node); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 335 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 336 | switch (msix->type) { |
| 337 | case IRQ_SDMA: |
| 338 | sde = (struct sdma_engine *)msix->arg; |
| 339 | scnprintf(extra, 64, "engine %u", sde->this_idx); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 340 | set = &entry->def_intr; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 341 | break; |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 342 | case IRQ_GENERAL: |
| 343 | cpu = cpumask_first(&entry->general_intr_mask); |
| 344 | break; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 345 | case IRQ_RCVCTXT: |
| 346 | rcd = (struct hfi1_ctxtdata *)msix->arg; |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 347 | if (rcd->ctxt == HFI1_CTRL_CTXT) |
| 348 | cpu = cpumask_first(&entry->general_intr_mask); |
| 349 | else |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 350 | set = &entry->rcv_intr; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 351 | scnprintf(extra, 64, "ctxt %u", rcd->ctxt); |
| 352 | break; |
| 353 | default: |
| 354 | dd_dev_err(dd, "Invalid IRQ type %d\n", msix->type); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | |
| 358 | /* |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 359 | * The general and control contexts are placed on a particular |
| 360 | * CPU, which is set above. Skip accounting for it. Everything else |
| 361 | * finds its CPU here. |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 362 | */ |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 363 | if (cpu == -1 && set) { |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 364 | if (cpumask_equal(&set->mask, &set->used)) { |
| 365 | /* |
| 366 | * We've used up all the CPUs, bump up the generation |
| 367 | * and reset the 'used' map |
| 368 | */ |
| 369 | set->gen++; |
| 370 | cpumask_clear(&set->used); |
| 371 | } |
| 372 | cpumask_andnot(diff, &set->mask, &set->used); |
| 373 | cpu = cpumask_first(diff); |
| 374 | cpumask_set_cpu(cpu, &set->used); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | switch (msix->type) { |
| 378 | case IRQ_SDMA: |
| 379 | sde->cpu = cpu; |
| 380 | break; |
| 381 | case IRQ_GENERAL: |
| 382 | case IRQ_RCVCTXT: |
| 383 | case IRQ_OTHER: |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | cpumask_set_cpu(cpu, &msix->mask); |
| 388 | dd_dev_info(dd, "IRQ vector: %u, type %s %s -> cpu: %d\n", |
| 389 | msix->msix.vector, irq_type_names[msix->type], |
| 390 | extra, cpu); |
| 391 | irq_set_affinity_hint(msix->msix.vector, &msix->mask); |
| 392 | |
| 393 | free_cpumask_var(diff); |
| 394 | return 0; |
| 395 | } |
| 396 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 397 | int hfi1_get_irq_affinity(struct hfi1_devdata *dd, struct hfi1_msix_entry *msix) |
| 398 | { |
| 399 | int ret; |
| 400 | |
| 401 | mutex_lock(&node_affinity.lock); |
| 402 | ret = get_irq_affinity(dd, msix); |
| 403 | mutex_unlock(&node_affinity.lock); |
| 404 | return ret; |
| 405 | } |
| 406 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 407 | void hfi1_put_irq_affinity(struct hfi1_devdata *dd, |
| 408 | struct hfi1_msix_entry *msix) |
| 409 | { |
| 410 | struct cpu_mask_set *set = NULL; |
| 411 | struct hfi1_ctxtdata *rcd; |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 412 | struct hfi1_affinity_node *entry; |
| 413 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 414 | mutex_lock(&node_affinity.lock); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 415 | entry = node_affinity_lookup(dd->node); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 416 | |
| 417 | switch (msix->type) { |
| 418 | case IRQ_SDMA: |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 419 | set = &entry->def_intr; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 420 | break; |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 421 | case IRQ_GENERAL: |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 422 | /* Don't do accounting for general contexts */ |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 423 | break; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 424 | case IRQ_RCVCTXT: |
| 425 | rcd = (struct hfi1_ctxtdata *)msix->arg; |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 426 | /* Don't do accounting for control contexts */ |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 427 | if (rcd->ctxt != HFI1_CTRL_CTXT) |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 428 | set = &entry->rcv_intr; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 429 | break; |
| 430 | default: |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 431 | mutex_unlock(&node_affinity.lock); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | |
| 435 | if (set) { |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 436 | cpumask_andnot(&set->used, &set->used, &msix->mask); |
| 437 | if (cpumask_empty(&set->used) && set->gen) { |
| 438 | set->gen--; |
| 439 | cpumask_copy(&set->used, &set->mask); |
| 440 | } |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | irq_set_affinity_hint(msix->msix.vector, NULL); |
| 444 | cpumask_clear(&msix->mask); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 445 | mutex_unlock(&node_affinity.lock); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 448 | /* This should be called with node_affinity.lock held */ |
| 449 | static void find_hw_thread_mask(uint hw_thread_no, cpumask_var_t hw_thread_mask, |
| 450 | struct hfi1_affinity_node_list *affinity) |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 451 | { |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 452 | int possible, curr_cpu, i; |
| 453 | uint num_cores_per_socket = node_affinity.num_online_cpus / |
| 454 | affinity->num_core_siblings / |
| 455 | node_affinity.num_online_nodes; |
| 456 | |
| 457 | cpumask_copy(hw_thread_mask, &affinity->proc.mask); |
| 458 | if (affinity->num_core_siblings > 0) { |
| 459 | /* Removing other siblings not needed for now */ |
| 460 | possible = cpumask_weight(hw_thread_mask); |
| 461 | curr_cpu = cpumask_first(hw_thread_mask); |
| 462 | for (i = 0; |
| 463 | i < num_cores_per_socket * node_affinity.num_online_nodes; |
| 464 | i++) |
| 465 | curr_cpu = cpumask_next(curr_cpu, hw_thread_mask); |
| 466 | |
| 467 | for (; i < possible; i++) { |
| 468 | cpumask_clear_cpu(curr_cpu, hw_thread_mask); |
| 469 | curr_cpu = cpumask_next(curr_cpu, hw_thread_mask); |
| 470 | } |
| 471 | |
| 472 | /* Identifying correct HW threads within physical cores */ |
| 473 | cpumask_shift_left(hw_thread_mask, hw_thread_mask, |
| 474 | num_cores_per_socket * |
| 475 | node_affinity.num_online_nodes * |
| 476 | hw_thread_no); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | int hfi1_get_proc_affinity(int node) |
| 481 | { |
| 482 | int cpu = -1, ret, i; |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 483 | struct hfi1_affinity_node *entry; |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 484 | cpumask_var_t diff, hw_thread_mask, available_mask, intrs_mask; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 485 | const struct cpumask *node_mask, |
| 486 | *proc_mask = tsk_cpus_allowed(current); |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 487 | struct hfi1_affinity_node_list *affinity = &node_affinity; |
| 488 | struct cpu_mask_set *set = &affinity->proc; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 489 | |
| 490 | /* |
| 491 | * check whether process/context affinity has already |
| 492 | * been set |
| 493 | */ |
| 494 | if (cpumask_weight(proc_mask) == 1) { |
Leon Romanovsky | f242d93a | 2016-05-31 10:54:36 +0300 | [diff] [blame] | 495 | hfi1_cdbg(PROC, "PID %u %s affinity set to CPU %*pbl", |
| 496 | current->pid, current->comm, |
| 497 | cpumask_pr_args(proc_mask)); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 498 | /* |
| 499 | * Mark the pre-set CPU as used. This is atomic so we don't |
| 500 | * need the lock |
| 501 | */ |
| 502 | cpu = cpumask_first(proc_mask); |
| 503 | cpumask_set_cpu(cpu, &set->used); |
| 504 | goto done; |
| 505 | } else if (cpumask_weight(proc_mask) < cpumask_weight(&set->mask)) { |
Leon Romanovsky | f242d93a | 2016-05-31 10:54:36 +0300 | [diff] [blame] | 506 | hfi1_cdbg(PROC, "PID %u %s affinity set to CPU set(s) %*pbl", |
| 507 | current->pid, current->comm, |
| 508 | cpumask_pr_args(proc_mask)); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 509 | goto done; |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | * The process does not have a preset CPU affinity so find one to |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 514 | * recommend using the following algorithm: |
| 515 | * |
| 516 | * For each user process that is opening a context on HFI Y: |
| 517 | * a) If all cores are filled, reinitialize the bitmask |
| 518 | * b) Fill real cores first, then HT cores (First set of HT |
| 519 | * cores on all physical cores, then second set of HT core, |
| 520 | * and, so on) in the following order: |
| 521 | * |
| 522 | * 1. Same NUMA node as HFI Y and not running an IRQ |
| 523 | * handler |
| 524 | * 2. Same NUMA node as HFI Y and running an IRQ handler |
| 525 | * 3. Different NUMA node to HFI Y and not running an IRQ |
| 526 | * handler |
| 527 | * 4. Different NUMA node to HFI Y and running an IRQ |
| 528 | * handler |
| 529 | * c) Mark core as filled in the bitmask. As user processes are |
| 530 | * done, clear cores from the bitmask. |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 531 | */ |
| 532 | |
| 533 | ret = zalloc_cpumask_var(&diff, GFP_KERNEL); |
| 534 | if (!ret) |
| 535 | goto done; |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 536 | ret = zalloc_cpumask_var(&hw_thread_mask, GFP_KERNEL); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 537 | if (!ret) |
| 538 | goto free_diff; |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 539 | ret = zalloc_cpumask_var(&available_mask, GFP_KERNEL); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 540 | if (!ret) |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 541 | goto free_hw_thread_mask; |
| 542 | ret = zalloc_cpumask_var(&intrs_mask, GFP_KERNEL); |
| 543 | if (!ret) |
| 544 | goto free_available_mask; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 545 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 546 | mutex_lock(&affinity->lock); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 547 | /* |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 548 | * If we've used all available HW threads, clear the mask and start |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 549 | * overloading. |
| 550 | */ |
| 551 | if (cpumask_equal(&set->mask, &set->used)) { |
| 552 | set->gen++; |
| 553 | cpumask_clear(&set->used); |
| 554 | } |
| 555 | |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 556 | /* |
| 557 | * If NUMA node has CPUs used by interrupt handlers, include them in the |
| 558 | * interrupt handler mask. |
| 559 | */ |
| 560 | entry = node_affinity_lookup(node); |
| 561 | if (entry) { |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 562 | cpumask_copy(intrs_mask, (entry->def_intr.gen ? |
| 563 | &entry->def_intr.mask : |
| 564 | &entry->def_intr.used)); |
| 565 | cpumask_or(intrs_mask, intrs_mask, (entry->rcv_intr.gen ? |
| 566 | &entry->rcv_intr.mask : |
| 567 | &entry->rcv_intr.used)); |
| 568 | cpumask_or(intrs_mask, intrs_mask, &entry->general_intr_mask); |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 569 | } |
Leon Romanovsky | f242d93a | 2016-05-31 10:54:36 +0300 | [diff] [blame] | 570 | hfi1_cdbg(PROC, "CPUs used by interrupts: %*pbl", |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 571 | cpumask_pr_args(intrs_mask)); |
| 572 | |
| 573 | cpumask_copy(hw_thread_mask, &set->mask); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 574 | |
| 575 | /* |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 576 | * If HT cores are enabled, identify which HW threads within the |
| 577 | * physical cores should be used. |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 578 | */ |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 579 | if (affinity->num_core_siblings > 0) { |
| 580 | for (i = 0; i < affinity->num_core_siblings; i++) { |
| 581 | find_hw_thread_mask(i, hw_thread_mask, affinity); |
| 582 | |
| 583 | /* |
| 584 | * If there's at least one available core for this HW |
| 585 | * thread number, stop looking for a core. |
| 586 | * |
| 587 | * diff will always be not empty at least once in this |
| 588 | * loop as the used mask gets reset when |
| 589 | * (set->mask == set->used) before this loop. |
| 590 | */ |
| 591 | cpumask_andnot(diff, hw_thread_mask, &set->used); |
| 592 | if (!cpumask_empty(diff)) |
| 593 | break; |
| 594 | } |
| 595 | } |
| 596 | hfi1_cdbg(PROC, "Same available HW thread on all physical CPUs: %*pbl", |
| 597 | cpumask_pr_args(hw_thread_mask)); |
| 598 | |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 599 | node_mask = cpumask_of_node(node); |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 600 | hfi1_cdbg(PROC, "Device on NUMA %u, CPUs %*pbl", node, |
Leon Romanovsky | f242d93a | 2016-05-31 10:54:36 +0300 | [diff] [blame] | 601 | cpumask_pr_args(node_mask)); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 602 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 603 | /* Get cpumask of available CPUs on preferred NUMA */ |
| 604 | cpumask_and(available_mask, hw_thread_mask, node_mask); |
| 605 | cpumask_andnot(available_mask, available_mask, &set->used); |
| 606 | hfi1_cdbg(PROC, "Available CPUs on NUMA %u: %*pbl", node, |
| 607 | cpumask_pr_args(available_mask)); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * At first, we don't want to place processes on the same |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 611 | * CPUs as interrupt handlers. Then, CPUs running interrupt |
| 612 | * handlers are used. |
| 613 | * |
| 614 | * 1) If diff is not empty, then there are CPUs not running |
| 615 | * non-interrupt handlers available, so diff gets copied |
| 616 | * over to available_mask. |
| 617 | * 2) If diff is empty, then all CPUs not running interrupt |
| 618 | * handlers are taken, so available_mask contains all |
| 619 | * available CPUs running interrupt handlers. |
| 620 | * 3) If available_mask is empty, then all CPUs on the |
| 621 | * preferred NUMA node are taken, so other NUMA nodes are |
| 622 | * used for process assignments using the same method as |
| 623 | * the preferred NUMA node. |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 624 | */ |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 625 | cpumask_andnot(diff, available_mask, intrs_mask); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 626 | if (!cpumask_empty(diff)) |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 627 | cpumask_copy(available_mask, diff); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 628 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 629 | /* If we don't have CPUs on the preferred node, use other NUMA nodes */ |
| 630 | if (cpumask_empty(available_mask)) { |
| 631 | cpumask_andnot(available_mask, hw_thread_mask, &set->used); |
| 632 | /* Excluding preferred NUMA cores */ |
| 633 | cpumask_andnot(available_mask, available_mask, node_mask); |
| 634 | hfi1_cdbg(PROC, |
| 635 | "Preferred NUMA node cores are taken, cores available in other NUMA nodes: %*pbl", |
| 636 | cpumask_pr_args(available_mask)); |
| 637 | |
| 638 | /* |
| 639 | * At first, we don't want to place processes on the same |
| 640 | * CPUs as interrupt handlers. |
| 641 | */ |
| 642 | cpumask_andnot(diff, available_mask, intrs_mask); |
| 643 | if (!cpumask_empty(diff)) |
| 644 | cpumask_copy(available_mask, diff); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 645 | } |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 646 | hfi1_cdbg(PROC, "Possible CPUs for process: %*pbl", |
| 647 | cpumask_pr_args(available_mask)); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 648 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 649 | cpu = cpumask_first(available_mask); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 650 | if (cpu >= nr_cpu_ids) /* empty */ |
| 651 | cpu = -1; |
| 652 | else |
| 653 | cpumask_set_cpu(cpu, &set->used); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 654 | |
| 655 | mutex_unlock(&affinity->lock); |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 656 | hfi1_cdbg(PROC, "Process assigned to CPU %d", cpu); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 657 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 658 | free_cpumask_var(intrs_mask); |
| 659 | free_available_mask: |
| 660 | free_cpumask_var(available_mask); |
| 661 | free_hw_thread_mask: |
| 662 | free_cpumask_var(hw_thread_mask); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 663 | free_diff: |
| 664 | free_cpumask_var(diff); |
| 665 | done: |
| 666 | return cpu; |
| 667 | } |
| 668 | |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 669 | void hfi1_put_proc_affinity(int cpu) |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 670 | { |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 671 | struct hfi1_affinity_node_list *affinity = &node_affinity; |
| 672 | struct cpu_mask_set *set = &affinity->proc; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 673 | |
| 674 | if (cpu < 0) |
| 675 | return; |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 676 | |
| 677 | mutex_lock(&affinity->lock); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 678 | cpumask_clear_cpu(cpu, &set->used); |
Sebastian Sanchez | b094a36 | 2016-07-25 07:54:57 -0700 | [diff] [blame] | 679 | hfi1_cdbg(PROC, "Returning CPU %d for future process assignment", cpu); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 680 | if (cpumask_empty(&set->used) && set->gen) { |
| 681 | set->gen--; |
| 682 | cpumask_copy(&set->used, &set->mask); |
| 683 | } |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 684 | mutex_unlock(&affinity->lock); |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 685 | } |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 686 | |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 687 | int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf, |
| 688 | size_t count) |
| 689 | { |
| 690 | struct hfi1_affinity_node *entry; |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 691 | cpumask_var_t mask; |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 692 | int ret, i; |
| 693 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 694 | mutex_lock(&node_affinity.lock); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 695 | entry = node_affinity_lookup(dd->node); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 696 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 697 | if (!entry) { |
| 698 | ret = -EINVAL; |
| 699 | goto unlock; |
| 700 | } |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 701 | |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 702 | ret = zalloc_cpumask_var(&mask, GFP_KERNEL); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 703 | if (!ret) { |
| 704 | ret = -ENOMEM; |
| 705 | goto unlock; |
| 706 | } |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 707 | |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 708 | ret = cpulist_parse(buf, mask); |
| 709 | if (ret) |
| 710 | goto out; |
| 711 | |
| 712 | if (!cpumask_subset(mask, cpu_online_mask) || cpumask_empty(mask)) { |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 713 | dd_dev_warn(dd, "Invalid CPU mask\n"); |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 714 | ret = -EINVAL; |
| 715 | goto out; |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 718 | /* reset the SDMA interrupt affinity details */ |
| 719 | init_cpu_mask_set(&entry->def_intr); |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 720 | cpumask_copy(&entry->def_intr.mask, mask); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 721 | |
| 722 | /* Reassign the affinity for each SDMA interrupt. */ |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 723 | for (i = 0; i < dd->num_msix_entries; i++) { |
| 724 | struct hfi1_msix_entry *msix; |
| 725 | |
| 726 | msix = &dd->msix_entries[i]; |
| 727 | if (msix->type != IRQ_SDMA) |
| 728 | continue; |
| 729 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 730 | ret = get_irq_affinity(dd, msix); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 731 | |
| 732 | if (ret) |
| 733 | break; |
| 734 | } |
Tadeusz Struk | 8303f68 | 2016-08-03 20:19:32 -0400 | [diff] [blame] | 735 | out: |
| 736 | free_cpumask_var(mask); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 737 | unlock: |
| 738 | mutex_unlock(&node_affinity.lock); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 739 | return ret ? ret : strnlen(buf, PAGE_SIZE); |
| 740 | } |
| 741 | |
| 742 | int hfi1_get_sdma_affinity(struct hfi1_devdata *dd, char *buf) |
| 743 | { |
| 744 | struct hfi1_affinity_node *entry; |
| 745 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 746 | mutex_lock(&node_affinity.lock); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 747 | entry = node_affinity_lookup(dd->node); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 748 | |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 749 | if (!entry) { |
| 750 | mutex_unlock(&node_affinity.lock); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 751 | return -EINVAL; |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 752 | } |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 753 | |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 754 | cpumap_print_to_pagebuf(true, buf, &entry->def_intr.mask); |
Tadeusz Struk | 584d957 | 2016-09-06 04:36:18 -0700 | [diff] [blame^] | 755 | mutex_unlock(&node_affinity.lock); |
Tadeusz Struk | b14db1f | 2016-07-25 13:39:27 -0700 | [diff] [blame] | 756 | return strnlen(buf, PAGE_SIZE); |
| 757 | } |