public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: linux-kernel@vger.kernel.org, Johannes Berg <johannes.berg@intel.com>
Cc: linux-tip-commits@vger.kernel.org,
	kernel test robot <lkp@intel.com>,
	Johannes Berg <johannes.berg@intel.com>,
	x86@kernel.org
Subject: Re: [tip: x86/msr] um: Add UML version of <asm/tsc.h> to define rdtsc()
Date: Wed, 7 May 2025 20:47:04 +0200	[thread overview]
Message-ID: <aBuqqJoHOag7ZRML@gmail.com> (raw)
In-Reply-To: <174664324585.406.10812098910624084030.tip-bot2@tip-bot2>


Johannes: this is basically an RFC, not a final commit, will add your 
Reviewed-by if it's fine to you, or will change the patch if it's not.

Thanks,

	Ingo

* tip-bot2 for Ingo Molnar <tip-bot2@linutronix.de> wrote:

> The following commit has been merged into the x86/msr branch of tip:
> 
> Commit-ID:     24b58adaa7508d9d2cdb6bca44803954baf24459
> Gitweb:        https://git.kernel.org/tip/24b58adaa7508d9d2cdb6bca44803954baf24459
> Author:        Ingo Molnar <mingo@kernel.org>
> AuthorDate:    Wed, 07 May 2025 20:18:22 +02:00
> Committer:     Ingo Molnar <mingo@kernel.org>
> CommitterDate: Wed, 07 May 2025 20:30:39 +02:00
> 
> um: Add UML version of <asm/tsc.h> to define rdtsc()
> 
> In the x86 tree rdtsc() methods got moved out of <asm/msr.h>, but this
> broke UML, as the x86 version of <asm/tsc.h> cannot be used by UML as-is:
> 
> 	  CC [M]  drivers/accel/habanalabs/common/habanalabs_ioctl.o
> 	In file included from drivers/accel/habanalabs/common/habanalabs_ioctl.c:20:
> 	./arch/x86/include/asm/tsc.h:70:28: error: conflicting types for ‘cycles_t’; have ‘long long unsigned int’
> 	   70 | typedef unsigned long long cycles_t;
> 	      |                            ^~~~~~~~
> 	In file included from ./arch/um/include/asm/timex.h:7,
> 	                 from ./include/linux/timex.h:67,
> 	                 from ./include/linux/time32.h:13,
> 	                 from ./include/linux/time.h:60,
> 	                 from ./include/linux/skbuff.h:15,
> 	                 from ./include/linux/if_ether.h:19,
> 	                 from ./include/linux/habanalabs/cpucp_if.h:12,
> 	                 from drivers/accel/habanalabs/common/habanalabs.h:11,
> 	                 from drivers/accel/habanalabs/common/habanalabs_ioctl.c:11:
> 	./include/asm-generic/timex.h:8:23: note: previous declaration of ‘cycles_t’ with type ‘cycles_t’ {aka ‘long unsigned int’}
> 	    8 | typedef unsigned long cycles_t;
> 	      |                       ^~~~~~~~
> 
> To resolve these kinds of problems and to allow <asm/tsc.h> to be included on UML,
> add a simplified version of <asm/tsc.h>, which only adds the rdtsc() definition.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> Cc: Johannes Berg <johannes.berg@intel.com>
> Link: https://lore.kernel.org/r/202505080003.0t7ewxGp-lkp@intel.com
> ---
>  arch/um/include/asm/tsc.h | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>  create mode 100644 arch/um/include/asm/tsc.h
> 
> diff --git a/arch/um/include/asm/tsc.h b/arch/um/include/asm/tsc.h
> new file mode 100644
> index 0000000..a52b0e4
> --- /dev/null
> +++ b/arch/um/include/asm/tsc.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_UM_TSC_H
> +#define _ASM_UM_TSC_H
> +
> +#include <asm/asm.h>
> +
> +/**
> + * rdtsc() - returns the current TSC without ordering constraints
> + *
> + * rdtsc() returns the result of RDTSC as a 64-bit integer.  The
> + * only ordering constraint it supplies is the ordering implied by
> + * "asm volatile": it will put the RDTSC in the place you expect.  The
> + * CPU can and will speculatively execute that RDTSC, though, so the
> + * results can be non-monotonic if compared on different CPUs.
> + */
> +static __always_inline u64 rdtsc(void)
> +{
> +	EAX_EDX_DECLARE_ARGS(val, low, high);
> +
> +	asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
> +
> +	return EAX_EDX_VAL(val, low, high);
> +}
> +
> +#endif /* _ASM_UM_TSC_H */

  reply	other threads:[~2025-05-07 18:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 16:41 [tip:x86/msr 5/19] drivers/accel/habanalabs/common/habanalabs_ioctl.c:326:23: error: call to undeclared function 'rdtsc'; ISO C99 and later do not support implicit function declarations kernel test robot
2025-05-07 18:40 ` [tip: x86/msr] accel/habanalabs: Add explicit include of <asm/tsc.h> to pick up the rdtsc() definition tip-bot2 for Ingo Molnar
2025-05-07 18:40 ` [tip: x86/msr] um: Add UML version of <asm/tsc.h> to define rdtsc() tip-bot2 for Ingo Molnar
2025-05-07 18:47   ` Ingo Molnar [this message]
2025-05-07 20:36   ` Johannes Berg
2025-05-08  8:57     ` [PATCH -v2] accel/habanalabs: Don't build the driver on UML Ingo Molnar
2025-05-08  9:02       ` Johannes Berg
2025-05-08  9:03         ` Ingo Molnar
2025-05-08  9:09 ` [tip: x86/msr] " tip-bot2 for Ingo Molnar

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=aBuqqJoHOag7ZRML@gmail.com \
    --to=mingo@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=x86@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