From patchwork Thu Apr 4 03:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB56613B5 for ; Thu, 4 Apr 2019 03:37:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEB5C289BF for ; Thu, 4 Apr 2019 03:37:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A340E28A30; Thu, 4 Apr 2019 03:37:36 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 44DF528A27 for ; Thu, 4 Apr 2019 03:37:36 +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:References: In-Reply-To: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:List-Owner; bh=ISWBjR8flQvgmqMwJ1RGh1A8v+7TC3p6XWhsPKBFNc8=; b=AvQhzrVZmhgjNlEaWvNu6w1HjQ 6L+UivDVVX/+slpxisqRQimr1p0BZQEyB8EXSnqZgfFpV+SeJiekwck4+G8tjZD7Z9t8nLopYPWYe qqKBXsuWxWSlesz5PqdpWq/Ywbw/pLo1toRmB22Ei2K2fnzHeV0TYTuDPwWV+om4Tnp+cs1bLiwXW Nt26UvSjRc5fC4MoEVDAs3MT+i4oaPOsmqW9eESvnOHOXgaUBOV/MRan58oViAxF7HjTWmK6zRsio hCxPPGwPwqgcIoEYyZeF3/TQ0CdLwJbsRWYAT38OJgihFVALNo5gzUihEUlgzpAbkes1QJofhMZqH g5S9qCTw==; 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 1hBtC1-0004qG-L4; Thu, 04 Apr 2019 03:37:33 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtB3-0003cJ-Nt for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:03 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so618955pfc.7 for ; Wed, 03 Apr 2019 20:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dOOzJONg42NBLUevdjidfidJoqrClGTmFfG3kUUzoxQ=; b=qXhOlJqPUARfaFRhk52W+mdWfLOuctMZRZL+W/w7PkoTzwJehVfu/CSbnqE7KuHEbG wEqDswYmao+uuJ55P/SNTWJ2q+VHF7M3zbj5UnFBy2rn8iq/LS2lKxzff5g/qcxYZIw3 qdgM5FuaS/DEGzMCy8RiTbrxYmNRZzKx5Jh/QwJ0GUQQoCRa4YBuph91rmXfm3W2FiZY tW09b3cejjCN2nmCbToB8Gfg0i28XiA6P+IbyAUWekRyrMpimXCB92W44kpgi6+kZFES umLywbqC2ssdNYBrLJseCl3SdmPWBGzZmWZnY1ptvETPAi2wGf1xB7Vwzs1EehjWIHi+ en2g== 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:in-reply-to :references; bh=dOOzJONg42NBLUevdjidfidJoqrClGTmFfG3kUUzoxQ=; b=cTXjyVs6FQHq0ARmx0c/xeZEgwmduYpTFlB6mvhdkthiIt0YJZFZDmYR26H2HxvFcP 8vpWnH/GSVM2g41ONxH4140wQJCQ54DA7vQRdMGsnmcE14Ybp3aFHly41sHOj7MqcKVf mXo8eQPCpfvsWbG400r01DXg3oIxk0rQbRwBb1/bYO5SSadJBUqRWroGJr8cZmjhtzFl 6Tthagj2utjqf+Ay7YK8I4Ke3ksSrj9ElenCVV5+20GqMY3jdOhkAXDMv5wZusCufBQR bimyVKOkh0zeGjqARo6vggKoxU67+YwkYtiDfPLxK0Sga3vg38/rewcFdUGJNVCbYlC5 rtog== X-Gm-Message-State: APjAAAULFmbSE/cSeShh0DLyg+dWpEgTENCVtgGf1KI3mh2mbXcTRxPl XyYgtxzEwTiDGCFYF5WafELVte6qLew= X-Google-Smtp-Source: APXvYqzxpJ20zCtqQ3VxnIub/k1QTL0CDHWGDt+viLS9oCnQwvYmGaU5Drsu/DVa+tv4mjL3A3Q0bA== X-Received: by 2002:a63:8143:: with SMTP id t64mr3341387pgd.301.1554348993093; Wed, 03 Apr 2019 20:36:33 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:32 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 12/20] coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf() Date: Wed, 3 Apr 2019 21:35:33 -0600 Message-Id: <20190404033541.14072-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203634_212706_DDCDA570 X-CRM114-Status: GOOD ( 15.15 ) 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: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.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 Refactoring function tmc_etr_setup_perf_buf() so that it only deals with the high level etr_perf_buffer, leaving the allocation of the backend buffer (i.e etr_buf) to another function. That way the backend buffer allocation function can decide if it wants to reuse an existing buffer (CPU-wide trace scenarios) or simply create a new one. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etr.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 00db6a6ce23f..e9c77009188a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1159,29 +1159,24 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } /* - * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. + * alloc_etr_buf: Allocate ETR buffer for use by perf. * The size of the hardware buffer is dependent on the size configured * via sysfs and the perf ring buffer size. We prefer to allocate the * largest possible size, scaling down the size by half until it * reaches a minimum limit (1M), beyond which we give up. */ -static struct etr_perf_buffer * -tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, - int nr_pages, void **pages, bool snapshot) +static struct etr_buf * +alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) { int node, cpu = event->cpu; struct etr_buf *etr_buf; - struct etr_perf_buffer *etr_perf; unsigned long size; if (cpu == -1) cpu = smp_processor_id(); node = cpu_to_node(cpu); - etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); - if (!etr_perf) - return ERR_PTR(-ENOMEM); - /* * Try to match the perf ring buffer size if it is larger * than the size requested via sysfs. @@ -1205,6 +1200,32 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, size /= 2; } while (size >= TMC_ETR_PERF_MIN_BUF_SIZE); + return ERR_PTR(-ENOMEM); + +done: + return etr_buf; +} + +static struct etr_perf_buffer * +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) +{ + int node, cpu = event->cpu; + struct etr_buf *etr_buf; + struct etr_perf_buffer *etr_perf; + + if (cpu == -1) + cpu = smp_processor_id(); + node = cpu_to_node(cpu); + + etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); + if (!etr_perf) + return ERR_PTR(-ENOMEM); + + etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + if (!IS_ERR(etr_buf)) + goto done; + kfree(etr_perf); return ERR_PTR(-ENOMEM);