linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: mingo@redhat.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH 1/4] sched: make nr_running() return 32-bit
Date: Thu, 13 May 2021 10:23:44 +0300	[thread overview]
Message-ID: <YJzUAHQwFj1x2HCH@localhost.localdomain> (raw)
In-Reply-To: <87fsyr5wtj.ffs@nanos.tec.linutronix.de>

On Thu, May 13, 2021 at 01:58:16AM +0200, Thomas Gleixner wrote:
> Alexey,
> 
> On Thu, Apr 22 2021 at 23:02, Alexey Dobriyan wrote:
> > Creating 2**32 tasks is impossible due to futex pid limits and wasteful
> > anyway. Nobody has done it.
> >
> 
> this whole pile lacks useful numbers. What's the actual benefit of that
> churn?

The long term goal is to use 32-bit data more. People will see it in
core kernel and copy everywhere elase.

> Just with the default config for one of my reference machines:
> 
>    text		data	bss	dec	 hex	 filename
> 16679864	6627950	1671296	24979110 17d26a6 ../build/vmlinux-before
> 16679894	6627950	1671296	24979140 17d26c4 ../build/vmlinux-after
> ------------------------------------------------------------------------
>      +30
> 
> I'm truly impressed by the massive savings of this change and I'm even
> more impressed by the justification:
> 
> > Bring nr_running() into 32-bit world to save on REX prefixes.

I collected numbers initially but then stopped because noone cared and
they can be config and arch dependent.

> Aside of the obvious useless churn,

oh... Sometimes I think churn is the whole point.

> REX prefixes are universaly true for
> all architectures, right? There is a world outside x86 ...

In general, 32-bitness is preferred for code generation.

32-bit RISCs naturally prefers 32-bit.

64-bit RISCs don't care because they remember 32-bit roots and
have necessary 32-bit fixed width(!) instructions.

x86_64 is the only arch where going 64-bit generally adds more bytes
to the instruction stream.

Effects can be smudged by compilers of course, in this case, percpu
stuff. That "unsigned int i" is a mistake. Proper diff looks like this:

	-ffffffff811115fa: 8b 44 18 04      mov    eax,DWORD PTR [rax+rbx*1+0x4]
	-ffffffff811115fe: 49 01 c4         add    r12,rax
	+ffffffff811115fa: 44 03 64 18 04   add    r12d,DWORD PTR [rax+rbx*1+0x4]

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4348,9 +4348,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
  * externally visible scheduler statistics: current number of runnable
  * threads, total number of context switches performed since bootup.
  */
-unsigned long nr_running(void)
+unsigned int nr_running(void)
 {
-	unsigned long i, sum = 0;
+	unsigned int sum = 0;
+	unsigned long i;
 
 	for_each_online_cpu(i)
 		sum += cpu_rq(i)->nr_running;

  reply	other threads:[~2021-05-13  7:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 20:02 [PATCH 1/4] sched: make nr_running() return 32-bit Alexey Dobriyan
2021-04-22 20:02 ` [PATCH 2/4] sched: make nr_iowait() return 32-bit value Alexey Dobriyan
2021-05-12 20:01   ` [tip: sched/core] sched: Make " tip-bot2 for Alexey Dobriyan
2021-04-22 20:02 ` [PATCH 3/4] sched: make nr_iowait_cpu() return 32-bit Alexey Dobriyan
2021-05-12 20:01   ` [tip: sched/core] sched: Make nr_iowait_cpu() return 32-bit value tip-bot2 for Alexey Dobriyan
2021-04-22 20:02 ` [PATCH 4/4] sched: make multiple runqueue task counters 32-bit Alexey Dobriyan
2021-05-12 19:36   ` Ingo Molnar
2021-05-12 20:01   ` [tip: sched/core] sched: Make " tip-bot2 for Alexey Dobriyan
2021-05-12 20:01 ` [tip: sched/core] sched: Make nr_running() return 32-bit value tip-bot2 for Alexey Dobriyan
2021-05-12 23:58 ` [PATCH 1/4] sched: make nr_running() return 32-bit Thomas Gleixner
2021-05-13  7:23   ` Alexey Dobriyan [this message]
2021-05-13  9:58   ` Ingo Molnar
2021-05-13 21:22     ` Alexey Dobriyan
2021-05-14 12:52     ` Thomas Gleixner
2021-05-14 18:18     ` Thomas Gleixner

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=YJzUAHQwFj1x2HCH@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).