Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1197963 > unrolled thread

Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write

Started byThomas Gleixner <tglx@linutronix.de>
First post2015-08-01 12:20 +0200
Last post2015-08-02 18:00 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write Thomas Gleixner <tglx@linutronix.de> - 2015-08-01 12:20 +0200
    Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write Thomas Gleixner <tglx@linutronix.de> - 2015-08-02 21:50 +0200
      Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write Shaohua Li <shli@fb.com> - 2015-08-04 02:00 +0200
    Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write Shaohua Li <shli@fb.com> - 2015-08-02 18:00 +0200

#1197963 — Re: [PATCH] x86: serialize LVTT and TSC_DEADLINE write

FromThomas Gleixner <tglx@linutronix.de>
Date2015-08-01 12:20 +0200
SubjectRe: [PATCH] x86: serialize LVTT and TSC_DEADLINE write
Message-ID<pSC3v-1Jd-3@gated-at.bofh.it>
On Fri, 31 Jul 2015, Shaohua Li wrote:
> @@ -336,6 +336,22 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
>  	apic_write(APIC_LVTT, lvtt_value);
>  
>  	if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) {
> +		u64 msr;
> +
> +		/*
> +		 * See Intel SDM: TSC-Deadline Mode chapter. In xAPIC mode,
> +		 * writing APIC LVTT and TSC_DEADLINE MSR isn't serialized.
> +		 * This uses the algorithm described in Intel SDM to serialize
> +		 * the two writes
> +		 * */
> +		while (1) {
> +			wrmsrl(MSR_IA32_TSC_DEADLINE, -1L);
> +			rdmsrl(MSR_IA32_TSC_DEADLINE, msr);
> +			if (msr)
> +				break;
> +		}
> +		wrmsrl(MSR_IA32_TSC_DEADLINE, 0);


I think this is exceptionally silly. A proper fence after the
apic_write() should have the same effect.

Thanks,

	tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1198297

FromThomas Gleixner <tglx@linutronix.de>
Date2015-08-02 21:50 +0200
Message-ID<pT7qG-5jq-1@gated-at.bofh.it>
In reply to#1197963

[Multipart message — attachments visible in raw view] — view raw

On Sun, 2 Aug 2015, Shaohua Li wrote:

> On Sat, Aug 01, 2015 at 12:10:41PM +0200, Thomas Gleixner wrote:
> > On Fri, 31 Jul 2015, Shaohua Li wrote:
> > > @@ -336,6 +336,22 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
> > >  	apic_write(APIC_LVTT, lvtt_value);
> > >  
> > >  	if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) {
> > > +		u64 msr;
> > > +
> > > +		/*
> > > +		 * See Intel SDM: TSC-Deadline Mode chapter. In xAPIC mode,
> > > +		 * writing APIC LVTT and TSC_DEADLINE MSR isn't serialized.
> > > +		 * This uses the algorithm described in Intel SDM to serialize
> > > +		 * the two writes
> > > +		 * */
> > > +		while (1) {
> > > +			wrmsrl(MSR_IA32_TSC_DEADLINE, -1L);
> > > +			rdmsrl(MSR_IA32_TSC_DEADLINE, msr);
> > > +			if (msr)
> > > +				break;
> > > +		}
> > > +		wrmsrl(MSR_IA32_TSC_DEADLINE, 0);
> > 
> > 
> > I think this is exceptionally silly. A proper fence after the
> > apic_write() should have the same effect.
> 
> Not sure what happens in the hardware, I could have a try of fence, but
> I'd prefer using the algorithm Intel described. This is not a fast path,

s/algorithm/voodoo/

> the loop will exit immediately regardless the issue occurs anyway.

Well, the SDM also says:

 "To allow for efficient access to the APIC registers in x2APIC mode,
  the serializing semantics of WRMSR are relaxed when writing to the
  APIC registers. Thus, system software should not use “WRMSR to APIC
  registers in x2APIC mode” as a serializing instruction. Read and write
  accesses to the APIC registers will occur in program order. A WRMSR to
  an APIC register may complete before all preceding stores are globally
  visible; software can prevent this by inserting a serializing
  instruction, an SFENCE, or an MFENCE before the WRMSR."

And that's what happens here. The write to the LVT has not yet hit the
APIC, so the WRMSR has no effect.

Thanks,

	tglx

[toc] | [prev] | [next] | [standalone]


#1199335

FromShaohua Li <shli@fb.com>
Date2015-08-04 02:00 +0200
Message-ID<pTxOa-1FZ-5@gated-at.bofh.it>
In reply to#1198297
On Sun, Aug 02, 2015 at 09:41:08PM +0200, Thomas Gleixner wrote:
> On Sun, 2 Aug 2015, Shaohua Li wrote:
> 
> > On Sat, Aug 01, 2015 at 12:10:41PM +0200, Thomas Gleixner wrote:
> > > On Fri, 31 Jul 2015, Shaohua Li wrote:
> > > > @@ -336,6 +336,22 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
> > > >  	apic_write(APIC_LVTT, lvtt_value);
> > > >  
> > > >  	if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) {
> > > > +		u64 msr;
> > > > +
> > > > +		/*
> > > > +		 * See Intel SDM: TSC-Deadline Mode chapter. In xAPIC mode,
> > > > +		 * writing APIC LVTT and TSC_DEADLINE MSR isn't serialized.
> > > > +		 * This uses the algorithm described in Intel SDM to serialize
> > > > +		 * the two writes
> > > > +		 * */
> > > > +		while (1) {
> > > > +			wrmsrl(MSR_IA32_TSC_DEADLINE, -1L);
> > > > +			rdmsrl(MSR_IA32_TSC_DEADLINE, msr);
> > > > +			if (msr)
> > > > +				break;
> > > > +		}
> > > > +		wrmsrl(MSR_IA32_TSC_DEADLINE, 0);
> > > 
> > > 
> > > I think this is exceptionally silly. A proper fence after the
> > > apic_write() should have the same effect.
> > 
> > Not sure what happens in the hardware, I could have a try of fence, but
> > I'd prefer using the algorithm Intel described. This is not a fast path,
> 
> s/algorithm/voodoo/
> 
> > the loop will exit immediately regardless the issue occurs anyway.
> 
> Well, the SDM also says:
> 
>  "To allow for efficient access to the APIC registers in x2APIC mode,
>   the serializing semantics of WRMSR are relaxed when writing to the
>   APIC registers. Thus, system software should not use “WRMSR to APIC
>   registers in x2APIC mode” as a serializing instruction. Read and write
>   accesses to the APIC registers will occur in program order. A WRMSR to
>   an APIC register may complete before all preceding stores are globally
>   visible; software can prevent this by inserting a serializing
>   instruction, an SFENCE, or an MFENCE before the WRMSR."
> 
> And that's what happens here. The write to the LVT has not yet hit the
> APIC, so the WRMSR has no effect.

What you quoted is for x2APIC, I didn't see similar description for
xAPIC.

Tested mfence here, it does work. But I'm not convinced it's the right
thing. the xAPIC access is memory mapped IO, mfence is nothing related
to it. Anyway, cc-ed more intel people, hope they can share some
insights.

Thanks,
Shaohua
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1198433

FromShaohua Li <shli@fb.com>
Date2015-08-02 18:00 +0200
Message-ID<pT3Q6-59-11@gated-at.bofh.it>
In reply to#1197963
On Sat, Aug 01, 2015 at 12:10:41PM +0200, Thomas Gleixner wrote:
> On Fri, 31 Jul 2015, Shaohua Li wrote:
> > @@ -336,6 +336,22 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
> >  	apic_write(APIC_LVTT, lvtt_value);
> >  
> >  	if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) {
> > +		u64 msr;
> > +
> > +		/*
> > +		 * See Intel SDM: TSC-Deadline Mode chapter. In xAPIC mode,
> > +		 * writing APIC LVTT and TSC_DEADLINE MSR isn't serialized.
> > +		 * This uses the algorithm described in Intel SDM to serialize
> > +		 * the two writes
> > +		 * */
> > +		while (1) {
> > +			wrmsrl(MSR_IA32_TSC_DEADLINE, -1L);
> > +			rdmsrl(MSR_IA32_TSC_DEADLINE, msr);
> > +			if (msr)
> > +				break;
> > +		}
> > +		wrmsrl(MSR_IA32_TSC_DEADLINE, 0);
> 
> 
> I think this is exceptionally silly. A proper fence after the
> apic_write() should have the same effect.

Not sure what happens in the hardware, I could have a try of fence, but
I'd prefer using the algorithm Intel described. This is not a fast path,
the loop will exit immediately regardless the issue occurs anyway.

Thanks,
Shaohua
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web