2008-07-28 11:06:00 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2012-01-26 11:44:34 +00:00
|
|
|
#include <linux/sched.h>
|
2008-07-28 11:06:00 +00:00
|
|
|
|
|
|
|
#include "blk.h"
|
|
|
|
|
|
|
|
static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
|
|
|
|
|
2008-09-13 18:26:01 +00:00
|
|
|
/*
|
|
|
|
* Softirq action handler - move entries to local list and loop over them
|
|
|
|
* while passing them to the queue registered handler.
|
|
|
|
*/
|
|
|
|
static void blk_done_softirq(struct softirq_action *h)
|
|
|
|
{
|
|
|
|
struct list_head *cpu_list, local_list;
|
|
|
|
|
|
|
|
local_irq_disable();
|
block: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-15 18:22:29 +00:00
|
|
|
cpu_list = this_cpu_ptr(&blk_cpu_done);
|
2008-09-13 18:26:01 +00:00
|
|
|
list_replace_init(cpu_list, &local_list);
|
|
|
|
local_irq_enable();
|
|
|
|
|
|
|
|
while (!list_empty(&local_list)) {
|
|
|
|
struct request *rq;
|
|
|
|
|
2014-02-24 15:39:54 +00:00
|
|
|
rq = list_entry(local_list.next, struct request, queuelist);
|
|
|
|
list_del_init(&rq->queuelist);
|
2008-09-13 18:26:01 +00:00
|
|
|
rq->q->softirq_done_fn(rq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-14 22:32:07 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2008-09-13 18:26:01 +00:00
|
|
|
static void trigger_softirq(void *data)
|
|
|
|
{
|
|
|
|
struct request *rq = data;
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *list;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
block: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-15 18:22:29 +00:00
|
|
|
list = this_cpu_ptr(&blk_cpu_done);
|
2014-02-24 15:39:54 +00:00
|
|
|
/*
|
|
|
|
* We reuse queuelist for a list of requests to process. Since the
|
|
|
|
* queuelist is used by the block layer only for requests waiting to be
|
|
|
|
* submitted to the device it is unused now.
|
|
|
|
*/
|
|
|
|
list_add_tail(&rq->queuelist, list);
|
2008-09-13 18:26:01 +00:00
|
|
|
|
2014-02-24 15:39:54 +00:00
|
|
|
if (list->next == &rq->queuelist)
|
2008-09-13 18:26:01 +00:00
|
|
|
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)) {
|
|
|
|
struct call_single_data *data = &rq->csd;
|
|
|
|
|
|
|
|
data->func = trigger_softirq;
|
|
|
|
data->info = rq;
|
|
|
|
data->flags = 0;
|
|
|
|
|
2014-02-24 15:40:01 +00:00
|
|
|
__smp_call_function_single(cpu, data);
|
2008-09-13 18:26:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2013-11-14 22:32:07 +00:00
|
|
|
#else /* CONFIG_SMP */
|
2008-09-13 18:26:01 +00:00
|
|
|
static int raise_blk_irq(int cpu, struct request *rq)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-19 19:26:23 +00:00
|
|
|
static int blk_cpu_notify(struct notifier_block *self, unsigned long action,
|
|
|
|
void *hcpu)
|
2008-07-28 11:06:00 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If a CPU goes away, splice its entries to the current CPU
|
|
|
|
* and trigger a run of the softirq
|
|
|
|
*/
|
|
|
|
if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
|
|
|
|
int cpu = (unsigned long) hcpu;
|
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
list_splice_init(&per_cpu(blk_cpu_done, cpu),
|
block: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-15 18:22:29 +00:00
|
|
|
this_cpu_ptr(&blk_cpu_done));
|
2008-07-28 11:06:00 +00:00
|
|
|
raise_softirq_irqoff(BLOCK_SOFTIRQ);
|
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 19:26:23 +00:00
|
|
|
static struct notifier_block blk_cpu_notifier = {
|
2008-07-28 11:06:00 +00:00
|
|
|
.notifier_call = blk_cpu_notify,
|
|
|
|
};
|
|
|
|
|
2008-09-14 12:55:09 +00:00
|
|
|
void __blk_complete_request(struct request *req)
|
2008-07-28 11:06:00 +00:00
|
|
|
{
|
2012-01-26 11:44:34 +00:00
|
|
|
int ccpu, cpu;
|
2008-09-13 18:26:01 +00:00
|
|
|
struct request_queue *q = req->q;
|
2008-07-28 11:06:00 +00:00
|
|
|
unsigned long flags;
|
2012-01-26 11:44:34 +00:00
|
|
|
bool shared = false;
|
2008-07-28 11:06:00 +00:00
|
|
|
|
2008-09-13 18:26:01 +00:00
|
|
|
BUG_ON(!q->softirq_done_fn);
|
2008-07-28 11:06:00 +00:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
2008-09-13 18:26:01 +00:00
|
|
|
cpu = smp_processor_id();
|
2008-07-28 11:06:00 +00:00
|
|
|
|
2008-09-13 18:26:01 +00:00
|
|
|
/*
|
|
|
|
* Select completion CPU
|
|
|
|
*/
|
2011-09-14 07:31:01 +00:00
|
|
|
if (req->cpu != -1) {
|
2008-09-13 18:26:01 +00:00
|
|
|
ccpu = req->cpu;
|
2012-01-26 11:44:34 +00:00
|
|
|
if (!test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags))
|
|
|
|
shared = cpus_share_cache(cpu, ccpu);
|
2011-07-23 18:44:25 +00:00
|
|
|
} else
|
2008-09-13 18:26:01 +00:00
|
|
|
ccpu = cpu;
|
|
|
|
|
block: improve rq_affinity placement
This patch reverts commit 35ae66e0a09ab70ed(block: Make rq_affinity = 1
work as expected). The purpose is to avoid an unnecessary IPI.
Let's take an example. My test box has cpu 0-7, one socket. Say request is
added from CPU 1, blk_complete_request() occurs at CPU 7. Without the reverted
patch, softirq will be done at CPU 7. With it, an IPI will be directed to CPU
0, and softirq will be done at CPU 0. In this case, doing softirq at CPU 0 and
CPU 7 have no difference from cache sharing point view and we can avoid an
ipi if doing it in CPU 7.
An immediate concern is this is just like 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 (I checked several LSI
cards and AHCI), so only one CPU can run blk_complete_request(). This is
still quite different as QUEUE_FLAG_SAME_FORCE.
Since only one CPU runs softirq, the only difference with below patch is
softirq not always runs at the first CPU of a group.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-11 08:39:04 +00:00
|
|
|
/*
|
2012-01-26 11:44:34 +00:00
|
|
|
* If current CPU and requested CPU share a cache, run the softirq on
|
|
|
|
* the current CPU. One might concern this is just like
|
block: improve rq_affinity placement
This patch reverts commit 35ae66e0a09ab70ed(block: Make rq_affinity = 1
work as expected). The purpose is to avoid an unnecessary IPI.
Let's take an example. My test box has cpu 0-7, one socket. Say request is
added from CPU 1, blk_complete_request() occurs at CPU 7. Without the reverted
patch, softirq will be done at CPU 7. With it, an IPI will be directed to CPU
0, and softirq will be done at CPU 0. In this case, doing softirq at CPU 0 and
CPU 7 have no difference from cache sharing point view and we can avoid an
ipi if doing it in CPU 7.
An immediate concern is this is just like 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 (I checked several LSI
cards and AHCI), so only one CPU can run blk_complete_request(). This is
still quite different as QUEUE_FLAG_SAME_FORCE.
Since only one CPU runs softirq, the only difference with below patch is
softirq not always runs at the first CPU of a group.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-11 08:39:04 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2012-01-26 11:44:34 +00:00
|
|
|
if (ccpu == cpu || shared) {
|
2008-09-13 18:26:01 +00:00
|
|
|
struct list_head *list;
|
|
|
|
do_local:
|
block: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-15 18:22:29 +00:00
|
|
|
list = this_cpu_ptr(&blk_cpu_done);
|
2014-02-24 15:39:54 +00:00
|
|
|
list_add_tail(&req->queuelist, list);
|
2008-09-13 18:26:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-02-24 15:39:54 +00:00
|
|
|
if (list->next == &req->queuelist)
|
2008-09-13 18:26:01 +00:00
|
|
|
raise_softirq_irqoff(BLOCK_SOFTIRQ);
|
|
|
|
} else if (raise_blk_irq(ccpu, req))
|
|
|
|
goto do_local;
|
2008-07-28 11:06:00 +00:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
2008-09-14 12:55:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_complete_request - end I/O on a request
|
|
|
|
* @req: the request being processed
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Ends all I/O on a request. It does not handle partial completions,
|
|
|
|
* unless the driver actually implements this in its completion callback
|
|
|
|
* through requeueing. The actual completion happens out-of-order,
|
|
|
|
* through a softirq handler. The user must have registered a completion
|
|
|
|
* callback through blk_queue_softirq_done().
|
|
|
|
**/
|
|
|
|
void blk_complete_request(struct request *req)
|
|
|
|
{
|
2008-09-14 12:56:33 +00:00
|
|
|
if (unlikely(blk_should_fake_timeout(req->q)))
|
|
|
|
return;
|
2008-09-14 12:55:09 +00:00
|
|
|
if (!blk_mark_rq_complete(req))
|
|
|
|
__blk_complete_request(req);
|
|
|
|
}
|
2008-07-28 11:06:00 +00:00
|
|
|
EXPORT_SYMBOL(blk_complete_request);
|
|
|
|
|
2008-12-10 14:47:33 +00:00
|
|
|
static __init int blk_softirq_init(void)
|
2008-07-28 11:06:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i)
|
|
|
|
INIT_LIST_HEAD(&per_cpu(blk_cpu_done, i));
|
|
|
|
|
|
|
|
open_softirq(BLOCK_SOFTIRQ, blk_done_softirq);
|
|
|
|
register_hotcpu_notifier(&blk_cpu_notifier);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(blk_softirq_init);
|