From patchwork Wed Jul 5 00:27:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 115753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1195987vqx; Tue, 4 Jul 2023 05:50:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlGUipFZodtOk9/RBXWTdjVsh/+MxeX/TPsdQfLrwOv7sEt0ySddlQvwTk9IqElh9tAHF27Y X-Received: by 2002:a05:6a21:6811:b0:118:b2e1:9adb with SMTP id wr17-20020a056a21681100b00118b2e19adbmr10981291pzb.61.1688475008872; Tue, 04 Jul 2023 05:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688475008; cv=none; d=google.com; s=arc-20160816; b=NBrNPP9Nmh/V+IMl59+SWH/4XrtogfU6Rzmun+L57nboy20f4BUGMucVQTaSXi2MXA +BQlhHFc2hQSXcMeKKgy2PLC0VIQJQBp0WM5vQcr9LOgq/gF+uUXa69VktN2W/Ken5eC Fik1mMGhkxBhyEOWB2AidD53S4QByXVFndhJHqOFh9yPvXfP/qqDhLKzFMAMyfsF17CM k6fJryto3jmVry08fiVZ+S8ZSMBlWqG3bDbOOo9AIZ9V4XJ1YmskwYyquzlV4WoMuAG3 GbN02wM+YAnlhKunXH/SMFfiVINgcLdC0WXz2set5D24SBodFDSUqOem2jRKZS9REQcr hiMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=K9uohXT9GGtzNY1pc0Y4bRzcUTIbMA7piX8giXlRB/I=; fh=PwHYXN3KuwhE6QCpsOa/5p0UIeb3ZMBZjsuIaG9V42k=; b=TeKSlFwnh5D7QAvI7DM83Xc7qETWeXlSEKhGXhdGIiskYwbuVtXqSkrPoxAZHkrLQH nDbnEv7edAkf4k5mDm7DVJfo/5h2NPRcvQ+EPXgt7yO+Kx3YB+UMOx8OrVoJciIzjDH7 zvM7uup6Hj9wP0cWhLWEYMwOBHaBMvjR4RjTAeVc8jrRGbDP9oIzM6kVT7cc1dDTt+hx D5L4lbXdMpzyWZRJLjUwAMyJTioF8vUyxpl+vyf/+VjKDEDjlp4NAwUkugKJtBLCBZYb hnIuMJ2thHrT6I4B1wXLeXpAGddhwUY6qlezv7vKLsvX5mUrWEHOVNh1G9SM0V4IuiDS AVNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z29-20020aa79f9d000000b006825a7e9415si9287154pfr.354.2023.07.04.05.49.54; Tue, 04 Jul 2023 05:50:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbjGDM1Y (ORCPT + 99 others); Tue, 4 Jul 2023 08:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjGDM1E (ORCPT ); Tue, 4 Jul 2023 08:27:04 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA2410D8; Tue, 4 Jul 2023 05:26:36 -0700 (PDT) Received: from dggpeml500012.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QwMRW0ZNszLnfY; Tue, 4 Jul 2023 20:24:23 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 4 Jul 2023 20:26:34 +0800 From: Zheng Yejian To: , CC: , , Subject: [PATCH] tracing: Set actual size after ring buffer resize Date: Wed, 5 Jul 2023 08:27:05 +0800 Message-ID: <20230705002705.576633-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500012.china.huawei.com (7.185.36.15) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770494370611138203?= X-GMAIL-MSGID: =?utf-8?q?1770494370611138203?= Currently we can resize trace ringbuffer by writing a value into file 'buffer_size_kb', then by reading the file, we get the value that is usually what we wrote. However, this value may be not actual size of trace ring buffer because of the round up when doing resize in kernel, and the actual size would be more useful. Signed-off-by: Zheng Yejian --- kernel/trace/trace.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b04f52e7cd28..37e0e0b5ff6d 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6287,6 +6287,15 @@ static void set_buffer_entries(struct array_buffer *buf, unsigned long val) per_cpu_ptr(buf->data, cpu)->entries = val; } +static void update_buffer_entries(struct array_buffer *buf, int cpu) +{ + if (cpu == RING_BUFFER_ALL_CPUS) { + set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0)); + } else { + per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu); + } +} + #ifdef CONFIG_TRACER_MAX_TRACE /* resize @tr's buffer to the size of @size_tr's entries */ static int resize_buffer_duplicate_size(struct array_buffer *trace_buf, @@ -6365,18 +6374,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, return ret; } - if (cpu == RING_BUFFER_ALL_CPUS) - set_buffer_entries(&tr->max_buffer, size); - else - per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; + update_buffer_entries(&tr->max_buffer, cpu); out: #endif /* CONFIG_TRACER_MAX_TRACE */ - if (cpu == RING_BUFFER_ALL_CPUS) - set_buffer_entries(&tr->array_buffer, size); - else - per_cpu_ptr(tr->array_buffer.data, cpu)->entries = size; + update_buffer_entries(&tr->array_buffer, cpu); return ret; }