Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Stream_MGR.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #include "Posix_Wrapp.h"
20 
21 #include "Stream_MGR.h"
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 
28 
29 #include "Timer.h"
30 
31 
32 
33 __thread struct Stream_Infos * __trace_module = NULL;
34 
36 
37 
39 {
40  uint64_t ret = 0;
41 
43 
44  uint64_t my_rank = Stream_Manager()->rank;
45 
46  ret |= Stream_Manager()->partition_id << 56;
47  ret |= (my_rank & 0x00FFFFFFFFFFFFFFllu) << 32;
48  ret |= (Stream_Manager()->current_id++ & 0x00000000FFFFFFFFllu);
49 
51 
52  return ret;
53 }
54 
55 
57 {
58  Chained_List_init( &Stream_Manager()->streams, 64, sizeof( struct Stream_Infos ) );
60  Stream_Manager()->lock = 0;
61  PMPI_Comm_rank( VMPI_Get_partition_comm(), &Stream_Manager()->rank );
63 
64 }
65 
67 {
70  Stream_Manager()->lock = 0;
71  Stream_Manager()->rank = -1;
73 }
74 
75 
76 void Stream_Infos_init( struct Stream_Infos *infos )
77 {
78  memset( infos, 0, sizeof( struct Stream_Infos ) );
79  Buffered_FIFO_init( &infos->mpi_wrapped_event_buffer, 32, sizeof( struct MALP_Trace_Event ) );
80 }
81 
82 void Stream_Infos_release( struct Stream_Infos *infos )
83 {
85 }
86 
87 
88 
90 {
91 
92  struct MALP_Trace_Event tmp;
93  struct Stream_Infos infos;
94 
95  Stream_Infos_init( &infos );
96 
97  tmp.type = MALP_EVENT_META;
98  tmp.timestamp = Timer_tsc();
99  tmp.duration = 0;
100  tmp.tid = parent?parent->tid:0;
102 
103 
105 
106  if( parent )
107  {
108  tmp.event.stream_descriptor.parent_tid = parent->tid;
109  }
110  else
111  {
113  }
114 
117  tmp.event.stream_descriptor.type = type;
118 
119  tmp.event.stream_descriptor.start_time = Timer_tsc();
121 
124 
125  if( gethostname(tmp.event.stream_descriptor.hostname, 32) < 0 )
126  sprintf( tmp.event.stream_descriptor.hostname, "Unknown");
127 
128  Event_Packer_push( &tmp );
129 
130  // Copy the infos back tot he stream descriptor
131  infos.infos = tmp.event.stream_descriptor;
132 
133  void *pinfos = Chained_List_push( &Stream_Manager()->streams, (void *)&infos );
134 
135  return (struct Stream_Infos *)pinfos;
136 }
137 
139 {
140 
141  struct Stream_Infos *infos = Stream_infos_get();
142  struct Stream_Descriptor *desc = &infos->infos;
143 
144  struct MALP_Trace_Event tmp;
145 
146 
147  tmp.type = MALP_EVENT_META;
148  tmp.timestamp = Timer_tsc();
149  tmp.duration = 0;
150  tmp.tid = desc->tid;
152 
153 
154  tmp.event.stream_descriptor.tid = desc->tid;
158  tmp.event.stream_descriptor.type = desc->type;
159 
161  tmp.event.stream_descriptor.end_time = Timer_tsc();
162 
165 
166  TEST_LOAD_SYMBOL(gethostname);
167 
168  if( REAL(gethostname)(tmp.event.stream_descriptor.hostname, 32) < 0 )
169  sprintf( tmp.event.stream_descriptor.hostname, "Unknown");
170 
171 
172  Event_Packer_push( &tmp );
173 
174  Stream_Infos_release( infos );
175 
176  Stream_infos_set(NULL);
177 }
struct Stream_Descriptor infos
The stream descriptor.
Definition: Stream_MGR.h:103
uint64_t partition_id
The id of the partition.
Definition: Stream_MGR.h:46
struct Chained_List streams
The list of managed streams.
Definition: Stream_MGR.h:44
static struct Stream_Manager * Stream_Manager()
A getter for the stream manager.
Definition: Stream_MGR.h:60
void Stream_Infos_release(struct Stream_Infos *infos)
Releases a Stream_Infos.
Definition: Stream_MGR.c:82
uint64_t tid
id of the stream (see Stream_MGR_gen_id())
#define REAL(a)
Definition: Posix_Wrapp.h:81
uint64_t omp_thread
OpenMP thread id of the source of the stream.
Stream_type
enum defining the type of the source of the stream
The event contains meta data.
Definition: Event_Desc.h:44
struct Stream_Descriptor stream_descriptor
See Stream_Descriptor.
Definition: Event_Desc.h:72
uint64_t partition_id
The sender partition id.
Definition: Event_Desc.h:89
static MPI_Comm VMPI_Get_partition_comm()
Returns current partition's communicator.
Definition: VMPI.h:175
Struct defining a stream manager.
Definition: Stream_MGR.h:42
void Buffered_FIFO_release(struct Buffered_FIFO *fifo, void(*free_func)(void *))
releases a FIFO
void Event_Packer_push(struct MALP_Trace_Event *event)
Sends an event.
Definition: Event_Pack.c:141
Structure containing data related to a stream and intended to be sent as an event (see MALP_Trace_Eve...
struct Stream_Infos * Stream_MGR_new_stream(struct Stream_Descriptor *parent, Stream_type type)
Adds a stream into the current stream manager.
Definition: Stream_MGR.c:89
static void Chained_List_init(struct Chained_List *list, uint64_t chunk_size, size_t payload_size)
Initializes a Chained_List.
Definition: Chained_List.h:286
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
struct Stream_Infos * __trace_module
This is a global Stream_Infos (not shared between threads)
Definition: Stream_MGR.c:33
Struct defining an event.
Definition: Event_Desc.h:82
uint64_t partition_id
id of the partition (mpi program that the stream belongs to)
Structure describing a stream.
Definition: Stream_MGR.h:101
uint64_t duration
Duration.
Definition: Event_Desc.h:87
event is stream release
uint64_t mpi_rank
mpi rank of the source of the stream
struct Buffered_FIFO mpi_wrapped_event_buffer
FIFO of events for MPI calls.
Definition: Stream_MGR.h:105
MALP_Spinlock lock
the lock for concurrent access
Definition: Stream_MGR.h:48
static void * Chained_List_push(struct Chained_List *list, void *payload)
Adds an element to the list.
Definition: Chained_List.h:312
static struct Stream_Infos * Stream_infos_get()
Getter on the current Stream_Infos.
Definition: Stream_MGR.h:129
void Stream_Manager_init()
Initialises the manager for current MPI process.
Definition: Stream_MGR.c:56
MALP_Trace_event_type type
The type of the event.
Definition: Event_Desc.h:85
struct Stream_Manager __stream_Stream_Manager
The stream manager for current MPI process.
Definition: Stream_MGR.c:35
#define TEST_LOAD_SYMBOL(a)
Definition: Posix_Wrapp.h:83
uint64_t tid
The stream unique id.
Definition: Event_Desc.h:88
Stream_type type
the type of the source of the steram
uint64_t start_time
time at stream creation
MALP_Trace_event_t event
The event data.
Definition: Event_Desc.h:91
event is stream creation
void Stream_MGR_end_stream()
Signals end of stream.
Definition: Stream_MGR.c:138
uint64_t timestamp
Creation date.
Definition: Event_Desc.h:86
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
uint64_t Stream_MGR_gen_id()
Definition: Stream_MGR.c:38
int rank
the rank (within the partition
Definition: Stream_MGR.h:47
void Buffered_FIFO_init(struct Buffered_FIFO *fifo, uint64_t chunk_size, size_t elem_size)
Initializes a Buffered_FIFO.
static int VMPI_Get_partition_id()
Returns the unique ID of the current partition.
Definition: VMPI.h:142
static void Chained_List_release(struct Chained_List *list)
Clears a Chained_List.
Definition: Chained_List.h:298
char hostname[32]
name of the host running the source of the stream
void Stream_Infos_init(struct Stream_Infos *infos)
Initializes a Stream_Infos.
Definition: Stream_MGR.c:76
Stream_Descriptor_type desc_type
identifies whether this is a stream creation or release event
static void Stream_infos_set(struct Stream_Infos *sd)
Setter on the current Stream_Infos.
Definition: Stream_MGR.h:138
void Stream_Manager_release()
Releases the manager for current MPI process (including all streams )
Definition: Stream_MGR.c:66
uint64_t current_id
a globally unique id for the streams
Definition: Stream_MGR.h:45
uint64_t end_time
time at stream release
uint64_t parent_tid
id of parent stream