aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-08-02 13:55:32 -0400
committerDavid S. Miller <davem@davemloft.net>2018-08-02 13:55:32 -0400
commit89b1698c93a9dee043154f33d96bca9964e705f1 (patch)
treedd9dcb1965baae8edcf0b496aaa6a70609b6fc11 /tools
parentffd7ce3cd9c294f1ff49ec02cdbd1bc7cb913db6 (diff)
parente30cb13c5a09ff5f043a6570c32e49b063bea6a1 (diff)
Merge ra.kernel.org:/pub/scm/linux/kernel/git/davem/net
The BTF conflicts were simple overlapping changes. The virtio_net conflict was an overlap of a fix of statistics counter, happening alongisde a move over to a bonafide statistics structure rather than counting value on the stack. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/include/uapi/linux/btf.h2
-rw-r--r--tools/lib/bpf/btf.c46
-rw-r--r--tools/lib/bpf/btf.h10
-rw-r--r--tools/lib/bpf/libbpf.c87
-rw-r--r--tools/lib/bpf/libbpf.h4
-rw-r--r--tools/power/x86/turbostat/turbostat.84
-rw-r--r--tools/power/x86/turbostat/turbostat.c120
-rw-r--r--tools/testing/selftests/bpf/bpf_helpers.h9
-rw-r--r--tools/testing/selftests/bpf/test_btf.c114
-rw-r--r--tools/testing/selftests/bpf/test_btf_haskv.c7
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/snapshot.tc28
-rw-r--r--tools/usb/ffs-test.c19
-rw-r--r--tools/virtio/asm/barrier.h4
-rw-r--r--tools/virtio/linux/kernel.h5
14 files changed, 318 insertions, 141 deletions
diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
index 0b5ddbe135a4..972265f32871 100644
--- a/tools/include/uapi/linux/btf.h
+++ b/tools/include/uapi/linux/btf.h
@@ -76,7 +76,7 @@ struct btf_type {
76 */ 76 */
77#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) 77#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
78#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) 78#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16)
79#define BTF_INT_BITS(VAL) ((VAL) & 0x0000ffff) 79#define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
80 80
81/* Attributes stored in the BTF_INT_ENCODING */ 81/* Attributes stored in the BTF_INT_ENCODING */
82#define BTF_INT_SIGNED (1 << 0) 82#define BTF_INT_SIGNED (1 << 0)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 03161be094b4..1622a309f169 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2,7 +2,6 @@
2/* Copyright (c) 2018 Facebook */ 2/* Copyright (c) 2018 Facebook */
3 3
4#include <stdlib.h> 4#include <stdlib.h>
5#include <stdint.h>
6#include <string.h> 5#include <string.h>
7#include <unistd.h> 6#include <unistd.h>
8#include <errno.h> 7#include <errno.h>
@@ -32,17 +31,25 @@ struct btf {
32 struct btf_type **types; 31 struct btf_type **types;
33 const char *strings; 32 const char *strings;
34 void *nohdr_data; 33 void *nohdr_data;
35 uint32_t nr_types; 34 __u32 nr_types;
36 uint32_t types_size; 35 __u32 types_size;
37 uint32_t data_size; 36 __u32 data_size;
38 int fd; 37 int fd;
39}; 38};
40 39
40static const char *btf_name_by_offset(const struct btf *btf, __u32 offset)
41{
42 if (offset < btf->hdr->str_len)
43 return &btf->strings[offset];
44 else
45 return NULL;
46}
47
41static int btf_add_type(struct btf *btf, struct btf_type *t) 48static int btf_add_type(struct btf *btf, struct btf_type *t)
42{ 49{
43 if (btf->types_size - btf->nr_types < 2) { 50 if (btf->types_size - btf->nr_types < 2) {
44 struct btf_type **new_types; 51 struct btf_type **new_types;
45 u32 expand_by, new_size; 52 __u32 expand_by, new_size;
46 53
47 if (btf->types_size == BTF_MAX_NR_TYPES) 54 if (btf->types_size == BTF_MAX_NR_TYPES)
48 return -E2BIG; 55 return -E2BIG;
@@ -69,7 +76,7 @@ static int btf_add_type(struct btf *btf, struct btf_type *t)
69static int btf_parse_hdr(struct btf *btf, btf_print_fn_t err_log) 76static int btf_parse_hdr(struct btf *btf, btf_print_fn_t err_log)
70{ 77{
71 const struct btf_header *hdr = btf->hdr; 78 const struct btf_header *hdr = btf->hdr;
72 u32 meta_left; 79 __u32 meta_left;
73 80
74 if (btf->data_size < sizeof(struct btf_header)) { 81 if (btf->data_size < sizeof(struct btf_header)) {
75 elog("BTF header not found\n"); 82 elog("BTF header not found\n");
@@ -148,7 +155,7 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
148 155
149 while (next_type < end_type) { 156 while (next_type < end_type) {
150 struct btf_type *t = next_type; 157 struct btf_type *t = next_type;
151 uint16_t vlen = BTF_INFO_VLEN(t->info); 158 __u16 vlen = BTF_INFO_VLEN(t->info);
152 int err; 159 int err;
153 160
154 next_type += sizeof(*t); 161 next_type += sizeof(*t);
@@ -187,6 +194,14 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
187 return 0; 194 return 0;
188} 195}
189 196
197const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id)
198{
199 if (type_id > btf->nr_types)
200 return NULL;
201
202 return btf->types[type_id];
203}
204
190static bool btf_type_is_void(const struct btf_type *t) 205static bool btf_type_is_void(const struct btf_type *t)
191{ 206{
192 return t == &btf_void || BTF_INFO_KIND(t->info) == BTF_KIND_FWD; 207 return t == &btf_void || BTF_INFO_KIND(t->info) == BTF_KIND_FWD;
@@ -197,7 +212,7 @@ static bool btf_type_is_void_or_null(const struct btf_type *t)
197 return !t || btf_type_is_void(t); 212 return !t || btf_type_is_void(t);
198} 213}
199 214
200static int64_t btf_type_size(const struct btf_type *t) 215static __s64 btf_type_size(const struct btf_type *t)
201{ 216{
202 switch (BTF_INFO_KIND(t->info)) { 217 switch (BTF_INFO_KIND(t->info)) {
203 case BTF_KIND_INT: 218 case BTF_KIND_INT:
@@ -214,12 +229,12 @@ static int64_t btf_type_size(const struct btf_type *t)
214 229
215#define MAX_RESOLVE_DEPTH 32 230#define MAX_RESOLVE_DEPTH 32
216 231
217int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id) 232__s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
218{ 233{
219 const struct btf_array *array; 234 const struct btf_array *array;
220 const struct btf_type *t; 235 const struct btf_type *t;
221 uint32_t nelems = 1; 236 __u32 nelems = 1;
222 int64_t size = -1; 237 __s64 size = -1;
223 int i; 238 int i;
224 239
225 t = btf__type_by_id(btf, type_id); 240 t = btf__type_by_id(btf, type_id);
@@ -279,9 +294,9 @@ int btf__resolve_type(const struct btf *btf, __u32 type_id)
279 return type_id; 294 return type_id;
280} 295}
281 296
282int32_t btf__find_by_name(const struct btf *btf, const char *type_name) 297__s32 btf__find_by_name(const struct btf *btf, const char *type_name)
283{ 298{
284 uint32_t i; 299 __u32 i;
285 300
286 if (!strcmp(type_name, "void")) 301 if (!strcmp(type_name, "void"))
287 return 0; 302 return 0;
@@ -310,10 +325,9 @@ void btf__free(struct btf *btf)
310 free(btf); 325 free(btf);
311} 326}
312 327
313struct btf *btf__new(uint8_t *data, uint32_t size, 328struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log)
314 btf_print_fn_t err_log)
315{ 329{
316 uint32_t log_buf_size = 0; 330 __u32 log_buf_size = 0;
317 char *log_buf = NULL; 331 char *log_buf = NULL;
318 struct btf *btf; 332 struct btf *btf;
319 int err; 333 int err;
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 24f361d99a5e..dd8a86eab8ca 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -4,19 +4,21 @@
4#ifndef __BPF_BTF_H 4#ifndef __BPF_BTF_H
5#define __BPF_BTF_H 5#define __BPF_BTF_H
6 6
7#include <stdint.h> 7#include <linux/types.h>
8 8
9#define BTF_ELF_SEC ".BTF" 9#define BTF_ELF_SEC ".BTF"
10 10
11struct btf; 11struct btf;
12struct btf_type;
12 13
13typedef int (*btf_print_fn_t)(const char *, ...) 14typedef int (*btf_print_fn_t)(const char *, ...)
14 __attribute__((format(printf, 1, 2))); 15 __attribute__((format(printf, 1, 2)));
15 16
16void btf__free(struct btf *btf); 17void btf__free(struct btf *btf);
17struct btf *btf__new(uint8_t *data, uint32_t size, btf_print_fn_t err_log); 18struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
18int32_t btf__find_by_name(const struct btf *btf, const char *type_name); 19__s32 btf__find_by_name(const struct btf *btf, const char *type_name);
19int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id); 20const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 id);
21__s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
20int btf__resolve_type(const struct btf *btf, __u32 type_id); 22int btf__resolve_type(const struct btf *btf, __u32 type_id);
21int btf__fd(const struct btf *btf); 23int btf__fd(const struct btf *btf);
22const char *btf__name_by_offset(const struct btf *btf, __u32 offset); 24const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 955f8eafbf41..26e9527ee464 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -37,6 +37,7 @@
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/kernel.h> 38#include <linux/kernel.h>
39#include <linux/bpf.h> 39#include <linux/bpf.h>
40#include <linux/btf.h>
40#include <linux/list.h> 41#include <linux/list.h>
41#include <linux/limits.h> 42#include <linux/limits.h>
42#include <sys/stat.h> 43#include <sys/stat.h>
@@ -170,8 +171,8 @@ struct bpf_map {
170 size_t offset; 171 size_t offset;
171 int map_ifindex; 172 int map_ifindex;
172 struct bpf_map_def def; 173 struct bpf_map_def def;
173 uint32_t btf_key_type_id; 174 __u32 btf_key_type_id;
174 uint32_t btf_value_type_id; 175 __u32 btf_value_type_id;
175 void *priv; 176 void *priv;
176 bpf_map_clear_priv_t clear_priv; 177 bpf_map_clear_priv_t clear_priv;
177}; 178};
@@ -969,68 +970,72 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
969 970
970static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf) 971static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf)
971{ 972{
973 const struct btf_type *container_type;
974 const struct btf_member *key, *value;
972 struct bpf_map_def *def = &map->def; 975 struct bpf_map_def *def = &map->def;
973 const size_t max_name = 256; 976 const size_t max_name = 256;
974 int64_t key_size, value_size; 977 char container_name[max_name];
975 int32_t key_id, value_id; 978 __s64 key_size, value_size;
976 char name[max_name]; 979 __s32 container_id;
977 980
978 /* Find key type by name from BTF */ 981 if (snprintf(container_name, max_name, "____btf_map_%s", map->name) ==
979 if (snprintf(name, max_name, "%s_key", map->name) == max_name) { 982 max_name) {
980 pr_warning("map:%s length of BTF key_type:%s_key is too long\n", 983 pr_warning("map:%s length of '____btf_map_%s' is too long\n",
981 map->name, map->name); 984 map->name, map->name);
982 return -EINVAL; 985 return -EINVAL;
983 } 986 }
984 987
985 key_id = btf__find_by_name(btf, name); 988 container_id = btf__find_by_name(btf, container_name);
986 if (key_id < 0) { 989 if (container_id < 0) {
987 pr_debug("map:%s key_type:%s cannot be found in BTF\n", 990 pr_debug("map:%s container_name:%s cannot be found in BTF. Missing BPF_ANNOTATE_KV_PAIR?\n",
988 map->name, name); 991 map->name, container_name);
989 return key_id; 992 return container_id;
990 } 993 }
991 994
992 key_size = btf__resolve_size(btf, key_id); 995 container_type = btf__type_by_id(btf, container_id);
993 if (key_size < 0) { 996 if (!container_type) {
994 pr_warning("map:%s key_type:%s cannot get the BTF type_size\n", 997 pr_warning("map:%s cannot find BTF type for container_id:%u\n",
995 map->name, name); 998 map->name, container_id);
996 return key_size; 999 return -EINVAL;
997 } 1000 }
998 1001
999 if (def->key_size != key_size) { 1002 if (BTF_INFO_KIND(container_type->info) != BTF_KIND_STRUCT ||
1000 pr_warning("map:%s key_type:%s has BTF type_size:%u != key_size:%u\n", 1003 BTF_INFO_VLEN(container_type->info) < 2) {
1001 map->name, name, (unsigned int)key_size, def->key_size); 1004 pr_warning("map:%s container_name:%s is an invalid container struct\n",
1005 map->name, container_name);
1002 return -EINVAL; 1006 return -EINVAL;
1003 } 1007 }
1004 1008
1005 /* Find value type from BTF */ 1009 key = (struct btf_member *)(container_type + 1);
1006 if (snprintf(name, max_name, "%s_value", map->name) == max_name) { 1010 value = key + 1;
1007 pr_warning("map:%s length of BTF value_type:%s_value is too long\n", 1011
1008 map->name, map->name); 1012 key_size = btf__resolve_size(btf, key->type);
1009 return -EINVAL; 1013 if (key_size < 0) {
1014 pr_warning("map:%s invalid BTF key_type_size\n",
1015 map->name);
1016 return key_size;
1010 } 1017 }
1011 1018
1012 value_id = btf__find_by_name(btf, name); 1019 if (def->key_size != key_size) {
1013 if (value_id < 0) { 1020 pr_warning("map:%s btf_key_type_size:%u != map_def_key_size:%u\n",
1014 pr_debug("map:%s value_type:%s cannot be found in BTF\n", 1021 map->name, (__u32)key_size, def->key_size);
1015 map->name, name); 1022 return -EINVAL;
1016 return value_id;
1017 } 1023 }
1018 1024
1019 value_size = btf__resolve_size(btf, value_id); 1025 value_size = btf__resolve_size(btf, value->type);
1020 if (value_size < 0) { 1026 if (value_size < 0) {
1021 pr_warning("map:%s value_type:%s cannot get the BTF type_size\n", 1027 pr_warning("map:%s invalid BTF value_type_size\n", map->name);
1022 map->name, name);
1023 return value_size; 1028 return value_size;
1024 } 1029 }
1025 1030
1026 if (def->value_size != value_size) { 1031 if (def->value_size != value_size) {
1027 pr_warning("map:%s value_type:%s has BTF type_size:%u != value_size:%u\n", 1032 pr_warning("map:%s btf_value_type_size:%u != map_def_value_size:%u\n",
1028 map->name, name, (unsigned int)value_size, def->value_size); 1033 map->name, (__u32)value_size, def->value_size);
1029 return -EINVAL; 1034 return -EINVAL;
1030 } 1035 }
1031 1036
1032 map->btf_key_type_id = key_id; 1037 map->btf_key_type_id = key->type;
1033 map->btf_value_type_id = value_id; 1038 map->btf_value_type_id = value->type;
1034 1039
1035 return 0; 1040 return 0;
1036} 1041}
@@ -2141,12 +2146,12 @@ const char *bpf_map__name(struct bpf_map *map)
2141 return map ? map->name : NULL; 2146 return map ? map->name : NULL;
2142} 2147}
2143 2148
2144uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map) 2149__u32 bpf_map__btf_key_type_id(const struct bpf_map *map)
2145{ 2150{
2146 return map ? map->btf_key_type_id : 0; 2151 return map ? map->btf_key_type_id : 0;
2147} 2152}
2148 2153
2149uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map) 2154__u32 bpf_map__btf_value_type_id(const struct bpf_map *map)
2150{ 2155{
2151 return map ? map->btf_value_type_id : 0; 2156 return map ? map->btf_value_type_id : 0;
2152} 2157}
@@ -2333,8 +2338,8 @@ bpf_perf_event_read_simple(void *mem, unsigned long size,
2333 volatile struct perf_event_mmap_page *header = mem; 2338 volatile struct perf_event_mmap_page *header = mem;
2334 __u64 data_tail = header->data_tail; 2339 __u64 data_tail = header->data_tail;
2335 __u64 data_head = header->data_head; 2340 __u64 data_head = header->data_head;
2341 int ret = LIBBPF_PERF_EVENT_ERROR;
2336 void *base, *begin, *end; 2342 void *base, *begin, *end;
2337 int ret;
2338 2343
2339 asm volatile("" ::: "memory"); /* in real code it should be smp_rmb() */ 2344 asm volatile("" ::: "memory"); /* in real code it should be smp_rmb() */
2340 if (data_head == data_tail) 2345 if (data_head == data_tail)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 1f8fc2060460..413778a93499 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -254,8 +254,8 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
254int bpf_map__fd(struct bpf_map *map); 254int bpf_map__fd(struct bpf_map *map);
255const struct bpf_map_def *bpf_map__def(struct bpf_map *map); 255const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
256const char *bpf_map__name(struct bpf_map *map); 256const char *bpf_map__name(struct bpf_map *map);
257uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map); 257__u32 bpf_map__btf_key_type_id(const struct bpf_map *map);
258uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map); 258__u32 bpf_map__btf_value_type_id(const struct bpf_map *map);
259 259
260typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); 260typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
261int bpf_map__set_priv(struct bpf_map *map, void *priv, 261int bpf_map__set_priv(struct bpf_map *map, void *priv,
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
index d39e4ff7d0bf..a6db83a88e85 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -106,7 +106,7 @@ The system configuration dump (if --quiet is not used) is followed by statistics
106\fBC1%, C2%, C3%\fP The residency percentage that Linux requested C1, C2, C3.... The system summary is the average of all CPUs in the system. Note that these are software, reflecting what was requested. The hardware counters reflect what was actually achieved. 106\fBC1%, C2%, C3%\fP The residency percentage that Linux requested C1, C2, C3.... The system summary is the average of all CPUs in the system. Note that these are software, reflecting what was requested. The hardware counters reflect what was actually achieved.
107\fBCPU%c1, CPU%c3, CPU%c6, CPU%c7\fP show the percentage residency in hardware core idle states. These numbers are from hardware residency counters. 107\fBCPU%c1, CPU%c3, CPU%c6, CPU%c7\fP show the percentage residency in hardware core idle states. These numbers are from hardware residency counters.
108\fBCoreTmp\fP Degrees Celsius reported by the per-core Digital Thermal Sensor. 108\fBCoreTmp\fP Degrees Celsius reported by the per-core Digital Thermal Sensor.
109\fBPkgTtmp\fP Degrees Celsius reported by the per-package Package Thermal Monitor. 109\fBPkgTmp\fP Degrees Celsius reported by the per-package Package Thermal Monitor.
110\fBGFX%rc6\fP The percentage of time the GPU is in the "render C6" state, rc6, during the measurement interval. From /sys/class/drm/card0/power/rc6_residency_ms. 110\fBGFX%rc6\fP The percentage of time the GPU is in the "render C6" state, rc6, during the measurement interval. From /sys/class/drm/card0/power/rc6_residency_ms.
111\fBGFXMHz\fP Instantaneous snapshot of what sysfs presents at the end of the measurement interval. From /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz. 111\fBGFXMHz\fP Instantaneous snapshot of what sysfs presents at the end of the measurement interval. From /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz.
112\fBPkg%pc2, Pkg%pc3, Pkg%pc6, Pkg%pc7\fP percentage residency in hardware package idle states. These numbers are from hardware residency counters. 112\fBPkg%pc2, Pkg%pc3, Pkg%pc6, Pkg%pc7\fP percentage residency in hardware package idle states. These numbers are from hardware residency counters.
@@ -114,7 +114,7 @@ The system configuration dump (if --quiet is not used) is followed by statistics
114\fBCorWatt\fP Watts consumed by the core part of the package. 114\fBCorWatt\fP Watts consumed by the core part of the package.
115\fBGFXWatt\fP Watts consumed by the Graphics part of the package -- available only on client processors. 115\fBGFXWatt\fP Watts consumed by the Graphics part of the package -- available only on client processors.
116\fBRAMWatt\fP Watts consumed by the DRAM DIMMS -- available only on server processors. 116\fBRAMWatt\fP Watts consumed by the DRAM DIMMS -- available only on server processors.
117\fBPKG_%\fP percent of the interval that RAPL throttling was active on the Package. 117\fBPKG_%\fP percent of the interval that RAPL throttling was active on the Package. Note that the system summary is the sum of the package throttling time, and thus may be higher than 100% on a multi-package system. Note that the meaning of this field is model specific. For example, some hardware increments this counter when RAPL responds to thermal limits, but does not increment this counter when RAPL responds to power limits. Comparing PkgWatt and PkgTmp to system limits is necessary.
118\fBRAM_%\fP percent of the interval that RAPL throttling was active on DRAM. 118\fBRAM_%\fP percent of the interval that RAPL throttling was active on DRAM.
119.fi 119.fi
120.SH TOO MUCH INFORMATION EXAMPLE 120.SH TOO MUCH INFORMATION EXAMPLE
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 4d14bbbf9b63..980bd9d20646 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -1163,9 +1163,7 @@ void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_
1163 if (!printed || !summary_only) 1163 if (!printed || !summary_only)
1164 print_header("\t"); 1164 print_header("\t");
1165 1165
1166 if (topo.num_cpus > 1) 1166 format_counters(&average.threads, &average.cores, &average.packages);
1167 format_counters(&average.threads, &average.cores,
1168 &average.packages);
1169 1167
1170 printed = 1; 1168 printed = 1;
1171 1169
@@ -1692,7 +1690,7 @@ void get_apic_id(struct thread_data *t)
1692 t->x2apic_id = edx; 1690 t->x2apic_id = edx;
1693 1691
1694 if (debug && (t->apic_id != t->x2apic_id)) 1692 if (debug && (t->apic_id != t->x2apic_id))
1695 fprintf(stderr, "cpu%d: apic 0x%x x2apic 0x%x\n", t->cpu_id, t->apic_id, t->x2apic_id); 1693 fprintf(outf, "cpu%d: apic 0x%x x2apic 0x%x\n", t->cpu_id, t->apic_id, t->x2apic_id);
1696} 1694}
1697 1695
1698/* 1696/*
@@ -2473,55 +2471,43 @@ int get_core_id(int cpu)
2473 2471
2474void set_node_data(void) 2472void set_node_data(void)
2475{ 2473{
2476 char path[80]; 2474 int pkg, node, lnode, cpu, cpux;
2477 FILE *filep; 2475 int cpu_count;
2478 int pkg, node, cpu; 2476
2479 2477 /* initialize logical_node_id */
2480 struct pkg_node_info { 2478 for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu)
2481 int count; 2479 cpus[cpu].logical_node_id = -1;
2482 int min; 2480
2483 } *pni; 2481 cpu_count = 0;
2484 2482 for (pkg = 0; pkg < topo.num_packages; pkg++) {
2485 pni = calloc(topo.num_packages, sizeof(struct pkg_node_info)); 2483 lnode = 0;
2486 if (!pni) 2484 for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu) {
2487 err(1, "calloc pkg_node_count"); 2485 if (cpus[cpu].physical_package_id != pkg)
2488 2486 continue;
2489 for (pkg = 0; pkg < topo.num_packages; pkg++) 2487 /* find a cpu with an unset logical_node_id */
2490 pni[pkg].min = topo.num_cpus; 2488 if (cpus[cpu].logical_node_id != -1)
2491 2489 continue;
2492 for (node = 0; node <= topo.max_node_num; node++) { 2490 cpus[cpu].logical_node_id = lnode;
2493 /* find the "first" cpu in the node */ 2491 node = cpus[cpu].physical_node_id;
2494 sprintf(path, "/sys/bus/node/devices/node%d/cpulist", node); 2492 cpu_count++;
2495 filep = fopen(path, "r"); 2493 /*
2496 if (!filep) 2494 * find all matching cpus on this pkg and set
2497 continue; 2495 * the logical_node_id
2498 fscanf(filep, "%d", &cpu); 2496 */
2499 fclose(filep); 2497 for (cpux = cpu; cpux <= topo.max_cpu_num; cpux++) {
2500 2498 if ((cpus[cpux].physical_package_id == pkg) &&
2501 pkg = cpus[cpu].physical_package_id; 2499 (cpus[cpux].physical_node_id == node)) {
2502 pni[pkg].count++; 2500 cpus[cpux].logical_node_id = lnode;
2503 2501 cpu_count++;
2504 if (node < pni[pkg].min) 2502 }
2505 pni[pkg].min = node; 2503 }
2506 } 2504 lnode++;
2507 2505 if (lnode > topo.nodes_per_pkg)
2508 for (pkg = 0; pkg < topo.num_packages; pkg++) 2506 topo.nodes_per_pkg = lnode;
2509 if (pni[pkg].count > topo.nodes_per_pkg) 2507 }
2510 topo.nodes_per_pkg = pni[0].count; 2508 if (cpu_count >= topo.max_cpu_num)
2511 2509 break;
2512 /* Fake 1 node per pkg for machines that don't
2513 * expose nodes and thus avoid -nan results
2514 */
2515 if (topo.nodes_per_pkg == 0)
2516 topo.nodes_per_pkg = 1;
2517
2518 for (cpu = 0; cpu < topo.num_cpus; cpu++) {
2519 pkg = cpus[cpu].physical_package_id;
2520 node = cpus[cpu].physical_node_id;
2521 cpus[cpu].logical_node_id = node - pni[pkg].min;
2522 } 2510 }
2523 free(pni);
2524
2525} 2511}
2526 2512
2527int get_physical_node_id(struct cpu_topology *thiscpu) 2513int get_physical_node_id(struct cpu_topology *thiscpu)
@@ -4471,7 +4457,9 @@ void process_cpuid()
4471 family = (fms >> 8) & 0xf; 4457 family = (fms >> 8) & 0xf;
4472 model = (fms >> 4) & 0xf; 4458 model = (fms >> 4) & 0xf;
4473 stepping = fms & 0xf; 4459 stepping = fms & 0xf;
4474 if (family == 6 || family == 0xf) 4460 if (family == 0xf)
4461 family += (fms >> 20) & 0xff;
4462 if (family >= 6)
4475 model += ((fms >> 16) & 0xf) << 4; 4463 model += ((fms >> 16) & 0xf) << 4;
4476 4464
4477 if (!quiet) { 4465 if (!quiet) {
@@ -4840,16 +4828,8 @@ void topology_probe()
4840 siblings = get_thread_siblings(&cpus[i]); 4828 siblings = get_thread_siblings(&cpus[i]);
4841 if (siblings > max_siblings) 4829 if (siblings > max_siblings)
4842 max_siblings = siblings; 4830 max_siblings = siblings;
4843 if (cpus[i].thread_id != -1) 4831 if (cpus[i].thread_id == 0)
4844 topo.num_cores++; 4832 topo.num_cores++;
4845
4846 if (debug > 1)
4847 fprintf(outf,
4848 "cpu %d pkg %d node %d core %d thread %d\n",
4849 i, cpus[i].physical_package_id,
4850 cpus[i].physical_node_id,
4851 cpus[i].physical_core_id,
4852 cpus[i].thread_id);
4853 } 4833 }
4854 4834
4855 topo.cores_per_node = max_core_id + 1; 4835 topo.cores_per_node = max_core_id + 1;
@@ -4875,6 +4855,20 @@ void topology_probe()
4875 topo.threads_per_core = max_siblings; 4855 topo.threads_per_core = max_siblings;
4876 if (debug > 1) 4856 if (debug > 1)
4877 fprintf(outf, "max_siblings %d\n", max_siblings); 4857 fprintf(outf, "max_siblings %d\n", max_siblings);
4858
4859 if (debug < 1)
4860 return;
4861
4862 for (i = 0; i <= topo.max_cpu_num; ++i) {
4863 fprintf(outf,
4864 "cpu %d pkg %d node %d lnode %d core %d thread %d\n",
4865 i, cpus[i].physical_package_id,
4866 cpus[i].physical_node_id,
4867 cpus[i].logical_node_id,
4868 cpus[i].physical_core_id,
4869 cpus[i].thread_id);
4870 }
4871
4878} 4872}
4879 4873
4880void 4874void
@@ -5102,7 +5096,7 @@ int get_and_dump_counters(void)
5102} 5096}
5103 5097
5104void print_version() { 5098void print_version() {
5105 fprintf(outf, "turbostat version 18.06.20" 5099 fprintf(outf, "turbostat version 18.07.27"
5106 " - Len Brown <lenb@kernel.org>\n"); 5100 " - Len Brown <lenb@kernel.org>\n");
5107} 5101}
5108 5102
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index f2f28b6c8915..810de20e8e26 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -158,6 +158,15 @@ struct bpf_map_def {
158 unsigned int numa_node; 158 unsigned int numa_node;
159}; 159};
160 160
161#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
162 struct ____btf_map_##name { \
163 type_key key; \
164 type_val value; \
165 }; \
166 struct ____btf_map_##name \
167 __attribute__ ((section(".maps." #name), used)) \
168 ____btf_map_##name = { }
169
161static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) = 170static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
162 (void *) BPF_FUNC_skb_load_bytes; 171 (void *) BPF_FUNC_skb_load_bytes;
163static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) = 172static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c
index 3619f3023088..ffdd27737c9e 100644
--- a/tools/testing/selftests/bpf/test_btf.c
+++ b/tools/testing/selftests/bpf/test_btf.c
@@ -247,6 +247,34 @@ static struct btf_raw_test raw_tests[] = {
247 .max_entries = 4, 247 .max_entries = 4,
248}, 248},
249 249
250{
251 .descr = "struct test #3 Invalid member offset",
252 .raw_types = {
253 /* int */ /* [1] */
254 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
255 /* int64 */ /* [2] */
256 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8),
257
258 /* struct A { */ /* [3] */
259 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 16),
260 BTF_MEMBER_ENC(NAME_TBD, 1, 64), /* int m; */
261 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* int64 n; */
262 /* } */
263 BTF_END_RAW,
264 },
265 .str_sec = "\0A\0m\0n\0",
266 .str_sec_size = sizeof("\0A\0m\0n\0"),
267 .map_type = BPF_MAP_TYPE_ARRAY,
268 .map_name = "struct_test3_map",
269 .key_size = sizeof(int),
270 .value_size = 16,
271 .key_type_id = 1,
272 .value_type_id = 3,
273 .max_entries = 4,
274 .btf_load_err = true,
275 .err_str = "Invalid member bits_offset",
276},
277
250/* Test member exceeds the size of struct. 278/* Test member exceeds the size of struct.
251 * 279 *
252 * struct A { 280 * struct A {
@@ -479,7 +507,7 @@ static struct btf_raw_test raw_tests[] = {
479 .key_size = sizeof(int), 507 .key_size = sizeof(int),
480 .value_size = sizeof(void *) * 4, 508 .value_size = sizeof(void *) * 4,
481 .key_type_id = 1, 509 .key_type_id = 1,
482 .value_type_id = 4, 510 .value_type_id = 5,
483 .max_entries = 4, 511 .max_entries = 4,
484}, 512},
485 513
@@ -1264,6 +1292,88 @@ static struct btf_raw_test raw_tests[] = {
1264 .err_str = "type != 0", 1292 .err_str = "type != 0",
1265}, 1293},
1266 1294
1295{
1296 .descr = "arraymap invalid btf key (a bit field)",
1297 .raw_types = {
1298 /* int */ /* [1] */
1299 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1300 /* 32 bit int with 32 bit offset */ /* [2] */
1301 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 32, 32, 8),
1302 BTF_END_RAW,
1303 },
1304 .str_sec = "",
1305 .str_sec_size = sizeof(""),
1306 .map_type = BPF_MAP_TYPE_ARRAY,
1307 .map_name = "array_map_check_btf",
1308 .key_size = sizeof(int),
1309 .value_size = sizeof(int),
1310 .key_type_id = 2,
1311 .value_type_id = 1,
1312 .max_entries = 4,
1313 .map_create_err = true,
1314},
1315
1316{
1317 .descr = "arraymap invalid btf key (!= 32 bits)",
1318 .raw_types = {
1319 /* int */ /* [1] */
1320 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1321 /* 16 bit int with 0 bit offset */ /* [2] */
1322 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 16, 2),
1323 BTF_END_RAW,
1324 },
1325 .str_sec = "",
1326 .str_sec_size = sizeof(""),
1327 .map_type = BPF_MAP_TYPE_ARRAY,
1328 .map_name = "array_map_check_btf",
1329 .key_size = sizeof(int),
1330 .value_size = sizeof(int),
1331 .key_type_id = 2,
1332 .value_type_id = 1,
1333 .max_entries = 4,
1334 .map_create_err = true,
1335},
1336
1337{
1338 .descr = "arraymap invalid btf value (too small)",
1339 .raw_types = {
1340 /* int */ /* [1] */
1341 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1342 BTF_END_RAW,
1343 },
1344 .str_sec = "",
1345 .str_sec_size = sizeof(""),
1346 .map_type = BPF_MAP_TYPE_ARRAY,
1347 .map_name = "array_map_check_btf",
1348 .key_size = sizeof(int),
1349 /* btf_value_size < map->value_size */
1350 .value_size = sizeof(__u64),
1351 .key_type_id = 1,
1352 .value_type_id = 1,
1353 .max_entries = 4,
1354 .map_create_err = true,
1355},
1356
1357{
1358 .descr = "arraymap invalid btf value (too big)",
1359 .raw_types = {
1360 /* int */ /* [1] */
1361 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1362 BTF_END_RAW,
1363 },
1364 .str_sec = "",
1365 .str_sec_size = sizeof(""),
1366 .map_type = BPF_MAP_TYPE_ARRAY,
1367 .map_name = "array_map_check_btf",
1368 .key_size = sizeof(int),
1369 /* btf_value_size > map->value_size */
1370 .value_size = sizeof(__u16),
1371 .key_type_id = 1,
1372 .value_type_id = 1,
1373 .max_entries = 4,
1374 .map_create_err = true,
1375},
1376
1267}; /* struct btf_raw_test raw_tests[] */ 1377}; /* struct btf_raw_test raw_tests[] */
1268 1378
1269static const char *get_next_str(const char *start, const char *end) 1379static const char *get_next_str(const char *start, const char *end)
@@ -2023,7 +2133,7 @@ static struct btf_raw_test pprint_test = {
2023 BTF_ENUM_ENC(NAME_TBD, 2), 2133 BTF_ENUM_ENC(NAME_TBD, 2),
2024 BTF_ENUM_ENC(NAME_TBD, 3), 2134 BTF_ENUM_ENC(NAME_TBD, 3),
2025 /* struct pprint_mapv */ /* [16] */ 2135 /* struct pprint_mapv */ /* [16] */
2026 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 8), 28), 2136 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 8), 32),
2027 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */ 2137 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */
2028 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */ 2138 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */
2029 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */ 2139 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */
diff --git a/tools/testing/selftests/bpf/test_btf_haskv.c b/tools/testing/selftests/bpf/test_btf_haskv.c
index 8c7ca096ecf2..b21b876f475d 100644
--- a/tools/testing/selftests/bpf/test_btf_haskv.c
+++ b/tools/testing/selftests/bpf/test_btf_haskv.c
@@ -10,11 +10,6 @@ struct ipv_counts {
10 unsigned int v6; 10 unsigned int v6;
11}; 11};
12 12
13typedef int btf_map_key;
14typedef struct ipv_counts btf_map_value;
15btf_map_key dumm_key;
16btf_map_value dummy_value;
17
18struct bpf_map_def SEC("maps") btf_map = { 13struct bpf_map_def SEC("maps") btf_map = {
19 .type = BPF_MAP_TYPE_ARRAY, 14 .type = BPF_MAP_TYPE_ARRAY,
20 .key_size = sizeof(int), 15 .key_size = sizeof(int),
@@ -22,6 +17,8 @@ struct bpf_map_def SEC("maps") btf_map = {
22 .max_entries = 4, 17 .max_entries = 4,
23}; 18};
24 19
20BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
21
25struct dummy_tracepoint_args { 22struct dummy_tracepoint_args {
26 unsigned long long pad; 23 unsigned long long pad;
27 struct sock *sock; 24 struct sock *sock;
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/snapshot.tc b/tools/testing/selftests/ftrace/test.d/00basic/snapshot.tc
new file mode 100644
index 000000000000..3b1f45e13a2e
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/00basic/snapshot.tc
@@ -0,0 +1,28 @@
1#!/bin/sh
2# description: Snapshot and tracing setting
3# flags: instance
4
5[ ! -f snapshot ] && exit_unsupported
6
7echo "Set tracing off"
8echo 0 > tracing_on
9
10echo "Allocate and take a snapshot"
11echo 1 > snapshot
12
13# Since trace buffer is empty, snapshot is also empty, but allocated
14grep -q "Snapshot is allocated" snapshot
15
16echo "Ensure keep tracing off"
17test `cat tracing_on` -eq 0
18
19echo "Set tracing on"
20echo 1 > tracing_on
21
22echo "Take a snapshot again"
23echo 1 > snapshot
24
25echo "Ensure keep tracing on"
26test `cat tracing_on` -eq 1
27
28exit 0
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index 95dd14648ba5..0f395dfb7774 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -44,12 +44,25 @@
44 44
45/******************** Little Endian Handling ********************************/ 45/******************** Little Endian Handling ********************************/
46 46
47#define cpu_to_le16(x) htole16(x) 47/*
48#define cpu_to_le32(x) htole32(x) 48 * cpu_to_le16/32 are used when initializing structures, a context where a
49 * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way
50 * that allows them to be used when initializing structures.
51 */
52
53#if __BYTE_ORDER == __LITTLE_ENDIAN
54#define cpu_to_le16(x) (x)
55#define cpu_to_le32(x) (x)
56#else
57#define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
58#define cpu_to_le32(x) \
59 ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
60 (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
61#endif
62
49#define le32_to_cpu(x) le32toh(x) 63#define le32_to_cpu(x) le32toh(x)
50#define le16_to_cpu(x) le16toh(x) 64#define le16_to_cpu(x) le16toh(x)
51 65
52
53/******************** Messages and Errors ***********************************/ 66/******************** Messages and Errors ***********************************/
54 67
55static const char argv0[] = "ffs-test"; 68static const char argv0[] = "ffs-test";
diff --git a/tools/virtio/asm/barrier.h b/tools/virtio/asm/barrier.h
index 0ac3caf90877..d0351f83aebe 100644
--- a/tools/virtio/asm/barrier.h
+++ b/tools/virtio/asm/barrier.h
@@ -13,8 +13,8 @@
13} while (0); 13} while (0);
14/* Weak barriers should be used. If not - it's a bug */ 14/* Weak barriers should be used. If not - it's a bug */
15# define mb() abort() 15# define mb() abort()
16# define rmb() abort() 16# define dma_rmb() abort()
17# define wmb() abort() 17# define dma_wmb() abort()
18#else 18#else
19#error Please fill in barrier macros 19#error Please fill in barrier macros
20#endif 20#endif
diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
index fca8381bbe04..fb22bccfbc8a 100644
--- a/tools/virtio/linux/kernel.h
+++ b/tools/virtio/linux/kernel.h
@@ -52,6 +52,11 @@ static inline void *kmalloc(size_t s, gfp_t gfp)
52 return __kmalloc_fake; 52 return __kmalloc_fake;
53 return malloc(s); 53 return malloc(s);
54} 54}
55static inline void *kmalloc_array(unsigned n, size_t s, gfp_t gfp)
56{
57 return kmalloc(n * s, gfp);
58}
59
55static inline void *kzalloc(size_t s, gfp_t gfp) 60static inline void *kzalloc(size_t s, gfp_t gfp)
56{ 61{
57 void *p = kmalloc(s, gfp); 62 void *p = kmalloc(s, gfp);