Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp709457ybz; Fri, 24 Apr 2020 08:01:29 -0700 (PDT) X-Google-Smtp-Source: APiQypJ2/4HxTWcJheaU0yKYNJtzqbvpOM5xCCPxuwyJzRuRF8rdWjzIIo8Svf/8Ajod/xbTlspo X-Received: by 2002:adf:df8c:: with SMTP id z12mr12404841wrl.116.1587740489381; Fri, 24 Apr 2020 08:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587740489; cv=none; d=google.com; s=arc-20160816; b=AN+UnPq1D+tNhjsOtUBAIVcAKmrvxKCWM+gcwQaMQwqT0tDvYikJcoeHGbSvL5EhdQ I0eZmFriAjoxSWXCMQ+rKnXgxvcuj1v2HAr5/SY5OQ0dB0V3Okp+yTWxVEsFdAmIxLww NFb/3vjMQGUsUDpM9hI2PnKcj3MHWFwsPqq4954xMHHr4WuK12gtyaR479SmFi1+o71E 3/gwGLSkvNunIQIUd/iX9u0m1ORMiXDdFxj0IoCdpbx147NP4vAl6c59k95g+LCukMlj 9W/k7abbwh924yHarMiLlH3i9RFnFj5rP35xI4PwviWmNcfyLE0Pg9dDoE4LL4cKcBp1 irTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to; bh=tKBjjl52d9XXltCSOw1JT98o+N7YnA5fSuVjtiHcZrk=; b=pswuhxDe7yJnoTKB7BxNgjM4aa0zlwtOktpqeC+QWrNhWuTWdwzhA711IrDaiekl4p hpev8NBsXr234ops62O7eXiT6oOZiWdkYEuPmtysFhx/MZnG6Hm1+Cs0mICa2/kx/Ff7 BVnYoZioYlOYJj/n/Cvnm5l2UaCPjYG2AG5DFMhoSroyIu3BMXs2IqhXM1emCMngCHBr akOgu7i8nYKOrlByBOSSRrNWTq1a91NuC4GyzGCzUDi4fdfoT2elMGSE5p/8x6xiGubE V//w/VjlJ4/h4YVaRHLNUTRwtnXYGx8YXQ0HdtPklR7lItz2XKsSHtMSevQaORR5Du1i NuAA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi18si3476245edb.109.2020.04.24.08.01.02; Fri, 24 Apr 2020 08:01:29 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727074AbgDXO70 (ORCPT + 99 others); Fri, 24 Apr 2020 10:59:26 -0400 Received: from mx3.molgen.mpg.de ([141.14.17.11]:58885 "EHLO mx1.molgen.mpg.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726698AbgDXO7Z (ORCPT ); Fri, 24 Apr 2020 10:59:25 -0400 Received: from [192.168.0.5] (ip5f5af075.dynamic.kabel-deutschland.de [95.90.240.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 782FD2002EE1D; Fri, 24 Apr 2020 16:59:22 +0200 (CEST) To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: x86@kernel.org, LKML , Tom Lendacky From: Paul Menzel Subject: `calibrate_APIC_clock()` takes 100 ms on AMD systems Message-ID: Date: Fri, 24 Apr 2020 16:59:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dear Linux folks, Trying to decrease the boot time, I noticed on AMD systems `calibrate_APIC_clock()` takes around 100 ms. [ 0.004764] Freeing SMP alternatives memory: 32K [ 0.107676] smpboot: CPU0: AMD Ryzen 3 2200G with Radeon Vega Graphics (family: 0x17, model: 0x11, stepping: 0x0) On a different system with `apic=verbose`: [ 0.209161] Freeing SMP alternatives memory: 28K [ 0.212830] Using local APIC timer interrupts. calibrating APIC timer ... [ 0.320928] ... lapic delta = 625044 [ 0.320928] ... PM-Timer delta = 357959 [ 0.320928] ... PM-Timer result ok [ 0.320929] ..... delta 625044 [ 0.320930] ..... mult: 26844619 [ 0.320930] ..... calibration result: 400028 [ 0.320931] ..... CPU clock speed is 4400.1228 MHz. [ 0.320931] ..... host bus clock speed is 100.0028 MHz. [ 0.320936] smpboot: CPU0: AMD A6-6400K APU with Radeon(tm) HD Graphics (family: 0x15, model: 0x13, stepping: 0x1) On Intel systems TSC deadline is used, and the function returns right away. if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) return 0; [ 0.078373] Freeing SMP alternatives memory: 32K [ 0.080373] TSC deadline timer enabled [ 0.080375] smpboot: CPU0: Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz (family: 0x6, model: 0x3d, stepping: 0x4) 100 ms is almost 10 % percent of the total one second the Linux kernel takes here on the AMD systems, so I wonder if there are ways to reduce that. #define LAPIC_CAL_LOOPS (HZ/10) is 100 on my system, so the while loop below runs 100 times. while (lapic_cal_loops <= LAPIC_CAL_LOOPS) { /* Wait for a tick to elapse */ while (1) { if (tsc_khz) { u64 tsc_now = rdtsc(); if ((tsc_now - tsc_start) >= tsc_perj) { tsc_start += tsc_perj; break; } } else { unsigned long jif_now = READ_ONCE(jiffies); if (time_after(jif_now, jif_start)) { jif_start = jif_now; break; } } cpu_relax(); } /* Invoke the calibration routine */ local_irq_disable(); lapic_cal_handler(NULL); local_irq_enable(); } Can you give more information, why HZ/10 is chosen? Is there a way to break out earlier? Do AMD devices feature an alternatives like for Intel? What other possibilities are there? (Please excuse my ignorance.) For example, taking the calibration values from the firmware, or could they be passed on the command line, if the user knows, the system has not changed? Kind regards, Paul