|
46 | 46 | #include "util/bpf-event.h" |
47 | 47 | #include "util/util.h" |
48 | 48 | #include "util/pfm.h" |
| 49 | +#include "util/clockid.h" |
49 | 50 | #include "asm/bug.h" |
50 | 51 | #include "perf.h" |
51 | 52 |
|
@@ -2102,103 +2103,6 @@ static int perf_record_config(const char *var, const char *value, void *cb) |
2102 | 2103 | return 0; |
2103 | 2104 | } |
2104 | 2105 |
|
2105 | | -struct clockid_map { |
2106 | | - const char *name; |
2107 | | - int clockid; |
2108 | | -}; |
2109 | | - |
2110 | | -#define CLOCKID_MAP(n, c) \ |
2111 | | - { .name = n, .clockid = (c), } |
2112 | | - |
2113 | | -#define CLOCKID_END { .name = NULL, } |
2114 | | - |
2115 | | - |
2116 | | -/* |
2117 | | - * Add the missing ones, we need to build on many distros... |
2118 | | - */ |
2119 | | -#ifndef CLOCK_MONOTONIC_RAW |
2120 | | -#define CLOCK_MONOTONIC_RAW 4 |
2121 | | -#endif |
2122 | | -#ifndef CLOCK_BOOTTIME |
2123 | | -#define CLOCK_BOOTTIME 7 |
2124 | | -#endif |
2125 | | -#ifndef CLOCK_TAI |
2126 | | -#define CLOCK_TAI 11 |
2127 | | -#endif |
2128 | | - |
2129 | | -static const struct clockid_map clockids[] = { |
2130 | | - /* available for all events, NMI safe */ |
2131 | | - CLOCKID_MAP("monotonic", CLOCK_MONOTONIC), |
2132 | | - CLOCKID_MAP("monotonic_raw", CLOCK_MONOTONIC_RAW), |
2133 | | - |
2134 | | - /* available for some events */ |
2135 | | - CLOCKID_MAP("realtime", CLOCK_REALTIME), |
2136 | | - CLOCKID_MAP("boottime", CLOCK_BOOTTIME), |
2137 | | - CLOCKID_MAP("tai", CLOCK_TAI), |
2138 | | - |
2139 | | - /* available for the lazy */ |
2140 | | - CLOCKID_MAP("mono", CLOCK_MONOTONIC), |
2141 | | - CLOCKID_MAP("raw", CLOCK_MONOTONIC_RAW), |
2142 | | - CLOCKID_MAP("real", CLOCK_REALTIME), |
2143 | | - CLOCKID_MAP("boot", CLOCK_BOOTTIME), |
2144 | | - |
2145 | | - CLOCKID_END, |
2146 | | -}; |
2147 | | - |
2148 | | -static int get_clockid_res(clockid_t clk_id, u64 *res_ns) |
2149 | | -{ |
2150 | | - struct timespec res; |
2151 | | - |
2152 | | - *res_ns = 0; |
2153 | | - if (!clock_getres(clk_id, &res)) |
2154 | | - *res_ns = res.tv_nsec + res.tv_sec * NSEC_PER_SEC; |
2155 | | - else |
2156 | | - pr_warning("WARNING: Failed to determine specified clock resolution.\n"); |
2157 | | - |
2158 | | - return 0; |
2159 | | -} |
2160 | | - |
2161 | | -static int parse_clockid(const struct option *opt, const char *str, int unset) |
2162 | | -{ |
2163 | | - struct record_opts *opts = (struct record_opts *)opt->value; |
2164 | | - const struct clockid_map *cm; |
2165 | | - const char *ostr = str; |
2166 | | - |
2167 | | - if (unset) { |
2168 | | - opts->use_clockid = 0; |
2169 | | - return 0; |
2170 | | - } |
2171 | | - |
2172 | | - /* no arg passed */ |
2173 | | - if (!str) |
2174 | | - return 0; |
2175 | | - |
2176 | | - /* no setting it twice */ |
2177 | | - if (opts->use_clockid) |
2178 | | - return -1; |
2179 | | - |
2180 | | - opts->use_clockid = true; |
2181 | | - |
2182 | | - /* if its a number, we're done */ |
2183 | | - if (sscanf(str, "%d", &opts->clockid) == 1) |
2184 | | - return get_clockid_res(opts->clockid, &opts->clockid_res_ns); |
2185 | | - |
2186 | | - /* allow a "CLOCK_" prefix to the name */ |
2187 | | - if (!strncasecmp(str, "CLOCK_", 6)) |
2188 | | - str += 6; |
2189 | | - |
2190 | | - for (cm = clockids; cm->name; cm++) { |
2191 | | - if (!strcasecmp(str, cm->name)) { |
2192 | | - opts->clockid = cm->clockid; |
2193 | | - return get_clockid_res(opts->clockid, |
2194 | | - &opts->clockid_res_ns); |
2195 | | - } |
2196 | | - } |
2197 | | - |
2198 | | - opts->use_clockid = false; |
2199 | | - ui__warning("unknown clockid %s, check man page\n", ostr); |
2200 | | - return -1; |
2201 | | -} |
2202 | 2106 |
|
2203 | 2107 | static int record__parse_affinity(const struct option *opt, const char *str, int unset) |
2204 | 2108 | { |
|
0 commit comments