From patchwork Thu Apr 25 19:53:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 162867 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2362518jan; Thu, 25 Apr 2019 12:53:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3VKLFNh5QoK+vSZOanD8dQV7Md46GweVWvESadoGVMPuYjbJwlb7zi/0dlVpWA/cL2nC4 X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr41751375plq.234.1556222028211; Thu, 25 Apr 2019 12:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556222028; cv=none; d=google.com; s=arc-20160816; b=M1ZJKRO43I4+Happ/04fLerds4/rn6doArPHGhry2BIkTw0EZ7TBDnZowZuc4d6Vvn F4ZPQ9lcUmou3L3NmJOiE+YCwci1qmNSguXZ82oD5Rj3z9e3hpP0CkpE31QAyMZQd5ek IkOqe4wrX9IFxyS2MtNgkPVPTN3gcpGIpqJEnxMrahPbItPDe55mvrbKVGTHspzKSs+b sNlgOT0RqxC+uM63tc8ewBt/luU6d6te6xjUu/tnj3NwkJYQ1TnmoBERXiArWWLzInaF k9dvqhRsrSrSqKmygL9yGtYLCglOgTxx4+pJPd/7c3jZEN8Dt2JhrmO22XzOia/+35OK TzuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XBoKGJ3NBpX+0QpEcxQgM6T5eOFdLhBw4o64el6pVv8=; b=EY4aofuPXNChE4UiizRaVUvHPV04ldCMtzGRDjHBXeMVBlm8c7r3uhww4y3eRKqAhy nLH+qNCiSLhK3c10lCS9O8jf5bQ+jIJ44Q06/abHv1dTrrnFCyJib1uzHVZOYePbiUah 9z5Z73zc0bVwBGno1G89n0QNou9Dr29XEqJYnZqgW7cqEhrz1T49cFc7J7MU+lBr1pps vvnDbqAShZv7g9tBiFxBqO8BXEntcZNiZKqb7c544xx1xJuvnhgftOhXByYQ8i8SYvbC Gge+zhicleoWJKw668Kky0HlBHVk22F1qmzAcOX7a8xlHp8J3mUNlG1gg5yXlSJhSRrG cn3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGnsIWFn; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si24127877plb.276.2019.04.25.12.53.47; Thu, 25 Apr 2019 12:53:48 -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=@linaro.org header.s=google header.b=HGnsIWFn; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730748AbfDYTxq (ORCPT + 30 others); Thu, 25 Apr 2019 15:53:46 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35720 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730708AbfDYTxo (ORCPT ); Thu, 25 Apr 2019 15:53:44 -0400 Received: by mail-pf1-f194.google.com with SMTP id t21so446429pfh.2 for ; Thu, 25 Apr 2019 12:53:43 -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=XBoKGJ3NBpX+0QpEcxQgM6T5eOFdLhBw4o64el6pVv8=; b=HGnsIWFn4b5O6kKBRdpR1PsesB627x+xvgTbDN+UtpU7rrh3GW2cjFQI/vHtW2uGWT +jt6r1eWuPCkTidtEZGjEz9BBzdHrtM3Fgv09k7FI6wtzPujrJf3ZPATscyJA5JGvOVB xwWLqw4HlgobFMVm+FVM8OMCu/8TNFh/B42xbj7vvIiH9ksgw3yIz6AWPR1q34HVFmqy zWjv2+GHOzRvkx5WEthV2ri76hDx6XjxJmw5Qv8qP9seJ/zey1vly3OF1A/TpcgFiyua DZ+Vy0qHBydbjqfiZyXDMI/TczJSvY6juQjET94us2xD30USL3iRjlB/bKsDGj+XiOw7 8Mvw== 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=XBoKGJ3NBpX+0QpEcxQgM6T5eOFdLhBw4o64el6pVv8=; b=gowWgP9pbdLTRYsUr4Aqdx42aYJLU8FFSPQiYybt6fOBcQNasjglC9zjmPFuoBFMgC ox9zvl6rOQx8WOHauhalyJ6abPgM0trgl3bOL8VzbONcS2KXLzZ99hXebVgVlpRESIlL 07z36/gVmbnc/Ezltza0L53OlY61QJqHKJ94NY9LRlKN1qBzexFRUyBn1H5E4KZZOWvs X4bbbz1dqmNwEMtFdCcMjEMUJ2UO2bhJiWfcaW8ifHMLD0bgDsPxAWmUT8j7cSP7A3Sb PZkz5D9zhEw7u0DVeb9kBnAbvxazPznGEEd399vgKFB6KMjEV3m2ElUBAQYWOTHViO8b uvwQ== X-Gm-Message-State: APjAAAVDh5cWTcTlyBjsj65tdR1tT0OlkDmT126zBGNuuc5hXjwvTrGd wGD9UhNiMBWRraj6rQfDitPJip4a2Rw= X-Received: by 2002:a63:ff26:: with SMTP id k38mr39270549pgi.123.1556222023475; Thu, 25 Apr 2019 12:53:43 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id t64sm47261961pfa.86.2019.04.25.12.53.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 12:53:42 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/32] coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf() Date: Thu, 25 Apr 2019 13:53:02 -0600 Message-Id: <20190425195310.31562-25-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190425195310.31562-1-mathieu.poirier@linaro.org> References: <20190425195310.31562-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Tested-by: Leo Yan Tested-by: Robert Walker --- .../hwtracing/coresight/coresight-tmc-etr.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 55ee0aca321c..e1d2128ee757 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1160,29 +1160,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. @@ -1206,6 +1201,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);