perf: Export software-only event group characteristic as a flag
authorFrederic Weisbecker <fweisbec@gmail.com>
Sun, 10 Jan 2010 00:25:51 +0000 (01:25 +0100)
committerFrederic Weisbecker <fweisbec@gmail.com>
Sat, 16 Jan 2010 11:30:40 +0000 (12:30 +0100)
Before scheduling an event group, we first check if a group can go
on. We first check if the group is made of software only events
first, in which case it is enough to know if the group can be
scheduled in.

For that purpose, we iterate through the whole group, which is
wasteful as we could do this check when we add/delete an event to
a group.

So we create a group_flags field in perf event that can host
characteristics from a group of events, starting with a first
PERF_GROUP_SOFTWARE flag that reduces the check on the fast path.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
include/linux/perf_event.h
kernel/perf_event.c

index cdbc2aa64a0be6f2999b6029d4a47ef8499f799c..c6f812e4d058855e95274af743b76d003b4631d4 100644 (file)
@@ -565,6 +565,10 @@ typedef void (*perf_overflow_handler_t)(struct perf_event *, int,
                                        struct perf_sample_data *,
                                        struct pt_regs *regs);
 
+enum perf_group_flag {
+       PERF_GROUP_SOFTWARE = 0x1,
+};
+
 /**
  * struct perf_event - performance event kernel representation:
  */
@@ -574,6 +578,7 @@ struct perf_event {
        struct list_head                event_entry;
        struct list_head                sibling_list;
        int                             nr_siblings;
+       int                             group_flags;
        struct perf_event               *group_leader;
        struct perf_event               *output;
        const struct pmu                *pmu;
index bbebe28326398d578a0dd5584e8c643c6e2c69e9..eae6ff69360477c8fb0f610fe016a017bf9203a8 100644 (file)
@@ -315,9 +315,16 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
        if (group_leader == event) {
                struct list_head *list;
 
+               if (is_software_event(event))
+                       event->group_flags |= PERF_GROUP_SOFTWARE;
+
                list = ctx_group_list(event, ctx);
                list_add_tail(&event->group_entry, list);
        } else {
+               if (group_leader->group_flags & PERF_GROUP_SOFTWARE &&
+                   !is_software_event(event))
+                       group_leader->group_flags &= ~PERF_GROUP_SOFTWARE;
+
                list_add_tail(&event->group_entry, &group_leader->sibling_list);
                group_leader->nr_siblings++;
        }
@@ -372,6 +379,9 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
                list = ctx_group_list(event, ctx);
                list_move_tail(&sibling->group_entry, list);
                sibling->group_leader = sibling;
+
+               /* Inherit group flags from the previous leader */
+               sibling->group_flags = event->group_flags;
        }
 }
 
@@ -699,24 +709,6 @@ group_error:
        return -EAGAIN;
 }
 
-/*
- * Return 1 for a group consisting entirely of software events,
- * 0 if the group contains any hardware events.
- */
-static int is_software_only_group(struct perf_event *leader)
-{
-       struct perf_event *event;
-
-       if (!is_software_event(leader))
-               return 0;
-
-       list_for_each_entry(event, &leader->sibling_list, group_entry)
-               if (!is_software_event(event))
-                       return 0;
-
-       return 1;
-}
-
 /*
  * Work out whether we can put this event group on the CPU now.
  */
@@ -727,7 +719,7 @@ static int group_can_go_on(struct perf_event *event,
        /*
         * Groups consisting entirely of software events can always go on.
         */
-       if (is_software_only_group(event))
+       if (event->group_flags & PERF_GROUP_SOFTWARE)
                return 1;
        /*
         * If an exclusive group is already on, no other hardware