static void process_event(union perf_event *event, struct perf_sample *sample,
                          struct perf_evsel *evsel, struct machine *machine,
-                         struct addr_location *al)
+                         struct thread *thread,
+                         struct addr_location *al __maybe_unused)
 {
        struct perf_event_attr *attr = &evsel->attr;
-       struct thread *thread = al->thread;
 
        if (output[attr->type].fields == 0)
                return;
        if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
                return 0;
 
-       scripting_ops->process_event(event, sample, evsel, machine, &al);
+       scripting_ops->process_event(event, sample, evsel, machine, thread, &al);
 
        evsel->hists.stats.total_period += sample->period;
        return 0;
 
                                    struct perf_sample *sample,
                                    struct perf_evsel *evsel,
                                    struct machine *machine __maybe_unused,
-                                   struct addr_location *al)
+                                   struct thread *thread,
+                                       struct addr_location *al)
 {
        struct format_field *field;
        static char handler[256];
        int cpu = sample->cpu;
        void *data = sample->raw_data;
        unsigned long long nsecs = sample->time;
-       struct thread *thread = al->thread;
        char *comm = thread->comm;
 
        dSP;
                                       struct perf_sample *sample,
                                       struct perf_evsel *evsel,
                                       struct machine *machine __maybe_unused,
-                                      struct addr_location *al __maybe_unused)
+                                      struct thread *thread __maybe_unused,
+                                          struct addr_location *al __maybe_unused)
 {
        dSP;
 
                               struct perf_sample *sample,
                               struct perf_evsel *evsel,
                               struct machine *machine,
-                              struct addr_location *al)
+                              struct thread *thread,
+                                  struct addr_location *al)
 {
-       perl_process_tracepoint(event, sample, evsel, machine, al);
-       perl_process_event_generic(event, sample, evsel, machine, al);
+       perl_process_tracepoint(event, sample, evsel, machine, thread, al);
+       perl_process_event_generic(event, sample, evsel, machine, thread, al);
 }
 
 static void run_start_sub(void)
 
                                 struct perf_sample *sample,
                                 struct perf_evsel *evsel,
                                 struct machine *machine __maybe_unused,
+                                struct thread *thread,
                                 struct addr_location *al)
 {
        PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
        int cpu = sample->cpu;
        void *data = sample->raw_data;
        unsigned long long nsecs = sample->time;
-       struct thread *thread = al->thread;
        char *comm = thread->comm;
 
        t = PyTuple_New(MAX_FIELDS);
                                         struct perf_sample *sample,
                                         struct perf_evsel *evsel,
                                         struct machine *machine __maybe_unused,
+                                        struct thread *thread,
                                         struct addr_location *al)
 {
        PyObject *handler, *retval, *t, *dict;
        static char handler_name[64];
        unsigned n = 0;
-       struct thread *thread = al->thread;
 
        /*
         * Use the MAX_FIELDS to make the function expandable, though
                                 struct perf_sample *sample,
                                 struct perf_evsel *evsel,
                                 struct machine *machine,
+                                struct thread *thread,
                                 struct addr_location *al)
 {
        switch (evsel->attr.type) {
        case PERF_TYPE_TRACEPOINT:
                python_process_tracepoint(perf_event, sample, evsel,
-                                         machine, al);
+                                         machine, thread, al);
                break;
        /* Reserve for future process_hw/sw/raw APIs */
        default:
                python_process_general_event(perf_event, sample, evsel,
-                                            machine, al);
+                                            machine, thread, al);
        }
 }
 
 
                                      struct perf_sample *sample __maybe_unused,
                                      struct perf_evsel *evsel __maybe_unused,
                                      struct machine *machine __maybe_unused,
-                                     struct addr_location *al __maybe_unused)
+                                     struct thread *thread __maybe_unused,
+                                         struct addr_location *al __maybe_unused)
 {
 }
 
 
 struct perf_sample;
 union perf_event;
 struct perf_tool;
+struct thread;
 
 extern struct pevent *perf_pevent;
 
                               struct perf_sample *sample,
                               struct perf_evsel *evsel,
                               struct machine *machine,
-                              struct addr_location *al);
+                              struct thread *thread,
+                                  struct addr_location *al);
        int (*generate_script) (struct pevent *pevent, const char *outfile);
 };