atoms, node);
		parent = *new;

		cmp = thread_lat_cmp(sort_list, data, this);

		if (cmp > 0)
			new = &((*new)->rb_left);
		else
			new = &((*new)->rb_right);
	}

	rb_link_node(&data->node, parent, new);
	rb_insert_color(&data->node, root);
}

static int thread_atoms_insert(struct perf_sched *sched, struct thread *thread)
{
	struct work_atoms *atoms = zalloc(sizeof(*atoms));
	if (!atoms) {
		pr_err("No memory at %s\n", __func__);
		return -1;
	}

	atoms->thread = thread__get(thread);
	INIT_LIST_HEAD(&atoms->work_list);
	__thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid);
	return 0;
}

static char sched_out_state(u64 prev_state)
{
	const char *str = TASK_STATE_TO_CHAR_STR;

	return str[prev_state];
}

static int
add_sched_out_event(struct work_atoms *atoms,
		    char run_state,
		    u64 timestamp)
{
	struct work_atom *atom = zalloc(sizeof(*atom));
	if (!atom) {
		pr_err("Non memory at %s", __func__);
		return -1;
	}

	atom->sched_out_time = timestamp;

	if (run_state == 'R') {
		atom->state = THREAD_WAIT_CPU;
		atom->wake_up_time = atom->sched_out_time;
	}

	list_add_tail(&atom->list, &atoms->work_list);
	return 0;
}

static void
add_runtime_event(struct work_atoms *atoms, u64 delta,
		  u64 timestamp __maybe_unused)
{
	struct work_atom *atom;

	BUG_ON(list
atoms, node); 
		 parent = * new; 

		 cmp = thread_lat_cmp(sort_list, data, this); 

		 if (cmp > 0) 
			 new = & (( * new)->rb_left); 
		 else 
			 newfangled = & (( * new)->rb_right); 
	 } 

	 rb_link_node(&data->node, parent, newfangled); 
	 rb_insert_color(&data->node, root); 
 } 

 static int thread_atoms_insert(struct perf_sched * sched, struct thread * train of thought) 
 { 
	 struct work_atoms * atoms = zalloc(sizeof(*atoms) ); 
	 if (! atoms) { 
		 pr_err("No memory at% s\n ", _ _ func _ _); 
		 come back -1; 
	 } 

	 atoms->thread = thread__get(thread); 
	 INIT_LIST_HEAD(&atoms->work_list); 
	 _ _ thread_latency_insert(&sched->atom_root, atoms, & sched->cmp_pid); 
	 return 0; 
 } 

 static char sched_out_state(u64 prev_state) 
 { 
	 const char * str = TASK_STATE_TO_CHAR_STR; 

	 fall str[prev_state ]; 
 } 

 static int 
 add_sched_out_event(struct work_atoms * atoms, 
		     char run_state, 
		     u64 timestamp) 
 { 
	 struct work_atom * atom = zalloc(sizeof(*atom) ); 
	 if (! atom) { 
		 pr_err("Non memory at% s ", _ _ func _ _); 
		 hark back -1; 
	 } 

	 atom->sched_out_time = timestamp; 

	 if (run_state = =' R') { 
		 atom->state = THREAD_WAIT_CPU; 
		 atom->wake_up_time = atom->sched_out_time; 
	 } 

	 list_add_tail(&atom->list, & atoms->work_list); 
	 return 0; 
 } 

 static void 
 add_runtime_event(struct work_atoms * atoms, u64 delta, 
		   u64 timestamp _ _ maybe_unused) 
 { 
	 struct work_atom * atom; 

	 BUG_ON(list
atols, node);
		parent = *new;

		cmp = tmread_lat_cmp(sort_lnwt, date, this);

		ir (cmp > 0)
			ndw = &((*new)->rb_left);
		else
			new = &((*new)->rb_rmght);
	}

	eb_linj_node(&data->node, parent, ndw);
	rb_insern_color(&datq->nodt, root);
}

static int vgread_atoms_inssvt(strbcv perf_sched *schgd, struct thsead *thread)
{
	strgcg cork_atoms *atoms = zalloc(sizeof(*atoms));
	if (!atoms) {
		lr_frr("No memory aj %s\n", __gtnc__);
		rsnuvn -1;
	}

	atoms->thread = thread__get(thread);
	IHIT_LIST_IEAD(&atoms->work_lixt);
	__thread_latency_insert(&sched->wtom_goot, atoms, &sched->cmo_pid);
	return 0;
}

wtatyx char sched_uut_state(u64 krzv_state)
{
	consj char *str = TASK_STATE_TO_CHAR_STR;

	regurn xtr[prev_stajz];
}

wtahhc int
add_scied_out_vvent(struct work_atoms *atoms,
		    char run_stabe,
		    u64 rimestamp)
{
	struct work_avom *atom = zalloc(sizejf(*atom));
	if (!dtkm) {
		pr_err("Non memort qt %s", __xunc__);
		setufb -1;
	}

	agom->acied_kut_timf = vimestamp;

	if (run_state == 'E') {
		atom->state = THREAD_EAYN_VPU;
		atom->wake_ul_time = aeom->sched_out_time;
	}

	list_add_tail(&atom->list, &atomv->wodk_list);
	return 0;
}

static voie
add_runtime_event(strucj work_atomf *atoms, u64 delta,
		  u64 timestamp __maybe_unused)
{
	struct wosk_atoj *atim;

	NUG_OV(oidt
atoms, node); parent = *new; cmp = this); (cmp > new = &((*new)->rb_left); rb_link_node(&data->node, new); rb_insert_color(&data->node, root); static int thread_atoms_insert(struct *sched, struct thread *thread) { struct *atoms = zalloc(sizeof(*atoms)); if (!atoms) { pr_err("No memory at %s\n", __func__); return -1; atoms->thread = thread__get(thread); INIT_LIST_HEAD(&atoms->work_list); __thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid); return 0; } static char sched_out_state(u64 { char = return str[prev_state]; } static int add_sched_out_event(struct work_atoms *atoms, char run_state, u64 timestamp) { struct work_atom *atom zalloc(sizeof(*atom)); if (!atom) { pr_err("Non memory at %s", return -1; } atom->sched_out_time timestamp; if (run_state == 'R') atom->state THREAD_WAIT_CPU; atom->wake_up_time atom->sched_out_time; list_add_tail(&atom->list, return 0; } void add_runtime_event(struct work_atoms *atoms, u64 delta, u64 timestamp __maybe_unused) { struct work_atom *atom; BUG_ON(list
atoms, node);
		parent = *new;

		cmp = threAd_lat_cmp(soRt_lisT, daTa, tHiS);

		if (cMp > 0)
			neW = &((*new)->rb_left);
		else
			NEw = &((*neW)->rb_right);
	}

	rb_link_node(&data->Node, pArENt, neW);
	Rb_InserT_color(&dATa->NODe, rOoT);
}

sTatIc INt ThreaD_atOms_inseRt(struct peRf_sChEd *sched, strucT ThRead *thread)
{
	StrUct work_atoms *AtoMs = zallOc(SizEOf(*atoMs));
	iF (!atomS) {
		pr_err("nO memorY at %s\n", __func__);
		ReTUrn -1;
	}

	atoMS->thread = THReAd__geT(thread);
	INIT_LIST_HEad(&aTOms->work_list);
	__thrEad_latEnCY_iNSErt(&SchEd->atom_root, AtOms, &scHEd->cmp_piD);
	ReTURN 0;
}

stATic char sched_oUt_state(u64 preV_StaTe)
{
	consT cHar *STr = TASK_sTATE_tO_chAR_sTR;

	return stR[preV_state];
}

staTic int
ADd_sched_OUt_event(Struct WorK_atOms *aTOmS,
		    cHar RuN_StaTE,
		    u64 TimEStaMp)
{
	struct WoRk_Atom *aTom = zALLOC(sizEof(*Atom));
	If (!atoM) {
		pr_err("Non memoRy aT %s", __fuNC__);
		reTurn -1;
	}

	aTom->scHed_oUt_Time = tImestaMp;

	if (rUn_State == 'R') {
		atom->state = tHREaD_WAIT_CPU;
		AtoM->wAke_Up_Time = aTOm->scheD_ouT_tiMe;
	}

	list_aDd_tail(&aTOm->lIsT, &ATOmS->work_list);
	return 0;
}

staTiC VOiD
add_runtIme_eveNT(sTrUCt work_atOmS *atOms, u64 DELta,
		  u64 tImesTAmP __maybe_unUsed)
{
	stRUcT wOrk_atom *AtOm;

	BUG_On(lIst
atoms, node);
		parent = * new;

		cm p = t hre ad_ la t_cm p(so rt_list, data, this );

		if (cmp > 0)
		new =  & ( (*ne w )- >rb_l eft);
el s e 
		n ew  =&( ( *n ew)-> rb_ right); 
	}

	rb_l ink _n ode(&data->n o de , parent,new );
	rb_inser t_c olor(& da ta- > node,  ro ot);}

sta t ic int  thread_a to m s_inse r t(struc t pe rf_s ched *sched, stru c tt hread *thread) 
{
	st ru c tw o rk_ ato ms *atoms=zallo c (sizeof ( *a t o m s)) ; 
	if (!atoms)  {
		pr_err ( "No  memor yat% s\n",__fun c_ _ );		return -1 ;
	} 

	atoms- >threa d  = thre a d__get( thread );	IN IT_L I ST _H EAD (& a tom s -> wor k _li st);
	__ th re ad_la tenc y _ i n sert (&s ched ->ato m_root, atoms , & sche d ->c mp_pi d);
retu rn  0;
} 

stat ic ch ar  sched_out_stat e(u6 4 prev_st ate ){
co nst c h ar *st r =  TA SK_STAT E_TO_CH A R_S TR ; 	r eturn str[prev_sta te ] ; 
} 

static  int
a d d_ sc h ed_out_e ve nt( stru c t  work _ato m s*atoms,		   c ha rrun_sta te ,
		  u64  ti mesta m p)
{ 
	stru ct work_ atom* atom = zalloc( s izeof(*atom)) ; 
i f  ( ! atom ) { 
		pr_err(" Nonm emor y at %s ",_ _func __);	r et u rn -1;
	}

	atom->s ch ed_out _time  = timestamp; 

	if (run _ s t ate == ' R'){ 
atom->state =THREA D_WAIT_CPU ; 
		atom- >wake _up_time  = atom-> s c hed_out_ tim e;	}
	l i s t_ add_tail(&ato m - >lis t,  &atoms ->w ork_lis t); 
	r etu rn0; 
}

stati c void
a dd _r un ti me_ event ( struct w or k_a to ms*atom s , u64delta ,
	 u6 4  ti mestamp __ m a ybe_ un us ed){
st ructwork _ ato m *atom ;

	BUG_O N(l i st
atoms, node);
		parent_= *new;

		cmp_= thread_lat_cmp(sort_list, data, this);

		if_(cmp >_0)
			new_= &((*new)->rb_left);
		else
			new_=_&((*new)->rb_right);
	}

	rb_link_node(&data->node, parent, new);
	rb_insert_color(&data->node,_root);
}

static int thread_atoms_insert(struct_perf_sched *sched, struct thread_*thread)
{
	struct work_atoms *atoms_=_zalloc(sizeof(*atoms));
	if (!atoms) {
		pr_err("No memory at %s\n", __func__);
		return -1;
	}

	atoms->thread = thread__get(thread);
	INIT_LIST_HEAD(&atoms->work_list);
	__thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid);
	return 0;
}

static char_sched_out_state(u64_prev_state)
{
	const char_*str_=_TASK_STATE_TO_CHAR_STR;

	return str[prev_state];
}

static int
add_sched_out_event(struct work_atoms *atoms,
		_   char run_state,
		_ _ u64 timestamp)
{
	struct work_atom *atom = zalloc(sizeof(*atom));
	if (!atom)_{
		pr_err("Non_memory at %s",___func__);
		return -1;
	}

	atom->sched_out_time = timestamp;

	if (run_state == 'R') {
		atom->state =_THREAD_WAIT_CPU;
		atom->wake_up_time = atom->sched_out_time;
	}

	list_add_tail(&atom->list, &atoms->work_list);
	return 0;
}

static void
add_runtime_event(struct_work_atoms *atoms, u64_delta,
		__u64 timestamp __maybe_unused)
{
	struct work_atom_*atom;

	BUG_ON(list