Blame psm_perf.h

Packit Service 155747
/*
Packit Service 155747
Packit Service 155747
  This file is provided under a dual BSD/GPLv2 license.  When using or
Packit Service 155747
  redistributing this file, you may do so under either license.
Packit Service 155747
Packit Service 155747
  GPL LICENSE SUMMARY
Packit Service 155747
Packit Service 155747
  Copyright(c) 2017 Intel Corporation.
Packit Service 155747
Packit Service 155747
  This program is free software; you can redistribute it and/or modify
Packit Service 155747
  it under the terms of version 2 of the GNU General Public License as
Packit Service 155747
  published by the Free Software Foundation.
Packit Service 155747
Packit Service 155747
  This program is distributed in the hope that it will be useful, but
Packit Service 155747
  WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 155747
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 155747
  General Public License for more details.
Packit Service 155747
Packit Service 155747
  Contact Information:
Packit Service 155747
  Intel Corporation, www.intel.com
Packit Service 155747
Packit Service 155747
  BSD LICENSE
Packit Service 155747
Packit Service 155747
  Copyright(c) 2016 Intel Corporation.
Packit Service 155747
Packit Service 155747
  Redistribution and use in source and binary forms, with or without
Packit Service 155747
  modification, are permitted provided that the following conditions
Packit Service 155747
  are met:
Packit Service 155747
Packit Service 155747
    * Redistributions of source code must retain the above copyright
Packit Service 155747
      notice, this list of conditions and the following disclaimer.
Packit Service 155747
    * Redistributions in binary form must reproduce the above copyright
Packit Service 155747
      notice, this list of conditions and the following disclaimer in
Packit Service 155747
      the documentation and/or other materials provided with the
Packit Service 155747
      distribution.
Packit Service 155747
    * Neither the name of Intel Corporation nor the names of its
Packit Service 155747
      contributors may be used to endorse or promote products derived
Packit Service 155747
      from this software without specific prior written permission.
Packit Service 155747
Packit Service 155747
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 155747
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 155747
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service 155747
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service 155747
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service 155747
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 155747
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 155747
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 155747
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 155747
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 155747
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 155747
Packit Service 155747
*/
Packit Service 155747
Packit Service 155747
#define PSM_TX_SPEEDPATH_CTR 0
Packit Service 155747
#define PSM_RX_SPEEDPATH_CTR 1
Packit Service 155747
Packit Service 155747
#ifdef RDPMC_PERF_FRAMEWORK
Packit Service 155747
Packit Service 155747
/* Configuration */
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_MAX_SLOT_NUMBER (8)
Packit Service 155747
#define RDPMC_PERF_MAX_SLOT_NAME   (256)
Packit Service 155747
Packit Service 155747
/* RDPMC infrastructure */
Packit Service 155747
Packit Service 155747
extern __thread struct rdpmc_ctx global_rdpmc_ctx;
Packit Service 155747
Packit Service 155747
typedef unsigned long long u64;
Packit Service 155747
Packit Service 155747
extern u64 global_rdpmc_begin[RDPMC_PERF_MAX_SLOT_NUMBER];
Packit Service 155747
extern u64 global_rdpmc_summ[RDPMC_PERF_MAX_SLOT_NUMBER];
Packit Service 155747
extern u64 global_rdpmc_number[RDPMC_PERF_MAX_SLOT_NUMBER];
Packit Service 155747
Packit Service 155747
extern char global_rdpmc_slot_name[RDPMC_PERF_MAX_SLOT_NUMBER][RDPMC_PERF_MAX_SLOT_NAME];
Packit Service 155747
Packit Service 155747
extern __thread unsigned int global_rdpmc_type;
Packit Service 155747
extern __thread unsigned int global_rdpmc_config;
Packit Service 155747
Packit Service 155747
extern unsigned long long rdpmc_read(struct rdpmc_ctx *ctx);
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_INIT() \
Packit Service 155747
{                         \
Packit Service 155747
    int i;                \
Packit Service 155747
    for (i = 0; i < RDPMC_PERF_MAX_SLOT_NUMBER; i++) \
Packit Service 155747
    {                                                \
Packit Service 155747
        global_rdpmc_begin[i]  = 0; \
Packit Service 155747
        global_rdpmc_summ[i]   = 0; \
Packit Service 155747
        global_rdpmc_number[i] = 0; \
Packit Service 155747
        global_rdpmc_slot_name[i][0] = '\0'; \
Packit Service 155747
    }                               \
Packit Service 155747
}
Packit Service 155747
Packit Service 155747
/* There is no slot_number max range check */
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_SET_SLOT_NAME(slot_number, name)  \
Packit Service 155747
{                                                    \
Packit Service 155747
    strncpy(global_rdpmc_slot_name[(slot_number)], (name), RDPMC_PERF_MAX_SLOT_NAME - 1); \
Packit Service 155747
    global_rdpmc_slot_name[(slot_number)][RDPMC_PERF_MAX_SLOT_NAME - 1] = '\0';           \
Packit Service 155747
}
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_BEGIN(slot_number) \
Packit Service 155747
{                                     \
Packit Service 155747
    global_rdpmc_begin[(slot_number)] = rdpmc_read(&global_rdpmc_ctx); \
Packit Service 155747
}
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_END(slot_number) \
Packit Service 155747
{                        \
Packit Service 155747
    global_rdpmc_summ[(slot_number)] += (rdpmc_read(&global_rdpmc_ctx) - global_rdpmc_begin[(slot_number)]); \
Packit Service 155747
    global_rdpmc_number[(slot_number)]++;                                                                    \
Packit Service 155747
}
Packit Service 155747
Packit Service 155747
#define RDPMC_PERF_DUMP(stream) \
Packit Service 155747
{                         \
Packit Service 155747
    int i;                \
Packit Service 155747
    for (i = 0; i < RDPMC_PERF_MAX_SLOT_NUMBER; i++) \
Packit Service 155747
    {                                                \
Packit Service 155747
        if (global_rdpmc_slot_name[i][0])                  \
Packit Service 155747
        {                                            \
Packit Service 155747
            fprintf((stream), "RDPMC [%s] (%x, %04x) avg = %g (%llu times)\n", \
Packit Service 155747
                    global_rdpmc_slot_name[i], global_rdpmc_type, global_rdpmc_config, \
Packit Service 155747
                    (double)global_rdpmc_summ[i] / global_rdpmc_number[i], global_rdpmc_number[i]); \
Packit Service 155747
            fflush((stream));                                                 \
Packit Service 155747
        } \
Packit Service 155747
    }     \
Packit Service 155747
}
Packit Service 155747
Packit Service 155747
#define GENERIC_PERF_INIT()                           RDPMC_PERF_INIT()
Packit Service 155747
#define GENERIC_PERF_SET_SLOT_NAME(slot_number, name) RDPMC_PERF_SET_SLOT_NAME(slot_number, name)
Packit Service 155747
#define GENERIC_PERF_BEGIN(slot_number)               RDPMC_PERF_BEGIN(slot_number)
Packit Service 155747
#define GENERIC_PERF_END(slot_number)                 RDPMC_PERF_END(slot_number)
Packit Service 155747
#define GENERIC_PERF_DUMP(stream)                     RDPMC_PERF_DUMP(stream)
Packit Service 155747
#else /* RDPMC_PERF_FRAMEWORK */
Packit Service 155747
#define GENERIC_PERF_INIT()
Packit Service 155747
#define GENERIC_PERF_SET_SLOT_NAME(slot_number, name)
Packit Service 155747
#define GENERIC_PERF_BEGIN(slot_number)
Packit Service 155747
#define GENERIC_PERF_END(slot_number)
Packit Service 155747
#define GENERIC_PERF_DUMP(stream)
Packit Service 155747
#endif /* RDPMC_PERF_FRAMEWORK */