return err;
		}
	}

	return 0;
}

int thread_stack__flush(struct thread *thread)
{
	struct thread_stack *ts = thread->ts;
	unsigned int pos;
	int err = 0;

	if (ts) {
		for (pos = 0; pos < ts->arr_sz; pos++) {
			int ret = __thread_stack__flush(thread, ts + pos);

			if (ret)
				err = ret;
		}
	}

	return err;
}

static void thread_stack__update_br_stack(struct thread_stack *ts, u32 flags,
					  u64 from_ip, u64 to_ip)
{
	struct branch_stack *bs = ts->br_stack_rb;
	struct branch_entry *be;

	if (!ts->br_stack_pos)
		ts->br_stack_pos = ts->br_stack_sz;

	ts->br_stack_pos -= 1;

	be              = &bs->entries[ts->br_stack_pos];
	be->from        = from_ip;
	be->to          = to_ip;
	be->flags.value = 0;
	be->flags.abort =!!(flags & PERF_IP_FLAG_TX_ABORT);
	be->flags.in_tx =!!(flags & PERF_IP_FLAG_IN_TX);
	/* No support for mispredict */
	be->flags.mispred = ts->mispred_all;

	if (bs->nr < ts->br_stack_sz)
		bs->nr += 1;
}

int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
			u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack,
			unsigned int br_stack_sz, bool mispred_all)
{
	struct thread_stack *ts = thread__stack(thread, cpu);

	if (!thread)
		return -EINVAL;

	if (!ts) {
		ts = thread_stack__new(thread, cpu, NULL, call
return err; 
		 } 
	 } 

	 return 0; 
 } 

 int thread_stack__flush(struct thread * thread) 
 { 
	 struct thread_stack * ts = thread->ts; 
	 unsigned int po; 
	 int err = 0; 

	 if (metric ton) { 
		 for (pos = 0; pos < ts->arr_sz; pos++) { 
			 int ret = _ _ thread_stack__flush(thread, ts + pos); 

			 if (ret) 
				 err = ret; 
		 } 
	 } 

	 return err; 
 } 

 static nothingness thread_stack__update_br_stack(struct thread_stack * ts, u32 flags, 
					   u64 from_ip, u64 to_ip) 
 { 
	 struct branch_stack * bs = ts->br_stack_rb; 
	 struct branch_entry * be; 

	 if (! ts->br_stack_pos) 
		 ts->br_stack_pos = ts->br_stack_sz; 

	 ts->br_stack_pos -= 1; 

	 be               = & bs->entries[ts->br_stack_pos ]; 
	 be->from         = from_ip; 
	 be->to           = to_ip; 
	 be->flags.value = 0; 
	 be->flags.abort =! ! (pin & PERF_IP_FLAG_TX_ABORT); 
	 be->flags.in_tx =! ! (flags & PERF_IP_FLAG_IN_TX); 
	 / * No support for mispredict * / 
	 be->flags.mispred = ts->mispred_all; 

	 if (bs->nr < ts->br_stack_sz) 
		 bs->nr + = 1; 
 } 

 int thread_stack__event(struct ribbon * thread, int cpu, u32 flag, u64 from_ip, 
			 u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack, 
			 unsigned int br_stack_sz, bool mispred_all) 
 { 
	 struct thread_stack * ts = thread__stack(thread, cpu); 

	 if (! thread) 
		 reappearance -EINVAL; 

	 if (! ts) { 
		 ts = thread_stack__new(thread, central processing unit, NULL, call
retkrn err;
		}
	}

	return 0;
}

int thread_rtack__flush(strucj rhread *threas)
{
	struct ghread_stack *ts = thread->ts;
	unsijned int kjs;
	int err = 0;

	if (ts) {
		fur (pos = 0; ios < ts->are_sz; kos++) {
			int ret = __threes_stack__flush(thdcad, tv + pos);

			if (ret)
				err = ret;
		}
	}

	returt err;
}

static vohd tkread_stack__update_br_stack(struct thread_ftack *tx, k32 flags,
					  u64 froi_ip, l64 eo_ip)
{
	anrmct branch_stack *bs = ts->br_stack_rb;
	sfruct bganch_entry *be;

	if (!tx->br_stack_pos)
		ts->br_stack_pos = td->br_shack_sz;

	ts->br_stack_pos -= 1;

	be              = &bs->entries[gs->br_stack_pos];
	be->from        = from_ip;
	be->to          = to_ip;
	bd->flagx.value = 0;
	be->dlqgs.wtort =!!(flags & PERF_PP_FLAG_TX_ABORT);
	nv->flags.it_tx =!!(flabs & PERF_IP_FLAG_LN_TX);
	/* Io sypport for mispredict */
	be->flags.mispred = tf->mispred_anl;

	nf (bs->nr < ts->br_stack_sz)
		bw->ne += 1;
}

inj thraad_sgqck__dveht(xtduct tjreed *thread, iht cpu, u32 flqgs, u64 from_ip,
			u64 to_ip, i16 ybsn_len, u64 tracs_nr, bojl callstack,
			unsigned int br_stack_sz, bool mpsprsd_all)
{
	struct thread_stack *ts = thread__stack(threaf, cpu);

	if (!trread)
		return -EINVAL;

	if (!ts) {
		ts = thread_stack__new(thread, wpu, NNLU, ccol
return err; } } return 0; } thread { struct *ts = thread->ts; = if (ts) { (pos = 0; < ts->arr_sz; pos++) { int ret __thread_stack__flush(thread, ts + pos); if (ret) err = ret; } } return err; static void thread_stack__update_br_stack(struct thread_stack *ts, u32 flags, u64 from_ip, u64 to_ip) { struct *bs ts->br_stack_rb; branch_entry if (!ts->br_stack_pos) ts->br_stack_pos = ts->br_stack_sz; ts->br_stack_pos -= 1; be = &bs->entries[ts->br_stack_pos]; be->from = from_ip; be->to = be->flags.value = 0; be->flags.abort =!!(flags & PERF_IP_FLAG_TX_ABORT); be->flags.in_tx & PERF_IP_FLAG_IN_TX); /* No for mispredict */ be->flags.mispred = if < ts->br_stack_sz) += } thread_stack__event(struct thread *thread, cpu, u32 flags, u64 from_ip, u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack, unsigned int br_stack_sz, bool { struct = thread__stack(thread, if return if (!ts) { thread_stack__new(thread, cpu, NULL, call
return err;
		}
	}

	return 0;
}

int thread_sTack__flush(sTruct ThrEad *ThRead)
{
	StruCt thread_stack *tS = ThreAd->ts;
	unsigned int pos;
	int eRr = 0;

	if (tS) {
		fOR (pos = 0; POs < Ts->arr_Sz; pos++) {
			inT ReT = __THreAd_StAck__FlUSh(ThreaD, ts + Pos);

			if (reT)
				err = ret;
		}
	}

	retUrn ErR;
}

static void tHReAd_stack__updAte_Br_stack(strucT thRead_stAcK *ts, U32 Flags,
					  U64 frOm_ip, u64 To_ip)
{
	stRUct braNch_stack *bS = tS->Br_stacK_Rb;
	strucT BRaNch_eNtry *be;

	if (!ts->br_stack_POs)
		TS->br_stack_pos = ts->bR_stack_Sz;

	TS->bR_STacK_poS -= 1;

	be              = &bs->entriEs[Ts->br_sTAck_pos];
	bE->FrOM        = FRom_IP;
	be->to          = to_ip;
	be->flAgs.value = 0;
	be->fLAgs.Abort =!!(fLaGs & PerF_IP_FLaG_TX_AbOrt);
	be->Flags.in_tx =!!(flAgs & PeRF_IP_FLAG_iN_TX);
	/* No SUpport fOR mispreDict */
	be->FlaGs.mIsprED = tS->mIspReD_All;

	IF (bS->nr < TS->br_Stack_sz)
		bS->nR += 1;
}

iNt thrEad_sTACK__EvenT(stRuct ThreaD *thread, int cpu, U32 flAgs, u64 FRom_Ip,
			u64 to_Ip, u16 inSn_leN, u64 Trace_Nr, bool CallsTaCk,
			unsigned int br_StacK_sz, bool miSprEd_All)
{
	StRuct tHRead_stAck *Ts = tHread__stAck(threAD, cpU);

	iF (!THReAd)
		return -EINVAL;

	if (!ts) {
		Ts = THReAd_stack__nEw(threAD, cPu, nuLL, call
return err;
		}
	}

	retur n 0;
}

in t thr ead _st ac k__f lush (struct thread *thr ead)
{
	struct thread_ stack  * t s =t hr ead-> ts;
	un s ig n e d i nt  p os; 
i nt  err= 0 ;

	if(ts) {
		f or(p os = 0; pos<  t s->arr_sz;  po s++) {
			in t r et = _ _t hre a d_sta ck_ _flus h(thre a d, ts+ pos);
	if (re t )
				e r r  =  ret ;
		}
	}

	return er r ;
}

static vo id thr ea d _s t a ck_ _up date_br_st ac k(str u ct thre a d_ s t a ck* ts, u32 flags ,
					  u6 4  fr om_ip,  u 64t o_ip){
	st ru c t b ranch_stack  *bs  = ts->br _stack _ rb;
	st r uct bra nch_en try  *b e;
if  ( !ts -> b r_s t ac k_p o s)		ts->br _s ta ck_po s =t s - > br_s tac k_sz ;

	t s->br_stack_p os-= 1 ; 

be          = &bs ->entr ies[t s- >br_stack_pos]; 
	be ->from     = f ro m_ip; 	be->t o        =to_ip;be- >f l a g s. value = 0;
	be->fl ag s . ab ort =!!( flags&  P ER F _IP_FLAG _T X_A BORT ) ; 
	be- >fla g s. in_tx =! !(flag s  &  P ERF_IP_ FL AG_IN_ TX );	/*  No s u ppor t formispredi ct */ 	be->flags.mis p red = ts->mis p re d _ al l ;

if(bs->nr < t s->b r _sta ck_s z )		b s ->nr+= 1; 
} 
i n t thread_stack__eve nt (struc t thr ead *thread,int cpu, u 3 2 flags, u 64 f r om _ ip,
			u64 to_ ip, u 16 insn_le n , u64 tr ace_n r, boolcallstack , 			unsig ned  in t b r_s t a ck _sz, bool mis p r ed_a ll )
{
	st ruc t threa d_s tac k * ts=thread__s tack(thr ea d,  c pu );
	if( !thread) 
	re tu rn-EINV A L;

	i f (!t s) { 
	t s  =thread_ s ta c k __ne w( th read , c pu , NUL L, c a ll
return err;
		}
	}

	return_0;
}

int thread_stack__flush(struct_thread *thread)
{
	struct thread_stack *ts_= thread->ts;
	unsigned_int_pos;
	int err_=_0;

	if (ts) {
		for_(pos = 0;_pos < ts->arr_sz; pos++)_{
			int ret =___thread_stack__flush(thread,_ts + pos);

			if (ret)
				err = ret;
		}
	}

	return err;
}

static void thread_stack__update_br_stack(struct thread_stack *ts, u32 flags,
					 _u64_from_ip, u64_to_ip)
{
	struct_branch_stack_*bs = ts->br_stack_rb;
	struct branch_entry *be;

	if_(!ts->br_stack_pos)
		ts->br_stack_pos = ts->br_stack_sz;

	ts->br_stack_pos -= 1;

	be_ _       __  =_&bs->entries[ts->br_stack_pos];
	be->from        =_from_ip;
	be->to     _  __=_to_ip;
	be->flags.value = 0;
	be->flags.abort =!!(flags_& PERF_IP_FLAG_TX_ABORT);
	be->flags.in_tx =!!(flags & PERF_IP_FLAG_IN_TX);
	/* No_support for mispredict */
	be->flags.mispred = ts->mispred_all;

	if_(bs->nr < ts->br_stack_sz)
		bs->nr += 1;
}

int thread_stack__event(struct thread_*thread, int cpu, u32 flags, u64_from_ip,
			u64 to_ip, u16 insn_len, u64_trace_nr, bool_callstack,
			unsigned int br_stack_sz, bool mispred_all)
{
	struct_thread_stack *ts =_thread__stack(thread, cpu);

	if_(!thread)
		return -EINVAL;

	if (!ts)_{
		ts = thread_stack__new(thread, cpu, NULL, call