diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2018-06-22 21:20:35 +0200 | 
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2018-06-22 21:20:35 +0200 | 
| commit | 7731b8bc94e599c9a79e428f3359ff2c34b7576a (patch) | |
| tree | 879f18ccbe274122f2d4f095b43cbc7f953e0ada /tools/bpf/bpftool/common.c | |
| parent | 48e315618dc4dc8904182cd221e3d395d5d97005 (diff) | |
| parent | 9ffc59d57228d74809700be6f7ecb1db10292f05 (diff) | |
Merge branch 'linus' into x86/urgent
Required to queue a dependent fix.
Diffstat (limited to 'tools/bpf/bpftool/common.c')
| -rw-r--r-- | tools/bpf/bpftool/common.c | 77 | 
1 files changed, 76 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 465995281dcd..32f9e397a6c0 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -1,5 +1,5 @@  /* - * Copyright (C) 2017 Netronome Systems, Inc. + * Copyright (C) 2017-2018 Netronome Systems, Inc.   *   * This software is dual licensed under the GNU General License Version 2,   * June 1991 as shown in the file COPYING in the top-level directory of this @@ -33,6 +33,7 @@  /* Author: Jakub Kicinski <kubakici@wp.pl> */ +#include <ctype.h>  #include <errno.h>  #include <fcntl.h>  #include <fts.h> @@ -330,6 +331,16 @@ char *get_fdinfo(int fd, const char *key)  	return NULL;  } +void print_data_json(uint8_t *data, size_t len) +{ +	unsigned int i; + +	jsonw_start_array(json_wtr); +	for (i = 0; i < len; i++) +		jsonw_printf(json_wtr, "%d", data[i]); +	jsonw_end_array(json_wtr); +} +  void print_hex_data_json(uint8_t *data, size_t len)  {  	unsigned int i; @@ -420,6 +431,70 @@ void delete_pinned_obj_table(struct pinned_obj_table *tab)  	}  } +unsigned int get_page_size(void) +{ +	static int result; + +	if (!result) +		result = getpagesize(); +	return result; +} + +unsigned int get_possible_cpus(void) +{ +	static unsigned int result; +	char buf[128]; +	long int n; +	char *ptr; +	int fd; + +	if (result) +		return result; + +	fd = open("/sys/devices/system/cpu/possible", O_RDONLY); +	if (fd < 0) { +		p_err("can't open sysfs possible cpus"); +		exit(-1); +	} + +	n = read(fd, buf, sizeof(buf)); +	if (n < 2) { +		p_err("can't read sysfs possible cpus"); +		exit(-1); +	} +	close(fd); + +	if (n == sizeof(buf)) { +		p_err("read sysfs possible cpus overflow"); +		exit(-1); +	} + +	ptr = buf; +	n = 0; +	while (*ptr && *ptr != '\n') { +		unsigned int a, b; + +		if (sscanf(ptr, "%u-%u", &a, &b) == 2) { +			n += b - a + 1; + +			ptr = strchr(ptr, '-') + 1; +		} else if (sscanf(ptr, "%u", &a) == 1) { +			n++; +		} else { +			assert(0); +		} + +		while (isdigit(*ptr)) +			ptr++; +		if (*ptr == ',') +			ptr++; +	} + +	result = n; + +	return result; +} +  static char *  ifindex_to_name_ns(__u32 ifindex, __u32 ns_dev, __u32 ns_ino, char *buf)  {  | 
