<commit_before>/*
 * Copyright (c) 2015 - 2022, Intel Corporation
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "config.h"

#include "PlatformIOImp.hpp"

#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <memory>

#include "geopm/Agg.hpp"
#include "geopm/Exception.hpp"
#include "geopm/Helper.hpp"
#include "geopm/IOGroup.hpp"
#include "geopm/PlatformTopo.hpp"

#include "geopm_pio.h"
#include "BatchServer.hpp"
#include "CombinedSignal.hpp"
#include "ServiceIOGroup.hpp"

namespace geopm
{

    static PlatformIO &platform_io_helper(bool do_reset)
    {
        static std::unique_ptr<PlatformIOImp> instance = geopm::make_unique<PlatformIOImp>();
        if (do_reset) {
            instance = geopm::make_unique<PlatformIOImp>();
        }
        return *instance;
    }

    PlatformIO &platform_io(void)
    {
        return platform_io_helper(false);
    }

    static void platform_io_reset(void)
    {
        platform_io_helper(true);
    }

    PlatformIOImp::PlatformIOImp()
        : PlatformIOImp({}, platform_topo())
    {

    }


    const std::map<const std::string, const std::string>
    PlatformIOImp::m_signal_descriptions = {
        {"BOARD_ENERGY",
         "Total energy measured on the server's board. "},
        {"BOARD_POWER",
         "Power measured on the server's board. "},
        {"CPU_CYCLES_REFERENCE",
         "The count of the number of cycles while the logical processor is not in a "
         "halt state and not in a stop-clock state. The count rate is fixed at the "
         "TIMESTAMP_COUNT rate."},
        {"CPU_CYCLES_THREAD",
         "The count of the number of cycles while the logical processor is not in a "
         "halt state.  The count rate may change based on core frequency."},
        {"CPU_ENERGY",
         "An increasing meter of energy consumed by the package over time. It will "
         "reset periodically due to roll-over."},
        {"CPU_FREQUENCY_MAX",
         "Maximum processor frequency."},
        {"CPU_FREQUENCY_STATUS",
         "The current operating frequency of the CPU."},
        {"CPU_INSTRUCTIONS_RETIRED",
         "The count of the number of instructions executed."},
        {"CPU_POWER_LIMIT_CONTROL",
         "The average power usage limit over the time window specified in "
         "PL1_TIME_WINDOW."},
        {"CPU_POWER_TIME_WINDOW",
         "The time window associated with power limit 1."},
        {"CPU_POWER_MAX_AVAIL",
         "The maximum power limit based on the electrical specification."},
        {"CPU_POWER_MIN_AVAIL",
         "The minimum power limit based on the electrical specification."},
        {"CPU_POWER_LIMIT_DEFAULT",
         "Maximum power to stay within the thermal limits based on the design (TDP)."},
        {"CPU_POWER",
         "Total power aggregated over the processor package."},
        {"CPU_TIMESTAMP_COUNTER",
         "An always running, monotonically increasing counter that is "
         "incremented at a constant rate.  For use as a wall clock "
         "timer."},
        {"CPU_UNCORE_FREQUENCY_STATUS",
         "Target operating frequency of the uncore."},
        {"DRAM_ENERGY",
         "An increasing meter of energy consumed by the DRAM over time. It will reset "
         "periodically due to roll-over."},
        {"DRAM_POWER",
         "Total power aggregated over the DRAM DIMMs associated with a NUMA node."},
        {"EPOCH_COUNT",
         "Number of completed executions of an epoch.  Prior to the first call "
         "by the application to geopm_prof_epoch() the signal returns as -1. "
         "With each call to geopm_prof_epoch() the count increases by one."},
        {"GPU_CORE_ACTIVITY",
         "GPU compute core activity expressed as a ratio of cycles."},
        {"GPU_CORE_FREQENCY_MAX_AVAIL",
         "Maximum supported GPU core frequency over the specified domain."},
        {"GPU_CORE_FREQENCY_MIN_AVAIL",
         "Minimum supported GPU core frequency over the specified domain."},
        {"GPU_CORE_FREQUENCY_STATUS",
         "Average achieved GPU core frequency over the specified domain."},
        {"GPU_ENERGY",
         "Total energy aggregated over the GPU package."},
        {"GPU_POWER",
         "Total power aggregated over the GPU package."},
        {"GPU_TEMPERATURE",
         "Average GPU temperature in degrees Celsius."},
        {"GPU_UNCORE_ACTIVITY",
         "GPU memory access activity expressed as a ratio of cycles."},
        {"GPU_UTILIZATION",
         "Average GPU utilization expressed as a ratio of cycles."},
        {"REGION_HASH",
         "The hash of the region of code currently being "
         "run by all ranks, otherwise GEOPM_REGION_HASH_UNMARKED."},
        {"REGION_HINT",
         "The region hint associated with the currently "
         "running region.  For any interval when all ranks are within an MPI "
         "function inside of a user defined region, the hint will change from the "
         "hint associated with the user defined region to GEOPM_REGION_HINT_NETWORK. "
         "If the user defined region was defined with GEOPM_REGION_HINT_NETWORK and "
         "there is an interval within the region when all ranks are within an MPI "
         "function, GEOPM will not attribute the time spent within the MPI function as "
         "MPI time in the report files.  It will be instead attributed to the time "
         "spent in the region as a whole."},
        {"REGION_PROGRESS",
         "Minimum per-rank reported progress through the current region."},
        {"REGION_RUNTIME",
         "Maximum per-rank of the last recorded runtime for the current region."},
        {"TIME",
         "Time elapsed since the beginning of execution."}
    };

    const std::map<const std::string, const std::string>
    PlatformIOImp::m_control_descriptions = {
        {"CPU_FREQUENCY_CONTROL",
         "Target operating frequency of the CPU based on the control register."},
        {"GPU_CORE_FREQUENCY_CONTROL",
         "Average requested GPU core frequency over the specified domain."},
        {"GPU_POWER_LIMIT_CONTROL",
         "Average GPU power usage limit"}
    };


    PlatformIOImp::PlatformIOImp(std::list<std::shared_ptr<IOGroup> > iogroup_list,
                                 const PlatformTopo &topo)
        : m_is_active(false)<commit_msg>Add IOGroup and Alias to PIO description map<commit_after>/*
 * Copyright (c) 2015 - 2022, Intel Corporation
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "config.h"

#include "PlatformIOImp.hpp"

#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <memory>

#include "geopm/Agg.hpp"
#include "geopm/Exception.hpp"
#include "geopm/Helper.hpp"
#include "geopm/IOGroup.hpp"
#include "geopm/PlatformTopo.hpp"

#include "geopm_pio.h"
#include "BatchServer.hpp"
#include "CombinedSignal.hpp"
#include "ServiceIOGroup.hpp"

namespace geopm
{

    static PlatformIO &platform_io_helper(bool do_reset)
    {
        static std::unique_ptr<PlatformIOImp> instance = geopm::make_unique<PlatformIOImp>();
        if (do_reset) {
            instance = geopm::make_unique<PlatformIOImp>();
        }
        return *instance;
    }

    PlatformIO &platform_io(void)
    {
        return platform_io_helper(false);
    }

    static void platform_io_reset(void)
    {
        platform_io_helper(true);
    }

    PlatformIOImp::PlatformIOImp()
        : PlatformIOImp({}, platform_topo())
    {

    }


    const std::map<const std::string, const std::string>
    PlatformIOImp::m_signal_descriptions = {
        {"BOARD_ENERGY",
         "    description: Total energy measured on the server's board.\n"
         "    iogroup: CNL\n"
         "    alias_for: CNL::BOARD_ENERGY"},
        {"BOARD_POWER",
         "    description: Power measured on the server's board.\n"
         "    iogroup: CNL\n"
         "    alias_for: CNL::BOARD_POWER"},
        {"CPU_CYCLES_REFERENCE",
         "    description: The count of the number of cycles while the logical processor is not in a "
         "halt state and not in a stop-clock state. The count rate is fixed at the "
         "TIMESTAMP_COUNT rate.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::FIXED_CTR2:CPU_CLK_UNHALTED_REF_TSC"},
        {"CPU_CYCLES_THREAD",
         "    description: The count of the number of cycles while the logical processor is not in a "
         "halt state.  The count rate may change based on core frequency.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::FIXED_CTR1:CPU_CLK_UNHALTED_THREAD"},
        {"CPU_ENERGY",
         "    description: An increasing meter of energy consumed by the package over time. It will "
         "reset periodically due to roll-over.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_ENERGY_STATUS:ENERGY"},
        {"CPU_FREQUENCY_MAX",
         "    description: Maximum processor frequency.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::TURBO_RATIO_LIMIT:MAX_RATIO_LIMIT_0 or if HWP is enabled MSR::HWP_CAPABILITIES:HIGHEST_PERFORMANCE"},
        {"CPU_FREQUENCY_STATUS",
         "    description: The current operating frequency of the CPU.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PERF_STATUS:FREQ"},
        {"CPU_INSTRUCTIONS_RETIRED",
         "    description: The count of the number of instructions executed.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::FIXED_CTR0:INST_RETIRED_ANY"},
        {"CPU_POWER_LIMIT_CONTROL",
         "    description: The average power usage limit over the time window specified in "
         "PL1_TIME_WINDOW.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_POWER_LIMIT:PL1_POWER_LIMIT"},
        {"CPU_POWER_TIME_WINDOW",
         "    description: The time window associated with power limit 1.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_POWER_LIMIT:PL1_TIME_WINDOW"},
        {"CPU_POWER_MAX_AVAIL",
         "    description: The maximum power limit based on the electrical specification.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_POWER_INFO:MAX_POWER"},
        {"CPU_POWER_MIN_AVAIL",
         "    description: The minimum power limit based on the electrical specification.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_POWER_INFO:MIN_POWER"},
        {"CPU_POWER_LIMIT_DEFAULT",
         "    description: Maximum power to stay within the thermal limits based on the design (TDP).\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::PKG_POWER_INFO:THERMAL_SPEC_POWER"},
        {"CPU_POWER",
         "    description: Total power aggregated over the processor package.  Derived from CPU_ENERGY.\n"
         "    iogroup: MSR"}, // This is not an alias.  This is a defined signal in the MSRIOGroup.
        {"CPU_TIMESTAMP_COUNTER",
         "    description: An always running, monotonically increasing counter that is "
         "incremented at a constant rate.  For use as a wall clock "
         "timer.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::TIME_STAMP_COUNTER:TIMESTAMP_COUNT"},
        {"CPU_UNCORE_FREQUENCY_STATUS",
         "    description: Target operating frequency of the uncore.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::UNCORE_PERF_STATUS:FREQ"},
        {"DRAM_ENERGY",
         "    description: An increasing meter of energy consumed by the DRAM over time. It will reset "
         "periodically due to roll-over.\n"
         "    iogroup: MSR\n"
         "    alias_for: MSR::DRAM_ENERGY_STATUS:ENERGY"},
        {"DRAM_POWER",
         "    description: Total power aggregated over the DRAM DIMMs associated with a NUMA node. "
         "Derived from DRAM_ENERGY.\n"
         "    iogroup: MSR"},
        {"EPOCH_COUNT",
         "    description: Number of completed executions of an epoch.  Prior to the first call "
         "by the application to geopm_prof_epoch() the signal returns as -1. "
         "With each call to geopm_prof_epoch() the count increases by one.\n"
         "    iogroup: Epoch"},
        {"GPU_CORE_ACTIVITY",
         "    description: GPU compute core activity expressed as a ratio of cycles.\n"
         "    iogroup: DCGM\n"
         "    alias_for: DCGM::SM_ACTIVE"},
        {"GPU_CORE_FREQENCY_MAX_AVAIL",
         "    description: Maximum supported GPU core frequency over the specified domain.\n"
         "    iogroup: LevelZero, NVML\n"
         "    alias_for: LEVELZERO::GPU_CORE_FREQUENCY_MAX_AVAIL, NVML::GPU_CORE_FREQUENCY_MAX_AVAIL"},
        {"GPU_CORE_FREQUENCY_MIN_AVAIL",
         "    description: Minimum supported GPU core frequency over the specified domain.\n"
         "    iogroup: LevelZero, NVML\n"
         "    alias_for: LEVELZERO::GPU_CORE_FREQUENCY_MIN_AVAIL, NVML::GPU_CORE_FREQUENCY_MIN_AVAIL"},
        {"GPU_CORE_FREQUENCY_STATUS",
         "    description: Average achieved GPU core frequency over the specified domain.\n"
         "    iogroup: LevelZero, NVML\n"
         "    alias_for: LEVELZERO::GPU_CORE_FREQUENCY_STATUS, NVML::GPU_CORE_FREQUENCY_STATUS"},
        {"GPU_ENERGY",
         "    description: Total energy aggregated over the GPU package.\n"
         "    iogroup: LevelZero, NVML\n"
         "    alias_for: LEVELZERO::GPU_ENERGY, NVML::GPU_ENERGY_CONSUMPTION_TOTAL"},
        {"GPU_POWER",
         "    description: Total power aggregated over the GPU package. Derived from GPU_ENERGY.\n"
         "    iogroup: LevelZero, NVML"},
        {"GPU_TEMPERATURE",
         "    description: Average GPU temperature in degrees Celsius.\n"
         "    iogroup: NVML\n"
         "    alias_for: NVML::GPU_TEMPERATURE"},
        {"GPU_UNCORE_ACTIVITY",
         "    description: GPU memory access activity expressed as a ratio of cycles.\n"
         "    iogroup: DCGM\n"
         "    alias_for: DCGM::DRAM_ACTIVE"},
        {"GPU_UTILIZATION",
         "    description: Average GPU utilization expressed as a ratio of cycles.\n"
         "    iogroup: LevelZero, NVML\n"
         "    alias_for: LEVELZERO::GPU_UTILIZATION, NVML::GPU_UTILIZATION"},
        {"REGION_HASH",
         "    description: The hash of the region of code currently being "
         "run by all ranks, otherwise GEOPM_REGION_HASH_UNMARKED.\n"
         "    iogroup: Profile"},
        {"REGION_HINT",
         "    description: The region hint associated with the currently "
         "running region.  For any interval when all ranks are within an MPI "
         "function inside of a user defined region, the hint will change from the "
         "hint associated with the user defined region to GEOPM_REGION_HINT_NETWORK. "
         "If the user defined region was defined with GEOPM_REGION_HINT_NETWORK and "
         "there is an interval within the region when all ranks are within an MPI "
         "function, GEOPM will not attribute the time spent within the MPI function as "
         "MPI time in the report files.  It will be instead attributed to the time "
         "spent in the region as a whole.\n"
         "    iogroup: Profile"},
        {"REGION_PROGRESS",
         "    description: Minimum per-rank reported progress through the current region.\n"
         "    iogroup: Profile"},
        {"REGION_RUNTIME",
         "    description: Maximum per-rank of the last recorded runtime for the current region.\n"
         "    iogroup: Profile"},
        {"TIME",
         "    description: Time elapsed since the beginning of execution.\n"
         "    iogroup: Time"}
    };

    const std::map<const std::string, const std::string>
    PlatformIOImp::m_control_descriptions = {
        {"CPU_FREQUENCY_CONTROL",
         "Target operating frequency of the CPU based on the control register."},
        {"GPU_CORE_FREQUENCY_CONTROL",
         "Average requested GPU core frequency over the specified domain."},
        {"GPU_POWER_LIMIT_CONTROL",
         "Average GPU power usage limit"}
    };


    PlatformIOImp::PlatformIOImp(std::list<std::shared_ptr<IOGroup> > iogroup_list,
                                 const PlatformTopo &topo)
        : m_is_active(false)
{'fraction_non_alphanumeric': 0.09393827615885897, 'fraction_numerical': 0.0018443378827001106, 'mean_word_length': 2.527103209019948, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457835', 'n_tokens_mistral': 4927, 'n_tokens_neox': 4849, 'n_words': 1432}