Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp344489pxb; Sat, 11 Sep 2021 06:55:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv/nvlq4i9Z4NI3Tlm/p6oRD8e8Dnct+vny0XOm0w2Ohjf3gH6P4ZQsT4M/mYUZdV2TY4H X-Received: by 2002:aa7:d649:: with SMTP id v9mr3491349edr.38.1631368517820; Sat, 11 Sep 2021 06:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631368517; cv=none; d=google.com; s=arc-20160816; b=o4+pbriE4KydDot9/46FJIXHLr6E2A+PScqSy2kA0ip9zSky4EcZqLvQxG+Tg8G7HU nBb9hy9zRbpLWr37gDOLV8POSgUge+zO7EOgUsAC9WPIvDX3ZqDOc3Bgz8Y7ovX9R8C7 dkS+mRLdqsieICw73kOIqwU8dVLLcnp+Nkuj/3EPIw34oGPfj7AO9pLEuY1BlIgpkKg3 B3Dpkf5Rsb945sqeMoaqcOl1KX1eYRDu40ZSuGRvPIHyxUgVqP44WZoYKII53m4BMMUy V5tghvAX9sS1thadV+qP/sNoipE8QLWPcewgBiuEm4Yqk2AeR/nUgZ4BUZYc/IWAXC+7 887g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=UqX7gsJGOyd7SoYX039baGqG57In771CQRrVYJqtN70=; b=IFd8t8r1eLiXQNVWLTya4sMcl4tyWJquswZDJs89yBZKv06L4gWTJXOqxmcVr/W0gR /Q3WqfA95ailDRFYrfM2rtjBoS9uEtisyYCgVxQRAitxt5jcNq9p2+GGrWM1AsXv2Y1d 8kuH0m3prD2TgBoiWeJXcu3cs/EOqYPPh3Ryeyv4UM9+hlxsKi7VF9qcGivBYIcG2p/I FKkq0pVSiiYoElnUqg7/MK+YTWTStpDRGCs+nuOaFA/Mu3lTz5Zp5DpJJn49iZ7VeHLG 3KIB3aV5ew+6MZlqWzQhWDc0zyAPx5MuhUZ4M1pnSgVYkf1R05CGyJ213wRAcoWm6V8o oFBw== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si1620048edf.629.2021.09.11.06.54.39; Sat, 11 Sep 2021 06:55:17 -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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235963AbhIKNwc (ORCPT + 99 others); Sat, 11 Sep 2021 09:52:32 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:45506 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235934AbhIKNwb (ORCPT ); Sat, 11 Sep 2021 09:52:31 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=yinan@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Uo-bker_1631368273; Received: from localhost(mailfrom:yinan@linux.alibaba.com fp:SMTPD_---0Uo-bker_1631368273) by smtp.aliyun-inc.com(127.0.0.1); Sat, 11 Sep 2021 21:51:17 +0800 From: Yinan Liu To: yinan@linux.alibaba.com, rostedt@goodmis.org, mark-pk.tsai@mediatek.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] scripts: ftrace - move the nop-processing in ftrace_init to compile time Date: Sat, 11 Sep 2021 21:50:43 +0800 Message-Id: <20210911135043.16014-3-yinan@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 In-Reply-To: <20210911135043.16014-1-yinan@linux.alibaba.com> References: <20210911135043.16014-1-yinan@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When ftrace is enabled, ftrace_init will consume a period of time, usually around 15~20ms. Approximately 60% of the time is consumed by nop-processing. Moving the nop-processing to the compile time can speed up the kernel boot process. performance test: env: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz method: before and after patching, compare the total time of ftrace_init(), and verify the functionality of ftrace. avg_time of ftrace_init: with patch: 7.114ms without patch: 15.763ms Signed-off-by: Yinan Liu --- kernel/trace/ftrace.c | 4 ++++ scripts/recordmcount.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c236da868990..ae3fba331179 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6261,6 +6261,10 @@ static int ftrace_process_locs(struct module *mod, * until we are finished with it, and there's no * reason to cause large interrupt latencies while we do it. */ +#if defined CONFIG_X86 || defined CONFIG_X86_64 || defined CONFIG_ARM || defined CONFIG_ARM64 + ret = 0; + goto out; +#endif if (!mod) local_irq_save(flags); ftrace_update_code(mod, start_pg); diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index 1e9baa5c4fc6..152311639a0b 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -406,6 +406,8 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, uint_t const recval, unsigned const reltype) { + Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff) + (void *)ehdr); + Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)]; uint_t *const mloc0 = mlocp; Elf_Rel *mrelp = *mrelpp; Elf_Sym const *sym0; @@ -419,6 +421,7 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp); for (t = nrel; t; --t) { + int ret = -1; if (!mcountsym) mcountsym = get_mcountsym(sym0, relp, str0); @@ -436,6 +439,17 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, *mlocp++ = addend; mrelp = (Elf_Rel *)(rel_entsize + (void *)mrelp); + /* convert mcount into nop */ + if (make_nop) + ret = make_nop((void *)ehdr, + _w(shdr->sh_offset) + _w(relp->r_offset)); + if (!ret) { + Elf_Rel rel; + rel = *(Elf_Rel *)relp; + Elf_r_info(&rel, Elf_r_sym(relp), rel_type_nop); + ulseek(fd_map, (void *)relp - (void *)ehdr, SEEK_SET); + uwrite(fd_map, &rel, sizeof(rel)); + } } relp = (Elf_Rel const *)(rel_entsize + (void *)relp); } -- 2.14.4.44.g2045bb6