Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1174757rwd; Thu, 1 Jun 2023 11:28:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ds19dl1N1lVfWvKm/2lhhjcSg6jJPUsMjnJuRkwAvvo5mYlfTn7+R2PhgJO45ZwtqN/uU X-Received: by 2002:a05:6a20:4325:b0:110:6146:1056 with SMTP id h37-20020a056a20432500b0011061461056mr13101623pzk.2.1685644098788; Thu, 01 Jun 2023 11:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685644098; cv=none; d=google.com; s=arc-20160816; b=E2Y2aIJbQxSnvObPh4NLO00j+LFdgpRWJnqBS4TLKfuSE6vH57CovKjCPvr/gbLymt +ue6pVED7fpFNHlWspQoepZYgN2Lj+XxEng4awVkq6CGBKwyNSQ+/kAafwzVcPk7wsnh QEz4qPB+RXc+mNO1I0dt4Kb5xwlFu5H3KylmZc41OKnBL8/SYegXdjPmCO9XEdbvtBHJ 6soHWMVrb+r5e9Kbv1Ve94J5lGOb54Tk7lzQX+/UJNyVUo7PlCkOvsXjpuhlLYKT3ONC sP8i5QzhUg8wiv2KV/gWMBXiRo+L18V7RDiDV9TEp+lJ4I1c/yjFCvMd9BEC3qMLxM0B oW0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=CNltx9NDvm+OFNXI1L4w30XEBvloNgIO3y8bVWYDrIM=; b=LNzAgIaKaBqTLSMefu+Harqkyx+sv3xjwJUibhW0EztWGvRbXCvmbr6c/9xIGARax+ e2S8bB8WxkKZvv1F9dUiBhBvt0OMyXnUdjRwrgjT/yh2QyzSgCvPZUD8GKuVfPEO18v1 kGv2gnwfoGg5lvuUyD4Lp3fpZA4rX1FaJNtxx4lo9TXLdCaopQcmKL+EuzA5DC4ILlqn QgRuxyj5LfFyV8JboahG1NCzHAwPMUu/kGDkoGtT2iYRxHkt2ie1hmyBOxfUQ32+Wojg rxPHeAvTPOng+3AzuVosORrXkMRS4FolONo+OKJC9Az0EXsEVQGsjllyvm3Ryvi9ocI+ f0Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BdVhrvQl; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x69-20020a638648000000b0053f2551834esi2013192pgd.735.2023.06.01.11.28.07; Thu, 01 Jun 2023 11:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BdVhrvQl; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbjFASUu (ORCPT + 99 others); Thu, 1 Jun 2023 14:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjFASUq (ORCPT ); Thu, 1 Jun 2023 14:20:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3036F1A1; Thu, 1 Jun 2023 11:20:42 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685643640; 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: in-reply-to:in-reply-to:references:references; bh=CNltx9NDvm+OFNXI1L4w30XEBvloNgIO3y8bVWYDrIM=; b=BdVhrvQlOYVHGgHmU7sjV76MXVHPlm6F5z2GWHVOlu6kGKpdOFrMw3ROtpALV4V1iVa7rB Yuzws9M/Hm6Z4xtl2jRUzIyCagWemy+W8G7LDvmM0CTFcwoCVNLW3imu5SUSC61ecWutvq ih7SLxsWOdMZ/SjFdA196XLzIvcWjYY6DNiuKFfzRMBInSe13ZSriLZef/BKzNYAmoavtp nsCOmZTxcIFMu8Fc0Sv/7fMhxrToLBoJiVLYgQvQnm9F0o1+p3jzUqTAyhSLcmH0DTD480 ai8ngFYungyu7xaS3bZXNdGNmkBVLGH3XYRYGUA597XfgsS84EUbc6uAin8sjg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685643640; 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: in-reply-to:in-reply-to:references:references; bh=CNltx9NDvm+OFNXI1L4w30XEBvloNgIO3y8bVWYDrIM=; b=e8b2hcjpsAod9hIu5JWZDiQuGBbkRWTcJggRVunU9vsqsYDXfYYbO1Qp58L+EVMjX3D1hy 8ufBpd4dTHzJNtBQ== To: Muhammad Usama Anjum , Jonathan Corbet , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:DOCUMENTATION" , open list , "Guilherme G. Piccoli" Cc: Muhammad Usama Anjum , Steven Noonan , kernel@collabora.com Subject: Re: Direct rdtsc call side-effect In-Reply-To: <87mt1jeax1.ffs@tglx> References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> Date: Thu, 01 Jun 2023 20:20:39 +0200 Message-ID: <87h6rrdoy0.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 01 2023 at 12:26, Thomas Gleixner wrote: > On Thu, Jun 01 2023 at 13:45, Muhammad Usama Anjum wrote: >> We are thinking of saving and restoring the timestamp counter at suspend >> and resume time respectively. I assume you talk about suspend to disk here, right? Suspend to RAM definitely does not have the problem at least not on any halfways contemporary CPU. >> In theory it can work on Intel because of >> TSC_ADJUST register. But it'll never work on AMD until: >> * AMD supports the same kind of adjust register. (AMD has said that the >> adjust register cannot be implemented in their firmware. They'll have to >> add it to their hardware.) >> * by manual synchronization in kernel (I know you don't like this idea. But >> there is something Windows is doing to save/restore and sync the TSC) > > Synchronizing TSC by writing the TSC MSR is fragile as hell. This has > been tried so often and never reliably passed all synchronization tests > on a wide range of systems. > > It kinda works on single socket, but not on larger systems. Here is an example where it falls flat on its nose. One of the early Ryzen laptops had a broken BIOS which came up with unsynchronized TSCs. I tried to fix that up, but couldn't get it to sync on all CPUs because for some stupid reason the TSC write got arbritrarily delayed (assumably by SMI/SMM). After the vendor fixed the BIOS, I tried again and the problem persisted. So on such a machine the 'fixup time' mechanism would simply render an otherwise perfectly fine TSC unusable for timekeeping. We asked both Intel and AMD to add TSC_ADJUST probably 15 years ago. Intel added it with some HSW variants (IIRC) and since SKL all CPUs have it. I don't know why AMD thought it's not required. That could have spared a gazillion of bugzilla entries vs. the early Ryzen machines. Thanks, tglx