2
* Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
4
* This software is available to you under a choice of one of two
5
* licenses. You may choose to be licensed under the terms of the GNU
6
* General Public License (GPL) Version 2, available from the file
7
* COPYING in the main directory of this source tree, or the
8
* OpenIB.org BSD license below:
10
* Redistribution and use in source and binary forms, with or
11
* without modification, are permitted provided that the following
14
* - Redistributions of source code must retain the above
15
* copyright notice, this list of conditions and the following
18
* - Redistributions in binary form must reproduce the above
19
* copyright notice, this list of conditions and the following
20
* disclaimer in the documentation and/or other materials
21
* provided with the distribution.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
* IB Management Simulator MAD Dispatcher: Worker Threads and MAD Queue
43
* The simulator stores incoming mads in a special queue that provides
44
* randomization of transport time. A group of worker threads is responsible
45
* to pop mad messages from the queue, route them to the destination nodes
46
* and call their mad processor.
49
* Eitan Zahavi, Mellanox
58
class IBMSDispatcher {
61
class IBMSNode *pFromNode; /* the node the mad was injected from */
62
uint8_t fromPort; /* the port number the mad was injected from */
63
ibms_mad_msg_t madMsg; /* the mad message */
66
typedef std::multimap<uint64_t, struct madItem > mmap_uint64_mad;
67
typedef std::list< struct madItem > mad_list;
69
/* we track our worker threads and timer in the array of sub-threads */
72
/* the queue of mads waiting for processing */
73
mmap_uint64_mad madQueueByWakeup;
75
/* lock to synchronize popping up and pushing into the madQueueByWakeup */
76
pthread_mutex_t madQueueByWakeupLock;
78
/* list of mads waiting for dispatching */
79
mad_list madDispatchQueue;
81
/* lock to synchronize popping and pushing into mad dispatch list */
82
pthread_mutex_t madDispatchQueueLock;
84
/* signal the timer waits on - signaled when new mads are pushed into Q */
85
pthread_cond_t newMadIntoWaitQ;
87
/* signal the workers when new MAD moved to dispatch Q */
88
pthread_cond_t newMadIntoDispatchQ;
90
/* flag to tell the threads to exit */
93
/* average delay from introducing the mad to when it appear on the queue */
94
uint64_t avgDelay_usec;
96
/* deviation on the delay */
97
uint64_t stdDevDelay_usec;
99
/* route the mad to the destination by direct route */
100
int routeMadToDestByDR(madItem &item);
102
/* route the mad to the destination by dest lid */
103
int routeMadToDestByLid(madItem &item);
105
/* route a mad to the destination node. On the way can drop mads by
106
statistics and update the relevant port counters on the actual node. */
107
int routeMadToDest(madItem &item);
109
/* The callback function for the threads */
110
static void *workerCallback(void *context);
113
* The timer thread main - should signal the threads
114
* if there is an outstanding mad - or wait for next one
116
static void *timerCallback(void *context);
120
IBMSDispatcher(int numWorkers,
121
uint64_t delayAvg_usec, uint64_t delayStdDev_usec);
125
/* sets the average delay for a mad on the wire */
126
int setDelayAvg(uint64_t delayAvg_usec);
128
/* sets the deviation of the delay for a mad on the wire */
129
int setDelayStdDev(uint64_t delayStdDev_usec);
131
/* introduce a new mad to the dispatcher */
132
int dispatchMad(IBMSNode *pFromNode, uint8_t fromPort, ibms_mad_msg_t &msg);
136
#endif /* IBMS_WORKER_H */