Merge tag 'sound-fix-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[cascardo/linux.git] / block / blk-mq-tag.c
index c9a22db..dcf5ce3 100644 (file)
@@ -7,7 +7,6 @@
  */
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/random.h>
 
 #include <linux/blk-mq.h>
 #include "blk.h"
@@ -91,14 +90,11 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
        return atomic_read(&hctx->nr_active) < depth;
 }
 
-#define BT_ALLOC_RR(tags) (tags->alloc_policy == BLK_TAG_ALLOC_RR)
-
-static int __bt_get(struct blk_mq_hw_ctx *hctx, struct sbitmap_queue *bt,
-                   struct blk_mq_tags *tags)
+static int __bt_get(struct blk_mq_hw_ctx *hctx, struct sbitmap_queue *bt)
 {
        if (!hctx_may_queue(hctx, bt))
                return -1;
-       return __sbitmap_queue_get(bt, BT_ALLOC_RR(tags));
+       return __sbitmap_queue_get(bt);
 }
 
 static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,
@@ -108,7 +104,7 @@ static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,
        DEFINE_WAIT(wait);
        int tag;
 
-       tag = __bt_get(hctx, bt, tags);
+       tag = __bt_get(hctx, bt);
        if (tag != -1)
                return tag;
 
@@ -119,7 +115,7 @@ static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,
        do {
                prepare_to_wait(&ws->wait, &wait, TASK_UNINTERRUPTIBLE);
 
-               tag = __bt_get(hctx, bt, tags);
+               tag = __bt_get(hctx, bt);
                if (tag != -1)
                        break;
 
@@ -136,7 +132,7 @@ static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,
                 * Retry tag allocation after running the hardware queue,
                 * as running the queue may also have found completions.
                 */
-               tag = __bt_get(hctx, bt, tags);
+               tag = __bt_get(hctx, bt);
                if (tag != -1)
                        break;
 
@@ -145,8 +141,7 @@ static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,
                io_schedule();
 
                data->ctx = blk_mq_get_ctx(data->q);
-               data->hctx = data->q->mq_ops->map_queue(data->q,
-                               data->ctx->cpu);
+               data->hctx = blk_mq_map_queue(data->q, data->ctx->cpu);
                if (data->flags & BLK_MQ_REQ_RESERVED) {
                        bt = &data->hctx->tags->breserved_tags;
                } else {
@@ -206,12 +201,10 @@ void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
                const int real_tag = tag - tags->nr_reserved_tags;
 
                BUG_ON(real_tag >= tags->nr_tags);
-               sbitmap_queue_clear(&tags->bitmap_tags, real_tag,
-                                   BT_ALLOC_RR(tags), ctx->cpu);
+               sbitmap_queue_clear(&tags->bitmap_tags, real_tag, ctx->cpu);
        } else {
                BUG_ON(tag >= tags->nr_reserved_tags);
-               sbitmap_queue_clear(&tags->breserved_tags, tag,
-                                   BT_ALLOC_RR(tags), ctx->cpu);
+               sbitmap_queue_clear(&tags->breserved_tags, tag, ctx->cpu);
        }
 }
 
@@ -363,21 +356,23 @@ static unsigned int bt_unused_tags(const struct sbitmap_queue *bt)
        return bt->sb.depth - sbitmap_weight(&bt->sb);
 }
 
-static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth, int node)
+static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
+                   bool round_robin, int node)
 {
-       return sbitmap_queue_init_node(bt, depth, -1, GFP_KERNEL, node);
+       return sbitmap_queue_init_node(bt, depth, -1, round_robin, GFP_KERNEL,
+                                      node);
 }
 
 static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
                                                   int node, int alloc_policy)
 {
        unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
+       bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
 
-       tags->alloc_policy = alloc_policy;
-
-       if (bt_alloc(&tags->bitmap_tags, depth, node))
+       if (bt_alloc(&tags->bitmap_tags, depth, round_robin, node))
                goto free_tags;
-       if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node))
+       if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, round_robin,
+                    node))
                goto free_bitmap_tags;
 
        return tags;
@@ -403,11 +398,6 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
        if (!tags)
                return NULL;
 
-       if (!zalloc_cpumask_var(&tags->cpumask, GFP_KERNEL)) {
-               kfree(tags);
-               return NULL;
-       }
-
        tags->nr_tags = total_tags;
        tags->nr_reserved_tags = reserved_tags;
 
@@ -418,17 +408,9 @@ void blk_mq_free_tags(struct blk_mq_tags *tags)
 {
        sbitmap_queue_free(&tags->bitmap_tags);
        sbitmap_queue_free(&tags->breserved_tags);
-       free_cpumask_var(tags->cpumask);
        kfree(tags);
 }
 
-void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *tag)
-{
-       unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
-
-       *tag = prandom_u32() % depth;
-}
-
 int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
 {
        tdepth -= tags->nr_reserved_tags;
@@ -464,7 +446,7 @@ u32 blk_mq_unique_tag(struct request *rq)
        int hwq = 0;
 
        if (q->mq_ops) {
-               hctx = q->mq_ops->map_queue(q, rq->mq_ctx->cpu);
+               hctx = blk_mq_map_queue(q, rq->mq_ctx->cpu);
                hwq = hctx->queue_num;
        }