Skip to content

Commit 4ff6a8d

Browse files
David Carrillo-CisnerosIngo Molnar
authored andcommitted
perf/core: Generalize event->group_flags
Currently, PERF_GROUP_SOFTWARE is used in the group_flags field of a group's leader to indicate that is_software_event(event) is true for all events in a group. This is the only usage of event->group_flags. This pattern of setting a group level flags when all events in the group share a property is useful for the flag introduced in the next patch and for future CQM/CMT flags. So this patches generalizes group_flags to work as an aggregate of event level flags. PERF_GROUP_SOFTWARE denotes an inmutable event's property. All other flags that I intend to add are also determinable at event initialization. To better convey the above, this patch renames event's group_flags to group_caps and PERF_GROUP_SOFTWARE to PERF_EV_CAP_SOFTWARE. Individual event flags are stored in the new event->event_caps. Since the cap flags do not change after event initialization, there is no need to serialize event_caps. This new field is used when events are added to a context, similarly to how PERF_GROUP_SOFTWARE and is_software_event() worked. Lastly, for consistency, updates is_software_event() to rely in event_cap instead of the context index. Signed-off-by: David Carrillo-Cisneros <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul Turner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vegard Nossum <[email protected]> Cc: Vince Weaver <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 29dd328 commit 4ff6a8d

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

include/linux/perf_event.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,12 @@ typedef void (*perf_overflow_handler_t)(struct perf_event *,
510510
struct perf_sample_data *,
511511
struct pt_regs *regs);
512512

513-
enum perf_group_flag {
514-
PERF_GROUP_SOFTWARE = 0x1,
515-
};
513+
/*
514+
* Event capabilities. For event_caps and groups caps.
515+
*
516+
* PERF_EV_CAP_SOFTWARE: Is a software event.
517+
*/
518+
#define PERF_EV_CAP_SOFTWARE BIT(0)
516519

517520
#define SWEVENT_HLIST_BITS 8
518521
#define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
@@ -568,7 +571,12 @@ struct perf_event {
568571
struct hlist_node hlist_entry;
569572
struct list_head active_entry;
570573
int nr_siblings;
571-
int group_flags;
574+
575+
/* Not serialized. Only written during event initialization. */
576+
int event_caps;
577+
/* The cumulative AND of all event_caps for events in this group. */
578+
int group_caps;
579+
572580
struct perf_event *group_leader;
573581
struct pmu *pmu;
574582
void *pmu_private;
@@ -988,7 +996,7 @@ static inline bool is_sampling_event(struct perf_event *event)
988996
*/
989997
static inline int is_software_event(struct perf_event *event)
990998
{
991-
return event->pmu->task_ctx_nr == perf_sw_context;
999+
return event->event_caps & PERF_EV_CAP_SOFTWARE;
9921000
}
9931001

9941002
extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];

kernel/events/core.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,7 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
14751475
if (event->group_leader == event) {
14761476
struct list_head *list;
14771477

1478-
if (is_software_event(event))
1479-
event->group_flags |= PERF_GROUP_SOFTWARE;
1478+
event->group_caps = event->event_caps;
14801479

14811480
list = ctx_group_list(event, ctx);
14821481
list_add_tail(&event->group_entry, list);
@@ -1630,9 +1629,7 @@ static void perf_group_attach(struct perf_event *event)
16301629

16311630
WARN_ON_ONCE(group_leader->ctx != event->ctx);
16321631

1633-
if (group_leader->group_flags & PERF_GROUP_SOFTWARE &&
1634-
!is_software_event(event))
1635-
group_leader->group_flags &= ~PERF_GROUP_SOFTWARE;
1632+
group_leader->group_caps &= event->event_caps;
16361633

16371634
list_add_tail(&event->group_entry, &group_leader->sibling_list);
16381635
group_leader->nr_siblings++;
@@ -1723,7 +1720,7 @@ static void perf_group_detach(struct perf_event *event)
17231720
sibling->group_leader = sibling;
17241721

17251722
/* Inherit group flags from the previous leader */
1726-
sibling->group_flags = event->group_flags;
1723+
sibling->group_caps = event->group_caps;
17271724

17281725
WARN_ON_ONCE(sibling->ctx != event->ctx);
17291726
}
@@ -2149,7 +2146,7 @@ static int group_can_go_on(struct perf_event *event,
21492146
/*
21502147
* Groups consisting entirely of software events can always go on.
21512148
*/
2152-
if (event->group_flags & PERF_GROUP_SOFTWARE)
2149+
if (event->group_caps & PERF_EV_CAP_SOFTWARE)
21532150
return 1;
21542151
/*
21552152
* If an exclusive group is already on, no other hardware
@@ -9490,6 +9487,9 @@ SYSCALL_DEFINE5(perf_event_open,
94909487
goto err_alloc;
94919488
}
94929489

9490+
if (pmu->task_ctx_nr == perf_sw_context)
9491+
event->event_caps |= PERF_EV_CAP_SOFTWARE;
9492+
94939493
if (group_leader &&
94949494
(is_software_event(event) != is_software_event(group_leader))) {
94959495
if (is_software_event(event)) {
@@ -9503,7 +9503,7 @@ SYSCALL_DEFINE5(perf_event_open,
95039503
*/
95049504
pmu = group_leader->pmu;
95059505
} else if (is_software_event(group_leader) &&
9506-
(group_leader->group_flags & PERF_GROUP_SOFTWARE)) {
9506+
(group_leader->group_caps & PERF_EV_CAP_SOFTWARE)) {
95079507
/*
95089508
* In case the group is a pure software group, and we
95099509
* try to add a hardware event, move the whole group to

0 commit comments

Comments
 (0)