Skip to contentSkip to conversation

perf tools: Add API to config maps in bpf object

PATCH Arnaldo Carvalho de Melo 2 participants 3 messages Feb 19, 2016 – Feb 22, 2016 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Sorry for the top post, but the message below didn't made it thru due to local problems as I recently switched notebooks, my postfix setup barfed this one :-\

This is what I have in my tmp.perf/bpf_map:

https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/bpf_map&id=5c78fe3c5a944ba7f9a85f59548295211f3d252c

Please take a look and see if you're ok with it,

I'm going thru the other patches in this week's patchkit, thanks for keeping up with this work,

Regards,

- Arnaldo

Em Fri, Feb 05, 2016 at 02:01:31PM +0000, Wang Nan escreveu:

Quoted 5 lines

bpf__config_obj() is introduced as a core API to config BPF object after loading. One configuration option of maps is introduced. After this patch BPF object can accept configuration like:

maps:my_map.value=1234

Ok, tested this, works great, trace_printk gets what I pass via the event definition, etc.

One suggestion, tho. I think "maps", plural, is strange, we're referring to one map, not multiple ones when we write: "map:my_map.value=1234", so I have this on a separate branch, tmp.perf/bpf_map, do you agree? Shorter, one character less to type :-)

I also changed some error reports and the commit log, hope that improved it, please also take a look.

I'm now working on the patch right after this, all will be on the tmp.perf/bpf_map shortly.

- Arnaldo

tools/perf/util/bpf-loader.c +6 -7
index e24d5b7a9fec..fdb23c785ced 100644
@@ -921,8 +921,8 @@ bpf__obj_config_map(struct bpf_object *obj,
 		    struct perf_evlist *evlist,
 		    int *key_scan_pos)
 {
-	/* key is "maps:<mapname>.<config opt>" */
-	char *map_name = strdup(term->config + sizeof("maps:") - 1);
+	/* key is "map:<mapname>.<config opt>" */
+	char *map_name = strdup(term->config + sizeof("map:") - 1);
 	struct bpf_map *map;
 	int err = -BPF_LOADER_ERRNO__OBJCONF_OPT;
 	char *map_opt;
@@ -961,8 +961,7 @@ bpf__obj_config_map(struct bpf_object *obj,
 		}
 	}
 
-	pr_debug("ERROR: Invalid config option '%s' for maps\n",
-		 map_opt);
+	pr_debug("ERROR: Invalid map config option '%s'\n", map_opt);
 	err = -BPF_LOADER_ERRNO__OBJCONF_MAP_OPT;
 out:
 	free(map_name);
@@ -982,8 +981,8 @@ int bpf__config_obj(struct bpf_object *obj,
 	if (!obj || !term || !term->config)
 		return -EINVAL;
 
-	if (!prefixcmp(term->config, "maps:")) {
-		key_scan_pos = sizeof("maps:") - 1;
+	if (!prefixcmp(term->config, "map:")) {
+		key_scan_pos = sizeof("map:") - 1;
 		err = bpf__obj_config_map(obj, term, evlist, &key_scan_pos);
 		goto out;
 	}
@@ -1011,7 +1010,7 @@ static const char *bpf_loader_strerror_table[NR_ERRNO] = {
 	[ERRCODE_OFFSET(PROLOGUEOOB)]	= "Offset out of bound for prologue",
 	[ERRCODE_OFFSET(OBJCONF_OPT)]	= "Invalid object config option",
 	[ERRCODE_OFFSET(OBJCONF_CONF)]	= "Config value not set (missing '=')",
-	[ERRCODE_OFFSET(OBJCONF_MAP_OPT)]	= "Invalid object maps config option",
+	[ERRCODE_OFFSET(OBJCONF_MAP_OPT)]	= "Invalid object map config option",
 	[ERRCODE_OFFSET(OBJCONF_MAP_NOTEXIST)]	= "Target map doesn't exist",
 	[ERRCODE_OFFSET(OBJCONF_MAP_VALUE)]	= "Incorrect value type for map",
 	[ERRCODE_OFFSET(OBJCONF_MAP_TYPE)]	= "Incorrect map type",

----- End forwarded message -----

#1 lore raw
Quoted 9 lines · Arnaldo Carvalho de Melo

Sorry for the top post, but the message below didn't made it thru due to local problems as I recently switched notebooks, my postfix setup barfed this one :-\

This is what I have in my tmp.perf/bpf_map:

https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/bpf_map&id=5c78fe3c5a944ba7f9a85f59548295211f3d252c

Please take a look and see if you're ok with it,

I agree your change, but the commit you mentioned has a bug which I have already fixed in Feb. 19 patch set:

At bpf_map__config_value:

+ if (!term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
+ pr_debug("ERROR: wrong value type\n");
+ return -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE;
+ }

Should use

         if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM)

I'll switch 'maps' to 'map' as you did in my tree and send this patch again. (still based on perf/core, so I can solve potential conflicts in my side).

Thank you.

author maintainer
#2 lore raw

Em Mon, Feb 22, 2016 at 12:05:36PM +0800, Wangnan (F) escreveu:

Quoted 23 lines · Arnaldo Carvalho de Melo
Quoted 9 lines

Sorry for the top post, but the message below didn't made it thru due to local problems as I recently switched notebooks, my postfix setup barfed this one :-\

This is what I have in my tmp.perf/bpf_map:

https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/bpf_map&id=5c78fe3c5a944ba7f9a85f59548295211f3d252c

Please take a look and see if you're ok with it,

I agree your change, but the commit you mentioned has a bug which I have already fixed in Feb. 19 patch set:

At bpf_map__config_value:

(quoted diff) +4 -0
+        if (!term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
+                pr_debug("ERROR: wrong value type\n");
+                return -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE;
+        }
Quoted 7 lines

Should use

         if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM)

I'll switch 'maps' to 'map' as you did in my tree and send this patch again. (still based on perf/core, so I can solve potential conflicts in my side).

Ok, going thru the patchkit again, noticed the only change was the above one for this patch, thanks:

uet linux]$ interdiff /wb/1.patch /tmp/acme.patch

tools/perf/util/bpf-loader.c +1 -1
diff -u b/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
@@ -897,7 +897,7 @@
 		return -BPF_LOADER_ERRNO__OBJCONF_CONF;
 	}
 
-	if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM) {
+	if (!term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
 		pr_debug("ERROR: wrong value type\n");
 		return -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE;
 	}

[acme@jouet linux]$