~ubuntu-branches/ubuntu/raring/ibutils/raring-proposed

« back to all changes in this revision

Viewing changes to ibmgtsim/src/dispatcher.h

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-01-11 22:22:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100111222200-53kum2et5nh13rv3
Tags: upstream-1.2-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.2-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
 
3
 *
 
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:
 
9
 *
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 *
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 *
 
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.
 
22
 *
 
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
 
30
 * SOFTWARE.
 
31
 *
 
32
 * $Id$
 
33
 */
 
34
 
 
35
#ifndef IBMS_WORKER_H
 
36
#define IBMS_WORKER_H
 
37
 
 
38
/****h* IBMS/Worker
 
39
* NAME
 
40
*       IB Management Simulator MAD Dispatcher: Worker Threads and MAD Queue
 
41
*
 
42
* DESCRIPTION
 
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.
 
47
*
 
48
* AUTHOR
 
49
*       Eitan Zahavi, Mellanox
 
50
*
 
51
*********/
 
52
 
 
53
#include "simmsg.h"
 
54
#include <map>
 
55
#include <list>
 
56
#include <pthread.h>
 
57
 
 
58
class IBMSDispatcher {
 
59
 
 
60
  struct madItem {
 
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 */
 
64
  };
 
65
 
 
66
  typedef std::multimap<uint64_t, struct madItem > mmap_uint64_mad;
 
67
  typedef std::list< struct madItem > mad_list;
 
68
 
 
69
  /* we track our worker threads and timer in the array of sub-threads */
 
70
  pthread_t *threads;
 
71
 
 
72
  /* the queue of mads waiting for processing */
 
73
  mmap_uint64_mad madQueueByWakeup;
 
74
 
 
75
  /* lock to synchronize popping up and pushing into the madQueueByWakeup */
 
76
  pthread_mutex_t madQueueByWakeupLock;
 
77
 
 
78
  /* list of mads waiting for dispatching */
 
79
  mad_list madDispatchQueue;
 
80
 
 
81
  /* lock to synchronize popping and pushing into mad dispatch list */
 
82
  pthread_mutex_t madDispatchQueueLock;
 
83
 
 
84
  /* signal the timer waits on - signaled when new mads are pushed into Q */
 
85
  pthread_cond_t newMadIntoWaitQ;
 
86
 
 
87
  /* signal the workers when new MAD moved to dispatch Q */
 
88
  pthread_cond_t newMadIntoDispatchQ;
 
89
 
 
90
  /* flag to tell the threads to exit */
 
91
  boolean_t exit_now;
 
92
 
 
93
  /* average delay from introducing the mad to when it appear on the queue */
 
94
  uint64_t avgDelay_usec;
 
95
 
 
96
  /* deviation on the delay */
 
97
  uint64_t stdDevDelay_usec;
 
98
 
 
99
  /* route the mad to the destination by direct route */
 
100
  int routeMadToDestByDR(madItem &item);
 
101
 
 
102
  /* route the mad to the destination by dest lid */
 
103
  int routeMadToDestByLid(madItem &item);
 
104
 
 
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);
 
108
 
 
109
  /* The callback function for the threads */
 
110
  static void *workerCallback(void *context);
 
111
 
 
112
  /*
 
113
        * The timer thread main - should signal the threads
 
114
        * if there is an outstanding mad - or wait for next one
 
115
        */
 
116
  static void *timerCallback(void *context);
 
117
 
 
118
 public:
 
119
  /* constructor */
 
120
  IBMSDispatcher(int numWorkers,
 
121
                 uint64_t delayAvg_usec, uint64_t delayStdDev_usec);
 
122
 
 
123
  ~IBMSDispatcher();
 
124
 
 
125
  /* sets the average delay for a mad on the wire */
 
126
  int   setDelayAvg(uint64_t delayAvg_usec);
 
127
 
 
128
  /* sets the deviation of the delay for a mad on the wire */
 
129
  int   setDelayStdDev(uint64_t delayStdDev_usec);
 
130
 
 
131
  /* introduce a new mad to the dispatcher */
 
132
  int dispatchMad(IBMSNode *pFromNode, uint8_t fromPort, ibms_mad_msg_t &msg);
 
133
 
 
134
};
 
135
 
 
136
#endif /* IBMS_WORKER_H */