perf_events: Move code around to prepare for cgroup