PERF_SAMPLE_REGS_INTR                   = 1U << 18,
        PERF_SAMPLE_PHYS_ADDR                   = 1U << 19,
        PERF_SAMPLE_AUX                         = 1U << 20,
+       PERF_SAMPLE_CGROUP                      = 1U << 21,
 
-       PERF_SAMPLE_MAX = 1U << 21,             /* non-ABI */
+       PERF_SAMPLE_MAX = 1U << 22,             /* non-ABI */
 
        __PERF_SAMPLE_CALLCHAIN_EARLY           = 1ULL << 63, /* non-ABI; internal use */
 };
 
        help
          This option extends the perf per-cpu mode to restrict monitoring
          to threads which belong to the cgroup specified and run on the
-         designated cpu.
+         designated cpu.  Or this can be used to have cgroup ID in samples
+         so that it can monitor performance events among cgroups.
 
          Say N if unsure.
 
 
        if (sample_type & PERF_SAMPLE_PHYS_ADDR)
                size += sizeof(data->phys_addr);
 
+       if (sample_type & PERF_SAMPLE_CGROUP)
+               size += sizeof(data->cgroup);
+
        event->header_size = size;
 }
 
        if (sample_type & PERF_SAMPLE_PHYS_ADDR)
                perf_output_put(handle, data->phys_addr);
 
+       if (sample_type & PERF_SAMPLE_CGROUP)
+               perf_output_put(handle, data->cgroup);
+
        if (sample_type & PERF_SAMPLE_AUX) {
                perf_output_put(handle, data->aux_size);
 
        if (sample_type & PERF_SAMPLE_PHYS_ADDR)
                data->phys_addr = perf_virt_to_phys(data->addr);
 
+#ifdef CONFIG_CGROUP_PERF
+       if (sample_type & PERF_SAMPLE_CGROUP) {
+               struct cgroup *cgrp;
+
+               /* protected by RCU */
+               cgrp = task_css_check(current, perf_event_cgrp_id, 1)->cgroup;
+               data->cgroup = cgroup_id(cgrp);
+       }
+#endif
+
        if (sample_type & PERF_SAMPLE_AUX) {
                u64 size;
 
 
        if (attr->sample_type & PERF_SAMPLE_REGS_INTR)
                ret = perf_reg_validate(attr->sample_regs_intr);
+
+#ifndef CONFIG_CGROUP_PERF
+       if (attr->sample_type & PERF_SAMPLE_CGROUP)
+               return -EINVAL;
+#endif
+
 out:
        return ret;