}
 }
 
-void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
+void perf_event_attr__set_max_precise_ip(struct perf_event_attr *pattr)
 {
-       attr->precise_ip = 3;
+       struct perf_event_attr attr = {
+               .type           = PERF_TYPE_HARDWARE,
+               .config         = PERF_COUNT_HW_CPU_CYCLES,
+               .exclude_kernel = 1,
+               .precise_ip     = 3,
+       };
 
-       while (attr->precise_ip != 0) {
-               int fd = sys_perf_event_open(attr, 0, -1, -1, 0);
+       event_attr_init(&attr);
+
+       /*
+        * Unnamed union member, not supported as struct member named
+        * initializer in older compilers such as gcc 4.4.7
+        */
+       attr.sample_period = 1;
+
+       while (attr.precise_ip != 0) {
+               int fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
                if (fd != -1) {
                        close(fd);
                        break;
                }
-               --attr->precise_ip;
+               --attr.precise_ip;
        }
+
+       pattr->precise_ip = attr.precise_ip;
 }
 
 int __perf_evlist__add_default(struct perf_evlist *evlist, bool precise)
 
 
        if (!precise)
                goto new_event;
-       /*
-        * Unnamed union member, not supported as struct member named
-        * initializer in older compilers such as gcc 4.4.7
-        *
-        * Just for probing the precise_ip:
-        */
-       attr.sample_period = 1;
 
        perf_event_attr__set_max_precise_ip(&attr);
        /*
         * Now let the usual logic to set up the perf_event_attr defaults
         * to kick in when we return and before perf_evsel__open() is called.
         */
-       attr.sample_period = 0;
 new_event:
        evsel = perf_evsel__new(&attr);
        if (evsel == NULL)