/* generate .h file, event enumeration then structures and functions */
fprintf(iFp, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
fprintf(iFp, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+ fprintf(iFp, "#ifdef CONFIG_LTT\n");
generateEnumEvent(iFp, fac->name, &nbEvent, checksum);
+ fprintf(iFp, "#endif //CONFIG_LTT\n");
fprintf(iFp, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
fprintf(hFp, "#ifndef _LTT_FACILITY_%s_H_\n",fac->capname);
fprintf(hFp, "#define _LTT_FACILITY_%s_H_\n\n",fac->capname);
+ //fprintf(hFp, "#ifdef CONFIG_LTT\n");
generateTypeDefs(hFp, fac->name);
generateStructFunc(hFp, fac->name,checksum);
+ //fprintf(hFp, "#endif //CONFIG_LTT\n");
fprintf(hFp, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
/* generate .h file, calls to register the facility at init time */
static void
printStruct(FILE * fp, int len, void ** array, char * name, char * facName,
- int * whichTypeFirst, int * hasStrSeq, int * structCount)
+ int * whichTypeFirst, int * hasStrSeq, int * structCount,
+ type_descriptor *type)
{
int flag = 0;
int pos;
}
if(flag) {
- fprintf(fp,"} __attribute__ ((packed));\n\n");
+ if(type->alignment == 0)
+ fprintf(fp,"} __attribute__ ((packed));\n\n");
+ else {
+ if(type->alignment != 1 && type->alignment != 2
+ && type->alignment != 4 && type->alignment != 8) {
+ printf("Wrong alignment %i, using packed.\n", type->alignment);
+ fprintf(fp,"} __attribute__ ((packed));\n\n");
+ } else
+ fprintf(fp,"} __attribute__ ((aligned(%i)));\n\n", type->alignment);
+ }
}
}
fprintf(fp,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n", facName);
fprintf(fp,"#include <linux/ltt-core.h>\n");
+#if 0 //broken
fprintf(fp, "/**** Basic Type Definitions ****/\n\n");
for (pos = 0; pos < fac->named_types.values.position; pos++) {
fprintf(fp, "typedef struct _%s %s;\n\n",
type->type_name, type->type_name);
}
+#endif //0
}
//structure for kernel
if(ev->type != 0)
printStruct(fp, ev->type->fields.position, ev->type->fields.array,
- ev->name, facName, &whichTypeFirst, &hasStrSeq, &structCount);
+ ev->name, facName, &whichTypeFirst, &hasStrSeq, &structCount,
+ ev->type);
- //trace function : function name and parameters
+
+ //trace function : function name and parameters : stub function.
seqCount = 0;
strCount = 0;
+ fprintf(fp, "#ifndef CONFIG_LTT\n");
fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name);
if(ev->type == 0)
fprintf(fp, "void");
if(pos1 != ev->type->fields.position - 1) fprintf(fp,", ");
}
fprintf(fp,")\n{\n");
+ fprintf(fp,"}\n");
+ fprintf(fp,"#else\n");
- //length of buffer : length of all structures
- fprintf(fp,"\tint length = ");
- if(ev->type == 0) fprintf(fp, "0");
-
- for(pos1=0;pos1<structCount;pos1++){
- fprintf(fp,"sizeof(struct %s_%s_%d)",ev->name, facName,pos1+1);
- if(pos1 != structCount-1) fprintf(fp," + ");
- }
-
- //length of buffer : length of all arrays, sequences and strings
+ //trace function : function name and parameters
seqCount = 0;
strCount = 0;
- flag = 0;
- if(ev->type != 0)
- for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){
- fld = (field *)ev->type->fields.array[pos1];
- td = fld->type;
- if(td->type == SEQUENCE || td->type==STRING || td->type==ARRAY){
- if(structCount || flag > 0) fprintf(fp," + ");
- if(td->type == SEQUENCE)
- fprintf(fp,"sizeof(%s) + sizeof(%s) * seqlength_%d",
- uintOutputTypes[td->size], getTypeStr(td), ++seqCount);
- else if(td->type==STRING) fprintf(fp,"strlength_%d + 1", ++strCount);
- else if(td->type==ARRAY)
- fprintf(fp,"sizeof(%s) * %d", getTypeStr(td),td->size);
- if(structCount == 0) flag = 1;
- }
- }
- fprintf(fp,";\n");
+ fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name);
+ if(ev->type == 0)
+ fprintf(fp, "void");
+ else
+ for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){
+ fld = (field *)ev->type->fields.array[pos1];
+ td = fld->type;
+ if(td->type == ARRAY ){
+ fprintf(fp,"%s * %s",getTypeStr(td), fld->name);
+ }else if(td->type == STRING){
+ fprintf(fp,"short int strlength_%d, %s * %s",
+ ++strCount, getTypeStr(td), fld->name);
+ }else if(td->type == SEQUENCE){
+ fprintf(fp,"%s seqlength_%d, %s * %s",
+ uintOutputTypes[td->size], ++seqCount,getTypeStr(td), fld->name);
+ }else fprintf(fp,"%s %s",getTypeStr(td), fld->name);
+ if(pos1 != ev->type->fields.position - 1) fprintf(fp,", ");
+ }
+ fprintf(fp,")\n{\n");
+
+
//allocate buffer
// MD no more need. fprintf(fp,"\tchar buff[buflength];\n");
// write directly to the channel
+ fprintf(fp, "\tint length;\n");
fprintf(fp, "\tunsigned int index;\n");
fprintf(fp, "\tstruct ltt_channel_struct *channel;\n");
fprintf(fp, "\tstruct ltt_trace_struct *trace;\n");
fprintf(fp, "\tunsigned long _flags;\n");
+ fprintf(fp, "\tvoid *buff;\n");
+ fprintf(fp, "\tvoid *offset_ptr;\n");
+ fprintf(fp, "\tunsigned int header_length;\n");
+ fprintf(fp, "\tunsigned int event_length;\n");
+ fprintf(fp, "\tint resret;\n");
+ fprintf(fp, "\tunsigned char _offset;\n");
+ fprintf(fp, "\tunsigned char length_offset;\n");
+ fprintf(fp, "\tstruct rchan_buf *buf;\n");
+
if(ev->type != 0)
fprintf(fp, "\tstruct %s_%s_1* __1;\n\n", ev->name, facName);
- fprintf(fp, "\tread_lock(<t_traces.traces_rwlock);\n\n");
+ /* Warning : this is done prior to taking locks :
+ * setting this value must be done at the end of the trace activation.
+ * (we don't care for trace removal, as the list of traces is protected : it
+ * just won't iterate on any trace). */
fprintf(fp,
- "\tif(ltt_traces.num_active_traces == 0) goto unlock_traces;\n\n");
+ "\tif(ltt_traces.num_active_traces == 0) return;\n\n");
+
+ fprintf(fp, "\t/* Disable interrupts. */\n");
+ fprintf(fp, "\tlocal_irq_save(_flags);\n");
+ fprintf(fp, "\tpreempt_disable();\n\n");
+ fprintf(fp, "\tltt_nesting[smp_processor_id()]++;\n");
+ fprintf(fp, "\tbarrier();\n");
+ fprintf(fp, "\tif(ltt_nesting[smp_processor_id()] > 1) goto unlock;\n");
+ fprintf(fp, "\tspin_lock(<t_traces.locks[smp_processor_id()]);\n\n");
+
fprintf(fp,
"\tindex = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
"\t\t\t\tevent_%s);\n",
facName, checksum, ev->name);
fprintf(fp,"\n");
- fprintf(fp, "\t/* Disable interrupts. */\n");
- fprintf(fp, "\tlocal_irq_save(_flags);\n\n");
-
/* For each trace */
fprintf(fp, "\tlist_for_each_entry(trace, <t_traces.head, list) {\n");
fprintf(fp, "\t\tif(!trace->active) continue;\n\n");
-
- fprintf(fp, "\t\tunsigned int header_length = "
- "ltt_get_event_header_size(trace);\n");
- fprintf(fp, "\t\tunsigned int event_length = header_length + length;\n");
+
+ //length of buffer : length of all structures
+ fprintf(fp,"\t\tlength = 0;\n");
+ fprintf(fp,"\t\tlength_offset = 0;\n");
+ // if(ev->type == 0) fprintf(fp, "0");
- /* Reserve the channel */
fprintf(fp, "\t\tchannel = ltt_get_channel_from_index(trace, index);\n");
- fprintf(fp,
- "\t\tvoid *buff = relay_reserve(channel->rchan, event_length);\n");
+ fprintf(fp, "\t\tbuf = channel->rchan->buf[smp_processor_id()];\n");
+ /* Warning : not atomic reservation : event size depends on the current
+ * address for alignment */
+ // Replaces _offset
+ fprintf(fp, "\t\theader_length = "
+ "ltt_get_event_header_size(trace, channel,"
+ "buf->data + buf->offset, &_offset);\n");
+
+ for(pos1=0;pos1<structCount;pos1++){
+
+ if(ev->type->alignment > 1) {
+ fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1) ;\n",
+ ev->type->alignment, ev->type->alignment, ev->type->alignment);
+ }
+ fprintf(fp,"\t\tlength+=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 *)ev->type->fields.array[pos1];
+ td = fld->type;
+ if(td->type == SEQUENCE || td->type==STRING || td->type==ARRAY){
+ if(td->type == SEQUENCE) {
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1)) ;\n",
+ td->alignment, td->alignment, td->alignment);
+ }
+ fprintf(fp,
+ "\t\tlength+=sizeof(%s) + (sizeof(%s) * seqlength_%d);\n",
+ uintOutputTypes[td->size], getTypeStr(td), ++seqCount);
+ } else if(td->type==STRING) {
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1)) ;\n",
+ td->alignment, td->alignment, td->alignment);
+ }
+ fprintf(fp,"length+=strlength_%d + 1;\n",
+ ++strCount);
+ }
+ else if(td->type==ARRAY) {
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ td->alignment, td->alignment, td->alignment);
+ }
+ fprintf(fp,"\t\tlength+=sizeof(%s) * %d;\n",
+ getTypeStr(td),td->size);
+ if(structCount == 0) flag = 1;
+ }
+ }
+ }
+ fprintf(fp,";\n");
+
+ fprintf(fp, "\t\tevent_length = _offset + header_length + "
+ "length_offset + length;\n");
+
+ /* Reserve the channel */
+ fprintf(fp, "\t\tbuff = relay_reserve(channel->rchan, event_length, &resret);\n");
fprintf(fp, "\t\tif(buff == NULL) {\n");
fprintf(fp, "\t\t\t/* Buffer is full*/\n");
fprintf(fp, "\t\t\t/* for debug BUG(); */\n"); // DEBUG!
fprintf(fp, "\t\t\tchannel->events_lost[smp_processor_id()]++;\n");
- fprintf(fp, "\t\t\tgoto commit_work;\n");
+ fprintf(fp, "\t\t\tbreak;\n"); /* don't commit a NULL reservation! */
fprintf(fp, "\t\t}\n");
/* DEBUG */
- fprintf(fp, "/* for debug printk(\"f%%lu e\%%u \", ltt_facility_%s_%X, event_%s); */",
+ fprintf(fp, "\t\tif(resret == 1) {\n");
+ fprintf(fp, "printk(\"f%%lu e\%%u \", ltt_facility_%s_%X, event_%s);",
facName, checksum, ev->name);
+ fprintf(fp, "\t\t}\n");
/* Write the header */
fprintf(fp, "\n");
fprintf(fp, "\t\tltt_write_event_header(trace, channel, buff, \n"
- "\t\t\t\tltt_facility_%s_%X, event_%s, length);\n",
+ "\t\t\t\tltt_facility_%s_%X, event_%s, length, _offset);\n",
facName, checksum, ev->name);
fprintf(fp, "\n");
-
+ fprintf(fp, "\t\tchar *ptr = (char*)buff + _offset + header_length;\n");
+
+
//declare a char pointer if needed : starts at the end of the structs.
- if(structCount + hasStrSeq > 1) {
- fprintf(fp,"\t\tchar * ptr = (char*)buff + header_length");
- for(pos1=0;pos1<structCount;pos1++){
- fprintf(fp," + sizeof(struct %s_%s_%d)",ev->name, facName,pos1+1);
- }
- if(structCount + hasStrSeq > 1) fprintf(fp,";\n");
- }
+ //if(structCount + hasStrSeq > 1) {
+ // fprintf(fp,"\t\tchar * ptr = (char*)buff + header_length");
+ // for(pos1=0;pos1<structCount;pos1++){
+ // fprintf(fp," + sizeof(struct %s_%s_%d)",ev->name, facName,pos1+1);
+ // }
+ // if(structCount + hasStrSeq > 1) fprintf(fp,";\n");
+ //}
// Declare an alias pointer of the struct type to the beginning
// of the reserved area, just after the event header.
- if(ev->type != 0)
- fprintf(fp, "\t\t__1 = (struct %s_%s_1 *)(buff + header_length);\n",
+ if(ev->type != 0) {
+ if(ev->type->alignment > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ ev->type->alignment, ev->type->alignment, ev->type->alignment);
+ }
+
+ fprintf(fp, "\t\t__1 = (struct %s_%s_1 *)(ptr);\n",
ev->name, facName);
+ }
//allocate memory for new struct and initialize it
//if(whichTypeFirst == 1){ //struct first
//for(pos1=0;pos1<structCount;pos1++){
}
if(structCount) fprintf(fp,"\n");
//set ptr to the end of first struct if needed;
- if(structCount + hasStrSeq > 1){
- fprintf(fp,"\n\t\t//set ptr to the end of the first struct\n");
- fprintf(fp,"\t\tptr += sizeof(struct %s_%s_1);\n\n",ev->name, facName);
- }
+ //if(structCount + hasStrSeq > 1){
+ // fprintf(fp,"\n\t\t//set ptr to the end of the first struct\n");
+ // fprintf(fp,"\t\tptr += sizeof(struct %s_%s_1);\n\n",ev->name, facName);
+ //}
//copy struct, sequence and string to buffer
seqCount = 0;
if(td->type == SEQUENCE){
flag = 0;
fprintf(fp,"\t\t//copy sequence length and sequence to buffer\n");
+
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ td->alignment, td->alignment, td->alignment);
+ }
fprintf(fp,"\t\t*ptr = seqlength_%d;\n",++seqCount);
fprintf(fp,"\t\tptr += sizeof(%s);\n",uintOutputTypes[td->size]);
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ td->alignment, td->alignment, td->alignment);
+ }
fprintf(fp,"\t\tmemcpy(ptr, %s, sizeof(%s) * seqlength_%d);\n",
fld->name, getTypeStr(td), seqCount);
- fprintf(fp,"\t\tptr += sizeof(%s) * seqlength_%d;\n\n",
+ fprintf(fp,"\t\tptr += sizeof(%s) * seqlength_%d;\n\n",
getTypeStr(td), seqCount);
}
else if(td->type==STRING){
flag = 0;
fprintf(fp,"\t\t//copy string to buffer\n");
fprintf(fp,"\t\tif(strlength_%d > 0){\n",++strCount);
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ td->alignment, td->alignment, td->alignment);
+ }
fprintf(fp,"\t\t\tmemcpy(ptr, %s, strlength_%d + 1);\n",
fld->name, strCount);
fprintf(fp,"\t\t\tptr += strlength_%d + 1;\n",strCount);
}else if(td->type==ARRAY){
flag = 0;
fprintf(fp,"\t//copy array to buffer\n");
+ if(td->alignment > 1) {
+ fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n",
+ td->alignment, td->alignment, td->alignment);
+ }
fprintf(fp,"\tmemcpy(ptr, %s, sizeof(%s) * %d);\n",
fld->name, getTypeStr(td), td->size);
fprintf(fp,"\tptr += sizeof(%s) * %d;\n\n", getTypeStr(td), td->size);
}
if(structCount + seqCount > 1) fprintf(fp,"\n");
- fprintf(fp,"\n");
- fprintf(fp,"commit_work:\n");
fprintf(fp,"\n");
fprintf(fp, "\t\t/* Commit the work */\n");
fprintf(fp, "\t\trelay_commit(channel->rchan->buf[smp_processor_id()],\n"
"\t\t\t\tbuff, event_length);\n");
+ fprintf(fp, "\t\tltt_write_commit_counter("
+ "channel->rchan->buf[smp_processor_id()],\n"
+ "\t\t\t\tbuff);\n");
/* End of traces iteration */
fprintf(fp, "\t}\n\n");
+ fprintf(fp, "\n");
+ // The generated preempt_check_resched is not dangerous because
+ // interrupts are disabled.
+ fprintf(fp, "\tspin_unlock(<t_traces.locks[smp_processor_id()]);\n");
+
+ fprintf(fp, "unlock:\n");
+ fprintf(fp, "\tbarrier();\n");
+ fprintf(fp, "\tltt_nesting[smp_processor_id()]--;\n");
fprintf(fp, "\t/* Re-enable interrupts */\n");
fprintf(fp, "\tlocal_irq_restore(_flags);\n");
- fprintf(fp, "\tpreempt_check_resched();\n");
+ fprintf(fp, "\tpreempt_enable_no_resched();\n");
+ //fprintf(fp, "\tpreempt_check_resched();\n");
- fprintf(fp, "\n");
- fprintf(fp, "unlock_traces:\n");
- fprintf(fp, "\tread_unlock(<t_traces.traces_rwlock);\n");
//call trace function
//fprintf(fp,"\n\t//call trace function\n");
//fprintf(fp,"\tltt_log_event(ltt_facility_%s_%X, %s, bufLength, buff);\n",facName,checksum,ev->name);
- fprintf(fp,"}\n\n\n");
+ fprintf(fp,"}\n");
+ fprintf(fp, "#endif //CONFIG_LTT\n\n");
}
}