From patchwork Wed Apr 11 19:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasyl Gomonovych X-Patchwork-Id: 10336833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D30836020F for ; Wed, 11 Apr 2018 19:17:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1E682434C for ; Wed, 11 Apr 2018 19:17:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B672B25F3E; Wed, 11 Apr 2018 19:17:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0BAB2434C for ; Wed, 11 Apr 2018 19:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=QYUEKT0XnIPM1mu29SW9r3xyNG/v6mCdumINk8dIHNA=; b=OjS wAUbM2v+EfjIo7i4UFG1j2HzhSE4qkFg4usfQ5WodN0SUKTViELsSjX+gtPBaULb1ML7t9l/73DCh xsS7E6kKx7TDcgGozBala88OP/zKhLxLPEunyW36VbApH9qI8zWKgpV9oV5zT6J3iD8hzf3kaDyxp D/4FRh2JtWDrVEEFYzA8yqggdaREaqBRTE5BA4sfDhZxrWRyKNf09JelRZX3Xy19v2gse++loMm2a k7Mpj87hNeA3zKcOXrP5g/XXGAY2K1exO9Gwp/lnyDysERrzUPGyMWwFqnMmkZwR9lhnnrNNvKJ/x AWXCvgU1OUWmo3eKM3L0cHDop5CpZfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6LFJ-00063k-HZ; Wed, 11 Apr 2018 19:17:29 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6LFF-000615-VH for linux-arm-kernel@lists.infradead.org; Wed, 11 Apr 2018 19:17:27 +0000 Received: by mail-lf0-x241.google.com with SMTP id p142-v6so4218647lfd.6 for ; Wed, 11 Apr 2018 12:17:12 -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=jcWIEz66qI2xqfdcBh0MaryqLgR03e4iYanAy4KAnrs=; b=RPfslE34YZMUPmECvXzSDJqGsBKssBlFNhab3vX+E0Ew7pieh8GvSb5qFw4skLJpeo ssd6/edTd65WEOsn8Lpm6KVW+Ei2HmXoNPLSt19iPLmb3zwPiIgLx7gcE2Ecy7cw5aAj A2J5gSwggHrEOCPEmtlqbm5jEORztbvMwAANGRUmIVuwX0kZ60Ua1u/4U7MBsHPcYJIx 7NeypF70CPSLHRNZZ4cvN8BEYTspcG7D5Nvm+C24m3B5DxlDUzstztvi7BlR/qRrb2MJ e7wJYWGflQXVtlQ5IArQPTbTRCGrPO8Yo11+PDEzUdvfqo/6VkTb0FetZ0S8+8pq3S9K RbxQ== 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=jcWIEz66qI2xqfdcBh0MaryqLgR03e4iYanAy4KAnrs=; b=JWJ2LPCX7U3Pg08Mq2E1bdDKnQ4YTBLSJt5A5CrBchmkBmvp1SU+ZP9uOp7TmFkCOO Vsr/ODSnEKb7TpJPJW3QpLdkCjpt8R3ywMqk1l5vpBPQYdAfOI059ZZjcUT1znNSuzvc hmXMS8DzKPGehgEIn30MDP4vA18E/k/b/Pg3eks4IhxcSI6cQHcEw9gZFxHlnHNRdyVX Yv7HI8xDLdVakwHv4CPSz/C7KnytJgFyifAVD04YfU+PwnnqrBBLjMGFWOFBezp7yCZz WmphE0ntBv8oCCZFVXet6tkQ4+iR2WQ1gKvhTnJ29nzXBhqF11W3W/iuBSjZCtiqn367 zU7g== X-Gm-Message-State: ALQs6tAb2zs9hxQP3VyF3zex4np56L8CyqdomHI8bvGUirUWuIhDEjWI BlKxuGSGDlDIe6HPenQD/tA= X-Google-Smtp-Source: AIpwx48M7PJMBLaK/+/hEHPQ4LPfScRyQWbJqbBm9sOYYuueiHnyaZWjsr9QJqGDBbeg3jlFSqj0Aw== X-Received: by 2002:a19:12c1:: with SMTP id 62-v6mr1306917lfs.21.1523474230986; Wed, 11 Apr 2018 12:17:10 -0700 (PDT) Received: from localhost.localdomain ([195.254.138.66]) by smtp.gmail.com with ESMTPSA id p1sm311987lje.56.2018.04.11.12.17.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 12:17:09 -0700 (PDT) From: Vasyl Gomonovych To: gomonovych@gmail.com, ssantosh@kernel.org Subject: [PATCH] soc: ti: knav_qmss: Use percpu instead atomic for stats counter Date: Wed, 11 Apr 2018 21:16:29 +0200 Message-Id: <20180411191629.21545-1-gomonovych@gmail.com> X-Mailer: git-send-email 2.14.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180411_121726_050175_D8B1F18F X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hwqueue has collect statistics in heavy use queue_pop/queu_push functions for cache efficiency and make push/pop faster use percpu variables. For performance reasons, driver should keep descriptor in software handler as short as possible and quickly return it back to hardware queue. Descriptors coming into driver from hardware after pop and return back by push to reduce descriptor lifetime in driver collect statistics on percpu. Signed-off-by: Vasyl Gomonovych --- drivers/soc/ti/knav_qmss.h | 14 ++++++---- drivers/soc/ti/knav_qmss_queue.c | 60 ++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/drivers/soc/ti/knav_qmss.h b/drivers/soc/ti/knav_qmss.h index 905b974d1bdc..22f409b86107 100644 --- a/drivers/soc/ti/knav_qmss.h +++ b/drivers/soc/ti/knav_qmss.h @@ -19,6 +19,8 @@ #ifndef __KNAV_QMSS_H__ #define __KNAV_QMSS_H__ +#include + #define THRESH_GTE BIT(7) #define THRESH_LT 0 @@ -162,11 +164,11 @@ struct knav_qmgr_info { * notifies: notifier counts */ struct knav_queue_stats { - atomic_t pushes; - atomic_t pops; - atomic_t push_errors; - atomic_t pop_errors; - atomic_t notifies; + unsigned int pushes; + unsigned int pops; + unsigned int push_errors; + unsigned int pop_errors; + unsigned int notifies; }; /** @@ -283,7 +285,7 @@ struct knav_queue_inst { struct knav_queue { struct knav_reg_queue __iomem *reg_push, *reg_pop, *reg_peek; struct knav_queue_inst *inst; - struct knav_queue_stats stats; + struct knav_queue_stats __percpu *stats; knav_queue_notify_fn notifier_fn; void *notifier_fn_arg; atomic_t notifier_enabled; diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index 77d6b5c03aae..384d70bd8605 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -83,7 +83,7 @@ void knav_queue_notify(struct knav_queue_inst *inst) continue; if (WARN_ON(!qh->notifier_fn)) continue; - atomic_inc(&qh->stats.notifies); + this_cpu_inc(qh->stats->notifies); qh->notifier_fn(qh->notifier_fn_arg); } rcu_read_unlock(); @@ -214,6 +214,12 @@ static struct knav_queue *__knav_queue_open(struct knav_queue_inst *inst, if (!qh) return ERR_PTR(-ENOMEM); + qh->stats = alloc_percpu(struct knav_queue_stats); + if (!qh->stats) { + ret = -ENOMEM; + goto err; + } + qh->flags = flags; qh->inst = inst; id = inst->id - inst->qmgr->start_queue; @@ -229,13 +235,17 @@ static struct knav_queue *__knav_queue_open(struct knav_queue_inst *inst, if (range->ops && range->ops->open_queue) ret = range->ops->open_queue(range, inst, flags); - if (ret) { - devm_kfree(inst->kdev->dev, qh); - return ERR_PTR(ret); - } + if (ret) + goto err; } list_add_tail_rcu(&qh->list, &inst->handles); return qh; + +err: + if (qh->stats) + free_percpu(qh->stats); + devm_kfree(inst->kdev->dev, qh); + return ERR_PTR(ret); } static struct knav_queue * @@ -411,6 +421,12 @@ static void knav_queue_debug_show_instance(struct seq_file *s, { struct knav_device *kdev = inst->kdev; struct knav_queue *qh; + int cpu = 0; + int pushes = 0; + int pops = 0; + int push_errors = 0; + int pop_errors = 0; + int notifies = 0; if (!knav_queue_is_busy(inst)) return; @@ -418,19 +434,22 @@ static void knav_queue_debug_show_instance(struct seq_file *s, seq_printf(s, "\tqueue id %d (%s)\n", kdev->base_id + inst->id, inst->name); for_each_handle_rcu(qh, inst) { - seq_printf(s, "\t\thandle %p: ", qh); - seq_printf(s, "pushes %8d, ", - atomic_read(&qh->stats.pushes)); - seq_printf(s, "pops %8d, ", - atomic_read(&qh->stats.pops)); - seq_printf(s, "count %8d, ", - knav_queue_get_count(qh)); - seq_printf(s, "notifies %8d, ", - atomic_read(&qh->stats.notifies)); - seq_printf(s, "push errors %8d, ", - atomic_read(&qh->stats.push_errors)); - seq_printf(s, "pop errors %8d\n", - atomic_read(&qh->stats.pop_errors)); + for_each_possible_cpu(cpu) { + pushes += per_cpu_ptr(qh->stats, cpu)->pushes; + pops += per_cpu_ptr(qh->stats, cpu)->pops; + push_errors += per_cpu_ptr(qh->stats, cpu)->push_errors; + pop_errors += per_cpu_ptr(qh->stats, cpu)->pop_errors; + notifies += per_cpu_ptr(qh->stats, cpu)->notifies; + } + + seq_printf(s, "\t\thandle %p: pushes %8d, pops %8d, count %8d, notifies %8d, push errors %8d, pop errors %8d\n", + qh, + pushes, + pops, + knav_queue_get_count(qh), + notifies, + push_errors, + pop_errors); } } @@ -547,6 +566,7 @@ void knav_queue_close(void *qhandle) if (range->ops && range->ops->close_queue) range->ops->close_queue(range, inst); } + free_percpu(qh->stats); devm_kfree(inst->kdev->dev, qh); } EXPORT_SYMBOL_GPL(knav_queue_close); @@ -620,7 +640,7 @@ int knav_queue_push(void *qhandle, dma_addr_t dma, val = (u32)dma | ((size / 16) - 1); writel_relaxed(val, &qh->reg_push[0].ptr_size_thresh); - atomic_inc(&qh->stats.pushes); + this_cpu_inc(qh->stats->pushes); return 0; } EXPORT_SYMBOL_GPL(knav_queue_push); @@ -658,7 +678,7 @@ dma_addr_t knav_queue_pop(void *qhandle, unsigned *size) if (size) *size = ((val & DESC_SIZE_MASK) + 1) * 16; - atomic_inc(&qh->stats.pops); + this_cpu_inc(qh->stats->pops); return dma; } EXPORT_SYMBOL_GPL(knav_queue_pop);