From patchwork Mon Aug 28 21:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chanudet X-Patchwork-Id: 13368337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19F82C83F11 for ; Mon, 28 Aug 2023 21:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=KEPptv1MamBamC/7oZw3DXFIezbnA28vxrcWYftrgXg=; b=R/LtDpUb8CRcKo Gou35obletV9YnrKPgKNKlChqOMhIajQmmS7Z3CXl1Y0LQmqD9juo4HJwO3UKh1tChx4ZLAmMCPt1 BfivVeyoP+zS2CLJFD/JsMnHm8xqrKfBHvxszWU7QURTzZGimneV2LUDcTtMLwqE8bYlSQZwBIA/Y 2oX9V2d488hBIs1M1sHT1YIbl+KyF6H7mpugCuqQJrPW/TyvufBAy4+o2hJclhHpSDYynI95Pm/c0 d2s8SSaHd6kYjHD5ZArveP1X2YDFehR09Pz+WXI2n/8yq8PZTuwmww2hXCcYKKS1LtGKAv812r4vw nQEjR7JFj7xlbBkiLs9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qajYm-00AI19-1j; Mon, 28 Aug 2023 21:14:08 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qajYj-00AI0o-1M for linux-arm-kernel@lists.infradead.org; Mon, 28 Aug 2023 21:14:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693257241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DqxapwNpcXU5UQrJcGPZCzbnwE7dcwZ4jrY3BSYkS+c=; b=PmWNYwZQX4/aw5SYmBtNXWQFeYYs0/EArm70qUVP1U3LxxuA/DWPVFUcMSYsYWdcDhK5AT lkDWEKqt6nuoljHAomuvOdWohJ2qSr6wy4lv0hO/Ac70jHPonaQZtcA7gs9iK7vnW5kJoQ 4s2D824GoiC6Mu1Af7g4gBBNRqY36GY= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-5-rbXGI9Mc648KuGTbycfw-1; Mon, 28 Aug 2023 17:11:25 -0400 X-MC-Unique: 5-rbXGI9Mc648KuGTbycfw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-40fefde5a99so40843551cf.3 for ; Mon, 28 Aug 2023 14:11:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693257085; x=1693861885; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DqxapwNpcXU5UQrJcGPZCzbnwE7dcwZ4jrY3BSYkS+c=; b=OiBz8vtyAJy3DxceC0kb+sV4FXvE+xZl6j7A9x7NLGXOkPAzB2zTIRMG/UT73vCcEC EBRHU1tcGlAPEbDbGBh7UWTw3XnJEiQNnDw/jUfgPOMvbut+16UNq5AYU87EuiaaN42Q I2efD4DPJA49GAukDpuexCay4WM8fc8PFpBim30nC/GduN93PV0LgCYX6SpEV+htyTEW 3AhDCAVDWm+KXvkg9W6F77NI4Qnn6v8QVslpiujOIy5fu4mjxmpsmqunPVRR4K0K3asU 1/6LH+ydSyf76LMLdpl6SFZmyAWgKBAkVKzfdIPivHG2EvIxFndJT0+sKH91E8LZoLhQ KKAQ== X-Gm-Message-State: AOJu0YxiS39HMAcRpK5+VFbFBtjqoVYavpElYKPX8O4O5/m64u/Z4C/N ULFzZ6y8gC9mCUbB3prKDTNYlfQYDYTGV+Yj8poWSzr5d0afL30tbxz+iPAc6f7dtRbGC4TmUEz 4EfTuOCyONp5fMdVoNsgVUKibBV6jAS0+EK4= X-Received: by 2002:a05:622a:153:b0:40d:2d0c:5685 with SMTP id v19-20020a05622a015300b0040d2d0c5685mr34948135qtw.55.1693257085074; Mon, 28 Aug 2023 14:11:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnu4KOW0+2uXvz9joKEIl2jERq2FqfY95dr1tvn41dKl3063IiNY5EHisHBegqlXQdyQCmZA== X-Received: by 2002:a05:622a:153:b0:40d:2d0c:5685 with SMTP id v19-20020a05622a015300b0040d2d0c5685mr34948117qtw.55.1693257084760; Mon, 28 Aug 2023 14:11:24 -0700 (PDT) Received: from localhost (pool-71-184-142-128.bstnma.fios.verizon.net. [71.184.142.128]) by smtp.gmail.com with ESMTPSA id ge15-20020a05622a5c8f00b0041020e8e261sm2598756qtb.1.2023.08.28.14.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 14:11:24 -0700 (PDT) From: Eric Chanudet To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Eric Chanudet Subject: [RFC PATCH] arm64/arch_timer: register arch counter early Date: Mon, 28 Aug 2023 17:02:43 -0400 Message-ID: <20230828210548.1010192-3-echanude@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230828_141405_613059_96B1EBDC X-CRM114-Status: GOOD ( 19.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 #include #include +#include #include #include @@ -53,6 +54,9 @@ #include #include #include +#include + +#include 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;