Skip to contentSkip to conversation

Add 4 more cases for Intel PT.

PATCH Superseded Ammy Yi 3 participants 4 messages May 24, 2019 – May 31, 2019

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ammy Yi

author
#0 lore raw

PATCH v3 1/1 Add 4 more cases for Intel PT.

1. Add Intel PT sanpshot mode test.
2. Add Intel PT exclude user trace mode test.
3. Add Intel PT exclude kernel trace mode test.
4. Add Intel PT disable branch trace mode test.

---
 runtest/tracing                            |  4 ++
 testcases/kernel/tracing/pt_test/pt_test.c | 66 +++++++++++++++++++++++-------
 2 files changed, 56 insertions(+), 14 deletions(-)
runtest/tracing +4 -0
index 504132d70..d2700ca57 100644
@@ -4,3 +4,7 @@ ftrace_regression02	ftrace_regression02.sh
 ftrace-stress-test	ftrace_stress_test.sh 90
 dynamic_debug01		dynamic_debug01.sh
 pt_full_trace_basic pt_test
+pt_snapshot_trace_basic pt_test -m
+pt_ex_user pt_test -e user
+pt_ex_kernel pt_test -e kernel
+pt_disable_branch pt_test -b
testcases/kernel/tracing/pt_test/pt_test.c +52 -14

140 lines not on this page · raw message

Signature · 1 line
2.14.1
#1 lore raw

PATCH v3 1/1 Add 4 more cases for Intel PT.

Hi!

testcases/kernel/tracing/pt_test/pt_test.c int fde = -1; · line 64

Quoted 8 lines
testcases/kernel/tracing/pt_test/pt_test.c +8 -0
+	if (flag == 1) {
+		tst_res(TINFO, "memory will be r/w for full trace mode!");
+		pro_flag = PROT_READ | PROT_WRITE;
+	} else {
+		tst_res(TINFO, "memory will be r only for snapshot mode!");
+		pro_flag = PROT_READ;
+	}
+	buf_ev[0] = SAFE_MMAP(fde, INTEL_PT_MEMSIZE, PROT_READ | PROT_WRITE,

^
This should be NULL, right?

Quoted 47 lines
testcases/kernel/tracing/pt_test/pt_test.c +5 -6
 							MAP_SHARED, fde, 0);
 
 	pc = (struct perf_event_mmap_page *)buf_ev[0];
 	pc->aux_offset = INTEL_PT_MEMSIZE;
 	pc->aux_size = bufsize;
-	buf_ev[1] = SAFE_MMAP(NULL, bufsize, PROT_READ | PROT_WRITE,
+	buf_ev[1] = SAFE_MMAP(NULL, bufsize, pro_flag,
 					MAP_SHARED, fde, INTEL_PT_MEMSIZE);
 	return buf_ev;
 }
@@ -89,7 +101,7 @@ static void del_map(uint64_t **buf_ev, long bufsize)
 	free(buf_ev);
 }
 
-static void intel_pt_full_trace_check(void)
+static void intel_pt_trace_check(void)
 {
 	uint64_t aux_head = 0;
 	struct perf_event_mmap_page *pmp;
@@ -104,11 +116,11 @@ static void intel_pt_full_trace_check(void)
 	pmp = (struct perf_event_mmap_page *)bufm[0];
 	aux_head = *(volatile uint64_t *)&pmp->aux_head;
 	if (aux_head == 0) {
-		tst_res(TFAIL, "There is no trace!");
+		tst_res(TFAIL, "There is no trace.");
 		return;
 	}
 
-	tst_res(TPASS, "perf trace full mode is passed!");
+	tst_res(TPASS, "perf trace test is passed.");
 }
 
 static void setup(void)
@@ -116,6 +128,7 @@ static void setup(void)
 	struct perf_event_attr attr = {};
 
 	buhsz = 2 * PAGESIZE;
+
 	if (access(INTEL_PT_PATH, F_OK)) {
 		tst_brk(TCONF,
 			"Requires Intel Core 5th+ generation (Broadwell and newer)"
@@ -130,20 +143,36 @@ static void setup(void)
 	attr.config	= BIT(intel_pt_pmu_value(INTEL_PT_FORMAT_TSC)) |
 				BIT(intel_pt_pmu_value(INTEL_PT_FORMAT_NRT));
 	attr.size	= sizeof(struct perf_event_attr);
-	attr.exclude_kernel		= 0;
-	attr.exclude_user		= 0;

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 155

Quoted 10 lines
testcases/kernel/tracing/pt_test/pt_test.c +9 -0
 	attr.mmap			= 1;
+	if (str_branch_flag) {
+		tst_res(TINFO, "Intel PT will disable branch trace.");
+		attr.config |= 1;
+	}
+
+	attr.exclude_kernel	= 0;
+	attr.exclude_user	= 0;
+
+	if (str_exclude_info && strcmp(str_exclude_info, "user")) {

^
Should be !strcmp() as the function returns 0 on match

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 159

Quoted 4 lines
testcases/kernel/tracing/pt_test/pt_test.c +4 -0
+		tst_res(TINFO, "Intel PT will exclude kernel trace.");
+		attr.exclude_kernel = 1;
+	}
+	if (str_exclude_info && strcmp(str_exclude_info, "kernel")) {

^
Here as well.

Quoted 47 lines
testcases/kernel/tracing/pt_test/pt_test.c +18 -4
+		tst_res(TINFO, "Intel PT will exclude user trace.");
+		attr.exclude_user = 1;
+	}
 
 	/* only get trace for own pid */
 	fde = tst_syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
 	if (fde < 0) {
-		tst_res(TINFO, "Open Intel PT event failed!");
-		tst_res(TFAIL, "perf trace full mode is failed!");
+		tst_res(TINFO, "Open Intel PT event failed.");
+		tst_res(TFAIL, "perf trace full mode is failed.");
 		return;
 	}
 	bufm = NULL;
-	bufm = create_map(fde, buhsz);
+	if (str_mode)
+		mode = 0;
 
+	bufm = create_map(fde, buhsz, mode);
 }
 
 static void cleanup(void)
@@ -154,8 +183,17 @@ static void cleanup(void)
 	del_map(bufm, buhsz);
 }
 
+static struct tst_option options[] = {
+	{"m", &str_mode, "-m different mode, default is full mode"},
+	{"e:", &str_exclude_info, "-e exclude info, user or kernel"},
+	{"b", &str_branch_flag, "-b if disable branch trace"},
+	{NULL, NULL, NULL}
+};
+
+
 static struct tst_test test = {
-	.test_all = intel_pt_full_trace_check,
+	.test_all = intel_pt_trace_check,
+	.options = options,
 	.min_kver = "4.1",
 	.setup = setup,
 	.cleanup = cleanup,
Signature · 5 lines
2.14.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH v3 1/1 Add 4 more cases for Intel PT.

Hi Hrubis,

Add comments. Thanks.

Best Regards
Ammy Yi

-----Original Message-----
From: Cyril Hrubis [mailto:[email protected]]
Sent: Wednesday, May 29, 2019 10:39 PM
To: Yi, Ammy <[email protected]>
Cc: [email protected]
Subject: Re: [LTP] [PATCH v3 ltp] Add 4 more cases for Intel PT.

Hi!

testcases/kernel/tracing/pt_test/pt_test.c int fde = -1; · line 64

Quoted 8 lines
testcases/kernel/tracing/pt_test/pt_test.c +8 -0
+	if (flag == 1) {
+		tst_res(TINFO, "memory will be r/w for full trace mode!");
+		pro_flag = PROT_READ | PROT_WRITE;
+	} else {
+		tst_res(TINFO, "memory will be r only for snapshot mode!");
+		pro_flag = PROT_READ;
+	}
+	buf_ev[0] = SAFE_MMAP(fde, INTEL_PT_MEMSIZE, PROT_READ | PROT_WRITE,

^
This should be NULL, right?
[Ammy] Do you mean tis will get NULL? No, SAFE_MMAP should be successfully here.

Quoted 47 lines
testcases/kernel/tracing/pt_test/pt_test.c +5 -6
 							MAP_SHARED, fde, 0);
 
 	pc = (struct perf_event_mmap_page *)buf_ev[0];
 	pc->aux_offset = INTEL_PT_MEMSIZE;
 	pc->aux_size = bufsize;
-	buf_ev[1] = SAFE_MMAP(NULL, bufsize, PROT_READ | PROT_WRITE,
+	buf_ev[1] = SAFE_MMAP(NULL, bufsize, pro_flag,
 					MAP_SHARED, fde, INTEL_PT_MEMSIZE);
 	return buf_ev;
 }
@@ -89,7 +101,7 @@ static void del_map(uint64_t **buf_ev, long bufsize)
 	free(buf_ev);
 }
 
-static void intel_pt_full_trace_check(void)
+static void intel_pt_trace_check(void)
 {
 	uint64_t aux_head = 0;
 	struct perf_event_mmap_page *pmp;
@@ -104,11 +116,11 @@ static void intel_pt_full_trace_check(void)
 	pmp = (struct perf_event_mmap_page *)bufm[0];
 	aux_head = *(volatile uint64_t *)&pmp->aux_head;
 	if (aux_head == 0) {
-		tst_res(TFAIL, "There is no trace!");
+		tst_res(TFAIL, "There is no trace.");
 		return;
 	}
 
-	tst_res(TPASS, "perf trace full mode is passed!");
+	tst_res(TPASS, "perf trace test is passed.");
 }
 
 static void setup(void)
@@ -116,6 +128,7 @@ static void setup(void)
 	struct perf_event_attr attr = {};
 
 	buhsz = 2 * PAGESIZE;
+
 	if (access(INTEL_PT_PATH, F_OK)) {
 		tst_brk(TCONF,
 			"Requires Intel Core 5th+ generation (Broadwell and newer)"
@@ -130,20 +143,36 @@ static void setup(void)
 	attr.config	= BIT(intel_pt_pmu_value(INTEL_PT_FORMAT_TSC)) |
 				BIT(intel_pt_pmu_value(INTEL_PT_FORMAT_NRT));
 	attr.size	= sizeof(struct perf_event_attr);
-	attr.exclude_kernel		= 0;
-	attr.exclude_user		= 0;

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 155

Quoted 10 lines
testcases/kernel/tracing/pt_test/pt_test.c +9 -0
 	attr.mmap			= 1;
+	if (str_branch_flag) {
+		tst_res(TINFO, "Intel PT will disable branch trace.");
+		attr.config |= 1;
+	}
+
+	attr.exclude_kernel	= 0;
+	attr.exclude_user	= 0;
+
+	if (str_exclude_info && strcmp(str_exclude_info, "user")) {

^
Should be !strcmp() as the function
returns 0 on match
[Ammy] This is a little tricky here, if = user, means exclude user, then attr.exclude_user = 1. Here is right. If not match with user, it means not exclude user, it need exclude kernel trace, then attr.exclude_kernel = 1; From following execution log, we can see case name is " pt_ex_user " for exclude user test, then " Intel PT will exclude user trace " in log, they are matched.
<<<test_start>>>
tag=pt_ex_user stime=1559243215
cmdline="pt_test -e user"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
pt_test.c:164: INFO: Intel PT will exclude user trace.
pt_test.c:58: INFO: memory will be r/w for full trace mode!
pt_test.c:67: INFO: buf_ev[0] = -166998016
pt_test.c:70: INFO: Open Intel PT event failed.
pt_test.c:127: PASS: perf trace test is passed.

Summary:

passed   1
failed   0
skipped  0

warnings 0
<<<execution_status>>>

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 159

Quoted 4 lines
testcases/kernel/tracing/pt_test/pt_test.c +4 -0
+		tst_res(TINFO, "Intel PT will exclude kernel trace.");
+		attr.exclude_kernel = 1;
+	}
+	if (str_exclude_info && strcmp(str_exclude_info, "kernel")) {

^
Here as well.
[Ammy] Same as above.

Quoted 47 lines
testcases/kernel/tracing/pt_test/pt_test.c +18 -4
+		tst_res(TINFO, "Intel PT will exclude user trace.");
+		attr.exclude_user = 1;
+	}
 
 	/* only get trace for own pid */
 	fde = tst_syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
 	if (fde < 0) {
-		tst_res(TINFO, "Open Intel PT event failed!");
-		tst_res(TFAIL, "perf trace full mode is failed!");
+		tst_res(TINFO, "Open Intel PT event failed.");
+		tst_res(TFAIL, "perf trace full mode is failed.");
 		return;
 	}
 	bufm = NULL;
-	bufm = create_map(fde, buhsz);
+	if (str_mode)
+		mode = 0;
 
+	bufm = create_map(fde, buhsz, mode);
 }
 
 static void cleanup(void)
@@ -154,8 +183,17 @@ static void cleanup(void)
 	del_map(bufm, buhsz);
 }
 
+static struct tst_option options[] = {
+	{"m", &str_mode, "-m different mode, default is full mode"},
+	{"e:", &str_exclude_info, "-e exclude info, user or kernel"},
+	{"b", &str_branch_flag, "-b if disable branch trace"},
+	{NULL, NULL, NULL}
+};
+
+
 static struct tst_test test = {
-	.test_all = intel_pt_full_trace_check,
+	.test_all = intel_pt_trace_check,
+	.options = options,
 	.min_kver = "4.1",
 	.setup = setup,
 	.cleanup = cleanup,
Signature · 5 lines
2.14.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v3 1/1 Add 4 more cases for Intel PT.

Hi!

Quoted 11 lines

testcases/kernel/tracing/pt_test/pt_test.c int fde = -1; · line 64

Quoted 8 lines
testcases/kernel/tracing/pt_test/pt_test.c +8 -0
+	if (flag == 1) {
+		tst_res(TINFO, "memory will be r/w for full trace mode!");
+		pro_flag = PROT_READ | PROT_WRITE;
+	} else {
+		tst_res(TINFO, "memory will be r only for snapshot mode!");
+		pro_flag = PROT_READ;
+	}
+	buf_ev[0] = SAFE_MMAP(fde, INTEL_PT_MEMSIZE, PROT_READ | PROT_WRITE,

^
This should be NULL, right?
[Ammy] Do you mean tis will get NULL? No, SAFE_MMAP should be successfully here.

Not at all. You are passing file descriptor as addr parameter to mmap() which is wrong and the mmap() call only passes because the address parameters is ignored unless we pass MAP_FIXED.

Quoted 6 lines
Quoted 6 lines
testcases/kernel/tracing/pt_test/pt_test.c +6 -0
+	if (str_branch_flag) {
+		tst_res(TINFO, "Intel PT will disable branch trace.");
+		attr.config |= 1;
+	}
+
+	attr.exclude_kernel	= 0;
Quoted 8 lines

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 155

Quoted 3 lines
testcases/kernel/tracing/pt_test/pt_test.c +3 -0
+	attr.exclude_user	= 0;
+
+	if (str_exclude_info && strcmp(str_exclude_info, "user")) {

^
Should be !strcmp() as the function
returns 0 on match
[Ammy] This is a little tricky here, if = user, means exclude user, then attr.exclude_user = 1. Here is right. If not match with user, it means not exclude user, it need exclude kernel trace, then attr.exclude_kernel = 1; From following execution log, we can see case name is " pt_ex_user " for exclude user test, then " Intel PT will exclude user trace " in log, they are matched.

Well as it is this will also work if we pass garbage to the -e parameter it will set both exclude_kernel and exclude_user paramters.

Why isn't this simply:

	if (str_exclude) {
		if (!strcmp(str_exclude, "user")) {
			tst_res(TINFO, "Excluding user trace");
			attr.exclude_user = 1;
		} else if (!strcmp(str_exclude, "kernel")) {
			tst_res(TINFO, "Excluding kernel trace");
			attr.exclude_kernel = 1;
		} else {
			tst_brk(TBROK, "Invalid -e '%s'", str_exclude);
		}
	}
Quoted 58 lines

testcases/kernel/tracing/pt_test/pt_test.c static void setup(void) · line 159

Quoted 4 lines
testcases/kernel/tracing/pt_test/pt_test.c +4 -0
+		tst_res(TINFO, "Intel PT will exclude kernel trace.");
+		attr.exclude_kernel = 1;
+	}
+	if (str_exclude_info && strcmp(str_exclude_info, "kernel")) {

^
Here as well.
[Ammy] Same as above.

Quoted 47 lines
testcases/kernel/tracing/pt_test/pt_test.c +18 -4
+		tst_res(TINFO, "Intel PT will exclude user trace.");
+		attr.exclude_user = 1;
+	}
 
 	/* only get trace for own pid */
 	fde = tst_syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
 	if (fde < 0) {
-		tst_res(TINFO, "Open Intel PT event failed!");
-		tst_res(TFAIL, "perf trace full mode is failed!");
+		tst_res(TINFO, "Open Intel PT event failed.");
+		tst_res(TFAIL, "perf trace full mode is failed.");
 		return;
 	}
 	bufm = NULL;
-	bufm = create_map(fde, buhsz);
+	if (str_mode)
+		mode = 0;
 
+	bufm = create_map(fde, buhsz, mode);
 }
 
 static void cleanup(void)
@@ -154,8 +183,17 @@ static void cleanup(void)
 	del_map(bufm, buhsz);
 }
 
+static struct tst_option options[] = {
+	{"m", &str_mode, "-m different mode, default is full mode"},
+	{"e:", &str_exclude_info, "-e exclude info, user or kernel"},
+	{"b", &str_branch_flag, "-b if disable branch trace"},
+	{NULL, NULL, NULL}
+};
+
+
 static struct tst_test test = {
-	.test_all = intel_pt_full_trace_check,
+	.test_all = intel_pt_trace_check,
+	.options = options,
 	.min_kver = "4.1",
 	.setup = setup,
 	.cleanup = cleanup,
Signature · 5 lines
2.14.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
Signature · 2 lines
Cyril Hrubis
[email protected]