From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B476129D27E for ; Wed, 26 Nov 2025 07:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764142703; cv=none; b=M3oeth+3BiGsFBg7q5Z8r2wR4vaF4IWNOHH448fnHz00N1noVMhZP5TnMGXjY7MH5kMi6UWQ++3KDHZxJT5N8T1vmL8p/o7JYdEVMJ5Y8KkN861GlTCALkCwQRGkUloGsayu7piJ5pKdgahLs15/URhmWLev4lyo8BAKSkp/lf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764142703; c=relaxed/simple; bh=hQjcREfmDf8kc6CthdiGrCZppDcgkHBuidE5S8kfQ3c=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hFAKt+mhj6OtCn1xF+tx4+DNhB0DQp8524NCxcdbZROOXpCYwXjB3Tx3aFau7d6aDwskU5HAwJOLLSrVl+L5Rr+Ypqtl1HrhQ5TF6wkMK7uc73s8/NUQhp7CUnnr1QgnZqJnHJjHFwEGYVDBcqdG7mGKryNJKAhF/fsPIvSW7FA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.221.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-55b155c9ab2so1810546e0c.1 for ; Tue, 25 Nov 2025 23:38:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764142700; x=1764747500; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3ldRNpfqbXV5QZPEtLE6N6H3iPgRz6jkmwW5HKpKnis=; b=BxNOK8UdgXkVr+J4cDX8+4Rx9WBMPUYvIV+O1rFss/oAK+sRLTBzk4HpZTSxleazqC j/U/Ypihe0Fk+rsU4pXKMnRggGyCw4xMTjqo4E5iGBpM26zxgir/BtwUjrdlR+Y5xGUr /X0gcxA3DLgYA7O5Yv7edDLnTxCmaUkD/brSSsyxufduadMkbtGenZQLQBTBmxw9W8uV fcFpg+NnlKMSFi8SaNndGa6qGmRpS7NwD3CBh1BKS7bmtVSkWBqq/9nBnOAW8jARBKUU xKYg3eogh2t8QtqPAJBYJwL3cLwRQLNRBZekFtb+Hss+DtrAvgl8OGr2KAKtT9fo0APP UwPg== X-Forwarded-Encrypted: i=1; AJvYcCXpEsZ7k+5ophb9ZmY9LpZSgqeU4Hl6KNu+t4CmZeiEnQiQzDPGGj56VBZeZrPCjhZHGHIoo2aRqyTiyQM=@vger.kernel.org X-Gm-Message-State: AOJu0YyHxS9SfgsmDPZEgei1QO1EoO4ELEvvO26+djC+M1HJeVEcYQFG DRNicoYYGMq+UklVOKQ/fe+fNPzunW0xnF++AOt7/3eVoc08AUQde58p5k+tb7pd X-Gm-Gg: ASbGncuFbW1dPExg9QWs4EfElDbcKBfEHdqj+AfubgDXaj9tb05cIoAPD52gi392m5l zi4gEKIDUH4qySQr2enzAv5jPZ8ZQjPElXlN7SAc5nB99jOCzcVmcD16G2AcHPMBTaPOu8/EqS2 16kpNBMdJqTZzCAItWfLG6fvtwJL2OI3LXZ9hGHnoFSrvQOcJ7If6aIIV3vZf2P8xjgAVKJrX+O zwrf538gVLKz2ot50SPGLYPFdiXQjafa9lKZ9J7ldDLZ3gM7v2tDi2l6WeIqWF1p7aYaNOjsynQ hnuBfm+lNjrYoTowLn1M1+qXYFuat1Qgrl86JxlnDVnlZ+TN3anLhvPO8tJ1QFuY8MrBYdFIaUY qsKQh1ykQW1+LWrE3PZSv1ZItfMx/mErj1G4+m+OSVnB+w+/iNiBnyGyI7iX5PtQJtFDlsckGWf MpndTQSWy/gdtBlgzo3ybTKY9QjjYSS7AGarbXut+R2HnxXpC/KPOZ X-Google-Smtp-Source: AGHT+IFCCglctvcpYDCgmCYCR9rTtkJpK+f6sLnspaI3ZlSFvlIsfojhGj9r9Byua9PmbFexL7ZEtA== X-Received: by 2002:a05:6102:5e84:b0:5dd:83de:badc with SMTP id ada2fe7eead31-5e1de4050c3mr5229077137.38.1764142700456; Tue, 25 Nov 2025 23:38:20 -0800 (PST) Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com. [209.85.222.46]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5e1bdd21e37sm7492777137.11.2025.11.25.23.38.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Nov 2025 23:38:20 -0800 (PST) Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-93a9f6efe8bso1700017241.0 for ; Tue, 25 Nov 2025 23:38:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX5gUEBJ6HyhT40X7Z+6JOP2aPVI2TSHbQaKMveZlisZ80rcwB7wi+mmsDpAUXJSmePuPOfT4SEwBo9g6A=@vger.kernel.org X-Received: by 2002:a05:6102:a4e:b0:5db:debf:658f with SMTP id ada2fe7eead31-5e1de1bbc80mr6167553137.19.1764142699789; Tue, 25 Nov 2025 23:38:19 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <39b09edb-8998-4ebd-a564-7d594434a981@bird.org> In-Reply-To: From: Geert Uytterhoeven Date: Wed, 26 Nov 2025 08:38:08 +0100 X-Gmail-Original-Message-ID: X-Gm-Features: AWmQ_bl9K3DasbrqdP3TSIeyM8E_taze7ucJuUBAyOiXwK8kBD6r8Oh7Vdc01Oo Message-ID: Subject: Re: [PATCH] printk: add early_counter_ns routine for printk blind spot To: Francesco Valla Cc: Tim Bird , pmladek@suse.com, Steve Rostedt , john.ogness@linutronix.de, senozhatsky@chromium.org, Tim Bird , Andrew Morton , LKML , Linux Embedded Content-Type: text/plain; charset="UTF-8" Hi all, On Wed, 26 Nov 2025 at 03:24, Francesco Valla wrote: > On Mon, Nov 24, 2025 at 10:30:52PM -0700, Tim Bird wrote: > > From: Tim Bird > > > > During early boot, printk timestamps are reported as zero, > > which creates a blind spot in early boot timings. This blind > > spot hinders timing and optimization efforts for code that > > executes before time_init(), which is when local_clock() is > > initialized sufficiently to start returning non-zero timestamps. > > This period is about 400 milliseconds for many current desktop > > and embedded machines running Linux. > > > > Add an early_counter_ns function that returns nanosecond > > timestamps based on get_cycles(). get_cycles() is operational > > on arm64 and x86_64 from kernel start. Add some calibration > > printks to allow setting configuration variables that are used > > to convert cycle counts to nanoseconds (which are then used > > in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as > > some associated conversion variables, as new kernel config > > variables. > > > > After proper configuration, this yields non-zero timestamps for > > printks from the very start of kernel execution. The timestamps > > are relative to the start of the architecture-specific counter > > used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). > > This means that the time reported reflects time-from-power-on for > > most embedded products. This is also a useful data point for > > boot-time optimization work. > > > > Note that there is a discontinuity in the timestamp sequencing > > when standard clocks are finally initialized in time_init(). > > The printk timestamps are thus not monotonically increasing > > through the entire boot. > > This is... not going to work, IMO, and might lead to breakages in > userspace tools (are printk timings a userspace API?). I think they are. Another approach would be to defer the calibration/conversion to userspace, and make sure the early part stands out. I.e. when real timekeeping is available, kernel messages are prefixed by "[%5lu.%06lu]". Early messages could be prefixed by a plain integer "[%12u]", containing the raw cycle counter value. The presence of the decimal point would make the difference obvious. > I actually have a counter-proposal: the time obtained through cycle > evaluation is used as an offset to be added to the printk time after > time_init() is called. A (working, but maybe sub-optimal) patch to > obtain this is attached at the end. Oh, that's a nice idea, too! Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds