+++ /dev/null
-SHELL = /bin/sh
-
-CC = gcc
-
-#CFLAGS = -std=c99 -Wall -g -DDEBUG
-CFLAGS = -std=c99 -Wall -g
-
-all: genevent
-
-install: genevent
- cp -f genevent /usr/local/bin
-
-genevent: genevent.o parser.o
- $(CC) $(CFLAGS) -o $@ $^
-
-genevent.o: genevent.c genevent.h parser.h
- $(CC) $(CFLAGS) -c -o $@ $<
-
-parser.o: parser.c parser.h
- $(CC) $(CFLAGS) -c -o $@ $<
-
-.PHONY: clean
-
-clean:
- rm -rf *.o *~ *# genevent
-
-
+++ /dev/null
-
-Mathieu Desnoyers -- November 2005
-
-This is a complete rework of genevent.
-
-The 'genevent' program parses event descriptions and generates
-the inline functions to record events in the kernel.
-
-There are several files in the directory:
- genevent.c, genevent.h, crc32.tab, parser.c and parser.h
-
-In fact, crc32.tab, parser.c and parser.h are the same files as
-those in LTT library.
-
-Important notes :
- * Do not put "-" symbols in facilities name.
- * Use the exact same name for facility xml file and for facility name.
- * As from genevent 0.17, a standard XML 1.0 description is "required". It must
- begin with the <?xml version="1.0"?> header.
-
-Note about strings :
-There are three methods to write strings in genevent, each suitable and
-efficient for a particular case. They are explained here from the fastest
-to the slowest.
-1 - The C code presents a fixed size string.
- For example, you find :
- char mystring[10];
- as string definition.
-
- you must then define it as an array of char :
- <array size="10"><char></array>
-
- Note, however, that you might not want to declare a fixed size for trace size
- and unnecessary copy matters.
-
- For instance, on a 32 bits architecture, copying a n bytes array takes
- approximately* n/4 memory read and write, for n/2 memory operations.
-
- Using the slower method described in (3), with a strlen and memcpy, where
- "u" is the number of used caracters, takes u+1 reads for the strlen, and
- approximately* (u+1)/4 read and write for the memcpy, for a total of :
- (3/2)*(u+1) memory access.
-
- So, if (n/2) > (3/2)*(u+1), or : n > 3*u+3
- where n is the size of the array
- u is the average number of used caracters (excluding the \0)
- it becomes faster to use the method number 3 with strlen.
-
-2 - The C code presents a variable size string together with its
- size.
-
- A typical use for this case is filenames in the Linux kernel. The
- dentry strucure has a d_name member, which is a struct qstr containing
- a unsigned int len and const unsigned char *name.
-
- you must use a sequence to declare this efficiently :
- <sequence><uint><char></sequence>
-
-3 - The C code presents a \0 terminated string.
-
- This is the slowest, but most convenient way to declare a string. You are
- discouraged to use it when options 1 or 2 are available. It will dynamically
- calculate the string length (byte by byte read) and only afterward do a
- memcpy.
-
- Note that, as explained in 1, if n > 3*u+3, it becomes faster to use this
- method instead of copying the whole fixed size array.
-
- Declare like this :
- <string>
-
-Here is a brief description of how to use genevent.
-
-make
-make install
-
-
-* Add new events to the kernel with genevent
-
-su -
-cd /usr/local/share/LinuxTraceToolkitViewer/facilities
-cp process.xml yourfacility.xml
- * edit yourfacility.xml to fit your needs.
-cd /tmp
-/usr/local/bin/genevent /usr/local/share/LinuxTraceToolkitViewer/yourfacility.xml
-cp ltt-facility-yourfacility.h ltt-facility-id-yourfacility.h \
- /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt
-cp ltt-facility-loader-yourfacility.c ltt-facility-loader-yourfacility.h \
- /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/ltt
- * edit the kernel file you want to instrument
- - Add #include <linux/ltt/ltt-facility-yourfacility.h> at the beginning
- of the file.
- - Add a call to the tracing functions. See their names and parameters in
- /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt/ltt-facility-yourfacility.h
-
-
-
-* The approximation comes from the fact that copies of number of caracters non
- multiple of the architecture size takes more operations (maximum of :
- (architecture size (in bytes) - 1) operations).
-
+++ /dev/null
- 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
- 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
- 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
- 0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
- 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
- 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
- 0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
- 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
- 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
- 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
- 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
- 0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
- 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
- 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
- 0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
- 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
- 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
- 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
- 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
- 0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
- 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
- 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
- 0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
- 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
- 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
- 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
- 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
- 0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
- 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
- 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
- 0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
- 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
- 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
- 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
- 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
- 0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
- 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
- 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
- 0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
- 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
- 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
- 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
- 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
- 0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
- 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
- 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
- 0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
- 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
- 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
- 0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
- 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
- 0x2d02ef8dU
+++ /dev/null
-/******************************************************************************
- * Genevent
- *
- * Event generator. XML to logging C code converter.
- *
- * Program parameters :
- * ./genevent name.xml
- *
- * Will generate ltt-facility-name.h, ltt-facility-id-name.h
- * ltt-facility-loader-name.c, ltt-facility-loader-name.h
- * in the current directory.
- *
- * Supports :
- * - C Alignment
- * - C types : struct, union, enum, basic types.
- * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
- *
- * Additionnal structures supported :
- * - embedded variable size strings
- * - embedded variable size arrays
- * - embedded variable size sequences
- *
- * Notes :
- * (1)
- * enums are limited to integer type, as this is what is used in C. Note,
- * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
- * unsigned int or int. This is implementation defined (compiler). That's why we
- * add a check for sizeof enum.
- *
- * (2)
- * Because of archtecture defined type sizes, we need to ask for ltt_align
- * (which gives the alignment) by passing basic types, not their actual sizes.
- * It's up to ltt_align to determine sizes of types.
- *
- * Note that, from
- * http://www.usenix.org/publications/login/standards/10.data.html
- * (Andrew Josey <a.josey@opengroup.org>) :
- *
- * Data Type LP32 ILP32 ILP64 LLP64 LP64
- * char 8 8 8 8 8
- * short 16 16 16 16 16
- * int32 32
- * int 16 32 64 32 32
- * long 32 32 64 32 64
- * long long (int64) 64
- * pointer 32 32 64 64 64
- *
- * With these constraints :
- * sizeof(char) <= sizeof(short) <= sizeof(int)
- * <= sizeof(long) = sizeof(size_t)
- *
- * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
- *
- * Which means we only have to remember which is the biggest type in a structure
- * to know the structure's alignment.
- */
-
-#define _GNU_SOURCE
-#include <limits.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <assert.h>
-
-#include "genevent.h"
-#include "parser.h"
-
-
-#define TRUE 1
-#define FALSE (!TRUE)
-
-/* Debugging printf */
-#ifdef DEBUG
-#define dprintf(...) \
- do {\
- printf(__FILE__ ",%u,%s: ",\
- __LINE__, __func__);\
- printf(__VA_ARGS__);\
- } while(0)
-#else
-#define dprintf(...)
-#endif
-
-
-enum user_fct_types { USER_FCT_PROTO, USER_FCT_DECLARATION } ;
-
-/* Code printing */
-
-void print_tabs(unsigned int tabs, FILE *fd)
-{
- for(unsigned int i = 0; i<tabs;i++)
- fprintf(fd, "\t");
-}
-
-/* print type.
- *
- * Copied from construct_types_and_fields in LTTV facility.c */
-
-int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- strcpy(basename, nest_name);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_')
- && (field_name[0] != '\0')) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- switch(td->type) {
- case INT_FIXED:
- fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
- break;
- case UINT_FIXED:
- fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
- break;
- case CHAR:
- fprintf(fd, "signed char");
- break;
- case UCHAR:
- fprintf(fd, "unsigned char");
- break;
- case SHORT:
- fprintf(fd, "short");
- break;
- case USHORT:
- fprintf(fd, "unsigned short");
- break;
- case INT:
- fprintf(fd, "int");
- break;
- case UINT:
- fprintf(fd, "unsigned int");
- break;
- case FLOAT:
- fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
- break;
- case POINTER:
- fprintf(fd, "const void *");
- break;
- case LONG:
- fprintf(fd, "long");
- break;
- case ULONG:
- fprintf(fd, "unsigned long");
- break;
- case SIZE_T:
- fprintf(fd, "size_t");
- break;
- case SSIZE_T:
- fprintf(fd, "ssize_t");
- break;
- case OFF_T:
- fprintf(fd, "off_t");
- break;
- case STRING:
- fprintf(fd, "const char *");
- break;
- case ENUM:
- fprintf(fd, "enum lttng_%s", basename);
- break;
- case ARRAY:
- fprintf(fd, "lttng_array_%s", basename);
- break;
- case SEQUENCE:
- fprintf(fd, "lttng_sequence_%s", basename);
- break;
- case STRUCT:
- fprintf(fd, "struct lttng_%s", basename);
- break;
- case UNION:
- fprintf(fd, "union lttng_%s", basename);
- break;
- default:
- printf("print_type : unknown type\n");
- return 1;
- }
-
- return 0;
-}
-
-/* Print logging function argument */
-int print_arg(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- strcpy(basename, nest_name);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_')
- && (field_name[0] != '\0')) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- print_tabs(tabs, fd);
-
- switch(td->type) {
- case INT_FIXED:
- fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case UINT_FIXED:
- fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case CHAR:
- fprintf(fd, "signed char");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case UCHAR:
- fprintf(fd, "unsigned char");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case SHORT:
- fprintf(fd, "short");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case USHORT:
- fprintf(fd, "unsigned short");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case INT:
- fprintf(fd, "int");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case UINT:
- fprintf(fd, "unsigned int");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case FLOAT:
- fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case POINTER:
- fprintf(fd, "const void *");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case LONG:
- fprintf(fd, "long");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case ULONG:
- fprintf(fd, "unsigned long");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case SIZE_T:
- fprintf(fd, "size_t");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case SSIZE_T:
- fprintf(fd, "ssize_t");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case OFF_T:
- fprintf(fd, "off_t");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case STRING:
- fprintf(fd, "const char *");
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case ENUM:
- fprintf(fd, "enum lttng_%s", basename);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case ARRAY:
- fprintf(fd, "lttng_array_%s", basename);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case SEQUENCE:
- fprintf(fd, "lttng_sequence_%s *", basename);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case STRUCT:
- fprintf(fd, "struct lttng_%s *", basename);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- case UNION:
- fprintf(fd, "union lttng_%s *", basename);
- fprintf(fd, " lttng_param_%s", field_name);
- break;
- default:
- printf("print_type : unknown type\n");
- return 1;
- }
-
- return 0;
-}
-
-
-/* Does the type has a fixed size ? (as know from the compiler)
- *
- * 1 : fixed size
- * 0 : variable length
- */
-int has_type_fixed_size(type_descriptor_t *td)
-{
- switch(td->type) {
- case INT_FIXED:
- case UINT_FIXED:
- case CHAR:
- case UCHAR:
- case SHORT:
- case USHORT:
- case INT:
- case UINT:
- case FLOAT:
- case POINTER:
- case LONG:
- case ULONG:
- case SIZE_T:
- case SSIZE_T:
- case OFF_T:
- case ENUM:
- case UNION: /* The union must have fixed size children. Must be checked by
- the parser */
- return 1;
- break;
- case STRING:
- case SEQUENCE:
- return 0;
- break;
- case STRUCT:
- {
- int has_type_fixed = 0;
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
-
- has_type_fixed = has_type_fixed_size(type);
- if(!has_type_fixed) return 0;
- }
- return 1;
- }
- break;
- case ARRAY:
- assert(td->size >= 0);
- return has_type_fixed_size(((field_t*)td->fields.array[0])->type);
- break;
- case NONE:
- printf("There is a type defined to NONE : bad.\n");
- assert(0);
- break;
- }
- return 0; //make gcc happy.
-}
-
-
-
-
-
-/* print type declaration.
- *
- * Copied from construct_types_and_fields in LTTV facility.c */
-
-int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- if(td->custom_write) return 0; /* Does print custom type */
-
- strncpy(basename, nest_name, PATH_MAX);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name, except for
- * the array. */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_'
- && (field_name[0] != '\0'))) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- switch(td->type) {
- case ENUM:
- fprintf(fd, "enum lttng_%s", basename);
- fprintf(fd, " {\n");
- for(unsigned int i=0;i<td->labels.position;i++){
- print_tabs(1, fd);
- fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]),
- (*(int*)td->labels_values.array[i]));
- fprintf(fd, ",\n");
- }
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
- break;
-
- case ARRAY:
- dprintf("%s\n", basename);
- assert(td->size >= 0);
- if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
- /* Not a named nested type : we must print its declaration first */
- if(print_type_declaration(((field_t*)td->fields.array[0])->type,
- fd, 0, basename, "")) return 1;
- }
- fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename,
- td->size);
- fprintf(fd, "typedef ");
- if(print_type(((field_t*)td->fields.array[0])->type,
- fd, tabs, basename, "")) return 1;
- fprintf(fd, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename,
- basename);
- fprintf(fd, "\n");
- break;
- case SEQUENCE:
- /* We assume that the sequence length type does not need to be declared.
- */
- if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
- /* Not a named nested type : we must print its declaration first */
- if(print_type_declaration(((field_t*)td->fields.array[1])->type,
- fd, 0, basename, "")) return 1;
- }
- fprintf(fd, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
- basename,
- basename);
- fprintf(fd, "struct lttng_sequence_%s", basename);
- fprintf(fd, " {\n");
- print_tabs(1, fd);
- if(print_type(((field_t*)td->fields.array[0])->type,
- fd, tabs, basename, "")) return 1;
- fprintf(fd, " len;\n");
- print_tabs(1, fd);
- fprintf(fd, "const ");
- if(print_type(((field_t*)td->fields.array[1])->type,
- fd, tabs, basename, "")) return 1;
- fprintf(fd, " *array;\n");
- fprintf(fd, "};\n"); /* We do not LTT_ALIGN, because we never copy
- it to the buffer directly. */
- fprintf(fd, "\n");
- break;
-
- case STRUCT:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its declaration first */
- if(print_type_declaration(type,
- fd, 0, basename, field->name)) return 1;
- }
- }
- fprintf(fd, "struct lttng_%s", basename);
- fprintf(fd, " {\n");
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- print_tabs(1, fd);
- if(print_type(type, fd, tabs, basename, field->name)) return 1;
- fprintf(fd, " ");
- fprintf(fd, "%s", field->name);
- fprintf(fd, ";\n");
- }
- if(td->fac->align)
- fprintf(fd, "} LTT_ALIGN;\n");
- else
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
- break;
- case UNION:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its declaration first */
- if(print_type_declaration(type,
- fd, 0, basename, field->name)) return 1;
- }
- }
- fprintf(fd, "union lttng_%s", basename);
- fprintf(fd, " {\n");
- for(unsigned i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- print_tabs(1, fd);
- if(print_type(type, fd, tabs, basename, field->name)) return 1;
- fprintf(fd, " ");
- fprintf(fd, "%s", field->name);
- fprintf(fd, ";\n");
- }
- if(td->fac->align)
- fprintf(fd, "} LTT_ALIGN;\n");
- else
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
- break;
- default:
- dprintf("print_type_declaration : unknown type or nothing to declare.\n");
- break;
- }
-
- return 0;
-}
-
-
-/* print type alignment.
- *
- * Copied from construct_types_and_fields in LTTV facility.c
- *
- * basename is the name which identifies the type (along with a prefix
- * (possibly)). */
-
-int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name, char *obj_prefix)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- strncpy(basename, nest_name, PATH_MAX);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name, except for
- * the array. */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_'
- && field_name != NULL
- && (field_name[0] != '\0'))) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- if(field_name != NULL)
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- if(field_name[0] == '\0') {
- /* We are in a write function : it's the obj that we must align. */
- switch(td->type) {
- case SEQUENCE:
- fprintf(fd, "lttng_get_alignment_sequence_%s(%s)", basename,
- obj_prefix);
- break;
- case STRUCT:
- fprintf(fd, "lttng_get_alignment_struct_%s(%s)", basename,
- obj_prefix);
- break;
- case UNION:
- fprintf(fd, "lttng_get_alignment_union_%s(%s)", basename,
- obj_prefix);
- break;
- case ARRAY:
- fprintf(fd, "lttng_get_alignment_array_%s(%s)", basename,
- obj_prefix);
- case STRING:
- fprintf(fd, "sizeof(char)");
- break;
- case INT_FIXED:
- case UINT_FIXED:
- case CHAR:
- case UCHAR:
- case SHORT:
- case USHORT:
- case INT:
- case UINT:
- case FLOAT:
- case POINTER:
- case LONG:
- case ULONG:
- case SIZE_T:
- case SSIZE_T:
- case OFF_T:
- case ENUM:
- fprintf(fd, "sizeof(");
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, ")");
- break;
-
- default:
- printf("error : type unexpected\n");
- return 1;
- break;
- }
- } else {
-
- switch(td->type) {
- case INT_FIXED:
- case UINT_FIXED:
- case CHAR:
- case UCHAR:
- case SHORT:
- case USHORT:
- case INT:
- case UINT:
- case FLOAT:
- case POINTER:
- case LONG:
- case ULONG:
- case SIZE_T:
- case SSIZE_T:
- case OFF_T:
- case ENUM:
- fprintf(fd, "sizeof(");
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, ")");
- break;
- case STRING:
- fprintf(fd, "sizeof(char)");
- break;
- case SEQUENCE:
- fprintf(fd, "lttng_get_alignment_sequence_%s(&%s%s)", basename,
- obj_prefix, field_name);
- break;
- case STRUCT:
- fprintf(fd, "lttng_get_alignment_struct_%s(&%s%s)", basename,
- obj_prefix, field_name);
- break;
- case UNION:
- fprintf(fd, "lttng_get_alignment_union_%s(&%s%s)", basename,
- obj_prefix, field_name);
- break;
- case ARRAY:
- fprintf(fd, "lttng_get_alignment_array_%s(%s%s)", basename,
- obj_prefix, field_name);
- break;
- case NONE:
- printf("error : type NONE unexpected\n");
- return 1;
- break;
- }
- }
-
- return 0;
-}
-
-/* print type write.
- *
- * Copied from construct_types_and_fields in LTTV facility.c
- *
- * basename is the name which identifies the type (along with a prefix
- * (possibly)). */
-
-int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name, char *obj_prefix, int get_ptr)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
- char get_ptr_char[2] = "";
- char custom[PATH_MAX] = "";
-
- strncpy(basename, nest_name, PATH_MAX);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name, except for
- * the array. */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_'
- && (field_name[0] != '\0'))) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- if(get_ptr) {
- strcpy(get_ptr_char, "&");
- }
-
- if(td->custom_write) {
- strcpy(custom, "_custom");
- }
-
- switch(td->type) {
- case INT_FIXED:
- case UINT_FIXED:
- case CHAR:
- case UCHAR:
- case SHORT:
- case USHORT:
- case INT:
- case UINT:
- case FLOAT:
- case POINTER:
- case LONG:
- case ULONG:
- case SIZE_T:
- case SSIZE_T:
- case OFF_T:
- case ENUM:
- print_tabs(tabs, fd);
- fprintf(fd, "align = ");
- if(td->fac->align) {
- if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
- } else
- fprintf(fd, "0");
- fprintf(fd, ";\n");
- fprintf(fd, "\n");
- print_tabs(tabs, fd);
- fprintf(fd, "if (*len == 0) {\n");
- print_tabs(tabs+1, fd);
- fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
- print_tabs(tabs, fd);
- fprintf(fd, "} else {\n");
- print_tabs(tabs+1, fd);
- fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
- print_tabs(tabs, fd);
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
-
- print_tabs(tabs, fd);
- fprintf(fd, "*len += ");
- fprintf(fd, "sizeof(");
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, ");\n");
-
- break;
- case STRING:
- print_tabs(tabs, fd);
- fprintf(fd,
- "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n",
- custom, basename, obj_prefix, field_name);
- break;
- case SEQUENCE:
- print_tabs(tabs, fd);
- fprintf(fd,
- "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
- custom, basename, get_ptr_char, obj_prefix, field_name);
- break;
- case STRUCT:
- print_tabs(tabs, fd);
- fprintf(fd,
- "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
- custom, basename, get_ptr_char, obj_prefix, field_name);
- break;
- case UNION:
- print_tabs(tabs, fd);
- fprintf(fd,
- "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);",
- custom, basename, get_ptr_char, obj_prefix, field_name);
- break;
- case ARRAY:
- print_tabs(tabs, fd);
- fprintf(fd,
- "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);",
- custom, basename, obj_prefix, field_name);
- break;
- case NONE:
- printf("Error : type NONE unexpected\n");
- return 1;
- break;
- }
-
- return 0;
-}
-
-/* print need local vars ?.
- *
- * Copied from print_type_write
- *
- * Does the type_write call needs local size and from variables ?
- * return value : 1 yes, 0 no.
- */
-
-int has_type_local(type_descriptor_t * td)
-{
- switch(td->type) {
- case INT_FIXED:
- case UINT_FIXED:
- case CHAR:
- case UCHAR:
- case SHORT:
- case USHORT:
- case INT:
- case UINT:
- case FLOAT:
- case POINTER:
- case LONG:
- case ULONG:
- case SIZE_T:
- case SSIZE_T:
- case OFF_T:
- case ENUM:
- return 1;
- break;
- case STRING:
- case SEQUENCE:
- case STRUCT:
- case UNION:
- case ARRAY:
- return 0;
- break;
- case NONE:
- printf("Error : type NONE unexpected\n");
- return 1;
- break;
- }
-
- return 0;
-}
-
-
-
-/* print type alignment function.
- *
- * Copied from construct_types_and_fields in LTTV facility.c
- *
- * basename is the name which identifies the type (along with a prefix
- * (possibly)). */
-
-int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
- unsigned int tabs,
- char *nest_name, char *field_name)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- if(td->custom_write) return 0; /* Does print custom type */
- if(td->fac->align == 0) return 0;
-
- strncpy(basename, nest_name, PATH_MAX);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name, except for
- * the array. */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_'
- && (field_name[0] != '\0'))) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- switch(td->type) {
- case SEQUENCE:
- if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
- /* Not a named nested type : we must print its align fct */
- if(print_type_alignment_fct(((field_t*)td->fields.array[1])->type, fd,
- 0, basename, "")) return 1;
- }
- /* Function header */
- fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n",
- basename);
- print_tabs(2, fd);
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, " *obj)\n");
- fprintf(fd, "{\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t align=0, localign;");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "localign = ");
- if(print_type_alignment(((field_t*)td->fields.array[0])->type,
- fd, 0, basename, "len", "obj->")) return 1;
- fprintf(fd, ";\n");
- print_tabs(1, fd);
- fprintf(fd, "align = max(align, localign);\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "localign = ");
- if(print_type_alignment(((field_t*)td->fields.array[1])->type,
- fd, 0, basename, "array[0]", "obj->")) return 1;
- fprintf(fd, ";\n");
- print_tabs(1, fd);
- fprintf(fd, "align = max(align, localign);\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "return align;\n");
- break;
- case STRUCT:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its align fct */
- if(print_type_alignment_fct(type, fd,
- 0, basename, field->name)) return 1;
- }
- }
- /* Function header */
- fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n",
- basename);
- print_tabs(2, fd);
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, " *obj)\n");
- fprintf(fd, "{\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t align=0, localign;");
- fprintf(fd, "\n");
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- print_tabs(1, fd);
- fprintf(fd, "localign = ");
- if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
- return 1;
- fprintf(fd, ";\n");
- print_tabs(1, fd);
- fprintf(fd, "align = max(align, localign);\n");
- fprintf(fd, "\n");
- }
- print_tabs(1, fd);
- fprintf(fd, "return align;\n");
-
- break;
- case UNION:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its align fct */
- if(print_type_alignment_fct(type, fd,
- 0, basename, field->name)) return 1;
- }
- }
- /* Function header */
- fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n",
- basename);
- print_tabs(2, fd);
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, " *obj)\n");
- fprintf(fd, "{\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t align=0, localign;");
- fprintf(fd, "\n");
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- print_tabs(1, fd);
- fprintf(fd, "localign = ");
- if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
- return 1;
- fprintf(fd, ";\n");
- print_tabs(1, fd);
- fprintf(fd, "align = max(align, localign);\n");
- fprintf(fd, "\n");
- }
- print_tabs(1, fd);
- fprintf(fd, "return align;\n");
-
- break;
- case ARRAY:
- if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
- /* Not a named nested type : we must print its align fct */
- if(print_type_alignment_fct(((field_t*)td->fields.array[0])->type, fd,
- 0, basename, "")) return 1;
- }
- /* Function header */
- fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n",
- basename);
- print_tabs(2, fd);
- if(print_type(td, fd, 0, basename, "")) return 1;
- fprintf(fd, " obj)\n");
- fprintf(fd, "{\n");
- print_tabs(1, fd);
- fprintf(fd, "return \n");
- if(print_type_alignment(((field_t*)td->fields.array[0])->type,
- fd, 0, basename, "", "obj[0]"))
- return 1;
- fprintf(fd, ";\n");
- break;
- default:
- dprintf("print_type_alignment_fct : type has no alignment function.\n");
- return 0;
- break;
- }
-
-
- /* Function footer */
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
-
- return 0;
-}
-
-/* print type write function.
- *
- * Copied from construct_types_and_fields in LTTV facility.c
- *
- * basename is the name which identifies the type (along with a prefix
- * (possibly)). */
-
-int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
- char *nest_name, char *field_name)
-{
- char basename[PATH_MAX];
- unsigned int basename_len = 0;
-
- if(td->custom_write) return 0; /* Does print custom type */
-
- strncpy(basename, nest_name, PATH_MAX);
- basename_len = strlen(basename);
-
- /* For a named type, we use the type_name directly */
- if(td->type_name != NULL) {
- strncpy(basename, td->type_name, PATH_MAX);
- basename_len = strlen(basename);
- } else {
- /* For a unnamed type, there must be a field name, except for
- * the array. */
- if((basename_len != 0)
- && (basename[basename_len-1] != '_'
- && (field_name[0] != '\0'))) {
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len = strlen(basename);
- }
- strncat(basename, field_name, PATH_MAX - basename_len);
- }
-
- switch(td->type) {
- case SEQUENCE:
- if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
- /* Not a named nested type : we must print its write fct */
- if(print_type_write_fct(((field_t*)td->fields.array[1])->type, fd,
- 0, basename, "")) return 1;
- }
- break;
- case STRUCT:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its write fct */
- if(print_type_write_fct(type, fd,
- 0, basename, field->name)) return 1;
- }
- }
- break;
- case UNION:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(type->type_name == NULL) {
- /* Not a named nested type : we must print its write fct */
- if(print_type_write_fct(type, fd,
- 0, basename, field->name)) return 1;
- }
- }
- break;
- case ARRAY:
- if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
- /* Not a named nested type : we must print its write fct */
- if(print_type_write_fct(((field_t*)td->fields.array[0])->type, fd,
- 0, basename, "")) return 1;
- }
- break;
- case STRING:
- break;
- default:
- dprintf("print_type_write_fct : type has no write function.\n");
- return 0;
- break;
- }
-
- /* Print header */
- switch(td->type) {
- case SEQUENCE:
- fprintf(fd, "static inline void lttng_write_sequence_%s(\n",
- basename);
- break;
- case STRUCT:
- fprintf(fd, "static inline void lttng_write_struct_%s(\n", basename);
- break;
- case UNION:
- fprintf(fd, "static inline void lttng_write_union_%s(\n", basename);
- break;
- case ARRAY:
- fprintf(fd, "static inline void lttng_write_array_%s(\n", basename);
- break;
- case STRING:
- fprintf(fd, "static inline void lttng_write_string_%s(\n", basename);
- break;
- default:
- printf("print_type_write_fct : type has no write function.\n");
- break;
- }
-
- print_tabs(2, fd);
- fprintf(fd, "char *buffer,\n");
- print_tabs(2, fd);
- fprintf(fd, "size_t *to_base,\n");
- print_tabs(2, fd);
- fprintf(fd, "size_t *to,\n");
- print_tabs(2, fd);
- fprintf(fd, "const char **from,\n");
- print_tabs(2, fd);
- fprintf(fd, "size_t *len,\n");
- print_tabs(2, fd);
- if(print_type(td, fd, 0, basename, "")) return 1;
-
- switch(td->type) {
- case SEQUENCE:
- fprintf(fd, " *obj)\n");
- break;
- case STRUCT:
- fprintf(fd, " *obj)\n");
- break;
- case UNION:
- fprintf(fd, " *obj)\n");
- break;
- case ARRAY:
- fprintf(fd, " obj)\n");
- break;
- case STRING:
- fprintf(fd, " obj)\n");
- break;
- default:
- printf("print_type_write_fct : type has no write function.\n");
- break;
- }
-
- fprintf(fd, "{\n");
-
- switch(td->type) {
- case STRING:
- print_tabs(1, fd);
- fprintf(fd, "size_t size;\n");
- break;
- default:
- break;
- }
-
- print_tabs(1, fd);
- fprintf(fd, "size_t align;\n");
- fprintf(fd, "\n");
-
- switch(td->type) {
- case SEQUENCE:
- case STRING:
- print_tabs(1, fd);
- fprintf(fd, "/* Flush pending memcpy */\n");
- print_tabs(1, fd);
- fprintf(fd, "if (*len != 0) {\n");
- print_tabs(2, fd);
- fprintf(fd, "if (buffer != NULL)\n");
- print_tabs(3, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
- print_tabs(1, fd);
- fprintf(fd, "}\n");
- print_tabs(1, fd);
- fprintf(fd, "*to += *len;\n");
- print_tabs(1, fd);
- fprintf(fd, "*len = 0;\n");
- fprintf(fd, "\n");
- break;
- case STRUCT:
- case UNION:
- case ARRAY:
- break;
- default:
- printf("print_type_write_fct : type has no write function.\n");
- break;
- }
-
- print_tabs(1, fd);
- fprintf(fd, "align = ");
- if(td->fac->align) {
- if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
- } else
- fprintf(fd, "0");
- fprintf(fd, ";\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "if (*len == 0) {\n");
- print_tabs(2, fd);
- fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
- print_tabs(1, fd);
- fprintf(fd, "} else {\n");
- print_tabs(2, fd);
- fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
- print_tabs(1, fd);
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
-
- /* First, check if the type has a fixed size. If it is the case, then the size
- * to write is know by the compiler : simply use a sizeof() */
- if(has_type_fixed_size(td)) {
- print_tabs(1, fd);
- fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "*len += sizeof(");
- if(print_type(td, fd, 0, basename, field_name)) return 1;
- fprintf(fd, ");\n");
- } else {
- /* The type contains nested variable size subtypes :
- * we must write field by field. */
- print_tabs(1, fd);
- fprintf(fd, "/* Contains variable sized fields : must explode the structure */\n");
- fprintf(fd, "\n");
-
- switch(td->type) {
- case SEQUENCE:
- print_tabs(1, fd);
- fprintf(fd, "/* Copy members */\n");
-// print_tabs(1, fd);
-// fprintf(fd, "size = sizeof(\n");
- if(print_type_write(((field_t*)td->fields.array[0])->type,
- fd, 1, basename, "len", "obj->", 1)) return 1;
- fprintf(fd, "\n");
-// fprintf(fd, ");\n");
-// print_tabs(1, fd);
-// fprintf(fd, "*to += ltt_align(*to, size);\n");
- print_tabs(1, fd);
- fprintf(fd, "if (buffer != NULL)\n");
- print_tabs(2, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
- print_tabs(1, fd);
- fprintf(fd, "*to += *len;\n");
- print_tabs(1, fd);
- fprintf(fd, "*len = 0;\n");
- fprintf(fd, "\n");
-
- /* Write the child : varlen child or not ? */
- if(has_type_fixed_size(((field_t*)td->fields.array[1])->type)) {
- /* Fixed size len child : use a multiplication of its size */
-// print_tabs(1, fd);
-// fprintf(fd, "size = sizeof(\n");
-
- //print_tabs(1, fd);
- /* We know that *len does not contain alignment because of the
- * previous align output. len is always 0 here. */
- if(print_type_write(((field_t*)td->fields.array[1])->type,
- fd, 1, basename, "array[0]", "obj->", 1))
- return 1;
-// fprintf(fd, ");\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "*len = obj->len * (*len);\n");
- print_tabs(1, fd);
- fprintf(fd, "if (buffer != NULL)\n");
- print_tabs(2, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
- print_tabs(1, fd);
- fprintf(fd, "*to += *len;\n");
- print_tabs(1, fd);
- fprintf(fd, "*len = 0;\n");
- fprintf(fd, "\n");
- } else {
- print_tabs(1, fd);
- fprintf(fd, "/* Variable length child : iter. */\n");
- print_tabs(1, fd);
- fprintf(fd, "for (unsigned int i = 0; i < obj->len; i++) {\n");
- if(print_type_write(((field_t*)td->fields.array[1])->type,
- fd, 2, basename, "array[i]", "obj->", 1)) return 1;
- print_tabs(1, fd);
- fprintf(fd, "}\n");
- }
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
- print_tabs(1, fd);
- if(td->fac->align)
- fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
- print_tabs(1, fd);
- fprintf(fd, "*to_base = *to_base+*to;\n");
- print_tabs(1, fd);
- fprintf(fd, "*to = 0;\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Put source *from just after the C sequence */\n");
- print_tabs(1, fd);
- fprintf(fd, "*from = (const char*)(obj+1);\n");
- break;
- case STRING:
- print_tabs(1, fd);
- fprintf(fd, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
- print_tabs(1, fd);
- fprintf(fd, "if (buffer != NULL)\n");
- print_tabs(2, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, obj, size);\n");
- print_tabs(1, fd);
- fprintf(fd, "*to += size;\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
- print_tabs(1, fd);
- if(td->fac->align)
- fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
- print_tabs(1, fd);
- fprintf(fd, "*to_base = *to_base+*to;\n");
- print_tabs(1, fd);
- fprintf(fd, "*to = 0;\n");
- fprintf(fd, "\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Put source *from just after the C string */\n");
- print_tabs(1, fd);
- fprintf(fd, "*from += size;\n");
- break;
- case STRUCT:
- for(unsigned int i=0;i<td->fields.position;i++){
- field_t *field = (field_t*)(td->fields.array[i]);
- type_descriptor_t *type = field->type;
- if(print_type_write(type,
- fd, 1, basename, field->name, "obj->", 1)) return 1;
- fprintf(fd, "\n");
- }
- break;
- case UNION:
- printf("ERROR : A union CANNOT contain a variable size child.\n");
- return 1;
- break;
- case ARRAY:
- /* Write the child : varlen child or not ? */
- if(has_type_fixed_size(((field_t*)td->fields.array[0])->type)) {
- /* Error : if an array has a variable size, then its child must also
- * have a variable size. */
- assert(0);
- } else {
- print_tabs(1, fd);
- fprintf(fd, "/* Variable length child : iter. */\n");
- print_tabs(1, fd);
- fprintf(fd, "for (unsigned int i = 0; i < LTTNG_ARRAY_SIZE_%s; i++) {\n", basename);
- if(print_type_write(((field_t*)td->fields.array[0])->type,
- fd, 2, basename, "", "obj->array[i]", 1)) return 1;
- print_tabs(1, fd);
- fprintf(fd, "}\n");
- }
- break;
- default:
- printf("print_type_write_fct : type has no write function.\n");
- break;
- }
-
-
- }
-
-
- /* Function footer */
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
- return 0;
-}
-
-
-
-/* Print the logging function of an event. This is the core of genevent */
-int print_event_logging_function(char *basename, facility_t *fac,
- event_t *event, FILE *fd)
-{
- fprintf(fd, "static inline void trace_%s(\n", basename);
- int has_argument = 0;
- int has_type_fixed = 0;
-
- /* Does it support per trace tracing ? */
- if(event->per_trace) {
- print_tabs(2, fd);
- fprintf(fd, "struct ltt_trace_struct *dest_trace");
- has_argument = 1;
- }
-
- /* Does it support per tracefile tracing ? */
- if(event->per_tracefile) {
- if(has_argument) {
- fprintf(fd, ",");
- fprintf(fd, "\n");
- }
- fprintf(fd, "unsigned int tracefile_index");
- has_argument = 1;
- }
-
- for(unsigned int j = 0; j < event->fields.position; j++) {
- /* For each field, print the function argument */
- field_t *f = (field_t*)event->fields.array[j];
- type_descriptor_t *t = f->type;
- if(has_argument) {
- fprintf(fd, ",");
- fprintf(fd, "\n");
- }
- if(print_arg(t, fd, 2, basename, f->name)) return 1;
- has_argument = 1;
- }
- if(!has_argument) {
- print_tabs(2, fd);
- fprintf(fd, "void");
- }
- fprintf(fd,")\n");
-#if 0
- fprintf(fd,
- "#if (!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n",
- fac->capname, fac->capname);
- fprintf(fd, "{\n");
- fprintf(fd, "}\n");
- fprintf(fd,"#else\n");
-#endif //0
- fprintf(fd, "{\n");
- /* Print the function variables */
- print_tabs(1, fd);
- fprintf(fd, "unsigned int index;\n");
- print_tabs(1, fd);
- fprintf(fd, "struct ltt_channel_struct *channel;\n");
- print_tabs(1, fd);
- fprintf(fd, "struct ltt_trace_struct *trace;\n");
- print_tabs(1, fd);
- fprintf(fd, "void *transport_data;\n");
- print_tabs(1, fd);
- fprintf(fd, "char *buffer = NULL;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to_base = &real_to_base;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to = &real_to;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_len = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *len = &real_len;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t reserve_size;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t slot_size;\n");
- print_tabs(1, fd);
-
- if(event->fields.position > 0) {
- for(unsigned int i=0;i<event->fields.position;i++){
- /* Search for at least one child with fixed size. It means
- * we need local variables.*/
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- has_type_fixed = has_type_local(type);
- if(has_type_fixed) break;
- }
-
- if(has_type_fixed) {
- fprintf(fd, "size_t align;\n");
- print_tabs(1, fd);
- }
-
- fprintf(fd, "const char *real_from;\n");
- print_tabs(1, fd);
- fprintf(fd, "const char **from = &real_from;\n");
- print_tabs(1, fd);
- }
- fprintf(fd, "u64 tsc;\n");
- fprintf(fd, "\n");
-
- if(!event->force) {
- print_tabs(1, fd);
- fprintf(fd, "if (ltt_traces.num_active_traces == 0)\n");
- print_tabs(2, fd);
- fprintf(fd, "return;\n");
- fprintf(fd, "\n");
- }
-
- /* Calculate event variable len + event data alignment offset.
- * Assume that the padding for alignment starts at a void*
- * address.
- * This excludes the header size and alignment. */
-
- print_tabs(1, fd);
- fprintf(fd, "/* For each field, calculate the field size. */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* size = *to_base + *to + *len */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
- print_tabs(1, fd);
- fprintf(fd, " * sizeof(void *) address. */\n");
- fprintf(fd, "\n");
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- /* Set from */
- print_tabs(1, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
- if(print_type_write(type,
- fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
- }
- print_tabs(1, fd);
- fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
-
- /* Take locks : make sure the trace does not vanish while we write on
- * it. A simple preemption disabling is enough (using rcu traces). */
- print_tabs(1, fd);
- fprintf(fd, "preempt_disable();\n");
- print_tabs(1, fd);
- fprintf(fd, "ltt_nesting[smp_processor_id()]++;\n");
-
- /* Get facility index */
-
- if(event->per_tracefile) {
- print_tabs(1, fd);
- fprintf(fd, "index = tracefile_index;\n");
- } else {
- print_tabs(1, fd);
- fprintf(fd,
- "index = ltt_get_index_from_facility_%s(" \
- "\t\t\t\t\t\tevent_%s_%s);\n",
- fac->name, fac->name, event->name);
- }
- fprintf(fd,"\n");
-
-
- /* For each trace */
- print_tabs(1, fd);
- fprintf(fd, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
- if(!event->force) {
- print_tabs(2, fd);
- fprintf(fd, "if (!trace->active)\n");
- print_tabs(3, fd);
- fprintf(fd, "continue;\n\n");
- }
-
- if(event->per_trace) {
- print_tabs(2, fd);
- fprintf(fd, "if (dest_trace != trace)\n");
- print_tabs(3, fd);
- fprintf(fd, "continue;\n\n");
- }
-
- print_tabs(2, fd);
- fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n");
- fprintf(fd, "\n");
-
-
- /* Relay reserve */
- /* If error, increment event lost counter (done by ltt_reserve_slot) and
- * return */
- print_tabs(2, fd);
- fprintf(fd, "slot_size = 0;\n");
- print_tabs(2, fd);
- fprintf(fd, "buffer = ltt_reserve_slot(trace, channel, &transport_data,\n");
- print_tabs(3, fd);
- fprintf(fd, "reserve_size, &slot_size, &tsc);\n");
- /* If error, return */
- print_tabs(2, fd);
- fprintf(fd, "if (!buffer)\n");
- print_tabs(3, fd);
- fprintf(fd, "continue; /* buffer full */\n\n");
- //print_tabs(2, fd);
- // for DEBUG only
- // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
- print_tabs(2, fd);
- fprintf(fd, "*to_base = *to = *len = 0;\n");
- fprintf(fd, "\n");
-
- /* Write event header */
- if(strcmp("compact", fac->name) != 0) {
- print_tabs(2, fd);
- fprintf(fd, "buffer = ltt_write_event_header(trace, channel, buffer,\n");
- print_tabs(3, fd);
- fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
- fac->name, event->name);
- print_tabs(3, fd);
- fprintf(fd, "reserve_size, tsc);\n");
- } else {
- print_tabs(2, fd);
- fprintf(fd, "buffer = ltt_write_compact_header(trace, channel, buffer,\n");
- print_tabs(3, fd);
- fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
- fac->name, event->name);
- print_tabs(3, fd);
- if(event->compact_data) {
- assert(event->fields.position > 0);
- field_t *field = (field_t*)(event->fields.array[0]);
- fprintf(fd, "reserve_size, tsc, lttng_param_%s);\n",
- field->name);
- } else
- fprintf(fd, "reserve_size, tsc, 0);\n");
- }
-
- /* write data. */
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
-
- /* First param is compacted in the header */
- if(event->compact_data && i == 0)
- continue;
- /* Set from */
- print_tabs(2, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
-
- if(print_type_write(type,
- fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
-
- /* Don't forget to flush pending memcpy */
- print_tabs(2, fd);
- fprintf(fd, "/* Flush pending memcpy */\n");
- print_tabs(2, fd);
- fprintf(fd, "if (*len != 0) {\n");
- print_tabs(3, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
- print_tabs(3, fd);
- fprintf(fd, "*to += *len;\n");
- //print_tabs(3, fd);
- //fprintf(fd, "from += len;\n");
- print_tabs(3, fd);
- fprintf(fd, "*len = 0;\n");
- print_tabs(2, fd);
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
- }
-
-
- /* commit */
- // for DEBUG only.
- //fprintf(fd, "commit:\n"); /* DEBUG! */
- print_tabs(2, fd);
- fprintf(fd, "ltt_commit_slot(channel, &transport_data, buffer, slot_size);\n\n");
-
- print_tabs(1, fd);
- fprintf(fd, "}\n\n");
-
- /* Release locks */
- print_tabs(1, fd);
- fprintf(fd, "ltt_nesting[smp_processor_id()]--;\n");
- print_tabs(1, fd);
- fprintf(fd, "preempt_enable();\n");
-
- fprintf(fd, "}\n");
-#if 0
- fprintf(fd, "#endif //(!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n\n",
- fac->capname, fac->capname);
-#endif //0
- return 0;
-}
-
-int print_event_logging_function_header_user_generic(char *basename, facility_t *fac,
- event_t *event, FILE *fd, enum user_fct_types fct_type)
-{
- char *attrib;
-
- if(event->no_instrument_function && fct_type == USER_FCT_PROTO) {
- attrib = "__attribute__((no_instrument_function)) ";
- } else {
- attrib = "";
- }
- if(event->param_buffer) {
- fprintf(fd, "static inline %sint trace_%s_param_buffer(\n", attrib, basename);
- } else {
- fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
- }
- int has_argument = 0;
-
- if(event->param_buffer) {
- if(has_argument) {
- fprintf(fd, ",");
- fprintf(fd, "\n");
- }
- print_tabs(2, fd);
- fprintf(fd, "char *buffer");
- has_argument = 1;
- fprintf(fd, ",");
- fprintf(fd, "\n");
- print_tabs(2, fd);
- fprintf(fd, "size_t reserve_size");
- } else {
- for(unsigned int j = 0; j < event->fields.position; j++) {
- /* For each field, print the function argument */
- field_t *f = (field_t*)event->fields.array[j];
- type_descriptor_t *t = f->type;
- if(has_argument) {
- fprintf(fd, ",");
- fprintf(fd, "\n");
- }
- if(print_arg(t, fd, 2, basename, f->name)) return 1;
- has_argument = 1;
- }
- }
- if(!has_argument) {
- print_tabs(2, fd);
- fprintf(fd, "void");
- }
- fprintf(fd,")");
- return 0;
-}
-
-
-/* print_event_logging_function_user_generic
- * Print the logging function of an event for userspace tracing. This is the
- * core of genevent */
-int print_event_logging_function_user_generic(char *basename, facility_t *fac,
- event_t *event, FILE *fd)
-{
- int has_type_fixed = 0;
-
- if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_PROTO)) return 1;
- fprintf(fd,";\n");
- fprintf(fd,"\n");
- fprintf(fd, "#ifndef LTT_TRACE_FAST\n");
- if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_DECLARATION)) return 1;
- fprintf(fd,"\n");
- fprintf(fd,
- "#ifndef LTT_TRACE\n");
- fprintf(fd, "{\n");
- fprintf(fd, "}\n");
- fprintf(fd,"#else\n");
- fprintf(fd, "{\n");
- /* Print the function variables */
- print_tabs(1, fd);
- fprintf(fd, "int ret = 0;\n");
- if(event->param_buffer) {
- //FIX print_tabs(1, fd);
- //fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
- print_tabs(1, fd);
- fprintf(fd, "{\n");
- goto do_syscall;
- }
- print_tabs(1, fd);
- fprintf(fd, "char *buffer = NULL;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to_base = &real_to_base;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to = &real_to;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_len = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *len = &real_len;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t reserve_size;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t slot_size;\n");
- print_tabs(1, fd);
-
- if(event->fields.position > 0) {
- for(unsigned int i=0;i<event->fields.position;i++){
- /* Search for at least one child with fixed size. It means
- * we need local variables.*/
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- has_type_fixed = has_type_local(type);
- if(has_type_fixed) break;
- }
-
- if(has_type_fixed) {
- fprintf(fd, "size_t align;\n");
- print_tabs(1, fd);
- }
-
- fprintf(fd, "const char *real_from;\n");
- print_tabs(1, fd);
- fprintf(fd, "const char **from = &real_from;\n");
- print_tabs(1, fd);
- }
-
- /* Calculate event variable len + event data alignment offset.
- * Assume that the padding for alignment starts at a void*
- * address.
- * This excludes the header size and alignment. */
-
- print_tabs(1, fd);
- fprintf(fd, "/* For each field, calculate the field size. */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* size = *to_base + *to + *len */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
- print_tabs(1, fd);
- fprintf(fd, " * sizeof(void *) address. */\n");
- fprintf(fd, "\n");
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- /* Set from */
- print_tabs(1, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
- if(print_type_write(type,
- fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
- }
- print_tabs(1, fd);
- fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
-
- print_tabs(1, fd);
- fprintf(fd, "{\n");
- print_tabs(2, fd);
- fprintf(fd, "char stack_buffer[reserve_size];\n");
- print_tabs(2, fd);
- fprintf(fd, "buffer = stack_buffer;\n");
- fprintf(fd, "\n");
-
-
- //print_tabs(2, fd);
- // for DEBUG only
- // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
- print_tabs(2, fd);
- fprintf(fd, "*to_base = *to = *len = 0;\n");
- fprintf(fd, "\n");
-
- /* write data. */
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
-
- /* Set from */
- print_tabs(2, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
-
- if(print_type_write(type,
- fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
-
- /* Don't forget to flush pending memcpy */
- print_tabs(2, fd);
- fprintf(fd, "/* Flush pending memcpy */\n");
- print_tabs(2, fd);
- fprintf(fd, "if (*len != 0) {\n");
- print_tabs(3, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
- print_tabs(3, fd);
- fprintf(fd, "*to += *len;\n");
- //print_tabs(3, fd);
- //fprintf(fd, "from += len;\n");
- print_tabs(3, fd);
- fprintf(fd, "*len = 0;\n");
- print_tabs(2, fd);
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
- }
-
-do_syscall:
- print_tabs(2, fd);
- fprintf(fd, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING, %u);\n", fac->name, fac->checksum, fac->name, event->name, event->high_priority);
-
- print_tabs(1, fd);
- fprintf(fd, "}\n\n");
-
- print_tabs(1, fd);
- fprintf(fd, "return ret;\n\n");
-
- fprintf(fd, "}\n");
- fprintf(fd,
- "#endif //LTT_TRACE\n");
- fprintf(fd, "#endif //!LTT_TRACE_FAST\n\n");
-
- return 0;
-}
-
-/* print_event_logging_function_user_fast
- * Print the logging function of an event for userspace tracing. This is the
- * core of genevent */
-int print_event_logging_function_user_fast(char *basename, facility_t *fac,
- event_t *event, FILE *fd)
-{
- char *attrib;
-
- fprintf(fd, "#ifdef LTT_TRACE_FAST\n");
-
- if(event->no_instrument_function) {
- attrib = "__attribute__((no_instrument_function)) ";
- } else {
- attrib = "";
- }
- fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
-
- int has_argument = 0;
- int has_type_fixed = 0;
-
- for(unsigned int j = 0; j < event->fields.position; j++) {
- /* For each field, print the function argument */
- field_t *f = (field_t*)event->fields.array[j];
- type_descriptor_t *t = f->type;
- if(has_argument) {
- fprintf(fd, ",");
- fprintf(fd, "\n");
- }
- if(print_arg(t, fd, 2, basename, f->name)) return 1;
- has_argument = 1;
- }
- if(!has_argument) {
- print_tabs(2, fd);
- fprintf(fd, "void");
- }
- fprintf(fd,")\n");
- fprintf(fd,
- "#ifndef LTT_TRACE\n");
- fprintf(fd, "{\n");
- fprintf(fd, "}\n");
- fprintf(fd,"#else\n");
- fprintf(fd, "{\n");
- /* Print the function variables */
- print_tabs(1, fd);
- fprintf(fd, "unsigned int index;\n");
- print_tabs(1, fd);
- fprintf(fd, "struct ltt_trace_info *trace = thread_trace_info;\n");
- print_tabs(1, fd);
- fprintf(fd, "struct ltt_buf *ltt_buf;\n");
- print_tabs(1, fd);
- fprintf(fd, "char *buffer = NULL;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to_base = &real_to_base;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_to = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *to = &real_to;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t real_len = 0;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t *len = &real_len;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t reserve_size;\n");
- print_tabs(1, fd);
- fprintf(fd, "size_t slot_size;\n");
- print_tabs(1, fd);
-
- if(event->fields.position > 0) {
- for(unsigned int i=0;i<event->fields.position;i++){
- /* Search for at least one child with fixed size. It means
- * we need local variables.*/
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- has_type_fixed = has_type_local(type);
- if(has_type_fixed) break;
- }
-
- if(has_type_fixed) {
- fprintf(fd, "size_t align;\n");
- print_tabs(1, fd);
- }
-
- fprintf(fd, "const char *real_from;\n");
- print_tabs(1, fd);
- fprintf(fd, "const char **from = &real_from;\n");
- print_tabs(1, fd);
- }
- fprintf(fd, "uint64_t tsc;\n");
- print_tabs(1, fd);
-
- print_tabs(1, fd);
- fprintf(fd, "if (!trace) {\n");
- print_tabs(2, fd);
- fprintf(fd, "ltt_thread_init();\n");
- print_tabs(2, fd);
- fprintf(fd, "trace = thread_trace_info;\n");
- print_tabs(1, fd);
- fprintf(fd, "}\n\n");
- fprintf(fd, "\n");
-
- /* Calculate event variable len + event data alignment offset.
- * Assume that the padding for alignment starts at a void*
- * address.
- * This excludes the header size and alignment. */
-
- print_tabs(1, fd);
- fprintf(fd, "/* For each field, calculate the field size. */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* size = *to_base + *to + *len */\n");
- print_tabs(1, fd);
- fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
- print_tabs(1, fd);
- fprintf(fd, " * sizeof(void *) address. */\n");
- fprintf(fd, "\n");
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
- /* Set from */
- print_tabs(1, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
- if(print_type_write(type,
- fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
- }
- print_tabs(1, fd);
- fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
-
- print_tabs(1, fd);
- fprintf(fd, "trace->nesting++;\n");
-
- /* Get facility index */
-
- print_tabs(1, fd);
- fprintf(fd,
- "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
- "\t\t\t\t\t\tevent_%s_%s);\n",
- fac->name, fac->checksum, fac->name, event->name);
- fprintf(fd,"\n");
-
-
- print_tabs(1, fd);
- fprintf(fd, "{\n");
-
- if(event->per_trace) {
- print_tabs(2, fd);
- fprintf(fd, "if (dest_trace != trace) continue;\n\n");
- }
-
- print_tabs(2, fd);
- fprintf(fd, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
- print_tabs(2, fd);
-
-
- /* Relay reserve */
- /* If error, increment event lost counter (done by ltt_reserve_slot) and
- * return */
- print_tabs(2, fd);
- fprintf(fd, "slot_size = 0;\n");
- print_tabs(2, fd);
- fprintf(fd, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
- print_tabs(3, fd);
- fprintf(fd, "reserve_size, &slot_size, &tsc);\n");
- /* If error, return */
- print_tabs(2, fd);
- fprintf(fd, "if (!buffer)\n");
- print_tabs(3, fd);
- fprintf(fd, "goto end; /* buffer full */\n\n");
- //print_tabs(2, fd);
- // for DEBUG only
- // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
- print_tabs(2, fd);
- fprintf(fd, "*to_base = *to = *len = 0;\n");
- fprintf(fd, "\n");
-
- /* Write event header */
- print_tabs(2, fd);
- fprintf(fd, "buffer = ltt_write_event_header(trace, ltt_buf, buffer,\n");
- print_tabs(3, fd);
- fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
- fac->name, event->name);
- print_tabs(3, fd);
- fprintf(fd, "reserve_size, tsc);\n");
-
- /* write data. */
-
- for(unsigned int i=0;i<event->fields.position;i++){
- field_t *field = (field_t*)(event->fields.array[i]);
- type_descriptor_t *type = field->type;
-
- /* Set from */
- print_tabs(2, fd);
- switch(type->type) {
- case SEQUENCE:
- case UNION:
- case ARRAY:
- case STRUCT:
- case STRING:
- fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
- break;
- default:
- fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
- break;
- }
-
-
- if(print_type_write(type,
- fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
- fprintf(fd, "\n");
-
- /* Don't forget to flush pending memcpy */
- print_tabs(2, fd);
- fprintf(fd, "/* Flush pending memcpy */\n");
- print_tabs(2, fd);
- fprintf(fd, "if (*len != 0) {\n");
- print_tabs(3, fd);
- fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
- print_tabs(3, fd);
- fprintf(fd, "*to += *len;\n");
- //print_tabs(3, fd);
- //fprintf(fd, "from += len;\n");
- print_tabs(3, fd);
- fprintf(fd, "*len = 0;\n");
- print_tabs(2, fd);
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
- }
-
-
- /* commit */
- // for DEBUG only.
- //fprintf(fd, "commit:\n"); /* DEBUG! */
- print_tabs(2, fd);
- fprintf(fd, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
-
- fprintf(fd, "}\n\n");
-
- fprintf(fd, "end:\n");
- /* Release locks */
- print_tabs(1, fd);
- fprintf(fd, "trace->nesting--;\n");
-
-
- fprintf(fd, "}\n");
- fprintf(fd,
- "#endif //LTT_TRACE\n");
- fprintf(fd, "#endif //LTT_TRACE_FAST\n");
-
- return 0;
-}
-
-
-
-
-
-
-/* ltt-facility-name.h : main logging header.
- * log_header */
-
-void print_log_header_head(facility_t *fac, FILE *fd)
-{
- fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
- fprintf(fd, "#include <linux/types.h>\n");
- if(!fac->arch)
- fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name);
- else
- fprintf(fd, "#include <ltt/ltt-facility-id-%s_%s.h>\n",
- fac->name,
- fac->arch);
- fprintf(fd, "#include <ltt/ltt-tracer.h>\n");
- fprintf(fd, "\n");
-}
-
-/* ltt-facility-name.h : main logging header.
- * log_header */
-
-void print_log_header_head_user(facility_t *fac, FILE *fd)
-{
- fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
- fprintf(fd, "#include <sys/types.h>\n");
- if(!fac->arch)
- fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name);
- else
- fprintf(fd, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
- fac->name,
- fac->arch);
- fprintf(fd, "#include <ltt/ltt-usertrace.h>\n");
- fprintf(fd, "\n");
- fprintf(fd, "#ifdef __cplusplus\n");
- fprintf(fd, "extern \"C\" {\n");
- fprintf(fd, "#endif\n");
- fprintf(fd, "\n");
-}
-
-
-int print_log_header_types(facility_t *fac, FILE *fd)
-{
- sequence_t *types = &fac->named_types.values;
- fprintf(fd, "/* Named types */\n");
- fprintf(fd, "\n");
-
- for(unsigned int i = 0; i < types->position; i++) {
- /* For each named type, print the definition */
- if(print_type_declaration(types->array[i], fd,
- 0, "", "")) return 1;
- /* Print also the align function */
- if(((type_descriptor_t*)types->array[i])->fac->align)
- if(print_type_alignment_fct(types->array[i], fd,
- 0, "", "")) return 1;
- /* Print also the write function */
- if(print_type_write_fct(types->array[i], fd,
- 0, "", "")) return 1;
- }
- return 0;
-}
-
-int print_log_header_events(facility_t *fac, FILE *fd)
-{
- sequence_t *events = &fac->events;
- char basename[PATH_MAX];
- unsigned int facname_len;
-
- strncpy(basename, fac->name, PATH_MAX);
- facname_len = strlen(basename);
- strncat(basename, "_", PATH_MAX-facname_len);
- facname_len = strlen(basename);
-
- for(unsigned int i = 0; i < events->position; i++) {
- event_t *event = (event_t*)events->array[i];
- strncpy(&basename[facname_len], event->name, PATH_MAX-facname_len);
-
- /* For each event, print structure, and then logging function */
- fprintf(fd, "/* Event %s structures */\n",
- event->name);
- for(unsigned int j = 0; j < event->fields.position; j++) {
- /* For each unnamed type, print the definition */
- field_t *f = (field_t*)event->fields.array[j];
- type_descriptor_t *t = f->type;
- if(t->type_name == NULL) {
- if((print_type_declaration(t, fd, 0, basename, f->name))) return 1;
- /* Print also the align function */
- if(fac->align) {
- if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1;
- }
- /* Print also the write function */
- if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1;
- }
- }
-
- fprintf(fd, "\n");
-
- fprintf(fd, "/* Event %s logging function */\n",
- event->name);
-
- if(!fac->user) {
- if(print_event_logging_function(basename, fac, event, fd)) return 1;
- } else {
- if(print_event_logging_function_user_generic(basename, fac, event, fd))
- return 1;
- if(print_event_logging_function_user_fast(basename, fac, event, fd))
- return 1;
- }
-
- fprintf(fd, "\n");
- }
-
- return 0;
-}
-
-
-void print_log_header_tail(facility_t *fac, FILE *fd)
-{
- fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
-}
-
-void print_log_header_tail_user(facility_t *fac, FILE *fd)
-{
- fprintf(fd, "#ifdef __cplusplus\n");
- fprintf(fd, "} /* end of extern \"C\" */\n");
- fprintf(fd, "#endif\n");
- fprintf(fd, "\n");
- fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
-}
-
-int print_log_header(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".h", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- /* Print file head */
- if(!fac->user)
- print_log_header_head(fac, fd);
- else
- print_log_header_head_user(fac, fd);
-
- /* print named types in declaration order */
- if(print_log_header_types(fac, fd)) return 1;
-
- /* Print events */
- if(print_log_header_events(fac, fd)) return 1;
-
- /* Print file tail */
- if(!fac->user)
- print_log_header_tail(fac, fd);
- else
- print_log_header_tail_user(fac, fd);
-
-
-
- fclose(fd);
-
- return 0;
-}
-
-
-/* ltt-facility-id-name.h : facility id.
- * log_id_header */
-int print_id_header(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- char basename[PATH_MAX];
- char basename_len = 0;
-
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-id-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".h", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- if(!fac->user) {
- fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
- fprintf(fd, "#ifdef CONFIG_LTT\n");
-
- fprintf(fd,"#include <linux/ltt-facilities.h>\n\n");
-
- fprintf(fd,"/**** facility handle ****/\n\n");
- fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
- fac->name, fac->checksum);
- fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
-
- strncpy(basename, fac->name, PATH_MAX);
- basename_len = strlen(basename);
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len++;
-
- fprintf(fd,"/**** event index ****/\n\n");
- fprintf(fd,"enum %s_event {\n",fac->name);
-
- for(unsigned int i = 0; i < fac->events.position; i++) {
- event_t *event = (event_t*)fac->events.array[i];
- strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
- print_tabs(1, fd);
- fprintf(fd, "event_%s,\n", basename);
- }
- print_tabs(1, fd);
- fprintf(fd, "facility_%s_num_events\n", fac->name);
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
-
-
- fprintf(fd, "#endif //CONFIG_LTT\n");
- fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
- } else {
- fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
- fprintf(fd, "#ifdef LTT_TRACE\n");
-
- fprintf(fd,"#include <ltt/ltt-usertrace.h>\n\n");
-
- fprintf(fd,"/**** facility handle ****/\n\n");
- fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
- fac->name, fac->checksum);
- fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
-
- strncpy(basename, fac->name, PATH_MAX);
- basename_len = strlen(basename);
- strncat(basename, "_", PATH_MAX - basename_len);
- basename_len++;
-
- fprintf(fd,"/**** event index ****/\n\n");
- fprintf(fd,"enum %s_event {\n",fac->name);
-
- for(unsigned int i = 0; i < fac->events.position; i++) {
- event_t *event = (event_t*)fac->events.array[i];
- strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
- print_tabs(1, fd);
- fprintf(fd, "event_%s,\n", basename);
- }
- print_tabs(1, fd);
- fprintf(fd, "facility_%s_num_events\n", fac->name);
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
-
-
- fprintf(fd, "#endif //LTT_TRACE\n");
- fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
- }
-
-
- fclose(fd);
-
- return 0;
-}
-
-
-/* ltt-facility-loader-name.h : facility specific loader info.
- * loader_header */
-int print_loader_header(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-loader-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".h", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
- fprintf(fd, "#ifdef CONFIG_LTT\n\n");
- fprintf(fd,"#include <linux/ltt-facilities.h>\n");
- if(!fac->arch)
- fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n",
- fac->name);
- else
- fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
- fac->name,
- fac->arch);
- fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
- fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
- fac->name, fac->checksum);
- fprintf(fd,"extern unsigned int ltt_get_channel_index_%s(u8 eID);\n\n",
- fac->name);
-
- fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\tltt_facility_%s\n",
- fac->name);
- fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\tltt_facility_%s_%X\n",
- fac->name, fac->checksum);
- fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t0x%X\n", fac->checksum);
- fprintf(fd,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac->name);
- fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n",
- fac->name);
- fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t%u\n\n",
- fac->align);
- fprintf(fd,"#define LTT_FACILITY_SELECT\t\tltt_get_channel_index_%s\n\n",
- fac->name);
- fprintf(fd, "#endif //CONFIG_LTT\n\n");
- fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
-
- fclose(fd);
-
- return 0;
-}
-
-int print_loader_header_user(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-loader-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".h", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
- fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
- fprintf(fd,"#include <ltt/ltt-usertrace.h>\n");
- if(!fac->arch)
- fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n",
- fac->name);
- else
- fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
- fac->name,
- fac->arch);
- fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
- fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
- fac->name, fac->checksum);
-
- fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
- fac->name);
- fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
- fac->name, fac->checksum);
- fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum);
- fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name);
- fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
- fac->name);
- fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t\t\t\t%u\n\n",
- fac->align);
- fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
-
- fclose(fd);
-
- return 0;
-}
-
-
-
-/* ltt-facility-loader-name.c : generic facility loader
- * loader_c */
-int print_loader_c(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-loader-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".c", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- fprintf(fd, "/*\n");
- if(!fac->arch)
- fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
- else
- fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
- fprintf(fd, " *\n");
- fprintf(fd, " * (C) Copyright 2005 - \n");
- fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
- fprintf(fd, " *\n");
- fprintf(fd, " * Contains the LTT facility loader.\n");
- fprintf(fd, " *\n");
- fprintf(fd, " */\n");
- fprintf(fd, "\n");
- fprintf(fd, "\n");
- fprintf(fd, "#include <linux/ltt-facilities.h>\n");
- fprintf(fd, "#include <linux/module.h>\n");
- fprintf(fd, "#include <linux/init.h>\n");
- if(!fac->arch)
- fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
- else
- fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
- fac->name, fac->arch);
- fprintf(fd, "\n");
- fprintf(fd, "\n");
- fprintf(fd, "#ifdef CONFIG_LTT\n");
- fprintf(fd, "\n");
- fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
- fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
- fprintf(fd, "\n");
- fprintf(fd, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
- fprintf(fd, "\n");
- fprintf(fd, "#define SYMBOL_STRING(sym) #sym\n");
- fprintf(fd, "\n");
- fprintf(fd, "static struct ltt_facility facility = {\n");
- fprintf(fd, "\t.name = ltt_facility_name,\n");
- fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
- fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
- fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
- fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT,\n");
- fprintf(fd, "\t.select = LTT_FACILITY_SELECT,\n");
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
- fprintf(fd, "static int __init facility_init(void)\n");
- fprintf(fd, "{\n");
- fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac->name);
- fprintf(fd, "\n");
- fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
- fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
- fprintf(fd, "\t\n");
- fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n");
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
- fprintf(fd, "#ifndef MODULE\n");
- fprintf(fd, "__initcall(facility_init);\n");
- fprintf(fd, "#else\n");
- fprintf(fd, "module_init(facility_init);\n");
- fprintf(fd, "static void __exit facility_exit(void)\n");
- fprintf(fd, "{\n");
- fprintf(fd, "\tint err;\n");
- fprintf(fd, "\n");
- fprintf(fd, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
- fprintf(fd, "\tif (err != 0)\n");
- fprintf(fd, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
- fprintf(fd, "\n");
- fprintf(fd, "}\n");
- fprintf(fd, "module_exit(facility_exit)\n");
- fprintf(fd, "\n");
- fprintf(fd, "MODULE_LICENSE(\"GPL\");\n");
- fprintf(fd, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
- fprintf(fd, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
- fprintf(fd, "\n");
- fprintf(fd, "#endif //MODULE\n");
- fprintf(fd, "\n");
- fprintf(fd, "#endif //CONFIG_LTT\n");
-
- fclose(fd);
-
- return 0;
-}
-
-int print_loader_c_user(facility_t *fac)
-{
- char filename[PATH_MAX];
- unsigned int filename_size = 0;
- FILE *fd;
- dprintf("%s\n", fac->name);
-
- strcpy(filename, "ltt-facility-loader-");
- filename_size = strlen(filename);
-
- strncat(filename, fac->name, PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- if(fac->arch) {
- strncat(filename, "_", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
- strncat(filename, fac->arch, PATH_MAX - filename_size);
- filename_size = strlen(filename);
- }
-
- strncat(filename, ".c", PATH_MAX - filename_size);
- filename_size = strlen(filename);
-
-
- fd = fopen(filename, "w");
- if(fd == NULL) {
- printf("Error opening file %s for writing : %s\n",
- filename, strerror(errno));
- return errno;
- }
-
- fprintf(fd, "/*\n");
- if(!fac->arch)
- fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
- else
- fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
- fprintf(fd, " *\n");
- fprintf(fd, " * (C) Copyright 2005 - \n");
- fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
- fprintf(fd, " *\n");
- fprintf(fd, " * Contains the LTT user space facility loader.\n");
- fprintf(fd, " *\n");
- fprintf(fd, " */\n");
- fprintf(fd, "\n");
- fprintf(fd, "\n");
- fprintf(fd, "#define LTT_TRACE\n");
- fprintf(fd, "#include <error.h>\n");
- fprintf(fd, "#include <stdio.h>\n");
- fprintf(fd, "#include <ltt/ltt-usertrace.h>\n");
- if(!fac->arch)
- fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
- else
- fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
- fac->name, fac->arch);
- fprintf(fd, "\n");
- fprintf(fd, "static struct user_facility_info facility = {\n");
- fprintf(fd, "\t.name = LTT_FACILITY_NAME,\n");
- fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
- fprintf(fd, "#ifndef LTT_PACK\n");
- fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,\n");
- fprintf(fd, "#else\n");
- fprintf(fd, "\t.alignment = 0,\n");
- fprintf(fd, "#endif //LTT_PACK\n");
- fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
- fprintf(fd, "\t.int_size = sizeof(int),\n");
- fprintf(fd, "\t.long_size = sizeof(long),\n");
- fprintf(fd, "\t.pointer_size = sizeof(void*),\n");
- fprintf(fd, "\t.size_t_size = sizeof(size_t)\n");
- fprintf(fd, "};\n");
- fprintf(fd, "\n");
- fprintf(fd, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
- fprintf(fd, "{\n");
- fprintf(fd, "\tint err;\n");
- fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
- fprintf(fd, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac->name);
- fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
- fprintf(fd, "\n");
- fprintf(fd, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n");
- fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
- fprintf(fd, "\t\n");
- fprintf(fd, "\tif (err) {\n");
- fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
- fprintf(fd, "\t\tperror(\"Error in ltt_register_generic\");\n");
- fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
- fprintf(fd, "\t}\n");
- fprintf(fd, "}\n");
- fprintf(fd, "\n");
-
- fclose(fd);
-
- return 0;
-}
-
-
-
-/* open facility */
-/* code taken from ltt_facility_open in ltt/facility.c in lttv */
-
-/*****************************************************************************
- *Function name
- * ltt_facility_open : open facilities
- *Input params
- * pathname : the path name of the facility
- *
- * Open the facility corresponding to the right checksum.
- *
- *returns the facility on success, NULL on error.
- ****************************************************************************/
-facility_t *ltt_facility_open(char * pathname)
-{
- int ret = 0;
- char *token;
- parse_file_t in;
- facility_t * fac = NULL;
- char buffer[BUFFER_SIZE];
- int generated = FALSE;
-
- in.buffer = &(buffer[0]);
- in.lineno = 0;
- in.error = error_callback;
- in.name = pathname;
- in.unget = 0;
-
- in.fp = fopen(in.name, "r");
- if(in.fp == NULL) {
- ret = 1;
- goto open_error;
- }
-
- while(1){
- token = getToken(&in);
- if(in.type == ENDFILE) break;
-
- if(generated) {
- printf("More than one facility in the file. Only using the first one.\n");
- break;
- }
-
- if(strcmp(token, "<")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp(token, "?")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp(token, "xml")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp(token, "version")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp(token, "=")) in.error(&in,"not a facility file");
- token = getQuotedString(&in);
- if(strcmp(token, "1.0")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp(token, "?")) in.error(&in,"not a facility file");
- token = getToken(&in);
- if(strcmp(token, ">")) in.error(&in,"not a facility file");
-
- token = getName(&in);
- if(strcmp(token, "<")) in.error(&in,"not a facility file");
- token = getName(&in);
- if(strcmp("facility",token) == 0) {
- fac = malloc(sizeof(facility_t));
- fac->name = NULL;
- fac->description = NULL;
- sequence_init(&(fac->events));
- table_init(&(fac->named_types));
- sequence_init(&(fac->unnamed_types));
-
- parseFacility(&in, fac);
-
- //check if any namedType is not defined
- checkNamedTypesImplemented(&fac->named_types);
-
- generateChecksum(fac->name, &fac->checksum, &fac->events);
-
- generated = TRUE;
- }
- else {
- printf("facility token was expected in file %s\n", in.name);
- ret = 1;
- goto parse_error;
- }
- }
-
- parse_error:
- fclose(in.fp);
-open_error:
-
- if(!generated) {
- printf("Cannot find facility %s\n", pathname);
- fac = NULL;
- }
-
- return fac;
-}
-
-/* Close the facility */
-void ltt_facility_close(facility_t *fac)
-{
- free(fac->name);
- free(fac->capname);
- free(fac->description);
- freeEvents(&fac->events);
- sequence_dispose(&fac->events);
- freeNamedType(&fac->named_types);
- table_dispose(&fac->named_types);
- freeTypes(&fac->unnamed_types);
- sequence_dispose(&fac->unnamed_types);
- free(fac);
-}
-
-
-/* Show help */
-void show_help(int argc, char ** argv)
-{
- printf("Genevent help : \n");
- printf("\n");
- printf("Use %s name.xml\n", argv[0]);
- printf("to create :\n");
- printf("ltt-facility-name.h\n");
- printf("ltt-facility-id-name.h\n");
- printf("ltt-facility-loader-name.h\n");
- printf("ltt-facility-loader-name.c\n");
- printf("In the current directory.\n");
- printf("\n");
-}
-
-/* Parse program arguments */
-/* Return values :
- * 0 : continue program
- * -1 : stop program, return 0
- * > 0 : stop program, return value as exit.
- */
-int check_args(int argc, char **argv)
-{
- if(argc < 2) {
- printf("Not enough arguments\n");
- show_help(argc, argv);
- return EINVAL;
- }
-
- if(strcmp(argv[1], "-h") == 0) {
- show_help(argc, argv);
- return -1;
- }
-
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- int err = 0;
- facility_t *fac;
-
- err = check_args(argc, argv);
- if(err > 0) return err;
- else if(err < 0) return 0;
-
- /* open the facility */
- fac = ltt_facility_open(argv[1]);
- if(fac == NULL) {
- printf("Error opening file %s for reading : %s\n",
- argv[1], strerror(errno));
- return errno;
- }
-
- /* generate the output C files */
-
-
- /* ltt-facility-name.h : main logging header.
- * log_header */
- err = print_log_header(fac);
- if(err) return err;
-
- /* ltt-facility-id-name.h : facility id.
- * log_id_header */
- err = print_id_header(fac);
- if(err) return err;
-
- /* ltt-facility-loader-name.h : facility specific loader info.
- * loader_header */
- if(!fac->user)
- err = print_loader_header(fac);
- else
- err = print_loader_header_user(fac);
- if(err) return err;
-
- /* ltt-facility-loader-name.c : generic faciilty loader
- * loader_c */
- if(!fac->user)
- err = print_loader_c(fac);
- else
- err = print_loader_c_user(fac);
- if(err) return err;
-
- /* close the facility */
- ltt_facility_close(fac);
-
- return 0;
-}
-
-
+++ /dev/null
-/******************************************************************************
- * Genevent
- *
- * Event generator. XML to logging C code converter.
- *
- * Supports :
- * - C Alignment
- * - C types : struct, union, enum, basic types.
- * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
- *
- * Additionnal structures supported :
- * - embedded variable size strings
- * - embedded variable size arrays
- * - embedded variable size sequences
- *
- * Notes :
- * (1)
- * enums are limited to integer type, as this is what is used in C. Note,
- * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
- * unsigned int or int. This is implementation defined (compiler). That's why we
- * add a check for sizeof enum.
- *
- * (2)
- * Because of archtecture defined type sizes, we need to ask for ltt_align
- * (which gives the alignment) by passing basic types, not their actual sizes.
- * It's up to ltt_align to determine sizes of types.
- *
- * Note that, from
- * http://www.usenix.org/publications/login/standards/10.data.html
- * (Andrew Josey <a.josey@opengroup.org>) :
- *
- * Data Type LP32 ILP32 ILP64 LLP64 LP64
- * char 8 8 8 8 8
- * short 16 16 16 16 16
- * int32 32
- * int 16 32 64 32 32
- * long 32 32 64 32 64
- * long long (int64) 64
- * pointer 32 32 64 64 64
- *
- * With these constraints :
- * sizeof(char) <= sizeof(short) <= sizeof(int)
- * <= sizeof(long) = sizeof(size_t)
- *
- * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
- *
- * Which means we only have to remember which is the biggest type in a structure
- * to know the structure's alignment.
- */
-
-
-
-/* Code printing */
-
-/* Type size checking */
-int print_check(int fd);
-
-
-/* Print types */
-int print_types(int fd);
-
-/* Print events */
-int print_events(int fd);
-
-
-
+++ /dev/null
-
-#define __KERNEL__
-
-#include <assert.h>
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <linux/compiler.h>
-
-#define min(a,b) (((a)<(b))?a:b)
-#define max(a,b) (((a)>(b))?a:b)
-#define BUG_ON(a) assert(!(a))
-
-// Useful outside __KERNEL__. Not used here because inline is already redefined.
-#define force_inline inline __attribute__((always_inline))
-
-/* Calculate the offset needed to align the type */
-static inline unsigned int ltt_align(size_t align_drift,
- size_t size_of_type)
-{
- size_t alignment = min(sizeof(void*), size_of_type);
-
- return ((alignment - align_drift) & (alignment-1));
-}
-
-
-/* TEMPLATE */
-
-enum lttng_tasklet_priority {
- LTTNG_LOW,
- LTTNG_HIGH,
-};
-
-enum lttng_irq_mode {
- LTTNG_user,
- LTTNG_kernel,
-};
-
-struct lttng_mystruct2 {
- unsigned int irq_id;
- enum lttng_irq_mode mode;
- //struct lttng_mystruct teststr1;
-};
-
-#if 0
-static inline size_t lttng_get_size_mystruct2(
- struct lttng_mystruct2 * obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(enum lttng_irq_mode);
- size += ltt_align(size, locsize) + locsize;
-
- BUG_ON(sizeof(struct lttng_mystruct2) != size);
-
- return sizeof(struct lttng_mystruct2);
-}
-#endif //0
-
-static inline size_t lttng_get_alignment_mystruct2(
- struct lttng_mystruct2 *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(enum lttng_irq_mode);
- align = max(align, localign);
-
- return align;
-}
-
-static inline void lttng_write_mystruct2(
- void *buffer,
- size_t *to_base,
- size_t *to,
- void **from,
- size_t *len,
- struct lttng_mystruct2 *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct2(obj);
- //size = lttng_get_size_mystruct2(obj);
- size = sizeof(struct lttng_mystruct2);
-
- if(*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-}
-
-
-
-#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
-typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
-
-#if 0
-static inline size_t lttng_get_size_array_mystruct_myarray(
- lttng_array_mystruct_myarray obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(uint64_t);
- /* ltt_align == 0 always*/
- //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
- BUG_ON(ltt_align(size, locsize) != 0);
- size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
-
- BUG_ON(sizeof(lttng_array_mystruct_myarray) != size);
-
- return sizeof(lttng_array_mystruct_myarray);
-}
-#endif //0
-
-static inline size_t lttng_get_alignment_array_mystruct_myarray(
- lttng_array_mystruct_myarray obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(uint64_t);
- align = max(align, localign);
-
- return align;
-}
-
-
-static inline void lttng_write_array_mystruct_myarray(
- void *buffer,
- size_t *to_base,
- size_t *to,
- void **from,
- size_t *len,
- lttng_array_mystruct_myarray obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_array_mystruct_myarray(obj);
- //size = lttng_get_size_array_mystruct_myarray(obj);
- size = sizeof(lttng_array_mystruct_myarray);
-
- if(*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-#if 0
- /* For varlen child : let the child align itself. */
- for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_mystruct_myarray; i++) {
- lttng_write_child(buffer, to_base, to, from, len, obj[i]);
- }
-#endif //0
-
-}
-
-
-typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
-struct lttng_sequence_mystruct_mysequence {
- unsigned int len;
- double *array;
-};
-
-#if 0
-static inline size_t lttng_get_size_sequence_mystruct_mysequence(
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(double);
- size += ltt_align(size, locsize) + (obj->len * locsize);
-
- /* Realign on arch size */
- locsize = sizeof(void *);
- size += ltt_align(size, locsize);
-
- return size;
-}
-#endif //0
-
-static inline size_t lttng_get_alignment_sequence_mystruct_mysequence(
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(double);
- align = max(align, localign);
-
- return align;
-}
-
-
-static inline void lttng_write_sequence_mystruct_mysequence(
- void *buffer,
- size_t *to_base,
- size_t *to,
- void **from,
- size_t *len,
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t align;
- size_t size;
-
- /* Flush pending memcpy */
- if(*len != 0) {
- if(buffer != NULL)
- memcpy(buffer+*to_base+*to, *from, *len);
- }
- *to += *len;
- *len = 0;
-
- align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
- //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
-
- /* Align output */
- *to += ltt_align(*to, align); /* *len = 0 in this function */
-
- /* Copy members */
- size = sizeof(unsigned int);
- *to += ltt_align(*to, size);
- if(buffer != NULL)
- memcpy(buffer+*to_base+*to, &obj->len, size);
- *to += size;
-
- size = sizeof(double);
- *to += ltt_align(*to, size);
- size = obj->len * sizeof(double);
- if(buffer != NULL)
- memcpy(buffer+*to_base+*to, obj->array, size);
- *to += size;
-#if 0
- /* If varlen child : let child align itself */
- for(unsigned int i=0; i<obj->len; i++) {
- lttng_write_child(buffer, to_base, to, from, len, obj->array[i]);
- }
-#endif //0
-
-
- /* Realign the *to_base on arch size, set *to to 0 */
- *to = ltt_align(*to, sizeof(void *));
- *to_base = *to_base+*to;
- *to = 0;
-
- /* Put source *from just after the C sequence */
- *from = obj+1;
-}
-
-
-
-union lttng_mystruct_myunion {
- double myfloat;
- unsigned long myulong;
-};
-
-#if 0
-static inline size_t lttng_get_size_mystruct_myunion(
- union lttng_mystruct_myunion *obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(double);
- size = max(size, locsize);
-
- locsize = sizeof(unsigned long);
- size = max(size, locsize);
-
- BUG_ON(size != sizeof(union lttng_mystruct_myunion));
-
- return sizeof(union lttng_mystruct_myunion);
-}
-#endif //0
-
-static inline size_t lttng_get_alignment_mystruct_myunion(
- union lttng_mystruct_myunion *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(double);
- align = max(align, localign);
-
- localign = sizeof(unsigned long);
- align = max(align, localign);
-
- return align;
-}
-
-
-static inline void lttng_write_mystruct_myunion(
- void *buffer,
- size_t *to_base,
- size_t *to,
- void **from,
- size_t *len,
- union lttng_mystruct_myunion *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct_myunion(obj);
- //size = lttng_get_size_mystruct_myunion(obj);
- size = sizeof(union lttng_mystruct_myunion);
-
- if(*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-
- /* Assert : no varlen child. */
-}
-
-
-struct lttng_mystruct {
- unsigned int irq_id;
- enum lttng_irq_mode mode;
- struct lttng_mystruct2 teststr;
- lttng_array_mystruct_myarray myarray;
- lttng_sequence_mystruct_mysequence mysequence;
- union lttng_mystruct_myunion myunion;
-};
-
-#if 0
-static inline size_t lttng_get_size_mystruct(
- struct lttng_mystruct *obj)
-{
- size_t size=0, locsize, localign;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(enum lttng_irq_mode);
- size += ltt_align(size, locsize) + locsize;
-
- localign = lttng_get_alignment_mystruct2(&obj->teststr);
- locsize = lttng_get_size_mystruct2(&obj->teststr);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
- locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
- locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
- locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
- size += ltt_align(size, localign) + locsize;
-
- return size;
-}
-#endif //0
-
-static inline size_t lttng_get_alignment_mystruct(
- struct lttng_mystruct *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(enum lttng_irq_mode);
- align = max(align, localign);
-
- localign = lttng_get_alignment_mystruct2(&obj->teststr);
- align = max(align, localign);
-
- localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
- align = max(align, localign);
-
- localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
- align = max(align, localign);
-
- localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
- align = max(align, localign);
-
- return align;
-}
-
-static inline void lttng_write_mystruct(
- void *buffer,
- size_t *to_base,
- size_t *to,
- void **from,
- size_t *len,
- struct lttng_mystruct *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct(obj);
- // no need : contains variable size fields.
- // locsize = lttng_get_size_mystruct(obj);
-
- if(*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = sizeof(unsigned int);
- size += ltt_align(*to+*len, size) + size;
- *len += size;
-
- size = sizeof(enum lttng_irq_mode);
- size += ltt_align(*to+*len, size) + size;
- *len += size;
-
- lttng_write_mystruct2(buffer, to_base, to, from, len, &obj->teststr);
-
- lttng_write_array_mystruct_myarray(buffer, to_base, to, from, len, obj->myarray);
-
- /* Variable length field */
- lttng_write_sequence_mystruct_mysequence(buffer, to_base, to, from, len, &obj->mysequence);
- /* After this previous write, we are sure that *to is 0, *len is 0 and
- * *to_base is aligned on the architecture size : to rest of alignment will
- * be calculated statically. */
-
- lttng_write_mystruct_myunion(buffer, to_base, to, from, len, &obj->myunion);
-
- /* Don't forget to flush last write..... */
-}
-
-
-
-
-
-
-//void main()
-void test()
-{
- struct lttng_mystruct test;
- test.mysequence.len = 20;
- test.mysequence.array = malloc(20);
-
- //size_t size = lttng_get_size_mystruct(&test);
- //size_t align = lttng_get_alignment_mystruct(&test);
- //
- size_t to_base = 0; /* the buffer is allocated on arch_size alignment */
- size_t to = 0;
- void *from = &test;
- size_t len = 0;
-
- /* Get size */
- lttng_write_mystruct(NULL, &to_base, &to, &from, &len, &test);
- /* Size = to_base + to + len */
-
- void *buffer = malloc(to_base + to + len);
- to_base = 0; /* the buffer is allocated on arch_size alignment */
- to = 0;
- from = &test;
- len = 0;
-
- lttng_write_mystruct(buffer, &to_base, &to, &from, &len, &test);
- /* Final flush */
- /* Flush pending memcpy */
- if(len != 0) {
- // Assert buffer != NULL */
- memcpy(buffer+to_base+to, from, len);
- to += len;
- from += len;
- len = 0;
- }
-
- free(test.mysequence.array);
- free(buffer);
-}
+++ /dev/null
-#ifndef _LTT_FACILITY_TEST_H_
-#define _LTT_FACILITY_TEST_H_
-
-
-/* Facility activation at compile time. */
-#ifdef CONFIG_LTT_FACILITY_TEST
-
-/* Named types */
-
-
-enum lttng_tasklet_priority {
- LTTNG_LOW,
- LTTNG_HIGH,
-};
-
-enum lttng_irq_mode {
- LTTNG_user,
- LTTNG_kernel,
-};
-
-struct lttng_mystruct2 {
- unsigned int irq_id;
- enum lttng_irq_mode mode;
- //struct lttng_mystruct teststr1;
-};
-
-
-size_t lttng_get_size_mystruct2(
- struct lttng_mystruct2 *obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(enum lttng_irq_mode);
- size += ltt_align(size, locsize) + locsize;
-
- BUG_ON(sizeof(struct lttng_mystruct2) != size);
-
- return sizeof(struct lttng_mystruct2);
-}
-
-size_t lttng_get_alignment_mystruct2(
- struct lttng_mystruct2 *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(enum lttng_irq_mode);
- align = max(align, localign);
-
- return align;
-}
-
-void lttng_write_mystruct2(void **to,
- void **from,
- size_t *len,
- struct lttng_mystruct2 *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct2(obj);
- size = lttng_get_size_mystruct2(obj);
-
- if(*len == 0) {
- *to += ltt_align((size_t)(*to), align); /* align output */
- } else {
- *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-}
-
-
-
-#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
-typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
-
-size_t lttng_get_size_array_mystruct_myarray(
- lttng_array_mystruct_myarray obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(uint64_t);
- /* ltt_align == 0 always*/
- //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
- BUG_ON(ltt_align(size, locsize) != 0);
- size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
-
- BUG_ON(size != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
-
- return size;
-}
-
-size_t lttng_get_alignment_array_mystruct_myarray(
- lttng_array_mystruct_myarray obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(uint64_t);
- align = max(align, localign);
-
- return align;
-}
-
-
-void lttng_write_array_mystruct_myarray(void **to,
- void **from,
- size_t *len,
- lttng_array_mystruct_myarray obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_array_mystruct_myarray(obj);
- size = lttng_get_size_array_mystruct_myarray(obj);
-
- if(*len == 0) {
- *to += ltt_align((size_t)(*to), align); /* align output */
- } else {
- *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-}
-
-
-typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
-struct lttng_sequence_mystruct_mysequence {
- unsigned int len;
- double *array;
-};
-
-
-size_t lttng_get_size_sequence_mystruct_mysequence(
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(double);
- size += ltt_align(size, locsize) + (obj->len * locsize);
-
- return size;
-}
-
-size_t lttng_get_alignment_sequence_mystruct_mysequence(
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(double);
- align = max(align, localign);
-
- return align;
-}
-
-
-void lttng_write_sequence_mystruct_mysequence(void **to,
- void **from,
- size_t *len,
- lttng_sequence_mystruct_mysequence *obj)
-{
- size_t align, size;
- void *varfrom;
- size_t varlen=0;
-
- /* Flush pending memcpy */
- if(*len != 0) {
- memcpy(*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
- //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
-
- /* Align output */
- *to += ltt_align((size_t)(*to), align);
-
- /* Copy members */
- *to += ltt_align((size_t)*to, sizeof(unsigned int));
- varfrom = &obj->len;
- varlen += sizeof(unsigned int);
- memcpy(*to, varfrom, varlen);
- *to += varlen;
- varlen = 0;
-
- *to += ltt_align((size_t)*to, sizeof(double));
- varfrom = obj->array;
- varlen += obj->len * sizeof(double);
- memcpy(*to, varfrom, varlen);
- *to += varlen;
- varlen = 0;
-
- /* Put source *from just after the C sequence */
- *from = obj+1;
-}
-
-
-
-union lttng_mystruct_myunion {
- double myfloat;
- unsigned long myulong;
-};
-
-
-size_t lttng_get_size_mystruct_myunion(
- union lttng_mystruct_myunion *obj)
-{
- size_t size=0, locsize;
-
- locsize = sizeof(double);
- size = max(size, locsize);
-
- locsize = sizeof(unsigned long);
- size = max(size, locsize);
-
- BUG_ON(size != sizeof(union lttng_mystruct_myunion));
-
- return size;
-}
-
-
-size_t lttng_get_alignment_mystruct_myunion(
- union lttng_mystruct_myunion *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(double);
- align = max(align, localign);
-
- localign = sizeof(unsigned long);
- align = max(align, localign);
-
- return align;
-}
-
-
-void lttng_write_mystruct_myunion(void **to,
- void **from,
- size_t *len,
- union lttng_mystruct_myunion *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct_myunion(obj);
- size = lttng_get_size_mystruct_myunion(obj);
-
- if(*len == 0) {
- *to += ltt_align((size_t)(*to), align); /* align output */
- } else {
- *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
- }
-
- *len += size;
-}
-
-
-struct lttng_mystruct {
- unsigned int irq_id;
- enum lttng_irq_mode mode;
- struct lttng_mystruct2 teststr;
- lttng_array_mystruct_myarray myarray;
- lttng_sequence_mystruct_mysequence mysequence;
- union lttng_mystruct_myunion myunion;
-};
-
-size_t lttng_get_size_mystruct(
- struct lttng_mystruct *obj)
-{
- size_t size=0, locsize, localign;
-
- locsize = sizeof(unsigned int);
- size += ltt_align(size, locsize) + locsize;
-
- locsize = sizeof(enum lttng_irq_mode);
- size += ltt_align(size, locsize) + locsize;
-
- localign = lttng_get_alignment_mystruct2(&obj->teststr);
- locsize = lttng_get_size_mystruct2(&obj->teststr);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
- locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
- locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
- size += ltt_align(size, localign) + locsize;
-
- localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
- locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
- size += ltt_align(size, localign) + locsize;
-
- return size;
-}
-
-
-size_t lttng_get_alignment_mystruct(
- struct lttng_mystruct *obj)
-{
- size_t align=0, localign;
-
- localign = sizeof(unsigned int);
- align = max(align, localign);
-
- localign = sizeof(enum lttng_irq_mode);
- align = max(align, localign);
-
- localign = lttng_get_alignment_mystruct2(&obj->teststr);
- align = max(align, localign);
-
- localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
- align = max(align, localign);
-
- localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
- align = max(align, localign);
-
- localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
- align = max(align, localign);
-
- return align;
-}
-
-void lttng_write_mystruct(void **to,
- void **from,
- size_t *len,
- struct lttng_mystruct *obj)
-{
- size_t align, size;
-
- align = lttng_get_alignment_mystruct(obj);
- // no need : contains variable size fields.
- // locsize = lttng_get_size_mystruct(obj);
-
- if(*len == 0) {
- *to += ltt_align((size_t)(*to), align); /* align output */
- } else {
- *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = sizeof(unsigned int);
- *len += ltt_align((size_t)(*to+*len), size) + size;
-
- size = sizeof(enum lttng_irq_mode);
- *len += ltt_align((size_t)(*to+*len), size) + size;
-
- lttng_write_mystruct2(to, from, len, &obj->teststr);
-
- lttng_write_array_mystruct_myarray(to, from, len, obj->myarray);
-
- /* Variable length field */
- lttng_write_sequence_mystruct_mysequence(to, from, len, &obj->mysequence);
-
- lttng_write_mystruct_myunion(to, from, len, &obj->myunion);
-
- /* Don't forget to flush last write..... */
-}
-
-
-
-
-/* Event syscall_entry structures */
-
-/* Event syscall_entry logging function */
-static inline void trace_test_syscall_entry(
- unsigned int syscall_id,
- void * address)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event syscall_exit structures */
-
-/* Event syscall_exit logging function */
-static inline void trace_test_syscall_exit(
- void)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event trap_entry structures */
-
-/* Event trap_entry logging function */
-static inline void trace_test_trap_entry(
- unsigned int trap_id,
- void * address)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event trap_exit structures */
-
-/* Event trap_exit logging function */
-static inline void trace_test_trap_exit(
- void)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event soft_irq_entry structures */
-
-/* Event soft_irq_entry logging function */
-static inline void trace_test_soft_irq_entry(
- void * softirq_id)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event soft_irq_exit structures */
-
-/* Event soft_irq_exit logging function */
-static inline void trace_test_soft_irq_exit(
- void * softirq_id)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event tasklet_entry structures */
-
-/* Event tasklet_entry logging function */
-static inline void trace_test_tasklet_entry(
- enum lttng_tasklet_priority priority,
- void * address,
- unsigned long data)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event tasklet_exit structures */
-
-/* Event tasklet_exit logging function */
-static inline void trace_test_tasklet_exit(
- enum lttng_tasklet_priority priority,
- void * address,
- unsigned long data)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event irq_entry structures */
-
-/* Event irq_entry logging function */
-static inline void trace_test_irq_entry(
- unsigned int irq_id,
- enum lttng_irq_mode mode)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event irq_exit structures */
-
-/* Event irq_exit logging function */
-static inline void trace_test_irq_exit(
- void)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-/* Event big_array structures */
-union lttng_test_big_array_myarray_b {
- void * c;
-};
-
-struct lttng_test_big_array_myarray {
- void * a;
- union lttng_test_big_array_myarray_b b;
-};
-
-#define LTTNG_ARRAY_SIZE_test_big_array_myarray 2
-typedef struct lttng_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
-
-#define LTTNG_ARRAY_SIZE_test_big_array_myarray 10000
-typedef lttng_array_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
-
-
-/* Event big_array logging function */
-static inline void trace_test_big_array(
- lttng_array_test_big_array_myarray myarray)
-#ifndef CONFIG_LTT
-{
-}
-#else
-{
-}
-#endif //CONFIG_LTT
-
-
-#endif //CONFIG_LTT_FACILITY_TEST
-
-#endif //_LTT_FACILITY_TEST_H_
+++ /dev/null
-
-
-
-/*
-
-parser.c: Generate helper declarations and functions to trace events
- from an event description file.
-
- Copyright (C) 2005, Mathieu Desnoyers
- Copyright (C) 2002, Xianxiu Yang
- Copyright (C) 2002, Michel Dagenais
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/* This program reads the ".xml" event definitions input files
- and constructs structure for each event.
-
- The program uses a very simple tokenizer, called from a hand written
- recursive descent parser to fill a data structure describing the events.
- The result is a sequence of events definitions which refer to type
- definitions.
-
- A table of named types is maintained to allow refering to types by name
- when the same type is used at several places. Finally a sequence of
- all types is maintained to facilitate the freeing of all type
- information when the processing of an ".xml" file is finished. */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <linux/errno.h>
-#include <assert.h>
-#include <ctype.h>
-
-#include "parser.h"
-
-
-char *intOutputTypes[] = {
- "int8_t", "int16_t", "int32_t", "int64_t" };
-
-char *uintOutputTypes[] = {
- "uint8_t", "uint16_t", "uint32_t", "uint64_t" };
-
-char *floatOutputTypes[] = {
- "undef", "undef", "float", "double" };
-
-
-
-
-/* helper function */
-void strupper(char *string)
-{
- char *ptr = string;
-
- while(*ptr != '\0') {
- *ptr = toupper(*ptr);
- ptr++;
- }
-}
-
-
-int getSizeindex(unsigned int value)
-{
- switch(value) {
- case 1:
- return 0;
- case 2:
- return 1;
- case 4:
- return 2;
- case 8:
- return 3;
- default:
- printf("Error : unknown value size %d\n", value);
- exit(-1);
- }
-}
-
-/*****************************************************************************
- *Function name
- * getSize : translate from string to integer
- *Input params
- * in : input file handle
- *Return values
- * size
- *****************************************************************************/
-
-unsigned long long int getSize(parse_file_t *in)
-{
- char *token, *token2;
- unsigned long long int ret;
-
- token = getToken(in);
-
-
- if(in->type == QUOTEDSTRING) {
- in->type = NUMBER;
- token2 = token;
- do {
- if (!isdigit(*token2)) {
- in->type = QUOTEDSTRING;
- break;
- }
- } while (*(++token2) != '\0');
- }
-
- if(in->type == NUMBER) {
- ret = strtoull(token, NULL, 0);
- } else {
- goto error;
- }
-
- return ret;
-error:
- in->error(in,"incorrect size specification");
- return -1;
-}
-
-/*****************************************************************************
- *Function name
- * error_callback : print out error info
- *Input params
- * in : input file handle
- * msg : message to be printed
- ****************************************************************************/
-
-void error_callback(parse_file_t *in, char *msg)
-{
- if(in)
- printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
- else
- printf("%s\n",msg);
- assert(0);
- exit(1);
-}
-
-/*****************************************************************************
- *Function name
- * memAlloc : allocate memory
- *Input params
- * size : required memory size
- *return value
- * void * : pointer to allocate memory or NULL
- ****************************************************************************/
-
-void * memAlloc(int size)
-{
- void * addr;
- if(size == 0) return NULL;
- addr = malloc(size);
- if(!addr){
- printf("Failed to allocate memory");
- exit(1);
- }
- return addr;
-}
-
-/*****************************************************************************
- *Function name
- * allocAndCopy : allocate memory and initialize it
- *Input params
- * str : string to be put in memory
- *return value
- * char * : pointer to allocate memory or NULL
- ****************************************************************************/
-
-char *allocAndCopy(char *str)
-{
- char * addr;
- if(str == NULL) return NULL;
- addr = (char *)memAlloc(strlen(str)+1);
- strcpy(addr,str);
- return addr;
-}
-
-/**************************************************************************
- * Function :
- * getTypeAttributes
- * Description :
- * Read the attribute from the input file.
- *
- * Parameters :
- * in , input file handle.
- * t , the type descriptor to fill.
- *
- **************************************************************************/
-
-void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
- sequence_t * unnamed_types, table_t * named_types)
-{
- char * token;
- int car;
-
- t->fmt = NULL;
- t->size = 0;
- t->custom_write = 0;
- t->network = 0;
-
- while(1) {
- token = getToken(in);
- if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
- ungetToken(in);
- break;
- }
-
- if(!strcmp("format",token)) {
- getEqual(in);
- t->fmt = allocAndCopy(getQuotedString(in));
- // printf("%s - ",t->fmt);
- //} else if(!strcmp("name",token)) {
- // getEqual(in);
- // car = seekNextChar(in);
- // if(car == EOF) in->error(in,"name was expected");
- // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in));
- // else t->type_name = allocAndCopy(getName(in));
- } else if(!strcmp("size",token)) {
- getEqual(in);
- t->size = getSize(in);
- } else if(!strcmp("custom_write", token)) {
- t->custom_write = 1;
- } else if(!strcmp("byte_order",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"byte order was expected (network?)");
- else if(car == '\"') token = getQuotedString(in);
- else token = getName(in);
- if(!strcmp("network", token)) {
- t->network = 1;
- }
- } else if(!strcmp("write",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"write type was expected (custom?)");
- else if(car == '\"') token = getQuotedString(in);
- else token = getName(in);
- if(!strcmp("custom", token)) {
- t->custom_write = 1;
- }
- }
- }
-}
-
-/**************************************************************************
- * Function :
- * getEventAttributes
- * Description :
- * Read the attribute from the input file.
- *
- * Parameters :
- * in , input file handle.
- * ev , the event to fill.
- *
- **************************************************************************/
-
-void getEventAttributes(parse_file_t *in, event_t *ev)
-{
- char * token;
- int car;
-
- ev->name = NULL;
- ev->per_trace = 0;
- ev->per_tracefile = 0;
- ev->param_buffer = 0;
- ev->no_instrument_function = 0;
- ev->high_priority = 0;
- ev->force = 0;
- ev->compact_data = 0;
-
- while(1) {
- token = getToken(in);
- if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
- ungetToken(in);
- break;
- }
-
- if(!strcmp("name",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"name was expected");
- else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in));
- else ev->name = allocAndCopy(getName(in));
- } else if(!strcmp("scope", token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"scope was expected");
- else if(car == '\"') token = getQuotedString(in);
- else token = getName(in);
- if(!strcmp(token, "trace")) ev->per_trace = 1;
- else if(!strcmp(token, "tracefile")) ev->per_tracefile = 1;
- } else if(!strcmp("param", token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"parameter type was expected");
- else if(car == '\"') token = getQuotedString(in);
- else token = getName(in);
- if(!strcmp(token, "buffer")) ev->param_buffer = 1;
- } else if(!strcmp("attribute", token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"attribute was expected");
- else if(car == '\"') token = getQuotedString(in);
- else token = getName(in);
- if(!strcmp(token, "no_instrument_function"))
- ev->no_instrument_function = 1;
- else if(!strcmp(token, "high_priority"))
- ev->high_priority = 1;
- else if(!strcmp(token, "force"))
- ev->force = 1;
- else if(!strcmp(token, "compact_data"))
- ev->compact_data = 1;
- }
- }
-}
-
-/**************************************************************************
- * Function :
- * getFacilityAttributes
- * Description :
- * Read the attribute from the input file.
- *
- * Parameters :
- * in , input file handle.
- * fac , the facility to fill.
- *
- **************************************************************************/
-
-void getFacilityAttributes(parse_file_t *in, facility_t *fac)
-{
- char * token;
- int car;
-
- fac->name = NULL;
- fac->arch = NULL;
- fac->align = 1;
- fac->user = 0;
-
- while(1) {
- token = getToken(in);
- if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
- ungetToken(in);
- break;
- }
-
- if(!strcmp("name",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"name was expected");
- else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
- else fac->name = allocAndCopy(getName(in));
- if(!strncmp(fac->name, "user_", sizeof("user_")-1))
- fac->user = 1;
- } else if(!strcmp("arch", token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in));
- else fac->arch = allocAndCopy(getName(in));
- } else if(!strcmp("align", token)) {
- getEqual(in);
- fac->align = getSize(in);
- }
-
- }
-}
-
-/**************************************************************************
- * Function :
- * getFieldAttributes
- * Description :
- * Read the attribute from the input file.
- *
- * Parameters :
- * in , input file handle.
- * f , the field to fill.
- *
- **************************************************************************/
-
-void getFieldAttributes(parse_file_t *in, field_t *f)
-{
- char * token;
- int car;
-
- f->name = NULL;
-
- while(1) {
- token = getToken(in);
- if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
- ungetToken(in);
- break;
- }
-
- if(!strcmp("name",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"name was expected");
- else if(car == '\"') f->name = allocAndCopy(getQuotedString(in));
- else f->name = allocAndCopy(getName(in));
- }
- }
-}
-
-char *getNameAttribute(parse_file_t *in)
-{
- char * token;
- char *name = NULL;
- int car;
-
- while(1) {
- token = getToken(in);
- if(!strcmp("name",token)) {
- getEqual(in);
- car = seekNextChar(in);
- if(car == EOF) in->error(in,"name was expected");
- else if(car == '\"') name = allocAndCopy(getQuotedString(in));
- else name = allocAndCopy(getName(in));
- } else {
- ungetToken(in);
- break;
- }
-
- }
- if(name == NULL) in->error(in, "Name was expected");
- return name;
-}
-
-
-
-//for <label name=label_name value=n format="...">, value is an option
-//Return value : 0 : no value, 1 : has a value
-int getValueAttribute(parse_file_t *in, long long *value)
-{
- char * token, * endptr;
-
- token = getToken(in);
-
- if(strcmp("/",token) == 0 || strcmp(">", token) == 0){
- ungetToken(in);
- return 0;
- }
- if(strcmp("value",token))in->error(in,"value was expected");
-
- getEqual(in);
- token = getToken(in);
-
- *value = strtoll(token, &endptr, 0);
- if(*endptr != '\0')
- goto error;
- return 1;
-error:
- in->error(in,"invalid number specified");
- return 0;
-}
-
-char * getDescription(parse_file_t *in)
-{
- long int pos;
- char * token, *str;
- int car;
-
- pos = ftell(in->fp);
-
- getLAnglebracket(in);
- token = getName(in);
- if(strcmp("description",token)){
- fseek(in->fp, pos, SEEK_SET);
- return NULL;
- }
-
- getRAnglebracket(in);
-
- pos = 0;
- while((car = getc(in->fp)) != EOF) {
- if(car == '<') break;
- if(car == '\0') continue;
- in->buffer[pos] = car;
- pos++;
- }
- if(car == EOF)in->error(in,"not a valid description");
- in->buffer[pos] = '\0';
-
- str = allocAndCopy(in->buffer);
-
- getForwardslash(in);
- token = getName(in);
- if(strcmp("description", token))in->error(in,"not a valid description");
- getRAnglebracket(in);
-
- return str;
-}
-
-/*****************************************************************************
- *Function name
- * parseFacility : generate event list
- *Input params
- * in : input file handle
- * fac : empty facility
- *Output params
- * fac : facility filled with event list
- ****************************************************************************/
-
-void parseFacility(parse_file_t *in, facility_t * fac)
-{
- char * token;
- event_t *ev;
-
- getFacilityAttributes(in, fac);
- if(fac->name == NULL) in->error(in, "Attribute not named");
-
- fac->capname = allocAndCopy(fac->name);
- strupper(fac->capname);
- getRAnglebracket(in);
-
- fac->description = getDescription(in);
-
- while(1){
- getLAnglebracket(in);
-
- token = getToken(in);
- if(in->type == ENDFILE)
- in->error(in,"the definition of the facility is not finished");
-
- if(strcmp("event",token) == 0){
- ev = (event_t*) memAlloc(sizeof(event_t));
- sequence_push(&(fac->events),ev);
- parseEvent(fac, in, ev, &(fac->unnamed_types), &(fac->named_types));
- }else if(strcmp("type",token) == 0){
- parseTypeDefinition(fac, in, &(fac->unnamed_types), &(fac->named_types));
- }else if(in->type == FORWARDSLASH){
- break;
- }else in->error(in,"event or type token expected\n");
- }
-
- token = getName(in);
- if(strcmp("facility",token)) in->error(in,"not the end of the facility");
- getRAnglebracket(in); //</facility>
-}
-
-/*****************************************************************************
- *Function name
- * parseEvent : generate event from event definition
- *Input params
- * fac : facility holding the event
- * in : input file handle
- * ev : new event
- * unnamed_types : array of unamed types
- * named_types : array of named types
- *Output params
- * ev : new event (parameters are passed to it)
- ****************************************************************************/
-
-void parseEvent(facility_t *fac, parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
- table_t * named_types)
-{
- char *token;
- field_t *f;
-
- ev->fac = fac;
- sequence_init(&(ev->fields));
- //<event name=eventtype_name>
- getEventAttributes(in, ev);
- if(ev->name == NULL) in->error(in, "Event not named");
- getRAnglebracket(in);
-
- //<description>...</description>
- ev->description = getDescription(in);
-
- int got_end = 0;
- /* Events can have multiple fields. each field form at least a function
- * parameter of the logging function. */
- while(!got_end) {
- getLAnglebracket(in);
- token = getToken(in);
-
- switch(in->type) {
- case FORWARDSLASH: /* </event> */
- token = getName(in);
- if(strcmp("event",token))in->error(in,"not an event definition");
- getRAnglebracket(in); //</event>
- got_end = 1;
- break;
- case NAME: /* a field */
- if(strcmp("field",token))in->error(in,"expecting a field");
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(ev->fields),f);
- parseFields(fac, in, f, unnamed_types, named_types, 1);
- break;
- default:
- in->error(in, "expecting </event> or <field >");
- break;
- }
- }
-#if 0
- if(in->type == FORWARDSLASH){ //</event> NOTHING
- ev->type = NULL;
- }else if(in->type == NAME){
- if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
- ungetToken(in);
- ev->type = parseType(in,NULL, unnamed_types, named_types);
- if(ev->type->type != STRUCT && ev->type->type != NONE)
- in->error(in,"type must be a struct");
- }else in->error(in, "not a valid type");
-
- getLAnglebracket(in);
- getForwardslash(in);
- }else in->error(in,"not a struct type");
- getLAnglebracket(in);
- getForwardslash(in);
- token = getName(in);
- if(strcmp("event",token))in->error(in,"not an event definition");
- getRAnglebracket(in); //</event>
-#endif //0
-}
-
-/*****************************************************************************
- *Function name
- * parseField : get field infomation from buffer
- *Input params
- * fac : facility holding the field
- * in : input file handle
- * f : field
- * unnamed_types : array of unamed types
- * named_types : array of named types
- * tag : is field surrounded by a <field> </field> tag ?
- ****************************************************************************/
-
-void parseFields(facility_t *fac, parse_file_t *in, field_t *f,
- sequence_t * unnamed_types,
- table_t * named_types,
- int tag)
-{
- char * token;
- f->fac = fac;
- if(tag) {
- //<field name=field_name> <description> <type> </field>
- getFieldAttributes(in, f);
- if(f->name == NULL) in->error(in, "Field not named");
- getRAnglebracket(in);
-
- f->description = getDescription(in);
- } else {
- f->description = NULL;
- }
-
- //<int size=...>
- getLAnglebracket(in);
- f->type = parseType(fac, in,NULL, unnamed_types, named_types);
-
- if(tag) {
- getLAnglebracket(in);
- getForwardslash(in);
- token = getName(in);
- if(strcmp("field",token))in->error(in,"not a valid field definition");
- getRAnglebracket(in); //</field>
- }
-}
-
-
-/*****************************************************************************
- *Function name
- * parseType : get type information, type can be :
- * Primitive:
- * int(size,fmt); uint(size,fmt); float(size,fmt);
- * string(fmt); enum(size,fmt,(label1,label2...))
- * Compound:
- * array(arraySize, type); sequence(lengthSize,type)
- * struct(field(name,type,description)...)
- * type name:
- * type(name,type)
- *Input params
- * fac : facility
- * in : input file handle
- * inType : a type descriptor
- * unnamed_types : array of unamed types
- * named_types : array of named types
- *Return values
- * type_descriptor* : a type descriptor
- ****************************************************************************/
-
-type_descriptor_t *parseType(facility_t *fac, parse_file_t *in, type_descriptor_t *inType,
- sequence_t * unnamed_types, table_t * named_types)
-{
- char *token;
- type_descriptor_t *t;
- field_t *f;
-
- if(inType == NULL) {
- t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
- t->type_name = NULL;
- t->type = NONE;
- t->fmt = NULL;
- sequence_push(unnamed_types,t);
- }
- else t = inType;
- t->fac = fac;
-
- token = getName(in);
-
- if(strcmp(token,"struct") == 0) {
- t->type = STRUCT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getRAnglebracket(in); //<struct>
- getLAnglebracket(in); //<field name=..>
- token = getToken(in);
- sequence_init(&(t->fields));
- while(strcmp("field",token) == 0){
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
-
- parseFields(fac, in, f, unnamed_types, named_types, 1);
-
- //next field
- getLAnglebracket(in);
- token = getToken(in);
- }
- if(strcmp("/",token))in->error(in,"not a valid structure definition");
- token = getName(in);
- if(strcmp("struct",token)!=0)
- in->error(in,"not a valid structure definition");
- getRAnglebracket(in); //</struct>
- }
- else if(strcmp(token,"union") == 0) {
- t->type = UNION;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getRAnglebracket(in); //<union>
-
- getLAnglebracket(in); //<field name=..>
- token = getToken(in);
- sequence_init(&(t->fields));
- while(strcmp("field",token) == 0){
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
- parseFields(fac, in, f, unnamed_types, named_types, 1);
-
- //next field
- getLAnglebracket(in);
- token = getToken(in);
- }
- if(strcmp("/",token))in->error(in,"not a valid union definition");
- token = getName(in);
- if(strcmp("union",token)!=0)
- in->error(in,"not a valid union definition");
- getRAnglebracket(in); //</union>
- }
- else if(strcmp(token,"array") == 0) {
- t->type = ARRAY;
- sequence_init(&(t->fields));
- getTypeAttributes(in, t, unnamed_types, named_types);
- if(t->size == 0) in->error(in, "Array has empty size");
- getForwardslash(in);
- getRAnglebracket(in); //<array size=n>
-
- //getLAnglebracket(in); //<subtype>
- /* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
-
- f->name = NULL;
- sequence_push(&(t->fields),f);
- parseFields(fac, in, f, unnamed_types, named_types, 0);
-
- //getLAnglebracket(in); //<type struct>
- //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
-
- getLAnglebracket(in); //</array>
- getForwardslash(in);
- token = getName(in);
- if(strcmp("array",token))in->error(in,"not a valid array definition");
- getRAnglebracket(in); //</array>
- }
- else if(strcmp(token,"sequence") == 0) {
- t->type = SEQUENCE;
- sequence_init(&(t->fields));
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in); //<sequence>
-
- //getLAnglebracket(in); //<sequence size type>
- /* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
- f->name = NULL;
- sequence_push(&(t->fields),f);
- parseFields(fac, in, f, unnamed_types, named_types, 0);
-
- //getLAnglebracket(in); //<subtype>
- /* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
- f->name = NULL;
- sequence_push(&(t->fields),f);
- parseFields(fac, in, f, unnamed_types, named_types, 0);
-
- //getLAnglebracket(in); //<type sequence>
- //t->length_type = parseType(in, NULL, unnamed_types, named_types);
-
- //getLAnglebracket(in); //<type sequence>
-
- //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
-
- if(t->fields.position < 1) in->error(in, "Sequence has no length type");
- if(t->fields.position < 2) in->error(in, "Sequence has no subtype");
- switch(((field_t*)t->fields.array[0])->type->type) {
- case UINT_FIXED :
- case UCHAR :
- case USHORT :
- case UINT :
- case ULONG :
- case SIZE_T :
- case OFF_T :
- break;
- default:
- in->error(in, "Wrong length type for sequence");
- }
-
- getLAnglebracket(in); //</sequence>
- getForwardslash(in);
- token = getName(in);
- if(strcmp("sequence",token))in->error(in,"not a valid sequence definition");
- getRAnglebracket(in); //</sequence>
- }
- else if(strcmp(token,"enum") == 0) {
- char * str;
- long long value = -1;
-
- t->type = ENUM;
- sequence_init(&(t->labels));
- sequence_init(&(t->labels_values));
- sequence_init(&(t->labels_description));
- t->already_printed = 0;
- getTypeAttributes(in, t, unnamed_types, named_types);
- //if(t->size == 0) in->error(in, "Sequence has empty size");
- //Mathieu : we fix enum size to target int size. GCC is always like this.
- //fox copy optimisation.
- if(t->size != 0) in->error(in, "Enum has fixed size of target int.");
- t->size = 0;
- getRAnglebracket(in);
-
- //<label name=label1 value=n/>
- getLAnglebracket(in);
- token = getToken(in); //"label" or "/"
- while(strcmp("label",token) == 0){
- int *label_value = malloc(sizeof(int));
- int has_value = 0;
- long long loc_value;
-
- str = allocAndCopy(getNameAttribute(in));
- has_value = getValueAttribute(in, &loc_value);
-
- sequence_push(&(t->labels),str);
-
- if(has_value) value = loc_value;
- else value++;
-
- *label_value = value;
- sequence_push(&(t->labels_values), label_value);
-
- getForwardslash(in);
- getRAnglebracket(in);
-
- //read description if any. May be NULL.
- str = allocAndCopy(getDescription(in));
- sequence_push(&(t->labels_description),str);
-
- //next label definition
- getLAnglebracket(in);
- token = getToken(in); //"label" or "/"
- }
- if(strcmp("/",token))in->error(in, "not a valid enum definition");
- token = getName(in);
- if(strcmp("enum",token))in->error(in, "not a valid enum definition");
- getRAnglebracket(in); //</label>
- }
- else if(strcmp(token,"int_fixed") == 0) {
- t->type = INT_FIXED;
- getTypeAttributes(in, t, unnamed_types, named_types);
- if(t->size == 0) in->error(in, "int has empty size");
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"uint_fixed") == 0) {
- t->type = UINT_FIXED;
- getTypeAttributes(in, t, unnamed_types, named_types);
- if(t->size == 0) in->error(in, "uint has empty size");
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"char") == 0) {
- t->type = CHAR;
- getTypeAttributes(in, t, unnamed_types, named_types);
- t->size = 1;
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"uchar") == 0) {
- t->type = UCHAR;
- getTypeAttributes(in, t, unnamed_types, named_types);
- t->size = 1;
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"short") == 0) {
- t->type = SHORT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- t->size = 2;
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"ushort") == 0) {
- t->type = USHORT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- t->size = 2;
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"int") == 0) {
- t->type = INT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"uint") == 0) {
- t->type = UINT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
-
- else if(strcmp(token,"pointer") == 0) {
- t->type = POINTER;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"long") == 0) {
- t->type = LONG;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"ulong") == 0) {
- t->type = ULONG;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"size_t") == 0) {
- t->type = SIZE_T;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"ssize_t") == 0) {
- t->type = SSIZE_T;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"off_t") == 0) {
- t->type = OFF_T;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"float") == 0) {
- t->type = FLOAT;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"string") == 0) {
- t->type = STRING;
- getTypeAttributes(in, t, unnamed_types, named_types);
- getForwardslash(in);
- getRAnglebracket(in);
- }
- else if(strcmp(token,"typeref") == 0){
- // Must be a named type
- free(t);
- sequence_pop(unnamed_types);
- token = getNameAttribute(in);
- t = find_named_type(token, named_types);
- if(t == NULL) in->error(in,"Named referred to must be pre-declared.");
- getForwardslash(in); //<typeref name=type_name/>
- getRAnglebracket(in);
- return t;
- }else in->error(in,"not a valid type");
-
- return t;
-}
-
-/*****************************************************************************
- *Function name
- * find_named_type : find a named type from hash table
- *Input params
- * name : type name
- * named_types : array of named types
- *Return values
- * type_descriptor * : a type descriptor
- *****************************************************************************/
-
-type_descriptor_t * find_named_type(char *name, table_t * named_types)
-{
- type_descriptor_t *t;
-
- t = (type_descriptor_t*)table_find(named_types,name);
-
- return t;
-}
-
-type_descriptor_t * create_named_type(char *name, table_t * named_types)
-{
- type_descriptor_t *t;
-
- t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
- t->type_name = allocAndCopy(name);
- t->type = NONE;
- t->fmt = NULL;
- table_insert(named_types,t->type_name,t);
- // table_insert(named_types,allocAndCopy(name),t);
- return t;
-}
-
-/*****************************************************************************
- *Function name
- * parseTypeDefinition : get type information from type definition
- *Input params
- * fac : facility
- * in : input file handle
- * unnamed_types : array of unamed types
- * named_types : array of named types
- *****************************************************************************/
-
-void parseTypeDefinition(facility_t *fac, parse_file_t * in, sequence_t * unnamed_types,
- table_t * named_types)
-{
- char *token;
- type_descriptor_t *t;
-
- token = getNameAttribute(in);
- if(token == NULL) in->error(in, "Type has empty name");
- t = create_named_type(token, named_types);
-
- if(t->type != NONE) in->error(in,"redefinition of named type");
- getRAnglebracket(in); //<type name=type_name>
- getLAnglebracket(in); //<
- token = getName(in);
- //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition");
- ungetToken(in);
- parseType(fac, in,t, unnamed_types, named_types);
-
- //</type>
- getLAnglebracket(in);
- getForwardslash(in);
- token = getName(in);
- if(strcmp("type",token))in->error(in,"not a valid type definition");
- getRAnglebracket(in); //</type>
-}
-
-/**************************************************************************
- * Function :
- * getComa, getName, getNumber, getEqual
- * Description :
- * Read a token from the input file, check its type, return it scontent.
- *
- * Parameters :
- * in , input file handle.
- *
- * Return values :
- * address of token content.
- *
- **************************************************************************/
-
-char *getName(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- // Optional descriptions
- // if(in->type != NAME) in->error(in,"Name token was expected");
- return token;
-}
-
-int getNumber(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- if(in->type != NUMBER) in->error(in, "Number token was expected");
- return atoi(token);
-}
-
-char *getForwardslash(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- //if(in->type != FORWARDSLASH) in->error(in, "forward slash token was expected");
- /* Mathieu : final / is optional now. */
- if(in->type != FORWARDSLASH) ungetToken(in);
-
- return token;
-}
-
-char *getLAnglebracket(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- if(in->type != LANGLEBRACKET) in->error(in, "Left angle bracket was expected");
- return token;
-}
-
-char *getRAnglebracket(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- if(in->type != RANGLEBRACKET) in->error(in, "Right angle bracket was expected");
- return token;
-}
-
-char *getQuotedString(parse_file_t * in)
-{
- char *token;
-
- token = getToken(in);
- if(in->type != QUOTEDSTRING) in->error(in, "quoted string was expected");
- return token;
-}
-
-char * getEqual(parse_file_t *in)
-{
- char *token;
-
- token = getToken(in);
- if(in->type != EQUAL) in->error(in, "equal was expected");
- return token;
-}
-
-int seekNextChar(parse_file_t *in)
-{
- int car;
- while((car = getc(in->fp)) != EOF) {
- if(!isspace(car)){
- ungetc(car,in->fp);
- return car;
- }
- }
- return EOF;
-}
-
-/******************************************************************
- * Function :
- * getToken, ungetToken
- * Description :
- * Read a token from the input file and return its type and content.
- * Line numbers are accounted for and whitespace/comments are skipped.
- *
- * Parameters :
- * in, input file handle.
- *
- * Return values :
- * address of token content.
- *
- ******************************************************************/
-
-void ungetToken(parse_file_t * in)
-{
- in->unget = 1;
-}
-
-char *getToken(parse_file_t * in)
-{
- FILE *fp = in->fp;
- int car, car1;
- int pos = 0, escaped;
-
- if(in->unget == 1) {
- in->unget = 0;
- return in->buffer;
- }
-
- /* skip whitespace and comments */
-
- while((car = getc(fp)) != EOF) {
- if(car == '/') {
- car1 = getc(fp);
- if(car1 == '*') skipComment(in);
- else if(car1 == '/') skipEOL(in);
- else {
- car1 = ungetc(car1,fp);
- break;
- }
- }
- else if(car == '\n') in->lineno++;
- else if(!isspace(car)) break;
- }
-
- switch(car) {
- case EOF:
- in->type = ENDFILE;
- break;
- case '/':
- in->type = FORWARDSLASH;
- in->buffer[pos] = car;
- pos++;
- break;
- case '<':
- in->type = LANGLEBRACKET;
- in->buffer[pos] = car;
- pos++;
- break;
- case '>':
- in->type = RANGLEBRACKET;
- in->buffer[pos] = car;
- pos++;
- break;
- case '=':
- in->type = EQUAL;
- in->buffer[pos] = car;
- pos++;
- break;
- case '"':
- escaped = 0;
- while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
- if(car == '\\' && escaped == 0) {
- in->buffer[pos] = car;
- pos++;
- escaped = 1;
- continue;
- }
- if(car == '"' && escaped == 0) break;
- if(car == '\n' && escaped == 0) {
- in->error(in, "non escaped newline inside quoted string");
- }
- if(car == '\n') in->lineno++;
- in->buffer[pos] = car;
- pos++;
- escaped = 0;
- }
- if(car == EOF) in->error(in,"no ending quotemark");
- if(pos == BUFFER_SIZE) in->error(in, "quoted string token too large");
- in->type = QUOTEDSTRING;
- break;
- default:
- if(isdigit(car)) {
- in->buffer[pos] = car;
- pos++;
- while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
- if(!isdigit(car)) {
- ungetc(car,fp);
- break;
- }
- in->buffer[pos] = car;
- pos++;
- }
- if(car == EOF) ungetc(car,fp);
- if(pos == BUFFER_SIZE) in->error(in, "number token too large");
- in->type = NUMBER;
- }
- else if(isalnum(car) || car == '_' || car == '-') {
- in->buffer[0] = car;
- pos = 1;
- while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
- if(!(isalnum(car) || car == '_' || car == '-')) {
- ungetc(car,fp);
- break;
- }
- in->buffer[pos] = car;
- pos++;
- }
- if(car == EOF) ungetc(car,fp);
- if(pos == BUFFER_SIZE) in->error(in, "name token too large");
- in->type = NAME;
- } else if(car == '?') {
- in->buffer[0] = car;
- pos++;
- }
- else in->error(in, "invalid character, unrecognized token");
- }
- in->buffer[pos] = 0;
- return in->buffer;
-}
-
-void skipComment(parse_file_t * in)
-{
- int car;
- while((car = getc(in->fp)) != EOF) {
- if(car == '\n') in->lineno++;
- else if(car == '*') {
- car = getc(in->fp);
- if(car ==EOF) break;
- if(car == '/') return;
- ungetc(car,in->fp);
- }
- }
- if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
-}
-
-void skipEOL(parse_file_t * in)
-{
- int car;
- while((car = getc(in->fp)) != EOF) {
- if(car == '\n') {
- ungetc(car,in->fp);
- break;
- }
- }
- if(car == EOF)ungetc(car, in->fp);
-}
-
-/*****************************************************************************
- *Function name
- * checkNamedTypesImplemented : check if all named types have definition
- ****************************************************************************/
-
-void checkNamedTypesImplemented(table_t * named_types)
-{
- type_descriptor_t *t;
- int pos;
- char str[256];
-
- for(pos = 0 ; pos < named_types->values.position; pos++) {
- t = (type_descriptor_t *) named_types->values.array[pos];
- if(t->type == NONE){
- sprintf(str,"named type '%s' has no definition",
- (char*)named_types->keys.array[pos]);
- error_callback(NULL,str);
- }
- }
-}
-
-
-/*****************************************************************************
- *Function name
- * generateChecksum : generate checksum for the facility
- *Input Params
- * facName : name of facility
- *Output Params
- * checksum : checksum for the facility
- ****************************************************************************/
-
-void generateChecksum(char* facName,
- unsigned int * checksum, sequence_t * events)
-{
- unsigned long crc ;
- int pos;
- event_t * ev;
- unsigned int i;
-
- crc = crc32(facName);
- for(pos = 0; pos < events->position; pos++){
- ev = (event_t *)(events->array[pos]);
- crc = partial_crc32(ev->name, crc);
- for(i = 0; i < ev->fields.position; i++) {
- field_t *f = (field_t*)ev->fields.array[i];
- crc = partial_crc32(f->name, crc);
- crc = getTypeChecksum(crc, f->type);
- }
- }
- *checksum = crc;
-}
-
-/*****************************************************************************
- *Function name
- * getTypeChecksum : generate checksum by type info
- *Input Params
- * crc : checksum generated so far
- * type : type descriptor containing type info
- *Return value
- * unsigned long : checksum
- *****************************************************************************/
-
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
-{
- unsigned long crc = aCrc;
- char * str = NULL, buf[16];
- int flag = 0, pos;
- field_t * fld;
-
- switch(type->type){
- case INT_FIXED:
- str = intOutputTypes[getSizeindex(type->size)];
- break;
- case UINT_FIXED:
- str = uintOutputTypes[getSizeindex(type->size)];
- break;
- case POINTER:
- str = allocAndCopy("void *");
- flag = 1;
- break;
- case CHAR:
- str = allocAndCopy("signed char");
- flag = 1;
- break;
- case UCHAR:
- str = allocAndCopy("unsigned char");
- flag = 1;
- break;
- case SHORT:
- str = allocAndCopy("short");
- flag = 1;
- break;
- case USHORT:
- str = allocAndCopy("unsigned short");
- flag = 1;
- break;
- case INT:
- str = allocAndCopy("int");
- flag = 1;
- break;
- case UINT:
- str = allocAndCopy("uint");
- flag = 1;
- break;
- case LONG:
- str = allocAndCopy("long");
- flag = 1;
- break;
- case ULONG:
- str = allocAndCopy("unsigned long");
- flag = 1;
- break;
- case SIZE_T:
- str = allocAndCopy("size_t");
- flag = 1;
- break;
- case SSIZE_T:
- str = allocAndCopy("ssize_t");
- flag = 1;
- break;
- case OFF_T:
- str = allocAndCopy("off_t");
- flag = 1;
- break;
- case FLOAT:
- str = floatOutputTypes[getSizeindex(type->size)];
- break;
- case STRING:
- str = allocAndCopy("string");
- flag = 1;
- break;
- case ENUM:
- //str = appendString("enum ", uintOutputTypes[getSizeindex(type->size)]);
- str = allocAndCopy("enum");
- flag = 1;
- break;
- case ARRAY:
- sprintf(buf,"%zu", type->size);
- str = appendString("array ",buf);
- flag = 1;
- break;
- case SEQUENCE:
- str = allocAndCopy("sequence ");
- flag = 1;
- break;
- case STRUCT:
- str = allocAndCopy("struct");
- flag = 1;
- break;
- case UNION:
- str = allocAndCopy("union");
- flag = 1;
- break;
- default:
- error_callback(NULL, "named type has no definition");
- break;
- }
-
- crc = partial_crc32(str,crc);
- if(flag) free(str);
-
- //the format string is not included in the crc calculation
-
- //if(type->fmt) crc = partial_crc32(type->fmt,crc);
-
- if(type->type == ARRAY){
- crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
- } else if(type->type ==SEQUENCE) {
- crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
- crc = getTypeChecksum(crc,((field_t*)type->fields.array[1])->type);
- } else if(type->type == STRUCT || type->type == UNION){
- for(pos =0; pos < type->fields.position; pos++){
- fld = (field_t *) type->fields.array[pos];
- crc = partial_crc32(fld->name,crc);
- crc = getTypeChecksum(crc, fld->type);
- }
- }else if(type->type == ENUM){
- for(pos = 0; pos < type->labels.position; pos++)
- crc = partial_crc32((char*)type->labels.array[pos],crc);
- }
-
- return crc;
-}
-
-
-/* Event type descriptors */
-void freeType(type_descriptor_t * tp)
-{
- int pos2;
- field_t *f;
-
- if(tp->fmt != NULL) free(tp->fmt);
- if(tp->type == ENUM) {
- for(pos2 = 0; pos2 < tp->labels.position; pos2++) {
- free(tp->labels.array[pos2]);
- }
- sequence_dispose(&(tp->labels));
- for(pos2 = 0; pos2 < tp->labels_values.position; pos2++) {
- free(tp->labels_values.array[pos2]);
- }
- sequence_dispose(&(tp->labels_values));
- }
- if(tp->type == STRUCT) {
- for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
- f = (field_t *) tp->fields.array[pos2];
- free(f->name);
- free(f->description);
- free(f);
- }
- sequence_dispose(&(tp->fields));
- }
-}
-
-void freeNamedType(table_t * t)
-{
- int pos;
- type_descriptor_t * td;
-
- for(pos = 0 ; pos < t->keys.position; pos++) {
- free((char *)t->keys.array[pos]);
- td = (type_descriptor_t*)t->values.array[pos];
- freeType(td);
- free(td);
- }
-}
-
-void freeTypes(sequence_t *t)
-{
- int pos;
- type_descriptor_t *tp;
-
- for(pos = 0 ; pos < t->position; pos++) {
- tp = (type_descriptor_t *)t->array[pos];
- freeType(tp);
- free(tp);
- }
-}
-
-void freeEvents(sequence_t *t)
-{
- int pos;
- event_t *ev;
-
- for(pos = 0 ; pos < t->position; pos++) {
- ev = (event_t *) t->array[pos];
- free(ev->name);
- free(ev->description);
- sequence_dispose(&ev->fields);
- free(ev);
- }
-
-}
-
-
-/* Extensible array */
-
-void sequence_init(sequence_t *t)
-{
- t->size = 10;
- t->position = 0;
- t->array = (void **)memAlloc(t->size * sizeof(void *));
-}
-
-void sequence_dispose(sequence_t *t)
-{
- t->size = 0;
- free(t->array);
- t->array = NULL;
-}
-
-void sequence_push(sequence_t *t, void *elem)
-{
- void **tmp;
-
- if(t->position >= t->size) {
- tmp = t->array;
- t->array = (void **)memAlloc(t->size * 2 * sizeof(void *));
- memcpy(t->array, tmp, t->size * sizeof(void *));
- t->size = t->size * 2;
- free(tmp);
- }
- t->array[t->position] = elem;
- t->position++;
-}
-
-void *sequence_pop(sequence_t *t)
-{
- if(t->position == 0) printf("Error : trying to pop an empty sequence");
- return t->array[--t->position];
-}
-
-
-/* Hash table API, implementation is just linear search for now */
-
-void table_init(table_t *t)
-{
- sequence_init(&(t->keys));
- sequence_init(&(t->values));
-}
-
-void table_dispose(table_t *t)
-{
- sequence_dispose(&(t->keys));
- sequence_dispose(&(t->values));
-}
-
-void table_insert(table_t *t, char *key, void *value)
-{
- sequence_push(&(t->keys),key);
- sequence_push(&(t->values),value);
-}
-
-void *table_find(table_t *t, char *key)
-{
- int pos;
- for(pos = 0 ; pos < t->keys.position; pos++) {
- if(strcmp((char *)key,(char *)t->keys.array[pos]) == 0)
- return(t->values.array[pos]);
- }
- return NULL;
-}
-
-void table_insert_int(table_t *t, int *key, void *value)
-{
- sequence_push(&(t->keys),key);
- sequence_push(&(t->values),value);
-}
-
-void *table_find_int(table_t *t, int *key)
-{
- int pos;
- for(pos = 0 ; pos < t->keys.position; pos++) {
- if(*key == *(int *)t->keys.array[pos])
- return(t->values.array[pos]);
- }
- return NULL;
-}
-
-
-/* Concatenate strings */
-
-char *appendString(char *s, char *suffix)
-{
- char *tmp;
- if(suffix == NULL) return s;
-
- tmp = (char *)memAlloc(strlen(s) + strlen(suffix) + 1);
- strcpy(tmp,s);
- strcat(tmp,suffix);
- return tmp;
-}
+++ /dev/null
-#ifndef PARSER_H
-#define PARSER_H
-
-/* Extensible array container */
-
-typedef struct _sequence {
- int size;
- int position;
- void **array;
-} sequence_t;
-
-void sequence_init(sequence_t *t);
-void sequence_dispose(sequence_t *t);
-void sequence_push(sequence_t *t, void *elem);
-void *sequence_pop(sequence_t *t);
-
-
-/* Hash table */
-
-typedef struct _table {
- sequence_t keys;
- sequence_t values;
-} table_t;
-
-void table_init(table_t *t);
-void table_dispose(table_t *t);
-void table_insert(table_t *t, char *key, void *value);
-void *table_find(table_t *t, char *key);
-void table_insert_int(table_t *t, int *key, void *value);
-void *table_find_int(table_t *t, int *key);
-
-
-/* Token types */
-
-typedef enum _token_type {
- ENDFILE,
- FORWARDSLASH,
- LANGLEBRACKET,
- RANGLEBRACKET,
- EQUAL,
- QUOTEDSTRING,
- NUMBER,
- NAME
-} token_type_t;
-
-
-/* State associated with a file being parsed */
-typedef struct _parse_file {
- char *name;
- FILE * fp;
- int lineno;
- char *buffer;
- token_type_t type;
- int unget;
- void (*error) (struct _parse_file *, char *);
-} parse_file_t;
-
-void ungetToken(parse_file_t * in);
-char *getToken(parse_file_t *in);
-char *getForwardslash(parse_file_t *in);
-char *getLAnglebracket(parse_file_t *in);
-char *getRAnglebracket(parse_file_t *in);
-char *getQuotedString(parse_file_t *in);
-char *getName(parse_file_t *in);
-int getNumber(parse_file_t *in);
-char *getEqual(parse_file_t *in);
-int seekNextChar(parse_file_t *in);
-
-void skipComment(parse_file_t * in);
-void skipEOL(parse_file_t * in);
-
-/* Some constants */
-
-static const int BUFFER_SIZE = 1024;
-
-
-/* Events data types */
-
-typedef enum _data_type {
- INT_FIXED,
- UINT_FIXED,
- POINTER,
- CHAR,
- UCHAR,
- SHORT,
- USHORT,
- INT,
- UINT,
- LONG,
- ULONG,
- SIZE_T,
- SSIZE_T,
- OFF_T,
- FLOAT,
- STRING,
- ENUM,
- ARRAY,
- SEQUENCE,
- STRUCT,
- UNION,
- NONE
-} data_type_t;
-
-typedef struct _facility facility_t;
-typedef struct _event event_t;
-
-typedef struct _type_descriptor {
- facility_t *fac;
- char * type_name; //used for named type
- data_type_t type;
- char *fmt;
- size_t size;
- sequence_t labels; // for enumeration
- sequence_t labels_values; // for enumeration
- sequence_t labels_description;
- int already_printed;
- sequence_t fields; // for structure, array and sequence (field_t type)
- int custom_write; /* Should we use a custom write function ? */
- int network; /* Is the type a in network byte order ? */
-} type_descriptor_t;
-
-
-/* Fields within types or events */
-typedef struct _field{
- facility_t *fac;
- char *name;
- char *description;
- type_descriptor_t *type;
-} field_t;
-
-
-/* Events definitions */
-
-struct _event {
- facility_t *fac;
- char *name;
- char *description;
- //type_descriptor_t *type;
- sequence_t fields; /* event fields */
- int per_trace; /* Is the event able to be logged to a specific trace ? */
- int per_tracefile; /* Must we log this event in a specific tracefile ? */
- int param_buffer; /* For userspace tracing : takes a buffer as parameter? */
- int no_instrument_function;
- int high_priority;
- int force;
- int compact_data;
-};
-
-struct _facility {
- char * name;
- char * capname;
- char * arch;
- int align; /* Alignment : default 1, 0 no alignment. */
- char * description;
- sequence_t events;
- sequence_t unnamed_types; //FIXME : remove
- table_t named_types;
- unsigned int checksum;
- int user; /* Is this a userspace facility ? */
-};
-
-int getSizeindex(unsigned int value);
-unsigned long long int getSize(parse_file_t *in);
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
-
-void parseFacility(parse_file_t *in, facility_t * fac);
-void parseEvent(facility_t *fac, parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
- table_t * named_types);
-void parseTypeDefinition(facility_t *fac, parse_file_t *in,
- sequence_t * unnamed_types, table_t * named_types);
-type_descriptor_t *parseType(facility_t *fac, parse_file_t *in,
- type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
-void parseFields(facility_t *fac, parse_file_t *in, field_t *f,
- sequence_t * unnamed_types,
- table_t * named_types,
- int tag);
-void checkNamedTypesImplemented(table_t * namedTypes);
-type_descriptor_t * find_named_type(char *name, table_t * named_types);
-void generateChecksum(char * facName,
- unsigned int * checksum, sequence_t * events);
-
-
-/* get attributes */
-char * getNameAttribute(parse_file_t *in);
-char * getFormatAttribute(parse_file_t *in);
-int getSizeAttribute(parse_file_t *in);
-int getValueAttribute(parse_file_t *in, long long *value);
-
-char * getDescription(parse_file_t *in);
-
-
-/* Dynamic memory allocation and freeing */
-
-void * memAlloc(int size);
-char *allocAndCopy(char * str);
-char *appendString(char *s, char *suffix);
-void freeTypes(sequence_t *t);
-void freeType(type_descriptor_t * td);
-void freeEvents(sequence_t *t);
-void freeNamedType(table_t * t);
-void error_callback(parse_file_t *in, char *msg);
-
-
-//checksum part
-static const unsigned int crctab32[] =
-{
-#include "crc32.tab"
-};
-
-static inline unsigned long
-partial_crc32_one(unsigned char c, unsigned long crc)
-{
- return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
-}
-
-static inline unsigned long
-partial_crc32(const char *s, unsigned long crc)
-{
- while (*s)
- crc = partial_crc32_one(*s++, crc);
- return crc;
-}
-
-static inline unsigned long
-crc32(const char *s)
-{
- return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
-}
-
-
-extern char *intOutputTypes[];
-
-extern char *uintOutputTypes[];
-
-extern char *floatOutputTypes[];
-
-
-
-
-#endif // PARSER_H
+++ /dev/null
-#
-# Spec file for genevent
-#
-Summary: Genevent package
-Name: genevent
-Version: 0.22
-License: GPL
-Release: 1
-Group: Applications/Development
-Source: http://ltt.polymtl.ca/packages/%{name}-%{version}.tar.gz
-URL: http://ltt.polymtl.ca
-Packager: Martin Bisson <bissonm@discreet.com>
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
-
-%description
-This packages contains the facility code generator.
-
-%prep
-%setup -q
-
-%build
-make
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT $RPM_BUILD_ROOT/usr/bin
-cp genevent $RPM_BUILD_ROOT/usr/bin/genevent
-
-%files
-/usr/bin/genevent
+++ /dev/null
-<?xml version="1.0"?>
-<facility name="test">
- <description>The kernel facility has events related to kernel execution status.</description>
-
-
- <type name="tasklet_priority">
- <enum>
- <label name="LOW" value="0"> <description>Low priority tasklet</description>
- <label name="HIGH" value="1"> <description>High priority tasklet</description>
- </enum>
- </type>
-
- <type name="irq_mode">
- <enum>
- <label name="user" value="0"> <description>User context</description>
- <label name="kernel" value="1"> <description>Kernel context</description>
- </enum>
- </type>
-
- <type name="mystruct2">
- <struct>
- <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
- <field name="mode"> <description>Are we executing kernel code</description> <typeref name="irq_mode"> </field>
- </struct>
- </type>
-
- <type name="mystruct">
- <struct>
- <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
- <field name="mode"> <description>Are we executing kernel code</description> <typeref name="irq_mode"> </field>
-
- <field name="teststr"><typeref name="mystruct2"></field>
- <field name="myarray">
- <array size="10">
- <uint_fixed size="8">
- </array>
- </field>
- <field name="mysequence">
- <sequence>
- <uint>
- <float size="8">
- </sequence>
- </field>
- <field name="myunion">
- <union>
- <field name="myfloat"><float size="8"></field>
- <field name="myulong"><ulong></field>
- </union>
- </field>
- </struct>
- </type>
-
-
-
-
- <event name="syscall_entry">
- <description>System call entry</description>
- <field name="syscall_id"> <description>Syscall entry number in entry.S</description> <uint size="1"> </field>
- <field name="address"> <description>Address from which call was made</description> <pointer> </field>
- </event>
-
- <event name="syscall_exit">
- <description>System call exit</description>
- </event>
-
- <event name="trap_entry">
- <description>Entry in a trap</description>
- <field name="trap_id"> <description>Trap number</description> <uint size="2"> </field>
- <field name="address"> <description>Address where trap occured</description> <pointer> </field>
- </event>
-
- <event name="trap_exit">
- <description>Exit from a trap</description>
- </event>
-
- <event name="soft_irq_entry">
- <description>Soft IRQ entry</description>
- <field name="softirq_id"> <description>Soft IRQ number</description> <pointer> </field>
- </event>
-
- <event name="soft_irq_exit">
- <description>Soft IRQ exit</description>
- <field name="softirq_id"> <description>Soft IRQ number</description> <pointer> </field>
- </event>
-
- <event name="tasklet_entry">
- <description>Tasklet entry</description>
- <field name="priority"> <description>Tasklet priority</description> <typeref name="tasklet_priority"> </field>
- <field name="address"> <description>Tasklet function address</description> <pointer> </field>
- <field name="data"> <description>Tasklet data address</description> <ulong> </field>
- </event>
-
- <event name="tasklet_exit">
- <description>Tasklet exit</description>
- <field name="priority"> <description>Tasklet priority</description> <typeref name="tasklet_priority"> </field>
- <field name="address"> <description>Tasklet function address</description> <pointer> </field>
- <field name="data"> <description>Tasklet data address</description> <ulong> </field>
- </event>
-
- <event name="irq_entry">
- <description>Entry in an irq</description>
- <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
- <field name="mode"> <description>Are we executing kernel code</description><typeref name=""irq_mode""> </field>
- </event>
-
- <event name="irq_exit">
- <description>Exit from an IRQ</description>
- </event>
-
- <event name="big_array">
- <field name="myarray">
- <array size="10000">
- <array size="2">
- <struct>
- <field name="a"><pointer></field>
- <field name="b"><union>
- <field name="c"><pointer></field>
- </union>
- </field>
- </struct>
- </array>
- </array>
- </field>
- </event>
-
-</facility>
+++ /dev/null
-ifneq ($(KERNELRELEASE),)
-ifneq ($(CONFIG_LTT),)
- obj-m := ltt-control.o ltt-statedump.o
-endif
-
-else
- KERNELDIR ?= /lib/modules/$(shell uname -r)/build
- PWD := $(shell pwd)
- KERNELRELEASE = $(shell cat $(KERNELDIR)/$(KBUILD_OUTPUT)/include/linux/version.h | sed -n 's/.*UTS_RELEASE.*\"\(.*\)\".*/\1/p')
-ifneq ($(INSTALL_MOD_PATH),)
- DEPMOD_OPT := -b $(INSTALL_MOD_PATH)
-endif
-
-default:
- $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
-
-modules_install:
- $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
- if [ -f $(KERNELDIR)/$(KBUILD_OUTPUT)/System.map ] ; then /sbin/depmod -ae -F $(KERNELDIR)/$(KBUILD_OUTPUT)/System.map $(DEPMOD_OPT) $(KERNELRELEASE) ; fi
-
-
-clean:
- $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
-endif
+++ /dev/null
-/* ltt-control.c
- *
- * LTT control module over a netlink socket.
- *
- * Inspired from Relay Apps, by Tom Zanussi and iptables
- *
- * Copyright 2005 -
- * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
- */
-
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/ltt-core.h>
-#include <linux/netlink.h>
-#include <linux/inet.h>
-#include <linux/ip.h>
-#include <linux/security.h>
-#include <linux/skbuff.h>
-#include <linux/types.h>
-#include <net/sock.h>
-#include "ltt-control.h"
-
-
-#define LTTCTLM_BASE 0x10
-#define LTTCTLM_CONTROL (LTTCTLM_BASE + 1) /* LTT control message */
-
-static struct sock *socket;
-
-void ltt_control_input(struct sock *sk, int len)
-{
- struct sk_buff *skb;
- struct nlmsghdr *nlh = NULL;
- u8 *payload = NULL;
- lttctl_peer_msg_t *msg;
- int err;
-
- printk(KERN_ALERT "ltt-control ltt_control_input\n");
-
- while ((skb = skb_dequeue(&sk->sk_receive_queue))
- != NULL) {
-
- nlh = (struct nlmsghdr *)skb->data;
-
- if(security_netlink_recv(skb)) {
- netlink_ack(skb, nlh, EPERM);
- kfree_skb(skb);
- continue;
- }
-
- /* process netlink message pointed by skb->data */
- err = EINVAL;
- payload = NLMSG_DATA(nlh);
- /* process netlink message with header pointed by
- * nlh and payload pointed by payload
- */
- if(nlh->nlmsg_len != sizeof(lttctl_peer_msg_t) + sizeof(struct nlmsghdr)) {
- printk(KERN_ALERT "ltt-control bad message length\n");
- netlink_ack(skb, nlh, EINVAL);
- kfree_skb(skb);
- continue;
- }
- msg = (lttctl_peer_msg_t*)payload;
-
- switch(msg->op) {
- case OP_CREATE:
- err = ltt_control(LTT_CONTROL_CREATE_TRACE, msg->trace_name,
- msg->args);
- break;
- case OP_DESTROY:
- err = ltt_control(LTT_CONTROL_DESTROY_TRACE, msg->trace_name,
- msg->args);
- break;
- case OP_START:
- err = ltt_control(LTT_CONTROL_START, msg->trace_name,
- msg->args);
- break;
- case OP_STOP:
- err = ltt_control(LTT_CONTROL_STOP, msg->trace_name,
- msg->args);
- break;
- default:
- err = EBADRQC;
- printk(KERN_INFO "ltt-control invalid operation\n");
- }
- netlink_ack(skb, nlh, err);
- kfree_skb(skb);
- }
-}
-
-
-static int ltt_control_init(void)
-{
- printk(KERN_ALERT "ltt-control init\n");
-
- socket = netlink_kernel_create(NETLINK_LTT, 1,
- ltt_control_input, THIS_MODULE);
- if(socket == NULL) return -EPERM;
- else return 0;
-}
-
-static void ltt_control_exit(void)
-{
- printk(KERN_ALERT "ltt-control exit\n");
-
- sock_release(socket->sk_socket);
-}
-
-
-module_init(ltt_control_init)
-module_exit(ltt_control_exit)
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Mathieu Desnoyers");
-MODULE_DESCRIPTION("Linux Trace Toolkit Controller");
-
+++ /dev/null
-#ifndef _LTT_CONTROL_H
-#define _LTT_CONTROL_H
-
-
-//enum trace_mode {
-// TRACE_NORMAL,
-// TRACE_FLIGHT
-//};
-
-enum trace_op {
- OP_CREATE,
- OP_DESTROY,
- OP_START,
- OP_STOP,
- OP_ALIGN,
- OP_NONE
-};
-
-typedef struct lttctl_peer_msg {
- char trace_name[NAME_MAX];
- enum trace_op op;
- union ltt_control_args args;
-} lttctl_peer_msg_t;
-
-#endif //_LTT_CONTROL_H
-
+++ /dev/null
-/* ltt-state-dump.c
- *
- * Lunix Trace Toolkit Kernel State Dump
- *
- * Copyright 2005 -
- * Jean-Hugues Deschenes <jean-hugues.deschenes@polymtl.ca>
- *
- * Changes:
- * Eric Clement: add listing of network IP interface
- */
-
-#include <linux/config.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/ltt-core.h>
-#include <linux/netlink.h>
-#include <linux/inet.h>
-#include <linux/ip.h>
-#include <linux/kthread.h>
-#include <linux/proc_fs.h>
-#include <linux/file.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/cpu.h>
-#include <linux/ltt/ltt-facility-statedump.h>
-
-#define NB_PROC_CHUNK 20
-
-#include <linux/netdevice.h>
-#include <linux/inetdevice.h>
-
-/* in modules.c */
-extern int ltt_enumerate_modules(void);
-
-static inline int ltt_enumerate_network_ip_interface(void)
-{
- struct net_device *list;
- struct in_device *in_dev = NULL;
- struct in_ifaddr *ifa = NULL;
-
- read_lock(&dev_base_lock);
- for(list=dev_base; list != NULL; list=list->next) {
-
- if(list->flags & IFF_UP) {
- in_dev = in_dev_get(list);
-
- if(in_dev) {
- for (ifa = in_dev->ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
- trace_statedump_enumerate_network_ip_interface(list->name,
- ifa->ifa_address,
- LTTNG_UP);
- }
- in_dev_put(in_dev);
- }
- } else {
- trace_statedump_enumerate_network_ip_interface(list->name,
- 0,
- LTTNG_DOWN);
- }
- }
- read_unlock(&dev_base_lock);
-
- return 0;
-}
-
-static inline int ltt_enumerate_file_descriptors(void)
-{
- struct task_struct * t = &init_task;
- unsigned int i;
- struct file * filp;
- char *tmp = (char*)__get_free_page(GFP_KERNEL), *path;
- struct fdtable *fdt;
-
- /* Enumerate active file descriptors */
-
- do {
- read_lock(&tasklist_lock);
- if(t != &init_task) atomic_dec(&t->usage);
- t = next_task(t);
- atomic_inc(&t->usage);
- read_unlock(&tasklist_lock);
-
- task_lock(t);
- if (t->files) {
- spin_lock(&t->files->file_lock);
- fdt = files_fdtable(t->files);
- for (i=0; i < fdt->max_fds; i++) {
- filp = fcheck_files(t->files, i);
- if (!filp)
- continue;
- path = d_path(filp->f_dentry, filp->f_vfsmnt, tmp, PAGE_SIZE);
-
- /* Make sure we give at least some info */
- if(IS_ERR(path))
- trace_statedump_enumerate_file_descriptors(filp->f_dentry->d_name.name, t->pid, i);
- else
- trace_statedump_enumerate_file_descriptors(path, t->pid, i);
- }
- spin_unlock(&t->files->file_lock);
- }
- task_unlock(t);
-
- } while( t != &init_task );
-
- free_page((unsigned long)tmp);
-
- return 0;
-}
-
-static inline int ltt_enumerate_vm_maps(void)
-{
- struct mm_struct *mm;
- struct task_struct * t = &init_task;
- struct vm_area_struct * map;
- unsigned long ino = 0;
-
- do {
- read_lock(&tasklist_lock);
- if(t != &init_task) atomic_dec(&t->usage);
- t = next_task(t);
- atomic_inc(&t->usage);
- read_unlock(&tasklist_lock);
-
- /* get_task_mm does a task_lock... */
-
- mm = get_task_mm(t);
-
- if (mm)
- {
- map = mm->mmap;
-
- if(map)
- {
- down_read(&mm->mmap_sem);
-
- while (map) {
- if (map->vm_file) {
- ino = map->vm_file->f_dentry->d_inode->i_ino;
- } else {
- ino = 0;
- }
-
- trace_statedump_enumerate_vm_maps(t->pid, (void *)map->vm_start, (void *)map->vm_end, map->vm_flags, map->vm_pgoff << PAGE_SHIFT, ino);
- map = map->vm_next;
- }
-
- up_read(&mm->mmap_sem);
- }
-
- mmput(mm);
- }
-
- } while( t != &init_task );
-
- return 0;
-}
-
-#if defined( CONFIG_ARM )
-/* defined in arch/arm/kernel/irq.c because of dependency on statically-defined lock & irq_desc */
-int ltt_enumerate_interrupts(void);
-#else
-static inline int ltt_enumerate_interrupts(void)
-{
- unsigned int i;
- unsigned long flags = 0;
-
- /* needs irq_desc */
-
- for(i = 0; i < NR_IRQS; i++)
- {
- struct irqaction * action;
-
- spin_lock_irqsave(&irq_desc[i].lock, flags);
-
-
- for (action=irq_desc[i].action; action; action = action->next)
- trace_statedump_enumerate_interrupts(
- irq_desc[i].handler->typename,
- action->name,
- i );
-
- spin_unlock_irqrestore(&irq_desc[i].lock, flags);
- }
-
- return 0;
-}
-#endif
-
-static inline int ltt_enumerate_process_states(void)
-{
- struct task_struct * t = &init_task;
- struct task_struct * p = t;
- enum lttng_process_status status;
- enum lttng_thread_type type;
- enum lttng_execution_mode mode;
- enum lttng_execution_submode submode;
-
- do {
- mode = LTTNG_MODE_UNKNOWN;
- submode = LTTNG_UNKNOWN;
-
- read_lock(&tasklist_lock);
- if(t != &init_task) {
- atomic_dec(&t->usage);
- t = next_thread(t);
- }
- if(t == p) {
- t = p = next_task(t);
- }
- atomic_inc(&t->usage);
- read_unlock(&tasklist_lock);
-
- task_lock(t);
-
- if(t->exit_state == EXIT_ZOMBIE)
- status = LTTNG_ZOMBIE;
- else if(t->exit_state == EXIT_DEAD)
- status = LTTNG_DEAD;
- else if(t->state == TASK_RUNNING)
- {
- /* Is this a forked child that has not run yet? */
- if( list_empty(&t->run_list) )
- {
- status = LTTNG_WAIT_FORK;
- }
- else
- {
- /* All tasks are considered as wait_cpu; the viewer will sort out if the task was relly running at this time. */
- status = LTTNG_WAIT_CPU;
- }
- }
- else if(t->state & (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE))
- {
- /* Task is waiting for something to complete */
- status = LTTNG_WAIT;
- }
- else
- status = LTTNG_UNNAMED;
-
- submode = LTTNG_NONE;
-
-
- /* Verification of t->mm is to filter out kernel threads;
- Viewer will further filter out if a user-space thread was in syscall mode or not */
- if(t->mm)
- type = LTTNG_USER_THREAD;
- else
- type = LTTNG_KERNEL_THREAD;
-
- trace_statedump_enumerate_process_state(t->pid, t->parent->pid, t->comm,
- type, mode, submode, status);
-
- task_unlock(t);
-
- } while( t != &init_task );
-
- return 0;
-}
-
-void ltt_statedump_work_func(void *sem)
-{
- /* Our job is just to release the semaphore so
- that we are sure that each CPU has been in syscall
- mode before the end of ltt_statedump_thread */
- up((struct semaphore *)sem);
-}
-
-static struct work_struct cpu_work[NR_CPUS];
-
-int ltt_statedump_thread(void *data)
-{
- struct semaphore work_sema4;
- int cpu;
-
- printk("ltt_statedump_thread\n");
-
- ltt_enumerate_process_states();
-
- ltt_enumerate_file_descriptors();
-
- ltt_enumerate_modules();
-
- ltt_enumerate_vm_maps();
-
- ltt_enumerate_interrupts();
-
- ltt_enumerate_network_ip_interface();
-
- /* Fire off a work queue on each CPU. Their sole purpose in life
- * is to guarantee that each CPU has been in a state where is was in syscall
- * mode (i.e. not in a trap, an IRQ or a soft IRQ) */
- sema_init(&work_sema4, 1 - num_online_cpus());
-
- lock_cpu_hotplug();
- for_each_online_cpu(cpu)
- {
- INIT_WORK(&cpu_work[cpu], ltt_statedump_work_func, &work_sema4);
-
- schedule_delayed_work_on(cpu,&cpu_work[cpu],0);
- }
- unlock_cpu_hotplug();
-
- /* Wait for all work queues to have completed */
- down(&work_sema4);
-
- /* Our work is done */
- printk("trace_statedump_statedump_end\n");
- trace_statedump_statedump_end();
-
- do_exit(0);
-
- return 0;
-}
-
-int ltt_statedump_start(struct ltt_trace_struct *trace)
-{
- printk("ltt_statedump_start\n");
-
- kthread_run( ltt_statedump_thread,
- NULL,
- "ltt_statedump");
-
- return 0;
-}
-
-
-/* Dynamic facility. */
-
-static int __init statedump_init(void)
-{
- int ret;
- printk(KERN_INFO "LTT : ltt-facility-statedump init\n");
-
- ret = ltt_module_register(LTT_FUNCTION_STATEDUMP,
- ltt_statedump_start,THIS_MODULE);
-
- return ret;
-}
-
-static void __exit statedump_exit(void)
-{
- ltt_module_unregister(LTT_FUNCTION_STATEDUMP);
-}
-
-module_init(statedump_init)
-module_exit(statedump_exit)
-
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Jean-Hugues Deschenes");
-MODULE_DESCRIPTION("Linux Trace Toolkit Statedump");
-
+++ /dev/null
-
-CC=gcc
-INCLUDE_DIR?=/usr/include
-LIB_DIR?=/usr/lib
-RANLIB=ranlib
-
-LTT_CFLAGS=-I. -O2 -L. -fPIC
-# note : x86_64 needs -fPIC ? FIXME
-
-#For testing lib ltt-usertrace-fast
-#CFLAGS+=-DLTT_SUBBUF_SIZE_CPU=134217728
-#CFLAGS+=-DLTT_NULL_OUTPUT_TEST
-
-all: libs samples
-
-#SAMPLE PROGRAMS
-
-samples: sample sample-highspeed sample-printf \
- sample-instrument-fct sample-thread-slow sample-thread-fast sample-thread-brand sample-block
-
-sample: sample.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
-sample-block: sample-block.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
-
-sample-thread-brand: sample-thread-brand.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
-
-sample-highspeed: sample-highspeed.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-usertrace-fast -lltt-loader-user_generic -o $@ $^
-
-sample-printf: sample-printf.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
-
-sample-instrument-fct: sample-instrument-fct.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -g -finstrument-functions -lltt-instrument-functions -o $@ $^
-
-sample-thread-slow: sample-thread-slow.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -lltt-loader-user_generic -o $@ $^
-
-sample-thread-fast: sample-thread-fast.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -lltt-usertrace-fast -lltt-loader-user_generic -o $@ $^
-
-
-#LIBRAIRIES
-
-libs: libltt-instrument-functions.a libltt-instrument-functions.so.0 \
- libltt-usertrace-fast.a libltt-usertrace-fast.so.0 \
- libltt-loader-user_generic.a libltt-loader-user_generic.so.0
-
-libltt-usertrace-fast.a: ltt-usertrace-fast.o
- @rm -f libltt-usertrace-fast.a
- $(AR) rc $@ $^
- $(RANLIB) $@
-
-libltt-usertrace-fast.so.0: ltt-usertrace-fast.o
- @rm -f libltt-usertrace-fast.so libltt-usertrace-fast.so.0
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-usertrace-fast.so -o $@ $^
- ln -s libltt-usertrace-fast.so.0 libltt-usertrace-fast.so
-
-libltt-instrument-functions.a: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
- @rm -f libltt-instrument-functions.a
- $(AR) rc $@ $^
- $(RANLIB) $@
-
-libltt-instrument-functions.so.0: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
- @rm -f libltt-instrument-functions.so libltt-instrument-functions.so.0
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-instrument-functions.so -o $@ $^
- ln -s libltt-instrument-functions.so.0 libltt-instrument-functions.so
-
-libltt-loader-user_generic.a: ltt-facility-loader-user_generic.o
- @rm -f libltt-loader-user_generic.a
- $(AR) rc $@ $^
- $(RANLIB) $@
-
-libltt-loader-user_generic.so.0: ltt-facility-loader-user_generic.o
- @rm -f libltt-loader-user_generic.so libltt-loader-user_generic.so.0
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-loader-user_generic.so -o $@ $^
- ln -s libltt-loader-user_generic.so.0 libltt-loader-user_generic.so
-
-%.o: %.c
- $(CC) $(LTT_CFLAGS) $(CFLAGS) -c -o $@ $+
-
-.PHONY : clean install libs install_libs install_headers samples
-
-install_headers:
- if [ ! -e "$(INCLUDE_DIR)/ltt" ] ; then mkdir $(INCLUDE_DIR)/ltt ; fi
- cp -f ltt/*.h $(INCLUDE_DIR)/ltt
-
-install_libs:
- cp -df libltt-instrument-functions.so* libltt-instrument-functions.a $(LIB_DIR)
- cp -df libltt-usertrace-fast.so* libltt-usertrace-fast.a $(LIB_DIR)
- cp -df libltt-loader-user_generic.so* libltt-loader-user_generic.a $(LIB_DIR)
-
-install: install_headers libs install_libs
-
-clean:
- find . -name \*~ | xargs rm -fr *.o sample-thread sample sample-highspeed sample-printf sample-instrument-fct libltt-instrument-functions.so* libltt-instrument-functions.a libltt-usertrace-fast.a libltt-usertrace-fast.so* libltt-loader-user_generic.so* libltt-loader-user_generic.a sample-thread-slow sample-thread-fast sample-thread-brand sample-block java/*.class java/Sample.h java/TestBrand.h
+++ /dev/null
-
-LTTng usertrace package
-
-Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
-March 2006
-
-This package contains all the user space headers and c files necessary to make
-your application and library trace through an active LTTng tracer. Here is a
-short quickstart guide of it.
-
-Here are the currently supported architectures :
-x86
-(please add the ltt_trace_generic and ltt_register_generic system calls to
-other architectures as you need them : it will work magically)
-
-* Compile your kernel with the latest LTTng patch. Make sure the option
- "Allow tracing from userspace" is _active_!
- See the QUICKSTART guide at http://ltt.polymtl.ca/ for details about how to
- setup a working tracer and viewer. See the genevent installation step : it is
- required for method #2 below.
-
-* Extract the latest ltt-usertrace archive :
-su
-cd /usr/src
-wget http://ltt.polymtl.ca/packages/ltt-usertrace-x.x.tar.gz
-gzip -cd ltt-usertrace-x.x.tar.gz | tar xvof -
-
-* Build the sample programs and install the headers and librairies into your
-system :
-(32 bits)
-su
-cd /usr/src/ltt-usertrace
-make clean
-make install (will build and install headers and libraries)
-make
-(64 bits)
-su
-cd /usr/src/ltt-usertrace
-make clean
-LIB_DIR=/usr/lib64 make install CFLAGS=-m64
-make CFLAGS=-m64
-
-Feel free to look at the sample programs and the Makefile : they demonstrate
-very well the features of the usertrace package and how to use them.
-
-* There are three ways to trace information from your application. The choice
- will principally depend on the trace data rate.
-
-1) Easy way, but slow (printf style)
- See sample-printf.c for code example.
-
-- Add the following statements to your program source (the define must come
- _before_ the includes!) :
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-#include <ltt/ltt-facility-custom-user_generic.h>
-
-Note the define of LTT_BLOCKING to 1 : if a trace buffer is full, your
-application will block. The default of this parameter is 0 (non blocking) :
-events are lost when trace buffer is full. The choice is up to you.
-
-- Add something like the following sample line in your code. Note that this is a
- very standard format string, this is only a suggested presentation.
-
-trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
- __FILE__, __func__, __LINE__, count);
-
-- Compile your application with at least these parameters to gcc (it is splitted
- on two lines, joined by a "\") :
-gcc -D LTT_SHOW_DEBUG -I /usr/src/usertrace-generic -o myapp myapp.c \
- /usr/src/usertrace-generic/ltt-facility-loader-user_generic.c
-
-To see what the final result looks like :
-- Start tracing
-- Start your application
- ** You should see the following message when your program starts and the
- LTT_SHOW_DEBUG is defined :
- "LTT : ltt-facility-user_generic init in userspace"
- If you don't then you forgot to compile the facility loader in your
- application. If you find this output annoying, you can remove the
- "-D LTT_SHOW_DEBUG" gcc parameter, which will make the facility loader
- silent.
-- Stop tracing
-Then, to see only the user_generic events :
-lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic"
-
-It will show :
-user_generic.slow_printf: 35885.922829472 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 0." }
-user_generic.slow_printf: 35886.925685289 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 1." }
-...
-
-
-
-2) The second way to log events is still easy. The advantage is that it
- will make it easier to identify your data in the trace viewer afterward.
- Please read the comments in method 1) explained previously, as they
- are not repeated here.
- See sample.c and sample-thread-slow.c for code example.
-
-- Go to the ltt-usertrace directory
-su
-cd /usr/src/ltt-usertrace
-
-- Create your own facility (i.e. user_myfacility.xml).
- See the ones available in /usr/share/LinuxTraceToolkitViewer/facilities for
- examples.
- You facility _must_ be named following this standard : "user_*", where * is
- whatever you like. If it is not, it will be rejected by the kernel with a
- Operation not permitted (can be seen with the -D LTT_SHOW_DEBUG compilation
- parameter).
-
-user_myfacility.xml:
-
-<?xml version="1.0"?>
-<facility name="user_myfacility">
- <description>Sample facility</description>
- <event name="myevent">
- <description>Sample event</description>
- <field name="file"><string></field>
- <field name="function"><string></field>
- <field name="line"><int></field>
- <field name="firstval"><long></field>
- <field name="secondval"><pointer></field>
- </event>
-</facility>
-
-- AN IMPORTANT STEP FOLLOWS :
- *copy* the user_myfacility.xml file in your system :
-su
-cp user_myfacility.xml /usr/share/LinuxTraceToolkitViewer/facilities
-
-- Use genevent to create the c code and headers :
-su
-cd /tmp
-mkdir genevent
-cd genevent
-for a in /usr/share/LinuxTraceToolkitViewer/facilities/user_*.xml;
- do /usr/local/bin/genevent $a;
-done
-cd /usr/src/usertrace-generic
-cp /tmp/genevent/*load* .
-cd ltt
-cp /tmp/genevent/ltt-facility-id-user_myfacility.h .
-cp /tmp/genevent/ltt-facility-user_myfacility.h .
-cd ..
-make install
-
-- Add the following statements to your program source (the define must come
- _before_ the includes!) :
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_myfacility.h>
-
-- Add a call following the trace_user_myfacility_myevent function found in
- /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
-For instance :
-trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
-
-- Compile your application with at least these parameters to gcc (it is splitted
- on two lines, joined by a "\") :
-gcc -I /usr/src/usertrace-generic -o myapp myapp.c \
- /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
-
-To see what the final result looks like :
-- Start tracing
-- Start your application
-- Stop tracing
-Then, to see only the user_myfacility events :
-lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
-
-It will show, for example :
-user_myfacility.myevent: 39507.805584526 (/cpu_1), 15829, 15736, SYSCALL { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
-
-
-3) The third way to trace information from your application
-
-This method is cleary the _FASTEST_. It is principally I/O (disk and memory)
-bound. It will create a companion process for each of you program's thread which
-will dump the tracing information into /tmp/ltt-usertrace.
-
-See sample-highspeed.c and sample-thread-fast.c for code example.
-
-- Add the following statements to your program source (the define must come
- _before_ the includes!) :
-
-#define LTT_TRACE
-#define LTT_TRACE_FAST
-#include <ltt/ltt-facility-user_myfacility.h>
-
-- Add a call following the trace_user_myfacility_myevent function found in
- /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
-For instance :
-trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
-
-- Compile your application with at least these parameters to gcc (it is splitted
- on two lines, joined by a "\") :
-gcc -lltt-usertrace-fast -I /usr/src/usertrace-generic -o myapp myapp.c \
- /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
-
-It requires a supplementary operation when you take the trace :
-- Start tracing (with lttctl)
-- Start your application
-- Let your application run...
-- Stop tracing
-- Move or copy /tmp/ltt-usertrace info your trace.
-i.e., if your trace is in /tmp/trace1 :
-su
-mv /tmp/ltt-usertrace /tmp/trace1
-
-
-Then, to see only the user_myfacility events :
-lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
-
-It will show, for example :
-user_myfacility.myevent: 39507.805584526 (/ltt-usertrace/process-26174.26174.39236180500380_0), 15829, 15736, USER_MODE { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
-
-
-
-* Fun feature : function instrumentation
-
-Here is how to generate a full trace of you program function calls.
-See the sample-instrument-fct.c example program.
-
-- Compile your application with at least these parameters to gcc (it is splitted
- on two lines, joined by a "\") :
-gcc -g -finstrument-functions \
- -lltt-instrument-functions -o myapp myapp.c
-
-To see what the final result looks like :
-- Start tracing
-- Start your application
-- Stop tracing
-Then, to see only the function_entry and function_exit events :
-lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic & (event.name=function_entry & event.name=function_exit)"
-
-It will show, for example :
-user_generic.function_entry: 59329.709939111 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
-user_generic.function_exit: 59329.709944613 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
-
-you can then use (from the binutils package)
-addr2line -e sample-instrument-fct -i -f 0x8048454
-Which shows :
-test_function
-/usr/src/usertrace-generic/sample-instrument-fct.c:12
-
-The lookup in LTTV through libbfd has not been implemented yet.
-
-
-* Instrumentation of a java program
-
-See the java/ directory of this package. You will have to create a C library
-that holds the tracing functions, following the java-instrument-string.c. It has
-to be called from the Java code as shown in Sample.java.
-
-The generate.sh scripts compiles and executes the Java program with the JNI
-tracing library.
-
+++ /dev/null
-// The Sample.java file
-public class Sample
-{
- // Declaration of the Native (C) function
- private static native void trace_java_generic_string(String arg);
- static {
- System.loadLibrary("ltt-java-string");
- }
-
- public static void main(String[] args)
- {
- Sample.trace_java_generic_string("Tracing from java");
- }
-}
+++ /dev/null
-
-import ltt.*;
-
-// The Sample.java file
-public class TestBrand
-{
- public static void main(String[] args)
- {
- ltt.ThreadBrand.trace_java_generic_thread_brand("Brand_test");
- }
-}
+++ /dev/null
-
-package ltt;
-
-// The ThreadBrand.java file
-public class ThreadBrand
-{
- // Declaration of the Native (C) function
- public static native void trace_java_generic_thread_brand(String arg);
- static {
- System.loadLibrary("ltt-java-thread_brand");
- }
-}
+++ /dev/null
-#!/bin/sh
-
-export CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/bin
-
-#Sample
-javac Sample.java
-javah -jni Sample
-gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \
- -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \
- -shared -Wl,-soname,libltt-java-string \
- -o libltt-java-string.so ltt-java-string.c \
- ../ltt-facility-loader-user_generic.c
-LD_LIBRARY_PATH=. java Sample
-
-#TestBrand
-echo javac Threadbrand
-javac -d . ThreadBrand.java
-echo javah Threadbrand
-javah -jni ltt.ThreadBrand
-echo gcc
-gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \
- -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \
- -shared -Wl,-soname,libltt-java-thread_brand \
- -o libltt-java-thread_brand.so ltt-java-thread_brand.c \
- ../ltt-facility-loader-user_generic.c
-echo javac test
-javac TestBrand.java
-echo run
-LD_LIBRARY_PATH=. java TestBrand
+++ /dev/null
-
-#include <jni.h>
-#include "Sample.h"
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-JNIEXPORT void JNICALL Java_Sample_trace_1java_1generic_1string
- (JNIEnv *env, jobject obj, jstring jstr)
-{
- const char *str;
- str = (*env)->GetStringUTFChars(env, jstr, NULL);
- if (str == NULL) return; // out of memory error thrown
- trace_user_generic_string(str);
- (*env)->ReleaseStringUTFChars(env, jstr, str);
-}
-
+++ /dev/null
-
-#include <jni.h>
-#include "Sample.h"
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-JNIEXPORT void JNICALL Java_ltt_ThreadBrand_trace_1java_1generic_1thread_1brand
- (JNIEnv *env, jclass jc, jstring jstr)
-{
- const char *str;
- str = (*env)->GetStringUTFChars(env, jstr, NULL);
- if (str == NULL) return; // out of memory error thrown
- trace_user_generic_thread_brand(str);
- (*env)->ReleaseStringUTFChars(env, jstr, str);
-}
-
+++ /dev/null
-/*
- * ltt-facility-loader-user_generic.c
- *
- * (C) Copyright 2005 -
- * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
- *
- * Contains the LTT user space facility loader.
- *
- */
-
-
-#define LTT_TRACE
-#include <error.h>
-#include <stdio.h>
-#include <ltt/ltt-usertrace.h>
-#include "ltt-facility-loader-user_generic.h"
-
-static struct user_facility_info facility = {
- .name = LTT_FACILITY_NAME,
- .num_events = LTT_FACILITY_NUM_EVENTS,
-#ifndef LTT_PACK
- .alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,
-#else
- .alignment = 0,
-#endif //LTT_PACK
- .checksum = LTT_FACILITY_CHECKSUM,
- .int_size = sizeof(int),
- .long_size = sizeof(long),
- .pointer_size = sizeof(void*),
- .size_t_size = sizeof(size_t)
-};
-
-static void __attribute__((constructor)) __ltt_user_init(void)
-{
- int err;
-#ifdef LTT_SHOW_DEBUG
- printf("LTT : ltt-facility-user_generic init in userspace\n");
-#endif //LTT_SHOW_DEBUG
-
- err = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);
- LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
-
- if (err) {
-#ifdef LTT_SHOW_DEBUG
- perror("Error in ltt_register_generic");
-#endif //LTT_SHOW_DEBUG
- }
-}
-
+++ /dev/null
-#ifndef _LTT_FACILITY_LOADER_USER_GENERIC_H_
-#define _LTT_FACILITY_LOADER_USER_GENERIC_H_
-
-#include <ltt/ltt-usertrace.h>
-#include <ltt/ltt-facility-id-user_generic.h>
-
-ltt_facility_t ltt_facility_user_generic;
-ltt_facility_t ltt_facility_user_generic_B1865E44;
-
-#define LTT_FACILITY_SYMBOL ltt_facility_user_generic
-#define LTT_FACILITY_CHECKSUM_SYMBOL ltt_facility_user_generic_B1865E44
-#define LTT_FACILITY_CHECKSUM 0xB1865E44
-#define LTT_FACILITY_NAME "user_generic"
-#define LTT_FACILITY_NUM_EVENTS facility_user_generic_num_events
-
-#define LTT_FACILITY_ALIGNMENT 1
-
-#endif //_LTT_FACILITY_LOADER_USER_GENERIC_H_
+++ /dev/null
-/****************************************************************************
- * ltt-instrument-functions.c
- *
- * Mathieu Desnoyers
- * March 2006
- */
-
-#define inline inline __attribute__((always_inline))
-
-#define LTT_TRACE
-#define LTT_TRACE_FAST
-#include <ltt/ltt-usertrace-fast.h>
-#include <ltt/ltt-facility-user_generic.h>
-
-void __attribute__((no_instrument_function)) __cyg_profile_func_enter (
- void *this_fn,
- void *call_site)
-{
- /* don't care about the return value */
- trace_user_generic_function_entry(this_fn, call_site);
-}
-
-void __attribute__((no_instrument_function)) __cyg_profile_func_exit (
- void *this_fn,
- void *call_site)
-{
- /* don't care about the return value */
- trace_user_generic_function_exit(this_fn, call_site);
-}
-
+++ /dev/null
-/* LTTng user-space "fast" library
- *
- * This daemon is spawned by each traced thread (to share the mmap).
- *
- * Its job is to dump periodically this buffer to disk (when it receives a
- * SIGUSR1 from its parent).
- *
- * It uses the control information in the shared memory area (producer/consumer
- * count).
- *
- * When the parent thread dies (yes, those thing may happen) ;) , this daemon
- * will flush the last buffer and write it to disk.
- *
- * Supplement note for streaming : the daemon is responsible for flushing
- * periodically the buffer if it is streaming data.
- *
- *
- * Notes :
- * shm memory is typically limited to 4096 units (system wide limit SHMMNI in
- * /proc/sys/kernel/shmmni). As it requires computation time upon creation, we
- * do not use it : we will use a shared mmap() instead which is passed through
- * the fork().
- * MAP_SHARED mmap segment. Updated when msync or munmap are called.
- * MAP_ANONYMOUS.
- * Memory mapped by mmap() is preserved across fork(2), with the same
- * attributes.
- *
- * Eventually, there will be two mode :
- * * Slow thread spawn : a fork() is done for each new thread. If the process
- * dies, the data is not lost.
- * * Fast thread spawn : a pthread_create() is done by the application for each
- * new thread.
- *
- * We use a timer to check periodically if the parent died. I think it is less
- * intrusive than a ptrace() on the parent, which would get every signal. The
- * side effect of this is that we won't be notified if the parent does an
- * exec(). In this case, we will just sit there until the parent exits.
- *
- *
- * Copyright 2006 Mathieu Desnoyers
- *
- */
-
-#define inline inline __attribute__((always_inline))
-
-#define _GNU_SOURCE
-#define LTT_TRACE
-#define LTT_TRACE_FAST
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <syscall.h>
-#include <features.h>
-#include <pthread.h>
-#include <malloc.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#include <ltt/ltt-usertrace.h>
-
-#define gettid() syscall(__NR_gettid)
-
-#ifdef LTT_SHOW_DEBUG
-#define dbg_printf(...) printf(__VA_ARGS__)
-#else
-#define dbg_printf(...)
-#endif //LTT_SHOW_DEBUG
-
-
-enum force_switch_mode { FORCE_ACTIVE, FORCE_FLUSH };
-
-/* Writer (the traced application) */
-
-__thread struct ltt_trace_info *thread_trace_info = NULL;
-
-void ltt_usertrace_fast_buffer_switch(void)
-{
- struct ltt_trace_info *tmp = thread_trace_info;
- if(tmp)
- kill(tmp->daemon_id, SIGUSR1);
-}
-
-/* The cleanup should never be called from a signal handler */
-static void ltt_usertrace_fast_cleanup(void *arg)
-{
- struct ltt_trace_info *tmp = thread_trace_info;
- if(tmp) {
- thread_trace_info = NULL;
- kill(tmp->daemon_id, SIGUSR2);
- munmap(tmp, sizeof(*tmp));
- }
-}
-
-/* Reader (the disk dumper daemon) */
-
-static pid_t traced_pid = 0;
-static pid_t traced_tid = 0;
-static int parent_exited = 0;
-static int fd_process = -1;
-static char outfile_name[PATH_MAX];
-static char identifier_name[PATH_MAX];
-
-/* signal handling */
-static void handler_sigusr1(int signo)
-{
- dbg_printf("LTT Signal %d received : parent buffer switch.\n", signo);
-}
-
-static void handler_sigusr2(int signo)
-{
- dbg_printf("LTT Signal %d received : parent exited.\n", signo);
- parent_exited = 1;
-}
-
-static void handler_sigalarm(int signo)
-{
- dbg_printf("LTT Signal %d received\n", signo);
-
- if(getppid() != traced_pid) {
- /* Parent died */
- dbg_printf("LTT Parent %lu died, cleaning up\n", traced_pid);
- traced_pid = 0;
- }
- alarm(3);
-}
-
-/* Do a buffer switch. Don't switch if buffer is completely empty */
-static void flush_buffer(struct ltt_buf *ltt_buf, enum force_switch_mode mode)
-{
- uint64_t tsc;
- int offset_begin, offset_end, offset_old;
- int reserve_commit_diff;
- int consumed_old, consumed_new;
- int commit_count, reserve_count;
- int end_switch_old;
-
- do {
- offset_old = atomic_read(<t_buf->offset);
- offset_begin = offset_old;
- end_switch_old = 0;
- tsc = ltt_get_timestamp();
- if(tsc == 0) {
- /* Error in getting the timestamp : should not happen : it would
- * mean we are called from an NMI during a write seqlock on xtime. */
- return;
- }
-
- if(SUBBUF_OFFSET(offset_begin, ltt_buf) != 0) {
- offset_begin = SUBBUF_ALIGN(offset_begin, ltt_buf);
- end_switch_old = 1;
- } else {
- /* we do not have to switch : buffer is empty */
- return;
- }
- if(mode == FORCE_ACTIVE)
- offset_begin += ltt_subbuf_header_len(ltt_buf);
- /* Always begin_switch in FORCE_ACTIVE mode */
-
- /* Test new buffer integrity */
- reserve_commit_diff =
- atomic_read(
- <t_buf->reserve_count[SUBBUF_INDEX(offset_begin, ltt_buf)])
- - atomic_read(
- <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
- if(reserve_commit_diff == 0) {
- /* Next buffer not corrupted. */
- if(mode == FORCE_ACTIVE
- && (offset_begin-atomic_read(<t_buf->consumed))
- >= ltt_buf->alloc_size) {
- /* We do not overwrite non consumed buffers and we are full : ignore
- switch while tracing is active. */
- return;
- }
- } else {
- /* Next subbuffer corrupted. Force pushing reader even in normal mode */
- }
-
- offset_end = offset_begin;
- } while(atomic_cmpxchg(<t_buf->offset, offset_old, offset_end)
- != offset_old);
-
-
- if(mode == FORCE_ACTIVE) {
- /* Push the reader if necessary */
- do {
- consumed_old = atomic_read(<t_buf->consumed);
- /* If buffer is in overwrite mode, push the reader consumed count if
- the write position has reached it and we are not at the first
- iteration (don't push the reader farther than the writer).
- This operation can be done concurrently by many writers in the
- same buffer, the writer being at the fartest write position sub-buffer
- index in the buffer being the one which will win this loop. */
- /* If the buffer is not in overwrite mode, pushing the reader only
- happen if a sub-buffer is corrupted */
- if((SUBBUF_TRUNC(offset_end-1, ltt_buf)
- - SUBBUF_TRUNC(consumed_old, ltt_buf))
- >= ltt_buf->alloc_size)
- consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
- else {
- consumed_new = consumed_old;
- break;
- }
- } while(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
- != consumed_old);
-
- if(consumed_old != consumed_new) {
- /* Reader pushed : we are the winner of the push, we can therefore
- reequilibrate reserve and commit. Atomic increment of the commit
- count permits other writers to play around with this variable
- before us. We keep track of corrupted_subbuffers even in overwrite
- mode :
- we never want to write over a non completely committed sub-buffer :
- possible causes : the buffer size is too low compared to the unordered
- data input, or there is a writer who died between the reserve and the
- commit. */
- if(reserve_commit_diff) {
- /* We have to alter the sub-buffer commit count : a sub-buffer is
- corrupted */
- atomic_add(reserve_commit_diff,
- <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
- atomic_inc(<t_buf->corrupted_subbuffers);
- }
- }
- }
-
- /* Always switch */
-
- if(end_switch_old) {
- /* old subbuffer */
- /* Concurrency safe because we are the last and only thread to alter this
- sub-buffer. As long as it is not delivered and read, no other thread can
- alter the offset, alter the reserve_count or call the
- client_buffer_end_callback on this sub-buffer.
- The only remaining threads could be the ones with pending commits. They
- will have to do the deliver themself.
- Not concurrency safe in overwrite mode. We detect corrupted subbuffers with
- commit and reserve counts. We keep a corrupted sub-buffers count and push
- the readers across these sub-buffers.
- Not concurrency safe if a writer is stalled in a subbuffer and
- another writer switches in, finding out it's corrupted. The result will be
- than the old (uncommited) subbuffer will be declared corrupted, and that
- the new subbuffer will be declared corrupted too because of the commit
- count adjustment.
- Offset old should never be 0. */
- ltt_buffer_end_callback(ltt_buf, tsc, offset_old,
- SUBBUF_INDEX((offset_old), ltt_buf));
- /* Setting this reserve_count will allow the sub-buffer to be delivered by
- the last committer. */
- reserve_count = atomic_add_return((SUBBUF_OFFSET((offset_old-1),
- ltt_buf) + 1),
- <t_buf->reserve_count[SUBBUF_INDEX((offset_old),
- ltt_buf)]);
- if(reserve_count == atomic_read(
- <t_buf->commit_count[SUBBUF_INDEX((offset_old), ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_old), ltt_buf), NULL);
- }
- }
-
- if(mode == FORCE_ACTIVE) {
- /* New sub-buffer */
- /* This code can be executed unordered : writers may already have written
- to the sub-buffer before this code gets executed, caution. */
- /* The commit makes sure that this code is executed before the deliver
- of this sub-buffer */
- ltt_buffer_begin_callback(ltt_buf, tsc, SUBBUF_INDEX(offset_begin, ltt_buf));
- commit_count = atomic_add_return(ltt_subbuf_header_len(ltt_buf),
- <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
- /* Check if the written buffer has to be delivered */
- if(commit_count == atomic_read(
- <t_buf->reserve_count[SUBBUF_INDEX(offset_begin, ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_begin, ltt_buf), NULL);
- }
- }
-
-}
-
-
-static int open_output_files(void)
-{
- int ret;
- int fd;
- /* Open output files */
- umask(00000);
- ret = mkdir(LTT_USERTRACE_ROOT, 0777);
- if(ret < 0 && errno != EEXIST) {
- perror("LTT Error in creating output (mkdir)");
- exit(-1);
- }
- ret = chdir(LTT_USERTRACE_ROOT);
- if(ret < 0) {
- perror("LTT Error in creating output (chdir)");
- exit(-1);
- }
- snprintf(identifier_name, PATH_MAX-1, "%lu.%lu.%llu",
- traced_tid, traced_pid, get_cycles());
- snprintf(outfile_name, PATH_MAX-1, "process-%s", identifier_name);
-
-#ifndef LTT_NULL_OUTPUT_TEST
- fd = creat(outfile_name, 0644);
-#else
- /* NULL test */
- ret = symlink("/dev/null", outfile_name);
- if(ret < 0) {
- perror("error in symlink");
- exit(-1);
- }
- fd = open(outfile_name, O_WRONLY);
- if(fd_process < 0) {
- perror("Error in open");
- exit(-1);
- }
-#endif //LTT_NULL_OUTPUT_TEST
- return fd;
-}
-
-static inline int ltt_buffer_get(struct ltt_buf *ltt_buf,
- unsigned int *offset)
-{
- unsigned int consumed_old, consumed_idx;
- consumed_old = atomic_read(<t_buf->consumed);
- consumed_idx = SUBBUF_INDEX(consumed_old, ltt_buf);
-
- if(atomic_read(<t_buf->commit_count[consumed_idx])
- != atomic_read(<t_buf->reserve_count[consumed_idx])) {
- return -EAGAIN;
- }
- if((SUBBUF_TRUNC(atomic_read(<t_buf->offset), ltt_buf)
- -SUBBUF_TRUNC(consumed_old, ltt_buf)) == 0) {
- return -EAGAIN;
- }
-
- *offset = consumed_old;
-
- return 0;
-}
-
-static inline int ltt_buffer_put(struct ltt_buf *ltt_buf,
- unsigned int offset)
-{
- unsigned int consumed_old, consumed_new;
- int ret;
-
- consumed_old = offset;
- consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
- if(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
- != consumed_old) {
- /* We have been pushed by the writer : the last buffer read _is_
- * corrupted!
- * It can also happen if this is a buffer we never got. */
- return -EIO;
- } else {
- if(traced_pid == 0 || parent_exited) return 0;
-
- ret = sem_post(<t_buf->writer_sem);
- if(ret < 0) {
- printf("error in sem_post");
- }
- }
- return ret;
-}
-
-static int read_subbuffer(struct ltt_buf *ltt_buf, int fd)
-{
- unsigned int consumed_old;
- int err;
- dbg_printf("LTT read buffer\n");
-
-
- err = ltt_buffer_get(ltt_buf, &consumed_old);
- if(err != 0) {
- if(err != -EAGAIN) dbg_printf("LTT Reserving sub buffer failed\n");
- goto get_error;
- }
- if(fd_process == -1) {
- fd_process = fd = open_output_files();
- }
-
- err = TEMP_FAILURE_RETRY(write(fd,
- ltt_buf->start
- + (consumed_old & ((ltt_buf->alloc_size)-1)),
- ltt_buf->subbuf_size));
-
- if(err < 0) {
- perror("Error in writing to file");
- goto write_error;
- }
-#if 0
- err = fsync(pair->trace);
- if(err < 0) {
- ret = errno;
- perror("Error in writing to file");
- goto write_error;
- }
-#endif //0
-write_error:
- err = ltt_buffer_put(ltt_buf, consumed_old);
-
- if(err != 0) {
- if(err == -EIO) {
- dbg_printf("Reader has been pushed by the writer, last subbuffer corrupted.\n");
- /* FIXME : we may delete the last written buffer if we wish. */
- }
- goto get_error;
- }
-
-get_error:
- return err;
-}
-
-/* This function is called by ltt_rw_init which has signals blocked */
-static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
- sigset_t oldset, pid_t l_traced_pid, pthread_t l_traced_tid)
-{
- struct sigaction act;
- int ret;
-
- traced_pid = l_traced_pid;
- traced_tid = l_traced_tid;
-
- dbg_printf("LTT ltt_usertrace_fast_daemon : init is %d, pid is %lu, traced_pid is %lu, traced_tid is %lu\n",
- shared_trace_info->init, getpid(), traced_pid, traced_tid);
-
- act.sa_handler = handler_sigusr1;
- act.sa_flags = 0;
- sigemptyset(&(act.sa_mask));
- sigaddset(&(act.sa_mask), SIGUSR1);
- sigaction(SIGUSR1, &act, NULL);
-
- act.sa_handler = handler_sigusr2;
- act.sa_flags = 0;
- sigemptyset(&(act.sa_mask));
- sigaddset(&(act.sa_mask), SIGUSR2);
- sigaction(SIGUSR2, &act, NULL);
-
- act.sa_handler = handler_sigalarm;
- act.sa_flags = 0;
- sigemptyset(&(act.sa_mask));
- sigaddset(&(act.sa_mask), SIGALRM);
- sigaction(SIGALRM, &act, NULL);
-
- alarm(3);
-
- while(1) {
- ret = sigsuspend(&oldset);
- if(ret != -1) {
- perror("LTT Error in sigsuspend\n");
- }
- if(traced_pid == 0) break; /* parent died */
- if(parent_exited) break;
- dbg_printf("LTT Doing a buffer switch read. pid is : %lu\n", getpid());
-
- do {
- ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
- } while(ret == 0);
- }
- /* The parent thread is dead and we have finished with the buffer */
-
- /* Buffer force switch (flush). Using FLUSH instead of ACTIVE because we know
- * there is no writer. */
- flush_buffer(&shared_trace_info->channel.process, FORCE_FLUSH);
- do {
- ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
- } while(ret == 0);
-
- if(fd_process != -1)
- close(fd_process);
-
- ret = sem_destroy(&shared_trace_info->channel.process.writer_sem);
- if(ret < 0) {
- perror("error in sem_destroy");
- }
- munmap(shared_trace_info, sizeof(*shared_trace_info));
-
- exit(0);
-}
-
-
-/* Reader-writer initialization */
-
-static enum ltt_process_role { LTT_ROLE_WRITER, LTT_ROLE_READER }
- role = LTT_ROLE_WRITER;
-
-
-void ltt_rw_init(void)
-{
- pid_t pid;
- struct ltt_trace_info *shared_trace_info;
- int ret;
- sigset_t set, oldset;
- pid_t l_traced_pid = getpid();
- pid_t l_traced_tid = gettid();
-
- /* parent : create the shared memory map */
- shared_trace_info = mmap(0, sizeof(*thread_trace_info),
- PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0);
- shared_trace_info->init=0;
- shared_trace_info->filter=0;
- shared_trace_info->daemon_id=0;
- shared_trace_info->nesting=0;
- memset(&shared_trace_info->channel.process, 0,
- sizeof(shared_trace_info->channel.process));
- //Need NPTL!
- ret = sem_init(&shared_trace_info->channel.process.writer_sem, 1,
- LTT_N_SUBBUFS);
- if(ret < 0) {
- perror("error in sem_init");
- }
- shared_trace_info->channel.process.alloc_size = LTT_BUF_SIZE_PROCESS;
- shared_trace_info->channel.process.subbuf_size = LTT_SUBBUF_SIZE_PROCESS;
- shared_trace_info->channel.process.start =
- shared_trace_info->channel.process_buf;
- ltt_buffer_begin_callback(&shared_trace_info->channel.process,
- ltt_get_timestamp(), 0);
-
- shared_trace_info->init = 1;
-
- /* Disable signals */
- ret = sigfillset(&set);
- if(ret) {
- dbg_printf("LTT Error in sigfillset\n");
- }
-
- ret = pthread_sigmask(SIG_BLOCK, &set, &oldset);
- if(ret) {
- dbg_printf("LTT Error in pthread_sigmask\n");
- }
-
- pid = fork();
- if(pid > 0) {
- /* Parent */
- shared_trace_info->daemon_id = pid;
- thread_trace_info = shared_trace_info;
-
- /* Enable signals */
- ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- if(ret) {
- dbg_printf("LTT Error in pthread_sigmask\n");
- }
- } else if(pid == 0) {
- pid_t sid;
- /* Child */
- role = LTT_ROLE_READER;
- sid = setsid();
- //Not a good idea to renice, unless futex wait eventually implement
- //priority inheritence.
- //ret = nice(1);
- //if(ret < 0) {
- // perror("Error in nice");
- //}
- if(sid < 0) {
- perror("Error setting sid");
- }
- ltt_usertrace_fast_daemon(shared_trace_info, oldset, l_traced_pid,
- l_traced_tid);
- /* Should never return */
- exit(-1);
- } else if(pid < 0) {
- /* fork error */
- perror("LTT Error in forking ltt-usertrace-fast");
- }
-}
-
-static __thread struct _pthread_cleanup_buffer cleanup_buffer;
-
-void ltt_thread_init(void)
-{
- _pthread_cleanup_push(&cleanup_buffer, ltt_usertrace_fast_cleanup, NULL);
- ltt_rw_init();
-}
-
-void __attribute__((constructor)) __ltt_usertrace_fast_init(void)
-{
- dbg_printf("LTT usertrace-fast init\n");
-
- ltt_rw_init();
-}
-
-void __attribute__((destructor)) __ltt_usertrace_fast_fini(void)
-{
- if(role == LTT_ROLE_WRITER) {
- dbg_printf("LTT usertrace-fast fini\n");
- ltt_usertrace_fast_cleanup(NULL);
- }
-}
-
+++ /dev/null
-/*
- * PowerPC atomic operations
- */
-
-#ifndef _ASM_PPC_ATOMIC_H_
-#define _ASM_PPC_ATOMIC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct { volatile int counter; } atomic_t;
-
-#define ATOMIC_INIT(i) { (i) }
-
-#define atomic_read(v) ((v)->counter)
-#define atomic_set(v,i) (((v)->counter) = (i))
-
-extern void atomic_clear_mask(unsigned long mask, unsigned long *addr);
-
-#if 0 // We only do operation on one CPU at a time (LTT)
-#define SMP_SYNC "sync"
-#define SMP_ISYNC "\n\tisync"
-#else
-#define SMP_SYNC ""
-#define SMP_ISYNC
-#endif
-
-/* Erratum #77 on the 405 means we need a sync or dcbt before every stwcx.
- * The old ATOMIC_SYNC_FIX covered some but not all of this.
- */
-#ifdef CONFIG_IBM405_ERR77
-#define PPC405_ERR77(ra,rb) "dcbt " #ra "," #rb ";"
-#else
-#define PPC405_ERR77(ra,rb)
-#endif
-
-static __inline__ void atomic_add(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%3 # atomic_add\n\
- add %0,%2,%0\n"
- PPC405_ERR77(0,%3)
-" stwcx. %0,0,%3 \n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (a), "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_add_return(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_add_return\n\
- add %0,%1,%0\n"
- PPC405_ERR77(0,%2)
-" stwcx. %0,0,%2 \n\
- bne- 1b"
- SMP_ISYNC
- : "=&r" (t)
- : "r" (a), "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
-
-static __inline__ void atomic_sub(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%3 # atomic_sub\n\
- subf %0,%2,%0\n"
- PPC405_ERR77(0,%3)
-" stwcx. %0,0,%3 \n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (a), "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_sub_return(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_sub_return\n\
- subf %0,%1,%0\n"
- PPC405_ERR77(0,%2)
-" stwcx. %0,0,%2 \n\
- bne- 1b"
- SMP_ISYNC
- : "=&r" (t)
- : "r" (a), "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-static __inline__ void atomic_inc(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_inc\n\
- addic %0,%0,1\n"
- PPC405_ERR77(0,%2)
-" stwcx. %0,0,%2 \n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_inc_return(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%1 # atomic_inc_return\n\
- addic %0,%0,1\n"
- PPC405_ERR77(0,%1)
-" stwcx. %0,0,%1 \n\
- bne- 1b"
- SMP_ISYNC
- : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-/*
- * atomic_inc_and_test - increment and test
- * @v: pointer of type atomic_t
- *
- * Atomically increments @v by 1
- * and returns true if the result is zero, or false for all
- * other cases.
- */
-#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
-
-static __inline__ void atomic_dec(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_dec\n\
- addic %0,%0,-1\n"
- PPC405_ERR77(0,%2)\
-" stwcx. %0,0,%2\n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_dec_return(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%1 # atomic_dec_return\n\
- addic %0,%0,-1\n"
- PPC405_ERR77(0,%1)
-" stwcx. %0,0,%1\n\
- bne- 1b"
- SMP_ISYNC
- : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
-#define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
-
-/*
- * Atomically test *v and decrement if it is greater than 0.
- * The function returns the old value of *v minus 1.
- */
-static __inline__ int atomic_dec_if_positive(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%1 # atomic_dec_if_positive\n\
- addic. %0,%0,-1\n\
- blt- 2f\n"
- PPC405_ERR77(0,%1)
-" stwcx. %0,0,%1\n\
- bne- 1b"
- SMP_ISYNC
- "\n\
-2:" : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define __MB __asm__ __volatile__ (SMP_SYNC : : : "memory")
-#define smp_mb__before_atomic_dec() __MB
-#define smp_mb__after_atomic_dec() __MB
-#define smp_mb__before_atomic_inc() __MB
-#define smp_mb__after_atomic_inc() __MB
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* _ASM_PPC_ATOMIC_H_ */
+++ /dev/null
-/*
- * PowerPC64 atomic operations
- *
- * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM
- * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#ifndef _ASM_PPC64_ATOMIC_H_
-#define _ASM_PPC64_ATOMIC_H_
-
-#include <asm/memory.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct { volatile int counter; } atomic_t;
-
-#define ATOMIC_INIT(i) { (i) }
-
-#define atomic_read(v) ((v)->counter)
-#define atomic_set(v,i) (((v)->counter) = (i))
-
-static __inline__ void atomic_add(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%3 # atomic_add\n\
- add %0,%2,%0\n\
- stwcx. %0,0,%3\n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (a), "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_add_return(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%2 # atomic_add_return\n\
- add %0,%1,%0\n\
- stwcx. %0,0,%2\n\
- bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (t)
- : "r" (a), "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
-
-static __inline__ void atomic_sub(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%3 # atomic_sub\n\
- subf %0,%2,%0\n\
- stwcx. %0,0,%3\n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (a), "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_sub_return(int a, atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%2 # atomic_sub_return\n\
- subf %0,%1,%0\n\
- stwcx. %0,0,%2\n\
- bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (t)
- : "r" (a), "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-static __inline__ void atomic_inc(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_inc\n\
- addic %0,%0,1\n\
- stwcx. %0,0,%2\n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_inc_return(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%1 # atomic_inc_return\n\
- addic %0,%0,1\n\
- stwcx. %0,0,%1\n\
- bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-/*
- * atomic_inc_and_test - increment and test
- * @v: pointer of type atomic_t
- *
- * Atomically increments @v by 1
- * and returns true if the result is zero, or false for all
- * other cases.
- */
-#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
-
-static __inline__ void atomic_dec(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
-"1: lwarx %0,0,%2 # atomic_dec\n\
- addic %0,%0,-1\n\
- stwcx. %0,0,%2\n\
- bne- 1b"
- : "=&r" (t), "=m" (v->counter)
- : "r" (&v->counter), "m" (v->counter)
- : "cc");
-}
-
-static __inline__ int atomic_dec_return(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%1 # atomic_dec_return\n\
- addic %0,%0,-1\n\
- stwcx. %0,0,%1\n\
- bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
-#define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
-
-/*
- * Atomically test *v and decrement if it is greater than 0.
- * The function returns the old value of *v minus 1.
- */
-static __inline__ int atomic_dec_if_positive(atomic_t *v)
-{
- int t;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%1 # atomic_dec_if_positive\n\
- addic. %0,%0,-1\n\
- blt- 2f\n\
- stwcx. %0,0,%1\n\
- bne- 1b"
- ISYNC_ON_SMP
- "\n\
-2:" : "=&r" (t)
- : "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-}
-
-#define smp_mb__before_atomic_dec() smp_mb()
-#define smp_mb__after_atomic_dec() smp_mb()
-#define smp_mb__before_atomic_inc() smp_mb()
-#define smp_mb__after_atomic_inc() smp_mb()
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* _ASM_PPC64_ATOMIC_H_ */
+++ /dev/null
-/*****************************************************************************
- * kernelutils-arm.h
- *
- * This file holds the code needed by LTT usertrace that comes from the
- * kernel headers. Since including kernel headers is not recommended in
- * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
- * (i.e. copied/pasted) from the original kernel headers (2.6.18).
- *
- * Do not use these functions within signal handlers, as the architecture offers
- * no atomic operations. (Mathieu Desnoyers) It is safe to do multithreaded
- * tracing though, as the buffers are per thread.
- *
- * Deepak Saxena, October 2006
- */
-
-#ifndef _KERNELUTILS_ARM_H
-#define _KERNELUTILS_ARM_H
-
-#include <time.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct { volatile int counter; } atomic_t;
-
-#define atomic_read(v) ((v)->counter)
-
-static inline int atomic_add_return(int i, atomic_t *v)
-{
- unsigned long flags;
- int val;
-
- val = v->counter;
- v->counter = val += i;
-
- return val;
-}
-
-#define atomic_add(i, v) (void) atomic_add_return(i, v)
-#define atomic_inc(v) (void) atomic_add_return(1, v)
-
-static inline unsigned long cmpxchg(volatile void *ptr,
- unsigned long old,
- unsigned long new)
-{
- unsigned long flags, prev;
- volatile unsigned long *p = ptr;
-
- if ((prev = *p) == old)
- *p = new;
- return(prev);
-}
-
-static inline unsigned long long get_cycles(void)
-{
- struct timespec tp;
- clock_gettime(CLOCK_MONOTONIC, &tp);
- return tp.tv_sec * 1000000000 + tp.tv_nsec;
-}
-
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * kernelutils-x386.h
- *
- * This file holds the code needed by LTT usertrace that comes from the
- * kernel headers. Since including kernel headers is not recommended in
- * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
- * (i.e. copied/pasted) from the original kernel headers (2.6.17).
- *
- * Martin Bisson, July 2006
- * Mathieu Desnoyers, August 2006
- */
-
-#ifndef _KERNELUTILS_I386_H
-#define _KERNELUTILS_I386_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// We are careful, so we assume a possibly SMP machine
-#define LOCK "lock ; "
-#define LOCK_PREFIX "lock ; "
-
-
-// From atomic.h
-
-
-/*
- * Make sure gcc doesn't try to be clever and move things around
- * on us. We need to use _exactly_ the address the user gave us,
- * not some alias that contains the same information.
- */
-typedef struct { volatile int counter; } atomic_t;
-
-
-/**
- * atomic_read - read atomic variable
- * @v: pointer of type atomic_t
- *
- * Atomically reads the value of @v.
- */
-#define atomic_read(v) ((v)->counter)
-
-/**
- * atomic_add - add integer to atomic variable
- * @i: integer value to add
- * @v: pointer of type atomic_t
- *
- * Atomically adds @i to @v.
- */
-static __inline__ void atomic_add(int i, atomic_t *v)
-{
- __asm__ __volatile__(
- LOCK "addl %1,%0"
- :"=m" (v->counter)
- :"ir" (i), "m" (v->counter));
-}
-
-/**
- * atomic_inc - increment atomic variable
- * @v: pointer of type atomic_t
- *
- * Atomically increments @v by 1.
- */
-static __inline__ void atomic_inc(atomic_t *v)
-{
- __asm__ __volatile__(
- LOCK "incl %0"
- :"=m" (v->counter)
- :"m" (v->counter));
-}
-
-/**
- * atomic_add_return - add and return
- * @i: integer value to add
- * @v: pointer of type atomic_t
- *
- * Atomically adds @i to @v and returns @i + @v
- */
-static __inline__ int atomic_add_return(int i, atomic_t *v)
-{
- int __i = i;
- __asm__ __volatile__(
- LOCK "xaddl %0, %1;"
- :"=r"(i)
- :"m"(v->counter), "0"(i));
- return i + __i;
-}
-
-
-
-
-// From system.h
-
-struct __xchg_dummy { unsigned long a[100]; };
-#define __xg(x) ((struct __xchg_dummy *)(x))
-
-
-/*
- * Atomic compare and exchange. Compare OLD with MEM, if identical,
- * store NEW in MEM. Return the initial value in MEM. Success is
- * indicated by comparing RETURN with OLD.
- */
-
-#define __HAVE_ARCH_CMPXCHG 1
-#define cmpxchg(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
- (unsigned long)(n),sizeof(*(ptr))))
-
-static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
- unsigned long newval, int size)
-{
- unsigned long prev;
- switch (size) {
- case 1:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
- : "=a"(prev)
- : "q"(newval), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- case 2:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
- : "=a"(prev)
- : "r"(newval), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- case 4:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
- : "=a"(prev)
- : "r"(newval), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- }
- return old;
-}
-
-
-// From msr.h
-
-#define rdtscll(val) \
- __asm__ __volatile__("rdtsc" : "=A" (val))
-
-// From timex.h
-
-typedef unsigned long long cycles_t;
-
-static inline cycles_t get_cycles (void)
-{
- unsigned long long ret;
-
- rdtscll(ret);
- return ret;
-}
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif // _KERNELUTILS_I386_H
+++ /dev/null
-/*****************************************************************************
- * kernelutils-x86_64.h
- *
- * This file holds the code needed by LTT usertrace that comes from the
- * kernel headers. Since including kernel headers is not recommended in
- * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
- * (i.e. copied/pasted) from the original kernel headers (2.6.17).
- *
- * Martin Bisson, July 2006
- */
-
-#ifndef _KERNELUTILS_X86_64_H
-#define _KERNELUTILS_X86_64_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// We are careful, so we assume a possibly SMP machine
-#define LOCK "lock ; "
-#define LOCK_PREFIX "lock ; "
-
-
-
-
-// From atomic.h
-
-
-/*
- * Make sure gcc doesn't try to be clever and move things around
- * on us. We need to use _exactly_ the address the user gave us,
- * not some alias that contains the same information.
- */
-typedef struct { volatile int counter; } atomic_t;
-
-
-/**
- * atomic_read - read atomic variable
- * @v: pointer of type atomic_t
- *
- * Atomically reads the value of @v.
- */
-#define atomic_read(v) ((v)->counter)
-
-/**
- * atomic_add - add integer to atomic variable
- * @i: integer value to add
- * @v: pointer of type atomic_t
- *
- * Atomically adds @i to @v.
- */
-static __inline__ void atomic_add(int i, atomic_t *v)
-{
- __asm__ __volatile__(
- LOCK "addl %1,%0"
- :"=m" (v->counter)
- :"ir" (i), "m" (v->counter));
-}
-
-/**
- * atomic_inc - increment atomic variable
- * @v: pointer of type atomic_t
- *
- * Atomically increments @v by 1.
- */
-static __inline__ void atomic_inc(atomic_t *v)
-{
- __asm__ __volatile__(
- LOCK "incl %0"
- :"=m" (v->counter)
- :"m" (v->counter));
-}
-
-/**
- * atomic_add_return - add and return
- * @i: integer value to add
- * @v: pointer of type atomic_t
- *
- * Atomically adds @i to @v and returns @i + @v
- */
-static __inline__ int atomic_add_return(int i, atomic_t *v)
-{
- int __i = i;
- __asm__ __volatile__(
- LOCK "xaddl %0, %1;"
- :"=r"(i)
- :"m"(v->counter), "0"(i));
- return i + __i;
-}
-
-
-
-
-// From system.h
-
-#define __xg(x) ((volatile long *)(x))
-
-
-/*
- * Atomic compare and exchange. Compare OLD with MEM, if identical,
- * store NEW in MEM. Return the initial value in MEM. Success is
- * indicated by comparing RETURN with OLD.
- */
-
-#define __HAVE_ARCH_CMPXCHG 1
-
-static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
- unsigned long new, int size)
-{
- unsigned long prev;
- switch (size) {
- case 1:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
- : "=a"(prev)
- : "q"(new), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- case 2:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
- : "=a"(prev)
- : "r"(new), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- case 4:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2"
- : "=a"(prev)
- : "r"(new), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- case 8:
- __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2"
- : "=a"(prev)
- : "r"(new), "m"(*__xg(ptr)), "0"(old)
- : "memory");
- return prev;
- }
- return old;
-}
-
-#define cmpxchg(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
- (unsigned long)(n),sizeof(*(ptr))))
-
-
-
-
-// From msr.h
-
-
-#define rdtscll(val) do { \
- unsigned int __a,__d; \
- asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
- (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
-} while(0)
-
-
-
-
-// From timex.h
-
-typedef unsigned long long cycles_t;
-
-static inline cycles_t get_cycles (void)
-{
- unsigned long long ret;
-
- rdtscll(ret);
- return ret;
-}
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif // _KERNELUTILS_X86_64_H
+++ /dev/null
-#ifndef _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
-#define _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
-
-#include <sys/types.h>
-#include <ltt/ltt-facility-id-user_generic.h>
-#include <ltt/ltt-usertrace.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static int trace_user_generic_slow_printf(
- const char *fmt, ...)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- /* Guess we need no more than 100 bytes. */
- int n, size = 104;
- char *p, *np;
- va_list ap;
- int ret;
-
- size += ltt_align(size, sizeof(void*));
- if ((p = malloc (size)) == NULL)
- return -1;
-
- while (1) {
- /* Try to print in the allocated space. */
- va_start(ap, fmt);
- n = vsnprintf (p, size, fmt, ap);
- va_end(ap);
- /* If that worked, trace the string. */
- if (n > -1 && n < size) {
- ret = trace_user_generic_slow_printf_param_buffer(p, n+1+ltt_align(n+1, sizeof(void*)));
- free(p);
- return ret;
- }
- /* Else try again with more space. */
- if (n > -1) /* glibc 2.1 */
- size = n+1; /* precisely what is needed */
- else /* glibc 2.0 */
- size *= 2; /* twice the old size */
- size += ltt_align(size, sizeof(void*));
- if ((np = realloc (p, size)) == NULL) {
- free(p);
- return -1;
- } else {
- p = np;
- }
- }
-}
-#endif //LTT_TRACE
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif //_LTT_FACILITY_CUSTOM_USER_GENERIC_H_
+++ /dev/null
-#ifndef _LTT_FACILITY_ID_USER_GENERIC_H_
-#define _LTT_FACILITY_ID_USER_GENERIC_H_
-
-#ifdef LTT_TRACE
-#include <ltt/ltt-usertrace.h>
-
-/**** facility handle ****/
-
-extern ltt_facility_t ltt_facility_user_generic_B1865E44;
-extern ltt_facility_t ltt_facility_user_generic;
-
-
-/**** event index ****/
-
-enum user_generic_event {
- event_user_generic_string,
- event_user_generic_string_pointer,
- event_user_generic_slow_printf,
- event_user_generic_function_entry,
- event_user_generic_function_exit,
- event_user_generic_thread_brand,
- facility_user_generic_num_events
-};
-
-#endif //LTT_TRACE
-#endif //_LTT_FACILITY_ID_USER_GENERIC_H_
+++ /dev/null
-#ifndef _LTT_FACILITY_USER_GENERIC_H_
-#define _LTT_FACILITY_USER_GENERIC_H_
-
-#include <sys/types.h>
-#include <ltt/ltt-facility-id-user_generic.h>
-#include <ltt/ltt-usertrace.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Named types */
-
-/* Event string structures */
-static inline void lttng_write_string_user_generic_string_data(
- char *buffer,
- size_t *to_base,
- size_t *to,
- const char **from,
- size_t *len,
- const char * obj)
-{
- size_t size;
- size_t align;
-
- /* Flush pending memcpy */
- if (*len != 0) {
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, *from, *len);
- }
- *to += *len;
- *len = 0;
-
- align = sizeof(char);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = strlen(obj) + 1; /* Include final NULL char. */
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, obj, size);
- *to += size;
-
- /* Realign the *to_base on arch size, set *to to 0 */
- *to += ltt_align(*to, sizeof(void *));
- *to_base = *to_base+*to;
- *to = 0;
-
- /* Put source *from just after the C string */
- *from += size;
-}
-
-
-/* Event string logging function */
-static inline int trace_user_generic_string(
- const char * lttng_param_data);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_string(
- const char * lttng_param_data)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- const char *real_from;
- const char **from = &real_from;
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_data;
- lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
-
- reserve_size = *to_base + *to + *len;
- {
- char stack_buffer[reserve_size];
- buffer = stack_buffer;
-
- *to_base = *to = *len = 0;
-
- *from = (const char*)lttng_param_data;
- lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING, 0);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline int trace_user_generic_string(
- const char * lttng_param_data)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_data;
- lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_string);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_string,
- reserve_size, tsc);
- *from = (const char*)lttng_param_data;
- lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-/* Event string_pointer structures */
-static inline void lttng_write_string_user_generic_string_pointer_string(
- char *buffer,
- size_t *to_base,
- size_t *to,
- const char **from,
- size_t *len,
- const char * obj)
-{
- size_t size;
- size_t align;
-
- /* Flush pending memcpy */
- if (*len != 0) {
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, *from, *len);
- }
- *to += *len;
- *len = 0;
-
- align = sizeof(char);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = strlen(obj) + 1; /* Include final NULL char. */
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, obj, size);
- *to += size;
-
- /* Realign the *to_base on arch size, set *to to 0 */
- *to += ltt_align(*to, sizeof(void *));
- *to_base = *to_base+*to;
- *to = 0;
-
- /* Put source *from just after the C string */
- *from += size;
-}
-
-
-/* Event string_pointer logging function */
-static inline int trace_user_generic_string_pointer(
- const char * lttng_param_string,
- const void * lttng_param_pointer);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_string_pointer(
- const char * lttng_param_string,
- const void * lttng_param_pointer)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
-
- *from = (const char*)<tng_param_pointer;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- {
- char stack_buffer[reserve_size];
- buffer = stack_buffer;
-
- *to_base = *to = *len = 0;
-
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_pointer;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING, 0);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline int trace_user_generic_string_pointer(
- const char * lttng_param_string,
- const void * lttng_param_pointer)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
-
- *from = (const char*)<tng_param_pointer;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_string_pointer);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer,
- reserve_size, tsc);
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_pointer;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-/* Event slow_printf structures */
-static inline void lttng_write_string_user_generic_slow_printf_string(
- char *buffer,
- size_t *to_base,
- size_t *to,
- const char **from,
- size_t *len,
- const char * obj)
-{
- size_t size;
- size_t align;
-
- /* Flush pending memcpy */
- if (*len != 0) {
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, *from, *len);
- }
- *to += *len;
- *len = 0;
-
- align = sizeof(char);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = strlen(obj) + 1; /* Include final NULL char. */
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, obj, size);
- *to += size;
-
- /* Realign the *to_base on arch size, set *to to 0 */
- *to += ltt_align(*to, sizeof(void *));
- *to_base = *to_base+*to;
- *to = 0;
-
- /* Put source *from just after the C string */
- *from += size;
-}
-
-
-/* Event slow_printf logging function */
-static inline int trace_user_generic_slow_printf_param_buffer(
- char *buffer,
- size_t reserve_size);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_slow_printf_param_buffer(
- char *buffer,
- size_t reserve_size)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- {
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING, 0);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline int trace_user_generic_slow_printf(
- const char * lttng_param_string)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_slow_printf);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf,
- reserve_size, tsc);
- *from = (const char*)lttng_param_string;
- lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-/* Event function_entry structures */
-
-/* Event function_entry logging function */
-static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_function_entry(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- {
- char stack_buffer[reserve_size];
- buffer = stack_buffer;
-
- *to_base = *to = *len = 0;
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING, 0);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_function_entry);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_function_entry,
- reserve_size, tsc);
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-/* Event function_exit structures */
-
-/* Event function_exit logging function */
-static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_function_exit(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- {
- char stack_buffer[reserve_size];
- buffer = stack_buffer;
-
- *to_base = *to = *len = 0;
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING, 0);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
- const void * lttng_param_this_fn,
- const void * lttng_param_call_site)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- size_t align;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_function_exit);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_function_exit,
- reserve_size, tsc);
- *from = (const char*)<tng_param_this_fn;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- *from = (const char*)<tng_param_call_site;
- align = sizeof(const void *);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- *len += sizeof(const void *);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-/* Event thread_brand structures */
-static inline void lttng_write_string_user_generic_thread_brand_name(
- char *buffer,
- size_t *to_base,
- size_t *to,
- const char **from,
- size_t *len,
- const char * obj)
-{
- size_t size;
- size_t align;
-
- /* Flush pending memcpy */
- if (*len != 0) {
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, *from, *len);
- }
- *to += *len;
- *len = 0;
-
- align = sizeof(char);
-
- if (*len == 0) {
- *to += ltt_align(*to, align); /* align output */
- } else {
- *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
- }
-
- /* Contains variable sized fields : must explode the structure */
-
- size = strlen(obj) + 1; /* Include final NULL char. */
- if (buffer != NULL)
- memcpy(buffer+*to_base+*to, obj, size);
- *to += size;
-
- /* Realign the *to_base on arch size, set *to to 0 */
- *to += ltt_align(*to, sizeof(void *));
- *to_base = *to_base+*to;
- *to = 0;
-
- /* Put source *from just after the C string */
- *from += size;
-}
-
-
-/* Event thread_brand logging function */
-static inline int trace_user_generic_thread_brand(
- const char * lttng_param_name);
-
-#ifndef LTT_TRACE_FAST
-static inline int trace_user_generic_thread_brand(
- const char * lttng_param_name)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- int ret = 0;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- const char *real_from;
- const char **from = &real_from;
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_name;
- lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
-
- reserve_size = *to_base + *to + *len;
- {
- char stack_buffer[reserve_size];
- buffer = stack_buffer;
-
- *to_base = *to = *len = 0;
-
- *from = (const char*)lttng_param_name;
- lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand, buffer, reserve_size, LTT_BLOCKING, 1);
- }
-
- return ret;
-
-}
-#endif //LTT_TRACE
-#endif //!LTT_TRACE_FAST
-
-#ifdef LTT_TRACE_FAST
-static inline int trace_user_generic_thread_brand(
- const char * lttng_param_name)
-#ifndef LTT_TRACE
-{
-}
-#else
-{
- unsigned int index;
- struct ltt_trace_info *trace = thread_trace_info;
- struct ltt_buf *ltt_buf;
- char *buffer = NULL;
- size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
- size_t *to_base = &real_to_base;
- size_t real_to = 0;
- size_t *to = &real_to;
- size_t real_len = 0;
- size_t *len = &real_len;
- size_t reserve_size;
- size_t slot_size;
- const char *real_from;
- const char **from = &real_from;
- uint64_t tsc;
- if (!trace) {
- ltt_thread_init();
- trace = thread_trace_info;
- }
-
-
- /* For each field, calculate the field size. */
- /* size = *to_base + *to + *len */
- /* Assume that the padding for alignment starts at a
- * sizeof(void *) address. */
-
- *from = (const char*)lttng_param_name;
- lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
-
- reserve_size = *to_base + *to + *len;
- trace->nesting++;
- index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
- event_user_generic_thread_brand);
-
- {
- ltt_buf = ltt_get_channel_from_index(trace, index);
- slot_size = 0;
- buffer = ltt_reserve_slot(trace, ltt_buf,
- reserve_size, &slot_size, &tsc);
- if (!buffer)
- goto end; /* buffer full */
-
- *to_base = *to = *len = 0;
-
- buffer = ltt_write_event_header(trace, ltt_buf, buffer,
- ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand,
- reserve_size, tsc);
- *from = (const char*)lttng_param_name;
- lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
-
- /* Flush pending memcpy */
- if (*len != 0) {
- memcpy(buffer+*to_base+*to, *from, *len);
- *to += *len;
- *len = 0;
- }
-
- ltt_commit_slot(ltt_buf, buffer, slot_size);
-
-}
-
-end:
- trace->nesting--;
-}
-#endif //LTT_TRACE
-#endif //LTT_TRACE_FAST
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif //_LTT_FACILITY_USER_GENERIC_H_
+++ /dev/null
-
-/* LTTng user-space "fast" tracing header
- *
- * Copyright 2006 Mathieu Desnoyers
- *
- */
-
-#ifndef _LTT_USERTRACE_FAST_H
-#define _LTT_USERTRACE_FAST_H
-
-#ifdef LTT_TRACE
-#ifdef LTT_TRACE_FAST
-
-#include <errno.h>
-#include <pthread.h>
-#include <stdint.h>
-#include <syscall.h>
-#include <semaphore.h>
-#include <signal.h>
-
-#include <ltt/ltt-facility-id-user_generic.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef LTT_N_SUBBUFS
-#define LTT_N_SUBBUFS 2
-#endif //LTT_N_SUBBUFS
-
-#ifndef LTT_SUBBUF_SIZE_PROCESS
-#define LTT_SUBBUF_SIZE_PROCESS 1048576
-#endif //LTT_BUF_SIZE_CPU
-
-#define LTT_BUF_SIZE_PROCESS (LTT_SUBBUF_SIZE_PROCESS * LTT_N_SUBBUFS)
-
-#ifndef LTT_USERTRACE_ROOT
-#define LTT_USERTRACE_ROOT "/tmp/ltt-usertrace"
-#endif //LTT_USERTRACE_ROOT
-
-
-/* Buffer offset macros */
-
-#define BUFFER_OFFSET(offset, buf) (offset & (buf->alloc_size-1))
-#define SUBBUF_OFFSET(offset, buf) (offset & (buf->subbuf_size-1))
-#define SUBBUF_ALIGN(offset, buf) \
- (((offset) + buf->subbuf_size) & (~(buf->subbuf_size-1)))
-#define SUBBUF_TRUNC(offset, buf) \
- ((offset) & (~(buf->subbuf_size-1)))
-#define SUBBUF_INDEX(offset, buf) \
- (BUFFER_OFFSET(offset,buf)/buf->subbuf_size)
-
-
-#define LTT_TRACER_MAGIC_NUMBER 0x00D6B7ED
-#define LTT_TRACER_VERSION_MAJOR 0
-#define LTT_TRACER_VERSION_MINOR 8
-
-#ifndef atomic_cmpxchg
-#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
-#endif //atomic_cmpxchg
-
-struct ltt_trace_header {
- uint32_t magic_number;
- uint32_t arch_type;
- uint32_t arch_variant;
- uint32_t float_word_order; /* Only useful for user space traces */
- uint8_t arch_size;
- //uint32_t system_type;
- uint8_t major_version;
- uint8_t minor_version;
- uint8_t flight_recorder;
- uint8_t has_heartbeat;
- uint8_t has_alignment; /* Event header alignment */
- uint8_t tsc_lsb_truncate;
- uint8_t tscbits;
- uint32_t freq_scale;
- uint64_t start_freq;
- uint64_t start_tsc;
- uint64_t start_monotonic;
- uint64_t start_time_sec;
- uint64_t start_time_usec;
-} __attribute((packed));
-
-
-struct ltt_block_start_header {
- struct {
- uint64_t cycle_count;
- uint64_t freq; /* khz */
- } begin;
- struct {
- uint64_t cycle_count;
- uint64_t freq; /* khz */
- } end;
- uint32_t lost_size; /* Size unused at the end of the buffer */
- uint32_t buf_size; /* The size of this sub-buffer */
- struct ltt_trace_header trace;
-} __attribute((packed));
-
-
-
-struct ltt_buf {
- void *start;
- atomic_t offset;
- atomic_t consumed;
- atomic_t reserve_count[LTT_N_SUBBUFS];
- atomic_t commit_count[LTT_N_SUBBUFS];
-
- atomic_t events_lost;
- atomic_t corrupted_subbuffers;
- sem_t writer_sem; /* semaphore on which the writer waits */
- unsigned int alloc_size;
- unsigned int subbuf_size;
-};
-
-struct ltt_trace_info {
- int init;
- int filter;
- pid_t daemon_id;
- int nesting;
- struct {
- struct ltt_buf process;
- char process_buf[LTT_BUF_SIZE_PROCESS] __attribute__ ((aligned (8)));
- } channel;
-};
-
-
-struct ltt_event_header_nohb {
- uint64_t timestamp;
- unsigned char facility_id;
- unsigned char event_id;
- uint16_t event_size;
-} __attribute((packed));
-
-extern __thread struct ltt_trace_info *thread_trace_info;
-
-void ltt_thread_init(void);
-
-void __attribute__((no_instrument_function))
- ltt_usertrace_fast_buffer_switch(void);
-
-/* Get the offset of the channel in the ltt_trace_struct */
-#define GET_CHANNEL_INDEX(chan) \
- (unsigned int)&((struct ltt_trace_info*)NULL)->channel.chan
-
-/* ltt_get_index_from_facility
- *
- * Get channel index from facility and event id.
- *
- * @fID : facility ID
- * @eID : event number
- *
- * Get the channel index into which events must be written for the given
- * facility and event number. We get this structure offset as soon as possible
- * and remember it so we pass through this logic only once per trace call (not
- * for every trace).
- */
-static inline unsigned int __attribute__((no_instrument_function))
- ltt_get_index_from_facility(uint8_t fID,
- uint8_t eID)
-{
- return GET_CHANNEL_INDEX(process);
-}
-
-
-static inline struct ltt_buf * __attribute__((no_instrument_function))
- ltt_get_channel_from_index(
- struct ltt_trace_info *trace, unsigned int index)
-{
- return (struct ltt_buf *)((void*)trace+index);
-}
-
-
-/*
- * ltt_get_header_size
- *
- * Calculate alignment offset for arch size void*. This is the
- * alignment offset of the event header.
- *
- * Important note :
- * The event header must be a size multiple of the void* size. This is necessary
- * to be able to calculate statically the alignment offset of the variable
- * length data fields that follows. The total offset calculated here :
- *
- * Alignment of header struct on arch size
- * + sizeof(header struct)
- * + padding added to end of struct to align on arch size.
- * */
-static inline unsigned char __attribute__((no_instrument_function))
- ltt_get_header_size(struct ltt_trace_info *trace,
- void *address,
- size_t data_size,
- size_t *before_hdr_pad)
-{
- unsigned int padding;
- unsigned int header;
- size_t after_hdr_pad;
-
- header = sizeof(struct ltt_event_header_nohb);
-
- /* Padding before the header. Calculated dynamically */
- *before_hdr_pad = ltt_align((unsigned long)address, header);
- padding = *before_hdr_pad;
-
- /* Padding after header, considering header aligned on ltt_align.
- * Calculated statically if header size if known. */
- after_hdr_pad = ltt_align(header, sizeof(void*));
- padding += after_hdr_pad;
-
- return header+padding;
-}
-
-
-/* ltt_write_event_header
- *
- * Writes the event header to the pointer.
- *
- * @channel : pointer to the channel structure
- * @ptr : buffer pointer
- * @fID : facility ID
- * @eID : event ID
- * @event_size : size of the event, excluding the event header.
- * @tsc : time stamp counter.
- */
-static inline char *__attribute__((no_instrument_function))
- ltt_write_event_header(
- struct ltt_trace_info *trace, struct ltt_buf *buf,
- void *ptr, uint8_t fID, uint32_t eID, size_t event_size,
- uint64_t tsc)
-{
- size_t after_hdr_pad;
- struct ltt_event_header_nohb *nohb;
-
- event_size = min(event_size, 0xFFFFU);
- nohb = (struct ltt_event_header_nohb *)(ptr);
- nohb->timestamp = (uint64_t)tsc;
- nohb->facility_id = fID;
- nohb->event_id = eID;
- nohb->event_size = (uint16_t)event_size;
- after_hdr_pad = ltt_align(sizeof(*nohb), sizeof(void*));
- return ptr + sizeof(*nohb) + after_hdr_pad;
-}
-
-
-
-static inline uint64_t __attribute__((no_instrument_function))
-ltt_get_timestamp()
-{
- return get_cycles();
-}
-
-static inline unsigned int __attribute__((no_instrument_function))
-ltt_subbuf_header_len(struct ltt_buf *buf)
-{
- return sizeof(struct ltt_block_start_header);
-}
-
-
-
-static inline void __attribute__((no_instrument_function))
-ltt_write_trace_header(struct ltt_trace_header *header)
-{
- header->magic_number = LTT_TRACER_MAGIC_NUMBER;
- header->major_version = LTT_TRACER_VERSION_MAJOR;
- header->minor_version = LTT_TRACER_VERSION_MINOR;
- header->float_word_order = 0; //FIXME
- header->arch_type = 0; //FIXME LTT_ARCH_TYPE;
- header->arch_size = sizeof(void*);
- header->arch_variant = 0; //FIXME LTT_ARCH_VARIANT;
- header->flight_recorder = 0;
- header->has_heartbeat = 0;
- header->tsc_lsb_truncate = 0;
- header->tscbits = 0;
-
-#ifndef LTT_PACK
- header->has_alignment = sizeof(void*);
-#else
- header->has_alignment = 0;
-#endif
-
- //FIXME
- header->freq_scale = 0;
- header->start_freq = 0;
- header->start_tsc = 0;
- header->start_monotonic = 0;
- header->start_time_sec = 0;
- header->start_time_usec = 0;
-}
-
-
-static inline void __attribute__((no_instrument_function))
-ltt_buffer_begin_callback(struct ltt_buf *buf,
- uint64_t tsc, unsigned int subbuf_idx)
-{
- struct ltt_block_start_header *header =
- (struct ltt_block_start_header*)
- (buf->start + (subbuf_idx*buf->subbuf_size));
-
- header->begin.cycle_count = tsc;
- header->begin.freq = 0; //ltt_frequency();
-
- header->lost_size = 0xFFFFFFFF; // for debugging...
-
- header->buf_size = buf->subbuf_size;
-
- ltt_write_trace_header(&header->trace);
-
-}
-
-
-
-static inline void __attribute__((no_instrument_function))
-ltt_buffer_end_callback(struct ltt_buf *buf,
- uint64_t tsc, unsigned int offset, unsigned int subbuf_idx)
-{
- struct ltt_block_start_header *header =
- (struct ltt_block_start_header*)
- (buf->start + (subbuf_idx*buf->subbuf_size));
- /* offset is assumed to never be 0 here : never deliver a completely
- * empty subbuffer. */
- /* The lost size is between 0 and subbuf_size-1 */
- header->lost_size = SUBBUF_OFFSET((buf->subbuf_size - offset),
- buf);
- header->end.cycle_count = tsc;
- header->end.freq = 0; //ltt_frequency();
-}
-
-
-static inline void __attribute__((no_instrument_function))
-ltt_deliver_callback(struct ltt_buf *buf,
- unsigned subbuf_idx,
- void *subbuf)
-{
- ltt_usertrace_fast_buffer_switch();
-}
-
-
-/* ltt_reserve_slot
- *
- * Atomic slot reservation in a LTTng buffer. It will take care of
- * sub-buffer switching.
- *
- * Parameters:
- *
- * @trace : the trace structure to log to.
- * @buf : the buffer to reserve space into.
- * @data_size : size of the variable length data to log.
- * @slot_size : pointer to total size of the slot (out)
- * @tsc : pointer to the tsc at the slot reservation (out)
- * @before_hdr_pad : dynamic padding before the event header.
- * @after_hdr_pad : dynamic padding after the event header.
- *
- * Return : NULL if not enough space, else returns the pointer
- * to the beginning of the reserved slot. */
-static inline void * __attribute__((no_instrument_function)) ltt_reserve_slot(
- struct ltt_trace_info *trace,
- struct ltt_buf *ltt_buf,
- unsigned int data_size,
- size_t *slot_size,
- uint64_t *tsc)
-{
- int offset_begin, offset_end, offset_old;
- //int has_switch;
- int begin_switch, end_switch_current, end_switch_old;
- int reserve_commit_diff = 0;
- unsigned int size;
- size_t before_hdr_pad;
- int consumed_old, consumed_new;
- int commit_count, reserve_count;
- int ret;
- sigset_t oldset, set;
-
- do {
- offset_old = atomic_read(<t_buf->offset);
- offset_begin = offset_old;
- //has_switch = 0;
- begin_switch = 0;
- end_switch_current = 0;
- end_switch_old = 0;
- *tsc = ltt_get_timestamp();
- if(*tsc == 0) {
- /* Error in getting the timestamp, event lost */
- atomic_inc(<t_buf->events_lost);
- return NULL;
- }
-
- if(SUBBUF_OFFSET(offset_begin, ltt_buf) == 0) {
- begin_switch = 1; /* For offset_begin */
- } else {
- size = ltt_get_header_size(trace, ltt_buf->start + offset_begin,
- data_size, &before_hdr_pad)
- + data_size;
-
- if((SUBBUF_OFFSET(offset_begin, ltt_buf)+size)>ltt_buf->subbuf_size) {
- //has_switch = 1;
- end_switch_old = 1; /* For offset_old */
- begin_switch = 1; /* For offset_begin */
- }
- }
-
- if(begin_switch) {
- if(end_switch_old) {
- offset_begin = SUBBUF_ALIGN(offset_begin, ltt_buf);
- }
- offset_begin = offset_begin + ltt_subbuf_header_len(ltt_buf);
- /* Test new buffer integrity */
- reserve_commit_diff =
- atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_begin,
- ltt_buf)])
- - atomic_read(<t_buf->commit_count[SUBBUF_INDEX(offset_begin,
- ltt_buf)]);
-
- if(reserve_commit_diff == 0) {
- /* Next buffer not corrupted. */
- //if((SUBBUF_TRUNC(offset_begin, ltt_buf)
- // - SUBBUF_TRUNC(atomic_read(<t_buf->consumed), ltt_buf))
- // >= ltt_buf->alloc_size) {
- {
- /* sem_wait is not signal safe. Disable signals around it.
- * Signals are kept disabled to make sure we win the cmpxchg. */
- /* Disable signals */
- ret = sigfillset(&set);
- if(ret) perror("LTT Error in sigfillset\n");
-
- ret = pthread_sigmask(SIG_BLOCK, &set, &oldset);
- if(ret) perror("LTT Error in pthread_sigmask\n");
-
- /* We detect if a signal came between
- * the offset read and signal disabling:
- * if it is the case, then we restart
- * the loop after reenabling signals. It
- * means that it's a signal that has
- * won the buffer switch.*/
- if(offset_old != atomic_read(<t_buf->offset)) {
- ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- if(ret) perror("LTT Error in pthread_sigmask\n");
- continue;
- }
- /* If the offset is still the same, then
- * we can safely proceed to do the
- * buffer switch without being
- * interrupted by a signal. */
- sem_wait(<t_buf->writer_sem);
-
- }
- /* go on with the write */
-
- //} else {
- // /* next buffer not corrupted, we are either in overwrite mode or
- // * the buffer is not full. It's safe to write in this new subbuffer.*/
- //}
- } else {
- /* Next subbuffer corrupted. Force pushing reader even in normal
- * mode. It's safe to write in this new subbuffer. */
- /* No sem_post is required because we fall through without doing a
- * sem_wait. */
- }
- size = ltt_get_header_size(trace, ltt_buf->start + offset_begin,
- data_size, &before_hdr_pad) + data_size;
- if((SUBBUF_OFFSET(offset_begin,ltt_buf)+size)>ltt_buf->subbuf_size) {
- /* Event too big for subbuffers, report error, don't complete
- * the sub-buffer switch. */
- atomic_inc(<t_buf->events_lost);
- if(reserve_commit_diff == 0) {
- ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- if(ret) perror("LTT Error in pthread_sigmask\n");
- }
- return NULL;
- } else {
- /* We just made a successful buffer switch and the event fits in the
- * new subbuffer. Let's write. */
- }
- } else {
- /* Event fits in the current buffer and we are not on a switch boundary.
- * It's safe to write */
- }
- offset_end = offset_begin + size;
-
- if((SUBBUF_OFFSET(offset_end, ltt_buf)) == 0) {
- /* The offset_end will fall at the very beginning of the next subbuffer.
- */
- end_switch_current = 1; /* For offset_begin */
- }
-
- } while(atomic_cmpxchg(<t_buf->offset, offset_old, offset_end)
- != offset_old);
-
- /* Push the reader if necessary */
- do {
- consumed_old = atomic_read(<t_buf->consumed);
- /* If buffer is in overwrite mode, push the reader consumed count if
- the write position has reached it and we are not at the first
- iteration (don't push the reader farther than the writer).
- This operation can be done concurrently by many writers in the
- same buffer, the writer being at the fartest write position sub-buffer
- index in the buffer being the one which will win this loop. */
- /* If the buffer is not in overwrite mode, pushing the reader only
- happen if a sub-buffer is corrupted */
- if((SUBBUF_TRUNC(offset_end-1, ltt_buf)
- - SUBBUF_TRUNC(consumed_old, ltt_buf))
- >= ltt_buf->alloc_size)
- consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
- else {
- consumed_new = consumed_old;
- break;
- }
- } while(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
- != consumed_old);
-
- if(consumed_old != consumed_new) {
- /* Reader pushed : we are the winner of the push, we can therefore
- reequilibrate reserve and commit. Atomic increment of the commit
- count permits other writers to play around with this variable
- before us. We keep track of corrupted_subbuffers even in overwrite mode :
- we never want to write over a non completely committed sub-buffer :
- possible causes : the buffer size is too low compared to the unordered
- data input, or there is a writer who died between the reserve and the
- commit. */
- if(reserve_commit_diff) {
- /* We have to alter the sub-buffer commit count : a sub-buffer is
- corrupted. We do not deliver it. */
- atomic_add(reserve_commit_diff,
- <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
- atomic_inc(<t_buf->corrupted_subbuffers);
- }
- }
-
-
- if(end_switch_old) {
- /* old subbuffer */
- /* Concurrency safe because we are the last and only thread to alter this
- sub-buffer. As long as it is not delivered and read, no other thread can
- alter the offset, alter the reserve_count or call the
- client_buffer_end_callback on this sub-buffer.
- The only remaining threads could be the ones with pending commits. They
- will have to do the deliver themself.
- Not concurrency safe in overwrite mode. We detect corrupted subbuffers
- with commit and reserve counts. We keep a corrupted sub-buffers count
- and push the readers across these sub-buffers.
- Not concurrency safe if a writer is stalled in a subbuffer and
- another writer switches in, finding out it's corrupted. The result will
- be than the old (uncommited) subbuffer will be declared corrupted, and
- that the new subbuffer will be declared corrupted too because of the
- commit count adjustment.
- Note : offset_old should never be 0 here.*/
- ltt_buffer_end_callback(ltt_buf, *tsc, offset_old,
- SUBBUF_INDEX((offset_old-1), ltt_buf));
- /* Setting this reserve_count will allow the sub-buffer to be delivered by
- the last committer. */
- reserve_count =
- atomic_add_return((SUBBUF_OFFSET((offset_old-1), ltt_buf)+1),
- <t_buf->reserve_count[SUBBUF_INDEX((offset_old-1), ltt_buf)]);
- if(reserve_count
- == atomic_read(<t_buf->commit_count[SUBBUF_INDEX((offset_old-1),
- ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_old-1), ltt_buf),
- NULL);
- }
- }
-
- if(begin_switch) {
- /* Enable signals : this is what guaranteed that same reserve which did the
- * sem_wait does in fact win the cmpxchg for the offset. We only call
- * these system calls on buffer boundaries because of their performance
- * cost. */
- if(reserve_commit_diff == 0) {
- ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- if(ret) perror("LTT Error in pthread_sigmask\n");
- }
- /* New sub-buffer */
- /* This code can be executed unordered : writers may already have written
- to the sub-buffer before this code gets executed, caution. */
- /* The commit makes sure that this code is executed before the deliver
- of this sub-buffer */
- ltt_buffer_begin_callback(ltt_buf, *tsc, SUBBUF_INDEX(offset_begin, ltt_buf));
- commit_count = atomic_add_return(ltt_subbuf_header_len(ltt_buf),
- <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
- /* Check if the written buffer has to be delivered */
- if(commit_count
- == atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_begin,
- ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_begin, ltt_buf), NULL);
- }
- }
-
- if(end_switch_current) {
- /* current subbuffer */
- /* Concurrency safe because we are the last and only thread to alter this
- sub-buffer. As long as it is not delivered and read, no other thread can
- alter the offset, alter the reserve_count or call the
- client_buffer_end_callback on this sub-buffer.
- The only remaining threads could be the ones with pending commits. They
- will have to do the deliver themself.
- Not concurrency safe in overwrite mode. We detect corrupted subbuffers
- with commit and reserve counts. We keep a corrupted sub-buffers count
- and push the readers across these sub-buffers.
- Not concurrency safe if a writer is stalled in a subbuffer and
- another writer switches in, finding out it's corrupted. The result will
- be than the old (uncommited) subbuffer will be declared corrupted, and
- that the new subbuffer will be declared corrupted too because of the
- commit count adjustment. */
- ltt_buffer_end_callback(ltt_buf, *tsc, offset_end,
- SUBBUF_INDEX((offset_end-1), ltt_buf));
- /* Setting this reserve_count will allow the sub-buffer to be delivered by
- the last committer. */
- reserve_count =
- atomic_add_return((SUBBUF_OFFSET((offset_end-1), ltt_buf)+1),
- <t_buf->reserve_count[SUBBUF_INDEX((offset_end-1), ltt_buf)]);
- if(reserve_count
- == atomic_read(<t_buf->commit_count[SUBBUF_INDEX((offset_end-1),
- ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_end-1), ltt_buf), NULL);
- }
- }
-
- *slot_size = size;
-
- //BUG_ON(*slot_size != (data_size + *before_hdr_pad + *after_hdr_pad + *header_size));
- //BUG_ON(*slot_size != (offset_end - offset_begin));
-
- return ltt_buf->start + BUFFER_OFFSET(offset_begin, ltt_buf) + before_hdr_pad;
-}
-
-
-/* ltt_commit_slot
- *
- * Atomic unordered slot commit. Increments the commit count in the
- * specified sub-buffer, and delivers it if necessary.
- *
- * Parameters:
- *
- * @buf : the buffer to commit to.
- * @reserved : address of the end of the event header.
- * @slot_size : size of the reserved slot.
- *
- */
-static inline void __attribute__((no_instrument_function)) ltt_commit_slot(
- struct ltt_buf *ltt_buf,
- void *reserved,
- unsigned int slot_size)
-{
- unsigned int offset_end = reserved - ltt_buf->start;
- int commit_count;
-
- commit_count = atomic_add_return(slot_size,
- <t_buf->commit_count[SUBBUF_INDEX(offset_end-1,
- ltt_buf)]);
-
- /* Check if all commits have been done */
- if(commit_count ==
- atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_end-1, ltt_buf)])) {
- ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_end-1, ltt_buf), NULL);
- }
-}
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif //LTT_TRACE_FAST
-#endif //LTT_TRACE
-#endif //_LTT_USERTRACE_FAST_H
+++ /dev/null
-/*
- * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
- */
-#ifndef __LTT_USERTRACE_PPC_H
-#define __LTT_USERTRACE_PPC_H
-
-#ifdef __powerpc64__
-#include <ltt/atomic-ppc64.h>
-#include <ltt/system-ppc64.h>
-#else
-#include <ltt/ppc_asm-ppc.h>
-#include <ltt/atomic-ppc.h>
-#include <ltt/system-ppc.h>
-#include <ltt/timex-ppc.h>
-#endif
-
-
-#endif /* __LTT_USERTRACE_PPC_H */
+++ /dev/null
-/*****************************************************************************
- * ltt-usertrace.h
- *
- * LTT userspace tracing header
- *
- * Mathieu Desnoyers, March 2006
- */
-
-#ifndef _LTT_USERTRACE_H
-#define _LTT_USERTRACE_H
-
-#include <errno.h>
-#include <syscall.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define inline inline __attribute__((always_inline))
-
-#if defined(__powerpc__) || defined(__powerpc64__)
-#ifdef __powerpc64__
-#include <ltt/atomic-ppc64.h>
-#include <ltt/system-ppc64.h>
-#include <asm/timex.h>
-#else
-#include <ltt/ppc_asm-ppc.h>
-#include <ltt/atomic-ppc.h>
-#include <ltt/system-ppc.h>
-#include <ltt/timex-ppc.h>
-#endif
-#elif defined(__x86_64__)
-#include <ltt/kernelutils-x86_64.h>
-#elif defined(__i386__)
-#include <ltt/kernelutils-i386.h>
-#elif defined(__arm__)
-#include <ltt/kernelutils-arm.h>
-#elif defined(__SH4__)
-#include <ltt/kernelutils-sh.h>
-#else
-#error "Unsupported architecture"
-#endif
-
-#ifndef min
-#define min(a,b) ((a)<(b)?(a):(b))
-#endif
-
-#ifdef i386
-#define __NR_ltt_trace_generic 328
-#define __NR_ltt_register_generic 329
-#undef NR_syscalls
-#define NR_syscalls 330
-#endif
-
-#ifdef __x86_64__
-#define __NR_ltt_trace_generic 286
-#define __NR_ltt_register_generic 287
-#undef NR_syscalls
-#define NR_syscalls 288
-#endif
-
-#ifdef __powerpc__
-#define __NR_ltt_trace_generic 309
-#define __NR_ltt_register_generic 310
-#undef NR_syscalls
-#define NR_syscalls 311
-#endif
-
-#ifdef __powerpc64__
-#define __NR_ltt_trace_generic 309
-#define __NR_ltt_register_generic 310
-#undef NR_syscalls
-#define NR_syscalls 311
-#endif
-
-#ifdef __arm__
-#define __NR_ltt_trace_generic 352
-#define __NR_ltt_register_generic 353
-#undef NR_syscalls
-#define NR_syscalls 354
-#endif
-
-//FIXME : setup for MIPS
-
-#ifndef _LIBC
-// Put in bits/syscall.h
-#define SYS_ltt_trace_generic __NR_ltt_trace_generic
-#define SYS_ltt_register_generic __NR_ltt_register_generic
-#endif
-
-#define FACNAME_LEN 32
-
-/* LTT userspace tracing is non blocking by default when buffers are full */
-#ifndef LTT_BLOCKING
-#define LTT_BLOCKING 0
-#endif //LTT_BLOCKING
-
-typedef unsigned int ltt_facility_t;
-
-struct user_facility_info {
- char name[FACNAME_LEN];
- uint32_t num_events;
- uint32_t alignment;
- uint32_t checksum;
- uint32_t int_size;
- uint32_t long_size;
- uint32_t pointer_size;
- uint32_t size_t_size;
-};
-#if 0
-static inline __attribute__((no_instrument_function))
-_syscall5(int, ltt_trace_generic, unsigned int, facility_id,
- unsigned int, event_id, void *, data, size_t, data_size, int, blocking)
-static inline __attribute__((no_instrument_function))
-_syscall2(int, ltt_register_generic, unsigned int *, facility_id,
- const struct user_facility_info *, info)
-#endif //0
-
-#define ltt_register_generic(...) syscall(__NR_ltt_register_generic, __VA_ARGS__)
-#define ltt_trace_generic(...) syscall(__NR_ltt_trace_generic, __VA_ARGS__)
-
-static inline unsigned int __attribute__((no_instrument_function))
- ltt_align(size_t align_drift, size_t size_of_type);
-
-#ifndef LTT_PACK
-/* Calculate the offset needed to align the type */
-static inline unsigned int
- ltt_align(size_t align_drift, size_t size_of_type)
-{
- size_t alignment = min(sizeof(void*), size_of_type);
-
- return ((alignment - align_drift) & (alignment-1));
-}
-#define LTT_ALIGN
-#else
-static inline unsigned int ltt_align(size_t align_drift, size_t size_of_type)
-{
- return 0;
-}
-#define LTT_ALIGN __attribute__((packed))
-#endif //LTT_PACK
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#ifdef LTT_TRACE_FAST
-#include <ltt/ltt-usertrace-fast.h>
-#endif //LTT_TRACE_FAST
-
-#endif //_LTT_USERTRACE_H
+++ /dev/null
-/*
- * include/asm-ppc/ppc_asm.h
- *
- * Definitions used by various bits of low-level assembly code on PowerPC.
- *
- * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#ifndef _PPC_ASM_PPC_H
-#define _PPC_ASM_PPC_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Macros for storing registers into and loading registers from
- * exception frames.
- */
-#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
-#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
-#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
-#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
-#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
-#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
-#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
-#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
-#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
-#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
-
-#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
- SAVE_10GPRS(22, base)
-#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
- REST_10GPRS(22, base)
-
-#define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*(n)(base)
-#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
-#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
-#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
-#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
-#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
-#define REST_FPR(n, base) lfd n,THREAD_FPR0+8*(n)(base)
-#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
-#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
-#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
-#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
-#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
-
-#define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
-#define SAVE_2VR(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
-#define SAVE_4VR(n,b,base) SAVE_2VR(n,b,base); SAVE_2VR(n+2,b,base)
-#define SAVE_8VR(n,b,base) SAVE_4VR(n,b,base); SAVE_4VR(n+4,b,base)
-#define SAVE_16VR(n,b,base) SAVE_8VR(n,b,base); SAVE_8VR(n+8,b,base)
-#define SAVE_32VR(n,b,base) SAVE_16VR(n,b,base); SAVE_16VR(n+16,b,base)
-#define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
-#define REST_2VR(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
-#define REST_4VR(n,b,base) REST_2VR(n,b,base); REST_2VR(n+2,b,base)
-#define REST_8VR(n,b,base) REST_4VR(n,b,base); REST_4VR(n+4,b,base)
-#define REST_16VR(n,b,base) REST_8VR(n,b,base); REST_8VR(n+8,b,base)
-#define REST_32VR(n,b,base) REST_16VR(n,b,base); REST_16VR(n+16,b,base)
-
-#define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
-#define SAVE_2EVR(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
-#define SAVE_4EVR(n,s,base) SAVE_2EVR(n,s,base); SAVE_2EVR(n+2,s,base)
-#define SAVE_8EVR(n,s,base) SAVE_4EVR(n,s,base); SAVE_4EVR(n+4,s,base)
-#define SAVE_16EVR(n,s,base) SAVE_8EVR(n,s,base); SAVE_8EVR(n+8,s,base)
-#define SAVE_32EVR(n,s,base) SAVE_16EVR(n,s,base); SAVE_16EVR(n+16,s,base)
-
-#define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
-#define REST_2EVR(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
-#define REST_4EVR(n,s,base) REST_2EVR(n,s,base); REST_2EVR(n+2,s,base)
-#define REST_8EVR(n,s,base) REST_4EVR(n,s,base); REST_4EVR(n+4,s,base)
-#define REST_16EVR(n,s,base) REST_8EVR(n,s,base); REST_8EVR(n+8,s,base)
-#define REST_32EVR(n,s,base) REST_16EVR(n,s,base); REST_16EVR(n+16,s,base)
-
-#ifdef CONFIG_PPC601_SYNC_FIX
-#define SYNC \
-BEGIN_FTR_SECTION \
- sync; \
- isync; \
-END_FTR_SECTION_IFSET(CPU_FTR_601)
-#define SYNC_601 \
-BEGIN_FTR_SECTION \
- sync; \
-END_FTR_SECTION_IFSET(CPU_FTR_601)
-#define ISYNC_601 \
-BEGIN_FTR_SECTION \
- isync; \
-END_FTR_SECTION_IFSET(CPU_FTR_601)
-#else
-#define SYNC
-#define SYNC_601
-#define ISYNC_601
-#endif
-
-#ifndef CONFIG_SMP
-#define TLBSYNC
-#else /* CONFIG_SMP */
-/* tlbsync is not implemented on 601 */
-#define TLBSYNC \
-BEGIN_FTR_SECTION \
- tlbsync; \
- sync; \
-END_FTR_SECTION_IFCLR(CPU_FTR_601)
-#endif
-
-/*
- * This instruction is not implemented on the PPC 603 or 601; however, on
- * the 403GCX and 405GP tlbia IS defined and tlbie is not.
- * All of these instructions exist in the 8xx, they have magical powers,
- * and they must be used.
- */
-
-#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
-#define tlbia \
- li r4,1024; \
- mtctr r4; \
- lis r4,KERNELBASE@h; \
-0: tlbie r4; \
- addi r4,r4,0x1000; \
- bdnz 0b
-#endif
-
-#ifdef CONFIG_BOOKE
-#define tophys(rd,rs) \
- addis rd,rs,0
-
-#define tovirt(rd,rs) \
- addis rd,rs,0
-
-#else /* CONFIG_BOOKE */
-/*
- * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
- * physical base address of RAM at compile time.
- */
-#define tophys(rd,rs) \
-0: addis rd,rs,-KERNELBASE@h; \
- .section ".vtop_fixup","aw"; \
- .align 1; \
- .long 0b; \
- .previous
-
-#define tovirt(rd,rs) \
-0: addis rd,rs,KERNELBASE@h; \
- .section ".ptov_fixup","aw"; \
- .align 1; \
- .long 0b; \
- .previous
-#endif /* CONFIG_BOOKE */
-
-/*
- * On 64-bit cpus, we use the rfid instruction instead of rfi, but
- * we then have to make sure we preserve the top 32 bits except for
- * the 64-bit mode bit, which we clear.
- */
-#ifdef CONFIG_PPC64BRIDGE
-#define FIX_SRR1(ra, rb) \
- mr rb,ra; \
- mfmsr ra; \
- clrldi ra,ra,1; /* turn off 64-bit mode */ \
- rldimi ra,rb,0,32
-#define RFI .long 0x4c000024 /* rfid instruction */
-#define MTMSRD(r) .long (0x7c000164 + ((r) << 21)) /* mtmsrd */
-#define CLR_TOP32(r) rlwinm (r),(r),0,0,31 /* clear top 32 bits */
-
-#else
-#define FIX_SRR1(ra, rb)
-#ifndef CONFIG_40x
-#define RFI rfi
-#else
-#define RFI rfi; b . /* Prevent prefetch past rfi */
-#endif
-#define MTMSRD(r) mtmsr r
-#define CLR_TOP32(r)
-#endif /* CONFIG_PPC64BRIDGE */
-
-#define RFCI .long 0x4c000066 /* rfci instruction */
-#define RFDI .long 0x4c00004e /* rfdi instruction */
-#define RFMCI .long 0x4c00004c /* rfmci instruction */
-
-#ifdef CONFIG_IBM405_ERR77
-#define PPC405_ERR77(ra,rb) dcbt ra, rb;
-#define PPC405_ERR77_SYNC sync;
-#else
-#define PPC405_ERR77(ra,rb)
-#define PPC405_ERR77_SYNC
-#endif
-
-/* The boring bits... */
-
-/* Condition Register Bit Fields */
-
-#define cr0 0
-#define cr1 1
-#define cr2 2
-#define cr3 3
-#define cr4 4
-#define cr5 5
-#define cr6 6
-#define cr7 7
-
-
-/* General Purpose Registers (GPRs) */
-
-#define r0 0
-#define r1 1
-#define r2 2
-#define r3 3
-#define r4 4
-#define r5 5
-#define r6 6
-#define r7 7
-#define r8 8
-#define r9 9
-#define r10 10
-#define r11 11
-#define r12 12
-#define r13 13
-#define r14 14
-#define r15 15
-#define r16 16
-#define r17 17
-#define r18 18
-#define r19 19
-#define r20 20
-#define r21 21
-#define r22 22
-#define r23 23
-#define r24 24
-#define r25 25
-#define r26 26
-#define r27 27
-#define r28 28
-#define r29 29
-#define r30 30
-#define r31 31
-
-
-/* Floating Point Registers (FPRs) */
-
-#define fr0 0
-#define fr1 1
-#define fr2 2
-#define fr3 3
-#define fr4 4
-#define fr5 5
-#define fr6 6
-#define fr7 7
-#define fr8 8
-#define fr9 9
-#define fr10 10
-#define fr11 11
-#define fr12 12
-#define fr13 13
-#define fr14 14
-#define fr15 15
-#define fr16 16
-#define fr17 17
-#define fr18 18
-#define fr19 19
-#define fr20 20
-#define fr21 21
-#define fr22 22
-#define fr23 23
-#define fr24 24
-#define fr25 25
-#define fr26 26
-#define fr27 27
-#define fr28 28
-#define fr29 29
-#define fr30 30
-#define fr31 31
-
-#define vr0 0
-#define vr1 1
-#define vr2 2
-#define vr3 3
-#define vr4 4
-#define vr5 5
-#define vr6 6
-#define vr7 7
-#define vr8 8
-#define vr9 9
-#define vr10 10
-#define vr11 11
-#define vr12 12
-#define vr13 13
-#define vr14 14
-#define vr15 15
-#define vr16 16
-#define vr17 17
-#define vr18 18
-#define vr19 19
-#define vr20 20
-#define vr21 21
-#define vr22 22
-#define vr23 23
-#define vr24 24
-#define vr25 25
-#define vr26 26
-#define vr27 27
-#define vr28 28
-#define vr29 29
-#define vr30 30
-#define vr31 31
-
-#define evr0 0
-#define evr1 1
-#define evr2 2
-#define evr3 3
-#define evr4 4
-#define evr5 5
-#define evr6 6
-#define evr7 7
-#define evr8 8
-#define evr9 9
-#define evr10 10
-#define evr11 11
-#define evr12 12
-#define evr13 13
-#define evr14 14
-#define evr15 15
-#define evr16 16
-#define evr17 17
-#define evr18 18
-#define evr19 19
-#define evr20 20
-#define evr21 21
-#define evr22 22
-#define evr23 23
-#define evr24 24
-#define evr25 25
-#define evr26 26
-#define evr27 27
-#define evr28 28
-#define evr29 29
-#define evr30 30
-#define evr31 31
-
-/* some stab codes */
-#define N_FUN 36
-#define N_RSYM 64
-#define N_SLINE 68
-#define N_SO 100
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif //_PPC_ASM_PPC_H
+++ /dev/null
-/*
- * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
- */
-#ifndef __PPC_SYSTEM_H
-#define __PPC_SYSTEM_H
-
-#include <asm/atomic.h>
-#include <asm/hw_irq.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Memory barrier.
- * The sync instruction guarantees that all memory accesses initiated
- * by this processor have been performed (with respect to all other
- * mechanisms that access memory). The eieio instruction is a barrier
- * providing an ordering (separately) for (a) cacheable stores and (b)
- * loads and stores to non-cacheable memory (e.g. I/O devices).
- *
- * mb() prevents loads and stores being reordered across this point.
- * rmb() prevents loads being reordered across this point.
- * wmb() prevents stores being reordered across this point.
- * read_barrier_depends() prevents data-dependent loads being reordered
- * across this point (nop on PPC).
- *
- * We can use the eieio instruction for wmb, but since it doesn't
- * give any ordering guarantees about loads, we have to use the
- * stronger but slower sync instruction for mb and rmb.
- */
-#define mb() __asm__ __volatile__ ("sync" : : : "memory")
-#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
-#define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
-#define read_barrier_depends() do { } while(0)
-
-#define set_mb(var, value) do { var = value; mb(); } while (0)
-#define set_wmb(var, value) do { var = value; wmb(); } while (0)
-
-#ifdef CONFIG_SMP
-#define smp_mb() mb()
-#define smp_rmb() rmb()
-#define smp_wmb() wmb()
-#define smp_read_barrier_depends() read_barrier_depends()
-#else
-#define smp_mb() barrier()
-#define smp_rmb() barrier()
-#define smp_wmb() barrier()
-#define smp_read_barrier_depends() do { } while(0)
-#endif /* CONFIG_SMP */
-
-static inline unsigned long
-xchg_u32(volatile void *p, unsigned long val)
-{
- unsigned long prev;
-
- __asm__ __volatile__ ("\n\
-1: lwarx %0,0,%2 \n"
- PPC405_ERR77(0,%2)
-" stwcx. %3,0,%2 \n\
- bne- 1b"
- : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
- : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
- : "cc", "memory");
-
- return prev;
-}
-
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
-#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
-#define tas(ptr) (xchg((ptr),1))
-
-static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
-{
- switch (size) {
- case 4:
- return (unsigned long) xchg_u32(ptr, x);
-#if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
- case 8:
- return (unsigned long) xchg_u64(ptr, x);
-#endif /* 0 */
- }
- __xchg_called_with_bad_pointer();
- return x;
-
-
-}
-
-extern inline void * xchg_ptr(void * m, void * val)
-{
- return (void *) xchg_u32(m, (unsigned long) val);
-}
-
-
-#define __HAVE_ARCH_CMPXCHG 1
-
-static inline unsigned long
-__cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
-{
- unsigned int prev;
-
- __asm__ __volatile__ ("\n\
-1: lwarx %0,0,%2 \n\
- cmpw 0,%0,%3 \n\
- bne 2f \n"
- PPC405_ERR77(0,%2)
-" stwcx. %4,0,%2 \n\
- bne- 1b\n"
-#if 0 //only using one CPU at a time (LTT) // def CONFIG_SMP
-" sync\n"
-#endif /* CONFIG_SMP */
-"2:"
- : "=&r" (prev), "=m" (*p)
- : "r" (p), "r" (old), "r" (new), "m" (*p)
- : "cc", "memory");
-
- return prev;
-}
-
-/* This function doesn't exist, so you'll get a linker error
- if something tries to do an invalid cmpxchg(). */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
-static inline unsigned long
-__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
-{
- switch (size) {
- case 4:
- return __cmpxchg_u32(ptr, old, new);
-#if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
- case 8:
- return __cmpxchg_u64(ptr, old, new);
-#endif /* 0 */
- }
- __cmpxchg_called_with_bad_pointer();
- return old;
-}
-
-#define cmpxchg(ptr,o,n) \
- ({ \
- __typeof__(*(ptr)) _o_ = (o); \
- __typeof__(*(ptr)) _n_ = (n); \
- (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
- (unsigned long)_n_, sizeof(*(ptr))); \
- })
-
-#define arch_align_stack(x) (x)
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* __PPC_SYSTEM_H */
+++ /dev/null
-#ifndef __PPC64_SYSTEM_H
-#define __PPC64_SYSTEM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-//#include <linux/config.h>
-//#include <linux/compiler.h>
-#include <asm/page.h>
-#include <asm/processor.h>
-#include <asm/hw_irq.h>
-#include <asm/memory.h>
-
-/*
- * Memory barrier.
- * The sync instruction guarantees that all memory accesses initiated
- * by this processor have been performed (with respect to all other
- * mechanisms that access memory). The eieio instruction is a barrier
- * providing an ordering (separately) for (a) cacheable stores and (b)
- * loads and stores to non-cacheable memory (e.g. I/O devices).
- *
- * mb() prevents loads and stores being reordered across this point.
- * rmb() prevents loads being reordered across this point.
- * wmb() prevents stores being reordered across this point.
- * read_barrier_depends() prevents data-dependent loads being reordered
- * across this point (nop on PPC).
- *
- * We have to use the sync instructions for mb(), since lwsync doesn't
- * order loads with respect to previous stores. Lwsync is fine for
- * rmb(), though.
- * For wmb(), we use sync since wmb is used in drivers to order
- * stores to system memory with respect to writes to the device.
- * However, smp_wmb() can be a lighter-weight eieio barrier on
- * SMP since it is only used to order updates to system memory.
- */
-#define mb() __asm__ __volatile__ ("sync" : : : "memory")
-#define rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
-#define wmb() __asm__ __volatile__ ("sync" : : : "memory")
-#define read_barrier_depends() do { } while(0)
-
-#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
-#define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
-
-#ifdef CONFIG_SMP
-#define smp_mb() mb()
-#define smp_rmb() rmb()
-#define smp_wmb() __asm__ __volatile__ ("eieio" : : : "memory")
-#define smp_read_barrier_depends() read_barrier_depends()
-#else
-#define smp_mb() __asm__ __volatile__("": : :"memory")
-#define smp_rmb() __asm__ __volatile__("": : :"memory")
-#define smp_wmb() __asm__ __volatile__("": : :"memory")
-#define smp_read_barrier_depends() do { } while(0)
-#endif /* CONFIG_SMP */
-
-/*
- * Atomic exchange
- *
- * Changes the memory location '*ptr' to be val and returns
- * the previous value stored there.
- *
- * Inline asm pulled from arch/ppc/kernel/misc.S so ppc64
- * is more like most of the other architectures.
- */
-static inline unsigned long
-__xchg_u32(volatile int *m, unsigned long val)
-{
- unsigned long dummy;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: lwarx %0,0,%3 # __xchg_u32\n\
- stwcx. %2,0,%3\n\
-2: bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (dummy), "=m" (*m)
- : "r" (val), "r" (m)
- : "cc", "memory");
-
- return (dummy);
-}
-
-static inline unsigned long
-__xchg_u64(volatile long *m, unsigned long val)
-{
- unsigned long dummy;
-
- __asm__ __volatile__(
- EIEIO_ON_SMP
-"1: ldarx %0,0,%3 # __xchg_u64\n\
- stdcx. %2,0,%3\n\
-2: bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (dummy), "=m" (*m)
- : "r" (val), "r" (m)
- : "cc", "memory");
-
- return (dummy);
-}
-
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
-static inline unsigned long
-__xchg(volatile void *ptr, unsigned long x, int size)
-{
- switch (size) {
- case 4:
- return __xchg_u32(ptr, x);
- case 8:
- return __xchg_u64(ptr, x);
- }
- __xchg_called_with_bad_pointer();
- return x;
-}
-
-#define xchg(ptr,x) \
- ({ \
- __typeof__(*(ptr)) _x_ = (x); \
- (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
- })
-
-#define tas(ptr) (xchg((ptr),1))
-
-#define __HAVE_ARCH_CMPXCHG 1
-
-static inline unsigned long
-__cmpxchg_u32(volatile int *p, int old, int new)
-{
- unsigned int prev;
-
- __asm__ __volatile__ (
- EIEIO_ON_SMP
-"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
- cmpw 0,%0,%3\n\
- bne- 2f\n\
- stwcx. %4,0,%2\n\
- bne- 1b"
- ISYNC_ON_SMP
- "\n\
-2:"
- : "=&r" (prev), "=m" (*p)
- : "r" (p), "r" (old), "r" (new), "m" (*p)
- : "cc", "memory");
-
- return prev;
-}
-
-static inline unsigned long
-__cmpxchg_u64(volatile long *p, unsigned long old, unsigned long new)
-{
- unsigned long prev;
-
- __asm__ __volatile__ (
- EIEIO_ON_SMP
-"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
- cmpd 0,%0,%3\n\
- bne- 2f\n\
- stdcx. %4,0,%2\n\
- bne- 1b"
- ISYNC_ON_SMP
- "\n\
-2:"
- : "=&r" (prev), "=m" (*p)
- : "r" (p), "r" (old), "r" (new), "m" (*p)
- : "cc", "memory");
-
- return prev;
-}
-
-/* This function doesn't exist, so you'll get a linker error
- if something tries to do an invalid cmpxchg(). */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
-static inline unsigned long
-__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
-{
- switch (size) {
- case 4:
- return __cmpxchg_u32(ptr, old, new);
- case 8:
- return __cmpxchg_u64(ptr, old, new);
- }
- __cmpxchg_called_with_bad_pointer();
- return old;
-}
-
-#define cmpxchg(ptr,o,n) \
- ({ \
- __typeof__(*(ptr)) _o_ = (o); \
- __typeof__(*(ptr)) _n_ = (n); \
- (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
- (unsigned long)_n_, sizeof(*(ptr))); \
- })
-
-/*
- * We handle most unaligned accesses in hardware. On the other hand
- * unaligned DMA can be very expensive on some ppc64 IO chips (it does
- * powers of 2 writes until it reaches sufficient alignment).
- *
- * Based on this we disable the IP header alignment in network drivers.
- */
-#define NET_IP_ALIGN 0
-
-#define arch_align_stack(x) (x)
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif
+++ /dev/null
-#ifndef __TIMEX_PPC_H
-#define __TIMEX_PPC_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define CPU_FTR_601 0x00000100
-
-#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
-
-typedef uint64_t cycles_t;
-
-/* On ppc64 this gets us the whole timebase; on ppc32 just the lower half */
-static inline unsigned long get_tbl(void)
-{
- unsigned long tbl;
-
-//#if defined(CONFIG_403GCX)
-// asm volatile("mfspr %0, 0x3dd" : "=r" (tbl));
-//#else
- asm volatile("mftb %0" : "=r" (tbl));
-//#endif
- return tbl;
-}
-
-static inline unsigned int get_tbu(void)
-{
- unsigned int tbu;
-
-//#if defined(CONFIG_403GCX)
-// asm volatile("mfspr %0, 0x3dc" : "=r" (tbu));
-//#else
- asm volatile("mftbu %0" : "=r" (tbu));
-//#endif
- return tbu;
-}
-
-static inline uint64_t get_tb(void)
-{
- unsigned int tbhi, tblo, tbhi2;
-
- do {
- tbhi = get_tbu();
- tblo = get_tbl();
- tbhi2 = get_tbu();
- } while (tbhi != tbhi2);
-
- return ((uint64_t)tbhi << 32) | tblo;
-}
-
-static inline cycles_t get_cycles(void)
-{
- return get_tb();
-}
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif //__TIMEX_PPC_H
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-
-int main(int argc, char **argv)
-{
- printf("Will trace the following string : \"Hello world! Have a nice day.\"\n");
- printf("every microsecond.\n");
- printf("Abort with CTRL-C.\n");
- printf("No file is created with this example : it logs through a kernel\n");
- printf("system call. See the LTTng lttctl command to start tracing.\n");
-
- while(1) {
- trace_user_generic_string("Hello world! Have a nice day.");
- usleep(1);
- }
-
- return 0;
-}
-
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_TRACE_FAST
-#include <ltt/ltt-facility-user_generic.h>
-
-
-int main(int argc, char **argv)
-{
- printf("Will trace the following string : Running fast! in an infinite loop.\n");
- printf("Abort with CTRL-C or it will quickly fill up your disk.\n");
- printf("See the result file in /tmp/ltt-usertrace.\n");
-
- int i;
- while(1) {
- trace_user_generic_string("Running fast!");
- }
-
- return 0;
-}
-
+++ /dev/null
-
-
-#include <stdio.h>
-#include <unistd.h>
-
-
-
-
-void test_function(void)
-{
- printf("we are in a test function\n");
-}
-
-
-int main(int argc, char **argv)
-{
- printf("Abort with CTRL-C.\n");
- printf("See the result file in /tmp/ltt-usertrace.\n");
-
-
- while(1) {
- test_function();
- sleep(1);
- }
-
- return 0;
-}
-
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-#include <ltt/ltt-facility-custom-user_generic.h>
-// Notice the inclusion of ltt-facility-custom-user_generic.h for the
-// slow_printf support
-
-
-int main(int argc, char **argv)
-{
- printf("Will trace a printf of an incrementing counter.\n");
- printf("Abort with CTRL-C.\n");
- printf("No file is created with this example : it logs through a kernel\n");
- printf("system call. See the LTTng lttctl command to start tracing.\n");
-
- unsigned int count = 0;
-
- while(1) {
- trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
- __FILE__, __func__, __LINE__, count);
- count++;
- sleep(1);
- }
-
- return 0;
-}
-
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-
-int main(int argc, char **argv)
-{
- printf("Will create a branded thread\n");
- trace_user_generic_thread_brand("Sample_brand");
-
- sleep(2);
-
- return 0;
-}
-
+++ /dev/null
-
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#define LTT_TRACE
-#define LTT_TRACE_FAST
-#include <ltt/ltt-facility-user_generic.h>
-
-
-void *thr1(void *arg)
-{
- int i;
- ltt_thread_init(); /* This init is not required : it will be done
- automatically anyways at the first tracing call site */
- printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
-
- for(i=0; i<100000; i++) {
- trace_user_generic_string("Hello world! Have a nice day.");
- }
- pthread_exit((void*)1);
-}
-
-
-/* Example of a _bad_ thread, which still works with the tracing */
-void *thr2(void *arg)
-{
- int i;
- /* See ? no init */
- printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
-
- for(i=0; i<100000; i++) {
- trace_user_generic_string("Hello world! Have a nice day.");
- }
- /* This thread is a bad citizen : returning like this will cause its cancel
- * routines not to be executed. This is still detected by the tracer, but only
- * when the complete process dies. This is not recommended if you create a
- * huge amount of threads */
- return ((void*)2);
-}
-
-
-int main()
-{
- int err;
- pthread_t tid1, tid2;
- void *tret;
-
- printf("Will trace the following string : Hello world! Have a nice day.\n");
- printf("It will stop automatically.\n");
- printf("See the result file in /tmp/ltt-usertrace.\n");
-
- printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
- err = pthread_create(&tid1, NULL, thr1, NULL);
- if(err!=0) exit(1);
-
- err = pthread_create(&tid2, NULL, thr2, NULL);
- if(err!=0) exit(1);
-
- err = pthread_join(tid1, &tret);
- if(err!= 0) exit(1);
-
- err = pthread_join(tid2, &tret);
- if(err!= 0) exit(1);
-
- return 0;
-}
+++ /dev/null
-
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#define LTT_TRACE
-//this one is a non blocking sample (not #define LTT_BLOCKING 1)
-#include <ltt/ltt-facility-user_generic.h>
-
-
-void *thr1(void *arg)
-{
- printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
-
- while(1) {
- trace_user_generic_string("Hello world! Have a nice day.");
- sleep(2);
- }
- pthread_exit((void*)1);
-}
-
-
-/* Example of a _bad_ thread, which still works with the tracing */
-void *thr2(void *arg)
-{
- printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
- sleep(1);
- while(1) {
- trace_user_generic_string("Hello world! Have a nice day.");
- sleep(2);
- }
- return ((void*)2);
-}
-
-
-int main()
-{
- int err;
- pthread_t tid1, tid2;
- void *tret;
-
- printf("Will trace the following string : Hello world! Have a nice day.\n");
- printf("Press CTRL-C to stop.\n");
- printf("No file is created with this example : it logs through a kernel\n");
- printf("system call. See the LTTng lttctl command to start tracing.\n\n");
-
- printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
- err = pthread_create(&tid1, NULL, thr1, NULL);
- if(err!=0) exit(1);
-
- err = pthread_create(&tid2, NULL, thr2, NULL);
- if(err!=0) exit(1);
-
- err = pthread_join(tid1, &tret);
- if(err!= 0) exit(1);
-
- err = pthread_join(tid2, &tret);
- if(err!= 0) exit(1);
-
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-
-int main(int argc, char **argv)
-{
- printf("Will trace the following string : \"Hello world! Have a nice day.\"\n");
- printf("every second.\n");
- printf("Abort with CTRL-C.\n");
- printf("No file is created with this example : it logs through a kernel\n");
- printf("system call. See the LTTng lttctl command to start tracing.\n");
-
- while(1) {
- trace_user_generic_string("Hello world! Have a nice day.");
- sleep(1);
- }
-
- return 0;
-}
-
+++ /dev/null
-#
-# Spec file for LTT Usertrace
-#
-Summary: Linux Trace Toolkit Userspace Tracing Package
-Name: ltt-usertrace
-Version: 0.13
-License: GPL
-Release: 1
-Group: Applications/Development
-Source: http://ltt.polymtl.ca/packages/%{name}-%{version}.tar.gz
-URL: http://ltt.polymtl.ca
-Packager: Martin Bisson <bissonm@discreet.com>
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
-# Where do we install the libs
-%ifarch x86_64 ppc64 ppc64iseries ia64
-%define libdir /usr/lib64
-%else
-%define libdir /usr/lib
-%endif
-
-
-%description
-This packages makes it possible to do userspace tracing with the Linux
-Trace Toolkit.
-
-%prep
-%setup -q
-
-%build
-make libs
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT $RPM_BUILD_ROOT/usr/include $RPM_BUILD_ROOT/%{libdir}
-make INCLUDE_DIR=$RPM_BUILD_ROOT/usr/include LIB_DIR=$RPM_BUILD_ROOT/%{libdir} install
-
-%post
-echo "Running ldconfig (might take a while)"
-ldconfig
-
-%postun
-echo "Running ldconfig (might take a while)"
-ldconfig
-
-%files
-/usr/include/ltt
-/usr/include/ltt/atomic-ppc.h
-/usr/include/ltt/atomic-ppc64.h
-/usr/include/ltt/kernelutils-x86_64.h
-/usr/include/ltt/kernelutils-i386.h
-/usr/include/ltt/ltt-facility-custom-user_generic.h
-/usr/include/ltt/ltt-facility-id-user_generic.h
-/usr/include/ltt/ltt-facility-user_generic.h
-/usr/include/ltt/ltt-usertrace-fast.h
-/usr/include/ltt/ltt-usertrace-ppc.h
-/usr/include/ltt/ltt-usertrace.h
-/usr/include/ltt/ppc_asm-ppc.h
-/usr/include/ltt/system-ppc.h
-/usr/include/ltt/system-ppc64.h
-/usr/include/ltt/timex-ppc.h
-%{libdir}/libltt-instrument-functions.a
-%{libdir}/libltt-instrument-functions.so
-%{libdir}/libltt-instrument-functions.so.0
-%{libdir}/libltt-loader-user_generic.a
-%{libdir}/libltt-loader-user_generic.so
-%{libdir}/libltt-loader-user_generic.so.0
-%{libdir}/libltt-usertrace-fast.a
-%{libdir}/libltt-usertrace-fast.so
-%{libdir}/libltt-usertrace-fast.so.0
+++ /dev/null
-
-LIB_DIR=/usr/lib
-INCLUDE_DIR=/usr/include
-
-RANLIB=ranlib
-
-CC=gcc
-CFLAGS=-I. -O3
-#CFLAGS+=-DLTT_SUBBUF_SIZE_CPU=134217728
-#CFLAGS+=-DLTT_NULL_OUTPUT_TEST
-
-all: test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so.0 sample-loop
-
-test: test.c ltt-usertrace-fast.c
- $(CC) $(CFLAGS) -I. -lpthread -o $@ $^
-
-
-sample-instrument-fct: sample-instrument-fct.c
- $(CC) $(CFLAGS) -L. -g -finstrument-functions -lltt-instrument-functions -o $@ $^
-
-sample-loop: sample-loop.c ltt-usertrace-fast.o ltt-facility-loader-user_generic.o
- $(CC) $(CFLAGS) -L. -lpthread -g -o $@ $^
-
-libltt-instrument-functions.a: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
- @rm -f libltt-instrument-functions.a
- $(AR) rc $@ $^
- $(RANLIB) $@
-
-libltt-instrument-functions.so.0: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
- @rm -f libltt-instrument-functions.so libltt-instrument-functions.so.0
- $(CC) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-instrument-functions.so -o $@ $^
- ln -s libltt-instrument-functions.so.0 libltt-instrument-functions.so
-
-install:
- if [ ! -e "$(INCLUDE_DIR)/ltt" ] ; then mkdir $(INCLUDE_DIR)/ltt ; fi
- cp -f ltt/*.h $(INCLUDE_DIR)/ltt
- cp -df libltt-instrument-functions.so* libltt-instrument-functions.a $(LIB_DIR)
-
-.PHONY : clean install
-
-clean:
- rm -fr *.o *~ test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so*
+++ /dev/null
-/*
- * ltt-facility-loader-user_generic.c
- *
- * (C) Copyright 2005 -
- * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
- *
- * Contains the LTT user space facility loader.
- *
- */
-
-
-#define LTT_TRACE
-#include <error.h>
-#include <stdio.h>
-#include <ltt/ltt-generic.h>
-#include "ltt-facility-loader-user_generic.h"
-
-static struct user_facility_info facility = {
- .name = LTT_FACILITY_NAME,
- .num_events = LTT_FACILITY_NUM_EVENTS,
-#ifndef LTT_PACK
- .alignment = sizeof(void*),
-#else
- .alignment = 0,
-#endif //LTT_PACK
- .checksum = LTT_FACILITY_CHECKSUM,
- .int_size = sizeof(int),
- .long_size = sizeof(long),
- .pointer_size = sizeof(void*),
- .size_t_size = sizeof(size_t)
-};
-
-static void __attribute__((constructor)) __ltt_user_init(void)
-{
- int err;
-#ifdef LTT_SHOW_DEBUG
- printf("LTT : ltt-facility-user_generic init in userspace\n");
-#endif //LTT_SHOW_DEBUG
-
- err = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);
- LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
-
- if(err) {
-#ifdef LTT_SHOW_DEBUG
- perror("Error in ltt_register_generic");
-#endif //LTT_SHOW_DEBUG
- }
-}
-
+++ /dev/null
-#ifndef _LTT_FACILITY_LOADER_USER_GENERIC_H_
-#define _LTT_FACILITY_LOADER_USER_GENERIC_H_
-
-#include <ltt/ltt-generic.h>
-#include <ltt/ltt-facility-id-user_generic.h>
-
-ltt_facility_t ltt_facility_user_generic;
-ltt_facility_t ltt_facility_user_generic_F583779E;
-
-#define LTT_FACILITY_SYMBOL ltt_facility_user_generic
-#define LTT_FACILITY_CHECKSUM_SYMBOL ltt_facility_user_generic_F583779E
-#define LTT_FACILITY_CHECKSUM 0xF583779E
-#define LTT_FACILITY_NAME "user_generic"
-#define LTT_FACILITY_NUM_EVENTS facility_user_generic_num_events
-
-#endif //_LTT_FACILITY_LOADER_USER_GENERIC_H_
+++ /dev/null
-
-
-#include <stdio.h>
-#include <unistd.h>
-
-#define LTT_TRACE
-#define LTT_BLOCKING 1
-#include <ltt/ltt-facility-user_generic.h>
-
-
-void test_function(void)
-{
- printf("we are in a test function\n");
-}
-
-
-int main(int argc, char **argv)
-{
- while(1) {
- test_function();
- sleep(1);
- }
-
- return 0;
-}
-
+++ /dev/null
-
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <ltt/ltt-usertrace-fast.h>
-
-
-
-void *thr1(void *arg)
-{
- int i;
- ltt_thread_init();
- printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
-
- //while(1) {}
- for(i=0; i<5; i++) {
- // ltt_usertrace_fast_buffer_switch();
- sleep(1);
- }
-
- //return ((void*)1);
- pthread_exit((void*)1);
-}
-
-void *thr2(void *arg)
-{
- int i;
- ltt_thread_init();
- //while(1) {
- printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
- sleep(2);
- //}
- for(i=0; i<2; i++) {
- // ltt_usertrace_fast_buffer_switch();
- sleep(3);
- }
-
-
- return ((void*)2); /* testing "die" */
- //pthread_exit((void*)2);
-}
-
-
-int main()
-{
- int i;
- int err;
- pthread_t tid1, tid2;
- void *tret;
-
- printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
- err = pthread_create(&tid1, NULL, thr1, NULL);
- if(err!=0) exit(1);
-
- err = pthread_create(&tid2, NULL, thr2, NULL);
- if(err!=0) exit(1);
-
- for(i=0; i<2; i++) {
- // ltt_usertrace_fast_buffer_switch();
- sleep(3);
- }
-
- err = pthread_join(tid1, &tret);
- if(err!= 0) exit(1);
-
- err = pthread_join(tid2, &tret);
- if(err!= 0) exit(1);
-
- return 0;
-}
--- /dev/null
+SHELL = /bin/sh
+
+CC = gcc
+
+#CFLAGS = -std=c99 -Wall -g -DDEBUG
+CFLAGS = -std=c99 -Wall -g
+
+all: genevent
+
+install: genevent
+ cp -f genevent /usr/local/bin
+
+genevent: genevent.o parser.o
+ $(CC) $(CFLAGS) -o $@ $^
+
+genevent.o: genevent.c genevent.h parser.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+parser.o: parser.c parser.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o *~ *# genevent
+
+
--- /dev/null
+
+Mathieu Desnoyers -- November 2005
+
+This is a complete rework of genevent.
+
+The 'genevent' program parses event descriptions and generates
+the inline functions to record events in the kernel.
+
+There are several files in the directory:
+ genevent.c, genevent.h, crc32.tab, parser.c and parser.h
+
+In fact, crc32.tab, parser.c and parser.h are the same files as
+those in LTT library.
+
+Important notes :
+ * Do not put "-" symbols in facilities name.
+ * Use the exact same name for facility xml file and for facility name.
+ * As from genevent 0.17, a standard XML 1.0 description is "required". It must
+ begin with the <?xml version="1.0"?> header.
+
+Note about strings :
+There are three methods to write strings in genevent, each suitable and
+efficient for a particular case. They are explained here from the fastest
+to the slowest.
+1 - The C code presents a fixed size string.
+ For example, you find :
+ char mystring[10];
+ as string definition.
+
+ you must then define it as an array of char :
+ <array size="10"><char></array>
+
+ Note, however, that you might not want to declare a fixed size for trace size
+ and unnecessary copy matters.
+
+ For instance, on a 32 bits architecture, copying a n bytes array takes
+ approximately* n/4 memory read and write, for n/2 memory operations.
+
+ Using the slower method described in (3), with a strlen and memcpy, where
+ "u" is the number of used caracters, takes u+1 reads for the strlen, and
+ approximately* (u+1)/4 read and write for the memcpy, for a total of :
+ (3/2)*(u+1) memory access.
+
+ So, if (n/2) > (3/2)*(u+1), or : n > 3*u+3
+ where n is the size of the array
+ u is the average number of used caracters (excluding the \0)
+ it becomes faster to use the method number 3 with strlen.
+
+2 - The C code presents a variable size string together with its
+ size.
+
+ A typical use for this case is filenames in the Linux kernel. The
+ dentry strucure has a d_name member, which is a struct qstr containing
+ a unsigned int len and const unsigned char *name.
+
+ you must use a sequence to declare this efficiently :
+ <sequence><uint><char></sequence>
+
+3 - The C code presents a \0 terminated string.
+
+ This is the slowest, but most convenient way to declare a string. You are
+ discouraged to use it when options 1 or 2 are available. It will dynamically
+ calculate the string length (byte by byte read) and only afterward do a
+ memcpy.
+
+ Note that, as explained in 1, if n > 3*u+3, it becomes faster to use this
+ method instead of copying the whole fixed size array.
+
+ Declare like this :
+ <string>
+
+Here is a brief description of how to use genevent.
+
+make
+make install
+
+
+* Add new events to the kernel with genevent
+
+su -
+cd /usr/local/share/LinuxTraceToolkitViewer/facilities
+cp process.xml yourfacility.xml
+ * edit yourfacility.xml to fit your needs.
+cd /tmp
+/usr/local/bin/genevent /usr/local/share/LinuxTraceToolkitViewer/yourfacility.xml
+cp ltt-facility-yourfacility.h ltt-facility-id-yourfacility.h \
+ /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt
+cp ltt-facility-loader-yourfacility.c ltt-facility-loader-yourfacility.h \
+ /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/ltt
+ * edit the kernel file you want to instrument
+ - Add #include <linux/ltt/ltt-facility-yourfacility.h> at the beginning
+ of the file.
+ - Add a call to the tracing functions. See their names and parameters in
+ /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt/ltt-facility-yourfacility.h
+
+
+
+* The approximation comes from the fact that copies of number of caracters non
+ multiple of the architecture size takes more operations (maximum of :
+ (architecture size (in bytes) - 1) operations).
+
--- /dev/null
+ 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
+ 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
+ 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
+ 0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
+ 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
+ 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
+ 0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
+ 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
+ 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
+ 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
+ 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
+ 0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
+ 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
+ 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
+ 0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
+ 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
+ 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
+ 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
+ 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
+ 0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
+ 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
+ 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
+ 0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
+ 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
+ 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
+ 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
+ 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
+ 0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
+ 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
+ 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
+ 0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
+ 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
+ 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
+ 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
+ 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
+ 0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
+ 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
+ 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
+ 0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
+ 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
+ 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
+ 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
+ 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
+ 0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
+ 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
+ 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
+ 0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
+ 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
+ 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
+ 0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
+ 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
+ 0x2d02ef8dU
--- /dev/null
+/******************************************************************************
+ * Genevent
+ *
+ * Event generator. XML to logging C code converter.
+ *
+ * Program parameters :
+ * ./genevent name.xml
+ *
+ * Will generate ltt-facility-name.h, ltt-facility-id-name.h
+ * ltt-facility-loader-name.c, ltt-facility-loader-name.h
+ * in the current directory.
+ *
+ * Supports :
+ * - C Alignment
+ * - C types : struct, union, enum, basic types.
+ * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
+ *
+ * Additionnal structures supported :
+ * - embedded variable size strings
+ * - embedded variable size arrays
+ * - embedded variable size sequences
+ *
+ * Notes :
+ * (1)
+ * enums are limited to integer type, as this is what is used in C. Note,
+ * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
+ * unsigned int or int. This is implementation defined (compiler). That's why we
+ * add a check for sizeof enum.
+ *
+ * (2)
+ * Because of archtecture defined type sizes, we need to ask for ltt_align
+ * (which gives the alignment) by passing basic types, not their actual sizes.
+ * It's up to ltt_align to determine sizes of types.
+ *
+ * Note that, from
+ * http://www.usenix.org/publications/login/standards/10.data.html
+ * (Andrew Josey <a.josey@opengroup.org>) :
+ *
+ * Data Type LP32 ILP32 ILP64 LLP64 LP64
+ * char 8 8 8 8 8
+ * short 16 16 16 16 16
+ * int32 32
+ * int 16 32 64 32 32
+ * long 32 32 64 32 64
+ * long long (int64) 64
+ * pointer 32 32 64 64 64
+ *
+ * With these constraints :
+ * sizeof(char) <= sizeof(short) <= sizeof(int)
+ * <= sizeof(long) = sizeof(size_t)
+ *
+ * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
+ *
+ * Which means we only have to remember which is the biggest type in a structure
+ * to know the structure's alignment.
+ */
+
+#define _GNU_SOURCE
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "genevent.h"
+#include "parser.h"
+
+
+#define TRUE 1
+#define FALSE (!TRUE)
+
+/* Debugging printf */
+#ifdef DEBUG
+#define dprintf(...) \
+ do {\
+ printf(__FILE__ ",%u,%s: ",\
+ __LINE__, __func__);\
+ printf(__VA_ARGS__);\
+ } while(0)
+#else
+#define dprintf(...)
+#endif
+
+
+enum user_fct_types { USER_FCT_PROTO, USER_FCT_DECLARATION } ;
+
+/* Code printing */
+
+void print_tabs(unsigned int tabs, FILE *fd)
+{
+ for(unsigned int i = 0; i<tabs;i++)
+ fprintf(fd, "\t");
+}
+
+/* print type.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c */
+
+int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ strcpy(basename, nest_name);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_')
+ && (field_name[0] != '\0')) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ switch(td->type) {
+ case INT_FIXED:
+ fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
+ break;
+ case UINT_FIXED:
+ fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
+ break;
+ case CHAR:
+ fprintf(fd, "signed char");
+ break;
+ case UCHAR:
+ fprintf(fd, "unsigned char");
+ break;
+ case SHORT:
+ fprintf(fd, "short");
+ break;
+ case USHORT:
+ fprintf(fd, "unsigned short");
+ break;
+ case INT:
+ fprintf(fd, "int");
+ break;
+ case UINT:
+ fprintf(fd, "unsigned int");
+ break;
+ case FLOAT:
+ fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
+ break;
+ case POINTER:
+ fprintf(fd, "const void *");
+ break;
+ case LONG:
+ fprintf(fd, "long");
+ break;
+ case ULONG:
+ fprintf(fd, "unsigned long");
+ break;
+ case SIZE_T:
+ fprintf(fd, "size_t");
+ break;
+ case SSIZE_T:
+ fprintf(fd, "ssize_t");
+ break;
+ case OFF_T:
+ fprintf(fd, "off_t");
+ break;
+ case STRING:
+ fprintf(fd, "const char *");
+ break;
+ case ENUM:
+ fprintf(fd, "enum lttng_%s", basename);
+ break;
+ case ARRAY:
+ fprintf(fd, "lttng_array_%s", basename);
+ break;
+ case SEQUENCE:
+ fprintf(fd, "lttng_sequence_%s", basename);
+ break;
+ case STRUCT:
+ fprintf(fd, "struct lttng_%s", basename);
+ break;
+ case UNION:
+ fprintf(fd, "union lttng_%s", basename);
+ break;
+ default:
+ printf("print_type : unknown type\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Print logging function argument */
+int print_arg(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ strcpy(basename, nest_name);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_')
+ && (field_name[0] != '\0')) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ print_tabs(tabs, fd);
+
+ switch(td->type) {
+ case INT_FIXED:
+ fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case UINT_FIXED:
+ fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case CHAR:
+ fprintf(fd, "signed char");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case UCHAR:
+ fprintf(fd, "unsigned char");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case SHORT:
+ fprintf(fd, "short");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case USHORT:
+ fprintf(fd, "unsigned short");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case INT:
+ fprintf(fd, "int");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case UINT:
+ fprintf(fd, "unsigned int");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case FLOAT:
+ fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case POINTER:
+ fprintf(fd, "const void *");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case LONG:
+ fprintf(fd, "long");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case ULONG:
+ fprintf(fd, "unsigned long");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case SIZE_T:
+ fprintf(fd, "size_t");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case SSIZE_T:
+ fprintf(fd, "ssize_t");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case OFF_T:
+ fprintf(fd, "off_t");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case STRING:
+ fprintf(fd, "const char *");
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case ENUM:
+ fprintf(fd, "enum lttng_%s", basename);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case ARRAY:
+ fprintf(fd, "lttng_array_%s", basename);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case SEQUENCE:
+ fprintf(fd, "lttng_sequence_%s *", basename);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case STRUCT:
+ fprintf(fd, "struct lttng_%s *", basename);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ case UNION:
+ fprintf(fd, "union lttng_%s *", basename);
+ fprintf(fd, " lttng_param_%s", field_name);
+ break;
+ default:
+ printf("print_type : unknown type\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+
+/* Does the type has a fixed size ? (as know from the compiler)
+ *
+ * 1 : fixed size
+ * 0 : variable length
+ */
+int has_type_fixed_size(type_descriptor_t *td)
+{
+ switch(td->type) {
+ case INT_FIXED:
+ case UINT_FIXED:
+ case CHAR:
+ case UCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case POINTER:
+ case LONG:
+ case ULONG:
+ case SIZE_T:
+ case SSIZE_T:
+ case OFF_T:
+ case ENUM:
+ case UNION: /* The union must have fixed size children. Must be checked by
+ the parser */
+ return 1;
+ break;
+ case STRING:
+ case SEQUENCE:
+ return 0;
+ break;
+ case STRUCT:
+ {
+ int has_type_fixed = 0;
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+
+ has_type_fixed = has_type_fixed_size(type);
+ if(!has_type_fixed) return 0;
+ }
+ return 1;
+ }
+ break;
+ case ARRAY:
+ assert(td->size >= 0);
+ return has_type_fixed_size(((field_t*)td->fields.array[0])->type);
+ break;
+ case NONE:
+ printf("There is a type defined to NONE : bad.\n");
+ assert(0);
+ break;
+ }
+ return 0; //make gcc happy.
+}
+
+
+
+
+
+/* print type declaration.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c */
+
+int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ if(td->custom_write) return 0; /* Does print custom type */
+
+ strncpy(basename, nest_name, PATH_MAX);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name, except for
+ * the array. */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_'
+ && (field_name[0] != '\0'))) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ switch(td->type) {
+ case ENUM:
+ fprintf(fd, "enum lttng_%s", basename);
+ fprintf(fd, " {\n");
+ for(unsigned int i=0;i<td->labels.position;i++){
+ print_tabs(1, fd);
+ fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]),
+ (*(int*)td->labels_values.array[i]));
+ fprintf(fd, ",\n");
+ }
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+ break;
+
+ case ARRAY:
+ dprintf("%s\n", basename);
+ assert(td->size >= 0);
+ if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its declaration first */
+ if(print_type_declaration(((field_t*)td->fields.array[0])->type,
+ fd, 0, basename, "")) return 1;
+ }
+ fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename,
+ td->size);
+ fprintf(fd, "typedef ");
+ if(print_type(((field_t*)td->fields.array[0])->type,
+ fd, tabs, basename, "")) return 1;
+ fprintf(fd, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename,
+ basename);
+ fprintf(fd, "\n");
+ break;
+ case SEQUENCE:
+ /* We assume that the sequence length type does not need to be declared.
+ */
+ if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its declaration first */
+ if(print_type_declaration(((field_t*)td->fields.array[1])->type,
+ fd, 0, basename, "")) return 1;
+ }
+ fprintf(fd, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
+ basename,
+ basename);
+ fprintf(fd, "struct lttng_sequence_%s", basename);
+ fprintf(fd, " {\n");
+ print_tabs(1, fd);
+ if(print_type(((field_t*)td->fields.array[0])->type,
+ fd, tabs, basename, "")) return 1;
+ fprintf(fd, " len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "const ");
+ if(print_type(((field_t*)td->fields.array[1])->type,
+ fd, tabs, basename, "")) return 1;
+ fprintf(fd, " *array;\n");
+ fprintf(fd, "};\n"); /* We do not LTT_ALIGN, because we never copy
+ it to the buffer directly. */
+ fprintf(fd, "\n");
+ break;
+
+ case STRUCT:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its declaration first */
+ if(print_type_declaration(type,
+ fd, 0, basename, field->name)) return 1;
+ }
+ }
+ fprintf(fd, "struct lttng_%s", basename);
+ fprintf(fd, " {\n");
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ print_tabs(1, fd);
+ if(print_type(type, fd, tabs, basename, field->name)) return 1;
+ fprintf(fd, " ");
+ fprintf(fd, "%s", field->name);
+ fprintf(fd, ";\n");
+ }
+ if(td->fac->align)
+ fprintf(fd, "} LTT_ALIGN;\n");
+ else
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+ break;
+ case UNION:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its declaration first */
+ if(print_type_declaration(type,
+ fd, 0, basename, field->name)) return 1;
+ }
+ }
+ fprintf(fd, "union lttng_%s", basename);
+ fprintf(fd, " {\n");
+ for(unsigned i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ print_tabs(1, fd);
+ if(print_type(type, fd, tabs, basename, field->name)) return 1;
+ fprintf(fd, " ");
+ fprintf(fd, "%s", field->name);
+ fprintf(fd, ";\n");
+ }
+ if(td->fac->align)
+ fprintf(fd, "} LTT_ALIGN;\n");
+ else
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+ break;
+ default:
+ dprintf("print_type_declaration : unknown type or nothing to declare.\n");
+ break;
+ }
+
+ return 0;
+}
+
+
+/* print type alignment.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name, char *obj_prefix)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ strncpy(basename, nest_name, PATH_MAX);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name, except for
+ * the array. */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_'
+ && field_name != NULL
+ && (field_name[0] != '\0'))) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ if(field_name != NULL)
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ if(field_name[0] == '\0') {
+ /* We are in a write function : it's the obj that we must align. */
+ switch(td->type) {
+ case SEQUENCE:
+ fprintf(fd, "lttng_get_alignment_sequence_%s(%s)", basename,
+ obj_prefix);
+ break;
+ case STRUCT:
+ fprintf(fd, "lttng_get_alignment_struct_%s(%s)", basename,
+ obj_prefix);
+ break;
+ case UNION:
+ fprintf(fd, "lttng_get_alignment_union_%s(%s)", basename,
+ obj_prefix);
+ break;
+ case ARRAY:
+ fprintf(fd, "lttng_get_alignment_array_%s(%s)", basename,
+ obj_prefix);
+ case STRING:
+ fprintf(fd, "sizeof(char)");
+ break;
+ case INT_FIXED:
+ case UINT_FIXED:
+ case CHAR:
+ case UCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case POINTER:
+ case LONG:
+ case ULONG:
+ case SIZE_T:
+ case SSIZE_T:
+ case OFF_T:
+ case ENUM:
+ fprintf(fd, "sizeof(");
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, ")");
+ break;
+
+ default:
+ printf("error : type unexpected\n");
+ return 1;
+ break;
+ }
+ } else {
+
+ switch(td->type) {
+ case INT_FIXED:
+ case UINT_FIXED:
+ case CHAR:
+ case UCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case POINTER:
+ case LONG:
+ case ULONG:
+ case SIZE_T:
+ case SSIZE_T:
+ case OFF_T:
+ case ENUM:
+ fprintf(fd, "sizeof(");
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, ")");
+ break;
+ case STRING:
+ fprintf(fd, "sizeof(char)");
+ break;
+ case SEQUENCE:
+ fprintf(fd, "lttng_get_alignment_sequence_%s(&%s%s)", basename,
+ obj_prefix, field_name);
+ break;
+ case STRUCT:
+ fprintf(fd, "lttng_get_alignment_struct_%s(&%s%s)", basename,
+ obj_prefix, field_name);
+ break;
+ case UNION:
+ fprintf(fd, "lttng_get_alignment_union_%s(&%s%s)", basename,
+ obj_prefix, field_name);
+ break;
+ case ARRAY:
+ fprintf(fd, "lttng_get_alignment_array_%s(%s%s)", basename,
+ obj_prefix, field_name);
+ break;
+ case NONE:
+ printf("error : type NONE unexpected\n");
+ return 1;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+/* print type write.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name, char *obj_prefix, int get_ptr)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+ char get_ptr_char[2] = "";
+ char custom[PATH_MAX] = "";
+
+ strncpy(basename, nest_name, PATH_MAX);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name, except for
+ * the array. */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_'
+ && (field_name[0] != '\0'))) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ if(get_ptr) {
+ strcpy(get_ptr_char, "&");
+ }
+
+ if(td->custom_write) {
+ strcpy(custom, "_custom");
+ }
+
+ switch(td->type) {
+ case INT_FIXED:
+ case UINT_FIXED:
+ case CHAR:
+ case UCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case POINTER:
+ case LONG:
+ case ULONG:
+ case SIZE_T:
+ case SSIZE_T:
+ case OFF_T:
+ case ENUM:
+ print_tabs(tabs, fd);
+ fprintf(fd, "align = ");
+ if(td->fac->align) {
+ if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+ } else
+ fprintf(fd, "0");
+ fprintf(fd, ";\n");
+ fprintf(fd, "\n");
+ print_tabs(tabs, fd);
+ fprintf(fd, "if (*len == 0) {\n");
+ print_tabs(tabs+1, fd);
+ fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+ print_tabs(tabs, fd);
+ fprintf(fd, "} else {\n");
+ print_tabs(tabs+1, fd);
+ fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+ print_tabs(tabs, fd);
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+
+ print_tabs(tabs, fd);
+ fprintf(fd, "*len += ");
+ fprintf(fd, "sizeof(");
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, ");\n");
+
+ break;
+ case STRING:
+ print_tabs(tabs, fd);
+ fprintf(fd,
+ "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n",
+ custom, basename, obj_prefix, field_name);
+ break;
+ case SEQUENCE:
+ print_tabs(tabs, fd);
+ fprintf(fd,
+ "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
+ custom, basename, get_ptr_char, obj_prefix, field_name);
+ break;
+ case STRUCT:
+ print_tabs(tabs, fd);
+ fprintf(fd,
+ "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
+ custom, basename, get_ptr_char, obj_prefix, field_name);
+ break;
+ case UNION:
+ print_tabs(tabs, fd);
+ fprintf(fd,
+ "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);",
+ custom, basename, get_ptr_char, obj_prefix, field_name);
+ break;
+ case ARRAY:
+ print_tabs(tabs, fd);
+ fprintf(fd,
+ "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);",
+ custom, basename, obj_prefix, field_name);
+ break;
+ case NONE:
+ printf("Error : type NONE unexpected\n");
+ return 1;
+ break;
+ }
+
+ return 0;
+}
+
+/* print need local vars ?.
+ *
+ * Copied from print_type_write
+ *
+ * Does the type_write call needs local size and from variables ?
+ * return value : 1 yes, 0 no.
+ */
+
+int has_type_local(type_descriptor_t * td)
+{
+ switch(td->type) {
+ case INT_FIXED:
+ case UINT_FIXED:
+ case CHAR:
+ case UCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case POINTER:
+ case LONG:
+ case ULONG:
+ case SIZE_T:
+ case SSIZE_T:
+ case OFF_T:
+ case ENUM:
+ return 1;
+ break;
+ case STRING:
+ case SEQUENCE:
+ case STRUCT:
+ case UNION:
+ case ARRAY:
+ return 0;
+ break;
+ case NONE:
+ printf("Error : type NONE unexpected\n");
+ return 1;
+ break;
+ }
+
+ return 0;
+}
+
+
+
+/* print type alignment function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
+ unsigned int tabs,
+ char *nest_name, char *field_name)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ if(td->custom_write) return 0; /* Does print custom type */
+ if(td->fac->align == 0) return 0;
+
+ strncpy(basename, nest_name, PATH_MAX);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name, except for
+ * the array. */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_'
+ && (field_name[0] != '\0'))) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ switch(td->type) {
+ case SEQUENCE:
+ if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its align fct */
+ if(print_type_alignment_fct(((field_t*)td->fields.array[1])->type, fd,
+ 0, basename, "")) return 1;
+ }
+ /* Function header */
+ fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n",
+ basename);
+ print_tabs(2, fd);
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, " *obj)\n");
+ fprintf(fd, "{\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t align=0, localign;");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "localign = ");
+ if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+ fd, 0, basename, "len", "obj->")) return 1;
+ fprintf(fd, ";\n");
+ print_tabs(1, fd);
+ fprintf(fd, "align = max(align, localign);\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "localign = ");
+ if(print_type_alignment(((field_t*)td->fields.array[1])->type,
+ fd, 0, basename, "array[0]", "obj->")) return 1;
+ fprintf(fd, ";\n");
+ print_tabs(1, fd);
+ fprintf(fd, "align = max(align, localign);\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "return align;\n");
+ break;
+ case STRUCT:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its align fct */
+ if(print_type_alignment_fct(type, fd,
+ 0, basename, field->name)) return 1;
+ }
+ }
+ /* Function header */
+ fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n",
+ basename);
+ print_tabs(2, fd);
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, " *obj)\n");
+ fprintf(fd, "{\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t align=0, localign;");
+ fprintf(fd, "\n");
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ print_tabs(1, fd);
+ fprintf(fd, "localign = ");
+ if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+ return 1;
+ fprintf(fd, ";\n");
+ print_tabs(1, fd);
+ fprintf(fd, "align = max(align, localign);\n");
+ fprintf(fd, "\n");
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "return align;\n");
+
+ break;
+ case UNION:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its align fct */
+ if(print_type_alignment_fct(type, fd,
+ 0, basename, field->name)) return 1;
+ }
+ }
+ /* Function header */
+ fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n",
+ basename);
+ print_tabs(2, fd);
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, " *obj)\n");
+ fprintf(fd, "{\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t align=0, localign;");
+ fprintf(fd, "\n");
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ print_tabs(1, fd);
+ fprintf(fd, "localign = ");
+ if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+ return 1;
+ fprintf(fd, ";\n");
+ print_tabs(1, fd);
+ fprintf(fd, "align = max(align, localign);\n");
+ fprintf(fd, "\n");
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "return align;\n");
+
+ break;
+ case ARRAY:
+ if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its align fct */
+ if(print_type_alignment_fct(((field_t*)td->fields.array[0])->type, fd,
+ 0, basename, "")) return 1;
+ }
+ /* Function header */
+ fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n",
+ basename);
+ print_tabs(2, fd);
+ if(print_type(td, fd, 0, basename, "")) return 1;
+ fprintf(fd, " obj)\n");
+ fprintf(fd, "{\n");
+ print_tabs(1, fd);
+ fprintf(fd, "return \n");
+ if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+ fd, 0, basename, "", "obj[0]"))
+ return 1;
+ fprintf(fd, ";\n");
+ break;
+ default:
+ dprintf("print_type_alignment_fct : type has no alignment function.\n");
+ return 0;
+ break;
+ }
+
+
+ /* Function footer */
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+
+ return 0;
+}
+
+/* print type write function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+ char *nest_name, char *field_name)
+{
+ char basename[PATH_MAX];
+ unsigned int basename_len = 0;
+
+ if(td->custom_write) return 0; /* Does print custom type */
+
+ strncpy(basename, nest_name, PATH_MAX);
+ basename_len = strlen(basename);
+
+ /* For a named type, we use the type_name directly */
+ if(td->type_name != NULL) {
+ strncpy(basename, td->type_name, PATH_MAX);
+ basename_len = strlen(basename);
+ } else {
+ /* For a unnamed type, there must be a field name, except for
+ * the array. */
+ if((basename_len != 0)
+ && (basename[basename_len-1] != '_'
+ && (field_name[0] != '\0'))) {
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len = strlen(basename);
+ }
+ strncat(basename, field_name, PATH_MAX - basename_len);
+ }
+
+ switch(td->type) {
+ case SEQUENCE:
+ if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its write fct */
+ if(print_type_write_fct(((field_t*)td->fields.array[1])->type, fd,
+ 0, basename, "")) return 1;
+ }
+ break;
+ case STRUCT:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its write fct */
+ if(print_type_write_fct(type, fd,
+ 0, basename, field->name)) return 1;
+ }
+ }
+ break;
+ case UNION:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(type->type_name == NULL) {
+ /* Not a named nested type : we must print its write fct */
+ if(print_type_write_fct(type, fd,
+ 0, basename, field->name)) return 1;
+ }
+ }
+ break;
+ case ARRAY:
+ if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
+ /* Not a named nested type : we must print its write fct */
+ if(print_type_write_fct(((field_t*)td->fields.array[0])->type, fd,
+ 0, basename, "")) return 1;
+ }
+ break;
+ case STRING:
+ break;
+ default:
+ dprintf("print_type_write_fct : type has no write function.\n");
+ return 0;
+ break;
+ }
+
+ /* Print header */
+ switch(td->type) {
+ case SEQUENCE:
+ fprintf(fd, "static inline void lttng_write_sequence_%s(\n",
+ basename);
+ break;
+ case STRUCT:
+ fprintf(fd, "static inline void lttng_write_struct_%s(\n", basename);
+ break;
+ case UNION:
+ fprintf(fd, "static inline void lttng_write_union_%s(\n", basename);
+ break;
+ case ARRAY:
+ fprintf(fd, "static inline void lttng_write_array_%s(\n", basename);
+ break;
+ case STRING:
+ fprintf(fd, "static inline void lttng_write_string_%s(\n", basename);
+ break;
+ default:
+ printf("print_type_write_fct : type has no write function.\n");
+ break;
+ }
+
+ print_tabs(2, fd);
+ fprintf(fd, "char *buffer,\n");
+ print_tabs(2, fd);
+ fprintf(fd, "size_t *to_base,\n");
+ print_tabs(2, fd);
+ fprintf(fd, "size_t *to,\n");
+ print_tabs(2, fd);
+ fprintf(fd, "const char **from,\n");
+ print_tabs(2, fd);
+ fprintf(fd, "size_t *len,\n");
+ print_tabs(2, fd);
+ if(print_type(td, fd, 0, basename, "")) return 1;
+
+ switch(td->type) {
+ case SEQUENCE:
+ fprintf(fd, " *obj)\n");
+ break;
+ case STRUCT:
+ fprintf(fd, " *obj)\n");
+ break;
+ case UNION:
+ fprintf(fd, " *obj)\n");
+ break;
+ case ARRAY:
+ fprintf(fd, " obj)\n");
+ break;
+ case STRING:
+ fprintf(fd, " obj)\n");
+ break;
+ default:
+ printf("print_type_write_fct : type has no write function.\n");
+ break;
+ }
+
+ fprintf(fd, "{\n");
+
+ switch(td->type) {
+ case STRING:
+ print_tabs(1, fd);
+ fprintf(fd, "size_t size;\n");
+ break;
+ default:
+ break;
+ }
+
+ print_tabs(1, fd);
+ fprintf(fd, "size_t align;\n");
+ fprintf(fd, "\n");
+
+ switch(td->type) {
+ case SEQUENCE:
+ case STRING:
+ print_tabs(1, fd);
+ fprintf(fd, "/* Flush pending memcpy */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "if (*len != 0) {\n");
+ print_tabs(2, fd);
+ fprintf(fd, "if (buffer != NULL)\n");
+ print_tabs(3, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "}\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to += *len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*len = 0;\n");
+ fprintf(fd, "\n");
+ break;
+ case STRUCT:
+ case UNION:
+ case ARRAY:
+ break;
+ default:
+ printf("print_type_write_fct : type has no write function.\n");
+ break;
+ }
+
+ print_tabs(1, fd);
+ fprintf(fd, "align = ");
+ if(td->fac->align) {
+ if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+ } else
+ fprintf(fd, "0");
+ fprintf(fd, ";\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "if (*len == 0) {\n");
+ print_tabs(2, fd);
+ fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "} else {\n");
+ print_tabs(2, fd);
+ fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+
+ /* First, check if the type has a fixed size. If it is the case, then the size
+ * to write is know by the compiler : simply use a sizeof() */
+ if(has_type_fixed_size(td)) {
+ print_tabs(1, fd);
+ fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*len += sizeof(");
+ if(print_type(td, fd, 0, basename, field_name)) return 1;
+ fprintf(fd, ");\n");
+ } else {
+ /* The type contains nested variable size subtypes :
+ * we must write field by field. */
+ print_tabs(1, fd);
+ fprintf(fd, "/* Contains variable sized fields : must explode the structure */\n");
+ fprintf(fd, "\n");
+
+ switch(td->type) {
+ case SEQUENCE:
+ print_tabs(1, fd);
+ fprintf(fd, "/* Copy members */\n");
+// print_tabs(1, fd);
+// fprintf(fd, "size = sizeof(\n");
+ if(print_type_write(((field_t*)td->fields.array[0])->type,
+ fd, 1, basename, "len", "obj->", 1)) return 1;
+ fprintf(fd, "\n");
+// fprintf(fd, ");\n");
+// print_tabs(1, fd);
+// fprintf(fd, "*to += ltt_align(*to, size);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "if (buffer != NULL)\n");
+ print_tabs(2, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to += *len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*len = 0;\n");
+ fprintf(fd, "\n");
+
+ /* Write the child : varlen child or not ? */
+ if(has_type_fixed_size(((field_t*)td->fields.array[1])->type)) {
+ /* Fixed size len child : use a multiplication of its size */
+// print_tabs(1, fd);
+// fprintf(fd, "size = sizeof(\n");
+
+ //print_tabs(1, fd);
+ /* We know that *len does not contain alignment because of the
+ * previous align output. len is always 0 here. */
+ if(print_type_write(((field_t*)td->fields.array[1])->type,
+ fd, 1, basename, "array[0]", "obj->", 1))
+ return 1;
+// fprintf(fd, ");\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*len = obj->len * (*len);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "if (buffer != NULL)\n");
+ print_tabs(2, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to += *len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*len = 0;\n");
+ fprintf(fd, "\n");
+ } else {
+ print_tabs(1, fd);
+ fprintf(fd, "/* Variable length child : iter. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "for (unsigned int i = 0; i < obj->len; i++) {\n");
+ if(print_type_write(((field_t*)td->fields.array[1])->type,
+ fd, 2, basename, "array[i]", "obj->", 1)) return 1;
+ print_tabs(1, fd);
+ fprintf(fd, "}\n");
+ }
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+ print_tabs(1, fd);
+ if(td->fac->align)
+ fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to_base = *to_base+*to;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to = 0;\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Put source *from just after the C sequence */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*from = (const char*)(obj+1);\n");
+ break;
+ case STRING:
+ print_tabs(1, fd);
+ fprintf(fd, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "if (buffer != NULL)\n");
+ print_tabs(2, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, obj, size);\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to += size;\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+ print_tabs(1, fd);
+ if(td->fac->align)
+ fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to_base = *to_base+*to;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*to = 0;\n");
+ fprintf(fd, "\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Put source *from just after the C string */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "*from += size;\n");
+ break;
+ case STRUCT:
+ for(unsigned int i=0;i<td->fields.position;i++){
+ field_t *field = (field_t*)(td->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ if(print_type_write(type,
+ fd, 1, basename, field->name, "obj->", 1)) return 1;
+ fprintf(fd, "\n");
+ }
+ break;
+ case UNION:
+ printf("ERROR : A union CANNOT contain a variable size child.\n");
+ return 1;
+ break;
+ case ARRAY:
+ /* Write the child : varlen child or not ? */
+ if(has_type_fixed_size(((field_t*)td->fields.array[0])->type)) {
+ /* Error : if an array has a variable size, then its child must also
+ * have a variable size. */
+ assert(0);
+ } else {
+ print_tabs(1, fd);
+ fprintf(fd, "/* Variable length child : iter. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "for (unsigned int i = 0; i < LTTNG_ARRAY_SIZE_%s; i++) {\n", basename);
+ if(print_type_write(((field_t*)td->fields.array[0])->type,
+ fd, 2, basename, "", "obj->array[i]", 1)) return 1;
+ print_tabs(1, fd);
+ fprintf(fd, "}\n");
+ }
+ break;
+ default:
+ printf("print_type_write_fct : type has no write function.\n");
+ break;
+ }
+
+
+ }
+
+
+ /* Function footer */
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+ return 0;
+}
+
+
+
+/* Print the logging function of an event. This is the core of genevent */
+int print_event_logging_function(char *basename, facility_t *fac,
+ event_t *event, FILE *fd)
+{
+ fprintf(fd, "static inline void trace_%s(\n", basename);
+ int has_argument = 0;
+ int has_type_fixed = 0;
+
+ /* Does it support per trace tracing ? */
+ if(event->per_trace) {
+ print_tabs(2, fd);
+ fprintf(fd, "struct ltt_trace_struct *dest_trace");
+ has_argument = 1;
+ }
+
+ /* Does it support per tracefile tracing ? */
+ if(event->per_tracefile) {
+ if(has_argument) {
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ }
+ fprintf(fd, "unsigned int tracefile_index");
+ has_argument = 1;
+ }
+
+ for(unsigned int j = 0; j < event->fields.position; j++) {
+ /* For each field, print the function argument */
+ field_t *f = (field_t*)event->fields.array[j];
+ type_descriptor_t *t = f->type;
+ if(has_argument) {
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ }
+ if(print_arg(t, fd, 2, basename, f->name)) return 1;
+ has_argument = 1;
+ }
+ if(!has_argument) {
+ print_tabs(2, fd);
+ fprintf(fd, "void");
+ }
+ fprintf(fd,")\n");
+#if 0
+ fprintf(fd,
+ "#if (!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n",
+ fac->capname, fac->capname);
+ fprintf(fd, "{\n");
+ fprintf(fd, "}\n");
+ fprintf(fd,"#else\n");
+#endif //0
+ fprintf(fd, "{\n");
+ /* Print the function variables */
+ print_tabs(1, fd);
+ fprintf(fd, "unsigned int index;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "struct ltt_channel_struct *channel;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "struct ltt_trace_struct *trace;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "void *transport_data;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "char *buffer = NULL;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to_base = &real_to_base;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to = &real_to;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_len = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *len = &real_len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t reserve_size;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t slot_size;\n");
+ print_tabs(1, fd);
+
+ if(event->fields.position > 0) {
+ for(unsigned int i=0;i<event->fields.position;i++){
+ /* Search for at least one child with fixed size. It means
+ * we need local variables.*/
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ has_type_fixed = has_type_local(type);
+ if(has_type_fixed) break;
+ }
+
+ if(has_type_fixed) {
+ fprintf(fd, "size_t align;\n");
+ print_tabs(1, fd);
+ }
+
+ fprintf(fd, "const char *real_from;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "const char **from = &real_from;\n");
+ print_tabs(1, fd);
+ }
+ fprintf(fd, "u64 tsc;\n");
+ fprintf(fd, "\n");
+
+ if(!event->force) {
+ print_tabs(1, fd);
+ fprintf(fd, "if (ltt_traces.num_active_traces == 0)\n");
+ print_tabs(2, fd);
+ fprintf(fd, "return;\n");
+ fprintf(fd, "\n");
+ }
+
+ /* Calculate event variable len + event data alignment offset.
+ * Assume that the padding for alignment starts at a void*
+ * address.
+ * This excludes the header size and alignment. */
+
+ print_tabs(1, fd);
+ fprintf(fd, "/* For each field, calculate the field size. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* size = *to_base + *to + *len */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+ print_tabs(1, fd);
+ fprintf(fd, " * sizeof(void *) address. */\n");
+ fprintf(fd, "\n");
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ /* Set from */
+ print_tabs(1, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+ if(print_type_write(type,
+ fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+ /* Take locks : make sure the trace does not vanish while we write on
+ * it. A simple preemption disabling is enough (using rcu traces). */
+ print_tabs(1, fd);
+ fprintf(fd, "preempt_disable();\n");
+ print_tabs(1, fd);
+ fprintf(fd, "ltt_nesting[smp_processor_id()]++;\n");
+
+ /* Get facility index */
+
+ if(event->per_tracefile) {
+ print_tabs(1, fd);
+ fprintf(fd, "index = tracefile_index;\n");
+ } else {
+ print_tabs(1, fd);
+ fprintf(fd,
+ "index = ltt_get_index_from_facility_%s(" \
+ "\t\t\t\t\t\tevent_%s_%s);\n",
+ fac->name, fac->name, event->name);
+ }
+ fprintf(fd,"\n");
+
+
+ /* For each trace */
+ print_tabs(1, fd);
+ fprintf(fd, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
+ if(!event->force) {
+ print_tabs(2, fd);
+ fprintf(fd, "if (!trace->active)\n");
+ print_tabs(3, fd);
+ fprintf(fd, "continue;\n\n");
+ }
+
+ if(event->per_trace) {
+ print_tabs(2, fd);
+ fprintf(fd, "if (dest_trace != trace)\n");
+ print_tabs(3, fd);
+ fprintf(fd, "continue;\n\n");
+ }
+
+ print_tabs(2, fd);
+ fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n");
+ fprintf(fd, "\n");
+
+
+ /* Relay reserve */
+ /* If error, increment event lost counter (done by ltt_reserve_slot) and
+ * return */
+ print_tabs(2, fd);
+ fprintf(fd, "slot_size = 0;\n");
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = ltt_reserve_slot(trace, channel, &transport_data,\n");
+ print_tabs(3, fd);
+ fprintf(fd, "reserve_size, &slot_size, &tsc);\n");
+ /* If error, return */
+ print_tabs(2, fd);
+ fprintf(fd, "if (!buffer)\n");
+ print_tabs(3, fd);
+ fprintf(fd, "continue; /* buffer full */\n\n");
+ //print_tabs(2, fd);
+ // for DEBUG only
+ // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+ print_tabs(2, fd);
+ fprintf(fd, "*to_base = *to = *len = 0;\n");
+ fprintf(fd, "\n");
+
+ /* Write event header */
+ if(strcmp("compact", fac->name) != 0) {
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = ltt_write_event_header(trace, channel, buffer,\n");
+ print_tabs(3, fd);
+ fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+ fac->name, event->name);
+ print_tabs(3, fd);
+ fprintf(fd, "reserve_size, tsc);\n");
+ } else {
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = ltt_write_compact_header(trace, channel, buffer,\n");
+ print_tabs(3, fd);
+ fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+ fac->name, event->name);
+ print_tabs(3, fd);
+ if(event->compact_data) {
+ assert(event->fields.position > 0);
+ field_t *field = (field_t*)(event->fields.array[0]);
+ fprintf(fd, "reserve_size, tsc, lttng_param_%s);\n",
+ field->name);
+ } else
+ fprintf(fd, "reserve_size, tsc, 0);\n");
+ }
+
+ /* write data. */
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+
+ /* First param is compacted in the header */
+ if(event->compact_data && i == 0)
+ continue;
+ /* Set from */
+ print_tabs(2, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+
+ if(print_type_write(type,
+ fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+
+ /* Don't forget to flush pending memcpy */
+ print_tabs(2, fd);
+ fprintf(fd, "/* Flush pending memcpy */\n");
+ print_tabs(2, fd);
+ fprintf(fd, "if (*len != 0) {\n");
+ print_tabs(3, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*to += *len;\n");
+ //print_tabs(3, fd);
+ //fprintf(fd, "from += len;\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*len = 0;\n");
+ print_tabs(2, fd);
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+ }
+
+
+ /* commit */
+ // for DEBUG only.
+ //fprintf(fd, "commit:\n"); /* DEBUG! */
+ print_tabs(2, fd);
+ fprintf(fd, "ltt_commit_slot(channel, &transport_data, buffer, slot_size);\n\n");
+
+ print_tabs(1, fd);
+ fprintf(fd, "}\n\n");
+
+ /* Release locks */
+ print_tabs(1, fd);
+ fprintf(fd, "ltt_nesting[smp_processor_id()]--;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "preempt_enable();\n");
+
+ fprintf(fd, "}\n");
+#if 0
+ fprintf(fd, "#endif //(!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n\n",
+ fac->capname, fac->capname);
+#endif //0
+ return 0;
+}
+
+int print_event_logging_function_header_user_generic(char *basename, facility_t *fac,
+ event_t *event, FILE *fd, enum user_fct_types fct_type)
+{
+ char *attrib;
+
+ if(event->no_instrument_function && fct_type == USER_FCT_PROTO) {
+ attrib = "__attribute__((no_instrument_function)) ";
+ } else {
+ attrib = "";
+ }
+ if(event->param_buffer) {
+ fprintf(fd, "static inline %sint trace_%s_param_buffer(\n", attrib, basename);
+ } else {
+ fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
+ }
+ int has_argument = 0;
+
+ if(event->param_buffer) {
+ if(has_argument) {
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ }
+ print_tabs(2, fd);
+ fprintf(fd, "char *buffer");
+ has_argument = 1;
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ print_tabs(2, fd);
+ fprintf(fd, "size_t reserve_size");
+ } else {
+ for(unsigned int j = 0; j < event->fields.position; j++) {
+ /* For each field, print the function argument */
+ field_t *f = (field_t*)event->fields.array[j];
+ type_descriptor_t *t = f->type;
+ if(has_argument) {
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ }
+ if(print_arg(t, fd, 2, basename, f->name)) return 1;
+ has_argument = 1;
+ }
+ }
+ if(!has_argument) {
+ print_tabs(2, fd);
+ fprintf(fd, "void");
+ }
+ fprintf(fd,")");
+ return 0;
+}
+
+
+/* print_event_logging_function_user_generic
+ * Print the logging function of an event for userspace tracing. This is the
+ * core of genevent */
+int print_event_logging_function_user_generic(char *basename, facility_t *fac,
+ event_t *event, FILE *fd)
+{
+ int has_type_fixed = 0;
+
+ if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_PROTO)) return 1;
+ fprintf(fd,";\n");
+ fprintf(fd,"\n");
+ fprintf(fd, "#ifndef LTT_TRACE_FAST\n");
+ if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_DECLARATION)) return 1;
+ fprintf(fd,"\n");
+ fprintf(fd,
+ "#ifndef LTT_TRACE\n");
+ fprintf(fd, "{\n");
+ fprintf(fd, "}\n");
+ fprintf(fd,"#else\n");
+ fprintf(fd, "{\n");
+ /* Print the function variables */
+ print_tabs(1, fd);
+ fprintf(fd, "int ret = 0;\n");
+ if(event->param_buffer) {
+ //FIX print_tabs(1, fd);
+ //fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
+ print_tabs(1, fd);
+ fprintf(fd, "{\n");
+ goto do_syscall;
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "char *buffer = NULL;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to_base = &real_to_base;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to = &real_to;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_len = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *len = &real_len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t reserve_size;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t slot_size;\n");
+ print_tabs(1, fd);
+
+ if(event->fields.position > 0) {
+ for(unsigned int i=0;i<event->fields.position;i++){
+ /* Search for at least one child with fixed size. It means
+ * we need local variables.*/
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ has_type_fixed = has_type_local(type);
+ if(has_type_fixed) break;
+ }
+
+ if(has_type_fixed) {
+ fprintf(fd, "size_t align;\n");
+ print_tabs(1, fd);
+ }
+
+ fprintf(fd, "const char *real_from;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "const char **from = &real_from;\n");
+ print_tabs(1, fd);
+ }
+
+ /* Calculate event variable len + event data alignment offset.
+ * Assume that the padding for alignment starts at a void*
+ * address.
+ * This excludes the header size and alignment. */
+
+ print_tabs(1, fd);
+ fprintf(fd, "/* For each field, calculate the field size. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* size = *to_base + *to + *len */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+ print_tabs(1, fd);
+ fprintf(fd, " * sizeof(void *) address. */\n");
+ fprintf(fd, "\n");
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ /* Set from */
+ print_tabs(1, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+ if(print_type_write(type,
+ fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+ print_tabs(1, fd);
+ fprintf(fd, "{\n");
+ print_tabs(2, fd);
+ fprintf(fd, "char stack_buffer[reserve_size];\n");
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = stack_buffer;\n");
+ fprintf(fd, "\n");
+
+
+ //print_tabs(2, fd);
+ // for DEBUG only
+ // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+ print_tabs(2, fd);
+ fprintf(fd, "*to_base = *to = *len = 0;\n");
+ fprintf(fd, "\n");
+
+ /* write data. */
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+
+ /* Set from */
+ print_tabs(2, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+
+ if(print_type_write(type,
+ fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+
+ /* Don't forget to flush pending memcpy */
+ print_tabs(2, fd);
+ fprintf(fd, "/* Flush pending memcpy */\n");
+ print_tabs(2, fd);
+ fprintf(fd, "if (*len != 0) {\n");
+ print_tabs(3, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*to += *len;\n");
+ //print_tabs(3, fd);
+ //fprintf(fd, "from += len;\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*len = 0;\n");
+ print_tabs(2, fd);
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+ }
+
+do_syscall:
+ print_tabs(2, fd);
+ fprintf(fd, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING, %u);\n", fac->name, fac->checksum, fac->name, event->name, event->high_priority);
+
+ print_tabs(1, fd);
+ fprintf(fd, "}\n\n");
+
+ print_tabs(1, fd);
+ fprintf(fd, "return ret;\n\n");
+
+ fprintf(fd, "}\n");
+ fprintf(fd,
+ "#endif //LTT_TRACE\n");
+ fprintf(fd, "#endif //!LTT_TRACE_FAST\n\n");
+
+ return 0;
+}
+
+/* print_event_logging_function_user_fast
+ * Print the logging function of an event for userspace tracing. This is the
+ * core of genevent */
+int print_event_logging_function_user_fast(char *basename, facility_t *fac,
+ event_t *event, FILE *fd)
+{
+ char *attrib;
+
+ fprintf(fd, "#ifdef LTT_TRACE_FAST\n");
+
+ if(event->no_instrument_function) {
+ attrib = "__attribute__((no_instrument_function)) ";
+ } else {
+ attrib = "";
+ }
+ fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
+
+ int has_argument = 0;
+ int has_type_fixed = 0;
+
+ for(unsigned int j = 0; j < event->fields.position; j++) {
+ /* For each field, print the function argument */
+ field_t *f = (field_t*)event->fields.array[j];
+ type_descriptor_t *t = f->type;
+ if(has_argument) {
+ fprintf(fd, ",");
+ fprintf(fd, "\n");
+ }
+ if(print_arg(t, fd, 2, basename, f->name)) return 1;
+ has_argument = 1;
+ }
+ if(!has_argument) {
+ print_tabs(2, fd);
+ fprintf(fd, "void");
+ }
+ fprintf(fd,")\n");
+ fprintf(fd,
+ "#ifndef LTT_TRACE\n");
+ fprintf(fd, "{\n");
+ fprintf(fd, "}\n");
+ fprintf(fd,"#else\n");
+ fprintf(fd, "{\n");
+ /* Print the function variables */
+ print_tabs(1, fd);
+ fprintf(fd, "unsigned int index;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "struct ltt_trace_info *trace = thread_trace_info;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "struct ltt_buf *ltt_buf;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "char *buffer = NULL;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to_base = &real_to_base;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_to = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *to = &real_to;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t real_len = 0;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t *len = &real_len;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t reserve_size;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "size_t slot_size;\n");
+ print_tabs(1, fd);
+
+ if(event->fields.position > 0) {
+ for(unsigned int i=0;i<event->fields.position;i++){
+ /* Search for at least one child with fixed size. It means
+ * we need local variables.*/
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ has_type_fixed = has_type_local(type);
+ if(has_type_fixed) break;
+ }
+
+ if(has_type_fixed) {
+ fprintf(fd, "size_t align;\n");
+ print_tabs(1, fd);
+ }
+
+ fprintf(fd, "const char *real_from;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "const char **from = &real_from;\n");
+ print_tabs(1, fd);
+ }
+ fprintf(fd, "uint64_t tsc;\n");
+ print_tabs(1, fd);
+
+ print_tabs(1, fd);
+ fprintf(fd, "if (!trace) {\n");
+ print_tabs(2, fd);
+ fprintf(fd, "ltt_thread_init();\n");
+ print_tabs(2, fd);
+ fprintf(fd, "trace = thread_trace_info;\n");
+ print_tabs(1, fd);
+ fprintf(fd, "}\n\n");
+ fprintf(fd, "\n");
+
+ /* Calculate event variable len + event data alignment offset.
+ * Assume that the padding for alignment starts at a void*
+ * address.
+ * This excludes the header size and alignment. */
+
+ print_tabs(1, fd);
+ fprintf(fd, "/* For each field, calculate the field size. */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* size = *to_base + *to + *len */\n");
+ print_tabs(1, fd);
+ fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+ print_tabs(1, fd);
+ fprintf(fd, " * sizeof(void *) address. */\n");
+ fprintf(fd, "\n");
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+ /* Set from */
+ print_tabs(1, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+ if(print_type_write(type,
+ fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+ print_tabs(1, fd);
+ fprintf(fd, "trace->nesting++;\n");
+
+ /* Get facility index */
+
+ print_tabs(1, fd);
+ fprintf(fd,
+ "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
+ "\t\t\t\t\t\tevent_%s_%s);\n",
+ fac->name, fac->checksum, fac->name, event->name);
+ fprintf(fd,"\n");
+
+
+ print_tabs(1, fd);
+ fprintf(fd, "{\n");
+
+ if(event->per_trace) {
+ print_tabs(2, fd);
+ fprintf(fd, "if (dest_trace != trace) continue;\n\n");
+ }
+
+ print_tabs(2, fd);
+ fprintf(fd, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
+ print_tabs(2, fd);
+
+
+ /* Relay reserve */
+ /* If error, increment event lost counter (done by ltt_reserve_slot) and
+ * return */
+ print_tabs(2, fd);
+ fprintf(fd, "slot_size = 0;\n");
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
+ print_tabs(3, fd);
+ fprintf(fd, "reserve_size, &slot_size, &tsc);\n");
+ /* If error, return */
+ print_tabs(2, fd);
+ fprintf(fd, "if (!buffer)\n");
+ print_tabs(3, fd);
+ fprintf(fd, "goto end; /* buffer full */\n\n");
+ //print_tabs(2, fd);
+ // for DEBUG only
+ // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+ print_tabs(2, fd);
+ fprintf(fd, "*to_base = *to = *len = 0;\n");
+ fprintf(fd, "\n");
+
+ /* Write event header */
+ print_tabs(2, fd);
+ fprintf(fd, "buffer = ltt_write_event_header(trace, ltt_buf, buffer,\n");
+ print_tabs(3, fd);
+ fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+ fac->name, event->name);
+ print_tabs(3, fd);
+ fprintf(fd, "reserve_size, tsc);\n");
+
+ /* write data. */
+
+ for(unsigned int i=0;i<event->fields.position;i++){
+ field_t *field = (field_t*)(event->fields.array[i]);
+ type_descriptor_t *type = field->type;
+
+ /* Set from */
+ print_tabs(2, fd);
+ switch(type->type) {
+ case SEQUENCE:
+ case UNION:
+ case ARRAY:
+ case STRUCT:
+ case STRING:
+ fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name);
+ break;
+ default:
+ fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name);
+ break;
+ }
+
+
+ if(print_type_write(type,
+ fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+ fprintf(fd, "\n");
+
+ /* Don't forget to flush pending memcpy */
+ print_tabs(2, fd);
+ fprintf(fd, "/* Flush pending memcpy */\n");
+ print_tabs(2, fd);
+ fprintf(fd, "if (*len != 0) {\n");
+ print_tabs(3, fd);
+ fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*to += *len;\n");
+ //print_tabs(3, fd);
+ //fprintf(fd, "from += len;\n");
+ print_tabs(3, fd);
+ fprintf(fd, "*len = 0;\n");
+ print_tabs(2, fd);
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+ }
+
+
+ /* commit */
+ // for DEBUG only.
+ //fprintf(fd, "commit:\n"); /* DEBUG! */
+ print_tabs(2, fd);
+ fprintf(fd, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
+
+ fprintf(fd, "}\n\n");
+
+ fprintf(fd, "end:\n");
+ /* Release locks */
+ print_tabs(1, fd);
+ fprintf(fd, "trace->nesting--;\n");
+
+
+ fprintf(fd, "}\n");
+ fprintf(fd,
+ "#endif //LTT_TRACE\n");
+ fprintf(fd, "#endif //LTT_TRACE_FAST\n");
+
+ return 0;
+}
+
+
+
+
+
+
+/* ltt-facility-name.h : main logging header.
+ * log_header */
+
+void print_log_header_head(facility_t *fac, FILE *fd)
+{
+ fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
+ fprintf(fd, "#include <linux/types.h>\n");
+ if(!fac->arch)
+ fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name);
+ else
+ fprintf(fd, "#include <ltt/ltt-facility-id-%s_%s.h>\n",
+ fac->name,
+ fac->arch);
+ fprintf(fd, "#include <ltt/ltt-tracer.h>\n");
+ fprintf(fd, "\n");
+}
+
+/* ltt-facility-name.h : main logging header.
+ * log_header */
+
+void print_log_header_head_user(facility_t *fac, FILE *fd)
+{
+ fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
+ fprintf(fd, "#include <sys/types.h>\n");
+ if(!fac->arch)
+ fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name);
+ else
+ fprintf(fd, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
+ fac->name,
+ fac->arch);
+ fprintf(fd, "#include <ltt/ltt-usertrace.h>\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#ifdef __cplusplus\n");
+ fprintf(fd, "extern \"C\" {\n");
+ fprintf(fd, "#endif\n");
+ fprintf(fd, "\n");
+}
+
+
+int print_log_header_types(facility_t *fac, FILE *fd)
+{
+ sequence_t *types = &fac->named_types.values;
+ fprintf(fd, "/* Named types */\n");
+ fprintf(fd, "\n");
+
+ for(unsigned int i = 0; i < types->position; i++) {
+ /* For each named type, print the definition */
+ if(print_type_declaration(types->array[i], fd,
+ 0, "", "")) return 1;
+ /* Print also the align function */
+ if(((type_descriptor_t*)types->array[i])->fac->align)
+ if(print_type_alignment_fct(types->array[i], fd,
+ 0, "", "")) return 1;
+ /* Print also the write function */
+ if(print_type_write_fct(types->array[i], fd,
+ 0, "", "")) return 1;
+ }
+ return 0;
+}
+
+int print_log_header_events(facility_t *fac, FILE *fd)
+{
+ sequence_t *events = &fac->events;
+ char basename[PATH_MAX];
+ unsigned int facname_len;
+
+ strncpy(basename, fac->name, PATH_MAX);
+ facname_len = strlen(basename);
+ strncat(basename, "_", PATH_MAX-facname_len);
+ facname_len = strlen(basename);
+
+ for(unsigned int i = 0; i < events->position; i++) {
+ event_t *event = (event_t*)events->array[i];
+ strncpy(&basename[facname_len], event->name, PATH_MAX-facname_len);
+
+ /* For each event, print structure, and then logging function */
+ fprintf(fd, "/* Event %s structures */\n",
+ event->name);
+ for(unsigned int j = 0; j < event->fields.position; j++) {
+ /* For each unnamed type, print the definition */
+ field_t *f = (field_t*)event->fields.array[j];
+ type_descriptor_t *t = f->type;
+ if(t->type_name == NULL) {
+ if((print_type_declaration(t, fd, 0, basename, f->name))) return 1;
+ /* Print also the align function */
+ if(fac->align) {
+ if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1;
+ }
+ /* Print also the write function */
+ if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1;
+ }
+ }
+
+ fprintf(fd, "\n");
+
+ fprintf(fd, "/* Event %s logging function */\n",
+ event->name);
+
+ if(!fac->user) {
+ if(print_event_logging_function(basename, fac, event, fd)) return 1;
+ } else {
+ if(print_event_logging_function_user_generic(basename, fac, event, fd))
+ return 1;
+ if(print_event_logging_function_user_fast(basename, fac, event, fd))
+ return 1;
+ }
+
+ fprintf(fd, "\n");
+ }
+
+ return 0;
+}
+
+
+void print_log_header_tail(facility_t *fac, FILE *fd)
+{
+ fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
+}
+
+void print_log_header_tail_user(facility_t *fac, FILE *fd)
+{
+ fprintf(fd, "#ifdef __cplusplus\n");
+ fprintf(fd, "} /* end of extern \"C\" */\n");
+ fprintf(fd, "#endif\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
+}
+
+int print_log_header(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".h", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ /* Print file head */
+ if(!fac->user)
+ print_log_header_head(fac, fd);
+ else
+ print_log_header_head_user(fac, fd);
+
+ /* print named types in declaration order */
+ if(print_log_header_types(fac, fd)) return 1;
+
+ /* Print events */
+ if(print_log_header_events(fac, fd)) return 1;
+
+ /* Print file tail */
+ if(!fac->user)
+ print_log_header_tail(fac, fd);
+ else
+ print_log_header_tail_user(fac, fd);
+
+
+
+ fclose(fd);
+
+ return 0;
+}
+
+
+/* ltt-facility-id-name.h : facility id.
+ * log_id_header */
+int print_id_header(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ char basename[PATH_MAX];
+ char basename_len = 0;
+
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-id-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".h", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ if(!fac->user) {
+ fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+ fprintf(fd, "#ifdef CONFIG_LTT\n");
+
+ fprintf(fd,"#include <linux/ltt-facilities.h>\n\n");
+
+ fprintf(fd,"/**** facility handle ****/\n\n");
+ fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
+ fac->name, fac->checksum);
+ fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
+
+ strncpy(basename, fac->name, PATH_MAX);
+ basename_len = strlen(basename);
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len++;
+
+ fprintf(fd,"/**** event index ****/\n\n");
+ fprintf(fd,"enum %s_event {\n",fac->name);
+
+ for(unsigned int i = 0; i < fac->events.position; i++) {
+ event_t *event = (event_t*)fac->events.array[i];
+ strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
+ print_tabs(1, fd);
+ fprintf(fd, "event_%s,\n", basename);
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "facility_%s_num_events\n", fac->name);
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+
+
+ fprintf(fd, "#endif //CONFIG_LTT\n");
+ fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
+ } else {
+ fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+ fprintf(fd, "#ifdef LTT_TRACE\n");
+
+ fprintf(fd,"#include <ltt/ltt-usertrace.h>\n\n");
+
+ fprintf(fd,"/**** facility handle ****/\n\n");
+ fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
+ fac->name, fac->checksum);
+ fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
+
+ strncpy(basename, fac->name, PATH_MAX);
+ basename_len = strlen(basename);
+ strncat(basename, "_", PATH_MAX - basename_len);
+ basename_len++;
+
+ fprintf(fd,"/**** event index ****/\n\n");
+ fprintf(fd,"enum %s_event {\n",fac->name);
+
+ for(unsigned int i = 0; i < fac->events.position; i++) {
+ event_t *event = (event_t*)fac->events.array[i];
+ strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
+ print_tabs(1, fd);
+ fprintf(fd, "event_%s,\n", basename);
+ }
+ print_tabs(1, fd);
+ fprintf(fd, "facility_%s_num_events\n", fac->name);
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+
+
+ fprintf(fd, "#endif //LTT_TRACE\n");
+ fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
+ }
+
+
+ fclose(fd);
+
+ return 0;
+}
+
+
+/* ltt-facility-loader-name.h : facility specific loader info.
+ * loader_header */
+int print_loader_header(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-loader-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".h", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
+ fprintf(fd, "#ifdef CONFIG_LTT\n\n");
+ fprintf(fd,"#include <linux/ltt-facilities.h>\n");
+ if(!fac->arch)
+ fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n",
+ fac->name);
+ else
+ fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
+ fac->name,
+ fac->arch);
+ fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
+ fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
+ fac->name, fac->checksum);
+ fprintf(fd,"extern unsigned int ltt_get_channel_index_%s(u8 eID);\n\n",
+ fac->name);
+
+ fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\tltt_facility_%s\n",
+ fac->name);
+ fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\tltt_facility_%s_%X\n",
+ fac->name, fac->checksum);
+ fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t0x%X\n", fac->checksum);
+ fprintf(fd,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac->name);
+ fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n",
+ fac->name);
+ fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t%u\n\n",
+ fac->align);
+ fprintf(fd,"#define LTT_FACILITY_SELECT\t\tltt_get_channel_index_%s\n\n",
+ fac->name);
+ fprintf(fd, "#endif //CONFIG_LTT\n\n");
+ fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+
+ fclose(fd);
+
+ return 0;
+}
+
+int print_loader_header_user(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-loader-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".h", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+ fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
+ fprintf(fd,"#include <ltt/ltt-usertrace.h>\n");
+ if(!fac->arch)
+ fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n",
+ fac->name);
+ else
+ fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
+ fac->name,
+ fac->arch);
+ fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
+ fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
+ fac->name, fac->checksum);
+
+ fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
+ fac->name);
+ fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
+ fac->name, fac->checksum);
+ fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum);
+ fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name);
+ fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
+ fac->name);
+ fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t\t\t\t%u\n\n",
+ fac->align);
+ fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+
+ fclose(fd);
+
+ return 0;
+}
+
+
+
+/* ltt-facility-loader-name.c : generic facility loader
+ * loader_c */
+int print_loader_c(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-loader-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".c", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ fprintf(fd, "/*\n");
+ if(!fac->arch)
+ fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
+ else
+ fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
+ fprintf(fd, " *\n");
+ fprintf(fd, " * (C) Copyright 2005 - \n");
+ fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
+ fprintf(fd, " *\n");
+ fprintf(fd, " * Contains the LTT facility loader.\n");
+ fprintf(fd, " *\n");
+ fprintf(fd, " */\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#include <linux/ltt-facilities.h>\n");
+ fprintf(fd, "#include <linux/module.h>\n");
+ fprintf(fd, "#include <linux/init.h>\n");
+ if(!fac->arch)
+ fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
+ else
+ fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
+ fac->name, fac->arch);
+ fprintf(fd, "\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#ifdef CONFIG_LTT\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
+ fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#define SYMBOL_STRING(sym) #sym\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "static struct ltt_facility facility = {\n");
+ fprintf(fd, "\t.name = ltt_facility_name,\n");
+ fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
+ fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
+ fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
+ fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT,\n");
+ fprintf(fd, "\t.select = LTT_FACILITY_SELECT,\n");
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "static int __init facility_init(void)\n");
+ fprintf(fd, "{\n");
+ fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac->name);
+ fprintf(fd, "\n");
+ fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
+ fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+ fprintf(fd, "\t\n");
+ fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n");
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#ifndef MODULE\n");
+ fprintf(fd, "__initcall(facility_init);\n");
+ fprintf(fd, "#else\n");
+ fprintf(fd, "module_init(facility_init);\n");
+ fprintf(fd, "static void __exit facility_exit(void)\n");
+ fprintf(fd, "{\n");
+ fprintf(fd, "\tint err;\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
+ fprintf(fd, "\tif (err != 0)\n");
+ fprintf(fd, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "}\n");
+ fprintf(fd, "module_exit(facility_exit)\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "MODULE_LICENSE(\"GPL\");\n");
+ fprintf(fd, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
+ fprintf(fd, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#endif //MODULE\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#endif //CONFIG_LTT\n");
+
+ fclose(fd);
+
+ return 0;
+}
+
+int print_loader_c_user(facility_t *fac)
+{
+ char filename[PATH_MAX];
+ unsigned int filename_size = 0;
+ FILE *fd;
+ dprintf("%s\n", fac->name);
+
+ strcpy(filename, "ltt-facility-loader-");
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->name, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ if(fac->arch) {
+ strncat(filename, "_", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+ strncat(filename, fac->arch, PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+ }
+
+ strncat(filename, ".c", PATH_MAX - filename_size);
+ filename_size = strlen(filename);
+
+
+ fd = fopen(filename, "w");
+ if(fd == NULL) {
+ printf("Error opening file %s for writing : %s\n",
+ filename, strerror(errno));
+ return errno;
+ }
+
+ fprintf(fd, "/*\n");
+ if(!fac->arch)
+ fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
+ else
+ fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
+ fprintf(fd, " *\n");
+ fprintf(fd, " * (C) Copyright 2005 - \n");
+ fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
+ fprintf(fd, " *\n");
+ fprintf(fd, " * Contains the LTT user space facility loader.\n");
+ fprintf(fd, " *\n");
+ fprintf(fd, " */\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "#define LTT_TRACE\n");
+ fprintf(fd, "#include <error.h>\n");
+ fprintf(fd, "#include <stdio.h>\n");
+ fprintf(fd, "#include <ltt/ltt-usertrace.h>\n");
+ if(!fac->arch)
+ fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
+ else
+ fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
+ fac->name, fac->arch);
+ fprintf(fd, "\n");
+ fprintf(fd, "static struct user_facility_info facility = {\n");
+ fprintf(fd, "\t.name = LTT_FACILITY_NAME,\n");
+ fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
+ fprintf(fd, "#ifndef LTT_PACK\n");
+ fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,\n");
+ fprintf(fd, "#else\n");
+ fprintf(fd, "\t.alignment = 0,\n");
+ fprintf(fd, "#endif //LTT_PACK\n");
+ fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
+ fprintf(fd, "\t.int_size = sizeof(int),\n");
+ fprintf(fd, "\t.long_size = sizeof(long),\n");
+ fprintf(fd, "\t.pointer_size = sizeof(void*),\n");
+ fprintf(fd, "\t.size_t_size = sizeof(size_t)\n");
+ fprintf(fd, "};\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
+ fprintf(fd, "{\n");
+ fprintf(fd, "\tint err;\n");
+ fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
+ fprintf(fd, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac->name);
+ fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n");
+ fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+ fprintf(fd, "\t\n");
+ fprintf(fd, "\tif (err) {\n");
+ fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
+ fprintf(fd, "\t\tperror(\"Error in ltt_register_generic\");\n");
+ fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
+ fprintf(fd, "\t}\n");
+ fprintf(fd, "}\n");
+ fprintf(fd, "\n");
+
+ fclose(fd);
+
+ return 0;
+}
+
+
+
+/* open facility */
+/* code taken from ltt_facility_open in ltt/facility.c in lttv */
+
+/*****************************************************************************
+ *Function name
+ * ltt_facility_open : open facilities
+ *Input params
+ * pathname : the path name of the facility
+ *
+ * Open the facility corresponding to the right checksum.
+ *
+ *returns the facility on success, NULL on error.
+ ****************************************************************************/
+facility_t *ltt_facility_open(char * pathname)
+{
+ int ret = 0;
+ char *token;
+ parse_file_t in;
+ facility_t * fac = NULL;
+ char buffer[BUFFER_SIZE];
+ int generated = FALSE;
+
+ in.buffer = &(buffer[0]);
+ in.lineno = 0;
+ in.error = error_callback;
+ in.name = pathname;
+ in.unget = 0;
+
+ in.fp = fopen(in.name, "r");
+ if(in.fp == NULL) {
+ ret = 1;
+ goto open_error;
+ }
+
+ while(1){
+ token = getToken(&in);
+ if(in.type == ENDFILE) break;
+
+ if(generated) {
+ printf("More than one facility in the file. Only using the first one.\n");
+ break;
+ }
+
+ if(strcmp(token, "<")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp(token, "?")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp(token, "xml")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp(token, "version")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp(token, "=")) in.error(&in,"not a facility file");
+ token = getQuotedString(&in);
+ if(strcmp(token, "1.0")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp(token, "?")) in.error(&in,"not a facility file");
+ token = getToken(&in);
+ if(strcmp(token, ">")) in.error(&in,"not a facility file");
+
+ token = getName(&in);
+ if(strcmp(token, "<")) in.error(&in,"not a facility file");
+ token = getName(&in);
+ if(strcmp("facility",token) == 0) {
+ fac = malloc(sizeof(facility_t));
+ fac->name = NULL;
+ fac->description = NULL;
+ sequence_init(&(fac->events));
+ table_init(&(fac->named_types));
+ sequence_init(&(fac->unnamed_types));
+
+ parseFacility(&in, fac);
+
+ //check if any namedType is not defined
+ checkNamedTypesImplemented(&fac->named_types);
+
+ generateChecksum(fac->name, &fac->checksum, &fac->events);
+
+ generated = TRUE;
+ }
+ else {
+ printf("facility token was expected in file %s\n", in.name);
+ ret = 1;
+ goto parse_error;
+ }
+ }
+
+ parse_error:
+ fclose(in.fp);
+open_error:
+
+ if(!generated) {
+ printf("Cannot find facility %s\n", pathname);
+ fac = NULL;
+ }
+
+ return fac;
+}
+
+/* Close the facility */
+void ltt_facility_close(facility_t *fac)
+{
+ free(fac->name);
+ free(fac->capname);
+ free(fac->description);
+ freeEvents(&fac->events);
+ sequence_dispose(&fac->events);
+ freeNamedType(&fac->named_types);
+ table_dispose(&fac->named_types);
+ freeTypes(&fac->unnamed_types);
+ sequence_dispose(&fac->unnamed_types);
+ free(fac);
+}
+
+
+/* Show help */
+void show_help(int argc, char ** argv)
+{
+ printf("Genevent help : \n");
+ printf("\n");
+ printf("Use %s name.xml\n", argv[0]);
+ printf("to create :\n");
+ printf("ltt-facility-name.h\n");
+ printf("ltt-facility-id-name.h\n");
+ printf("ltt-facility-loader-name.h\n");
+ printf("ltt-facility-loader-name.c\n");
+ printf("In the current directory.\n");
+ printf("\n");
+}
+
+/* Parse program arguments */
+/* Return values :
+ * 0 : continue program
+ * -1 : stop program, return 0
+ * > 0 : stop program, return value as exit.
+ */
+int check_args(int argc, char **argv)
+{
+ if(argc < 2) {
+ printf("Not enough arguments\n");
+ show_help(argc, argv);
+ return EINVAL;
+ }
+
+ if(strcmp(argv[1], "-h") == 0) {
+ show_help(argc, argv);
+ return -1;
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int err = 0;
+ facility_t *fac;
+
+ err = check_args(argc, argv);
+ if(err > 0) return err;
+ else if(err < 0) return 0;
+
+ /* open the facility */
+ fac = ltt_facility_open(argv[1]);
+ if(fac == NULL) {
+ printf("Error opening file %s for reading : %s\n",
+ argv[1], strerror(errno));
+ return errno;
+ }
+
+ /* generate the output C files */
+
+
+ /* ltt-facility-name.h : main logging header.
+ * log_header */
+ err = print_log_header(fac);
+ if(err) return err;
+
+ /* ltt-facility-id-name.h : facility id.
+ * log_id_header */
+ err = print_id_header(fac);
+ if(err) return err;
+
+ /* ltt-facility-loader-name.h : facility specific loader info.
+ * loader_header */
+ if(!fac->user)
+ err = print_loader_header(fac);
+ else
+ err = print_loader_header_user(fac);
+ if(err) return err;
+
+ /* ltt-facility-loader-name.c : generic faciilty loader
+ * loader_c */
+ if(!fac->user)
+ err = print_loader_c(fac);
+ else
+ err = print_loader_c_user(fac);
+ if(err) return err;
+
+ /* close the facility */
+ ltt_facility_close(fac);
+
+ return 0;
+}
+
+
--- /dev/null
+/******************************************************************************
+ * Genevent
+ *
+ * Event generator. XML to logging C code converter.
+ *
+ * Supports :
+ * - C Alignment
+ * - C types : struct, union, enum, basic types.
+ * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
+ *
+ * Additionnal structures supported :
+ * - embedded variable size strings
+ * - embedded variable size arrays
+ * - embedded variable size sequences
+ *
+ * Notes :
+ * (1)
+ * enums are limited to integer type, as this is what is used in C. Note,
+ * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
+ * unsigned int or int. This is implementation defined (compiler). That's why we
+ * add a check for sizeof enum.
+ *
+ * (2)
+ * Because of archtecture defined type sizes, we need to ask for ltt_align
+ * (which gives the alignment) by passing basic types, not their actual sizes.
+ * It's up to ltt_align to determine sizes of types.
+ *
+ * Note that, from
+ * http://www.usenix.org/publications/login/standards/10.data.html
+ * (Andrew Josey <a.josey@opengroup.org>) :
+ *
+ * Data Type LP32 ILP32 ILP64 LLP64 LP64
+ * char 8 8 8 8 8
+ * short 16 16 16 16 16
+ * int32 32
+ * int 16 32 64 32 32
+ * long 32 32 64 32 64
+ * long long (int64) 64
+ * pointer 32 32 64 64 64
+ *
+ * With these constraints :
+ * sizeof(char) <= sizeof(short) <= sizeof(int)
+ * <= sizeof(long) = sizeof(size_t)
+ *
+ * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
+ *
+ * Which means we only have to remember which is the biggest type in a structure
+ * to know the structure's alignment.
+ */
+
+
+
+/* Code printing */
+
+/* Type size checking */
+int print_check(int fd);
+
+
+/* Print types */
+int print_types(int fd);
+
+/* Print events */
+int print_events(int fd);
+
+
+
--- /dev/null
+
+#define __KERNEL__
+
+#include <assert.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <linux/compiler.h>
+
+#define min(a,b) (((a)<(b))?a:b)
+#define max(a,b) (((a)>(b))?a:b)
+#define BUG_ON(a) assert(!(a))
+
+// Useful outside __KERNEL__. Not used here because inline is already redefined.
+#define force_inline inline __attribute__((always_inline))
+
+/* Calculate the offset needed to align the type */
+static inline unsigned int ltt_align(size_t align_drift,
+ size_t size_of_type)
+{
+ size_t alignment = min(sizeof(void*), size_of_type);
+
+ return ((alignment - align_drift) & (alignment-1));
+}
+
+
+/* TEMPLATE */
+
+enum lttng_tasklet_priority {
+ LTTNG_LOW,
+ LTTNG_HIGH,
+};
+
+enum lttng_irq_mode {
+ LTTNG_user,
+ LTTNG_kernel,
+};
+
+struct lttng_mystruct2 {
+ unsigned int irq_id;
+ enum lttng_irq_mode mode;
+ //struct lttng_mystruct teststr1;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct2(
+ struct lttng_mystruct2 * obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(enum lttng_irq_mode);
+ size += ltt_align(size, locsize) + locsize;
+
+ BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+ return sizeof(struct lttng_mystruct2);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct2(
+ struct lttng_mystruct2 *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(enum lttng_irq_mode);
+ align = max(align, localign);
+
+ return align;
+}
+
+static inline void lttng_write_mystruct2(
+ void *buffer,
+ size_t *to_base,
+ size_t *to,
+ void **from,
+ size_t *len,
+ struct lttng_mystruct2 *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct2(obj);
+ //size = lttng_get_size_mystruct2(obj);
+ size = sizeof(struct lttng_mystruct2);
+
+ if(*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+}
+
+
+
+#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
+typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+
+#if 0
+static inline size_t lttng_get_size_array_mystruct_myarray(
+ lttng_array_mystruct_myarray obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(uint64_t);
+ /* ltt_align == 0 always*/
+ //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+ BUG_ON(ltt_align(size, locsize) != 0);
+ size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+ BUG_ON(sizeof(lttng_array_mystruct_myarray) != size);
+
+ return sizeof(lttng_array_mystruct_myarray);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_array_mystruct_myarray(
+ lttng_array_mystruct_myarray obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(uint64_t);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+static inline void lttng_write_array_mystruct_myarray(
+ void *buffer,
+ size_t *to_base,
+ size_t *to,
+ void **from,
+ size_t *len,
+ lttng_array_mystruct_myarray obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_array_mystruct_myarray(obj);
+ //size = lttng_get_size_array_mystruct_myarray(obj);
+ size = sizeof(lttng_array_mystruct_myarray);
+
+ if(*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+#if 0
+ /* For varlen child : let the child align itself. */
+ for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_mystruct_myarray; i++) {
+ lttng_write_child(buffer, to_base, to, from, len, obj[i]);
+ }
+#endif //0
+
+}
+
+
+typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
+struct lttng_sequence_mystruct_mysequence {
+ unsigned int len;
+ double *array;
+};
+
+#if 0
+static inline size_t lttng_get_size_sequence_mystruct_mysequence(
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(double);
+ size += ltt_align(size, locsize) + (obj->len * locsize);
+
+ /* Realign on arch size */
+ locsize = sizeof(void *);
+ size += ltt_align(size, locsize);
+
+ return size;
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_sequence_mystruct_mysequence(
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(double);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+static inline void lttng_write_sequence_mystruct_mysequence(
+ void *buffer,
+ size_t *to_base,
+ size_t *to,
+ void **from,
+ size_t *len,
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t align;
+ size_t size;
+
+ /* Flush pending memcpy */
+ if(*len != 0) {
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
+ }
+ *to += *len;
+ *len = 0;
+
+ align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+ //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+ /* Align output */
+ *to += ltt_align(*to, align); /* *len = 0 in this function */
+
+ /* Copy members */
+ size = sizeof(unsigned int);
+ *to += ltt_align(*to, size);
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, &obj->len, size);
+ *to += size;
+
+ size = sizeof(double);
+ *to += ltt_align(*to, size);
+ size = obj->len * sizeof(double);
+ if(buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj->array, size);
+ *to += size;
+#if 0
+ /* If varlen child : let child align itself */
+ for(unsigned int i=0; i<obj->len; i++) {
+ lttng_write_child(buffer, to_base, to, from, len, obj->array[i]);
+ }
+#endif //0
+
+
+ /* Realign the *to_base on arch size, set *to to 0 */
+ *to = ltt_align(*to, sizeof(void *));
+ *to_base = *to_base+*to;
+ *to = 0;
+
+ /* Put source *from just after the C sequence */
+ *from = obj+1;
+}
+
+
+
+union lttng_mystruct_myunion {
+ double myfloat;
+ unsigned long myulong;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct_myunion(
+ union lttng_mystruct_myunion *obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(double);
+ size = max(size, locsize);
+
+ locsize = sizeof(unsigned long);
+ size = max(size, locsize);
+
+ BUG_ON(size != sizeof(union lttng_mystruct_myunion));
+
+ return sizeof(union lttng_mystruct_myunion);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct_myunion(
+ union lttng_mystruct_myunion *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(double);
+ align = max(align, localign);
+
+ localign = sizeof(unsigned long);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+static inline void lttng_write_mystruct_myunion(
+ void *buffer,
+ size_t *to_base,
+ size_t *to,
+ void **from,
+ size_t *len,
+ union lttng_mystruct_myunion *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct_myunion(obj);
+ //size = lttng_get_size_mystruct_myunion(obj);
+ size = sizeof(union lttng_mystruct_myunion);
+
+ if(*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+
+ /* Assert : no varlen child. */
+}
+
+
+struct lttng_mystruct {
+ unsigned int irq_id;
+ enum lttng_irq_mode mode;
+ struct lttng_mystruct2 teststr;
+ lttng_array_mystruct_myarray myarray;
+ lttng_sequence_mystruct_mysequence mysequence;
+ union lttng_mystruct_myunion myunion;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct(
+ struct lttng_mystruct *obj)
+{
+ size_t size=0, locsize, localign;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(enum lttng_irq_mode);
+ size += ltt_align(size, locsize) + locsize;
+
+ localign = lttng_get_alignment_mystruct2(&obj->teststr);
+ locsize = lttng_get_size_mystruct2(&obj->teststr);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+ locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+ locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+ locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
+ size += ltt_align(size, localign) + locsize;
+
+ return size;
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct(
+ struct lttng_mystruct *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(enum lttng_irq_mode);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_mystruct2(&obj->teststr);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+ align = max(align, localign);
+
+ return align;
+}
+
+static inline void lttng_write_mystruct(
+ void *buffer,
+ size_t *to_base,
+ size_t *to,
+ void **from,
+ size_t *len,
+ struct lttng_mystruct *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct(obj);
+ // no need : contains variable size fields.
+ // locsize = lttng_get_size_mystruct(obj);
+
+ if(*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = sizeof(unsigned int);
+ size += ltt_align(*to+*len, size) + size;
+ *len += size;
+
+ size = sizeof(enum lttng_irq_mode);
+ size += ltt_align(*to+*len, size) + size;
+ *len += size;
+
+ lttng_write_mystruct2(buffer, to_base, to, from, len, &obj->teststr);
+
+ lttng_write_array_mystruct_myarray(buffer, to_base, to, from, len, obj->myarray);
+
+ /* Variable length field */
+ lttng_write_sequence_mystruct_mysequence(buffer, to_base, to, from, len, &obj->mysequence);
+ /* After this previous write, we are sure that *to is 0, *len is 0 and
+ * *to_base is aligned on the architecture size : to rest of alignment will
+ * be calculated statically. */
+
+ lttng_write_mystruct_myunion(buffer, to_base, to, from, len, &obj->myunion);
+
+ /* Don't forget to flush last write..... */
+}
+
+
+
+
+
+
+//void main()
+void test()
+{
+ struct lttng_mystruct test;
+ test.mysequence.len = 20;
+ test.mysequence.array = malloc(20);
+
+ //size_t size = lttng_get_size_mystruct(&test);
+ //size_t align = lttng_get_alignment_mystruct(&test);
+ //
+ size_t to_base = 0; /* the buffer is allocated on arch_size alignment */
+ size_t to = 0;
+ void *from = &test;
+ size_t len = 0;
+
+ /* Get size */
+ lttng_write_mystruct(NULL, &to_base, &to, &from, &len, &test);
+ /* Size = to_base + to + len */
+
+ void *buffer = malloc(to_base + to + len);
+ to_base = 0; /* the buffer is allocated on arch_size alignment */
+ to = 0;
+ from = &test;
+ len = 0;
+
+ lttng_write_mystruct(buffer, &to_base, &to, &from, &len, &test);
+ /* Final flush */
+ /* Flush pending memcpy */
+ if(len != 0) {
+ // Assert buffer != NULL */
+ memcpy(buffer+to_base+to, from, len);
+ to += len;
+ from += len;
+ len = 0;
+ }
+
+ free(test.mysequence.array);
+ free(buffer);
+}
--- /dev/null
+#ifndef _LTT_FACILITY_TEST_H_
+#define _LTT_FACILITY_TEST_H_
+
+
+/* Facility activation at compile time. */
+#ifdef CONFIG_LTT_FACILITY_TEST
+
+/* Named types */
+
+
+enum lttng_tasklet_priority {
+ LTTNG_LOW,
+ LTTNG_HIGH,
+};
+
+enum lttng_irq_mode {
+ LTTNG_user,
+ LTTNG_kernel,
+};
+
+struct lttng_mystruct2 {
+ unsigned int irq_id;
+ enum lttng_irq_mode mode;
+ //struct lttng_mystruct teststr1;
+};
+
+
+size_t lttng_get_size_mystruct2(
+ struct lttng_mystruct2 *obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(enum lttng_irq_mode);
+ size += ltt_align(size, locsize) + locsize;
+
+ BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+ return sizeof(struct lttng_mystruct2);
+}
+
+size_t lttng_get_alignment_mystruct2(
+ struct lttng_mystruct2 *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(enum lttng_irq_mode);
+ align = max(align, localign);
+
+ return align;
+}
+
+void lttng_write_mystruct2(void **to,
+ void **from,
+ size_t *len,
+ struct lttng_mystruct2 *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct2(obj);
+ size = lttng_get_size_mystruct2(obj);
+
+ if(*len == 0) {
+ *to += ltt_align((size_t)(*to), align); /* align output */
+ } else {
+ *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+}
+
+
+
+#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
+typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+
+size_t lttng_get_size_array_mystruct_myarray(
+ lttng_array_mystruct_myarray obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(uint64_t);
+ /* ltt_align == 0 always*/
+ //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+ BUG_ON(ltt_align(size, locsize) != 0);
+ size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+ BUG_ON(size != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
+
+ return size;
+}
+
+size_t lttng_get_alignment_array_mystruct_myarray(
+ lttng_array_mystruct_myarray obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(uint64_t);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+void lttng_write_array_mystruct_myarray(void **to,
+ void **from,
+ size_t *len,
+ lttng_array_mystruct_myarray obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_array_mystruct_myarray(obj);
+ size = lttng_get_size_array_mystruct_myarray(obj);
+
+ if(*len == 0) {
+ *to += ltt_align((size_t)(*to), align); /* align output */
+ } else {
+ *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+}
+
+
+typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
+struct lttng_sequence_mystruct_mysequence {
+ unsigned int len;
+ double *array;
+};
+
+
+size_t lttng_get_size_sequence_mystruct_mysequence(
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(double);
+ size += ltt_align(size, locsize) + (obj->len * locsize);
+
+ return size;
+}
+
+size_t lttng_get_alignment_sequence_mystruct_mysequence(
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(double);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+void lttng_write_sequence_mystruct_mysequence(void **to,
+ void **from,
+ size_t *len,
+ lttng_sequence_mystruct_mysequence *obj)
+{
+ size_t align, size;
+ void *varfrom;
+ size_t varlen=0;
+
+ /* Flush pending memcpy */
+ if(*len != 0) {
+ memcpy(*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+ //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+ /* Align output */
+ *to += ltt_align((size_t)(*to), align);
+
+ /* Copy members */
+ *to += ltt_align((size_t)*to, sizeof(unsigned int));
+ varfrom = &obj->len;
+ varlen += sizeof(unsigned int);
+ memcpy(*to, varfrom, varlen);
+ *to += varlen;
+ varlen = 0;
+
+ *to += ltt_align((size_t)*to, sizeof(double));
+ varfrom = obj->array;
+ varlen += obj->len * sizeof(double);
+ memcpy(*to, varfrom, varlen);
+ *to += varlen;
+ varlen = 0;
+
+ /* Put source *from just after the C sequence */
+ *from = obj+1;
+}
+
+
+
+union lttng_mystruct_myunion {
+ double myfloat;
+ unsigned long myulong;
+};
+
+
+size_t lttng_get_size_mystruct_myunion(
+ union lttng_mystruct_myunion *obj)
+{
+ size_t size=0, locsize;
+
+ locsize = sizeof(double);
+ size = max(size, locsize);
+
+ locsize = sizeof(unsigned long);
+ size = max(size, locsize);
+
+ BUG_ON(size != sizeof(union lttng_mystruct_myunion));
+
+ return size;
+}
+
+
+size_t lttng_get_alignment_mystruct_myunion(
+ union lttng_mystruct_myunion *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(double);
+ align = max(align, localign);
+
+ localign = sizeof(unsigned long);
+ align = max(align, localign);
+
+ return align;
+}
+
+
+void lttng_write_mystruct_myunion(void **to,
+ void **from,
+ size_t *len,
+ union lttng_mystruct_myunion *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct_myunion(obj);
+ size = lttng_get_size_mystruct_myunion(obj);
+
+ if(*len == 0) {
+ *to += ltt_align((size_t)(*to), align); /* align output */
+ } else {
+ *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ *len += size;
+}
+
+
+struct lttng_mystruct {
+ unsigned int irq_id;
+ enum lttng_irq_mode mode;
+ struct lttng_mystruct2 teststr;
+ lttng_array_mystruct_myarray myarray;
+ lttng_sequence_mystruct_mysequence mysequence;
+ union lttng_mystruct_myunion myunion;
+};
+
+size_t lttng_get_size_mystruct(
+ struct lttng_mystruct *obj)
+{
+ size_t size=0, locsize, localign;
+
+ locsize = sizeof(unsigned int);
+ size += ltt_align(size, locsize) + locsize;
+
+ locsize = sizeof(enum lttng_irq_mode);
+ size += ltt_align(size, locsize) + locsize;
+
+ localign = lttng_get_alignment_mystruct2(&obj->teststr);
+ locsize = lttng_get_size_mystruct2(&obj->teststr);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+ locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+ locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
+ size += ltt_align(size, localign) + locsize;
+
+ localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+ locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
+ size += ltt_align(size, localign) + locsize;
+
+ return size;
+}
+
+
+size_t lttng_get_alignment_mystruct(
+ struct lttng_mystruct *obj)
+{
+ size_t align=0, localign;
+
+ localign = sizeof(unsigned int);
+ align = max(align, localign);
+
+ localign = sizeof(enum lttng_irq_mode);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_mystruct2(&obj->teststr);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+ align = max(align, localign);
+
+ localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+ align = max(align, localign);
+
+ return align;
+}
+
+void lttng_write_mystruct(void **to,
+ void **from,
+ size_t *len,
+ struct lttng_mystruct *obj)
+{
+ size_t align, size;
+
+ align = lttng_get_alignment_mystruct(obj);
+ // no need : contains variable size fields.
+ // locsize = lttng_get_size_mystruct(obj);
+
+ if(*len == 0) {
+ *to += ltt_align((size_t)(*to), align); /* align output */
+ } else {
+ *len += ltt_align((size_t)(*to+*len), align); /* C alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = sizeof(unsigned int);
+ *len += ltt_align((size_t)(*to+*len), size) + size;
+
+ size = sizeof(enum lttng_irq_mode);
+ *len += ltt_align((size_t)(*to+*len), size) + size;
+
+ lttng_write_mystruct2(to, from, len, &obj->teststr);
+
+ lttng_write_array_mystruct_myarray(to, from, len, obj->myarray);
+
+ /* Variable length field */
+ lttng_write_sequence_mystruct_mysequence(to, from, len, &obj->mysequence);
+
+ lttng_write_mystruct_myunion(to, from, len, &obj->myunion);
+
+ /* Don't forget to flush last write..... */
+}
+
+
+
+
+/* Event syscall_entry structures */
+
+/* Event syscall_entry logging function */
+static inline void trace_test_syscall_entry(
+ unsigned int syscall_id,
+ void * address)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event syscall_exit structures */
+
+/* Event syscall_exit logging function */
+static inline void trace_test_syscall_exit(
+ void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event trap_entry structures */
+
+/* Event trap_entry logging function */
+static inline void trace_test_trap_entry(
+ unsigned int trap_id,
+ void * address)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event trap_exit structures */
+
+/* Event trap_exit logging function */
+static inline void trace_test_trap_exit(
+ void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event soft_irq_entry structures */
+
+/* Event soft_irq_entry logging function */
+static inline void trace_test_soft_irq_entry(
+ void * softirq_id)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event soft_irq_exit structures */
+
+/* Event soft_irq_exit logging function */
+static inline void trace_test_soft_irq_exit(
+ void * softirq_id)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event tasklet_entry structures */
+
+/* Event tasklet_entry logging function */
+static inline void trace_test_tasklet_entry(
+ enum lttng_tasklet_priority priority,
+ void * address,
+ unsigned long data)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event tasklet_exit structures */
+
+/* Event tasklet_exit logging function */
+static inline void trace_test_tasklet_exit(
+ enum lttng_tasklet_priority priority,
+ void * address,
+ unsigned long data)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event irq_entry structures */
+
+/* Event irq_entry logging function */
+static inline void trace_test_irq_entry(
+ unsigned int irq_id,
+ enum lttng_irq_mode mode)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event irq_exit structures */
+
+/* Event irq_exit logging function */
+static inline void trace_test_irq_exit(
+ void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event big_array structures */
+union lttng_test_big_array_myarray_b {
+ void * c;
+};
+
+struct lttng_test_big_array_myarray {
+ void * a;
+ union lttng_test_big_array_myarray_b b;
+};
+
+#define LTTNG_ARRAY_SIZE_test_big_array_myarray 2
+typedef struct lttng_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
+
+#define LTTNG_ARRAY_SIZE_test_big_array_myarray 10000
+typedef lttng_array_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
+
+
+/* Event big_array logging function */
+static inline void trace_test_big_array(
+ lttng_array_test_big_array_myarray myarray)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+#endif //CONFIG_LTT_FACILITY_TEST
+
+#endif //_LTT_FACILITY_TEST_H_
--- /dev/null
+
+
+
+/*
+
+parser.c: Generate helper declarations and functions to trace events
+ from an event description file.
+
+ Copyright (C) 2005, Mathieu Desnoyers
+ Copyright (C) 2002, Xianxiu Yang
+ Copyright (C) 2002, Michel Dagenais
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/* This program reads the ".xml" event definitions input files
+ and constructs structure for each event.
+
+ The program uses a very simple tokenizer, called from a hand written
+ recursive descent parser to fill a data structure describing the events.
+ The result is a sequence of events definitions which refer to type
+ definitions.
+
+ A table of named types is maintained to allow refering to types by name
+ when the same type is used at several places. Finally a sequence of
+ all types is maintained to facilitate the freeing of all type
+ information when the processing of an ".xml" file is finished. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <linux/errno.h>
+#include <assert.h>
+#include <ctype.h>
+
+#include "parser.h"
+
+
+char *intOutputTypes[] = {
+ "int8_t", "int16_t", "int32_t", "int64_t" };
+
+char *uintOutputTypes[] = {
+ "uint8_t", "uint16_t", "uint32_t", "uint64_t" };
+
+char *floatOutputTypes[] = {
+ "undef", "undef", "float", "double" };
+
+
+
+
+/* helper function */
+void strupper(char *string)
+{
+ char *ptr = string;
+
+ while(*ptr != '\0') {
+ *ptr = toupper(*ptr);
+ ptr++;
+ }
+}
+
+
+int getSizeindex(unsigned int value)
+{
+ switch(value) {
+ case 1:
+ return 0;
+ case 2:
+ return 1;
+ case 4:
+ return 2;
+ case 8:
+ return 3;
+ default:
+ printf("Error : unknown value size %d\n", value);
+ exit(-1);
+ }
+}
+
+/*****************************************************************************
+ *Function name
+ * getSize : translate from string to integer
+ *Input params
+ * in : input file handle
+ *Return values
+ * size
+ *****************************************************************************/
+
+unsigned long long int getSize(parse_file_t *in)
+{
+ char *token, *token2;
+ unsigned long long int ret;
+
+ token = getToken(in);
+
+
+ if(in->type == QUOTEDSTRING) {
+ in->type = NUMBER;
+ token2 = token;
+ do {
+ if (!isdigit(*token2)) {
+ in->type = QUOTEDSTRING;
+ break;
+ }
+ } while (*(++token2) != '\0');
+ }
+
+ if(in->type == NUMBER) {
+ ret = strtoull(token, NULL, 0);
+ } else {
+ goto error;
+ }
+
+ return ret;
+error:
+ in->error(in,"incorrect size specification");
+ return -1;
+}
+
+/*****************************************************************************
+ *Function name
+ * error_callback : print out error info
+ *Input params
+ * in : input file handle
+ * msg : message to be printed
+ ****************************************************************************/
+
+void error_callback(parse_file_t *in, char *msg)
+{
+ if(in)
+ printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
+ else
+ printf("%s\n",msg);
+ assert(0);
+ exit(1);
+}
+
+/*****************************************************************************
+ *Function name
+ * memAlloc : allocate memory
+ *Input params
+ * size : required memory size
+ *return value
+ * void * : pointer to allocate memory or NULL
+ ****************************************************************************/
+
+void * memAlloc(int size)
+{
+ void * addr;
+ if(size == 0) return NULL;
+ addr = malloc(size);
+ if(!addr){
+ printf("Failed to allocate memory");
+ exit(1);
+ }
+ return addr;
+}
+
+/*****************************************************************************
+ *Function name
+ * allocAndCopy : allocate memory and initialize it
+ *Input params
+ * str : string to be put in memory
+ *return value
+ * char * : pointer to allocate memory or NULL
+ ****************************************************************************/
+
+char *allocAndCopy(char *str)
+{
+ char * addr;
+ if(str == NULL) return NULL;
+ addr = (char *)memAlloc(strlen(str)+1);
+ strcpy(addr,str);
+ return addr;
+}
+
+/**************************************************************************
+ * Function :
+ * getTypeAttributes
+ * Description :
+ * Read the attribute from the input file.
+ *
+ * Parameters :
+ * in , input file handle.
+ * t , the type descriptor to fill.
+ *
+ **************************************************************************/
+
+void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
+ sequence_t * unnamed_types, table_t * named_types)
+{
+ char * token;
+ int car;
+
+ t->fmt = NULL;
+ t->size = 0;
+ t->custom_write = 0;
+ t->network = 0;
+
+ while(1) {
+ token = getToken(in);
+ if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+ ungetToken(in);
+ break;
+ }
+
+ if(!strcmp("format",token)) {
+ getEqual(in);
+ t->fmt = allocAndCopy(getQuotedString(in));
+ // printf("%s - ",t->fmt);
+ //} else if(!strcmp("name",token)) {
+ // getEqual(in);
+ // car = seekNextChar(in);
+ // if(car == EOF) in->error(in,"name was expected");
+ // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in));
+ // else t->type_name = allocAndCopy(getName(in));
+ } else if(!strcmp("size",token)) {
+ getEqual(in);
+ t->size = getSize(in);
+ } else if(!strcmp("custom_write", token)) {
+ t->custom_write = 1;
+ } else if(!strcmp("byte_order",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"byte order was expected (network?)");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp("network", token)) {
+ t->network = 1;
+ }
+ } else if(!strcmp("write",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"write type was expected (custom?)");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp("custom", token)) {
+ t->custom_write = 1;
+ }
+ }
+ }
+}
+
+/**************************************************************************
+ * Function :
+ * getEventAttributes
+ * Description :
+ * Read the attribute from the input file.
+ *
+ * Parameters :
+ * in , input file handle.
+ * ev , the event to fill.
+ *
+ **************************************************************************/
+
+void getEventAttributes(parse_file_t *in, event_t *ev)
+{
+ char * token;
+ int car;
+
+ ev->name = NULL;
+ ev->per_trace = 0;
+ ev->per_tracefile = 0;
+ ev->param_buffer = 0;
+ ev->no_instrument_function = 0;
+ ev->high_priority = 0;
+ ev->force = 0;
+ ev->compact_data = 0;
+
+ while(1) {
+ token = getToken(in);
+ if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+ ungetToken(in);
+ break;
+ }
+
+ if(!strcmp("name",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"name was expected");
+ else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in));
+ else ev->name = allocAndCopy(getName(in));
+ } else if(!strcmp("scope", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"scope was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "trace")) ev->per_trace = 1;
+ else if(!strcmp(token, "tracefile")) ev->per_tracefile = 1;
+ } else if(!strcmp("param", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"parameter type was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "buffer")) ev->param_buffer = 1;
+ } else if(!strcmp("attribute", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"attribute was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "no_instrument_function"))
+ ev->no_instrument_function = 1;
+ else if(!strcmp(token, "high_priority"))
+ ev->high_priority = 1;
+ else if(!strcmp(token, "force"))
+ ev->force = 1;
+ else if(!strcmp(token, "compact_data"))
+ ev->compact_data = 1;
+ }
+ }
+}
+
+/**************************************************************************
+ * Function :
+ * getFacilityAttributes
+ * Description :
+ * Read the attribute from the input file.
+ *
+ * Parameters :
+ * in , input file handle.
+ * fac , the facility to fill.
+ *
+ **************************************************************************/
+
+void getFacilityAttributes(parse_file_t *in, facility_t *fac)
+{
+ char * token;
+ int car;
+
+ fac->name = NULL;
+ fac->arch = NULL;
+ fac->align = 1;
+ fac->user = 0;
+
+ while(1) {
+ token = getToken(in);
+ if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+ ungetToken(in);
+ break;
+ }
+
+ if(!strcmp("name",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"name was expected");
+ else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
+ else fac->name = allocAndCopy(getName(in));
+ if(!strncmp(fac->name, "user_", sizeof("user_")-1))
+ fac->user = 1;
+ } else if(!strcmp("arch", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in));
+ else fac->arch = allocAndCopy(getName(in));
+ } else if(!strcmp("align", token)) {
+ getEqual(in);
+ fac->align = getSize(in);
+ }
+
+ }
+}
+
+/**************************************************************************
+ * Function :
+ * getFieldAttributes
+ * Description :
+ * Read the attribute from the input file.
+ *
+ * Parameters :
+ * in , input file handle.
+ * f , the field to fill.
+ *
+ **************************************************************************/
+
+void getFieldAttributes(parse_file_t *in, field_t *f)
+{
+ char * token;
+ int car;
+
+ f->name = NULL;
+
+ while(1) {
+ token = getToken(in);
+ if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+ ungetToken(in);
+ break;
+ }
+
+ if(!strcmp("name",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"name was expected");
+ else if(car == '\"') f->name = allocAndCopy(getQuotedString(in));
+ else f->name = allocAndCopy(getName(in));
+ }
+ }
+}
+
+char *getNameAttribute(parse_file_t *in)
+{
+ char * token;
+ char *name = NULL;
+ int car;
+
+ while(1) {
+ token = getToken(in);
+ if(!strcmp("name",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"name was expected");
+ else if(car == '\"') name = allocAndCopy(getQuotedString(in));
+ else name = allocAndCopy(getName(in));
+ } else {
+ ungetToken(in);
+ break;
+ }
+
+ }
+ if(name == NULL) in->error(in, "Name was expected");
+ return name;
+}
+
+
+
+//for <label name=label_name value=n format="...">, value is an option
+//Return value : 0 : no value, 1 : has a value
+int getValueAttribute(parse_file_t *in, long long *value)
+{
+ char * token, * endptr;
+
+ token = getToken(in);
+
+ if(strcmp("/",token) == 0 || strcmp(">", token) == 0){
+ ungetToken(in);
+ return 0;
+ }
+ if(strcmp("value",token))in->error(in,"value was expected");
+
+ getEqual(in);
+ token = getToken(in);
+
+ *value = strtoll(token, &endptr, 0);
+ if(*endptr != '\0')
+ goto error;
+ return 1;
+error:
+ in->error(in,"invalid number specified");
+ return 0;
+}
+
+char * getDescription(parse_file_t *in)
+{
+ long int pos;
+ char * token, *str;
+ int car;
+
+ pos = ftell(in->fp);
+
+ getLAnglebracket(in);
+ token = getName(in);
+ if(strcmp("description",token)){
+ fseek(in->fp, pos, SEEK_SET);
+ return NULL;
+ }
+
+ getRAnglebracket(in);
+
+ pos = 0;
+ while((car = getc(in->fp)) != EOF) {
+ if(car == '<') break;
+ if(car == '\0') continue;
+ in->buffer[pos] = car;
+ pos++;
+ }
+ if(car == EOF)in->error(in,"not a valid description");
+ in->buffer[pos] = '\0';
+
+ str = allocAndCopy(in->buffer);
+
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("description", token))in->error(in,"not a valid description");
+ getRAnglebracket(in);
+
+ return str;
+}
+
+/*****************************************************************************
+ *Function name
+ * parseFacility : generate event list
+ *Input params
+ * in : input file handle
+ * fac : empty facility
+ *Output params
+ * fac : facility filled with event list
+ ****************************************************************************/
+
+void parseFacility(parse_file_t *in, facility_t * fac)
+{
+ char * token;
+ event_t *ev;
+
+ getFacilityAttributes(in, fac);
+ if(fac->name == NULL) in->error(in, "Attribute not named");
+
+ fac->capname = allocAndCopy(fac->name);
+ strupper(fac->capname);
+ getRAnglebracket(in);
+
+ fac->description = getDescription(in);
+
+ while(1){
+ getLAnglebracket(in);
+
+ token = getToken(in);
+ if(in->type == ENDFILE)
+ in->error(in,"the definition of the facility is not finished");
+
+ if(strcmp("event",token) == 0){
+ ev = (event_t*) memAlloc(sizeof(event_t));
+ sequence_push(&(fac->events),ev);
+ parseEvent(fac, in, ev, &(fac->unnamed_types), &(fac->named_types));
+ }else if(strcmp("type",token) == 0){
+ parseTypeDefinition(fac, in, &(fac->unnamed_types), &(fac->named_types));
+ }else if(in->type == FORWARDSLASH){
+ break;
+ }else in->error(in,"event or type token expected\n");
+ }
+
+ token = getName(in);
+ if(strcmp("facility",token)) in->error(in,"not the end of the facility");
+ getRAnglebracket(in); //</facility>
+}
+
+/*****************************************************************************
+ *Function name
+ * parseEvent : generate event from event definition
+ *Input params
+ * fac : facility holding the event
+ * in : input file handle
+ * ev : new event
+ * unnamed_types : array of unamed types
+ * named_types : array of named types
+ *Output params
+ * ev : new event (parameters are passed to it)
+ ****************************************************************************/
+
+void parseEvent(facility_t *fac, parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
+ table_t * named_types)
+{
+ char *token;
+ field_t *f;
+
+ ev->fac = fac;
+ sequence_init(&(ev->fields));
+ //<event name=eventtype_name>
+ getEventAttributes(in, ev);
+ if(ev->name == NULL) in->error(in, "Event not named");
+ getRAnglebracket(in);
+
+ //<description>...</description>
+ ev->description = getDescription(in);
+
+ int got_end = 0;
+ /* Events can have multiple fields. each field form at least a function
+ * parameter of the logging function. */
+ while(!got_end) {
+ getLAnglebracket(in);
+ token = getToken(in);
+
+ switch(in->type) {
+ case FORWARDSLASH: /* </event> */
+ token = getName(in);
+ if(strcmp("event",token))in->error(in,"not an event definition");
+ getRAnglebracket(in); //</event>
+ got_end = 1;
+ break;
+ case NAME: /* a field */
+ if(strcmp("field",token))in->error(in,"expecting a field");
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(ev->fields),f);
+ parseFields(fac, in, f, unnamed_types, named_types, 1);
+ break;
+ default:
+ in->error(in, "expecting </event> or <field >");
+ break;
+ }
+ }
+#if 0
+ if(in->type == FORWARDSLASH){ //</event> NOTHING
+ ev->type = NULL;
+ }else if(in->type == NAME){
+ if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
+ ungetToken(in);
+ ev->type = parseType(in,NULL, unnamed_types, named_types);
+ if(ev->type->type != STRUCT && ev->type->type != NONE)
+ in->error(in,"type must be a struct");
+ }else in->error(in, "not a valid type");
+
+ getLAnglebracket(in);
+ getForwardslash(in);
+ }else in->error(in,"not a struct type");
+ getLAnglebracket(in);
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("event",token))in->error(in,"not an event definition");
+ getRAnglebracket(in); //</event>
+#endif //0
+}
+
+/*****************************************************************************
+ *Function name
+ * parseField : get field infomation from buffer
+ *Input params
+ * fac : facility holding the field
+ * in : input file handle
+ * f : field
+ * unnamed_types : array of unamed types
+ * named_types : array of named types
+ * tag : is field surrounded by a <field> </field> tag ?
+ ****************************************************************************/
+
+void parseFields(facility_t *fac, parse_file_t *in, field_t *f,
+ sequence_t * unnamed_types,
+ table_t * named_types,
+ int tag)
+{
+ char * token;
+ f->fac = fac;
+ if(tag) {
+ //<field name=field_name> <description> <type> </field>
+ getFieldAttributes(in, f);
+ if(f->name == NULL) in->error(in, "Field not named");
+ getRAnglebracket(in);
+
+ f->description = getDescription(in);
+ } else {
+ f->description = NULL;
+ }
+
+ //<int size=...>
+ getLAnglebracket(in);
+ f->type = parseType(fac, in,NULL, unnamed_types, named_types);
+
+ if(tag) {
+ getLAnglebracket(in);
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("field",token))in->error(in,"not a valid field definition");
+ getRAnglebracket(in); //</field>
+ }
+}
+
+
+/*****************************************************************************
+ *Function name
+ * parseType : get type information, type can be :
+ * Primitive:
+ * int(size,fmt); uint(size,fmt); float(size,fmt);
+ * string(fmt); enum(size,fmt,(label1,label2...))
+ * Compound:
+ * array(arraySize, type); sequence(lengthSize,type)
+ * struct(field(name,type,description)...)
+ * type name:
+ * type(name,type)
+ *Input params
+ * fac : facility
+ * in : input file handle
+ * inType : a type descriptor
+ * unnamed_types : array of unamed types
+ * named_types : array of named types
+ *Return values
+ * type_descriptor* : a type descriptor
+ ****************************************************************************/
+
+type_descriptor_t *parseType(facility_t *fac, parse_file_t *in, type_descriptor_t *inType,
+ sequence_t * unnamed_types, table_t * named_types)
+{
+ char *token;
+ type_descriptor_t *t;
+ field_t *f;
+
+ if(inType == NULL) {
+ t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
+ t->type_name = NULL;
+ t->type = NONE;
+ t->fmt = NULL;
+ sequence_push(unnamed_types,t);
+ }
+ else t = inType;
+ t->fac = fac;
+
+ token = getName(in);
+
+ if(strcmp(token,"struct") == 0) {
+ t->type = STRUCT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getRAnglebracket(in); //<struct>
+ getLAnglebracket(in); //<field name=..>
+ token = getToken(in);
+ sequence_init(&(t->fields));
+ while(strcmp("field",token) == 0){
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+
+ parseFields(fac, in, f, unnamed_types, named_types, 1);
+
+ //next field
+ getLAnglebracket(in);
+ token = getToken(in);
+ }
+ if(strcmp("/",token))in->error(in,"not a valid structure definition");
+ token = getName(in);
+ if(strcmp("struct",token)!=0)
+ in->error(in,"not a valid structure definition");
+ getRAnglebracket(in); //</struct>
+ }
+ else if(strcmp(token,"union") == 0) {
+ t->type = UNION;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getRAnglebracket(in); //<union>
+
+ getLAnglebracket(in); //<field name=..>
+ token = getToken(in);
+ sequence_init(&(t->fields));
+ while(strcmp("field",token) == 0){
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+ parseFields(fac, in, f, unnamed_types, named_types, 1);
+
+ //next field
+ getLAnglebracket(in);
+ token = getToken(in);
+ }
+ if(strcmp("/",token))in->error(in,"not a valid union definition");
+ token = getName(in);
+ if(strcmp("union",token)!=0)
+ in->error(in,"not a valid union definition");
+ getRAnglebracket(in); //</union>
+ }
+ else if(strcmp(token,"array") == 0) {
+ t->type = ARRAY;
+ sequence_init(&(t->fields));
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ if(t->size == 0) in->error(in, "Array has empty size");
+ getForwardslash(in);
+ getRAnglebracket(in); //<array size=n>
+
+ //getLAnglebracket(in); //<subtype>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
+ parseFields(fac, in, f, unnamed_types, named_types, 0);
+
+ //getLAnglebracket(in); //<type struct>
+ //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+ getLAnglebracket(in); //</array>
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("array",token))in->error(in,"not a valid array definition");
+ getRAnglebracket(in); //</array>
+ }
+ else if(strcmp(token,"sequence") == 0) {
+ t->type = SEQUENCE;
+ sequence_init(&(t->fields));
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in); //<sequence>
+
+ //getLAnglebracket(in); //<sequence size type>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
+ parseFields(fac, in, f, unnamed_types, named_types, 0);
+
+ //getLAnglebracket(in); //<subtype>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
+ parseFields(fac, in, f, unnamed_types, named_types, 0);
+
+ //getLAnglebracket(in); //<type sequence>
+ //t->length_type = parseType(in, NULL, unnamed_types, named_types);
+
+ //getLAnglebracket(in); //<type sequence>
+
+ //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+ if(t->fields.position < 1) in->error(in, "Sequence has no length type");
+ if(t->fields.position < 2) in->error(in, "Sequence has no subtype");
+ switch(((field_t*)t->fields.array[0])->type->type) {
+ case UINT_FIXED :
+ case UCHAR :
+ case USHORT :
+ case UINT :
+ case ULONG :
+ case SIZE_T :
+ case OFF_T :
+ break;
+ default:
+ in->error(in, "Wrong length type for sequence");
+ }
+
+ getLAnglebracket(in); //</sequence>
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("sequence",token))in->error(in,"not a valid sequence definition");
+ getRAnglebracket(in); //</sequence>
+ }
+ else if(strcmp(token,"enum") == 0) {
+ char * str;
+ long long value = -1;
+
+ t->type = ENUM;
+ sequence_init(&(t->labels));
+ sequence_init(&(t->labels_values));
+ sequence_init(&(t->labels_description));
+ t->already_printed = 0;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ //if(t->size == 0) in->error(in, "Sequence has empty size");
+ //Mathieu : we fix enum size to target int size. GCC is always like this.
+ //fox copy optimisation.
+ if(t->size != 0) in->error(in, "Enum has fixed size of target int.");
+ t->size = 0;
+ getRAnglebracket(in);
+
+ //<label name=label1 value=n/>
+ getLAnglebracket(in);
+ token = getToken(in); //"label" or "/"
+ while(strcmp("label",token) == 0){
+ int *label_value = malloc(sizeof(int));
+ int has_value = 0;
+ long long loc_value;
+
+ str = allocAndCopy(getNameAttribute(in));
+ has_value = getValueAttribute(in, &loc_value);
+
+ sequence_push(&(t->labels),str);
+
+ if(has_value) value = loc_value;
+ else value++;
+
+ *label_value = value;
+ sequence_push(&(t->labels_values), label_value);
+
+ getForwardslash(in);
+ getRAnglebracket(in);
+
+ //read description if any. May be NULL.
+ str = allocAndCopy(getDescription(in));
+ sequence_push(&(t->labels_description),str);
+
+ //next label definition
+ getLAnglebracket(in);
+ token = getToken(in); //"label" or "/"
+ }
+ if(strcmp("/",token))in->error(in, "not a valid enum definition");
+ token = getName(in);
+ if(strcmp("enum",token))in->error(in, "not a valid enum definition");
+ getRAnglebracket(in); //</label>
+ }
+ else if(strcmp(token,"int_fixed") == 0) {
+ t->type = INT_FIXED;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ if(t->size == 0) in->error(in, "int has empty size");
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"uint_fixed") == 0) {
+ t->type = UINT_FIXED;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ if(t->size == 0) in->error(in, "uint has empty size");
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"char") == 0) {
+ t->type = CHAR;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 1;
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"uchar") == 0) {
+ t->type = UCHAR;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 1;
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"short") == 0) {
+ t->type = SHORT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 2;
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"ushort") == 0) {
+ t->type = USHORT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 2;
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"int") == 0) {
+ t->type = INT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"uint") == 0) {
+ t->type = UINT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+
+ else if(strcmp(token,"pointer") == 0) {
+ t->type = POINTER;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"long") == 0) {
+ t->type = LONG;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"ulong") == 0) {
+ t->type = ULONG;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"size_t") == 0) {
+ t->type = SIZE_T;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"ssize_t") == 0) {
+ t->type = SSIZE_T;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"off_t") == 0) {
+ t->type = OFF_T;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"float") == 0) {
+ t->type = FLOAT;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"string") == 0) {
+ t->type = STRING;
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
+ getRAnglebracket(in);
+ }
+ else if(strcmp(token,"typeref") == 0){
+ // Must be a named type
+ free(t);
+ sequence_pop(unnamed_types);
+ token = getNameAttribute(in);
+ t = find_named_type(token, named_types);
+ if(t == NULL) in->error(in,"Named referred to must be pre-declared.");
+ getForwardslash(in); //<typeref name=type_name/>
+ getRAnglebracket(in);
+ return t;
+ }else in->error(in,"not a valid type");
+
+ return t;
+}
+
+/*****************************************************************************
+ *Function name
+ * find_named_type : find a named type from hash table
+ *Input params
+ * name : type name
+ * named_types : array of named types
+ *Return values
+ * type_descriptor * : a type descriptor
+ *****************************************************************************/
+
+type_descriptor_t * find_named_type(char *name, table_t * named_types)
+{
+ type_descriptor_t *t;
+
+ t = (type_descriptor_t*)table_find(named_types,name);
+
+ return t;
+}
+
+type_descriptor_t * create_named_type(char *name, table_t * named_types)
+{
+ type_descriptor_t *t;
+
+ t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
+ t->type_name = allocAndCopy(name);
+ t->type = NONE;
+ t->fmt = NULL;
+ table_insert(named_types,t->type_name,t);
+ // table_insert(named_types,allocAndCopy(name),t);
+ return t;
+}
+
+/*****************************************************************************
+ *Function name
+ * parseTypeDefinition : get type information from type definition
+ *Input params
+ * fac : facility
+ * in : input file handle
+ * unnamed_types : array of unamed types
+ * named_types : array of named types
+ *****************************************************************************/
+
+void parseTypeDefinition(facility_t *fac, parse_file_t * in, sequence_t * unnamed_types,
+ table_t * named_types)
+{
+ char *token;
+ type_descriptor_t *t;
+
+ token = getNameAttribute(in);
+ if(token == NULL) in->error(in, "Type has empty name");
+ t = create_named_type(token, named_types);
+
+ if(t->type != NONE) in->error(in,"redefinition of named type");
+ getRAnglebracket(in); //<type name=type_name>
+ getLAnglebracket(in); //<
+ token = getName(in);
+ //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition");
+ ungetToken(in);
+ parseType(fac, in,t, unnamed_types, named_types);
+
+ //</type>
+ getLAnglebracket(in);
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("type",token))in->error(in,"not a valid type definition");
+ getRAnglebracket(in); //</type>
+}
+
+/**************************************************************************
+ * Function :
+ * getComa, getName, getNumber, getEqual
+ * Description :
+ * Read a token from the input file, check its type, return it scontent.
+ *
+ * Parameters :
+ * in , input file handle.
+ *
+ * Return values :
+ * address of token content.
+ *
+ **************************************************************************/
+
+char *getName(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ // Optional descriptions
+ // if(in->type != NAME) in->error(in,"Name token was expected");
+ return token;
+}
+
+int getNumber(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ if(in->type != NUMBER) in->error(in, "Number token was expected");
+ return atoi(token);
+}
+
+char *getForwardslash(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ //if(in->type != FORWARDSLASH) in->error(in, "forward slash token was expected");
+ /* Mathieu : final / is optional now. */
+ if(in->type != FORWARDSLASH) ungetToken(in);
+
+ return token;
+}
+
+char *getLAnglebracket(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ if(in->type != LANGLEBRACKET) in->error(in, "Left angle bracket was expected");
+ return token;
+}
+
+char *getRAnglebracket(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ if(in->type != RANGLEBRACKET) in->error(in, "Right angle bracket was expected");
+ return token;
+}
+
+char *getQuotedString(parse_file_t * in)
+{
+ char *token;
+
+ token = getToken(in);
+ if(in->type != QUOTEDSTRING) in->error(in, "quoted string was expected");
+ return token;
+}
+
+char * getEqual(parse_file_t *in)
+{
+ char *token;
+
+ token = getToken(in);
+ if(in->type != EQUAL) in->error(in, "equal was expected");
+ return token;
+}
+
+int seekNextChar(parse_file_t *in)
+{
+ int car;
+ while((car = getc(in->fp)) != EOF) {
+ if(!isspace(car)){
+ ungetc(car,in->fp);
+ return car;
+ }
+ }
+ return EOF;
+}
+
+/******************************************************************
+ * Function :
+ * getToken, ungetToken
+ * Description :
+ * Read a token from the input file and return its type and content.
+ * Line numbers are accounted for and whitespace/comments are skipped.
+ *
+ * Parameters :
+ * in, input file handle.
+ *
+ * Return values :
+ * address of token content.
+ *
+ ******************************************************************/
+
+void ungetToken(parse_file_t * in)
+{
+ in->unget = 1;
+}
+
+char *getToken(parse_file_t * in)
+{
+ FILE *fp = in->fp;
+ int car, car1;
+ int pos = 0, escaped;
+
+ if(in->unget == 1) {
+ in->unget = 0;
+ return in->buffer;
+ }
+
+ /* skip whitespace and comments */
+
+ while((car = getc(fp)) != EOF) {
+ if(car == '/') {
+ car1 = getc(fp);
+ if(car1 == '*') skipComment(in);
+ else if(car1 == '/') skipEOL(in);
+ else {
+ car1 = ungetc(car1,fp);
+ break;
+ }
+ }
+ else if(car == '\n') in->lineno++;
+ else if(!isspace(car)) break;
+ }
+
+ switch(car) {
+ case EOF:
+ in->type = ENDFILE;
+ break;
+ case '/':
+ in->type = FORWARDSLASH;
+ in->buffer[pos] = car;
+ pos++;
+ break;
+ case '<':
+ in->type = LANGLEBRACKET;
+ in->buffer[pos] = car;
+ pos++;
+ break;
+ case '>':
+ in->type = RANGLEBRACKET;
+ in->buffer[pos] = car;
+ pos++;
+ break;
+ case '=':
+ in->type = EQUAL;
+ in->buffer[pos] = car;
+ pos++;
+ break;
+ case '"':
+ escaped = 0;
+ while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+ if(car == '\\' && escaped == 0) {
+ in->buffer[pos] = car;
+ pos++;
+ escaped = 1;
+ continue;
+ }
+ if(car == '"' && escaped == 0) break;
+ if(car == '\n' && escaped == 0) {
+ in->error(in, "non escaped newline inside quoted string");
+ }
+ if(car == '\n') in->lineno++;
+ in->buffer[pos] = car;
+ pos++;
+ escaped = 0;
+ }
+ if(car == EOF) in->error(in,"no ending quotemark");
+ if(pos == BUFFER_SIZE) in->error(in, "quoted string token too large");
+ in->type = QUOTEDSTRING;
+ break;
+ default:
+ if(isdigit(car)) {
+ in->buffer[pos] = car;
+ pos++;
+ while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+ if(!isdigit(car)) {
+ ungetc(car,fp);
+ break;
+ }
+ in->buffer[pos] = car;
+ pos++;
+ }
+ if(car == EOF) ungetc(car,fp);
+ if(pos == BUFFER_SIZE) in->error(in, "number token too large");
+ in->type = NUMBER;
+ }
+ else if(isalnum(car) || car == '_' || car == '-') {
+ in->buffer[0] = car;
+ pos = 1;
+ while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+ if(!(isalnum(car) || car == '_' || car == '-')) {
+ ungetc(car,fp);
+ break;
+ }
+ in->buffer[pos] = car;
+ pos++;
+ }
+ if(car == EOF) ungetc(car,fp);
+ if(pos == BUFFER_SIZE) in->error(in, "name token too large");
+ in->type = NAME;
+ } else if(car == '?') {
+ in->buffer[0] = car;
+ pos++;
+ }
+ else in->error(in, "invalid character, unrecognized token");
+ }
+ in->buffer[pos] = 0;
+ return in->buffer;
+}
+
+void skipComment(parse_file_t * in)
+{
+ int car;
+ while((car = getc(in->fp)) != EOF) {
+ if(car == '\n') in->lineno++;
+ else if(car == '*') {
+ car = getc(in->fp);
+ if(car ==EOF) break;
+ if(car == '/') return;
+ ungetc(car,in->fp);
+ }
+ }
+ if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
+}
+
+void skipEOL(parse_file_t * in)
+{
+ int car;
+ while((car = getc(in->fp)) != EOF) {
+ if(car == '\n') {
+ ungetc(car,in->fp);
+ break;
+ }
+ }
+ if(car == EOF)ungetc(car, in->fp);
+}
+
+/*****************************************************************************
+ *Function name
+ * checkNamedTypesImplemented : check if all named types have definition
+ ****************************************************************************/
+
+void checkNamedTypesImplemented(table_t * named_types)
+{
+ type_descriptor_t *t;
+ int pos;
+ char str[256];
+
+ for(pos = 0 ; pos < named_types->values.position; pos++) {
+ t = (type_descriptor_t *) named_types->values.array[pos];
+ if(t->type == NONE){
+ sprintf(str,"named type '%s' has no definition",
+ (char*)named_types->keys.array[pos]);
+ error_callback(NULL,str);
+ }
+ }
+}
+
+
+/*****************************************************************************
+ *Function name
+ * generateChecksum : generate checksum for the facility
+ *Input Params
+ * facName : name of facility
+ *Output Params
+ * checksum : checksum for the facility
+ ****************************************************************************/
+
+void generateChecksum(char* facName,
+ unsigned int * checksum, sequence_t * events)
+{
+ unsigned long crc ;
+ int pos;
+ event_t * ev;
+ unsigned int i;
+
+ crc = crc32(facName);
+ for(pos = 0; pos < events->position; pos++){
+ ev = (event_t *)(events->array[pos]);
+ crc = partial_crc32(ev->name, crc);
+ for(i = 0; i < ev->fields.position; i++) {
+ field_t *f = (field_t*)ev->fields.array[i];
+ crc = partial_crc32(f->name, crc);
+ crc = getTypeChecksum(crc, f->type);
+ }
+ }
+ *checksum = crc;
+}
+
+/*****************************************************************************
+ *Function name
+ * getTypeChecksum : generate checksum by type info
+ *Input Params
+ * crc : checksum generated so far
+ * type : type descriptor containing type info
+ *Return value
+ * unsigned long : checksum
+ *****************************************************************************/
+
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
+{
+ unsigned long crc = aCrc;
+ char * str = NULL, buf[16];
+ int flag = 0, pos;
+ field_t * fld;
+
+ switch(type->type){
+ case INT_FIXED:
+ str = intOutputTypes[getSizeindex(type->size)];
+ break;
+ case UINT_FIXED:
+ str = uintOutputTypes[getSizeindex(type->size)];
+ break;
+ case POINTER:
+ str = allocAndCopy("void *");
+ flag = 1;
+ break;
+ case CHAR:
+ str = allocAndCopy("signed char");
+ flag = 1;
+ break;
+ case UCHAR:
+ str = allocAndCopy("unsigned char");
+ flag = 1;
+ break;
+ case SHORT:
+ str = allocAndCopy("short");
+ flag = 1;
+ break;
+ case USHORT:
+ str = allocAndCopy("unsigned short");
+ flag = 1;
+ break;
+ case INT:
+ str = allocAndCopy("int");
+ flag = 1;
+ break;
+ case UINT:
+ str = allocAndCopy("uint");
+ flag = 1;
+ break;
+ case LONG:
+ str = allocAndCopy("long");
+ flag = 1;
+ break;
+ case ULONG:
+ str = allocAndCopy("unsigned long");
+ flag = 1;
+ break;
+ case SIZE_T:
+ str = allocAndCopy("size_t");
+ flag = 1;
+ break;
+ case SSIZE_T:
+ str = allocAndCopy("ssize_t");
+ flag = 1;
+ break;
+ case OFF_T:
+ str = allocAndCopy("off_t");
+ flag = 1;
+ break;
+ case FLOAT:
+ str = floatOutputTypes[getSizeindex(type->size)];
+ break;
+ case STRING:
+ str = allocAndCopy("string");
+ flag = 1;
+ break;
+ case ENUM:
+ //str = appendString("enum ", uintOutputTypes[getSizeindex(type->size)]);
+ str = allocAndCopy("enum");
+ flag = 1;
+ break;
+ case ARRAY:
+ sprintf(buf,"%zu", type->size);
+ str = appendString("array ",buf);
+ flag = 1;
+ break;
+ case SEQUENCE:
+ str = allocAndCopy("sequence ");
+ flag = 1;
+ break;
+ case STRUCT:
+ str = allocAndCopy("struct");
+ flag = 1;
+ break;
+ case UNION:
+ str = allocAndCopy("union");
+ flag = 1;
+ break;
+ default:
+ error_callback(NULL, "named type has no definition");
+ break;
+ }
+
+ crc = partial_crc32(str,crc);
+ if(flag) free(str);
+
+ //the format string is not included in the crc calculation
+
+ //if(type->fmt) crc = partial_crc32(type->fmt,crc);
+
+ if(type->type == ARRAY){
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+ } else if(type->type ==SEQUENCE) {
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[1])->type);
+ } else if(type->type == STRUCT || type->type == UNION){
+ for(pos =0; pos < type->fields.position; pos++){
+ fld = (field_t *) type->fields.array[pos];
+ crc = partial_crc32(fld->name,crc);
+ crc = getTypeChecksum(crc, fld->type);
+ }
+ }else if(type->type == ENUM){
+ for(pos = 0; pos < type->labels.position; pos++)
+ crc = partial_crc32((char*)type->labels.array[pos],crc);
+ }
+
+ return crc;
+}
+
+
+/* Event type descriptors */
+void freeType(type_descriptor_t * tp)
+{
+ int pos2;
+ field_t *f;
+
+ if(tp->fmt != NULL) free(tp->fmt);
+ if(tp->type == ENUM) {
+ for(pos2 = 0; pos2 < tp->labels.position; pos2++) {
+ free(tp->labels.array[pos2]);
+ }
+ sequence_dispose(&(tp->labels));
+ for(pos2 = 0; pos2 < tp->labels_values.position; pos2++) {
+ free(tp->labels_values.array[pos2]);
+ }
+ sequence_dispose(&(tp->labels_values));
+ }
+ if(tp->type == STRUCT) {
+ for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
+ f = (field_t *) tp->fields.array[pos2];
+ free(f->name);
+ free(f->description);
+ free(f);
+ }
+ sequence_dispose(&(tp->fields));
+ }
+}
+
+void freeNamedType(table_t * t)
+{
+ int pos;
+ type_descriptor_t * td;
+
+ for(pos = 0 ; pos < t->keys.position; pos++) {
+ free((char *)t->keys.array[pos]);
+ td = (type_descriptor_t*)t->values.array[pos];
+ freeType(td);
+ free(td);
+ }
+}
+
+void freeTypes(sequence_t *t)
+{
+ int pos;
+ type_descriptor_t *tp;
+
+ for(pos = 0 ; pos < t->position; pos++) {
+ tp = (type_descriptor_t *)t->array[pos];
+ freeType(tp);
+ free(tp);
+ }
+}
+
+void freeEvents(sequence_t *t)
+{
+ int pos;
+ event_t *ev;
+
+ for(pos = 0 ; pos < t->position; pos++) {
+ ev = (event_t *) t->array[pos];
+ free(ev->name);
+ free(ev->description);
+ sequence_dispose(&ev->fields);
+ free(ev);
+ }
+
+}
+
+
+/* Extensible array */
+
+void sequence_init(sequence_t *t)
+{
+ t->size = 10;
+ t->position = 0;
+ t->array = (void **)memAlloc(t->size * sizeof(void *));
+}
+
+void sequence_dispose(sequence_t *t)
+{
+ t->size = 0;
+ free(t->array);
+ t->array = NULL;
+}
+
+void sequence_push(sequence_t *t, void *elem)
+{
+ void **tmp;
+
+ if(t->position >= t->size) {
+ tmp = t->array;
+ t->array = (void **)memAlloc(t->size * 2 * sizeof(void *));
+ memcpy(t->array, tmp, t->size * sizeof(void *));
+ t->size = t->size * 2;
+ free(tmp);
+ }
+ t->array[t->position] = elem;
+ t->position++;
+}
+
+void *sequence_pop(sequence_t *t)
+{
+ if(t->position == 0) printf("Error : trying to pop an empty sequence");
+ return t->array[--t->position];
+}
+
+
+/* Hash table API, implementation is just linear search for now */
+
+void table_init(table_t *t)
+{
+ sequence_init(&(t->keys));
+ sequence_init(&(t->values));
+}
+
+void table_dispose(table_t *t)
+{
+ sequence_dispose(&(t->keys));
+ sequence_dispose(&(t->values));
+}
+
+void table_insert(table_t *t, char *key, void *value)
+{
+ sequence_push(&(t->keys),key);
+ sequence_push(&(t->values),value);
+}
+
+void *table_find(table_t *t, char *key)
+{
+ int pos;
+ for(pos = 0 ; pos < t->keys.position; pos++) {
+ if(strcmp((char *)key,(char *)t->keys.array[pos]) == 0)
+ return(t->values.array[pos]);
+ }
+ return NULL;
+}
+
+void table_insert_int(table_t *t, int *key, void *value)
+{
+ sequence_push(&(t->keys),key);
+ sequence_push(&(t->values),value);
+}
+
+void *table_find_int(table_t *t, int *key)
+{
+ int pos;
+ for(pos = 0 ; pos < t->keys.position; pos++) {
+ if(*key == *(int *)t->keys.array[pos])
+ return(t->values.array[pos]);
+ }
+ return NULL;
+}
+
+
+/* Concatenate strings */
+
+char *appendString(char *s, char *suffix)
+{
+ char *tmp;
+ if(suffix == NULL) return s;
+
+ tmp = (char *)memAlloc(strlen(s) + strlen(suffix) + 1);
+ strcpy(tmp,s);
+ strcat(tmp,suffix);
+ return tmp;
+}
--- /dev/null
+#ifndef PARSER_H
+#define PARSER_H
+
+/* Extensible array container */
+
+typedef struct _sequence {
+ int size;
+ int position;
+ void **array;
+} sequence_t;
+
+void sequence_init(sequence_t *t);
+void sequence_dispose(sequence_t *t);
+void sequence_push(sequence_t *t, void *elem);
+void *sequence_pop(sequence_t *t);
+
+
+/* Hash table */
+
+typedef struct _table {
+ sequence_t keys;
+ sequence_t values;
+} table_t;
+
+void table_init(table_t *t);
+void table_dispose(table_t *t);
+void table_insert(table_t *t, char *key, void *value);
+void *table_find(table_t *t, char *key);
+void table_insert_int(table_t *t, int *key, void *value);
+void *table_find_int(table_t *t, int *key);
+
+
+/* Token types */
+
+typedef enum _token_type {
+ ENDFILE,
+ FORWARDSLASH,
+ LANGLEBRACKET,
+ RANGLEBRACKET,
+ EQUAL,
+ QUOTEDSTRING,
+ NUMBER,
+ NAME
+} token_type_t;
+
+
+/* State associated with a file being parsed */
+typedef struct _parse_file {
+ char *name;
+ FILE * fp;
+ int lineno;
+ char *buffer;
+ token_type_t type;
+ int unget;
+ void (*error) (struct _parse_file *, char *);
+} parse_file_t;
+
+void ungetToken(parse_file_t * in);
+char *getToken(parse_file_t *in);
+char *getForwardslash(parse_file_t *in);
+char *getLAnglebracket(parse_file_t *in);
+char *getRAnglebracket(parse_file_t *in);
+char *getQuotedString(parse_file_t *in);
+char *getName(parse_file_t *in);
+int getNumber(parse_file_t *in);
+char *getEqual(parse_file_t *in);
+int seekNextChar(parse_file_t *in);
+
+void skipComment(parse_file_t * in);
+void skipEOL(parse_file_t * in);
+
+/* Some constants */
+
+static const int BUFFER_SIZE = 1024;
+
+
+/* Events data types */
+
+typedef enum _data_type {
+ INT_FIXED,
+ UINT_FIXED,
+ POINTER,
+ CHAR,
+ UCHAR,
+ SHORT,
+ USHORT,
+ INT,
+ UINT,
+ LONG,
+ ULONG,
+ SIZE_T,
+ SSIZE_T,
+ OFF_T,
+ FLOAT,
+ STRING,
+ ENUM,
+ ARRAY,
+ SEQUENCE,
+ STRUCT,
+ UNION,
+ NONE
+} data_type_t;
+
+typedef struct _facility facility_t;
+typedef struct _event event_t;
+
+typedef struct _type_descriptor {
+ facility_t *fac;
+ char * type_name; //used for named type
+ data_type_t type;
+ char *fmt;
+ size_t size;
+ sequence_t labels; // for enumeration
+ sequence_t labels_values; // for enumeration
+ sequence_t labels_description;
+ int already_printed;
+ sequence_t fields; // for structure, array and sequence (field_t type)
+ int custom_write; /* Should we use a custom write function ? */
+ int network; /* Is the type a in network byte order ? */
+} type_descriptor_t;
+
+
+/* Fields within types or events */
+typedef struct _field{
+ facility_t *fac;
+ char *name;
+ char *description;
+ type_descriptor_t *type;
+} field_t;
+
+
+/* Events definitions */
+
+struct _event {
+ facility_t *fac;
+ char *name;
+ char *description;
+ //type_descriptor_t *type;
+ sequence_t fields; /* event fields */
+ int per_trace; /* Is the event able to be logged to a specific trace ? */
+ int per_tracefile; /* Must we log this event in a specific tracefile ? */
+ int param_buffer; /* For userspace tracing : takes a buffer as parameter? */
+ int no_instrument_function;
+ int high_priority;
+ int force;
+ int compact_data;
+};
+
+struct _facility {
+ char * name;
+ char * capname;
+ char * arch;
+ int align; /* Alignment : default 1, 0 no alignment. */
+ char * description;
+ sequence_t events;
+ sequence_t unnamed_types; //FIXME : remove
+ table_t named_types;
+ unsigned int checksum;
+ int user; /* Is this a userspace facility ? */
+};
+
+int getSizeindex(unsigned int value);
+unsigned long long int getSize(parse_file_t *in);
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
+
+void parseFacility(parse_file_t *in, facility_t * fac);
+void parseEvent(facility_t *fac, parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
+ table_t * named_types);
+void parseTypeDefinition(facility_t *fac, parse_file_t *in,
+ sequence_t * unnamed_types, table_t * named_types);
+type_descriptor_t *parseType(facility_t *fac, parse_file_t *in,
+ type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
+void parseFields(facility_t *fac, parse_file_t *in, field_t *f,
+ sequence_t * unnamed_types,
+ table_t * named_types,
+ int tag);
+void checkNamedTypesImplemented(table_t * namedTypes);
+type_descriptor_t * find_named_type(char *name, table_t * named_types);
+void generateChecksum(char * facName,
+ unsigned int * checksum, sequence_t * events);
+
+
+/* get attributes */
+char * getNameAttribute(parse_file_t *in);
+char * getFormatAttribute(parse_file_t *in);
+int getSizeAttribute(parse_file_t *in);
+int getValueAttribute(parse_file_t *in, long long *value);
+
+char * getDescription(parse_file_t *in);
+
+
+/* Dynamic memory allocation and freeing */
+
+void * memAlloc(int size);
+char *allocAndCopy(char * str);
+char *appendString(char *s, char *suffix);
+void freeTypes(sequence_t *t);
+void freeType(type_descriptor_t * td);
+void freeEvents(sequence_t *t);
+void freeNamedType(table_t * t);
+void error_callback(parse_file_t *in, char *msg);
+
+
+//checksum part
+static const unsigned int crctab32[] =
+{
+#include "crc32.tab"
+};
+
+static inline unsigned long
+partial_crc32_one(unsigned char c, unsigned long crc)
+{
+ return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
+}
+
+static inline unsigned long
+partial_crc32(const char *s, unsigned long crc)
+{
+ while (*s)
+ crc = partial_crc32_one(*s++, crc);
+ return crc;
+}
+
+static inline unsigned long
+crc32(const char *s)
+{
+ return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
+}
+
+
+extern char *intOutputTypes[];
+
+extern char *uintOutputTypes[];
+
+extern char *floatOutputTypes[];
+
+
+
+
+#endif // PARSER_H
--- /dev/null
+#
+# Spec file for genevent
+#
+Summary: Genevent package
+Name: genevent
+Version: 0.22
+License: GPL
+Release: 1
+Group: Applications/Development
+Source: http://ltt.polymtl.ca/packages/%{name}-%{version}.tar.gz
+URL: http://ltt.polymtl.ca
+Packager: Martin Bisson <bissonm@discreet.com>
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+
+%description
+This packages contains the facility code generator.
+
+%prep
+%setup -q
+
+%build
+make
+
+%install
+rm -rf $RPM_BUILD_ROOT
+mkdir -p $RPM_BUILD_ROOT $RPM_BUILD_ROOT/usr/bin
+cp genevent $RPM_BUILD_ROOT/usr/bin/genevent
+
+%files
+/usr/bin/genevent
--- /dev/null
+<?xml version="1.0"?>
+<facility name="test">
+ <description>The kernel facility has events related to kernel execution status.</description>
+
+
+ <type name="tasklet_priority">
+ <enum>
+ <label name="LOW" value="0"> <description>Low priority tasklet</description>
+ <label name="HIGH" value="1"> <description>High priority tasklet</description>
+ </enum>
+ </type>
+
+ <type name="irq_mode">
+ <enum>
+ <label name="user" value="0"> <description>User context</description>
+ <label name="kernel" value="1"> <description>Kernel context</description>
+ </enum>
+ </type>
+
+ <type name="mystruct2">
+ <struct>
+ <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
+ <field name="mode"> <description>Are we executing kernel code</description> <typeref name="irq_mode"> </field>
+ </struct>
+ </type>
+
+ <type name="mystruct">
+ <struct>
+ <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
+ <field name="mode"> <description>Are we executing kernel code</description> <typeref name="irq_mode"> </field>
+
+ <field name="teststr"><typeref name="mystruct2"></field>
+ <field name="myarray">
+ <array size="10">
+ <uint_fixed size="8">
+ </array>
+ </field>
+ <field name="mysequence">
+ <sequence>
+ <uint>
+ <float size="8">
+ </sequence>
+ </field>
+ <field name="myunion">
+ <union>
+ <field name="myfloat"><float size="8"></field>
+ <field name="myulong"><ulong></field>
+ </union>
+ </field>
+ </struct>
+ </type>
+
+
+
+
+ <event name="syscall_entry">
+ <description>System call entry</description>
+ <field name="syscall_id"> <description>Syscall entry number in entry.S</description> <uint size="1"> </field>
+ <field name="address"> <description>Address from which call was made</description> <pointer> </field>
+ </event>
+
+ <event name="syscall_exit">
+ <description>System call exit</description>
+ </event>
+
+ <event name="trap_entry">
+ <description>Entry in a trap</description>
+ <field name="trap_id"> <description>Trap number</description> <uint size="2"> </field>
+ <field name="address"> <description>Address where trap occured</description> <pointer> </field>
+ </event>
+
+ <event name="trap_exit">
+ <description>Exit from a trap</description>
+ </event>
+
+ <event name="soft_irq_entry">
+ <description>Soft IRQ entry</description>
+ <field name="softirq_id"> <description>Soft IRQ number</description> <pointer> </field>
+ </event>
+
+ <event name="soft_irq_exit">
+ <description>Soft IRQ exit</description>
+ <field name="softirq_id"> <description>Soft IRQ number</description> <pointer> </field>
+ </event>
+
+ <event name="tasklet_entry">
+ <description>Tasklet entry</description>
+ <field name="priority"> <description>Tasklet priority</description> <typeref name="tasklet_priority"> </field>
+ <field name="address"> <description>Tasklet function address</description> <pointer> </field>
+ <field name="data"> <description>Tasklet data address</description> <ulong> </field>
+ </event>
+
+ <event name="tasklet_exit">
+ <description>Tasklet exit</description>
+ <field name="priority"> <description>Tasklet priority</description> <typeref name="tasklet_priority"> </field>
+ <field name="address"> <description>Tasklet function address</description> <pointer> </field>
+ <field name="data"> <description>Tasklet data address</description> <ulong> </field>
+ </event>
+
+ <event name="irq_entry">
+ <description>Entry in an irq</description>
+ <field name="irq_id"> <description>IRQ number</description> <uint size="4"> </field>
+ <field name="mode"> <description>Are we executing kernel code</description><typeref name=""irq_mode""> </field>
+ </event>
+
+ <event name="irq_exit">
+ <description>Exit from an IRQ</description>
+ </event>
+
+ <event name="big_array">
+ <field name="myarray">
+ <array size="10000">
+ <array size="2">
+ <struct>
+ <field name="a"><pointer></field>
+ <field name="b"><union>
+ <field name="c"><pointer></field>
+ </union>
+ </field>
+ </struct>
+ </array>
+ </array>
+ </field>
+ </event>
+
+</facility>
--- /dev/null
+ifneq ($(KERNELRELEASE),)
+ifneq ($(CONFIG_LTT),)
+ obj-m := ltt-control.o ltt-statedump.o
+endif
+
+else
+ KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+ PWD := $(shell pwd)
+ KERNELRELEASE = $(shell cat $(KERNELDIR)/$(KBUILD_OUTPUT)/include/linux/version.h | sed -n 's/.*UTS_RELEASE.*\"\(.*\)\".*/\1/p')
+ifneq ($(INSTALL_MOD_PATH),)
+ DEPMOD_OPT := -b $(INSTALL_MOD_PATH)
+endif
+
+default:
+ $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
+
+modules_install:
+ $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
+ if [ -f $(KERNELDIR)/$(KBUILD_OUTPUT)/System.map ] ; then /sbin/depmod -ae -F $(KERNELDIR)/$(KBUILD_OUTPUT)/System.map $(DEPMOD_OPT) $(KERNELRELEASE) ; fi
+
+
+clean:
+ $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
+endif
--- /dev/null
+/* ltt-control.c
+ *
+ * LTT control module over a netlink socket.
+ *
+ * Inspired from Relay Apps, by Tom Zanussi and iptables
+ *
+ * Copyright 2005 -
+ * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/ltt-core.h>
+#include <linux/netlink.h>
+#include <linux/inet.h>
+#include <linux/ip.h>
+#include <linux/security.h>
+#include <linux/skbuff.h>
+#include <linux/types.h>
+#include <net/sock.h>
+#include "ltt-control.h"
+
+
+#define LTTCTLM_BASE 0x10
+#define LTTCTLM_CONTROL (LTTCTLM_BASE + 1) /* LTT control message */
+
+static struct sock *socket;
+
+void ltt_control_input(struct sock *sk, int len)
+{
+ struct sk_buff *skb;
+ struct nlmsghdr *nlh = NULL;
+ u8 *payload = NULL;
+ lttctl_peer_msg_t *msg;
+ int err;
+
+ printk(KERN_ALERT "ltt-control ltt_control_input\n");
+
+ while ((skb = skb_dequeue(&sk->sk_receive_queue))
+ != NULL) {
+
+ nlh = (struct nlmsghdr *)skb->data;
+
+ if(security_netlink_recv(skb)) {
+ netlink_ack(skb, nlh, EPERM);
+ kfree_skb(skb);
+ continue;
+ }
+
+ /* process netlink message pointed by skb->data */
+ err = EINVAL;
+ payload = NLMSG_DATA(nlh);
+ /* process netlink message with header pointed by
+ * nlh and payload pointed by payload
+ */
+ if(nlh->nlmsg_len != sizeof(lttctl_peer_msg_t) + sizeof(struct nlmsghdr)) {
+ printk(KERN_ALERT "ltt-control bad message length\n");
+ netlink_ack(skb, nlh, EINVAL);
+ kfree_skb(skb);
+ continue;
+ }
+ msg = (lttctl_peer_msg_t*)payload;
+
+ switch(msg->op) {
+ case OP_CREATE:
+ err = ltt_control(LTT_CONTROL_CREATE_TRACE, msg->trace_name,
+ msg->args);
+ break;
+ case OP_DESTROY:
+ err = ltt_control(LTT_CONTROL_DESTROY_TRACE, msg->trace_name,
+ msg->args);
+ break;
+ case OP_START:
+ err = ltt_control(LTT_CONTROL_START, msg->trace_name,
+ msg->args);
+ break;
+ case OP_STOP:
+ err = ltt_control(LTT_CONTROL_STOP, msg->trace_name,
+ msg->args);
+ break;
+ default:
+ err = EBADRQC;
+ printk(KERN_INFO "ltt-control invalid operation\n");
+ }
+ netlink_ack(skb, nlh, err);
+ kfree_skb(skb);
+ }
+}
+
+
+static int ltt_control_init(void)
+{
+ printk(KERN_ALERT "ltt-control init\n");
+
+ socket = netlink_kernel_create(NETLINK_LTT, 1,
+ ltt_control_input, THIS_MODULE);
+ if(socket == NULL) return -EPERM;
+ else return 0;
+}
+
+static void ltt_control_exit(void)
+{
+ printk(KERN_ALERT "ltt-control exit\n");
+
+ sock_release(socket->sk_socket);
+}
+
+
+module_init(ltt_control_init)
+module_exit(ltt_control_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Controller");
+
--- /dev/null
+#ifndef _LTT_CONTROL_H
+#define _LTT_CONTROL_H
+
+
+//enum trace_mode {
+// TRACE_NORMAL,
+// TRACE_FLIGHT
+//};
+
+enum trace_op {
+ OP_CREATE,
+ OP_DESTROY,
+ OP_START,
+ OP_STOP,
+ OP_ALIGN,
+ OP_NONE
+};
+
+typedef struct lttctl_peer_msg {
+ char trace_name[NAME_MAX];
+ enum trace_op op;
+ union ltt_control_args args;
+} lttctl_peer_msg_t;
+
+#endif //_LTT_CONTROL_H
+
--- /dev/null
+/* ltt-state-dump.c
+ *
+ * Lunix Trace Toolkit Kernel State Dump
+ *
+ * Copyright 2005 -
+ * Jean-Hugues Deschenes <jean-hugues.deschenes@polymtl.ca>
+ *
+ * Changes:
+ * Eric Clement: add listing of network IP interface
+ */
+
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/ltt-core.h>
+#include <linux/netlink.h>
+#include <linux/inet.h>
+#include <linux/ip.h>
+#include <linux/kthread.h>
+#include <linux/proc_fs.h>
+#include <linux/file.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/cpu.h>
+#include <linux/ltt/ltt-facility-statedump.h>
+
+#define NB_PROC_CHUNK 20
+
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
+
+/* in modules.c */
+extern int ltt_enumerate_modules(void);
+
+static inline int ltt_enumerate_network_ip_interface(void)
+{
+ struct net_device *list;
+ struct in_device *in_dev = NULL;
+ struct in_ifaddr *ifa = NULL;
+
+ read_lock(&dev_base_lock);
+ for(list=dev_base; list != NULL; list=list->next) {
+
+ if(list->flags & IFF_UP) {
+ in_dev = in_dev_get(list);
+
+ if(in_dev) {
+ for (ifa = in_dev->ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
+ trace_statedump_enumerate_network_ip_interface(list->name,
+ ifa->ifa_address,
+ LTTNG_UP);
+ }
+ in_dev_put(in_dev);
+ }
+ } else {
+ trace_statedump_enumerate_network_ip_interface(list->name,
+ 0,
+ LTTNG_DOWN);
+ }
+ }
+ read_unlock(&dev_base_lock);
+
+ return 0;
+}
+
+static inline int ltt_enumerate_file_descriptors(void)
+{
+ struct task_struct * t = &init_task;
+ unsigned int i;
+ struct file * filp;
+ char *tmp = (char*)__get_free_page(GFP_KERNEL), *path;
+ struct fdtable *fdt;
+
+ /* Enumerate active file descriptors */
+
+ do {
+ read_lock(&tasklist_lock);
+ if(t != &init_task) atomic_dec(&t->usage);
+ t = next_task(t);
+ atomic_inc(&t->usage);
+ read_unlock(&tasklist_lock);
+
+ task_lock(t);
+ if (t->files) {
+ spin_lock(&t->files->file_lock);
+ fdt = files_fdtable(t->files);
+ for (i=0; i < fdt->max_fds; i++) {
+ filp = fcheck_files(t->files, i);
+ if (!filp)
+ continue;
+ path = d_path(filp->f_dentry, filp->f_vfsmnt, tmp, PAGE_SIZE);
+
+ /* Make sure we give at least some info */
+ if(IS_ERR(path))
+ trace_statedump_enumerate_file_descriptors(filp->f_dentry->d_name.name, t->pid, i);
+ else
+ trace_statedump_enumerate_file_descriptors(path, t->pid, i);
+ }
+ spin_unlock(&t->files->file_lock);
+ }
+ task_unlock(t);
+
+ } while( t != &init_task );
+
+ free_page((unsigned long)tmp);
+
+ return 0;
+}
+
+static inline int ltt_enumerate_vm_maps(void)
+{
+ struct mm_struct *mm;
+ struct task_struct * t = &init_task;
+ struct vm_area_struct * map;
+ unsigned long ino = 0;
+
+ do {
+ read_lock(&tasklist_lock);
+ if(t != &init_task) atomic_dec(&t->usage);
+ t = next_task(t);
+ atomic_inc(&t->usage);
+ read_unlock(&tasklist_lock);
+
+ /* get_task_mm does a task_lock... */
+
+ mm = get_task_mm(t);
+
+ if (mm)
+ {
+ map = mm->mmap;
+
+ if(map)
+ {
+ down_read(&mm->mmap_sem);
+
+ while (map) {
+ if (map->vm_file) {
+ ino = map->vm_file->f_dentry->d_inode->i_ino;
+ } else {
+ ino = 0;
+ }
+
+ trace_statedump_enumerate_vm_maps(t->pid, (void *)map->vm_start, (void *)map->vm_end, map->vm_flags, map->vm_pgoff << PAGE_SHIFT, ino);
+ map = map->vm_next;
+ }
+
+ up_read(&mm->mmap_sem);
+ }
+
+ mmput(mm);
+ }
+
+ } while( t != &init_task );
+
+ return 0;
+}
+
+#if defined( CONFIG_ARM )
+/* defined in arch/arm/kernel/irq.c because of dependency on statically-defined lock & irq_desc */
+int ltt_enumerate_interrupts(void);
+#else
+static inline int ltt_enumerate_interrupts(void)
+{
+ unsigned int i;
+ unsigned long flags = 0;
+
+ /* needs irq_desc */
+
+ for(i = 0; i < NR_IRQS; i++)
+ {
+ struct irqaction * action;
+
+ spin_lock_irqsave(&irq_desc[i].lock, flags);
+
+
+ for (action=irq_desc[i].action; action; action = action->next)
+ trace_statedump_enumerate_interrupts(
+ irq_desc[i].handler->typename,
+ action->name,
+ i );
+
+ spin_unlock_irqrestore(&irq_desc[i].lock, flags);
+ }
+
+ return 0;
+}
+#endif
+
+static inline int ltt_enumerate_process_states(void)
+{
+ struct task_struct * t = &init_task;
+ struct task_struct * p = t;
+ enum lttng_process_status status;
+ enum lttng_thread_type type;
+ enum lttng_execution_mode mode;
+ enum lttng_execution_submode submode;
+
+ do {
+ mode = LTTNG_MODE_UNKNOWN;
+ submode = LTTNG_UNKNOWN;
+
+ read_lock(&tasklist_lock);
+ if(t != &init_task) {
+ atomic_dec(&t->usage);
+ t = next_thread(t);
+ }
+ if(t == p) {
+ t = p = next_task(t);
+ }
+ atomic_inc(&t->usage);
+ read_unlock(&tasklist_lock);
+
+ task_lock(t);
+
+ if(t->exit_state == EXIT_ZOMBIE)
+ status = LTTNG_ZOMBIE;
+ else if(t->exit_state == EXIT_DEAD)
+ status = LTTNG_DEAD;
+ else if(t->state == TASK_RUNNING)
+ {
+ /* Is this a forked child that has not run yet? */
+ if( list_empty(&t->run_list) )
+ {
+ status = LTTNG_WAIT_FORK;
+ }
+ else
+ {
+ /* All tasks are considered as wait_cpu; the viewer will sort out if the task was relly running at this time. */
+ status = LTTNG_WAIT_CPU;
+ }
+ }
+ else if(t->state & (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE))
+ {
+ /* Task is waiting for something to complete */
+ status = LTTNG_WAIT;
+ }
+ else
+ status = LTTNG_UNNAMED;
+
+ submode = LTTNG_NONE;
+
+
+ /* Verification of t->mm is to filter out kernel threads;
+ Viewer will further filter out if a user-space thread was in syscall mode or not */
+ if(t->mm)
+ type = LTTNG_USER_THREAD;
+ else
+ type = LTTNG_KERNEL_THREAD;
+
+ trace_statedump_enumerate_process_state(t->pid, t->parent->pid, t->comm,
+ type, mode, submode, status);
+
+ task_unlock(t);
+
+ } while( t != &init_task );
+
+ return 0;
+}
+
+void ltt_statedump_work_func(void *sem)
+{
+ /* Our job is just to release the semaphore so
+ that we are sure that each CPU has been in syscall
+ mode before the end of ltt_statedump_thread */
+ up((struct semaphore *)sem);
+}
+
+static struct work_struct cpu_work[NR_CPUS];
+
+int ltt_statedump_thread(void *data)
+{
+ struct semaphore work_sema4;
+ int cpu;
+
+ printk("ltt_statedump_thread\n");
+
+ ltt_enumerate_process_states();
+
+ ltt_enumerate_file_descriptors();
+
+ ltt_enumerate_modules();
+
+ ltt_enumerate_vm_maps();
+
+ ltt_enumerate_interrupts();
+
+ ltt_enumerate_network_ip_interface();
+
+ /* Fire off a work queue on each CPU. Their sole purpose in life
+ * is to guarantee that each CPU has been in a state where is was in syscall
+ * mode (i.e. not in a trap, an IRQ or a soft IRQ) */
+ sema_init(&work_sema4, 1 - num_online_cpus());
+
+ lock_cpu_hotplug();
+ for_each_online_cpu(cpu)
+ {
+ INIT_WORK(&cpu_work[cpu], ltt_statedump_work_func, &work_sema4);
+
+ schedule_delayed_work_on(cpu,&cpu_work[cpu],0);
+ }
+ unlock_cpu_hotplug();
+
+ /* Wait for all work queues to have completed */
+ down(&work_sema4);
+
+ /* Our work is done */
+ printk("trace_statedump_statedump_end\n");
+ trace_statedump_statedump_end();
+
+ do_exit(0);
+
+ return 0;
+}
+
+int ltt_statedump_start(struct ltt_trace_struct *trace)
+{
+ printk("ltt_statedump_start\n");
+
+ kthread_run( ltt_statedump_thread,
+ NULL,
+ "ltt_statedump");
+
+ return 0;
+}
+
+
+/* Dynamic facility. */
+
+static int __init statedump_init(void)
+{
+ int ret;
+ printk(KERN_INFO "LTT : ltt-facility-statedump init\n");
+
+ ret = ltt_module_register(LTT_FUNCTION_STATEDUMP,
+ ltt_statedump_start,THIS_MODULE);
+
+ return ret;
+}
+
+static void __exit statedump_exit(void)
+{
+ ltt_module_unregister(LTT_FUNCTION_STATEDUMP);
+}
+
+module_init(statedump_init)
+module_exit(statedump_exit)
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jean-Hugues Deschenes");
+MODULE_DESCRIPTION("Linux Trace Toolkit Statedump");
+
--- /dev/null
+
+CC=gcc
+INCLUDE_DIR?=/usr/include
+LIB_DIR?=/usr/lib
+RANLIB=ranlib
+
+LTT_CFLAGS=-I. -O2 -L. -fPIC
+# note : x86_64 needs -fPIC ? FIXME
+
+#For testing lib ltt-usertrace-fast
+#CFLAGS+=-DLTT_SUBBUF_SIZE_CPU=134217728
+#CFLAGS+=-DLTT_NULL_OUTPUT_TEST
+
+all: libs samples
+
+#SAMPLE PROGRAMS
+
+samples: sample sample-highspeed sample-printf \
+ sample-instrument-fct sample-thread-slow sample-thread-fast sample-thread-brand sample-block
+
+sample: sample.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
+sample-block: sample-block.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
+
+sample-thread-brand: sample-thread-brand.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
+
+sample-highspeed: sample-highspeed.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-usertrace-fast -lltt-loader-user_generic -o $@ $^
+
+sample-printf: sample-printf.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^
+
+sample-instrument-fct: sample-instrument-fct.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -g -finstrument-functions -lltt-instrument-functions -o $@ $^
+
+sample-thread-slow: sample-thread-slow.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -lltt-loader-user_generic -o $@ $^
+
+sample-thread-fast: sample-thread-fast.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -lltt-usertrace-fast -lltt-loader-user_generic -o $@ $^
+
+
+#LIBRAIRIES
+
+libs: libltt-instrument-functions.a libltt-instrument-functions.so.0 \
+ libltt-usertrace-fast.a libltt-usertrace-fast.so.0 \
+ libltt-loader-user_generic.a libltt-loader-user_generic.so.0
+
+libltt-usertrace-fast.a: ltt-usertrace-fast.o
+ @rm -f libltt-usertrace-fast.a
+ $(AR) rc $@ $^
+ $(RANLIB) $@
+
+libltt-usertrace-fast.so.0: ltt-usertrace-fast.o
+ @rm -f libltt-usertrace-fast.so libltt-usertrace-fast.so.0
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-usertrace-fast.so -o $@ $^
+ ln -s libltt-usertrace-fast.so.0 libltt-usertrace-fast.so
+
+libltt-instrument-functions.a: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
+ @rm -f libltt-instrument-functions.a
+ $(AR) rc $@ $^
+ $(RANLIB) $@
+
+libltt-instrument-functions.so.0: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
+ @rm -f libltt-instrument-functions.so libltt-instrument-functions.so.0
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-instrument-functions.so -o $@ $^
+ ln -s libltt-instrument-functions.so.0 libltt-instrument-functions.so
+
+libltt-loader-user_generic.a: ltt-facility-loader-user_generic.o
+ @rm -f libltt-loader-user_generic.a
+ $(AR) rc $@ $^
+ $(RANLIB) $@
+
+libltt-loader-user_generic.so.0: ltt-facility-loader-user_generic.o
+ @rm -f libltt-loader-user_generic.so libltt-loader-user_generic.so.0
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-loader-user_generic.so -o $@ $^
+ ln -s libltt-loader-user_generic.so.0 libltt-loader-user_generic.so
+
+%.o: %.c
+ $(CC) $(LTT_CFLAGS) $(CFLAGS) -c -o $@ $+
+
+.PHONY : clean install libs install_libs install_headers samples
+
+install_headers:
+ if [ ! -e "$(INCLUDE_DIR)/ltt" ] ; then mkdir $(INCLUDE_DIR)/ltt ; fi
+ cp -f ltt/*.h $(INCLUDE_DIR)/ltt
+
+install_libs:
+ cp -df libltt-instrument-functions.so* libltt-instrument-functions.a $(LIB_DIR)
+ cp -df libltt-usertrace-fast.so* libltt-usertrace-fast.a $(LIB_DIR)
+ cp -df libltt-loader-user_generic.so* libltt-loader-user_generic.a $(LIB_DIR)
+
+install: install_headers libs install_libs
+
+clean:
+ find . -name \*~ | xargs rm -fr *.o sample-thread sample sample-highspeed sample-printf sample-instrument-fct libltt-instrument-functions.so* libltt-instrument-functions.a libltt-usertrace-fast.a libltt-usertrace-fast.so* libltt-loader-user_generic.so* libltt-loader-user_generic.a sample-thread-slow sample-thread-fast sample-thread-brand sample-block java/*.class java/Sample.h java/TestBrand.h
--- /dev/null
+
+LTTng usertrace package
+
+Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+March 2006
+
+This package contains all the user space headers and c files necessary to make
+your application and library trace through an active LTTng tracer. Here is a
+short quickstart guide of it.
+
+Here are the currently supported architectures :
+x86
+(please add the ltt_trace_generic and ltt_register_generic system calls to
+other architectures as you need them : it will work magically)
+
+* Compile your kernel with the latest LTTng patch. Make sure the option
+ "Allow tracing from userspace" is _active_!
+ See the QUICKSTART guide at http://ltt.polymtl.ca/ for details about how to
+ setup a working tracer and viewer. See the genevent installation step : it is
+ required for method #2 below.
+
+* Extract the latest ltt-usertrace archive :
+su
+cd /usr/src
+wget http://ltt.polymtl.ca/packages/ltt-usertrace-x.x.tar.gz
+gzip -cd ltt-usertrace-x.x.tar.gz | tar xvof -
+
+* Build the sample programs and install the headers and librairies into your
+system :
+(32 bits)
+su
+cd /usr/src/ltt-usertrace
+make clean
+make install (will build and install headers and libraries)
+make
+(64 bits)
+su
+cd /usr/src/ltt-usertrace
+make clean
+LIB_DIR=/usr/lib64 make install CFLAGS=-m64
+make CFLAGS=-m64
+
+Feel free to look at the sample programs and the Makefile : they demonstrate
+very well the features of the usertrace package and how to use them.
+
+* There are three ways to trace information from your application. The choice
+ will principally depend on the trace data rate.
+
+1) Easy way, but slow (printf style)
+ See sample-printf.c for code example.
+
+- Add the following statements to your program source (the define must come
+ _before_ the includes!) :
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+#include <ltt/ltt-facility-custom-user_generic.h>
+
+Note the define of LTT_BLOCKING to 1 : if a trace buffer is full, your
+application will block. The default of this parameter is 0 (non blocking) :
+events are lost when trace buffer is full. The choice is up to you.
+
+- Add something like the following sample line in your code. Note that this is a
+ very standard format string, this is only a suggested presentation.
+
+trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
+ __FILE__, __func__, __LINE__, count);
+
+- Compile your application with at least these parameters to gcc (it is splitted
+ on two lines, joined by a "\") :
+gcc -D LTT_SHOW_DEBUG -I /usr/src/usertrace-generic -o myapp myapp.c \
+ /usr/src/usertrace-generic/ltt-facility-loader-user_generic.c
+
+To see what the final result looks like :
+- Start tracing
+- Start your application
+ ** You should see the following message when your program starts and the
+ LTT_SHOW_DEBUG is defined :
+ "LTT : ltt-facility-user_generic init in userspace"
+ If you don't then you forgot to compile the facility loader in your
+ application. If you find this output annoying, you can remove the
+ "-D LTT_SHOW_DEBUG" gcc parameter, which will make the facility loader
+ silent.
+- Stop tracing
+Then, to see only the user_generic events :
+lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic"
+
+It will show :
+user_generic.slow_printf: 35885.922829472 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 0." }
+user_generic.slow_printf: 35886.925685289 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 1." }
+...
+
+
+
+2) The second way to log events is still easy. The advantage is that it
+ will make it easier to identify your data in the trace viewer afterward.
+ Please read the comments in method 1) explained previously, as they
+ are not repeated here.
+ See sample.c and sample-thread-slow.c for code example.
+
+- Go to the ltt-usertrace directory
+su
+cd /usr/src/ltt-usertrace
+
+- Create your own facility (i.e. user_myfacility.xml).
+ See the ones available in /usr/share/LinuxTraceToolkitViewer/facilities for
+ examples.
+ You facility _must_ be named following this standard : "user_*", where * is
+ whatever you like. If it is not, it will be rejected by the kernel with a
+ Operation not permitted (can be seen with the -D LTT_SHOW_DEBUG compilation
+ parameter).
+
+user_myfacility.xml:
+
+<?xml version="1.0"?>
+<facility name="user_myfacility">
+ <description>Sample facility</description>
+ <event name="myevent">
+ <description>Sample event</description>
+ <field name="file"><string></field>
+ <field name="function"><string></field>
+ <field name="line"><int></field>
+ <field name="firstval"><long></field>
+ <field name="secondval"><pointer></field>
+ </event>
+</facility>
+
+- AN IMPORTANT STEP FOLLOWS :
+ *copy* the user_myfacility.xml file in your system :
+su
+cp user_myfacility.xml /usr/share/LinuxTraceToolkitViewer/facilities
+
+- Use genevent to create the c code and headers :
+su
+cd /tmp
+mkdir genevent
+cd genevent
+for a in /usr/share/LinuxTraceToolkitViewer/facilities/user_*.xml;
+ do /usr/local/bin/genevent $a;
+done
+cd /usr/src/usertrace-generic
+cp /tmp/genevent/*load* .
+cd ltt
+cp /tmp/genevent/ltt-facility-id-user_myfacility.h .
+cp /tmp/genevent/ltt-facility-user_myfacility.h .
+cd ..
+make install
+
+- Add the following statements to your program source (the define must come
+ _before_ the includes!) :
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_myfacility.h>
+
+- Add a call following the trace_user_myfacility_myevent function found in
+ /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
+For instance :
+trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
+
+- Compile your application with at least these parameters to gcc (it is splitted
+ on two lines, joined by a "\") :
+gcc -I /usr/src/usertrace-generic -o myapp myapp.c \
+ /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
+
+To see what the final result looks like :
+- Start tracing
+- Start your application
+- Stop tracing
+Then, to see only the user_myfacility events :
+lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
+
+It will show, for example :
+user_myfacility.myevent: 39507.805584526 (/cpu_1), 15829, 15736, SYSCALL { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
+
+
+3) The third way to trace information from your application
+
+This method is cleary the _FASTEST_. It is principally I/O (disk and memory)
+bound. It will create a companion process for each of you program's thread which
+will dump the tracing information into /tmp/ltt-usertrace.
+
+See sample-highspeed.c and sample-thread-fast.c for code example.
+
+- Add the following statements to your program source (the define must come
+ _before_ the includes!) :
+
+#define LTT_TRACE
+#define LTT_TRACE_FAST
+#include <ltt/ltt-facility-user_myfacility.h>
+
+- Add a call following the trace_user_myfacility_myevent function found in
+ /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
+For instance :
+trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
+
+- Compile your application with at least these parameters to gcc (it is splitted
+ on two lines, joined by a "\") :
+gcc -lltt-usertrace-fast -I /usr/src/usertrace-generic -o myapp myapp.c \
+ /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
+
+It requires a supplementary operation when you take the trace :
+- Start tracing (with lttctl)
+- Start your application
+- Let your application run...
+- Stop tracing
+- Move or copy /tmp/ltt-usertrace info your trace.
+i.e., if your trace is in /tmp/trace1 :
+su
+mv /tmp/ltt-usertrace /tmp/trace1
+
+
+Then, to see only the user_myfacility events :
+lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
+
+It will show, for example :
+user_myfacility.myevent: 39507.805584526 (/ltt-usertrace/process-26174.26174.39236180500380_0), 15829, 15736, USER_MODE { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
+
+
+
+* Fun feature : function instrumentation
+
+Here is how to generate a full trace of you program function calls.
+See the sample-instrument-fct.c example program.
+
+- Compile your application with at least these parameters to gcc (it is splitted
+ on two lines, joined by a "\") :
+gcc -g -finstrument-functions \
+ -lltt-instrument-functions -o myapp myapp.c
+
+To see what the final result looks like :
+- Start tracing
+- Start your application
+- Stop tracing
+Then, to see only the function_entry and function_exit events :
+lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic & (event.name=function_entry & event.name=function_exit)"
+
+It will show, for example :
+user_generic.function_entry: 59329.709939111 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
+user_generic.function_exit: 59329.709944613 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
+
+you can then use (from the binutils package)
+addr2line -e sample-instrument-fct -i -f 0x8048454
+Which shows :
+test_function
+/usr/src/usertrace-generic/sample-instrument-fct.c:12
+
+The lookup in LTTV through libbfd has not been implemented yet.
+
+
+* Instrumentation of a java program
+
+See the java/ directory of this package. You will have to create a C library
+that holds the tracing functions, following the java-instrument-string.c. It has
+to be called from the Java code as shown in Sample.java.
+
+The generate.sh scripts compiles and executes the Java program with the JNI
+tracing library.
+
--- /dev/null
+// The Sample.java file
+public class Sample
+{
+ // Declaration of the Native (C) function
+ private static native void trace_java_generic_string(String arg);
+ static {
+ System.loadLibrary("ltt-java-string");
+ }
+
+ public static void main(String[] args)
+ {
+ Sample.trace_java_generic_string("Tracing from java");
+ }
+}
--- /dev/null
+
+import ltt.*;
+
+// The Sample.java file
+public class TestBrand
+{
+ public static void main(String[] args)
+ {
+ ltt.ThreadBrand.trace_java_generic_thread_brand("Brand_test");
+ }
+}
--- /dev/null
+
+package ltt;
+
+// The ThreadBrand.java file
+public class ThreadBrand
+{
+ // Declaration of the Native (C) function
+ public static native void trace_java_generic_thread_brand(String arg);
+ static {
+ System.loadLibrary("ltt-java-thread_brand");
+ }
+}
--- /dev/null
+#!/bin/sh
+
+export CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/bin
+
+#Sample
+javac Sample.java
+javah -jni Sample
+gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \
+ -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \
+ -shared -Wl,-soname,libltt-java-string \
+ -o libltt-java-string.so ltt-java-string.c \
+ ../ltt-facility-loader-user_generic.c
+LD_LIBRARY_PATH=. java Sample
+
+#TestBrand
+echo javac Threadbrand
+javac -d . ThreadBrand.java
+echo javah Threadbrand
+javah -jni ltt.ThreadBrand
+echo gcc
+gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \
+ -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \
+ -shared -Wl,-soname,libltt-java-thread_brand \
+ -o libltt-java-thread_brand.so ltt-java-thread_brand.c \
+ ../ltt-facility-loader-user_generic.c
+echo javac test
+javac TestBrand.java
+echo run
+LD_LIBRARY_PATH=. java TestBrand
--- /dev/null
+
+#include <jni.h>
+#include "Sample.h"
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+JNIEXPORT void JNICALL Java_Sample_trace_1java_1generic_1string
+ (JNIEnv *env, jobject obj, jstring jstr)
+{
+ const char *str;
+ str = (*env)->GetStringUTFChars(env, jstr, NULL);
+ if (str == NULL) return; // out of memory error thrown
+ trace_user_generic_string(str);
+ (*env)->ReleaseStringUTFChars(env, jstr, str);
+}
+
--- /dev/null
+
+#include <jni.h>
+#include "Sample.h"
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+JNIEXPORT void JNICALL Java_ltt_ThreadBrand_trace_1java_1generic_1thread_1brand
+ (JNIEnv *env, jclass jc, jstring jstr)
+{
+ const char *str;
+ str = (*env)->GetStringUTFChars(env, jstr, NULL);
+ if (str == NULL) return; // out of memory error thrown
+ trace_user_generic_thread_brand(str);
+ (*env)->ReleaseStringUTFChars(env, jstr, str);
+}
+
--- /dev/null
+/*
+ * ltt-facility-loader-user_generic.c
+ *
+ * (C) Copyright 2005 -
+ * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
+ *
+ * Contains the LTT user space facility loader.
+ *
+ */
+
+
+#define LTT_TRACE
+#include <error.h>
+#include <stdio.h>
+#include <ltt/ltt-usertrace.h>
+#include "ltt-facility-loader-user_generic.h"
+
+static struct user_facility_info facility = {
+ .name = LTT_FACILITY_NAME,
+ .num_events = LTT_FACILITY_NUM_EVENTS,
+#ifndef LTT_PACK
+ .alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,
+#else
+ .alignment = 0,
+#endif //LTT_PACK
+ .checksum = LTT_FACILITY_CHECKSUM,
+ .int_size = sizeof(int),
+ .long_size = sizeof(long),
+ .pointer_size = sizeof(void*),
+ .size_t_size = sizeof(size_t)
+};
+
+static void __attribute__((constructor)) __ltt_user_init(void)
+{
+ int err;
+#ifdef LTT_SHOW_DEBUG
+ printf("LTT : ltt-facility-user_generic init in userspace\n");
+#endif //LTT_SHOW_DEBUG
+
+ err = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);
+ LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
+
+ if (err) {
+#ifdef LTT_SHOW_DEBUG
+ perror("Error in ltt_register_generic");
+#endif //LTT_SHOW_DEBUG
+ }
+}
+
--- /dev/null
+#ifndef _LTT_FACILITY_LOADER_USER_GENERIC_H_
+#define _LTT_FACILITY_LOADER_USER_GENERIC_H_
+
+#include <ltt/ltt-usertrace.h>
+#include <ltt/ltt-facility-id-user_generic.h>
+
+ltt_facility_t ltt_facility_user_generic;
+ltt_facility_t ltt_facility_user_generic_B1865E44;
+
+#define LTT_FACILITY_SYMBOL ltt_facility_user_generic
+#define LTT_FACILITY_CHECKSUM_SYMBOL ltt_facility_user_generic_B1865E44
+#define LTT_FACILITY_CHECKSUM 0xB1865E44
+#define LTT_FACILITY_NAME "user_generic"
+#define LTT_FACILITY_NUM_EVENTS facility_user_generic_num_events
+
+#define LTT_FACILITY_ALIGNMENT 1
+
+#endif //_LTT_FACILITY_LOADER_USER_GENERIC_H_
--- /dev/null
+/****************************************************************************
+ * ltt-instrument-functions.c
+ *
+ * Mathieu Desnoyers
+ * March 2006
+ */
+
+#define inline inline __attribute__((always_inline))
+
+#define LTT_TRACE
+#define LTT_TRACE_FAST
+#include <ltt/ltt-usertrace-fast.h>
+#include <ltt/ltt-facility-user_generic.h>
+
+void __attribute__((no_instrument_function)) __cyg_profile_func_enter (
+ void *this_fn,
+ void *call_site)
+{
+ /* don't care about the return value */
+ trace_user_generic_function_entry(this_fn, call_site);
+}
+
+void __attribute__((no_instrument_function)) __cyg_profile_func_exit (
+ void *this_fn,
+ void *call_site)
+{
+ /* don't care about the return value */
+ trace_user_generic_function_exit(this_fn, call_site);
+}
+
--- /dev/null
+/* LTTng user-space "fast" library
+ *
+ * This daemon is spawned by each traced thread (to share the mmap).
+ *
+ * Its job is to dump periodically this buffer to disk (when it receives a
+ * SIGUSR1 from its parent).
+ *
+ * It uses the control information in the shared memory area (producer/consumer
+ * count).
+ *
+ * When the parent thread dies (yes, those thing may happen) ;) , this daemon
+ * will flush the last buffer and write it to disk.
+ *
+ * Supplement note for streaming : the daemon is responsible for flushing
+ * periodically the buffer if it is streaming data.
+ *
+ *
+ * Notes :
+ * shm memory is typically limited to 4096 units (system wide limit SHMMNI in
+ * /proc/sys/kernel/shmmni). As it requires computation time upon creation, we
+ * do not use it : we will use a shared mmap() instead which is passed through
+ * the fork().
+ * MAP_SHARED mmap segment. Updated when msync or munmap are called.
+ * MAP_ANONYMOUS.
+ * Memory mapped by mmap() is preserved across fork(2), with the same
+ * attributes.
+ *
+ * Eventually, there will be two mode :
+ * * Slow thread spawn : a fork() is done for each new thread. If the process
+ * dies, the data is not lost.
+ * * Fast thread spawn : a pthread_create() is done by the application for each
+ * new thread.
+ *
+ * We use a timer to check periodically if the parent died. I think it is less
+ * intrusive than a ptrace() on the parent, which would get every signal. The
+ * side effect of this is that we won't be notified if the parent does an
+ * exec(). In this case, we will just sit there until the parent exits.
+ *
+ *
+ * Copyright 2006 Mathieu Desnoyers
+ *
+ */
+
+#define inline inline __attribute__((always_inline))
+
+#define _GNU_SOURCE
+#define LTT_TRACE
+#define LTT_TRACE_FAST
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+#include <syscall.h>
+#include <features.h>
+#include <pthread.h>
+#include <malloc.h>
+#include <string.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include <ltt/ltt-usertrace.h>
+
+#define gettid() syscall(__NR_gettid)
+
+#ifdef LTT_SHOW_DEBUG
+#define dbg_printf(...) printf(__VA_ARGS__)
+#else
+#define dbg_printf(...)
+#endif //LTT_SHOW_DEBUG
+
+
+enum force_switch_mode { FORCE_ACTIVE, FORCE_FLUSH };
+
+/* Writer (the traced application) */
+
+__thread struct ltt_trace_info *thread_trace_info = NULL;
+
+void ltt_usertrace_fast_buffer_switch(void)
+{
+ struct ltt_trace_info *tmp = thread_trace_info;
+ if(tmp)
+ kill(tmp->daemon_id, SIGUSR1);
+}
+
+/* The cleanup should never be called from a signal handler */
+static void ltt_usertrace_fast_cleanup(void *arg)
+{
+ struct ltt_trace_info *tmp = thread_trace_info;
+ if(tmp) {
+ thread_trace_info = NULL;
+ kill(tmp->daemon_id, SIGUSR2);
+ munmap(tmp, sizeof(*tmp));
+ }
+}
+
+/* Reader (the disk dumper daemon) */
+
+static pid_t traced_pid = 0;
+static pid_t traced_tid = 0;
+static int parent_exited = 0;
+static int fd_process = -1;
+static char outfile_name[PATH_MAX];
+static char identifier_name[PATH_MAX];
+
+/* signal handling */
+static void handler_sigusr1(int signo)
+{
+ dbg_printf("LTT Signal %d received : parent buffer switch.\n", signo);
+}
+
+static void handler_sigusr2(int signo)
+{
+ dbg_printf("LTT Signal %d received : parent exited.\n", signo);
+ parent_exited = 1;
+}
+
+static void handler_sigalarm(int signo)
+{
+ dbg_printf("LTT Signal %d received\n", signo);
+
+ if(getppid() != traced_pid) {
+ /* Parent died */
+ dbg_printf("LTT Parent %lu died, cleaning up\n", traced_pid);
+ traced_pid = 0;
+ }
+ alarm(3);
+}
+
+/* Do a buffer switch. Don't switch if buffer is completely empty */
+static void flush_buffer(struct ltt_buf *ltt_buf, enum force_switch_mode mode)
+{
+ uint64_t tsc;
+ int offset_begin, offset_end, offset_old;
+ int reserve_commit_diff;
+ int consumed_old, consumed_new;
+ int commit_count, reserve_count;
+ int end_switch_old;
+
+ do {
+ offset_old = atomic_read(<t_buf->offset);
+ offset_begin = offset_old;
+ end_switch_old = 0;
+ tsc = ltt_get_timestamp();
+ if(tsc == 0) {
+ /* Error in getting the timestamp : should not happen : it would
+ * mean we are called from an NMI during a write seqlock on xtime. */
+ return;
+ }
+
+ if(SUBBUF_OFFSET(offset_begin, ltt_buf) != 0) {
+ offset_begin = SUBBUF_ALIGN(offset_begin, ltt_buf);
+ end_switch_old = 1;
+ } else {
+ /* we do not have to switch : buffer is empty */
+ return;
+ }
+ if(mode == FORCE_ACTIVE)
+ offset_begin += ltt_subbuf_header_len(ltt_buf);
+ /* Always begin_switch in FORCE_ACTIVE mode */
+
+ /* Test new buffer integrity */
+ reserve_commit_diff =
+ atomic_read(
+ <t_buf->reserve_count[SUBBUF_INDEX(offset_begin, ltt_buf)])
+ - atomic_read(
+ <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
+ if(reserve_commit_diff == 0) {
+ /* Next buffer not corrupted. */
+ if(mode == FORCE_ACTIVE
+ && (offset_begin-atomic_read(<t_buf->consumed))
+ >= ltt_buf->alloc_size) {
+ /* We do not overwrite non consumed buffers and we are full : ignore
+ switch while tracing is active. */
+ return;
+ }
+ } else {
+ /* Next subbuffer corrupted. Force pushing reader even in normal mode */
+ }
+
+ offset_end = offset_begin;
+ } while(atomic_cmpxchg(<t_buf->offset, offset_old, offset_end)
+ != offset_old);
+
+
+ if(mode == FORCE_ACTIVE) {
+ /* Push the reader if necessary */
+ do {
+ consumed_old = atomic_read(<t_buf->consumed);
+ /* If buffer is in overwrite mode, push the reader consumed count if
+ the write position has reached it and we are not at the first
+ iteration (don't push the reader farther than the writer).
+ This operation can be done concurrently by many writers in the
+ same buffer, the writer being at the fartest write position sub-buffer
+ index in the buffer being the one which will win this loop. */
+ /* If the buffer is not in overwrite mode, pushing the reader only
+ happen if a sub-buffer is corrupted */
+ if((SUBBUF_TRUNC(offset_end-1, ltt_buf)
+ - SUBBUF_TRUNC(consumed_old, ltt_buf))
+ >= ltt_buf->alloc_size)
+ consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
+ else {
+ consumed_new = consumed_old;
+ break;
+ }
+ } while(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
+ != consumed_old);
+
+ if(consumed_old != consumed_new) {
+ /* Reader pushed : we are the winner of the push, we can therefore
+ reequilibrate reserve and commit. Atomic increment of the commit
+ count permits other writers to play around with this variable
+ before us. We keep track of corrupted_subbuffers even in overwrite
+ mode :
+ we never want to write over a non completely committed sub-buffer :
+ possible causes : the buffer size is too low compared to the unordered
+ data input, or there is a writer who died between the reserve and the
+ commit. */
+ if(reserve_commit_diff) {
+ /* We have to alter the sub-buffer commit count : a sub-buffer is
+ corrupted */
+ atomic_add(reserve_commit_diff,
+ <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
+ atomic_inc(<t_buf->corrupted_subbuffers);
+ }
+ }
+ }
+
+ /* Always switch */
+
+ if(end_switch_old) {
+ /* old subbuffer */
+ /* Concurrency safe because we are the last and only thread to alter this
+ sub-buffer. As long as it is not delivered and read, no other thread can
+ alter the offset, alter the reserve_count or call the
+ client_buffer_end_callback on this sub-buffer.
+ The only remaining threads could be the ones with pending commits. They
+ will have to do the deliver themself.
+ Not concurrency safe in overwrite mode. We detect corrupted subbuffers with
+ commit and reserve counts. We keep a corrupted sub-buffers count and push
+ the readers across these sub-buffers.
+ Not concurrency safe if a writer is stalled in a subbuffer and
+ another writer switches in, finding out it's corrupted. The result will be
+ than the old (uncommited) subbuffer will be declared corrupted, and that
+ the new subbuffer will be declared corrupted too because of the commit
+ count adjustment.
+ Offset old should never be 0. */
+ ltt_buffer_end_callback(ltt_buf, tsc, offset_old,
+ SUBBUF_INDEX((offset_old), ltt_buf));
+ /* Setting this reserve_count will allow the sub-buffer to be delivered by
+ the last committer. */
+ reserve_count = atomic_add_return((SUBBUF_OFFSET((offset_old-1),
+ ltt_buf) + 1),
+ <t_buf->reserve_count[SUBBUF_INDEX((offset_old),
+ ltt_buf)]);
+ if(reserve_count == atomic_read(
+ <t_buf->commit_count[SUBBUF_INDEX((offset_old), ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_old), ltt_buf), NULL);
+ }
+ }
+
+ if(mode == FORCE_ACTIVE) {
+ /* New sub-buffer */
+ /* This code can be executed unordered : writers may already have written
+ to the sub-buffer before this code gets executed, caution. */
+ /* The commit makes sure that this code is executed before the deliver
+ of this sub-buffer */
+ ltt_buffer_begin_callback(ltt_buf, tsc, SUBBUF_INDEX(offset_begin, ltt_buf));
+ commit_count = atomic_add_return(ltt_subbuf_header_len(ltt_buf),
+ <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
+ /* Check if the written buffer has to be delivered */
+ if(commit_count == atomic_read(
+ <t_buf->reserve_count[SUBBUF_INDEX(offset_begin, ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_begin, ltt_buf), NULL);
+ }
+ }
+
+}
+
+
+static int open_output_files(void)
+{
+ int ret;
+ int fd;
+ /* Open output files */
+ umask(00000);
+ ret = mkdir(LTT_USERTRACE_ROOT, 0777);
+ if(ret < 0 && errno != EEXIST) {
+ perror("LTT Error in creating output (mkdir)");
+ exit(-1);
+ }
+ ret = chdir(LTT_USERTRACE_ROOT);
+ if(ret < 0) {
+ perror("LTT Error in creating output (chdir)");
+ exit(-1);
+ }
+ snprintf(identifier_name, PATH_MAX-1, "%lu.%lu.%llu",
+ traced_tid, traced_pid, get_cycles());
+ snprintf(outfile_name, PATH_MAX-1, "process-%s", identifier_name);
+
+#ifndef LTT_NULL_OUTPUT_TEST
+ fd = creat(outfile_name, 0644);
+#else
+ /* NULL test */
+ ret = symlink("/dev/null", outfile_name);
+ if(ret < 0) {
+ perror("error in symlink");
+ exit(-1);
+ }
+ fd = open(outfile_name, O_WRONLY);
+ if(fd_process < 0) {
+ perror("Error in open");
+ exit(-1);
+ }
+#endif //LTT_NULL_OUTPUT_TEST
+ return fd;
+}
+
+static inline int ltt_buffer_get(struct ltt_buf *ltt_buf,
+ unsigned int *offset)
+{
+ unsigned int consumed_old, consumed_idx;
+ consumed_old = atomic_read(<t_buf->consumed);
+ consumed_idx = SUBBUF_INDEX(consumed_old, ltt_buf);
+
+ if(atomic_read(<t_buf->commit_count[consumed_idx])
+ != atomic_read(<t_buf->reserve_count[consumed_idx])) {
+ return -EAGAIN;
+ }
+ if((SUBBUF_TRUNC(atomic_read(<t_buf->offset), ltt_buf)
+ -SUBBUF_TRUNC(consumed_old, ltt_buf)) == 0) {
+ return -EAGAIN;
+ }
+
+ *offset = consumed_old;
+
+ return 0;
+}
+
+static inline int ltt_buffer_put(struct ltt_buf *ltt_buf,
+ unsigned int offset)
+{
+ unsigned int consumed_old, consumed_new;
+ int ret;
+
+ consumed_old = offset;
+ consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
+ if(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
+ != consumed_old) {
+ /* We have been pushed by the writer : the last buffer read _is_
+ * corrupted!
+ * It can also happen if this is a buffer we never got. */
+ return -EIO;
+ } else {
+ if(traced_pid == 0 || parent_exited) return 0;
+
+ ret = sem_post(<t_buf->writer_sem);
+ if(ret < 0) {
+ printf("error in sem_post");
+ }
+ }
+ return ret;
+}
+
+static int read_subbuffer(struct ltt_buf *ltt_buf, int fd)
+{
+ unsigned int consumed_old;
+ int err;
+ dbg_printf("LTT read buffer\n");
+
+
+ err = ltt_buffer_get(ltt_buf, &consumed_old);
+ if(err != 0) {
+ if(err != -EAGAIN) dbg_printf("LTT Reserving sub buffer failed\n");
+ goto get_error;
+ }
+ if(fd_process == -1) {
+ fd_process = fd = open_output_files();
+ }
+
+ err = TEMP_FAILURE_RETRY(write(fd,
+ ltt_buf->start
+ + (consumed_old & ((ltt_buf->alloc_size)-1)),
+ ltt_buf->subbuf_size));
+
+ if(err < 0) {
+ perror("Error in writing to file");
+ goto write_error;
+ }
+#if 0
+ err = fsync(pair->trace);
+ if(err < 0) {
+ ret = errno;
+ perror("Error in writing to file");
+ goto write_error;
+ }
+#endif //0
+write_error:
+ err = ltt_buffer_put(ltt_buf, consumed_old);
+
+ if(err != 0) {
+ if(err == -EIO) {
+ dbg_printf("Reader has been pushed by the writer, last subbuffer corrupted.\n");
+ /* FIXME : we may delete the last written buffer if we wish. */
+ }
+ goto get_error;
+ }
+
+get_error:
+ return err;
+}
+
+/* This function is called by ltt_rw_init which has signals blocked */
+static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
+ sigset_t oldset, pid_t l_traced_pid, pthread_t l_traced_tid)
+{
+ struct sigaction act;
+ int ret;
+
+ traced_pid = l_traced_pid;
+ traced_tid = l_traced_tid;
+
+ dbg_printf("LTT ltt_usertrace_fast_daemon : init is %d, pid is %lu, traced_pid is %lu, traced_tid is %lu\n",
+ shared_trace_info->init, getpid(), traced_pid, traced_tid);
+
+ act.sa_handler = handler_sigusr1;
+ act.sa_flags = 0;
+ sigemptyset(&(act.sa_mask));
+ sigaddset(&(act.sa_mask), SIGUSR1);
+ sigaction(SIGUSR1, &act, NULL);
+
+ act.sa_handler = handler_sigusr2;
+ act.sa_flags = 0;
+ sigemptyset(&(act.sa_mask));
+ sigaddset(&(act.sa_mask), SIGUSR2);
+ sigaction(SIGUSR2, &act, NULL);
+
+ act.sa_handler = handler_sigalarm;
+ act.sa_flags = 0;
+ sigemptyset(&(act.sa_mask));
+ sigaddset(&(act.sa_mask), SIGALRM);
+ sigaction(SIGALRM, &act, NULL);
+
+ alarm(3);
+
+ while(1) {
+ ret = sigsuspend(&oldset);
+ if(ret != -1) {
+ perror("LTT Error in sigsuspend\n");
+ }
+ if(traced_pid == 0) break; /* parent died */
+ if(parent_exited) break;
+ dbg_printf("LTT Doing a buffer switch read. pid is : %lu\n", getpid());
+
+ do {
+ ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
+ } while(ret == 0);
+ }
+ /* The parent thread is dead and we have finished with the buffer */
+
+ /* Buffer force switch (flush). Using FLUSH instead of ACTIVE because we know
+ * there is no writer. */
+ flush_buffer(&shared_trace_info->channel.process, FORCE_FLUSH);
+ do {
+ ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
+ } while(ret == 0);
+
+ if(fd_process != -1)
+ close(fd_process);
+
+ ret = sem_destroy(&shared_trace_info->channel.process.writer_sem);
+ if(ret < 0) {
+ perror("error in sem_destroy");
+ }
+ munmap(shared_trace_info, sizeof(*shared_trace_info));
+
+ exit(0);
+}
+
+
+/* Reader-writer initialization */
+
+static enum ltt_process_role { LTT_ROLE_WRITER, LTT_ROLE_READER }
+ role = LTT_ROLE_WRITER;
+
+
+void ltt_rw_init(void)
+{
+ pid_t pid;
+ struct ltt_trace_info *shared_trace_info;
+ int ret;
+ sigset_t set, oldset;
+ pid_t l_traced_pid = getpid();
+ pid_t l_traced_tid = gettid();
+
+ /* parent : create the shared memory map */
+ shared_trace_info = mmap(0, sizeof(*thread_trace_info),
+ PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0);
+ shared_trace_info->init=0;
+ shared_trace_info->filter=0;
+ shared_trace_info->daemon_id=0;
+ shared_trace_info->nesting=0;
+ memset(&shared_trace_info->channel.process, 0,
+ sizeof(shared_trace_info->channel.process));
+ //Need NPTL!
+ ret = sem_init(&shared_trace_info->channel.process.writer_sem, 1,
+ LTT_N_SUBBUFS);
+ if(ret < 0) {
+ perror("error in sem_init");
+ }
+ shared_trace_info->channel.process.alloc_size = LTT_BUF_SIZE_PROCESS;
+ shared_trace_info->channel.process.subbuf_size = LTT_SUBBUF_SIZE_PROCESS;
+ shared_trace_info->channel.process.start =
+ shared_trace_info->channel.process_buf;
+ ltt_buffer_begin_callback(&shared_trace_info->channel.process,
+ ltt_get_timestamp(), 0);
+
+ shared_trace_info->init = 1;
+
+ /* Disable signals */
+ ret = sigfillset(&set);
+ if(ret) {
+ dbg_printf("LTT Error in sigfillset\n");
+ }
+
+ ret = pthread_sigmask(SIG_BLOCK, &set, &oldset);
+ if(ret) {
+ dbg_printf("LTT Error in pthread_sigmask\n");
+ }
+
+ pid = fork();
+ if(pid > 0) {
+ /* Parent */
+ shared_trace_info->daemon_id = pid;
+ thread_trace_info = shared_trace_info;
+
+ /* Enable signals */
+ ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+ if(ret) {
+ dbg_printf("LTT Error in pthread_sigmask\n");
+ }
+ } else if(pid == 0) {
+ pid_t sid;
+ /* Child */
+ role = LTT_ROLE_READER;
+ sid = setsid();
+ //Not a good idea to renice, unless futex wait eventually implement
+ //priority inheritence.
+ //ret = nice(1);
+ //if(ret < 0) {
+ // perror("Error in nice");
+ //}
+ if(sid < 0) {
+ perror("Error setting sid");
+ }
+ ltt_usertrace_fast_daemon(shared_trace_info, oldset, l_traced_pid,
+ l_traced_tid);
+ /* Should never return */
+ exit(-1);
+ } else if(pid < 0) {
+ /* fork error */
+ perror("LTT Error in forking ltt-usertrace-fast");
+ }
+}
+
+static __thread struct _pthread_cleanup_buffer cleanup_buffer;
+
+void ltt_thread_init(void)
+{
+ _pthread_cleanup_push(&cleanup_buffer, ltt_usertrace_fast_cleanup, NULL);
+ ltt_rw_init();
+}
+
+void __attribute__((constructor)) __ltt_usertrace_fast_init(void)
+{
+ dbg_printf("LTT usertrace-fast init\n");
+
+ ltt_rw_init();
+}
+
+void __attribute__((destructor)) __ltt_usertrace_fast_fini(void)
+{
+ if(role == LTT_ROLE_WRITER) {
+ dbg_printf("LTT usertrace-fast fini\n");
+ ltt_usertrace_fast_cleanup(NULL);
+ }
+}
+
--- /dev/null
+/*
+ * PowerPC atomic operations
+ */
+
+#ifndef _ASM_PPC_ATOMIC_H_
+#define _ASM_PPC_ATOMIC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct { volatile int counter; } atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+#define atomic_read(v) ((v)->counter)
+#define atomic_set(v,i) (((v)->counter) = (i))
+
+extern void atomic_clear_mask(unsigned long mask, unsigned long *addr);
+
+#if 0 // We only do operation on one CPU at a time (LTT)
+#define SMP_SYNC "sync"
+#define SMP_ISYNC "\n\tisync"
+#else
+#define SMP_SYNC ""
+#define SMP_ISYNC
+#endif
+
+/* Erratum #77 on the 405 means we need a sync or dcbt before every stwcx.
+ * The old ATOMIC_SYNC_FIX covered some but not all of this.
+ */
+#ifdef CONFIG_IBM405_ERR77
+#define PPC405_ERR77(ra,rb) "dcbt " #ra "," #rb ";"
+#else
+#define PPC405_ERR77(ra,rb)
+#endif
+
+static __inline__ void atomic_add(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%3 # atomic_add\n\
+ add %0,%2,%0\n"
+ PPC405_ERR77(0,%3)
+" stwcx. %0,0,%3 \n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (a), "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_add_return(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_add_return\n\
+ add %0,%1,%0\n"
+ PPC405_ERR77(0,%2)
+" stwcx. %0,0,%2 \n\
+ bne- 1b"
+ SMP_ISYNC
+ : "=&r" (t)
+ : "r" (a), "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
+
+static __inline__ void atomic_sub(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%3 # atomic_sub\n\
+ subf %0,%2,%0\n"
+ PPC405_ERR77(0,%3)
+" stwcx. %0,0,%3 \n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (a), "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_sub_return(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_sub_return\n\
+ subf %0,%1,%0\n"
+ PPC405_ERR77(0,%2)
+" stwcx. %0,0,%2 \n\
+ bne- 1b"
+ SMP_ISYNC
+ : "=&r" (t)
+ : "r" (a), "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+static __inline__ void atomic_inc(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_inc\n\
+ addic %0,%0,1\n"
+ PPC405_ERR77(0,%2)
+" stwcx. %0,0,%2 \n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_inc_return(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%1 # atomic_inc_return\n\
+ addic %0,%0,1\n"
+ PPC405_ERR77(0,%1)
+" stwcx. %0,0,%1 \n\
+ bne- 1b"
+ SMP_ISYNC
+ : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+/*
+ * atomic_inc_and_test - increment and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1
+ * and returns true if the result is zero, or false for all
+ * other cases.
+ */
+#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
+
+static __inline__ void atomic_dec(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_dec\n\
+ addic %0,%0,-1\n"
+ PPC405_ERR77(0,%2)\
+" stwcx. %0,0,%2\n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_dec_return(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%1 # atomic_dec_return\n\
+ addic %0,%0,-1\n"
+ PPC405_ERR77(0,%1)
+" stwcx. %0,0,%1\n\
+ bne- 1b"
+ SMP_ISYNC
+ : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
+#define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
+
+/*
+ * Atomically test *v and decrement if it is greater than 0.
+ * The function returns the old value of *v minus 1.
+ */
+static __inline__ int atomic_dec_if_positive(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%1 # atomic_dec_if_positive\n\
+ addic. %0,%0,-1\n\
+ blt- 2f\n"
+ PPC405_ERR77(0,%1)
+" stwcx. %0,0,%1\n\
+ bne- 1b"
+ SMP_ISYNC
+ "\n\
+2:" : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define __MB __asm__ __volatile__ (SMP_SYNC : : : "memory")
+#define smp_mb__before_atomic_dec() __MB
+#define smp_mb__after_atomic_dec() __MB
+#define smp_mb__before_atomic_inc() __MB
+#define smp_mb__after_atomic_inc() __MB
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif /* _ASM_PPC_ATOMIC_H_ */
--- /dev/null
+/*
+ * PowerPC64 atomic operations
+ *
+ * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM
+ * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC64_ATOMIC_H_
+#define _ASM_PPC64_ATOMIC_H_
+
+#include <asm/memory.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct { volatile int counter; } atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+#define atomic_read(v) ((v)->counter)
+#define atomic_set(v,i) (((v)->counter) = (i))
+
+static __inline__ void atomic_add(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%3 # atomic_add\n\
+ add %0,%2,%0\n\
+ stwcx. %0,0,%3\n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (a), "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_add_return(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%2 # atomic_add_return\n\
+ add %0,%1,%0\n\
+ stwcx. %0,0,%2\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (t)
+ : "r" (a), "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
+
+static __inline__ void atomic_sub(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%3 # atomic_sub\n\
+ subf %0,%2,%0\n\
+ stwcx. %0,0,%3\n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (a), "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_sub_return(int a, atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%2 # atomic_sub_return\n\
+ subf %0,%1,%0\n\
+ stwcx. %0,0,%2\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (t)
+ : "r" (a), "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+static __inline__ void atomic_inc(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_inc\n\
+ addic %0,%0,1\n\
+ stwcx. %0,0,%2\n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_inc_return(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%1 # atomic_inc_return\n\
+ addic %0,%0,1\n\
+ stwcx. %0,0,%1\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+/*
+ * atomic_inc_and_test - increment and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1
+ * and returns true if the result is zero, or false for all
+ * other cases.
+ */
+#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
+
+static __inline__ void atomic_dec(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # atomic_dec\n\
+ addic %0,%0,-1\n\
+ stwcx. %0,0,%2\n\
+ bne- 1b"
+ : "=&r" (t), "=m" (v->counter)
+ : "r" (&v->counter), "m" (v->counter)
+ : "cc");
+}
+
+static __inline__ int atomic_dec_return(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%1 # atomic_dec_return\n\
+ addic %0,%0,-1\n\
+ stwcx. %0,0,%1\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
+#define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
+
+/*
+ * Atomically test *v and decrement if it is greater than 0.
+ * The function returns the old value of *v minus 1.
+ */
+static __inline__ int atomic_dec_if_positive(atomic_t *v)
+{
+ int t;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%1 # atomic_dec_if_positive\n\
+ addic. %0,%0,-1\n\
+ blt- 2f\n\
+ stwcx. %0,0,%1\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ "\n\
+2:" : "=&r" (t)
+ : "r" (&v->counter)
+ : "cc", "memory");
+
+ return t;
+}
+
+#define smp_mb__before_atomic_dec() smp_mb()
+#define smp_mb__after_atomic_dec() smp_mb()
+#define smp_mb__before_atomic_inc() smp_mb()
+#define smp_mb__after_atomic_inc() smp_mb()
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif /* _ASM_PPC64_ATOMIC_H_ */
--- /dev/null
+/*****************************************************************************
+ * kernelutils-arm.h
+ *
+ * This file holds the code needed by LTT usertrace that comes from the
+ * kernel headers. Since including kernel headers is not recommended in
+ * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
+ * (i.e. copied/pasted) from the original kernel headers (2.6.18).
+ *
+ * Do not use these functions within signal handlers, as the architecture offers
+ * no atomic operations. (Mathieu Desnoyers) It is safe to do multithreaded
+ * tracing though, as the buffers are per thread.
+ *
+ * Deepak Saxena, October 2006
+ */
+
+#ifndef _KERNELUTILS_ARM_H
+#define _KERNELUTILS_ARM_H
+
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct { volatile int counter; } atomic_t;
+
+#define atomic_read(v) ((v)->counter)
+
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+ unsigned long flags;
+ int val;
+
+ val = v->counter;
+ v->counter = val += i;
+
+ return val;
+}
+
+#define atomic_add(i, v) (void) atomic_add_return(i, v)
+#define atomic_inc(v) (void) atomic_add_return(1, v)
+
+static inline unsigned long cmpxchg(volatile void *ptr,
+ unsigned long old,
+ unsigned long new)
+{
+ unsigned long flags, prev;
+ volatile unsigned long *p = ptr;
+
+ if ((prev = *p) == old)
+ *p = new;
+ return(prev);
+}
+
+static inline unsigned long long get_cycles(void)
+{
+ struct timespec tp;
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ return tp.tv_sec * 1000000000 + tp.tv_nsec;
+}
+
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * kernelutils-x386.h
+ *
+ * This file holds the code needed by LTT usertrace that comes from the
+ * kernel headers. Since including kernel headers is not recommended in
+ * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
+ * (i.e. copied/pasted) from the original kernel headers (2.6.17).
+ *
+ * Martin Bisson, July 2006
+ * Mathieu Desnoyers, August 2006
+ */
+
+#ifndef _KERNELUTILS_I386_H
+#define _KERNELUTILS_I386_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// We are careful, so we assume a possibly SMP machine
+#define LOCK "lock ; "
+#define LOCK_PREFIX "lock ; "
+
+
+// From atomic.h
+
+
+/*
+ * Make sure gcc doesn't try to be clever and move things around
+ * on us. We need to use _exactly_ the address the user gave us,
+ * not some alias that contains the same information.
+ */
+typedef struct { volatile int counter; } atomic_t;
+
+
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+#define atomic_read(v) ((v)->counter)
+
+/**
+ * atomic_add - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v.
+ */
+static __inline__ void atomic_add(int i, atomic_t *v)
+{
+ __asm__ __volatile__(
+ LOCK "addl %1,%0"
+ :"=m" (v->counter)
+ :"ir" (i), "m" (v->counter));
+}
+
+/**
+ * atomic_inc - increment atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1.
+ */
+static __inline__ void atomic_inc(atomic_t *v)
+{
+ __asm__ __volatile__(
+ LOCK "incl %0"
+ :"=m" (v->counter)
+ :"m" (v->counter));
+}
+
+/**
+ * atomic_add_return - add and return
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+ int __i = i;
+ __asm__ __volatile__(
+ LOCK "xaddl %0, %1;"
+ :"=r"(i)
+ :"m"(v->counter), "0"(i));
+ return i + __i;
+}
+
+
+
+
+// From system.h
+
+struct __xchg_dummy { unsigned long a[100]; };
+#define __xg(x) ((struct __xchg_dummy *)(x))
+
+
+/*
+ * Atomic compare and exchange. Compare OLD with MEM, if identical,
+ * store NEW in MEM. Return the initial value in MEM. Success is
+ * indicated by comparing RETURN with OLD.
+ */
+
+#define __HAVE_ARCH_CMPXCHG 1
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
+ (unsigned long)(n),sizeof(*(ptr))))
+
+static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
+ unsigned long newval, int size)
+{
+ unsigned long prev;
+ switch (size) {
+ case 1:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
+ : "=a"(prev)
+ : "q"(newval), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ case 2:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
+ : "=a"(prev)
+ : "r"(newval), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ case 4:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
+ : "=a"(prev)
+ : "r"(newval), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ }
+ return old;
+}
+
+
+// From msr.h
+
+#define rdtscll(val) \
+ __asm__ __volatile__("rdtsc" : "=A" (val))
+
+// From timex.h
+
+typedef unsigned long long cycles_t;
+
+static inline cycles_t get_cycles (void)
+{
+ unsigned long long ret;
+
+ rdtscll(ret);
+ return ret;
+}
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif // _KERNELUTILS_I386_H
--- /dev/null
+/*****************************************************************************
+ * kernelutils-x86_64.h
+ *
+ * This file holds the code needed by LTT usertrace that comes from the
+ * kernel headers. Since including kernel headers is not recommended in
+ * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
+ * (i.e. copied/pasted) from the original kernel headers (2.6.17).
+ *
+ * Martin Bisson, July 2006
+ */
+
+#ifndef _KERNELUTILS_X86_64_H
+#define _KERNELUTILS_X86_64_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// We are careful, so we assume a possibly SMP machine
+#define LOCK "lock ; "
+#define LOCK_PREFIX "lock ; "
+
+
+
+
+// From atomic.h
+
+
+/*
+ * Make sure gcc doesn't try to be clever and move things around
+ * on us. We need to use _exactly_ the address the user gave us,
+ * not some alias that contains the same information.
+ */
+typedef struct { volatile int counter; } atomic_t;
+
+
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+#define atomic_read(v) ((v)->counter)
+
+/**
+ * atomic_add - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v.
+ */
+static __inline__ void atomic_add(int i, atomic_t *v)
+{
+ __asm__ __volatile__(
+ LOCK "addl %1,%0"
+ :"=m" (v->counter)
+ :"ir" (i), "m" (v->counter));
+}
+
+/**
+ * atomic_inc - increment atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1.
+ */
+static __inline__ void atomic_inc(atomic_t *v)
+{
+ __asm__ __volatile__(
+ LOCK "incl %0"
+ :"=m" (v->counter)
+ :"m" (v->counter));
+}
+
+/**
+ * atomic_add_return - add and return
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+ int __i = i;
+ __asm__ __volatile__(
+ LOCK "xaddl %0, %1;"
+ :"=r"(i)
+ :"m"(v->counter), "0"(i));
+ return i + __i;
+}
+
+
+
+
+// From system.h
+
+#define __xg(x) ((volatile long *)(x))
+
+
+/*
+ * Atomic compare and exchange. Compare OLD with MEM, if identical,
+ * store NEW in MEM. Return the initial value in MEM. Success is
+ * indicated by comparing RETURN with OLD.
+ */
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
+ unsigned long new, int size)
+{
+ unsigned long prev;
+ switch (size) {
+ case 1:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
+ : "=a"(prev)
+ : "q"(new), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ case 2:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
+ : "=a"(prev)
+ : "r"(new), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ case 4:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2"
+ : "=a"(prev)
+ : "r"(new), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ case 8:
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2"
+ : "=a"(prev)
+ : "r"(new), "m"(*__xg(ptr)), "0"(old)
+ : "memory");
+ return prev;
+ }
+ return old;
+}
+
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
+ (unsigned long)(n),sizeof(*(ptr))))
+
+
+
+
+// From msr.h
+
+
+#define rdtscll(val) do { \
+ unsigned int __a,__d; \
+ asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
+ (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
+} while(0)
+
+
+
+
+// From timex.h
+
+typedef unsigned long long cycles_t;
+
+static inline cycles_t get_cycles (void)
+{
+ unsigned long long ret;
+
+ rdtscll(ret);
+ return ret;
+}
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif // _KERNELUTILS_X86_64_H
--- /dev/null
+#ifndef _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
+#define _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
+
+#include <sys/types.h>
+#include <ltt/ltt-facility-id-user_generic.h>
+#include <ltt/ltt-usertrace.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static int trace_user_generic_slow_printf(
+ const char *fmt, ...)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ /* Guess we need no more than 100 bytes. */
+ int n, size = 104;
+ char *p, *np;
+ va_list ap;
+ int ret;
+
+ size += ltt_align(size, sizeof(void*));
+ if ((p = malloc (size)) == NULL)
+ return -1;
+
+ while (1) {
+ /* Try to print in the allocated space. */
+ va_start(ap, fmt);
+ n = vsnprintf (p, size, fmt, ap);
+ va_end(ap);
+ /* If that worked, trace the string. */
+ if (n > -1 && n < size) {
+ ret = trace_user_generic_slow_printf_param_buffer(p, n+1+ltt_align(n+1, sizeof(void*)));
+ free(p);
+ return ret;
+ }
+ /* Else try again with more space. */
+ if (n > -1) /* glibc 2.1 */
+ size = n+1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+ size += ltt_align(size, sizeof(void*));
+ if ((np = realloc (p, size)) == NULL) {
+ free(p);
+ return -1;
+ } else {
+ p = np;
+ }
+ }
+}
+#endif //LTT_TRACE
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif //_LTT_FACILITY_CUSTOM_USER_GENERIC_H_
--- /dev/null
+#ifndef _LTT_FACILITY_ID_USER_GENERIC_H_
+#define _LTT_FACILITY_ID_USER_GENERIC_H_
+
+#ifdef LTT_TRACE
+#include <ltt/ltt-usertrace.h>
+
+/**** facility handle ****/
+
+extern ltt_facility_t ltt_facility_user_generic_B1865E44;
+extern ltt_facility_t ltt_facility_user_generic;
+
+
+/**** event index ****/
+
+enum user_generic_event {
+ event_user_generic_string,
+ event_user_generic_string_pointer,
+ event_user_generic_slow_printf,
+ event_user_generic_function_entry,
+ event_user_generic_function_exit,
+ event_user_generic_thread_brand,
+ facility_user_generic_num_events
+};
+
+#endif //LTT_TRACE
+#endif //_LTT_FACILITY_ID_USER_GENERIC_H_
--- /dev/null
+#ifndef _LTT_FACILITY_USER_GENERIC_H_
+#define _LTT_FACILITY_USER_GENERIC_H_
+
+#include <sys/types.h>
+#include <ltt/ltt-facility-id-user_generic.h>
+#include <ltt/ltt-usertrace.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Named types */
+
+/* Event string structures */
+static inline void lttng_write_string_user_generic_string_data(
+ char *buffer,
+ size_t *to_base,
+ size_t *to,
+ const char **from,
+ size_t *len,
+ const char * obj)
+{
+ size_t size;
+ size_t align;
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
+ }
+ *to += *len;
+ *len = 0;
+
+ align = sizeof(char);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = strlen(obj) + 1; /* Include final NULL char. */
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj, size);
+ *to += size;
+
+ /* Realign the *to_base on arch size, set *to to 0 */
+ *to += ltt_align(*to, sizeof(void *));
+ *to_base = *to_base+*to;
+ *to = 0;
+
+ /* Put source *from just after the C string */
+ *from += size;
+}
+
+
+/* Event string logging function */
+static inline int trace_user_generic_string(
+ const char * lttng_param_data);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_string(
+ const char * lttng_param_data)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ const char *real_from;
+ const char **from = &real_from;
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_data;
+ lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
+
+ reserve_size = *to_base + *to + *len;
+ {
+ char stack_buffer[reserve_size];
+ buffer = stack_buffer;
+
+ *to_base = *to = *len = 0;
+
+ *from = (const char*)lttng_param_data;
+ lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING, 0);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline int trace_user_generic_string(
+ const char * lttng_param_data)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_data;
+ lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_string);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_string,
+ reserve_size, tsc);
+ *from = (const char*)lttng_param_data;
+ lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+/* Event string_pointer structures */
+static inline void lttng_write_string_user_generic_string_pointer_string(
+ char *buffer,
+ size_t *to_base,
+ size_t *to,
+ const char **from,
+ size_t *len,
+ const char * obj)
+{
+ size_t size;
+ size_t align;
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
+ }
+ *to += *len;
+ *len = 0;
+
+ align = sizeof(char);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = strlen(obj) + 1; /* Include final NULL char. */
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj, size);
+ *to += size;
+
+ /* Realign the *to_base on arch size, set *to to 0 */
+ *to += ltt_align(*to, sizeof(void *));
+ *to_base = *to_base+*to;
+ *to = 0;
+
+ /* Put source *from just after the C string */
+ *from += size;
+}
+
+
+/* Event string_pointer logging function */
+static inline int trace_user_generic_string_pointer(
+ const char * lttng_param_string,
+ const void * lttng_param_pointer);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_string_pointer(
+ const char * lttng_param_string,
+ const void * lttng_param_pointer)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ *from = (const char*)<tng_param_pointer;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ {
+ char stack_buffer[reserve_size];
+ buffer = stack_buffer;
+
+ *to_base = *to = *len = 0;
+
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_pointer;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING, 0);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline int trace_user_generic_string_pointer(
+ const char * lttng_param_string,
+ const void * lttng_param_pointer)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ *from = (const char*)<tng_param_pointer;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_string_pointer);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer,
+ reserve_size, tsc);
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_pointer;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+/* Event slow_printf structures */
+static inline void lttng_write_string_user_generic_slow_printf_string(
+ char *buffer,
+ size_t *to_base,
+ size_t *to,
+ const char **from,
+ size_t *len,
+ const char * obj)
+{
+ size_t size;
+ size_t align;
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
+ }
+ *to += *len;
+ *len = 0;
+
+ align = sizeof(char);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = strlen(obj) + 1; /* Include final NULL char. */
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj, size);
+ *to += size;
+
+ /* Realign the *to_base on arch size, set *to to 0 */
+ *to += ltt_align(*to, sizeof(void *));
+ *to_base = *to_base+*to;
+ *to = 0;
+
+ /* Put source *from just after the C string */
+ *from += size;
+}
+
+
+/* Event slow_printf logging function */
+static inline int trace_user_generic_slow_printf_param_buffer(
+ char *buffer,
+ size_t reserve_size);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_slow_printf_param_buffer(
+ char *buffer,
+ size_t reserve_size)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ {
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING, 0);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline int trace_user_generic_slow_printf(
+ const char * lttng_param_string)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_slow_printf);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf,
+ reserve_size, tsc);
+ *from = (const char*)lttng_param_string;
+ lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+/* Event function_entry structures */
+
+/* Event function_entry logging function */
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_function_entry(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ {
+ char stack_buffer[reserve_size];
+ buffer = stack_buffer;
+
+ *to_base = *to = *len = 0;
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING, 0);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_function_entry);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_function_entry,
+ reserve_size, tsc);
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+/* Event function_exit structures */
+
+/* Event function_exit logging function */
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_function_exit(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ {
+ char stack_buffer[reserve_size];
+ buffer = stack_buffer;
+
+ *to_base = *to = *len = 0;
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING, 0);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
+ const void * lttng_param_this_fn,
+ const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ size_t align;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_function_exit);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_function_exit,
+ reserve_size, tsc);
+ *from = (const char*)<tng_param_this_fn;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ *from = (const char*)<tng_param_call_site;
+ align = sizeof(const void *);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ *len += sizeof(const void *);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+/* Event thread_brand structures */
+static inline void lttng_write_string_user_generic_thread_brand_name(
+ char *buffer,
+ size_t *to_base,
+ size_t *to,
+ const char **from,
+ size_t *len,
+ const char * obj)
+{
+ size_t size;
+ size_t align;
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, *from, *len);
+ }
+ *to += *len;
+ *len = 0;
+
+ align = sizeof(char);
+
+ if (*len == 0) {
+ *to += ltt_align(*to, align); /* align output */
+ } else {
+ *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+ }
+
+ /* Contains variable sized fields : must explode the structure */
+
+ size = strlen(obj) + 1; /* Include final NULL char. */
+ if (buffer != NULL)
+ memcpy(buffer+*to_base+*to, obj, size);
+ *to += size;
+
+ /* Realign the *to_base on arch size, set *to to 0 */
+ *to += ltt_align(*to, sizeof(void *));
+ *to_base = *to_base+*to;
+ *to = 0;
+
+ /* Put source *from just after the C string */
+ *from += size;
+}
+
+
+/* Event thread_brand logging function */
+static inline int trace_user_generic_thread_brand(
+ const char * lttng_param_name);
+
+#ifndef LTT_TRACE_FAST
+static inline int trace_user_generic_thread_brand(
+ const char * lttng_param_name)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ int ret = 0;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ const char *real_from;
+ const char **from = &real_from;
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_name;
+ lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
+
+ reserve_size = *to_base + *to + *len;
+ {
+ char stack_buffer[reserve_size];
+ buffer = stack_buffer;
+
+ *to_base = *to = *len = 0;
+
+ *from = (const char*)lttng_param_name;
+ lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand, buffer, reserve_size, LTT_BLOCKING, 1);
+ }
+
+ return ret;
+
+}
+#endif //LTT_TRACE
+#endif //!LTT_TRACE_FAST
+
+#ifdef LTT_TRACE_FAST
+static inline int trace_user_generic_thread_brand(
+ const char * lttng_param_name)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+ unsigned int index;
+ struct ltt_trace_info *trace = thread_trace_info;
+ struct ltt_buf *ltt_buf;
+ char *buffer = NULL;
+ size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+ size_t *to_base = &real_to_base;
+ size_t real_to = 0;
+ size_t *to = &real_to;
+ size_t real_len = 0;
+ size_t *len = &real_len;
+ size_t reserve_size;
+ size_t slot_size;
+ const char *real_from;
+ const char **from = &real_from;
+ uint64_t tsc;
+ if (!trace) {
+ ltt_thread_init();
+ trace = thread_trace_info;
+ }
+
+
+ /* For each field, calculate the field size. */
+ /* size = *to_base + *to + *len */
+ /* Assume that the padding for alignment starts at a
+ * sizeof(void *) address. */
+
+ *from = (const char*)lttng_param_name;
+ lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
+
+ reserve_size = *to_base + *to + *len;
+ trace->nesting++;
+ index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
+ event_user_generic_thread_brand);
+
+ {
+ ltt_buf = ltt_get_channel_from_index(trace, index);
+ slot_size = 0;
+ buffer = ltt_reserve_slot(trace, ltt_buf,
+ reserve_size, &slot_size, &tsc);
+ if (!buffer)
+ goto end; /* buffer full */
+
+ *to_base = *to = *len = 0;
+
+ buffer = ltt_write_event_header(trace, ltt_buf, buffer,
+ ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand,
+ reserve_size, tsc);
+ *from = (const char*)lttng_param_name;
+ lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
+
+ /* Flush pending memcpy */
+ if (*len != 0) {
+ memcpy(buffer+*to_base+*to, *from, *len);
+ *to += *len;
+ *len = 0;
+ }
+
+ ltt_commit_slot(ltt_buf, buffer, slot_size);
+
+}
+
+end:
+ trace->nesting--;
+}
+#endif //LTT_TRACE
+#endif //LTT_TRACE_FAST
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif //_LTT_FACILITY_USER_GENERIC_H_
--- /dev/null
+
+/* LTTng user-space "fast" tracing header
+ *
+ * Copyright 2006 Mathieu Desnoyers
+ *
+ */
+
+#ifndef _LTT_USERTRACE_FAST_H
+#define _LTT_USERTRACE_FAST_H
+
+#ifdef LTT_TRACE
+#ifdef LTT_TRACE_FAST
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <syscall.h>
+#include <semaphore.h>
+#include <signal.h>
+
+#include <ltt/ltt-facility-id-user_generic.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef LTT_N_SUBBUFS
+#define LTT_N_SUBBUFS 2
+#endif //LTT_N_SUBBUFS
+
+#ifndef LTT_SUBBUF_SIZE_PROCESS
+#define LTT_SUBBUF_SIZE_PROCESS 1048576
+#endif //LTT_BUF_SIZE_CPU
+
+#define LTT_BUF_SIZE_PROCESS (LTT_SUBBUF_SIZE_PROCESS * LTT_N_SUBBUFS)
+
+#ifndef LTT_USERTRACE_ROOT
+#define LTT_USERTRACE_ROOT "/tmp/ltt-usertrace"
+#endif //LTT_USERTRACE_ROOT
+
+
+/* Buffer offset macros */
+
+#define BUFFER_OFFSET(offset, buf) (offset & (buf->alloc_size-1))
+#define SUBBUF_OFFSET(offset, buf) (offset & (buf->subbuf_size-1))
+#define SUBBUF_ALIGN(offset, buf) \
+ (((offset) + buf->subbuf_size) & (~(buf->subbuf_size-1)))
+#define SUBBUF_TRUNC(offset, buf) \
+ ((offset) & (~(buf->subbuf_size-1)))
+#define SUBBUF_INDEX(offset, buf) \
+ (BUFFER_OFFSET(offset,buf)/buf->subbuf_size)
+
+
+#define LTT_TRACER_MAGIC_NUMBER 0x00D6B7ED
+#define LTT_TRACER_VERSION_MAJOR 0
+#define LTT_TRACER_VERSION_MINOR 8
+
+#ifndef atomic_cmpxchg
+#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
+#endif //atomic_cmpxchg
+
+struct ltt_trace_header {
+ uint32_t magic_number;
+ uint32_t arch_type;
+ uint32_t arch_variant;
+ uint32_t float_word_order; /* Only useful for user space traces */
+ uint8_t arch_size;
+ //uint32_t system_type;
+ uint8_t major_version;
+ uint8_t minor_version;
+ uint8_t flight_recorder;
+ uint8_t has_heartbeat;
+ uint8_t has_alignment; /* Event header alignment */
+ uint8_t tsc_lsb_truncate;
+ uint8_t tscbits;
+ uint32_t freq_scale;
+ uint64_t start_freq;
+ uint64_t start_tsc;
+ uint64_t start_monotonic;
+ uint64_t start_time_sec;
+ uint64_t start_time_usec;
+} __attribute((packed));
+
+
+struct ltt_block_start_header {
+ struct {
+ uint64_t cycle_count;
+ uint64_t freq; /* khz */
+ } begin;
+ struct {
+ uint64_t cycle_count;
+ uint64_t freq; /* khz */
+ } end;
+ uint32_t lost_size; /* Size unused at the end of the buffer */
+ uint32_t buf_size; /* The size of this sub-buffer */
+ struct ltt_trace_header trace;
+} __attribute((packed));
+
+
+
+struct ltt_buf {
+ void *start;
+ atomic_t offset;
+ atomic_t consumed;
+ atomic_t reserve_count[LTT_N_SUBBUFS];
+ atomic_t commit_count[LTT_N_SUBBUFS];
+
+ atomic_t events_lost;
+ atomic_t corrupted_subbuffers;
+ sem_t writer_sem; /* semaphore on which the writer waits */
+ unsigned int alloc_size;
+ unsigned int subbuf_size;
+};
+
+struct ltt_trace_info {
+ int init;
+ int filter;
+ pid_t daemon_id;
+ int nesting;
+ struct {
+ struct ltt_buf process;
+ char process_buf[LTT_BUF_SIZE_PROCESS] __attribute__ ((aligned (8)));
+ } channel;
+};
+
+
+struct ltt_event_header_nohb {
+ uint64_t timestamp;
+ unsigned char facility_id;
+ unsigned char event_id;
+ uint16_t event_size;
+} __attribute((packed));
+
+extern __thread struct ltt_trace_info *thread_trace_info;
+
+void ltt_thread_init(void);
+
+void __attribute__((no_instrument_function))
+ ltt_usertrace_fast_buffer_switch(void);
+
+/* Get the offset of the channel in the ltt_trace_struct */
+#define GET_CHANNEL_INDEX(chan) \
+ (unsigned int)&((struct ltt_trace_info*)NULL)->channel.chan
+
+/* ltt_get_index_from_facility
+ *
+ * Get channel index from facility and event id.
+ *
+ * @fID : facility ID
+ * @eID : event number
+ *
+ * Get the channel index into which events must be written for the given
+ * facility and event number. We get this structure offset as soon as possible
+ * and remember it so we pass through this logic only once per trace call (not
+ * for every trace).
+ */
+static inline unsigned int __attribute__((no_instrument_function))
+ ltt_get_index_from_facility(uint8_t fID,
+ uint8_t eID)
+{
+ return GET_CHANNEL_INDEX(process);
+}
+
+
+static inline struct ltt_buf * __attribute__((no_instrument_function))
+ ltt_get_channel_from_index(
+ struct ltt_trace_info *trace, unsigned int index)
+{
+ return (struct ltt_buf *)((void*)trace+index);
+}
+
+
+/*
+ * ltt_get_header_size
+ *
+ * Calculate alignment offset for arch size void*. This is the
+ * alignment offset of the event header.
+ *
+ * Important note :
+ * The event header must be a size multiple of the void* size. This is necessary
+ * to be able to calculate statically the alignment offset of the variable
+ * length data fields that follows. The total offset calculated here :
+ *
+ * Alignment of header struct on arch size
+ * + sizeof(header struct)
+ * + padding added to end of struct to align on arch size.
+ * */
+static inline unsigned char __attribute__((no_instrument_function))
+ ltt_get_header_size(struct ltt_trace_info *trace,
+ void *address,
+ size_t data_size,
+ size_t *before_hdr_pad)
+{
+ unsigned int padding;
+ unsigned int header;
+ size_t after_hdr_pad;
+
+ header = sizeof(struct ltt_event_header_nohb);
+
+ /* Padding before the header. Calculated dynamically */
+ *before_hdr_pad = ltt_align((unsigned long)address, header);
+ padding = *before_hdr_pad;
+
+ /* Padding after header, considering header aligned on ltt_align.
+ * Calculated statically if header size if known. */
+ after_hdr_pad = ltt_align(header, sizeof(void*));
+ padding += after_hdr_pad;
+
+ return header+padding;
+}
+
+
+/* ltt_write_event_header
+ *
+ * Writes the event header to the pointer.
+ *
+ * @channel : pointer to the channel structure
+ * @ptr : buffer pointer
+ * @fID : facility ID
+ * @eID : event ID
+ * @event_size : size of the event, excluding the event header.
+ * @tsc : time stamp counter.
+ */
+static inline char *__attribute__((no_instrument_function))
+ ltt_write_event_header(
+ struct ltt_trace_info *trace, struct ltt_buf *buf,
+ void *ptr, uint8_t fID, uint32_t eID, size_t event_size,
+ uint64_t tsc)
+{
+ size_t after_hdr_pad;
+ struct ltt_event_header_nohb *nohb;
+
+ event_size = min(event_size, 0xFFFFU);
+ nohb = (struct ltt_event_header_nohb *)(ptr);
+ nohb->timestamp = (uint64_t)tsc;
+ nohb->facility_id = fID;
+ nohb->event_id = eID;
+ nohb->event_size = (uint16_t)event_size;
+ after_hdr_pad = ltt_align(sizeof(*nohb), sizeof(void*));
+ return ptr + sizeof(*nohb) + after_hdr_pad;
+}
+
+
+
+static inline uint64_t __attribute__((no_instrument_function))
+ltt_get_timestamp()
+{
+ return get_cycles();
+}
+
+static inline unsigned int __attribute__((no_instrument_function))
+ltt_subbuf_header_len(struct ltt_buf *buf)
+{
+ return sizeof(struct ltt_block_start_header);
+}
+
+
+
+static inline void __attribute__((no_instrument_function))
+ltt_write_trace_header(struct ltt_trace_header *header)
+{
+ header->magic_number = LTT_TRACER_MAGIC_NUMBER;
+ header->major_version = LTT_TRACER_VERSION_MAJOR;
+ header->minor_version = LTT_TRACER_VERSION_MINOR;
+ header->float_word_order = 0; //FIXME
+ header->arch_type = 0; //FIXME LTT_ARCH_TYPE;
+ header->arch_size = sizeof(void*);
+ header->arch_variant = 0; //FIXME LTT_ARCH_VARIANT;
+ header->flight_recorder = 0;
+ header->has_heartbeat = 0;
+ header->tsc_lsb_truncate = 0;
+ header->tscbits = 0;
+
+#ifndef LTT_PACK
+ header->has_alignment = sizeof(void*);
+#else
+ header->has_alignment = 0;
+#endif
+
+ //FIXME
+ header->freq_scale = 0;
+ header->start_freq = 0;
+ header->start_tsc = 0;
+ header->start_monotonic = 0;
+ header->start_time_sec = 0;
+ header->start_time_usec = 0;
+}
+
+
+static inline void __attribute__((no_instrument_function))
+ltt_buffer_begin_callback(struct ltt_buf *buf,
+ uint64_t tsc, unsigned int subbuf_idx)
+{
+ struct ltt_block_start_header *header =
+ (struct ltt_block_start_header*)
+ (buf->start + (subbuf_idx*buf->subbuf_size));
+
+ header->begin.cycle_count = tsc;
+ header->begin.freq = 0; //ltt_frequency();
+
+ header->lost_size = 0xFFFFFFFF; // for debugging...
+
+ header->buf_size = buf->subbuf_size;
+
+ ltt_write_trace_header(&header->trace);
+
+}
+
+
+
+static inline void __attribute__((no_instrument_function))
+ltt_buffer_end_callback(struct ltt_buf *buf,
+ uint64_t tsc, unsigned int offset, unsigned int subbuf_idx)
+{
+ struct ltt_block_start_header *header =
+ (struct ltt_block_start_header*)
+ (buf->start + (subbuf_idx*buf->subbuf_size));
+ /* offset is assumed to never be 0 here : never deliver a completely
+ * empty subbuffer. */
+ /* The lost size is between 0 and subbuf_size-1 */
+ header->lost_size = SUBBUF_OFFSET((buf->subbuf_size - offset),
+ buf);
+ header->end.cycle_count = tsc;
+ header->end.freq = 0; //ltt_frequency();
+}
+
+
+static inline void __attribute__((no_instrument_function))
+ltt_deliver_callback(struct ltt_buf *buf,
+ unsigned subbuf_idx,
+ void *subbuf)
+{
+ ltt_usertrace_fast_buffer_switch();
+}
+
+
+/* ltt_reserve_slot
+ *
+ * Atomic slot reservation in a LTTng buffer. It will take care of
+ * sub-buffer switching.
+ *
+ * Parameters:
+ *
+ * @trace : the trace structure to log to.
+ * @buf : the buffer to reserve space into.
+ * @data_size : size of the variable length data to log.
+ * @slot_size : pointer to total size of the slot (out)
+ * @tsc : pointer to the tsc at the slot reservation (out)
+ * @before_hdr_pad : dynamic padding before the event header.
+ * @after_hdr_pad : dynamic padding after the event header.
+ *
+ * Return : NULL if not enough space, else returns the pointer
+ * to the beginning of the reserved slot. */
+static inline void * __attribute__((no_instrument_function)) ltt_reserve_slot(
+ struct ltt_trace_info *trace,
+ struct ltt_buf *ltt_buf,
+ unsigned int data_size,
+ size_t *slot_size,
+ uint64_t *tsc)
+{
+ int offset_begin, offset_end, offset_old;
+ //int has_switch;
+ int begin_switch, end_switch_current, end_switch_old;
+ int reserve_commit_diff = 0;
+ unsigned int size;
+ size_t before_hdr_pad;
+ int consumed_old, consumed_new;
+ int commit_count, reserve_count;
+ int ret;
+ sigset_t oldset, set;
+
+ do {
+ offset_old = atomic_read(<t_buf->offset);
+ offset_begin = offset_old;
+ //has_switch = 0;
+ begin_switch = 0;
+ end_switch_current = 0;
+ end_switch_old = 0;
+ *tsc = ltt_get_timestamp();
+ if(*tsc == 0) {
+ /* Error in getting the timestamp, event lost */
+ atomic_inc(<t_buf->events_lost);
+ return NULL;
+ }
+
+ if(SUBBUF_OFFSET(offset_begin, ltt_buf) == 0) {
+ begin_switch = 1; /* For offset_begin */
+ } else {
+ size = ltt_get_header_size(trace, ltt_buf->start + offset_begin,
+ data_size, &before_hdr_pad)
+ + data_size;
+
+ if((SUBBUF_OFFSET(offset_begin, ltt_buf)+size)>ltt_buf->subbuf_size) {
+ //has_switch = 1;
+ end_switch_old = 1; /* For offset_old */
+ begin_switch = 1; /* For offset_begin */
+ }
+ }
+
+ if(begin_switch) {
+ if(end_switch_old) {
+ offset_begin = SUBBUF_ALIGN(offset_begin, ltt_buf);
+ }
+ offset_begin = offset_begin + ltt_subbuf_header_len(ltt_buf);
+ /* Test new buffer integrity */
+ reserve_commit_diff =
+ atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_begin,
+ ltt_buf)])
+ - atomic_read(<t_buf->commit_count[SUBBUF_INDEX(offset_begin,
+ ltt_buf)]);
+
+ if(reserve_commit_diff == 0) {
+ /* Next buffer not corrupted. */
+ //if((SUBBUF_TRUNC(offset_begin, ltt_buf)
+ // - SUBBUF_TRUNC(atomic_read(<t_buf->consumed), ltt_buf))
+ // >= ltt_buf->alloc_size) {
+ {
+ /* sem_wait is not signal safe. Disable signals around it.
+ * Signals are kept disabled to make sure we win the cmpxchg. */
+ /* Disable signals */
+ ret = sigfillset(&set);
+ if(ret) perror("LTT Error in sigfillset\n");
+
+ ret = pthread_sigmask(SIG_BLOCK, &set, &oldset);
+ if(ret) perror("LTT Error in pthread_sigmask\n");
+
+ /* We detect if a signal came between
+ * the offset read and signal disabling:
+ * if it is the case, then we restart
+ * the loop after reenabling signals. It
+ * means that it's a signal that has
+ * won the buffer switch.*/
+ if(offset_old != atomic_read(<t_buf->offset)) {
+ ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+ if(ret) perror("LTT Error in pthread_sigmask\n");
+ continue;
+ }
+ /* If the offset is still the same, then
+ * we can safely proceed to do the
+ * buffer switch without being
+ * interrupted by a signal. */
+ sem_wait(<t_buf->writer_sem);
+
+ }
+ /* go on with the write */
+
+ //} else {
+ // /* next buffer not corrupted, we are either in overwrite mode or
+ // * the buffer is not full. It's safe to write in this new subbuffer.*/
+ //}
+ } else {
+ /* Next subbuffer corrupted. Force pushing reader even in normal
+ * mode. It's safe to write in this new subbuffer. */
+ /* No sem_post is required because we fall through without doing a
+ * sem_wait. */
+ }
+ size = ltt_get_header_size(trace, ltt_buf->start + offset_begin,
+ data_size, &before_hdr_pad) + data_size;
+ if((SUBBUF_OFFSET(offset_begin,ltt_buf)+size)>ltt_buf->subbuf_size) {
+ /* Event too big for subbuffers, report error, don't complete
+ * the sub-buffer switch. */
+ atomic_inc(<t_buf->events_lost);
+ if(reserve_commit_diff == 0) {
+ ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+ if(ret) perror("LTT Error in pthread_sigmask\n");
+ }
+ return NULL;
+ } else {
+ /* We just made a successful buffer switch and the event fits in the
+ * new subbuffer. Let's write. */
+ }
+ } else {
+ /* Event fits in the current buffer and we are not on a switch boundary.
+ * It's safe to write */
+ }
+ offset_end = offset_begin + size;
+
+ if((SUBBUF_OFFSET(offset_end, ltt_buf)) == 0) {
+ /* The offset_end will fall at the very beginning of the next subbuffer.
+ */
+ end_switch_current = 1; /* For offset_begin */
+ }
+
+ } while(atomic_cmpxchg(<t_buf->offset, offset_old, offset_end)
+ != offset_old);
+
+ /* Push the reader if necessary */
+ do {
+ consumed_old = atomic_read(<t_buf->consumed);
+ /* If buffer is in overwrite mode, push the reader consumed count if
+ the write position has reached it and we are not at the first
+ iteration (don't push the reader farther than the writer).
+ This operation can be done concurrently by many writers in the
+ same buffer, the writer being at the fartest write position sub-buffer
+ index in the buffer being the one which will win this loop. */
+ /* If the buffer is not in overwrite mode, pushing the reader only
+ happen if a sub-buffer is corrupted */
+ if((SUBBUF_TRUNC(offset_end-1, ltt_buf)
+ - SUBBUF_TRUNC(consumed_old, ltt_buf))
+ >= ltt_buf->alloc_size)
+ consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf);
+ else {
+ consumed_new = consumed_old;
+ break;
+ }
+ } while(atomic_cmpxchg(<t_buf->consumed, consumed_old, consumed_new)
+ != consumed_old);
+
+ if(consumed_old != consumed_new) {
+ /* Reader pushed : we are the winner of the push, we can therefore
+ reequilibrate reserve and commit. Atomic increment of the commit
+ count permits other writers to play around with this variable
+ before us. We keep track of corrupted_subbuffers even in overwrite mode :
+ we never want to write over a non completely committed sub-buffer :
+ possible causes : the buffer size is too low compared to the unordered
+ data input, or there is a writer who died between the reserve and the
+ commit. */
+ if(reserve_commit_diff) {
+ /* We have to alter the sub-buffer commit count : a sub-buffer is
+ corrupted. We do not deliver it. */
+ atomic_add(reserve_commit_diff,
+ <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
+ atomic_inc(<t_buf->corrupted_subbuffers);
+ }
+ }
+
+
+ if(end_switch_old) {
+ /* old subbuffer */
+ /* Concurrency safe because we are the last and only thread to alter this
+ sub-buffer. As long as it is not delivered and read, no other thread can
+ alter the offset, alter the reserve_count or call the
+ client_buffer_end_callback on this sub-buffer.
+ The only remaining threads could be the ones with pending commits. They
+ will have to do the deliver themself.
+ Not concurrency safe in overwrite mode. We detect corrupted subbuffers
+ with commit and reserve counts. We keep a corrupted sub-buffers count
+ and push the readers across these sub-buffers.
+ Not concurrency safe if a writer is stalled in a subbuffer and
+ another writer switches in, finding out it's corrupted. The result will
+ be than the old (uncommited) subbuffer will be declared corrupted, and
+ that the new subbuffer will be declared corrupted too because of the
+ commit count adjustment.
+ Note : offset_old should never be 0 here.*/
+ ltt_buffer_end_callback(ltt_buf, *tsc, offset_old,
+ SUBBUF_INDEX((offset_old-1), ltt_buf));
+ /* Setting this reserve_count will allow the sub-buffer to be delivered by
+ the last committer. */
+ reserve_count =
+ atomic_add_return((SUBBUF_OFFSET((offset_old-1), ltt_buf)+1),
+ <t_buf->reserve_count[SUBBUF_INDEX((offset_old-1), ltt_buf)]);
+ if(reserve_count
+ == atomic_read(<t_buf->commit_count[SUBBUF_INDEX((offset_old-1),
+ ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_old-1), ltt_buf),
+ NULL);
+ }
+ }
+
+ if(begin_switch) {
+ /* Enable signals : this is what guaranteed that same reserve which did the
+ * sem_wait does in fact win the cmpxchg for the offset. We only call
+ * these system calls on buffer boundaries because of their performance
+ * cost. */
+ if(reserve_commit_diff == 0) {
+ ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+ if(ret) perror("LTT Error in pthread_sigmask\n");
+ }
+ /* New sub-buffer */
+ /* This code can be executed unordered : writers may already have written
+ to the sub-buffer before this code gets executed, caution. */
+ /* The commit makes sure that this code is executed before the deliver
+ of this sub-buffer */
+ ltt_buffer_begin_callback(ltt_buf, *tsc, SUBBUF_INDEX(offset_begin, ltt_buf));
+ commit_count = atomic_add_return(ltt_subbuf_header_len(ltt_buf),
+ <t_buf->commit_count[SUBBUF_INDEX(offset_begin, ltt_buf)]);
+ /* Check if the written buffer has to be delivered */
+ if(commit_count
+ == atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_begin,
+ ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_begin, ltt_buf), NULL);
+ }
+ }
+
+ if(end_switch_current) {
+ /* current subbuffer */
+ /* Concurrency safe because we are the last and only thread to alter this
+ sub-buffer. As long as it is not delivered and read, no other thread can
+ alter the offset, alter the reserve_count or call the
+ client_buffer_end_callback on this sub-buffer.
+ The only remaining threads could be the ones with pending commits. They
+ will have to do the deliver themself.
+ Not concurrency safe in overwrite mode. We detect corrupted subbuffers
+ with commit and reserve counts. We keep a corrupted sub-buffers count
+ and push the readers across these sub-buffers.
+ Not concurrency safe if a writer is stalled in a subbuffer and
+ another writer switches in, finding out it's corrupted. The result will
+ be than the old (uncommited) subbuffer will be declared corrupted, and
+ that the new subbuffer will be declared corrupted too because of the
+ commit count adjustment. */
+ ltt_buffer_end_callback(ltt_buf, *tsc, offset_end,
+ SUBBUF_INDEX((offset_end-1), ltt_buf));
+ /* Setting this reserve_count will allow the sub-buffer to be delivered by
+ the last committer. */
+ reserve_count =
+ atomic_add_return((SUBBUF_OFFSET((offset_end-1), ltt_buf)+1),
+ <t_buf->reserve_count[SUBBUF_INDEX((offset_end-1), ltt_buf)]);
+ if(reserve_count
+ == atomic_read(<t_buf->commit_count[SUBBUF_INDEX((offset_end-1),
+ ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX((offset_end-1), ltt_buf), NULL);
+ }
+ }
+
+ *slot_size = size;
+
+ //BUG_ON(*slot_size != (data_size + *before_hdr_pad + *after_hdr_pad + *header_size));
+ //BUG_ON(*slot_size != (offset_end - offset_begin));
+
+ return ltt_buf->start + BUFFER_OFFSET(offset_begin, ltt_buf) + before_hdr_pad;
+}
+
+
+/* ltt_commit_slot
+ *
+ * Atomic unordered slot commit. Increments the commit count in the
+ * specified sub-buffer, and delivers it if necessary.
+ *
+ * Parameters:
+ *
+ * @buf : the buffer to commit to.
+ * @reserved : address of the end of the event header.
+ * @slot_size : size of the reserved slot.
+ *
+ */
+static inline void __attribute__((no_instrument_function)) ltt_commit_slot(
+ struct ltt_buf *ltt_buf,
+ void *reserved,
+ unsigned int slot_size)
+{
+ unsigned int offset_end = reserved - ltt_buf->start;
+ int commit_count;
+
+ commit_count = atomic_add_return(slot_size,
+ <t_buf->commit_count[SUBBUF_INDEX(offset_end-1,
+ ltt_buf)]);
+
+ /* Check if all commits have been done */
+ if(commit_count ==
+ atomic_read(<t_buf->reserve_count[SUBBUF_INDEX(offset_end-1, ltt_buf)])) {
+ ltt_deliver_callback(ltt_buf, SUBBUF_INDEX(offset_end-1, ltt_buf), NULL);
+ }
+}
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif //LTT_TRACE_FAST
+#endif //LTT_TRACE
+#endif //_LTT_USERTRACE_FAST_H
--- /dev/null
+/*
+ * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
+ */
+#ifndef __LTT_USERTRACE_PPC_H
+#define __LTT_USERTRACE_PPC_H
+
+#ifdef __powerpc64__
+#include <ltt/atomic-ppc64.h>
+#include <ltt/system-ppc64.h>
+#else
+#include <ltt/ppc_asm-ppc.h>
+#include <ltt/atomic-ppc.h>
+#include <ltt/system-ppc.h>
+#include <ltt/timex-ppc.h>
+#endif
+
+
+#endif /* __LTT_USERTRACE_PPC_H */
--- /dev/null
+/*****************************************************************************
+ * ltt-usertrace.h
+ *
+ * LTT userspace tracing header
+ *
+ * Mathieu Desnoyers, March 2006
+ */
+
+#ifndef _LTT_USERTRACE_H
+#define _LTT_USERTRACE_H
+
+#include <errno.h>
+#include <syscall.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define inline inline __attribute__((always_inline))
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+#ifdef __powerpc64__
+#include <ltt/atomic-ppc64.h>
+#include <ltt/system-ppc64.h>
+#include <asm/timex.h>
+#else
+#include <ltt/ppc_asm-ppc.h>
+#include <ltt/atomic-ppc.h>
+#include <ltt/system-ppc.h>
+#include <ltt/timex-ppc.h>
+#endif
+#elif defined(__x86_64__)
+#include <ltt/kernelutils-x86_64.h>
+#elif defined(__i386__)
+#include <ltt/kernelutils-i386.h>
+#elif defined(__arm__)
+#include <ltt/kernelutils-arm.h>
+#elif defined(__SH4__)
+#include <ltt/kernelutils-sh.h>
+#else
+#error "Unsupported architecture"
+#endif
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifdef i386
+#define __NR_ltt_trace_generic 328
+#define __NR_ltt_register_generic 329
+#undef NR_syscalls
+#define NR_syscalls 330
+#endif
+
+#ifdef __x86_64__
+#define __NR_ltt_trace_generic 286
+#define __NR_ltt_register_generic 287
+#undef NR_syscalls
+#define NR_syscalls 288
+#endif
+
+#ifdef __powerpc__
+#define __NR_ltt_trace_generic 309
+#define __NR_ltt_register_generic 310
+#undef NR_syscalls
+#define NR_syscalls 311
+#endif
+
+#ifdef __powerpc64__
+#define __NR_ltt_trace_generic 309
+#define __NR_ltt_register_generic 310
+#undef NR_syscalls
+#define NR_syscalls 311
+#endif
+
+#ifdef __arm__
+#define __NR_ltt_trace_generic 352
+#define __NR_ltt_register_generic 353
+#undef NR_syscalls
+#define NR_syscalls 354
+#endif
+
+//FIXME : setup for MIPS
+
+#ifndef _LIBC
+// Put in bits/syscall.h
+#define SYS_ltt_trace_generic __NR_ltt_trace_generic
+#define SYS_ltt_register_generic __NR_ltt_register_generic
+#endif
+
+#define FACNAME_LEN 32
+
+/* LTT userspace tracing is non blocking by default when buffers are full */
+#ifndef LTT_BLOCKING
+#define LTT_BLOCKING 0
+#endif //LTT_BLOCKING
+
+typedef unsigned int ltt_facility_t;
+
+struct user_facility_info {
+ char name[FACNAME_LEN];
+ uint32_t num_events;
+ uint32_t alignment;
+ uint32_t checksum;
+ uint32_t int_size;
+ uint32_t long_size;
+ uint32_t pointer_size;
+ uint32_t size_t_size;
+};
+#if 0
+static inline __attribute__((no_instrument_function))
+_syscall5(int, ltt_trace_generic, unsigned int, facility_id,
+ unsigned int, event_id, void *, data, size_t, data_size, int, blocking)
+static inline __attribute__((no_instrument_function))
+_syscall2(int, ltt_register_generic, unsigned int *, facility_id,
+ const struct user_facility_info *, info)
+#endif //0
+
+#define ltt_register_generic(...) syscall(__NR_ltt_register_generic, __VA_ARGS__)
+#define ltt_trace_generic(...) syscall(__NR_ltt_trace_generic, __VA_ARGS__)
+
+static inline unsigned int __attribute__((no_instrument_function))
+ ltt_align(size_t align_drift, size_t size_of_type);
+
+#ifndef LTT_PACK
+/* Calculate the offset needed to align the type */
+static inline unsigned int
+ ltt_align(size_t align_drift, size_t size_of_type)
+{
+ size_t alignment = min(sizeof(void*), size_of_type);
+
+ return ((alignment - align_drift) & (alignment-1));
+}
+#define LTT_ALIGN
+#else
+static inline unsigned int ltt_align(size_t align_drift, size_t size_of_type)
+{
+ return 0;
+}
+#define LTT_ALIGN __attribute__((packed))
+#endif //LTT_PACK
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#ifdef LTT_TRACE_FAST
+#include <ltt/ltt-usertrace-fast.h>
+#endif //LTT_TRACE_FAST
+
+#endif //_LTT_USERTRACE_H
--- /dev/null
+/*
+ * include/asm-ppc/ppc_asm.h
+ *
+ * Definitions used by various bits of low-level assembly code on PowerPC.
+ *
+ * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _PPC_ASM_PPC_H
+#define _PPC_ASM_PPC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Macros for storing registers into and loading registers from
+ * exception frames.
+ */
+#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
+#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
+#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
+#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
+#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
+#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
+#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
+#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
+#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
+#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
+
+#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
+ SAVE_10GPRS(22, base)
+#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
+ REST_10GPRS(22, base)
+
+#define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*(n)(base)
+#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
+#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
+#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
+#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
+#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
+#define REST_FPR(n, base) lfd n,THREAD_FPR0+8*(n)(base)
+#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
+#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
+#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
+#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
+#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
+
+#define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
+#define SAVE_2VR(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
+#define SAVE_4VR(n,b,base) SAVE_2VR(n,b,base); SAVE_2VR(n+2,b,base)
+#define SAVE_8VR(n,b,base) SAVE_4VR(n,b,base); SAVE_4VR(n+4,b,base)
+#define SAVE_16VR(n,b,base) SAVE_8VR(n,b,base); SAVE_8VR(n+8,b,base)
+#define SAVE_32VR(n,b,base) SAVE_16VR(n,b,base); SAVE_16VR(n+16,b,base)
+#define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
+#define REST_2VR(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
+#define REST_4VR(n,b,base) REST_2VR(n,b,base); REST_2VR(n+2,b,base)
+#define REST_8VR(n,b,base) REST_4VR(n,b,base); REST_4VR(n+4,b,base)
+#define REST_16VR(n,b,base) REST_8VR(n,b,base); REST_8VR(n+8,b,base)
+#define REST_32VR(n,b,base) REST_16VR(n,b,base); REST_16VR(n+16,b,base)
+
+#define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
+#define SAVE_2EVR(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
+#define SAVE_4EVR(n,s,base) SAVE_2EVR(n,s,base); SAVE_2EVR(n+2,s,base)
+#define SAVE_8EVR(n,s,base) SAVE_4EVR(n,s,base); SAVE_4EVR(n+4,s,base)
+#define SAVE_16EVR(n,s,base) SAVE_8EVR(n,s,base); SAVE_8EVR(n+8,s,base)
+#define SAVE_32EVR(n,s,base) SAVE_16EVR(n,s,base); SAVE_16EVR(n+16,s,base)
+
+#define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
+#define REST_2EVR(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
+#define REST_4EVR(n,s,base) REST_2EVR(n,s,base); REST_2EVR(n+2,s,base)
+#define REST_8EVR(n,s,base) REST_4EVR(n,s,base); REST_4EVR(n+4,s,base)
+#define REST_16EVR(n,s,base) REST_8EVR(n,s,base); REST_8EVR(n+8,s,base)
+#define REST_32EVR(n,s,base) REST_16EVR(n,s,base); REST_16EVR(n+16,s,base)
+
+#ifdef CONFIG_PPC601_SYNC_FIX
+#define SYNC \
+BEGIN_FTR_SECTION \
+ sync; \
+ isync; \
+END_FTR_SECTION_IFSET(CPU_FTR_601)
+#define SYNC_601 \
+BEGIN_FTR_SECTION \
+ sync; \
+END_FTR_SECTION_IFSET(CPU_FTR_601)
+#define ISYNC_601 \
+BEGIN_FTR_SECTION \
+ isync; \
+END_FTR_SECTION_IFSET(CPU_FTR_601)
+#else
+#define SYNC
+#define SYNC_601
+#define ISYNC_601
+#endif
+
+#ifndef CONFIG_SMP
+#define TLBSYNC
+#else /* CONFIG_SMP */
+/* tlbsync is not implemented on 601 */
+#define TLBSYNC \
+BEGIN_FTR_SECTION \
+ tlbsync; \
+ sync; \
+END_FTR_SECTION_IFCLR(CPU_FTR_601)
+#endif
+
+/*
+ * This instruction is not implemented on the PPC 603 or 601; however, on
+ * the 403GCX and 405GP tlbia IS defined and tlbie is not.
+ * All of these instructions exist in the 8xx, they have magical powers,
+ * and they must be used.
+ */
+
+#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
+#define tlbia \
+ li r4,1024; \
+ mtctr r4; \
+ lis r4,KERNELBASE@h; \
+0: tlbie r4; \
+ addi r4,r4,0x1000; \
+ bdnz 0b
+#endif
+
+#ifdef CONFIG_BOOKE
+#define tophys(rd,rs) \
+ addis rd,rs,0
+
+#define tovirt(rd,rs) \
+ addis rd,rs,0
+
+#else /* CONFIG_BOOKE */
+/*
+ * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
+ * physical base address of RAM at compile time.
+ */
+#define tophys(rd,rs) \
+0: addis rd,rs,-KERNELBASE@h; \
+ .section ".vtop_fixup","aw"; \
+ .align 1; \
+ .long 0b; \
+ .previous
+
+#define tovirt(rd,rs) \
+0: addis rd,rs,KERNELBASE@h; \
+ .section ".ptov_fixup","aw"; \
+ .align 1; \
+ .long 0b; \
+ .previous
+#endif /* CONFIG_BOOKE */
+
+/*
+ * On 64-bit cpus, we use the rfid instruction instead of rfi, but
+ * we then have to make sure we preserve the top 32 bits except for
+ * the 64-bit mode bit, which we clear.
+ */
+#ifdef CONFIG_PPC64BRIDGE
+#define FIX_SRR1(ra, rb) \
+ mr rb,ra; \
+ mfmsr ra; \
+ clrldi ra,ra,1; /* turn off 64-bit mode */ \
+ rldimi ra,rb,0,32
+#define RFI .long 0x4c000024 /* rfid instruction */
+#define MTMSRD(r) .long (0x7c000164 + ((r) << 21)) /* mtmsrd */
+#define CLR_TOP32(r) rlwinm (r),(r),0,0,31 /* clear top 32 bits */
+
+#else
+#define FIX_SRR1(ra, rb)
+#ifndef CONFIG_40x
+#define RFI rfi
+#else
+#define RFI rfi; b . /* Prevent prefetch past rfi */
+#endif
+#define MTMSRD(r) mtmsr r
+#define CLR_TOP32(r)
+#endif /* CONFIG_PPC64BRIDGE */
+
+#define RFCI .long 0x4c000066 /* rfci instruction */
+#define RFDI .long 0x4c00004e /* rfdi instruction */
+#define RFMCI .long 0x4c00004c /* rfmci instruction */
+
+#ifdef CONFIG_IBM405_ERR77
+#define PPC405_ERR77(ra,rb) dcbt ra, rb;
+#define PPC405_ERR77_SYNC sync;
+#else
+#define PPC405_ERR77(ra,rb)
+#define PPC405_ERR77_SYNC
+#endif
+
+/* The boring bits... */
+
+/* Condition Register Bit Fields */
+
+#define cr0 0
+#define cr1 1
+#define cr2 2
+#define cr3 3
+#define cr4 4
+#define cr5 5
+#define cr6 6
+#define cr7 7
+
+
+/* General Purpose Registers (GPRs) */
+
+#define r0 0
+#define r1 1
+#define r2 2
+#define r3 3
+#define r4 4
+#define r5 5
+#define r6 6
+#define r7 7
+#define r8 8
+#define r9 9
+#define r10 10
+#define r11 11
+#define r12 12
+#define r13 13
+#define r14 14
+#define r15 15
+#define r16 16
+#define r17 17
+#define r18 18
+#define r19 19
+#define r20 20
+#define r21 21
+#define r22 22
+#define r23 23
+#define r24 24
+#define r25 25
+#define r26 26
+#define r27 27
+#define r28 28
+#define r29 29
+#define r30 30
+#define r31 31
+
+
+/* Floating Point Registers (FPRs) */
+
+#define fr0 0
+#define fr1 1
+#define fr2 2
+#define fr3 3
+#define fr4 4
+#define fr5 5
+#define fr6 6
+#define fr7 7
+#define fr8 8
+#define fr9 9
+#define fr10 10
+#define fr11 11
+#define fr12 12
+#define fr13 13
+#define fr14 14
+#define fr15 15
+#define fr16 16
+#define fr17 17
+#define fr18 18
+#define fr19 19
+#define fr20 20
+#define fr21 21
+#define fr22 22
+#define fr23 23
+#define fr24 24
+#define fr25 25
+#define fr26 26
+#define fr27 27
+#define fr28 28
+#define fr29 29
+#define fr30 30
+#define fr31 31
+
+#define vr0 0
+#define vr1 1
+#define vr2 2
+#define vr3 3
+#define vr4 4
+#define vr5 5
+#define vr6 6
+#define vr7 7
+#define vr8 8
+#define vr9 9
+#define vr10 10
+#define vr11 11
+#define vr12 12
+#define vr13 13
+#define vr14 14
+#define vr15 15
+#define vr16 16
+#define vr17 17
+#define vr18 18
+#define vr19 19
+#define vr20 20
+#define vr21 21
+#define vr22 22
+#define vr23 23
+#define vr24 24
+#define vr25 25
+#define vr26 26
+#define vr27 27
+#define vr28 28
+#define vr29 29
+#define vr30 30
+#define vr31 31
+
+#define evr0 0
+#define evr1 1
+#define evr2 2
+#define evr3 3
+#define evr4 4
+#define evr5 5
+#define evr6 6
+#define evr7 7
+#define evr8 8
+#define evr9 9
+#define evr10 10
+#define evr11 11
+#define evr12 12
+#define evr13 13
+#define evr14 14
+#define evr15 15
+#define evr16 16
+#define evr17 17
+#define evr18 18
+#define evr19 19
+#define evr20 20
+#define evr21 21
+#define evr22 22
+#define evr23 23
+#define evr24 24
+#define evr25 25
+#define evr26 26
+#define evr27 27
+#define evr28 28
+#define evr29 29
+#define evr30 30
+#define evr31 31
+
+/* some stab codes */
+#define N_FUN 36
+#define N_RSYM 64
+#define N_SLINE 68
+#define N_SO 100
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif //_PPC_ASM_PPC_H
--- /dev/null
+/*
+ * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
+ */
+#ifndef __PPC_SYSTEM_H
+#define __PPC_SYSTEM_H
+
+#include <asm/atomic.h>
+#include <asm/hw_irq.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Memory barrier.
+ * The sync instruction guarantees that all memory accesses initiated
+ * by this processor have been performed (with respect to all other
+ * mechanisms that access memory). The eieio instruction is a barrier
+ * providing an ordering (separately) for (a) cacheable stores and (b)
+ * loads and stores to non-cacheable memory (e.g. I/O devices).
+ *
+ * mb() prevents loads and stores being reordered across this point.
+ * rmb() prevents loads being reordered across this point.
+ * wmb() prevents stores being reordered across this point.
+ * read_barrier_depends() prevents data-dependent loads being reordered
+ * across this point (nop on PPC).
+ *
+ * We can use the eieio instruction for wmb, but since it doesn't
+ * give any ordering guarantees about loads, we have to use the
+ * stronger but slower sync instruction for mb and rmb.
+ */
+#define mb() __asm__ __volatile__ ("sync" : : : "memory")
+#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
+#define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
+#define read_barrier_depends() do { } while(0)
+
+#define set_mb(var, value) do { var = value; mb(); } while (0)
+#define set_wmb(var, value) do { var = value; wmb(); } while (0)
+
+#ifdef CONFIG_SMP
+#define smp_mb() mb()
+#define smp_rmb() rmb()
+#define smp_wmb() wmb()
+#define smp_read_barrier_depends() read_barrier_depends()
+#else
+#define smp_mb() barrier()
+#define smp_rmb() barrier()
+#define smp_wmb() barrier()
+#define smp_read_barrier_depends() do { } while(0)
+#endif /* CONFIG_SMP */
+
+static inline unsigned long
+xchg_u32(volatile void *p, unsigned long val)
+{
+ unsigned long prev;
+
+ __asm__ __volatile__ ("\n\
+1: lwarx %0,0,%2 \n"
+ PPC405_ERR77(0,%2)
+" stwcx. %3,0,%2 \n\
+ bne- 1b"
+ : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
+ : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
+ : "cc", "memory");
+
+ return prev;
+}
+
+/*
+ * This function doesn't exist, so you'll get a linker error
+ * if something tries to do an invalid xchg().
+ */
+extern void __xchg_called_with_bad_pointer(void);
+
+#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
+#define tas(ptr) (xchg((ptr),1))
+
+static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
+{
+ switch (size) {
+ case 4:
+ return (unsigned long) xchg_u32(ptr, x);
+#if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
+ case 8:
+ return (unsigned long) xchg_u64(ptr, x);
+#endif /* 0 */
+ }
+ __xchg_called_with_bad_pointer();
+ return x;
+
+
+}
+
+extern inline void * xchg_ptr(void * m, void * val)
+{
+ return (void *) xchg_u32(m, (unsigned long) val);
+}
+
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+static inline unsigned long
+__cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
+{
+ unsigned int prev;
+
+ __asm__ __volatile__ ("\n\
+1: lwarx %0,0,%2 \n\
+ cmpw 0,%0,%3 \n\
+ bne 2f \n"
+ PPC405_ERR77(0,%2)
+" stwcx. %4,0,%2 \n\
+ bne- 1b\n"
+#if 0 //only using one CPU at a time (LTT) // def CONFIG_SMP
+" sync\n"
+#endif /* CONFIG_SMP */
+"2:"
+ : "=&r" (prev), "=m" (*p)
+ : "r" (p), "r" (old), "r" (new), "m" (*p)
+ : "cc", "memory");
+
+ return prev;
+}
+
+/* This function doesn't exist, so you'll get a linker error
+ if something tries to do an invalid cmpxchg(). */
+extern void __cmpxchg_called_with_bad_pointer(void);
+
+static inline unsigned long
+__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
+{
+ switch (size) {
+ case 4:
+ return __cmpxchg_u32(ptr, old, new);
+#if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
+ case 8:
+ return __cmpxchg_u64(ptr, old, new);
+#endif /* 0 */
+ }
+ __cmpxchg_called_with_bad_pointer();
+ return old;
+}
+
+#define cmpxchg(ptr,o,n) \
+ ({ \
+ __typeof__(*(ptr)) _o_ = (o); \
+ __typeof__(*(ptr)) _n_ = (n); \
+ (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
+ (unsigned long)_n_, sizeof(*(ptr))); \
+ })
+
+#define arch_align_stack(x) (x)
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif /* __PPC_SYSTEM_H */
--- /dev/null
+#ifndef __PPC64_SYSTEM_H
+#define __PPC64_SYSTEM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+//#include <linux/config.h>
+//#include <linux/compiler.h>
+#include <asm/page.h>
+#include <asm/processor.h>
+#include <asm/hw_irq.h>
+#include <asm/memory.h>
+
+/*
+ * Memory barrier.
+ * The sync instruction guarantees that all memory accesses initiated
+ * by this processor have been performed (with respect to all other
+ * mechanisms that access memory). The eieio instruction is a barrier
+ * providing an ordering (separately) for (a) cacheable stores and (b)
+ * loads and stores to non-cacheable memory (e.g. I/O devices).
+ *
+ * mb() prevents loads and stores being reordered across this point.
+ * rmb() prevents loads being reordered across this point.
+ * wmb() prevents stores being reordered across this point.
+ * read_barrier_depends() prevents data-dependent loads being reordered
+ * across this point (nop on PPC).
+ *
+ * We have to use the sync instructions for mb(), since lwsync doesn't
+ * order loads with respect to previous stores. Lwsync is fine for
+ * rmb(), though.
+ * For wmb(), we use sync since wmb is used in drivers to order
+ * stores to system memory with respect to writes to the device.
+ * However, smp_wmb() can be a lighter-weight eieio barrier on
+ * SMP since it is only used to order updates to system memory.
+ */
+#define mb() __asm__ __volatile__ ("sync" : : : "memory")
+#define rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
+#define wmb() __asm__ __volatile__ ("sync" : : : "memory")
+#define read_barrier_depends() do { } while(0)
+
+#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
+#define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
+
+#ifdef CONFIG_SMP
+#define smp_mb() mb()
+#define smp_rmb() rmb()
+#define smp_wmb() __asm__ __volatile__ ("eieio" : : : "memory")
+#define smp_read_barrier_depends() read_barrier_depends()
+#else
+#define smp_mb() __asm__ __volatile__("": : :"memory")
+#define smp_rmb() __asm__ __volatile__("": : :"memory")
+#define smp_wmb() __asm__ __volatile__("": : :"memory")
+#define smp_read_barrier_depends() do { } while(0)
+#endif /* CONFIG_SMP */
+
+/*
+ * Atomic exchange
+ *
+ * Changes the memory location '*ptr' to be val and returns
+ * the previous value stored there.
+ *
+ * Inline asm pulled from arch/ppc/kernel/misc.S so ppc64
+ * is more like most of the other architectures.
+ */
+static inline unsigned long
+__xchg_u32(volatile int *m, unsigned long val)
+{
+ unsigned long dummy;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%3 # __xchg_u32\n\
+ stwcx. %2,0,%3\n\
+2: bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (dummy), "=m" (*m)
+ : "r" (val), "r" (m)
+ : "cc", "memory");
+
+ return (dummy);
+}
+
+static inline unsigned long
+__xchg_u64(volatile long *m, unsigned long val)
+{
+ unsigned long dummy;
+
+ __asm__ __volatile__(
+ EIEIO_ON_SMP
+"1: ldarx %0,0,%3 # __xchg_u64\n\
+ stdcx. %2,0,%3\n\
+2: bne- 1b"
+ ISYNC_ON_SMP
+ : "=&r" (dummy), "=m" (*m)
+ : "r" (val), "r" (m)
+ : "cc", "memory");
+
+ return (dummy);
+}
+
+/*
+ * This function doesn't exist, so you'll get a linker error
+ * if something tries to do an invalid xchg().
+ */
+extern void __xchg_called_with_bad_pointer(void);
+
+static inline unsigned long
+__xchg(volatile void *ptr, unsigned long x, int size)
+{
+ switch (size) {
+ case 4:
+ return __xchg_u32(ptr, x);
+ case 8:
+ return __xchg_u64(ptr, x);
+ }
+ __xchg_called_with_bad_pointer();
+ return x;
+}
+
+#define xchg(ptr,x) \
+ ({ \
+ __typeof__(*(ptr)) _x_ = (x); \
+ (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
+ })
+
+#define tas(ptr) (xchg((ptr),1))
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+static inline unsigned long
+__cmpxchg_u32(volatile int *p, int old, int new)
+{
+ unsigned int prev;
+
+ __asm__ __volatile__ (
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
+ cmpw 0,%0,%3\n\
+ bne- 2f\n\
+ stwcx. %4,0,%2\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ "\n\
+2:"
+ : "=&r" (prev), "=m" (*p)
+ : "r" (p), "r" (old), "r" (new), "m" (*p)
+ : "cc", "memory");
+
+ return prev;
+}
+
+static inline unsigned long
+__cmpxchg_u64(volatile long *p, unsigned long old, unsigned long new)
+{
+ unsigned long prev;
+
+ __asm__ __volatile__ (
+ EIEIO_ON_SMP
+"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
+ cmpd 0,%0,%3\n\
+ bne- 2f\n\
+ stdcx. %4,0,%2\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ "\n\
+2:"
+ : "=&r" (prev), "=m" (*p)
+ : "r" (p), "r" (old), "r" (new), "m" (*p)
+ : "cc", "memory");
+
+ return prev;
+}
+
+/* This function doesn't exist, so you'll get a linker error
+ if something tries to do an invalid cmpxchg(). */
+extern void __cmpxchg_called_with_bad_pointer(void);
+
+static inline unsigned long
+__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
+{
+ switch (size) {
+ case 4:
+ return __cmpxchg_u32(ptr, old, new);
+ case 8:
+ return __cmpxchg_u64(ptr, old, new);
+ }
+ __cmpxchg_called_with_bad_pointer();
+ return old;
+}
+
+#define cmpxchg(ptr,o,n) \
+ ({ \
+ __typeof__(*(ptr)) _o_ = (o); \
+ __typeof__(*(ptr)) _n_ = (n); \
+ (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
+ (unsigned long)_n_, sizeof(*(ptr))); \
+ })
+
+/*
+ * We handle most unaligned accesses in hardware. On the other hand
+ * unaligned DMA can be very expensive on some ppc64 IO chips (it does
+ * powers of 2 writes until it reaches sufficient alignment).
+ *
+ * Based on this we disable the IP header alignment in network drivers.
+ */
+#define NET_IP_ALIGN 0
+
+#define arch_align_stack(x) (x)
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif
--- /dev/null
+#ifndef __TIMEX_PPC_H
+#define __TIMEX_PPC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CPU_FTR_601 0x00000100
+
+#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
+
+typedef uint64_t cycles_t;
+
+/* On ppc64 this gets us the whole timebase; on ppc32 just the lower half */
+static inline unsigned long get_tbl(void)
+{
+ unsigned long tbl;
+
+//#if defined(CONFIG_403GCX)
+// asm volatile("mfspr %0, 0x3dd" : "=r" (tbl));
+//#else
+ asm volatile("mftb %0" : "=r" (tbl));
+//#endif
+ return tbl;
+}
+
+static inline unsigned int get_tbu(void)
+{
+ unsigned int tbu;
+
+//#if defined(CONFIG_403GCX)
+// asm volatile("mfspr %0, 0x3dc" : "=r" (tbu));
+//#else
+ asm volatile("mftbu %0" : "=r" (tbu));
+//#endif
+ return tbu;
+}
+
+static inline uint64_t get_tb(void)
+{
+ unsigned int tbhi, tblo, tbhi2;
+
+ do {
+ tbhi = get_tbu();
+ tblo = get_tbl();
+ tbhi2 = get_tbu();
+ } while (tbhi != tbhi2);
+
+ return ((uint64_t)tbhi << 32) | tblo;
+}
+
+static inline cycles_t get_cycles(void)
+{
+ return get_tb();
+}
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif //__TIMEX_PPC_H
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+int main(int argc, char **argv)
+{
+ printf("Will trace the following string : \"Hello world! Have a nice day.\"\n");
+ printf("every microsecond.\n");
+ printf("Abort with CTRL-C.\n");
+ printf("No file is created with this example : it logs through a kernel\n");
+ printf("system call. See the LTTng lttctl command to start tracing.\n");
+
+ while(1) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ usleep(1);
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_TRACE_FAST
+#include <ltt/ltt-facility-user_generic.h>
+
+
+int main(int argc, char **argv)
+{
+ printf("Will trace the following string : Running fast! in an infinite loop.\n");
+ printf("Abort with CTRL-C or it will quickly fill up your disk.\n");
+ printf("See the result file in /tmp/ltt-usertrace.\n");
+
+ int i;
+ while(1) {
+ trace_user_generic_string("Running fast!");
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+
+#include <stdio.h>
+#include <unistd.h>
+
+
+
+
+void test_function(void)
+{
+ printf("we are in a test function\n");
+}
+
+
+int main(int argc, char **argv)
+{
+ printf("Abort with CTRL-C.\n");
+ printf("See the result file in /tmp/ltt-usertrace.\n");
+
+
+ while(1) {
+ test_function();
+ sleep(1);
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+#include <ltt/ltt-facility-custom-user_generic.h>
+// Notice the inclusion of ltt-facility-custom-user_generic.h for the
+// slow_printf support
+
+
+int main(int argc, char **argv)
+{
+ printf("Will trace a printf of an incrementing counter.\n");
+ printf("Abort with CTRL-C.\n");
+ printf("No file is created with this example : it logs through a kernel\n");
+ printf("system call. See the LTTng lttctl command to start tracing.\n");
+
+ unsigned int count = 0;
+
+ while(1) {
+ trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
+ __FILE__, __func__, __LINE__, count);
+ count++;
+ sleep(1);
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+int main(int argc, char **argv)
+{
+ printf("Will create a branded thread\n");
+ trace_user_generic_thread_brand("Sample_brand");
+
+ sleep(2);
+
+ return 0;
+}
+
--- /dev/null
+
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define LTT_TRACE
+#define LTT_TRACE_FAST
+#include <ltt/ltt-facility-user_generic.h>
+
+
+void *thr1(void *arg)
+{
+ int i;
+ ltt_thread_init(); /* This init is not required : it will be done
+ automatically anyways at the first tracing call site */
+ printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+
+ for(i=0; i<100000; i++) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ }
+ pthread_exit((void*)1);
+}
+
+
+/* Example of a _bad_ thread, which still works with the tracing */
+void *thr2(void *arg)
+{
+ int i;
+ /* See ? no init */
+ printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+
+ for(i=0; i<100000; i++) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ }
+ /* This thread is a bad citizen : returning like this will cause its cancel
+ * routines not to be executed. This is still detected by the tracer, but only
+ * when the complete process dies. This is not recommended if you create a
+ * huge amount of threads */
+ return ((void*)2);
+}
+
+
+int main()
+{
+ int err;
+ pthread_t tid1, tid2;
+ void *tret;
+
+ printf("Will trace the following string : Hello world! Have a nice day.\n");
+ printf("It will stop automatically.\n");
+ printf("See the result file in /tmp/ltt-usertrace.\n");
+
+ printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ err = pthread_create(&tid1, NULL, thr1, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_create(&tid2, NULL, thr2, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_join(tid1, &tret);
+ if(err!= 0) exit(1);
+
+ err = pthread_join(tid2, &tret);
+ if(err!= 0) exit(1);
+
+ return 0;
+}
--- /dev/null
+
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define LTT_TRACE
+//this one is a non blocking sample (not #define LTT_BLOCKING 1)
+#include <ltt/ltt-facility-user_generic.h>
+
+
+void *thr1(void *arg)
+{
+ printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+
+ while(1) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ sleep(2);
+ }
+ pthread_exit((void*)1);
+}
+
+
+/* Example of a _bad_ thread, which still works with the tracing */
+void *thr2(void *arg)
+{
+ printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ sleep(1);
+ while(1) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ sleep(2);
+ }
+ return ((void*)2);
+}
+
+
+int main()
+{
+ int err;
+ pthread_t tid1, tid2;
+ void *tret;
+
+ printf("Will trace the following string : Hello world! Have a nice day.\n");
+ printf("Press CTRL-C to stop.\n");
+ printf("No file is created with this example : it logs through a kernel\n");
+ printf("system call. See the LTTng lttctl command to start tracing.\n\n");
+
+ printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ err = pthread_create(&tid1, NULL, thr1, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_create(&tid2, NULL, thr2, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_join(tid1, &tret);
+ if(err!= 0) exit(1);
+
+ err = pthread_join(tid2, &tret);
+ if(err!= 0) exit(1);
+
+ return 0;
+}
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+int main(int argc, char **argv)
+{
+ printf("Will trace the following string : \"Hello world! Have a nice day.\"\n");
+ printf("every second.\n");
+ printf("Abort with CTRL-C.\n");
+ printf("No file is created with this example : it logs through a kernel\n");
+ printf("system call. See the LTTng lttctl command to start tracing.\n");
+
+ while(1) {
+ trace_user_generic_string("Hello world! Have a nice day.");
+ sleep(1);
+ }
+
+ return 0;
+}
+
--- /dev/null
+#
+# Spec file for LTT Usertrace
+#
+Summary: Linux Trace Toolkit Userspace Tracing Package
+Name: ltt-usertrace
+Version: 0.13
+License: GPL
+Release: 1
+Group: Applications/Development
+Source: http://ltt.polymtl.ca/packages/%{name}-%{version}.tar.gz
+URL: http://ltt.polymtl.ca
+Packager: Martin Bisson <bissonm@discreet.com>
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+# Where do we install the libs
+%ifarch x86_64 ppc64 ppc64iseries ia64
+%define libdir /usr/lib64
+%else
+%define libdir /usr/lib
+%endif
+
+
+%description
+This packages makes it possible to do userspace tracing with the Linux
+Trace Toolkit.
+
+%prep
+%setup -q
+
+%build
+make libs
+
+%install
+rm -rf $RPM_BUILD_ROOT
+mkdir -p $RPM_BUILD_ROOT $RPM_BUILD_ROOT/usr/include $RPM_BUILD_ROOT/%{libdir}
+make INCLUDE_DIR=$RPM_BUILD_ROOT/usr/include LIB_DIR=$RPM_BUILD_ROOT/%{libdir} install
+
+%post
+echo "Running ldconfig (might take a while)"
+ldconfig
+
+%postun
+echo "Running ldconfig (might take a while)"
+ldconfig
+
+%files
+/usr/include/ltt
+/usr/include/ltt/atomic-ppc.h
+/usr/include/ltt/atomic-ppc64.h
+/usr/include/ltt/kernelutils-x86_64.h
+/usr/include/ltt/kernelutils-i386.h
+/usr/include/ltt/ltt-facility-custom-user_generic.h
+/usr/include/ltt/ltt-facility-id-user_generic.h
+/usr/include/ltt/ltt-facility-user_generic.h
+/usr/include/ltt/ltt-usertrace-fast.h
+/usr/include/ltt/ltt-usertrace-ppc.h
+/usr/include/ltt/ltt-usertrace.h
+/usr/include/ltt/ppc_asm-ppc.h
+/usr/include/ltt/system-ppc.h
+/usr/include/ltt/system-ppc64.h
+/usr/include/ltt/timex-ppc.h
+%{libdir}/libltt-instrument-functions.a
+%{libdir}/libltt-instrument-functions.so
+%{libdir}/libltt-instrument-functions.so.0
+%{libdir}/libltt-loader-user_generic.a
+%{libdir}/libltt-loader-user_generic.so
+%{libdir}/libltt-loader-user_generic.so.0
+%{libdir}/libltt-usertrace-fast.a
+%{libdir}/libltt-usertrace-fast.so
+%{libdir}/libltt-usertrace-fast.so.0
--- /dev/null
+
+LIB_DIR=/usr/lib
+INCLUDE_DIR=/usr/include
+
+RANLIB=ranlib
+
+CC=gcc
+CFLAGS=-I. -O3
+#CFLAGS+=-DLTT_SUBBUF_SIZE_CPU=134217728
+#CFLAGS+=-DLTT_NULL_OUTPUT_TEST
+
+all: test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so.0 sample-loop
+
+test: test.c ltt-usertrace-fast.c
+ $(CC) $(CFLAGS) -I. -lpthread -o $@ $^
+
+
+sample-instrument-fct: sample-instrument-fct.c
+ $(CC) $(CFLAGS) -L. -g -finstrument-functions -lltt-instrument-functions -o $@ $^
+
+sample-loop: sample-loop.c ltt-usertrace-fast.o ltt-facility-loader-user_generic.o
+ $(CC) $(CFLAGS) -L. -lpthread -g -o $@ $^
+
+libltt-instrument-functions.a: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
+ @rm -f libltt-instrument-functions.a
+ $(AR) rc $@ $^
+ $(RANLIB) $@
+
+libltt-instrument-functions.so.0: ltt-instrument-functions.o ltt-facility-loader-user_generic.o ltt-usertrace-fast.o
+ @rm -f libltt-instrument-functions.so libltt-instrument-functions.so.0
+ $(CC) $(CFLAGS) -lpthread -shared -Wl,-soname,libltt-instrument-functions.so -o $@ $^
+ ln -s libltt-instrument-functions.so.0 libltt-instrument-functions.so
+
+install:
+ if [ ! -e "$(INCLUDE_DIR)/ltt" ] ; then mkdir $(INCLUDE_DIR)/ltt ; fi
+ cp -f ltt/*.h $(INCLUDE_DIR)/ltt
+ cp -df libltt-instrument-functions.so* libltt-instrument-functions.a $(LIB_DIR)
+
+.PHONY : clean install
+
+clean:
+ rm -fr *.o *~ test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so*
--- /dev/null
+/*
+ * ltt-facility-loader-user_generic.c
+ *
+ * (C) Copyright 2005 -
+ * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
+ *
+ * Contains the LTT user space facility loader.
+ *
+ */
+
+
+#define LTT_TRACE
+#include <error.h>
+#include <stdio.h>
+#include <ltt/ltt-generic.h>
+#include "ltt-facility-loader-user_generic.h"
+
+static struct user_facility_info facility = {
+ .name = LTT_FACILITY_NAME,
+ .num_events = LTT_FACILITY_NUM_EVENTS,
+#ifndef LTT_PACK
+ .alignment = sizeof(void*),
+#else
+ .alignment = 0,
+#endif //LTT_PACK
+ .checksum = LTT_FACILITY_CHECKSUM,
+ .int_size = sizeof(int),
+ .long_size = sizeof(long),
+ .pointer_size = sizeof(void*),
+ .size_t_size = sizeof(size_t)
+};
+
+static void __attribute__((constructor)) __ltt_user_init(void)
+{
+ int err;
+#ifdef LTT_SHOW_DEBUG
+ printf("LTT : ltt-facility-user_generic init in userspace\n");
+#endif //LTT_SHOW_DEBUG
+
+ err = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);
+ LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
+
+ if(err) {
+#ifdef LTT_SHOW_DEBUG
+ perror("Error in ltt_register_generic");
+#endif //LTT_SHOW_DEBUG
+ }
+}
+
--- /dev/null
+#ifndef _LTT_FACILITY_LOADER_USER_GENERIC_H_
+#define _LTT_FACILITY_LOADER_USER_GENERIC_H_
+
+#include <ltt/ltt-generic.h>
+#include <ltt/ltt-facility-id-user_generic.h>
+
+ltt_facility_t ltt_facility_user_generic;
+ltt_facility_t ltt_facility_user_generic_F583779E;
+
+#define LTT_FACILITY_SYMBOL ltt_facility_user_generic
+#define LTT_FACILITY_CHECKSUM_SYMBOL ltt_facility_user_generic_F583779E
+#define LTT_FACILITY_CHECKSUM 0xF583779E
+#define LTT_FACILITY_NAME "user_generic"
+#define LTT_FACILITY_NUM_EVENTS facility_user_generic_num_events
+
+#endif //_LTT_FACILITY_LOADER_USER_GENERIC_H_
--- /dev/null
+
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+void test_function(void)
+{
+ printf("we are in a test function\n");
+}
+
+
+int main(int argc, char **argv)
+{
+ while(1) {
+ test_function();
+ sleep(1);
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <ltt/ltt-usertrace-fast.h>
+
+
+
+void *thr1(void *arg)
+{
+ int i;
+ ltt_thread_init();
+ printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+
+ //while(1) {}
+ for(i=0; i<5; i++) {
+ // ltt_usertrace_fast_buffer_switch();
+ sleep(1);
+ }
+
+ //return ((void*)1);
+ pthread_exit((void*)1);
+}
+
+void *thr2(void *arg)
+{
+ int i;
+ ltt_thread_init();
+ //while(1) {
+ printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ sleep(2);
+ //}
+ for(i=0; i<2; i++) {
+ // ltt_usertrace_fast_buffer_switch();
+ sleep(3);
+ }
+
+
+ return ((void*)2); /* testing "die" */
+ //pthread_exit((void*)2);
+}
+
+
+int main()
+{
+ int i;
+ int err;
+ pthread_t tid1, tid2;
+ void *tret;
+
+ printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ err = pthread_create(&tid1, NULL, thr1, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_create(&tid2, NULL, thr2, NULL);
+ if(err!=0) exit(1);
+
+ for(i=0; i<2; i++) {
+ // ltt_usertrace_fast_buffer_switch();
+ sleep(3);
+ }
+
+ err = pthread_join(tid1, &tret);
+ if(err!= 0) exit(1);
+
+ err = pthread_join(tid2, &tret);
+ if(err!= 0) exit(1);
+
+ return 0;
+}