src/libpmem/pmem.c CLFLUSH not requires fences

62 views
Skip to first unread message

Chun-Hao Lai

unread,
Jan 9, 2016, 4:25:43 AM1/9/16
to pmem
Hello everyone,

  Just a little question. In the "src/libpmem/pmem.c", it comments as following.

 * To flush a range to pmem when neither CLFLUSHOPT or CLWB are available
 * (same as above but fences surrounding CLFLUSH are not required):
 *
 * CLFLUSH for each cache line in the given range.
 *
 * PCOMMIT to mark pmem stores in the memory subsystem.
 *
 * SFENCE to ensure the stores marked by PCOMMIT above have completed.

  And I'm curious about, why CLFLUSH doesn't require SFENCE, doesn't need to make it globally visible before PCOMMIT? 
  
Thank you,
Chun Hao

Andy Rudoff

unread,
Jan 9, 2016, 4:52:28 AM1/9/16
to Chun-Hao Lai, pmem
Hi Chun,

The CLFLUSH instruction has the fence built in to it. That's actually the motivation for adding the CLFUSHOPT instruction, so software can flush a range of cache lines without the implicit fence between each line. 

-andy
--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.
To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f4e59127-1ef5-4fdd-b9aa-d06324bc1ef4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

-andy

Chun-Hao Lai

unread,
Jan 9, 2016, 5:14:45 AM1/9/16
to pmem, jeary4...@gmail.com
Oh, I see. So, actually, if we only have CLFLUSH, we don't need to use MFENCE to order them.
But, why the document explicitly says that:

CLFLUSH is only ordered by the MFENCE instruction. It is not guaranteed to be ordered by any other fencing or serializing instructions or by another CLFLUSH instruction. For example, software can use an MFENCE instruction to insure that previous stores are included in the writeback.

Thanks a lot!

Andy Rudoff於 2016年1月9日星期六 UTC+8下午5時52分28秒寫道:
Hi Chun,

The CLFLUSH instruction has the fence built in to it. That's actually the motivation for adding the CLFUSHOPT instruction, so software can flush a range of cache lines without the implicit fence between each line. 

-andy

On Saturday, January 9, 2016, Chun-Hao Lai <jeary4...@gmail.com> wrote:
Hello everyone,

  Just a little question. In the "src/libpmem/pmem.c", it comments as following.

 * To flush a range to pmem when neither CLFLUSHOPT or CLWB are available
 * (same as above but fences surrounding CLFLUSH are not required):
 *
 * CLFLUSH for each cache line in the given range.
 *
 * PCOMMIT to mark pmem stores in the memory subsystem.
 *
 * SFENCE to ensure the stores marked by PCOMMIT above have completed.

  And I'm curious about, why CLFLUSH doesn't require SFENCE, doesn't need to make it globally visible before PCOMMIT? 
  
Thank you,
Chun Hao

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+unsubscribe@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f4e59127-1ef5-4fdd-b9aa-d06324bc1ef4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

-andy

Ross Zwisler

unread,
Jan 10, 2016, 1:09:51 PM1/10/16
to pmem, jeary4...@gmail.com
It may be true that current implementations of CLFLUSH contain an implicit fence, but according to the SDM this is not architecturally guaranteed to be true for all hardware.  I think that to be safe we should have an explicit fence between our CLFLUSH instructions and the following PCOMMIT.

BTW, the bit in the SDM about how CLFLUSH is ordered has been updated:

Executions of the CLFLUSH instruction are ordered with respect to each other and with respect to writes, locked
read-modify-write instructions, fence instructions, and executions of CLFLUSHOPT to the same cache line. [1] They
are not ordered with respect to executions of CLFLUSHOPT to different cache lines.

and

1. Earlier versions of this manual specified that executions of the CLFLUSH instruction were ordered only by the MFENCE instruction.  All processors implementing the CLFLUSH instruction also order it relative to the other operations enumerated above.

This update appears in version 325462-057US: 

- Ross
Reply all
Reply to author
Forward
0 new messages