Set a PMU parameter (such as umask) to the corresponding config field
| 133 | |
| 134 | // Set a PMU parameter (such as umask) to the corresponding config field |
| 135 | static bool setPmuConfig(const char* device, const char* param, __u64* config, __u64 val) { |
| 136 | char buf[256]; |
| 137 | if ((size_t)snprintf(buf, sizeof(buf), "/sys/bus/event_source/devices/%s/format/%s", device, param) >= sizeof(buf)) { |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | int fd = open(buf, O_RDONLY); |
| 142 | if (fd == -1) { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | ssize_t r = read(fd, buf, sizeof(buf)); |
| 147 | close(fd); |
| 148 | |
| 149 | if (r > 0 && r < sizeof(buf)) { |
| 150 | if (strncmp(buf, "config:", 7) == 0) { |
| 151 | config[0] |= val << atoi(buf + 7); |
| 152 | return true; |
| 153 | } else if (strncmp(buf, "config1:", 8) == 0) { |
| 154 | config[1] |= val << atoi(buf + 8); |
| 155 | return true; |
| 156 | } else if (strncmp(buf, "config2:", 8) == 0) { |
| 157 | config[2] |= val << atoi(buf + 8); |
| 158 | return true; |
| 159 | } |
| 160 | } |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | // Perf events consume one file descriptor per thread. |
| 165 | // Make sure the current limit is the highest possible. |