+ /* 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_offset = buf->offset;\n");
+ fprintf(fp, "\t\t\tbarrier();\n");
+ fprintf(fp, "\t\t\tptr = (char*)buf->data + old_offset;\n");
+
+
+ fprintf(fp, "\t\t\theader_length = ltt_get_event_header_data(trace, "
+ "channel,\n"
+ "\t\t\t\t\t\t\t\t\t\tptr, &_offset, &delta, &tsc);\n");
+
+ fprintf(fp, "\t\t\tptr += _offset + header_length;\n");
+
+ for(pos1=0;pos1<structCount;pos1++){
+
+ unsigned align = max(alignment, ev->type->alignment);
+ if(align > 1) {
+ fprintf(fp,"\t\t\tptr += (%u - ((unsigned int)ptr&(%u-1)))&(%u-1) ;\n",
+ align, align, align);
+ }
+ fprintf(fp,"\t\t\tptr += sizeof(struct %s_%s_%d);\n",ev->name,
+ facName,pos1+1);
+// if(pos1 != structCount-1) fprintf(fp," + ");
+ }
+
+ //length of buffer : length of all arrays, sequences and strings
+ seqCount = 0;
+ strCount = 0;
+ flag = 0;
+ if(ev->type != 0)
+ for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){
+ fld = (field_t *)ev->type->fields.array[pos1];
+ td = fld->type;
+ if(td->type == SEQUENCE || td->type==STRING || td->type==ARRAY){
+ if(td->type == SEQUENCE) {
+
+ unsigned align = max(alignment, td->alignment);
+ if(align > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ align, align, align);
+ }
+ fprintf(fp,"\t\tptr += sizeof(%s);\n",uintOutputTypes[td->size]);
+ if(align > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ align, align, align);
+ }
+ fprintf(fp,"\t\tptr += sizeof(%s) * seqlength_%d;\n\n",
+ getTypeStr(td), seqCount);
+
+ } else if(td->type==STRING) {
+ unsigned align = max(alignment, td->alignment);
+ if(align > 1) {
+ fprintf(fp,"\t\t\tptr += (%u - ((unsigned int)ptr&(%u-1)))&(%u-1)) ;\n",
+ align, align, align);
+ }
+ fprintf(fp,"ptr += strlength_%d + 1;\n",
+ ++strCount);
+ }
+ else if(td->type==ARRAY) {
+ unsigned align = max(alignment, td->alignment);
+ if(align > 1) {
+ fprintf(fp,"\t\t\tptr += (%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ align, align, align);
+ }
+ fprintf(fp,"\t\t\tptr += sizeof(%s) * %d;\n",
+ getTypeStr(td),td->size);
+ if(structCount == 0) flag = 1;
+ }
+ }
+ }
+ fprintf(fp, "\t\t\tevent_length = (unsigned long)ptr -"
+ "(unsigned long)(buf->data + old_offset);\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_offset);\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "\t\t} while(PTR_ERR(buff) == -EAGAIN);\n");
+ fprintf(fp, "\n");
+
+