Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1609240pxb; Mon, 11 Oct 2021 09:24:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1Ce+i6pa0DIRX6LAGHZWzDJ8nQnYLGbmVdJf0QFNKX/5L5WluTX/4tCR/H965K1yLPq/5 X-Received: by 2002:a17:907:7686:: with SMTP id jv6mr4712364ejc.486.1633969490470; Mon, 11 Oct 2021 09:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969490; cv=none; d=google.com; s=arc-20160816; b=UoNDNoR9e76tGV+/62xh5YFiXCY1FyHtglivNWuhkJacWRuoumiFSeiL7KH38h21Gm T7LNSix7DFIwa7jWQuEk1fjZMNTkHC3vACcsUL0QiNoVtLwJLpVm9go8lXKJsTZT/Hvr ZxbrThlFS4JUJOkdb4ThtGkY/HLRs71RyalZHUko/mO7mzOH71HIUhI65guBWf+allLX A1Svqt2D245m8qSs0wDxeZeu83E4YGioc7R/9gKkH1LgvL3meBVQzB8rB9i71WMwbk0g pTwuOgSJBFZInfE8LEAyqCJB2M0q+RjexArg2ZIg1FuaUsMAHN3tQGS01DB8DvBsu636 9cHw== 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=Y7HjefUCS9gDX7N8PA9K7db3sddMwExif+gUMH3Qi5A=; b=sNEDv6/hIIVqZfgPTn+CuKCPbDbpUqxP1B/BwLBCbKyCHyPkQdp+jmjcXH0MbOWfx2 lurs3GuJumcVjayoMilfo8gl0ZT1GFB4Z/CAcq0lW5MmUn7TmsKouuF2fIwlcN9P0+dI eX5CcCcHwlT8Q7c/xfE8xud/LFIBe6C+PBgLApKqEo40YtkPK3aubbztNA+2DjaFm9Ob 3f7HevF4FH1EjfjqiXX+SwvnWX0fmLZ88scU65O6gUUI1xlpY6b+e4MyntRJFDx4a2aC 5eqhWu+q3ar6CMZbI2P3n2vhsUAKPjtn2/hpWDZRfXZmBtG1EWKweqKtFmSRVPy87vqw tiiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si11235808ejr.788.2021.10.11.09.24.26; Mon, 11 Oct 2021 09:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234564AbhJKLuV (ORCPT + 99 others); Mon, 11 Oct 2021 07:50:21 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14324 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbhJKLuS (ORCPT ); Mon, 11 Oct 2021 07:50:18 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HScPX2bwVz906G; Mon, 11 Oct 2021 19:43:28 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 11 Oct 2021 19:48:16 +0800 Received: from ubuntu1804.huawei.com (10.67.174.61) 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.2308.8; Mon, 11 Oct 2021 19:48:16 +0800 From: Yang Jihong To: , , CC: Subject: [PATCH] tracing: save cmdline only when task does not exist in savecmd for optimization Date: Mon, 11 Oct 2021 19:50:18 +0800 Message-ID: <20211011115018.88948-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 commit 85f726a35e504418 use strncpy instead of memcpy when copying comm, on ARM64 machine, this commit causes performance degradation. For the task that already exists in savecmd, it is unnecessary to call set_cmdline to execute strncpy once, run set_cmdline only if the task does not exist in savecmd. I have written an example (which is an extreme case) in which trace sched switch is invoked for 1000 times, as shown in the following: for (int i = 0; i < 1000; i++) { trace_sched_switch(true, current, current); } On ARM64 machine, compare the data before and after the optimization: +---------------------+------------------------------+------------------------+ | | Total number of instructions | Total number of cycles | +---------------------+------------------------------+------------------------+ | Before optimization | 1107367 | 658491 | +---------------------+------------------------------+------------------------+ | After optimization | 869367 | 520171 | +---------------------+------------------------------+------------------------+ As shown above, there is nearly 26% performance Signed-off-by: Yang Jihong --- kernel/trace/trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 7896d30d90f7..a795610a3b37 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2427,8 +2427,11 @@ static int trace_save_cmdline(struct task_struct *tsk) savedcmd->cmdline_idx = idx; } - savedcmd->map_cmdline_to_pid[idx] = tsk->pid; - set_cmdline(idx, tsk->comm); + /* save cmdline only when task does not exist in savecmd */ + if (savedcmd->map_cmdline_to_pid[idx] != tsk->pid) { + savedcmd->map_cmdline_to_pid[idx] = tsk->pid; + set_cmdline(idx, tsk->comm); + } arch_spin_unlock(&trace_cmdline_lock); -- 2.30.GIT