Skip to content

Commit 66e26a4

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: host: mediatek: Set IRQ affinity policy for MCQ mode
Set the IRQ affinity for MCQ mode to improve performance. Specifically, it migrates the IRQ from CPU0 to CPU3 to enhance IRQ handling efficiency. Setting IRQ affinity directly from the kernel allows the configuration to take effect earlier, and provides greater security and consistency, especially important for systems with strict performanceor real-time requirements. Signed-off-by: Peter Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chun-Hung Wu <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a44ff97 commit 66e26a4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

drivers/ufs/host/ufs-mediatek.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,46 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
798798
return ret;
799799
}
800800

801+
static u32 ufs_mtk_mcq_get_irq(struct ufs_hba *hba, unsigned int cpu)
802+
{
803+
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
804+
struct blk_mq_tag_set *tag_set = &hba->host->tag_set;
805+
struct blk_mq_queue_map *map = &tag_set->map[HCTX_TYPE_DEFAULT];
806+
unsigned int nr = map->nr_queues;
807+
unsigned int q_index;
808+
809+
q_index = map->mq_map[cpu];
810+
if (q_index > nr) {
811+
dev_err(hba->dev, "hwq index %d exceed %d\n",
812+
q_index, nr);
813+
return MTK_MCQ_INVALID_IRQ;
814+
}
815+
816+
return host->mcq_intr_info[q_index].irq;
817+
}
818+
819+
static void ufs_mtk_mcq_set_irq_affinity(struct ufs_hba *hba, unsigned int cpu)
820+
{
821+
unsigned int irq, _cpu;
822+
int ret;
823+
824+
irq = ufs_mtk_mcq_get_irq(hba, cpu);
825+
if (irq == MTK_MCQ_INVALID_IRQ) {
826+
dev_err(hba->dev, "invalid irq. unable to bind irq to cpu%d", cpu);
827+
return;
828+
}
829+
830+
/* force migrate irq of cpu0 to cpu3 */
831+
_cpu = (cpu == 0) ? 3 : cpu;
832+
ret = irq_set_affinity(irq, cpumask_of(_cpu));
833+
if (ret) {
834+
dev_err(hba->dev, "set irq %d affinity to CPU %d failed\n",
835+
irq, _cpu);
836+
return;
837+
}
838+
dev_info(hba->dev, "set irq %d affinity to CPU: %d\n", irq, _cpu);
839+
}
840+
801841
static void ufs_mtk_get_controller_version(struct ufs_hba *hba)
802842
{
803843
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
@@ -1527,6 +1567,13 @@ static int ufs_mtk_apply_dev_quirks(struct ufs_hba *hba)
15271567
{
15281568
struct ufs_dev_info *dev_info = &hba->dev_info;
15291569
u16 mid = dev_info->wmanufacturerid;
1570+
unsigned int cpu;
1571+
1572+
if (hba->mcq_enabled) {
1573+
/* Iterate all cpus to set affinity for mcq irqs */
1574+
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
1575+
ufs_mtk_mcq_set_irq_affinity(hba, cpu);
1576+
}
15301577

15311578
if (mid == UFS_VENDOR_SAMSUNG) {
15321579
ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TACTIVATE), 6);

0 commit comments

Comments
 (0)