Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2787821ybd; Mon, 24 Jun 2019 12:40:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyq7BNeVse4Q9fJVFt3W8sy5k2Og3RZyWSTPF/51AiR8q7CHBjjxWUv9EIgpQFkKz0OcJV1 X-Received: by 2002:a17:90a:26a1:: with SMTP id m30mr27316989pje.59.1561405239812; Mon, 24 Jun 2019 12:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561405239; cv=none; d=google.com; s=arc-20160816; b=M+PT5xqo92YyG6KZzhNeUQgIeDcSXsKQ1SkefEOZzCdRYhTKUEFi2YkAGFUbz6Tjzo zUBNI8w7b6mx67epqdAjQXykaH7FREC0LeVsOiEDSuy1jIrfXU7zdawq9fro8w4JZrCj 5Un5URIVVSDj8ZTuiTdPPLqC5Enf1uqbYtaR49V1E4bXSzp94jdlkQzdvlOPn4+vJL/B U1YyOMtYAQvL3Otyx13tRRXr3QEPm15UlAdgRwB3t4s6z7FhjZH/IFmUqq2M5+Btj8ip 6clCnTXSGbHPEr5NxKOouHByGjYgEaQeZciTLwymRwDs7O/CFBrWCenAG9UxVZbwe9SF NvDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=lgND2Ln1TBQQyZCEAnGKpymz91Liq3socwltmWkX9XY=; b=BiHjE5a8a1HmubHlnANNFhvz/HAr/1NyH+Jm3SGbrHhc4woHrBJfjbhfxe3Mv+pfVN FiJ/P/YpX1WLSKtgNzDBUZqYv/bpEz3/6ymYnQCMO78ebTTOPIUcdByj5dVcfRSNSdck Ka/By9TAX6SbrXz1vYRlzqQ3exXc+BvQUe31U14QUoMAIf8nyvmYIwWVDZTuqxJF5e5h uIpT15zmVmqZe+rv6TRZQYtg9kkx5610ogiK73qcW1QIVir1K2GOWJxcHUD+XWqyXmkf 4xd6OiC9iOSCzM1NSvB+XtR2EV3IM1LtBsXkorFMZjgaQokTsxJv0cuZ2RMddCCW1v75 oiCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dYAtPv+9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si10233268pgq.226.2019.06.24.12.40.24; Mon, 24 Jun 2019 12:40:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dYAtPv+9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730798AbfFXPY0 (ORCPT + 99 others); Mon, 24 Jun 2019 11:24:26 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38371 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729026AbfFXPYZ (ORCPT ); Mon, 24 Jun 2019 11:24:25 -0400 Received: by mail-pg1-f193.google.com with SMTP id z75so4689241pgz.5; Mon, 24 Jun 2019 08:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lgND2Ln1TBQQyZCEAnGKpymz91Liq3socwltmWkX9XY=; b=dYAtPv+90C/VZ7Prob7WQ5L59If12of+wMC6Hzb+7Dxwqz1ZgnNyG3pu8E4fGOUchx drEImF0lbTOnCDOkUHGSZ7wbgkQYOSfBftt5Q2NIikF4PEKMSJOdhOUCOptP29vcLORw 4CctNYGVzXWa36/or8Mi3nVXspD7250Hy5k7ZffISYCusmRjAFkrze+gc227HLVWP4bC DSO1o7pkfyEsrudhx5FZh3kbAJMRR1JBcozhBJN02fwQZFo4HwEq5u2nzCXIWxHSt25H ycz2LRsZ58khQZoxbwBOK+QXlgmm393SvEZ7K8z1sKW6gnzzibIBjVLReb9U/sBvDyct JUHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lgND2Ln1TBQQyZCEAnGKpymz91Liq3socwltmWkX9XY=; b=CvRBx8XtBlAYaVsBwUpUMaUwA8AyDxkG0oGZuxibhrvdUeYu0pptsv7vIBZS2Hpu7Q wVoOysE+pW4/6xpNWg0C8ZO8wf0E4LH7HbVFYmCgMV62ZXeyk6vExIuW22xqYjTFT6iF QTnsDF3RjoR17MgN0Hc/2fLvjrrBCHDBMNXdHhHCose5KaIf3Ayy+vOKsQPYktjGp8V3 GLHWZAl4K7xr8bB/cElilIZcTTLB+UKWHl1JHWNiaXezvuWlbt4r9SkkQsQIUXb1mFku ncYntF5h4PnpWsgYjEYsDicMkgzqUFW9t+ybHjunWBuUiHLxBMotyflzA5EFxoZlka6m Emzw== X-Gm-Message-State: APjAAAXYXJVUTIqsMSvXWQusIxiNsGL+AG/1T6Zi9Mb6MijpXS/2JmGI JxNiroCqGcTY0EVFjuBiAfDSogEm X-Received: by 2002:a17:90b:d8a:: with SMTP id bg10mr25646706pjb.92.1561389865084; Mon, 24 Jun 2019 08:24:25 -0700 (PDT) Received: from bridge.tencent.com ([119.28.31.106]) by smtp.gmail.com with ESMTPSA id e63sm20066869pgc.62.2019.06.24.08.24.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 08:24:24 -0700 (PDT) From: Wenbin Zeng X-Google-Original-From: Wenbin Zeng To: axboe@kernel.dk, keith.busch@intel.com, hare@suse.com, ming.lei@redhat.com, osandov@fb.com, sagi@grimberg.me, bvanassche@acm.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Wenbin Zeng Subject: [PATCH] blk-mq: update hctx->cpumask at cpu-hotplug Date: Mon, 24 Jun 2019 23:24:07 +0800 Message-Id: <1561389847-30853-1-git-send-email-wenbinzeng@tencent.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently hctx->cpumask is not updated when hot-plugging new cpus, as there are many chances kblockd_mod_delayed_work_on() getting called with WORK_CPU_UNBOUND, workqueue blk_mq_run_work_fn may run on the newly-plugged cpus, consequently __blk_mq_run_hw_queue() reporting excessive "run queue from wrong CPU" messages because cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask) returns false. This patch added a cpu-hotplug handler into blk-mq, updating hctx->cpumask at cpu-hotplug. Signed-off-by: Wenbin Zeng --- block/blk-mq.c | 29 +++++++++++++++++++++++++++++ include/linux/blk-mq.h | 1 + 2 files changed, 30 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index ce0f5f4..2e465fc 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -39,6 +39,8 @@ #include "blk-mq-sched.h" #include "blk-rq-qos.h" +static enum cpuhp_state cpuhp_blk_mq_online; + static void blk_mq_poll_stats_start(struct request_queue *q); static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb); @@ -2215,6 +2217,21 @@ int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, return -ENOMEM; } +static int blk_mq_hctx_notify_online(unsigned int cpu, struct hlist_node *node) +{ + struct blk_mq_hw_ctx *hctx; + + hctx = hlist_entry_safe(node, struct blk_mq_hw_ctx, cpuhp_online); + + if (!cpumask_test_cpu(cpu, hctx->cpumask)) { + mutex_lock(&hctx->queue->sysfs_lock); + cpumask_set_cpu(cpu, hctx->cpumask); + mutex_unlock(&hctx->queue->sysfs_lock); + } + + return 0; +} + /* * 'cpu' is going away. splice any existing rq_list entries from this * software queue to the hw queue dispatch list, and ensure that it @@ -2251,6 +2268,9 @@ static int blk_mq_hctx_notify_dead(unsigned int cpu, struct hlist_node *node) static void blk_mq_remove_cpuhp(struct blk_mq_hw_ctx *hctx) { + if (cpuhp_blk_mq_online > 0) + cpuhp_state_remove_instance_nocalls(cpuhp_blk_mq_online, + &hctx->cpuhp_online); cpuhp_state_remove_instance_nocalls(CPUHP_BLK_MQ_DEAD, &hctx->cpuhp_dead); } @@ -2310,6 +2330,9 @@ static int blk_mq_init_hctx(struct request_queue *q, { hctx->queue_num = hctx_idx; + if (cpuhp_blk_mq_online > 0) + cpuhp_state_add_instance_nocalls(cpuhp_blk_mq_online, + &hctx->cpuhp_online); cpuhp_state_add_instance_nocalls(CPUHP_BLK_MQ_DEAD, &hctx->cpuhp_dead); hctx->tags = set->tags[hctx_idx]; @@ -3544,6 +3567,12 @@ unsigned int blk_mq_rq_cpu(struct request *rq) static int __init blk_mq_init(void) { + cpuhp_blk_mq_online = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, + "block/mq:online", + blk_mq_hctx_notify_online, NULL); + if (cpuhp_blk_mq_online <= 0) + pr_warn("blk_mq_init: failed to setup cpu online callback\n"); + cpuhp_setup_state_multi(CPUHP_BLK_MQ_DEAD, "block/mq:dead", NULL, blk_mq_hctx_notify_dead); return 0; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 15d1aa5..5241659 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -58,6 +58,7 @@ struct blk_mq_hw_ctx { atomic_t nr_active; + struct hlist_node cpuhp_online; struct hlist_node cpuhp_dead; struct kobject kobj; -- 1.8.3.1