From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3714BC83F2C for ; Mon, 4 Sep 2023 11:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352848AbjIDLqL (ORCPT ); Mon, 4 Sep 2023 07:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352841AbjIDLqJ (ORCPT ); Mon, 4 Sep 2023 07:46:09 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9E3CC6; Mon, 4 Sep 2023 04:46:05 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RfRZs5m1Hz1DDXx; Mon, 4 Sep 2023 19:42:45 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 4 Sep 2023 19:46:03 +0800 Subject: Re: [RFC v1 05/16] perf kwork: Overwrite original atom in the list when a new atom is pushed. To: Ian Rogers CC: , , , , , , , , , , , , References: <20230812084917.169338-1-yangjihong1@huawei.com> <20230812084917.169338-6-yangjihong1@huawei.com> From: Yang Jihong Message-ID: <91cb7bea-3bec-b40c-24a2-be9052a30937@huawei.com> Date: Mon, 4 Sep 2023 19:46:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On 2023/9/4 12:13, Ian Rogers wrote: > On Sat, Aug 12, 2023 at 1:52 AM Yang Jihong wrote: >> >> work_push_atom() supports nesting. Currently, all supported kworks are not >> nested. A `overwrite` parameter is added to overwrite the original atom in >> the list. >> >> Signed-off-by: Yang Jihong >> --- >> tools/perf/builtin-kwork.c | 24 ++++++++++++++++++------ >> 1 file changed, 18 insertions(+), 6 deletions(-) >> >> diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c >> index 42ea59a957ae..f620911a26a2 100644 >> --- a/tools/perf/builtin-kwork.c >> +++ b/tools/perf/builtin-kwork.c >> @@ -392,9 +392,10 @@ static int work_push_atom(struct perf_kwork *kwork, >> struct evsel *evsel, >> struct perf_sample *sample, >> struct machine *machine, >> - struct kwork_work **ret_work) >> + struct kwork_work **ret_work, >> + bool overwrite) > > kerneldoc would be useful. Pushing something seems self-evident but > what does overwrite mean without reading the code? Okay, I'll add comments. > >> { >> - struct kwork_atom *atom, *dst_atom; >> + struct kwork_atom *atom, *dst_atom, *last_atom; >> struct kwork_work *work, key; >> >> BUG_ON(class->work_init == NULL); >> @@ -427,6 +428,17 @@ static int work_push_atom(struct perf_kwork *kwork, >> if (ret_work != NULL) >> *ret_work = work; >> >> + if (overwrite) { >> + last_atom = list_last_entry_or_null(&work->atom_list[src_type], >> + struct kwork_atom, list); >> + if (last_atom) { >> + atom_del(last_atom); >> + >> + kwork->nr_skipped_events[src_type]++; >> + kwork->nr_skipped_events[KWORK_TRACE_MAX]++; >> + } >> + } >> + >> list_add_tail(&atom->list, &work->atom_list[src_type]); >> >> return 0; >> @@ -502,7 +514,7 @@ static int report_entry_event(struct perf_kwork *kwork, >> { >> return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, >> KWORK_TRACE_MAX, evsel, sample, >> - machine, NULL); >> + machine, NULL, true); > > nit: for constant arguments it can be useful to add parameter names > which can enable checks like clang-tidy's bugprone argument: > https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html > This would make this: > return work_push_atom(kwork, class, KWORK_TRACE_ENTRY, > KWORK_TRACE_MAX, evsel, sample, > machine, /*ret_work=*/NULL, /*overwite=*/true); > Thanks for your advice, will add parameter names later. Thanks, Yang