Blame view
block/blk-softirq.c
3.74 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
b646fc59b block: split soft... |
2 3 4 5 6 7 8 9 10 11 |
/* * Functions related to softirq rq completions */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/bio.h> #include <linux/blkdev.h> #include <linux/interrupt.h> #include <linux/cpu.h> |
39be35012 sched, block: Uni... |
12 |
#include <linux/sched.h> |
105ab3d8c sched/headers: Pr... |
13 |
#include <linux/sched/topology.h> |
b646fc59b block: split soft... |
14 15 16 17 |
#include "blk.h" static DEFINE_PER_CPU(struct list_head, blk_cpu_done); |
c7c22e4d5 block: add suppor... |
18 19 20 21 |
/* * Softirq action handler - move entries to local list and loop over them * while passing them to the queue registered handler. */ |
0766f788e latent_entropy: M... |
22 |
static __latent_entropy void blk_done_softirq(struct softirq_action *h) |
c7c22e4d5 block: add suppor... |
23 24 25 26 |
{ struct list_head *cpu_list, local_list; local_irq_disable(); |
170d800af block: Replace __... |
27 |
cpu_list = this_cpu_ptr(&blk_cpu_done); |
c7c22e4d5 block: add suppor... |
28 29 30 31 32 |
list_replace_init(cpu_list, &local_list); local_irq_enable(); while (!list_empty(&local_list)) { struct request *rq; |
360f92c24 block: fix regres... |
33 34 |
rq = list_entry(local_list.next, struct request, ipi_list); list_del_init(&rq->ipi_list); |
c7bb9ad17 block: get rid of... |
35 |
rq->q->mq_ops->complete(rq); |
c7c22e4d5 block: add suppor... |
36 37 |
} } |
0a06ff068 kernel: remove CO... |
38 |
#ifdef CONFIG_SMP |
c7c22e4d5 block: add suppor... |
39 40 41 42 43 44 45 |
static void trigger_softirq(void *data) { struct request *rq = data; unsigned long flags; struct list_head *list; local_irq_save(flags); |
170d800af block: Replace __... |
46 |
list = this_cpu_ptr(&blk_cpu_done); |
360f92c24 block: fix regres... |
47 |
list_add_tail(&rq->ipi_list, list); |
c7c22e4d5 block: add suppor... |
48 |
|
360f92c24 block: fix regres... |
49 |
if (list->next == &rq->ipi_list) |
c7c22e4d5 block: add suppor... |
50 51 52 53 54 55 56 57 58 59 60 |
raise_softirq_irqoff(BLOCK_SOFTIRQ); local_irq_restore(flags); } /* * Setup and invoke a run of 'trigger_softirq' on the given cpu. */ static int raise_blk_irq(int cpu, struct request *rq) { if (cpu_online(cpu)) { |
966a96711 smp: Avoid using ... |
61 |
call_single_data_t *data = &rq->csd; |
c7c22e4d5 block: add suppor... |
62 63 64 65 |
data->func = trigger_softirq; data->info = rq; data->flags = 0; |
c46fff2a3 smp: Rename __smp... |
66 |
smp_call_function_single_async(cpu, data); |
c7c22e4d5 block: add suppor... |
67 68 69 70 71 |
return 0; } return 1; } |
0a06ff068 kernel: remove CO... |
72 |
#else /* CONFIG_SMP */ |
c7c22e4d5 block: add suppor... |
73 74 75 76 77 |
static int raise_blk_irq(int cpu, struct request *rq) { return 1; } #endif |
9a659f43d block/softirq: Co... |
78 |
static int blk_softirq_cpu_dead(unsigned int cpu) |
b646fc59b block: split soft... |
79 80 81 82 83 |
{ /* * If a CPU goes away, splice its entries to the current CPU * and trigger a run of the softirq */ |
9a659f43d block/softirq: Co... |
84 85 86 87 88 |
local_irq_disable(); list_splice_init(&per_cpu(blk_cpu_done, cpu), this_cpu_ptr(&blk_cpu_done)); raise_softirq_irqoff(BLOCK_SOFTIRQ); local_irq_enable(); |
b646fc59b block: split soft... |
89 |
|
9a659f43d block/softirq: Co... |
90 |
return 0; |
b646fc59b block: split soft... |
91 |
} |
242f9dcb8 block: unify requ... |
92 |
void __blk_complete_request(struct request *req) |
b646fc59b block: split soft... |
93 |
{ |
c7c22e4d5 block: add suppor... |
94 |
struct request_queue *q = req->q; |
9cf2bab63 block: kill reque... |
95 |
int cpu, ccpu = req->mq_ctx->cpu; |
b646fc59b block: split soft... |
96 |
unsigned long flags; |
39be35012 sched, block: Uni... |
97 |
bool shared = false; |
b646fc59b block: split soft... |
98 |
|
c7bb9ad17 block: get rid of... |
99 |
BUG_ON(!q->mq_ops->complete); |
b646fc59b block: split soft... |
100 101 |
local_irq_save(flags); |
c7c22e4d5 block: add suppor... |
102 |
cpu = smp_processor_id(); |
b646fc59b block: split soft... |
103 |
|
c7c22e4d5 block: add suppor... |
104 105 106 |
/* * Select completion CPU */ |
36e765392 blk-mq: complete ... |
107 |
if (test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags) && ccpu != -1) { |
39be35012 sched, block: Uni... |
108 109 |
if (!test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags)) shared = cpus_share_cache(cpu, ccpu); |
5757a6d76 block: strict rq_... |
110 |
} else |
c7c22e4d5 block: add suppor... |
111 |
ccpu = cpu; |
bcf30e75b block: improve rq... |
112 |
/* |
39be35012 sched, block: Uni... |
113 114 |
* If current CPU and requested CPU share a cache, run the softirq on * the current CPU. One might concern this is just like |
bcf30e75b block: improve rq... |
115 116 117 118 119 |
* QUEUE_FLAG_SAME_FORCE, but actually not. blk_complete_request() is * running in interrupt handler, and currently I/O controller doesn't * support multiple interrupts, so current CPU is unique actually. This * avoids IPI sending from current CPU to the first CPU of a group. */ |
39be35012 sched, block: Uni... |
120 |
if (ccpu == cpu || shared) { |
c7c22e4d5 block: add suppor... |
121 122 |
struct list_head *list; do_local: |
170d800af block: Replace __... |
123 |
list = this_cpu_ptr(&blk_cpu_done); |
360f92c24 block: fix regres... |
124 |
list_add_tail(&req->ipi_list, list); |
c7c22e4d5 block: add suppor... |
125 126 127 128 129 130 131 |
/* * if the list only contains our just added request, * signal a raise of the softirq. If there are already * entries there, someone already raised the irq but it * hasn't run yet. */ |
360f92c24 block: fix regres... |
132 |
if (list->next == &req->ipi_list) |
c7c22e4d5 block: add suppor... |
133 134 135 |
raise_softirq_irqoff(BLOCK_SOFTIRQ); } else if (raise_blk_irq(ccpu, req)) goto do_local; |
b646fc59b block: split soft... |
136 137 138 |
local_irq_restore(flags); } |
242f9dcb8 block: unify requ... |
139 |
|
3c18ce71a block: make blk_s... |
140 |
static __init int blk_softirq_init(void) |
b646fc59b block: split soft... |
141 142 143 144 145 146 147 |
{ int i; for_each_possible_cpu(i) INIT_LIST_HEAD(&per_cpu(blk_cpu_done, i)); open_softirq(BLOCK_SOFTIRQ, blk_done_softirq); |
9a659f43d block/softirq: Co... |
148 149 150 |
cpuhp_setup_state_nocalls(CPUHP_BLOCK_SOFTIRQ_DEAD, "block/softirq:dead", NULL, blk_softirq_cpu_dead); |
b646fc59b block: split soft... |
151 152 153 |
return 0; } subsys_initcall(blk_softirq_init); |