Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL New Arnaldo Carvalho de Melo 1 participant 6 messages Oct 7, 2015

Subsystems (2)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit 712df65ccb63da08a484bf57c40b250dfd4103a7:

perf/x86/intel/uncore: Fix multi-segment problem of perf_event_intel_uncore (2015-10-06 17:31:51 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo

for you to fetch changes up to ae938802443732e77d01f8d5b52b900b9327ff30:

perf python: Support the PERF_RECORD_SWITCH event (2015-10-07 19:41:50 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

User visible:

- Adding a field via 'perf report -F' that already is enabled makes the tool get stuck in a loop, fix it (Jiri Olsa)

Infrastructure:

- Support PERF_RECORD_SWITCH in the python binding (Arnaldo Carvalho de Melo)

- Fix handling read() result using a signed variable, found with Coccinelle (Andrzej Hajda)

----------------------------------------------------------------
Andrzej Hajda (1):
perf tools: Fix handling read result using a signed variable

Arnaldo Carvalho de Melo (1):
perf python: Support the PERF_RECORD_SWITCH event

Jiri Olsa (3):
perf tools: Get rid of superfluos call to reset_dimensions perf tools: Introduce hpp_dimension__add_output function perf tools: Use hpp_dimension__add_output to register hpp columns

 tools/perf/python/twatch.py | 23 +++++++++++++++---
 tools/perf/ui/hist.c        | 16 ++++++------
 tools/perf/util/event.c     |  3 ++-
 tools/perf/util/python.c    | 59 ++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/sort.c      |  8 ++++--
 tools/perf/util/sort.h      |  2 ++
 6 files changed, 93 insertions(+), 18 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 perf tools: Get rid of superfluos call to reset_dimensions

From: Jiri Olsa <[email protected]>

There's no need to call reset_dimensions within __setup_output_field function. It's already called in its caller setup_sorting right before perf_hpp__init, which will be changed in following patch to respect taken dimension.

---
 tools/perf/util/sort.c | 2 --
 1 file changed, 2 deletions(-)
tools/perf/util/sort.c +0 -2
index ee94b728fca4..8521e3c89b8d 100644
@@ -1917,8 +1917,6 @@ static int __setup_output_field(void)
 	if (field_order == NULL)
 		return 0;
 
-	reset_dimensions();
-
 	strp = str = strdup(field_order);
 	if (str == NULL) {
 		error("Not enough memory to setup output fields");
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/5 perf tools: Introduce hpp_dimension__add_output function

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

This function will allow to register output column from ui code and respect taken sort/output dimensions.

---
 tools/perf/util/sort.c | 6 ++++++
 tools/perf/util/sort.h | 2 ++
 2 files changed, 8 insertions(+)
tools/perf/util/sort.c +6 -0
index 8521e3c89b8d..2d8ccd4d9e1b 100644
@@ -1577,6 +1577,12 @@ static int __hpp_dimension__add_output(struct hpp_dimension *hd)
 	return 0;
 }
 
+int hpp_dimension__add_output(unsigned col)
+{
+	BUG_ON(col >= PERF_HPP__MAX_INDEX);
+	return __hpp_dimension__add_output(&hpp_sort_dimensions[col]);
+}
+
 int sort_dimension__add(const char *tok)
 {
 	unsigned int i;
tools/perf/util/sort.h +2 -0
index 33b3d30e18d3..31228851e397 100644
@@ -234,4 +234,6 @@ void perf_hpp__set_elide(int idx, bool elide);
 int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
 
 bool is_strict_order(const char *order);
+
+int hpp_dimension__add_output(unsigned col);
 #endif	/* __PERF_SORT_H */
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 3/5 perf tools: Use hpp_dimension__add_output to register hpp columns

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

The perf_hpp__init currently does not respect sorting dimensions and the setup_sorting function could endup queueing same format twice. That screwed up the perf_hpp__list and got stuck in loop within perf_hpp__setup_output_field function.

  $ perf report -F +overhead
  0x00000000004c1355 in perf_hpp__is_sort_entry (format=format@entry=0x880440 <perf_hpp.format>) at util/sort.c:1506
  1506    {
     #0  0x00000000004c1355 in perf_hpp__is_sort_entry (format=format@entry=0x880440 <perf_hpp.format>) at util/sort.c:1506
     #1  0x00000000004c139d in perf_hpp__same_sort_entry (a=a@entry=0x880440 <perf_hpp.format>, b=b@entry=0x2bb2fe0) at util/sort.c:1380
     #2  0x00000000004f8d3c in perf_hpp__setup_output_field () at ui/hist.c:554
     #3  0x00000000004c1d1e in setup_sorting () at util/sort.c:1984
     #4  0x000000000042efbf in cmd_report (argc=0, argv=0x7ffea5a0e790, prefix=<optimized out>) at builtin-report.c:874
     #5  0x0000000000476f13 in run_builtin (p=p@entry=0x875628 <commands+168>, argc=argc@entry=3, argv=argv@entry=0x7ffea5a0e790) at perf.c:385
     #6  0x000000000047710b in handle_internal_command (argc=3, argv=0x7ffea5a0e790) at perf.c:445
     #7  0x0000000000477176 in run_argv (argcp=argcp@entry=0x7ffea5a0e5fc, argv=argv@entry=0x7ffea5a0e5f0) at perf.c:489
     #8  0x00000000004773e7 in main (argc=3, argv=0x7ffea5a0e790) at perf.c:606

Using hpp_dimension__add_output function to register the output column. It will also mark the dimension as taken and omit above stuck.

---
 tools/perf/ui/hist.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
tools/perf/ui/hist.c +8 -8
index 25d608394d74..5029ba2b55af 100644
@@ -463,27 +463,27 @@ void perf_hpp__init(void)
 		return;
 
 	if (symbol_conf.cumulate_callchain) {
-		perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);
+		hpp_dimension__add_output(PERF_HPP__OVERHEAD_ACC);
 		perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
 	}
 
-	perf_hpp__column_enable(PERF_HPP__OVERHEAD);
+	hpp_dimension__add_output(PERF_HPP__OVERHEAD);
 
 	if (symbol_conf.show_cpu_utilization) {
-		perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
-		perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
+		hpp_dimension__add_output(PERF_HPP__OVERHEAD_SYS);
+		hpp_dimension__add_output(PERF_HPP__OVERHEAD_US);
 
 		if (perf_guest) {
-			perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
-			perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
+			hpp_dimension__add_output(PERF_HPP__OVERHEAD_GUEST_SYS);
+			hpp_dimension__add_output(PERF_HPP__OVERHEAD_GUEST_US);
 		}
 	}
 
 	if (symbol_conf.show_nr_samples)
-		perf_hpp__column_enable(PERF_HPP__SAMPLES);
+		hpp_dimension__add_output(PERF_HPP__SAMPLES);
 
 	if (symbol_conf.show_total_period)
-		perf_hpp__column_enable(PERF_HPP__PERIOD);
+		hpp_dimension__add_output(PERF_HPP__PERIOD);
 
 	/* prepend overhead field for backward compatiblity.  */
 	list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
Signature · 1 line
2.1.0
author maintainer
#4 lore raw

PATCH 4/5 perf tools: Fix handling read result using a signed variable

In reply to Arnaldo Carvalho de Melo

From: Andrzej Hajda <[email protected]>

The function can return negative value, assigning it to unsigned variable can cause memory corruption.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 tools/perf/util/event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/event.c +2 -1
index cb98b5af9e17..8b10621b415c 100644
@@ -67,7 +67,8 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
 	char filename[PATH_MAX];
 	char bf[4096];
 	int fd;
-	size_t size = 0, n;
+	size_t size = 0;
+	ssize_t n;
 	char *nl, *name, *tgids, *ppids;
 
 	*tgid = -1;
Signature · 1 line
2.1.0
author maintainer
#5 lore raw

PATCH 5/5 perf python: Support the PERF_RECORD_SWITCH

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

To test it check tools/perf/python/twatch.py, after following the instructions there to enable context_switch, output looks like:

[root@zoo linux]# tools/perf/python/twatch.py
cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 0 }
cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 0 }
cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 }
cpu: 3, pid: 31463, tid: 31527 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31527, switch_out: 0 }
cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 1 }
cpu: 3, pid: 31463, tid: 31527 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31527, switch_out: 1 }
cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 0 } ^CTraceback (most recent call last):
File "tools/perf/python/twatch.py", line 67, in <module>
main(context_switch = 1, thread = 31463)
File "tools/perf/python/twatch.py", line 40, in main
evlist.poll(timeout = -1)
KeyboardInterrupt
[root@zoo linux]#

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Guy Streeter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/python/twatch.py | 23 +++++++++++++++---
 tools/perf/util/python.c    | 59 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 75 insertions(+), 7 deletions(-)
tools/perf/python/twatch.py +20 -3
index b9d508336ae6..c235c22b107a 100755
@@ -15,14 +15,14 @@
 
 import perf
 
-def main():
+def main(context_switch = 0, thread = -1):
 	cpus = perf.cpu_map()
-	threads = perf.thread_map()
+	threads = perf.thread_map(thread)
 	evsel = perf.evsel(type	  = perf.TYPE_SOFTWARE,
 			   config = perf.COUNT_SW_DUMMY,
 			   task = 1, comm = 1, mmap = 0, freq = 0,
 			   wakeup_events = 1, watermark = 1,
-			   sample_id_all = 1,
+			   sample_id_all = 1, context_switch = context_switch,
 			   sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
 
 	"""What we want are just the PERF_RECORD_ lifetime events for threads,
@@ -48,4 +48,21 @@ def main():
 			print event
 
 if __name__ == '__main__':
+    """
+	To test the PERF_RECORD_SWITCH record, pick a pid and replace
+	in the following line.
+
+	Example output:
+
+cpu: 3, pid: 31463, tid: 31593 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31593, switch_out: 1 }
+cpu: 1, pid: 31463, tid: 31489 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31489, switch_out: 1 }
+cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 }
+cpu: 3, pid: 31463, tid: 31491 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31491, switch_out: 0 }
+
+	It is possible as well to use event.misc & perf.PERF_RECORD_MISC_SWITCH_OUT
+	to figure out if this is a context switch in or out of the monitored threads.
+
+	If bored, please add command line option parsing support for these options :-)
+    """
+    # main(context_switch = 1, thread = 31463)
     main()
tools/perf/util/python.c +55 -4

130 lines not on this page · raw message

Signature · 1 line
2.1.0