File: Configuration.hpp

package info (click to toggle)
memkind 1.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,508 kB
  • sloc: ansic: 72,572; cpp: 39,493; sh: 4,594; perl: 4,250; xml: 2,044; python: 1,753; makefile: 1,393; csh: 7
file content (139 lines) | stat: -rw-r--r-- 3,846 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// SPDX-License-Identifier: BSD-2-Clause
/* Copyright (C) 2015 - 2021 Intel Corporation. */
#pragma once

#include <assert.h>
#include <map>
#include <string>

// AllocatorTypes class represent allocator types and names related to this
// types.
class AllocatorTypes
{
public:
    enum
    {
        STANDARD_ALLOCATOR,
        JEMALLOC,
        MEMKIND_DEFAULT,
        MEMKIND_REGULAR,
        MEMKIND_HBW,
        MEMKIND_INTERLEAVE,
        MEMKIND_HBW_INTERLEAVE,
        MEMKIND_HBW_PREFERRED,
        MEMKIND_HUGETLB,
        MEMKIND_GBTLB,
        MEMKIND_HBW_HUGETLB,
        MEMKIND_HBW_PREFERRED_HUGETLB,
        MEMKIND_HBW_GBTLB,
        MEMKIND_HBW_PREFERRED_GBTLB,
        HBWMALLOC_ALLOCATOR,
        MEMKIND_PMEM,
        MEMKIND_DAX_KMEM,
        NUM_OF_ALLOCATOR_TYPES
    };

    static const std::string &allocator_name(unsigned type)
    {
        static const std::string names[] = {"STANDARD_ALLOCATOR",
                                            "JEMALLOC",
                                            "MEMKIND_DEFAULT",
                                            "MEMKIND_REGULAR",
                                            "MEMKIND_HBW",
                                            "MEMKIND_INTERLEAVE",
                                            "MEMKIND_HBW_INTERLEAVE",
                                            "MEMKIND_HBW_PREFERRED",
                                            "MEMKIND_HUGETLB",
                                            "MEMKIND_GBTLB",
                                            "MEMKIND_HBW_HUGETLB",
                                            "MEMKIND_HBW_PREFERRED_HUGETLB",
                                            "MEMKIND_HBW_GBTLB",
                                            "MEMKIND_HBW_PREFERRED_GBTLB",
                                            "HBWMALLOC_ALLOCATOR",
                                            "MEMKIND_PMEM",
                                            "DAX_KMEM"};

        if (type >= NUM_OF_ALLOCATOR_TYPES)
            assert(!"Invalid input argument!");

        return names[type];
    }

    static unsigned allocator_type(const std::string &name)
    {
        for (unsigned i = 0; i < NUM_OF_ALLOCATOR_TYPES; i++) {
            if (allocator_name(i) == name)
                return i;
        }

        assert(!"Invalid input argument!");
    }

    static bool is_valid_memkind(unsigned type)
    {
        return (type >= MEMKIND_DEFAULT) && (type < NUM_OF_ALLOCATOR_TYPES);
    }
};

// Enable or disable enum values (types).
class TypesConf
{
public:
    TypesConf()
    {}

    TypesConf(unsigned type)
    {
        enable_type(type);
    }

    void enable_type(unsigned type)
    {
        types[type] = true;
    }

    void disable_type(unsigned type)
    {
        if (types.count(type))
            types[type] = false;
    }

    bool is_enabled(unsigned type) const
    {
        return (types.count(type) ? types.find(type)->second : false);
    }

private:
    std::map<unsigned, bool> types;
};

// AllocationSizesConf class represents allocation sizes configuration.
// This data is needed to generate "n" sizes in range from "size_from" to
// "size_to".
class AllocationSizesConf
{
public:
    unsigned n;
    size_t size_from;
    size_t size_to;
};

// TaskConf class contain configuration data for task,
// where:
// - "n" - number of iterations,
// - "allocation_sizes_conf" - allocation sizes configuration,
// - "func_calls" - enabled or disabled function calls,
// - "allocators_types" - enable allocators,
// - "seed" - random seed.
// - "touch_memory" - enable or disable touching memory
class TaskConf
{
public:
    unsigned n;
    AllocationSizesConf allocation_sizes_conf;
    TypesConf func_calls;
    TypesConf allocators_types;
    unsigned seed;
    bool touch_memory;
    bool is_csv_log_enabled;
};