1 /**
2 * Copyright (C) Mellanox Technologies Ltd. 2001-2015.  ALL RIGHTS RESERVED.
3 *
4 * See file LICENSE for terms.
5 */
6 
7 #ifndef TEST_PERF_H_
8 #define TEST_PERF_H_
9 
10 #include <common/test.h>
11 #include <tools/perf/api/libperf.h>
12 
13 
14 class test_perf {
15 protected:
16     struct test_spec {
17         const char             *title;
18         const char             *units;
19         ucx_perf_api_t         api;
20         ucx_perf_cmd_t         command;
21         ucx_perf_test_type_t   test_type;
22         int                    data_layout;
23         size_t                 msg_stride;
24         size_t                 msglencnt;
25         size_t                 msglen[3];
26         unsigned               max_outstanding;
27         size_t                 iters;
28         size_t                 field_offset;
29         double                 norm;
30         double                 min; /* TODO remove this field */
31         double                 max; /* TODO remove this field */
32         unsigned               test_flags;
33     };
34 
35     static std::vector<int> get_affinity();
36 
37     void run_test(const test_spec& test, unsigned flags, bool check_perf,
38                   const std::string &tl_name, const std::string &dev_name);
39 
40 private:
41     class rte_comm {
42     public:
43         rte_comm();
44 
45         void push(const void *data, size_t size);
46 
47         void pop(void *data, size_t size, void (*progress)(void *arg), void *arg);
48 
49     private:
50         pthread_mutex_t  m_mutex;
51         std::string      m_queue;
52     };
53 
54     class rte {
55     public:
56         /* RTE functions */
57         rte(unsigned index, rte_comm& send, rte_comm& recv);
58 
59         unsigned index() const;
60 
61         static unsigned group_size(void *rte_group);
62 
63         static unsigned group_index(void *rte_group);
64 
65         static void barrier(void *rte_group, void (*progress)(void *arg),
66                             void *arg);
67 
68         static void post_vec(void *rte_group, const struct iovec *iovec,
69                              int iovcnt, void **req);
70 
71         static void recv(void *rte_group, unsigned src, void *buffer,
72                          size_t max, void *req);
73 
74         static void exchange_vec(void *rte_group, void * req);
75 
76         static void report(void *rte_group, const ucx_perf_result_t *result,
77                            void *arg, int is_final, int is_multi_thread);
78 
79         static ucx_perf_rte_t test_rte;
80 
81     private:
82         const unsigned m_index;
83         rte_comm       &m_send;
84         rte_comm       &m_recv;
85     };
86 
87     struct thread_arg {
88         ucx_perf_params_t   params;
89         int                 cpu;
90     };
91 
92     struct test_result {
93         ucs_status_t        status;
94         ucx_perf_result_t   result;
95     };
96 
97     static void set_affinity(int cpu);
98 
99     static void* thread_func(void *arg);
100 
101     test_result run_multi_threaded(const test_spec &test, unsigned flags,
102                                    const std::string &tl_name,
103                                    const std::string &dev_name,
104                                    const std::vector<int> &cpus);
105 };
106 
107 #endif
108