File: pcm-memory-fuzz.cpp

package info (click to toggle)
pcm 202502-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,164 kB
  • sloc: cpp: 44,347; ansic: 1,161; sh: 778; python: 388; awk: 28; makefile: 13
file content (117 lines) | stat: -rw-r--r-- 4,017 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#define UNIT_TEST 1

#include "../src/pcm-memory.cpp"

#undef UNIT_TEST


extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
        size_t size_int = size / sizeof(int);
        const auto ints_used = 9;
        if (size_int < ints_used)
        {
                return 0;
        }
        print_help("");

        auto m = PCM::getInstance();
        const int *data_int = reinterpret_cast<const int *>(data);
        int pos = 0;

        bool csv = data_int[pos++] % 2;
        bool csvheader = data_int[pos++] % 2;
        bool show_channel_output = data_int[pos++] % 2;
        bool print_update = data_int[pos++] % 2;
        uint32 no_columns = DEFAULT_DISPLAY_COLUMNS; // Default number of columns is 2
        int delay = data_int[pos++] % 4;
        int rankA = data_int[pos++] % 11;
        int rankB = data_int[pos++] % 11;
        bool use_rank = data_int[pos++] % 2;
        if (!use_rank)
        {
                rankA = -1;
                rankB = -1;
        }


        ServerUncoreMemoryMetrics metrics;
        switch (data_int[pos++] % 4)
        {
        case 0:
                metrics = PartialWrites;
                break;
        case 1:
                metrics = Pmem;
                break;
        case 2:
                metrics = PmemMemoryMode;
                break;
        case 3:
                metrics = PmemMixedMode;
                break;
        }

        assert(pos == ints_used);

        m->resetPMU();
        m->disableJKTWorkaround();

        const auto cpu_family_model = m->getCPUFamilyModel();
        if (!m->hasPCICFGUncore())
        {
                cerr << "Unsupported processor model (0x" << std::hex << cpu_family_model << std::dec << ").\n";
                if (m->memoryTrafficMetricsAvailable())
                        cerr << "For processor-level memory bandwidth statistics please use 'pcm' utility\n";
                return 0;
        }
        if (anyPmem(metrics) && (m->PMMTrafficMetricsAvailable() == false))
        {
                cerr << "PMM/Pmem traffic metrics are not available on your processor.\n";
                return 0;
        }
        if (metrics == PmemMemoryMode && m->PMMMemoryModeMetricsAvailable() == false)
        {
                cerr << "PMM Memory Mode metrics are not available on your processor.\n";
                return 0;
        }
        if (metrics == PmemMixedMode && m->PMMMixedModeMetricsAvailable() == false)
        {
                cerr << "PMM Mixed Mode metrics are not available on your processor.\n";
                return 0;
        }
        if((rankA >= 0 || rankB >= 0) && anyPmem(metrics))
        {
                cerr << "PMM/Pmem traffic metrics are not available on rank level\n";
                return 0;
        }
        if((rankA >= 0 || rankB >= 0) && !show_channel_output)
        {
                cerr << "Rank level output requires channel output\n";
                return 0;
        }
        std::cerr << "programServerUncoreMemoryMetrics parameters:" << metrics << ";" << rankA << ";" << rankB << "\n";
        PCM::ErrorCode status = m->programServerUncoreMemoryMetrics(metrics, rankA, rankB);
        m->checkError(status);

        max_imc_channels = (pcm::uint32)m->getMCChannelsPerSocket();

        std::vector<ServerUncoreCounterState> BeforeState(m->getNumSockets());
        std::vector<ServerUncoreCounterState> AfterState(m->getNumSockets());
        uint64 BeforeTime = 0, AfterTime = 0;

        readState(BeforeState);
        BeforeTime = m->getTickCount();
        MySleepMs(delay);
        AfterTime = m->getTickCount();
        readState(AfterState);

        if(rankA >= 0 || rankB >= 0)
          calculate_bandwidth_rank(m,BeforeState, AfterState, AfterTime - BeforeTime, csv, csvheader, no_columns, rankA, rankB);
        else
          calculate_bandwidth(m,BeforeState,AfterState,AfterTime-BeforeTime,csv,csvheader, no_columns, metrics,
                show_channel_output, print_update, 0);

        return 0;
}