Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp27673pxb; Mon, 18 Oct 2021 19:42:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4pPikieAEEsuM2FcsGoG9fUuHwaCW1NLfNrGSAboPwOKHs2E+6ssPyr4DM3Y/QxSGVyca X-Received: by 2002:a17:906:f8d0:: with SMTP id lh16mr32992533ejb.367.1634611349829; Mon, 18 Oct 2021 19:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634611349; cv=none; d=google.com; s=arc-20160816; b=rnOmvG9InL2tFVZrK1v4htSRs+m6CQigkIQR8yRgwuNgd+aD1jzHdU7Q+XcNK3ryUs D2CqlQ6YbQnm2NsPa0AQ2VJGQt2ij/r3jrtIH3l6bKJNmeAwSn+xKSkbZOpqR8tE1ulG tXPPaFMbaf+3U0ED5Q5redOlVzab7ahcinvOPoKmfaE633VzohFcZH/lSyZvh3GowbBo kiaC/nQEZjOHI7ixa6e/A+SFoRY/9/lYUpC+3C1TyfmUVylCR7Gm5ewrLIddkTmakBKS tj3SaLjd2ecdbwEjOVRFDM9tNOV4J7LCkeCt7T02pY15LNcpxEguSChyHAMeDnhOsi4W P1LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=teKp3N+CmlIilA4QQX/Fo3UNRVmf99nMft2fq4PT8c0=; b=aKsowtwabKECRwt0o4NnoZemNl1TDpg0Wb9z0s1DlcAMRGKUSf1CQQuNcFUGYPXi8W yozlbydpp9bNJGhs6ymt/vzl80FcGx56sIyDXSo5mwUA3TJBar/dtQhM/J5Ywh/TCW1f 8s4Jv7nHNJd87VTdTZpsHL2lLz9l5V+VewWZ6apPcUhHdtN5E0PRGuOKqrdD8YktKQLv 6ztasard+3n2UQ/hxdcuGeB8zDifvxjKgr7owDjV+QsOue7sPEbTQHKDuqbjeyHkFRSo p7CoBWqYM+51IVOSXQrlh71Zvsnc99R7dQ7czqxCi33geMuDaMtsjUv3SGkEN+8G3ycW rflQ== 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 gv8si22125364ejc.712.2021.10.18.19.41.52; Mon, 18 Oct 2021 19:42:29 -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 S229876AbhJSCmF (ORCPT + 99 others); Mon, 18 Oct 2021 22:42:05 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:25231 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbhJSCmE (ORCPT ); Mon, 18 Oct 2021 22:42:04 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HYHxB4bXqz8tj0; Tue, 19 Oct 2021 10:38:38 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 19 Oct 2021 10:39:48 +0800 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.2308.15; Tue, 19 Oct 2021 10:39:48 +0800 Subject: Re: [QUESTION] Performance deterioration caused by commit 85f726a35e504418 To: Steven Rostedt CC: , linux-kernel References: <992d3b1c-70db-5cc7-8400-39caa5d502d5@huawei.com> <20211018093731.2dd5917f@gandalf.local.home> From: Yang Jihong Message-ID: <19e4222c-c9ac-5c1a-0c3a-b8bfd3524ab7@huawei.com> Date: Tue, 19 Oct 2021 10:39:47 +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: <20211018093731.2dd5917f@gandalf.local.home> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 Hi Steve, On 2021/10/18 21:37, Steven Rostedt wrote: > On Mon, 18 Oct 2021 11:23:14 +0800 > Yang Jihong wrote: > >> Hi Tom and Steven, >> >> commit 85f726a35e504418 use strncpy instead of memcpy when copying comm, >> on ARM64 machine, this commit causes performance degradation. >> >> I test the number of instructions executed by invoking the >> trace_sched_switch function once on an arm64 machine: >> 1. Use memcpy, the number of instructions executed is 850. >> 2. Use strncpy, the number of instructions executed 1100. >> That is, use strncpy is almost 250 more instructions than memcpy. >> >> Has the impact on performance been considered in this commit? :) >> What is the impact of revert the patch? >> > > It's a security issue. And like everything security, there's always going > to be a performance impact. Look at the performance impact due to spectre > and meltdown! > > That said, although memcpy() may not be used, we don't need strncpy. > strncpy() will pad the rest of the string with nul bytes. But since the > memory the string is being recorded into is already initialized (or can be > if it isn't), we could use the faster strlcpy(). > > Have you tried testing it by switching strncpy() with strlcpy()? > I have tried testing it by switching strncpy() with strlcpy(), there is no performance improvement, probably because the strlen function is called in strlpy and the string is traversed each time. Kind regards, Jihong > -- Steve > . >