@@ -45,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
4545 thread__set_comm (thread , comm , 0 );
4646 }
4747
48+ machine -> current_tid = NULL ;
49+
4850 return 0 ;
4951}
5052
@@ -104,6 +106,7 @@ void machine__exit(struct machine *machine)
104106 dsos__delete (& machine -> user_dsos );
105107 dsos__delete (& machine -> kernel_dsos );
106108 zfree (& machine -> root_dir );
109+ zfree (& machine -> current_tid );
107110}
108111
109112void machine__delete (struct machine * machine )
@@ -1481,3 +1484,46 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
14811484 /* command specified */
14821485 return 0 ;
14831486}
1487+
1488+ pid_t machine__get_current_tid (struct machine * machine , int cpu )
1489+ {
1490+ if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine -> current_tid )
1491+ return -1 ;
1492+
1493+ return machine -> current_tid [cpu ];
1494+ }
1495+
1496+ int machine__set_current_tid (struct machine * machine , int cpu , pid_t pid ,
1497+ pid_t tid )
1498+ {
1499+ struct thread * thread ;
1500+
1501+ if (cpu < 0 )
1502+ return - EINVAL ;
1503+
1504+ if (!machine -> current_tid ) {
1505+ int i ;
1506+
1507+ machine -> current_tid = calloc (MAX_NR_CPUS , sizeof (pid_t ));
1508+ if (!machine -> current_tid )
1509+ return - ENOMEM ;
1510+ for (i = 0 ; i < MAX_NR_CPUS ; i ++ )
1511+ machine -> current_tid [i ] = -1 ;
1512+ }
1513+
1514+ if (cpu >= MAX_NR_CPUS ) {
1515+ pr_err ("Requested CPU %d too large. " , cpu );
1516+ pr_err ("Consider raising MAX_NR_CPUS\n" );
1517+ return - EINVAL ;
1518+ }
1519+
1520+ machine -> current_tid [cpu ] = tid ;
1521+
1522+ thread = machine__findnew_thread (machine , pid , tid );
1523+ if (!thread )
1524+ return - ENOMEM ;
1525+
1526+ thread -> cpu = cpu ;
1527+
1528+ return 0 ;
1529+ }
0 commit comments