From: Eric Chanudet <echanude@redhat.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Eric Chanudet <echanude@redhat.com>
Subject: [RFC PATCH] arm64/arch_timer: register arch counter early
Date: Mon, 28 Aug 2023 17:02:43 -0400 [thread overview]
Message-ID: <20230828210548.1010192-3-echanude@redhat.com> (raw)
I was looking at how long it takes to get from primary_entry to
time_init(), when sched_clock is initialized and timestamps are
available to printks. Patching in cntvct_el0 reads in a recent
linux-next (next-20230821) with the default arm64 configuration, I found
the following:
* Qualcomm RideSX4 (sa8775p-ride, 36GB): ~700ms
* Ampere Altra MtSnow (96GB): ~1210ms
Narrowing it down a bit, most of this time is spent in:
start_kernel()
setup_arch()
paging_init()
map_mem()
// Mainly in for_each_mem_range(i, &start, &end)
From time_init(), each platform reports starting the init process after:
* Qualcomm RideSX4 (sa8775p-ride, 36GB): ~1100ms
* Ampere Altra MtSnow (96GB): ~600ms
So the timestamps are not accounting a relatively significant slice of
time spent initializing the kernel.
I found a recent similar thread[1], but I would rather account for time
spent solely in the kernel while using the arch counter.
IIUC arm64 can rely on having its arch counter, is it possible, and
sane, to attempt to register to sched_clock earlier in setup_arch()? It
would look similar to what is done for SPARC64[2]?
The following patch tries to experiment with this, but let the counter
re-register as sched_clock (through time_init->timer_probe) and does not
handle the erratas and other relevant situations:
- erratas and work-arounds in arm_arch_timer,
- cntvct vs cntpct (that shouldn't make a difference at this stage?),
- device-tree overrides for the frequency (?).
Alternatively, would it make more sense to capture a counter read early
on, for example close to primary_entry after jumping in the kernel, and
use it as epoch for sched_clock_register()? Since this is only happening
early it should not have time to overflow?
[1] https://lore.kernel.org/linux-arm-kernel/CAKZGPAOYPp3ANWfBWxcsT3TJdPt8jH-f2ZJzpin=UZ=-b_-QFg@mail.gmail.com/
[2] https://lore.kernel.org/all/1497300108-158125-7-git-send-email-pasha.tatashin@oracle.com/
Signed-off-by: Eric Chanudet <echanude@redhat.com>
---
arch/arm64/kernel/setup.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 417a8a86b2db..cbc51c42c9fd 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -32,6 +32,7 @@
#include <linux/sched/task.h>
#include <linux/scs.h>
#include <linux/mm.h>
+#include <linux/sched_clock.h>
#include <asm/acpi.h>
#include <asm/fixmap.h>
@@ -53,6 +54,9 @@
#include <asm/efi.h>
#include <asm/xen/hypervisor.h>
#include <asm/mmu_context.h>
+#include <asm/arch_timer.h>
+
+#include <clocksource/arm_arch_timer.h>
static int num_standard_resources;
static struct resource *standard_resources;
@@ -290,8 +294,23 @@ u64 cpu_logical_map(unsigned int cpu)
return __cpu_logical_map[cpu];
}
+static void __init early_sched_clock(void)
+{
+ u64 min_cycles;
+ u64 min_rollover_secs = 40ULL * 365 * 24 * 3600;
+ u32 rate;
+ int width;
+
+ rate = arch_timer_get_cntfrq();
+ min_cycles = min_rollover_secs * rate;
+ width = clamp_val(ilog2(min_cycles - 1) + 1, 56, 64);
+ sched_clock_register(__arch_counter_get_cntvct, width, rate);
+}
+
void __init __no_sanitize_address setup_arch(char **cmdline_p)
{
+ early_sched_clock();
+
setup_initial_init_mm(_stext, _etext, _edata, _end);
*cmdline_p = boot_command_line;
--
2.41.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reply other threads:[~2023-08-28 21:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230828210548.1010192-3-echanude@redhat.com \
--to=echanude@redhat.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@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).