Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27625807rwd; Tue, 4 Jul 2023 05:45:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FMECeUlvrwNpDJ1NVLUFW7N11lae8bc7rCkwf0kaHMniKTDa8YI6W1+9MZDVyNBO6ZNm6 X-Received: by 2002:a05:6a20:3d89:b0:127:aaf:59a2 with SMTP id s9-20020a056a203d8900b001270aaf59a2mr18144462pzi.35.1688474726597; Tue, 04 Jul 2023 05:45:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688474726; cv=none; d=google.com; s=arc-20160816; b=KcEABBibR0R2EgNJYfK2fcXL8bfkJ7l/H85p5NvhySoQrezZT8b1xRwijlVLW/OMm/ Tjxgbsc5dgCc2STKzbSZmPiY+FTdmGaR0MNSDQUrfKCHqPkowbaI+9WwSnLUVq3+18Ei tYXpwh82rW1vNPavZSooOtydLhmVxjL78+xPxyccg4+PXSbjUfWLxsFPCjp1kzR/Pz8R Aiify38/pppdpTcRVrEhz3rZdbMfjCVrc2ssjQff855diphdY6nQJrg5HBcyCTeu1AFh ia4toJRS5OYDL5fU/bEpUIPb6NutSPRRHcoP/wTkWe17NzLrTyBHue0rfs/TTmD0pdq0 qJlA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a056a00238300b00678a41b5a59si17813509pfc.349.2023.07.04.05.45.11; Tue, 04 Jul 2023 05:45:26 -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 S230335AbjGDM1Y (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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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; } -- 2.25.1