All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Yinan Liu <yinan@linux.alibaba.com>
Cc: mark-pk.tsai@mediatek.com, peterz@infradead.org,
	mingo@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scripts: ftrace - move the nop-processing in ftrace_init to compile time
Date: Tue, 16 Nov 2021 11:06:18 -0500	[thread overview]
Message-ID: <20211116110618.490b4a57@gandalf.local.home> (raw)
In-Reply-To: <20211116024942.60644-3-yinan@linux.alibaba.com>

On Tue, 16 Nov 2021 10:49:42 +0800
Yinan Liu <yinan@linux.alibaba.com> wrote:

> In some business scenarios, GCC versions are so old that
> optimizations in ftrace cannot be completed, such as
> -mrecord-mcount and -mnop-mcount. The recordmCount in the
> kernel is actually used. In this case, ftrace_init will
> consume a period of time, usually around 9~12ms. Do nop
> substitution in recordmcount.c to speed up ftrace_init.
> 
> Signed-off-by: Yinan Liu <yinan@linux.alibaba.com>
> ---
>  kernel/trace/ftrace.c  |  7 +++++++
>  scripts/recordmcount.h | 14 ++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index c776a2956237..ccc690e81556 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -6478,6 +6478,13 @@ 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.
>  	 */
> +#ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
> +#ifdef CONFIG_HAVE_C_RECORDMCOUNT

So the above alone does not guarantee that the callers are converted into
nops. So this is wrong.

There's already logic to convert to nops. But that's done in the
architecture code, not in the generic code.

> +	ret = 0;
> +	goto out;
> +#endif
> +#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)

Here you even have an if statement that only converts to nops if it is
already done.

-- Steve


> +				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);
>  	}


  parent reply	other threads:[~2021-11-16 16:06 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 13:50 [PATCH 0/2] ftrace: improve ftrace during compiling Yinan Liu
2021-09-11 13:50 ` [PATCH 1/2] scripts: ftrace - move the sort-processing in ftrace_init to compile time Yinan Liu
2021-09-11 13:59   ` Steven Rostedt
2021-10-03 13:42     ` Yinan Liu
2021-10-08 23:48       ` Steven Rostedt
2021-10-09  2:56         ` Yinan Liu
2021-10-25 13:20           ` Yinan Liu
2021-10-25 15:00             ` Steven Rostedt
2021-09-11 13:50 ` [PATCH 2/2] scripts: ftrace - move the nop-processing " Yinan Liu
2021-09-11 14:12   ` Steven Rostedt
2021-09-11 15:28     ` Yinan Liu
2021-09-11 16:07       ` Peter Zijlstra
2021-09-11 14:33   ` Peter Zijlstra
2021-09-11 17:15   ` kernel test robot
2021-09-11 17:15     ` kernel test robot
2021-09-11 18:04   ` kernel test robot
2021-09-11 18:04     ` kernel test robot
2021-11-16  2:49 ` [PATCH v2 0/2] ftrace optimization at " Yinan Liu
2021-11-16  2:49   ` [PATCH v2 1/2] scripts: ftrace - move the sort-processing in ftrace_init to " Yinan Liu
2021-11-16  8:07     ` Peter Zijlstra
2021-11-16 12:42       ` Yinan Liu
2021-11-16 13:05         ` Peter Zijlstra
2021-11-16 14:46           ` Yinan Liu
2021-11-17 13:34     ` kernel test robot
2021-11-17 13:34       ` kernel test robot
2021-11-16  2:49   ` [PATCH v2 2/2] scripts: ftrace - move the nop-processing " Yinan Liu
2021-11-16  8:10     ` Peter Zijlstra
2021-11-16 12:51       ` Yinan Liu
2021-11-16 13:07       ` Steven Rostedt
2021-11-16 15:02         ` Yinan Liu
2021-11-16 16:06     ` Steven Rostedt [this message]
2021-11-22 13:43 ` [PATCH v3] scripts: ftrace - move the sort-processing " Yinan Liu
2021-11-23 10:54 ` [PATCH v4] ftrace sorting optimization changelog Yinan Liu
2021-11-23 10:54   ` [PATCH v4] scripts: ftrace - move the sort-processing in ftrace_init to compile time Yinan Liu
2021-11-29  2:13     ` Yinan Liu
2021-11-29  3:51       ` Steven Rostedt
2021-11-29  6:52         ` Yinan Liu
2021-11-30 17:08     ` Steven Rostedt
2021-12-01  5:32 ` [PATCH v5 0/2] ftrace sorting optimization changelog Yinan Liu
2021-12-01  5:32   ` [PATCH v5 1/2] scripts: ftrace - move the sort-processing in ftrace_init to compile time Yinan Liu
2021-12-01 21:45     ` Steven Rostedt
2021-12-05 12:35     ` [scripts] 12955fb1c5: kernel-selftests.livepatch.test-ftrace.sh.fail kernel test robot
2021-12-05 12:35       ` kernel test robot
2021-12-01  5:32   ` [PATCH v5 2/2] script/sorttable: code style improvements Yinan Liu
2021-12-02  2:16 ` [PATCH v6 0/2] ftrace sorting optimization changelog Yinan Liu
2021-12-02  2:16   ` [PATCH v6 1/2] scripts: ftrace - move the sort-processing in ftrace_init Yinan Liu
2021-12-02 17:58     ` Steven Rostedt
2021-12-05 12:45       ` Masami Hiramatsu
2021-12-06 20:18       ` Steven Rostedt
2021-12-07  1:29         ` Yinan Liu
2021-12-02  2:16   ` [PATCH v6 2/2] script/sorttable: code style improvements Yinan Liu
2021-12-02 15:30   ` [PATCH v6 0/2] ftrace sorting optimization changelog Peter Zijlstra
2021-12-07 15:13 ` [PATCH v7 0/2] ftrace sorting optimization Yinan Liu
2021-12-07 15:13   ` [PATCH v7 1/2] scripts: ftrace - move the sort-processing in ftrace_init Yinan Liu
2021-12-11 14:50     ` Steven Rostedt
2021-12-07 15:13   ` [PATCH v7 2/2] script/sorttable: code style improvements Yinan Liu
2021-12-12 11:33 ` [PATCH v8 0/1] change log Yinan Liu
2021-12-12 11:33   ` [PATCH v8] scripts: ftrace - move the sort-processing in ftrace_init Yinan Liu
2022-01-21  9:46     ` Sven Schnelle
2022-01-21 10:42       ` Heiko Carstens
2022-01-21 11:14         ` Sven Schnelle
2022-01-21 11:29           ` Sven Schnelle
2022-01-21 18:11         ` Steven Rostedt
2022-01-22  9:17           ` Heiko Carstens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116110618.490b4a57@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark-pk.tsai@mediatek.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yinan@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.