Skip to content

Commit a488ede

Browse files
libipt: fix blk and insn timing queries
When implementing the block decoder on top of the event decoder in ed9222c libipt: blk on evt we dropped -pte_no_time -pte_no_cbr error returns when no TSC/CBR has been seen. This bug was later inherited by the insn decoder in 8b90e05 libipt, ptxed: insn on block when we implemented that on top of the block decoder. We already track whether we have seen TSC, but we're not using it in pt_blk_time(). Fix that and add tracking for CBR. Fixes #116. Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
1 parent 62aa406 commit a488ede

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

libipt/internal/include/pt_block_decoder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ struct pt_block_decoder {
132132
/* - whether @tsc tracks wall-clock time. */
133133
uint32_t has_tsc:1;
134134

135+
/* - whether @cbr is valid. */
136+
uint32_t has_cbr:1;
137+
135138
/* - whether @icnt is valid. */
136139
uint32_t has_icnt:1;
137140

libipt/src/pt_block_decoder.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static int pt_blk_reset(struct pt_block_decoder *decoder)
200200
decoder->enabled = 0;
201201
decoder->speculative = 0;
202202
decoder->has_tsc = 0;
203+
decoder->has_cbr = 0;
203204
decoder->has_icnt = 0;
204205
decoder->process_insn = 0;
205206
decoder->bound_paging = 0;
@@ -643,6 +644,9 @@ int pt_blk_time(struct pt_block_decoder *decoder, uint64_t *time,
643644
*lost_mtc = decoder->lost_mtc;
644645
*lost_cyc = decoder->lost_cyc;
645646

647+
if (!decoder->has_tsc)
648+
return -pte_no_time;
649+
646650
return 0;
647651
}
648652

@@ -651,6 +655,9 @@ int pt_blk_core_bus_ratio(struct pt_block_decoder *decoder, uint32_t *cbr)
651655
if (!decoder || !cbr)
652656
return -pte_invalid;
653657

658+
if (!decoder->has_cbr)
659+
return -pte_no_cbr;
660+
654661
*cbr = decoder->cbr;
655662

656663
return 0;
@@ -4147,6 +4154,7 @@ static int pt_blk_process_cbr(struct pt_block_decoder *decoder,
41474154
if (!decoder || !ev)
41484155
return -pte_internal;
41494156

4157+
decoder->has_cbr = 1;
41504158
decoder->cbr = ev->variant.cbr.ratio;
41514159

41524160
return 0;

libipt/test/src/ptunit-block_decoder.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ static struct ptunit_result cbr_null(void)
272272
return ptu_passed();
273273
}
274274

275+
static struct ptunit_result time_init(struct test_fixture *tfix)
276+
{
277+
uint64_t time;
278+
uint32_t lost_mtc, lost_cyc;
279+
int errcode;
280+
281+
errcode = pt_blk_time(&tfix->decoder, &time, &lost_mtc, &lost_cyc);
282+
ptu_int_eq(errcode, -pte_no_time);
283+
284+
return ptu_passed();
285+
}
286+
287+
static struct ptunit_result cbr_init(struct test_fixture *tfix)
288+
{
289+
uint32_t cbr;
290+
int errcode;
291+
292+
errcode = pt_blk_core_bus_ratio(&tfix->decoder, &cbr);
293+
ptu_int_eq(errcode, -pte_no_cbr);
294+
295+
return ptu_passed();
296+
}
297+
275298
static struct ptunit_result asid_null(void)
276299
{
277300
struct pt_block_decoder decoder;
@@ -351,6 +374,9 @@ int main(int argc, char **argv)
351374
ptu_run(suite, cbr_null);
352375
ptu_run(suite, asid_null);
353376

377+
ptu_run_f(suite, time_init, tfix);
378+
ptu_run_f(suite, cbr_init, tfix);
379+
354380
ptu_run(suite, next_null);
355381
ptu_run(suite, event_null);
356382

0 commit comments

Comments
 (0)