From: compudj Date: Sat, 30 Jul 2005 04:39:39 +0000 (+0000) Subject: add reserve, tsc and alignment atomicity with cmpxchg : add memory barrier to protect. X-Git-Tag: v0.12.20~2488 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c3e1c4c42843c85b7fd1fa3a8c74791dd4502b7b;p=lttv.git add reserve, tsc and alignment atomicity with cmpxchg : add memory barrier to protect. git-svn-id: http://ltt.polymtl.ca/svn@1001 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/genevent/genevent.c b/genevent/genevent.c index 5930489f..62db1274 100644 --- a/genevent/genevent.c +++ b/genevent/genevent.c @@ -540,8 +540,12 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ * address for alignment */ /* NOTE : using cmpxchg in reserve with repeat for atomicity */ // Replaces _offset + /* NOTE2 : as the read old address from memory must come before any + * protected event, let's add a memory barrier() to make sure the compiler + * will not reorder this read. */ fprintf(fp, "\t\tdo {\n"); fprintf(fp, "\t\t\told_address = buf->data + buf->offset;\n"); + fprintf(fp, "\t\t\tbarrier();\n"); fprintf(fp, "\t\t\tchar *ptr = (char*)old_address;\n"); @@ -602,7 +606,12 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ fprintf(fp, "\t\t\tevent_length = (unsigned long)ptr -" "(unsigned long)old_address;\n"); - + + /* let's put some protection before the cmpxchg : the space reservation and + * the get TSC are not dependant from each other. I don't want the compiler + * to reorder those in the wrong order. And relay_reserve is inline, so + * _yes_, the compiler could mess it up. */ + fprintf(fp, "\t\t\tbarrier();\n"); fprintf(fp, "\t\t\tbuff = relay_reserve(channel->rchan, event_length, " "old_address);\n"); fprintf(fp, "\n");