Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add evlist__disable_evsel/evlist__enable_evsel

Adding interface to enable/disable single event in the evlist based on
its name. It will be used later in new control enable/disable interface.

Keeping the evlist::enabled true when one or more events are enabled so
the toggle can work properly and toggle evlist to disabled state.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Alexei Budankov <abudankov@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20201210204330.233864-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
7cfcd1e0 96aea4da

+68 -3
+66 -3
tools/perf/util/evlist.c
··· 381 381 return true; 382 382 } 383 383 384 - void evlist__disable(struct evlist *evlist) 384 + static int evsel__strcmp(struct evsel *pos, char *evsel_name) 385 + { 386 + if (!evsel_name) 387 + return 0; 388 + if (evsel__is_dummy_event(pos)) 389 + return 1; 390 + return strcmp(pos->name, evsel_name); 391 + } 392 + 393 + static int evlist__is_enabled(struct evlist *evlist) 394 + { 395 + struct evsel *pos; 396 + 397 + evlist__for_each_entry(evlist, pos) { 398 + if (!evsel__is_group_leader(pos) || !pos->core.fd) 399 + continue; 400 + /* If at least one event is enabled, evlist is enabled. */ 401 + if (!pos->disabled) 402 + return true; 403 + } 404 + return false; 405 + } 406 + 407 + static void __evlist__disable(struct evlist *evlist, char *evsel_name) 385 408 { 386 409 struct evsel *pos; 387 410 struct affinity affinity; ··· 420 397 affinity__set(&affinity, cpu); 421 398 422 399 evlist__for_each_entry(evlist, pos) { 400 + if (evsel__strcmp(pos, evsel_name)) 401 + continue; 423 402 if (evsel__cpu_iter_skip(pos, cpu)) 424 403 continue; 425 404 if (pos->disabled || !evsel__is_group_leader(pos) || !pos->core.fd) ··· 439 414 440 415 affinity__cleanup(&affinity); 441 416 evlist__for_each_entry(evlist, pos) { 417 + if (evsel__strcmp(pos, evsel_name)) 418 + continue; 442 419 if (!evsel__is_group_leader(pos) || !pos->core.fd) 443 420 continue; 444 421 pos->disabled = true; 445 422 } 446 423 447 - evlist->enabled = false; 424 + /* 425 + * If we disabled only single event, we need to check 426 + * the enabled state of the evlist manually. 427 + */ 428 + if (evsel_name) 429 + evlist->enabled = evlist__is_enabled(evlist); 430 + else 431 + evlist->enabled = false; 448 432 } 449 433 450 - void evlist__enable(struct evlist *evlist) 434 + void evlist__disable(struct evlist *evlist) 435 + { 436 + __evlist__disable(evlist, NULL); 437 + } 438 + 439 + void evlist__disable_evsel(struct evlist *evlist, char *evsel_name) 440 + { 441 + __evlist__disable(evlist, evsel_name); 442 + } 443 + 444 + static void __evlist__enable(struct evlist *evlist, char *evsel_name) 451 445 { 452 446 struct evsel *pos; 453 447 struct affinity affinity; ··· 479 435 affinity__set(&affinity, cpu); 480 436 481 437 evlist__for_each_entry(evlist, pos) { 438 + if (evsel__strcmp(pos, evsel_name)) 439 + continue; 482 440 if (evsel__cpu_iter_skip(pos, cpu)) 483 441 continue; 484 442 if (!evsel__is_group_leader(pos) || !pos->core.fd) ··· 490 444 } 491 445 affinity__cleanup(&affinity); 492 446 evlist__for_each_entry(evlist, pos) { 447 + if (evsel__strcmp(pos, evsel_name)) 448 + continue; 493 449 if (!evsel__is_group_leader(pos) || !pos->core.fd) 494 450 continue; 495 451 pos->disabled = false; 496 452 } 497 453 454 + /* 455 + * Even single event sets the 'enabled' for evlist, 456 + * so the toggle can work properly and toggle to 457 + * 'disabled' state. 458 + */ 498 459 evlist->enabled = true; 460 + } 461 + 462 + void evlist__enable(struct evlist *evlist) 463 + { 464 + __evlist__enable(evlist, NULL); 465 + } 466 + 467 + void evlist__enable_evsel(struct evlist *evlist, char *evsel_name) 468 + { 469 + __evlist__enable(evlist, evsel_name); 499 470 } 500 471 501 472 void evlist__toggle_enable(struct evlist *evlist)
+2
tools/perf/util/evlist.h
··· 186 186 void evlist__disable(struct evlist *evlist); 187 187 void evlist__enable(struct evlist *evlist); 188 188 void evlist__toggle_enable(struct evlist *evlist); 189 + void evlist__disable_evsel(struct evlist *evlist, char *evsel_name); 190 + void evlist__enable_evsel(struct evlist *evlist, char *evsel_name); 189 191 190 192 int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx); 191 193